xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/crypto/default_state.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
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  * or implied warranty.
30  *
31  * Section 6 (Encryption) of the Kerberos revisions document defines
32  * cipher states to be used to chain encryptions and decryptions
33  * together.  Examples of cipher states include initialization vectors
34  * for CBC encription.  Most Kerberos encryption systems can share
35  * code for initializing and freeing cipher states.  This file
36  * contains that default code.
37  */
38 
39 #include <k5-int.h>
40 
41 /* ARGSUSED */
42 krb5_error_code krb5int_des_init_state(
43 	krb5_context context, const krb5_keyblock *key,
44 	krb5_keyusage usage, krb5_data *new_state )
45 {
46   new_state->length = 8;
47   new_state->data = (void *) MALLOC(8);
48   if (new_state->data) {
49     (void) memset (new_state->data, 0, new_state->length);
50     /* We need to copy in the key for des-cbc-cr--ick, but that's how it works*/
51     if (key->enctype == ENCTYPE_DES_CBC_CRC) {
52       (void) memcpy (new_state->data, key->contents, new_state->length);
53     }
54   } else {
55     return ENOMEM;
56   }
57   return 0;
58 }
59 
60 /* ARGSUSED */
61 krb5_error_code krb5int_default_free_state(
62 	krb5_context context, krb5_data *state)
63 {
64   if (state->data) {
65     FREE (state->data, state->length);
66     state-> data = NULL;
67     state->length = 0;
68   }
69   return 0;
70 }
71 
72