1 /* 2 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 #pragma ident "%Z%%M% %I% %E% SMI" 6 7 /* 8 * lib/crypto/state.c 9 * 10 * Copyright (C) 2001 by the Massachusetts Institute of Technology. 11 * All rights reserved. 12 * 13 * Export of this software from the United States of America may 14 * require a specific license from the United States Government. 15 * It is the responsibility of any person or organization contemplating 16 * export to obtain such a license before exporting. 17 * 18 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 19 * distribute this software and its documentation for any purpose and 20 * without fee is hereby granted, provided that the above copyright 21 * notice appear in all copies and that both that copyright notice and 22 * this permission notice appear in supporting documentation, and that 23 * the name of M.I.T. not be used in advertising or publicity pertaining 24 * to distribution of the software without specific, written prior 25 * permission. Furthermore if you modify this software you must label 26 * your software as modified software and not distribute it in such a 27 * fashion that it might be confused with the original M.I.T. software. 28 * M.I.T. makes no representations about the suitability of 29 * this software for any purpose. It is provided "as is" without express 30 31 * 32 * 33 * 34 * * Section 6 (Encryption) of the Kerberos revisions document defines 35 * cipher states to be used to chain encryptions and decryptions 36 * together. Examples of cipher states include initialization vectors 37 * for CBC encription. This file contains implementations of 38 * krb5_c_init_state and krb5_c_free_state used by clients of the 39 * Kerberos crypto library. 40 */ 41 #include <k5-int.h> 42 #include <etypes.h> 43 44 krb5_error_code KRB5_CALLCONV 45 krb5_c_init_state (krb5_context context, const krb5_keyblock *key, 46 krb5_keyusage keyusage, krb5_data *new_state) 47 { 48 int i; 49 50 for (i=0; i<krb5_enctypes_length; i++) { 51 if (krb5_enctypes_list[i].etype == key->enctype) 52 break; 53 } 54 55 if (i == krb5_enctypes_length) 56 return(KRB5_BAD_ENCTYPE); 57 58 return (*(krb5_enctypes_list[i].enc->init_state)) 59 (context, key, keyusage, new_state); 60 } 61 62 krb5_error_code KRB5_CALLCONV 63 krb5_c_free_state (krb5_context context, const krb5_keyblock *key, 64 krb5_data *state) 65 { 66 int i; 67 68 for (i=0; i<krb5_enctypes_length; i++) { 69 if (krb5_enctypes_list[i].etype == key->enctype) 70 break; 71 } 72 73 if (i == krb5_enctypes_length) 74 return(KRB5_BAD_ENCTYPE); 75 76 return (*(krb5_enctypes_list[i].enc->free_state)) 77 (context, state); 78 } 79