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