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