17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 1998 by the FundsXpress, INC.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * All rights reserved.
57c478bd9Sstevel@tonic-gate  *
67c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may require
77c478bd9Sstevel@tonic-gate  * a specific license from the United States Government.  It is the
87c478bd9Sstevel@tonic-gate  * responsibility of any person or organization contemplating export to
97c478bd9Sstevel@tonic-gate  * obtain such a license before exporting.
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
127c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
137c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
147c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
157c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
167c478bd9Sstevel@tonic-gate  * the name of FundsXpress. not be used in advertising or publicity pertaining
177c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
187c478bd9Sstevel@tonic-gate  * permission.  FundsXpress makes no representations about the suitability of
197c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
207c478bd9Sstevel@tonic-gate  * or implied warranty.
217c478bd9Sstevel@tonic-gate  *
227c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
237c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
247c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*159d09a2SMark Phalan #include "k5-int.h"
28*159d09a2SMark Phalan #include "etypes.h"
29*159d09a2SMark Phalan #include "cksumtypes.h"
307c478bd9Sstevel@tonic-gate 
etype_match(krb5_enctype e1,krb5_enctype e2)31*159d09a2SMark Phalan static int etype_match(krb5_enctype e1, krb5_enctype e2)
327c478bd9Sstevel@tonic-gate {
337c478bd9Sstevel@tonic-gate     int i1, i2;
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate     for (i1=0; i1<krb5_enctypes_length; i1++)
367c478bd9Sstevel@tonic-gate 	if (krb5_enctypes_list[i1].etype == e1)
377c478bd9Sstevel@tonic-gate 	    break;
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate     for (i2=0; i2<krb5_enctypes_length; i2++)
407c478bd9Sstevel@tonic-gate 	if (krb5_enctypes_list[i2].etype == e2)
417c478bd9Sstevel@tonic-gate 	    break;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate     return((i1 < krb5_enctypes_length) &&
447c478bd9Sstevel@tonic-gate 	   (i2 < krb5_enctypes_length) &&
457c478bd9Sstevel@tonic-gate 	   (krb5_enctypes_list[i1].enc == krb5_enctypes_list[i2].enc));
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*ARGSUSED*/
49505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_c_keyed_checksum_types(krb5_context context,krb5_enctype enctype,unsigned int * count,krb5_cksumtype ** cksumtypes)50505d05c7Sgtb krb5_c_keyed_checksum_types(krb5_context context, krb5_enctype enctype,
51505d05c7Sgtb 			    unsigned int *count, krb5_cksumtype **cksumtypes)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate     unsigned int i, c;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate     c = 0;
567c478bd9Sstevel@tonic-gate     for (i=0; i<krb5_cksumtypes_length; i++) {
577c478bd9Sstevel@tonic-gate 	if ((krb5_cksumtypes_list[i].keyhash &&
587c478bd9Sstevel@tonic-gate 	     etype_match(krb5_cksumtypes_list[i].keyed_etype, enctype)) ||
597c478bd9Sstevel@tonic-gate 	    (krb5_cksumtypes_list[i].flags & KRB5_CKSUMFLAG_DERIVE)) {
607c478bd9Sstevel@tonic-gate 	    c++;
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate     }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate     *count = c;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate     if ((*cksumtypes = (krb5_cksumtype *) malloc(c*sizeof(krb5_cksumtype)))
677c478bd9Sstevel@tonic-gate 	== NULL)
687c478bd9Sstevel@tonic-gate 	return(ENOMEM);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate     c = 0;
717c478bd9Sstevel@tonic-gate     for (i=0; i<krb5_cksumtypes_length; i++) {
727c478bd9Sstevel@tonic-gate 	if ((krb5_cksumtypes_list[i].keyhash &&
737c478bd9Sstevel@tonic-gate 	     etype_match(krb5_cksumtypes_list[i].keyed_etype, enctype)) ||
747c478bd9Sstevel@tonic-gate 	    (krb5_cksumtypes_list[i].flags & KRB5_CKSUMFLAG_DERIVE)) {
757c478bd9Sstevel@tonic-gate 	    (*cksumtypes)[c] = krb5_cksumtypes_list[i].ctype;
767c478bd9Sstevel@tonic-gate 	    c++;
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate     }
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate     return(0);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*ARGSUSED*/
84505d05c7Sgtb void KRB5_CALLCONV
krb5_free_cksumtypes(krb5_context context,krb5_cksumtype * val)85505d05c7Sgtb krb5_free_cksumtypes(krb5_context context, krb5_cksumtype *val)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate     if (val)
887c478bd9Sstevel@tonic-gate 	krb5_xfree(val);
897c478bd9Sstevel@tonic-gate     return;
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate 
92