xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/crypto/keyed_checksum_types.c (revision 505d05c73a6e56769f263d4803b22eddd168ee24)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 /*
3  * Copyright (C) 1998 by the FundsXpress, INC.
4  *
5  * All rights reserved.
6  *
7  * Export of this software from the United States of America may require
8  * a specific license from the United States Government.  It is the
9  * responsibility of any person or organization contemplating export to
10  * obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of FundsXpress. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  FundsXpress makes no representations about the suitability of
20  * this software for any purpose.  It is provided "as is" without express
21  * or implied warranty.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26  */
27 
28 #include <k5-int.h>
29 #include <etypes.h>
30 #include <cksumtypes.h>
31 
32 static int etype_match(e1, e2)
33      krb5_enctype e1, e2;
34 {
35     int i1, i2;
36 
37     for (i1=0; i1<krb5_enctypes_length; i1++)
38 	if (krb5_enctypes_list[i1].etype == e1)
39 	    break;
40 
41     for (i2=0; i2<krb5_enctypes_length; i2++)
42 	if (krb5_enctypes_list[i2].etype == e2)
43 	    break;
44 
45     return((i1 < krb5_enctypes_length) &&
46 	   (i2 < krb5_enctypes_length) &&
47 	   (krb5_enctypes_list[i1].enc == krb5_enctypes_list[i2].enc));
48 }
49 
50 /*ARGSUSED*/
51 
52 krb5_error_code KRB5_CALLCONV
53 krb5_c_keyed_checksum_types(krb5_context context, krb5_enctype enctype,
54 			    unsigned int *count, krb5_cksumtype **cksumtypes)
55 {
56     unsigned int i, c;
57 
58     c = 0;
59     for (i=0; i<krb5_cksumtypes_length; i++) {
60 	if ((krb5_cksumtypes_list[i].keyhash &&
61 	     etype_match(krb5_cksumtypes_list[i].keyed_etype, enctype)) ||
62 	    (krb5_cksumtypes_list[i].flags & KRB5_CKSUMFLAG_DERIVE)) {
63 	    c++;
64 	}
65     }
66 
67     *count = c;
68 
69     if ((*cksumtypes = (krb5_cksumtype *) malloc(c*sizeof(krb5_cksumtype)))
70 	== NULL)
71 	return(ENOMEM);
72 
73     c = 0;
74     for (i=0; i<krb5_cksumtypes_length; i++) {
75 	if ((krb5_cksumtypes_list[i].keyhash &&
76 	     etype_match(krb5_cksumtypes_list[i].keyed_etype, enctype)) ||
77 	    (krb5_cksumtypes_list[i].flags & KRB5_CKSUMFLAG_DERIVE)) {
78 	    (*cksumtypes)[c] = krb5_cksumtypes_list[i].ctype;
79 	    c++;
80 	}
81     }
82 
83     return(0);
84 }
85 
86 /*ARGSUSED*/
87 void KRB5_CALLCONV
88 krb5_free_cksumtypes(krb5_context context, krb5_cksumtype *val)
89 {
90     if (val)
91 	krb5_xfree(val);
92     return;
93 }
94 
95