xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/gen_subkey.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
2*7c478bd9Sstevel@tonic-gate /*
3*7c478bd9Sstevel@tonic-gate  * lib/krb5/krb/gen_subkey.c
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * Copyright 1991 by the Massachusetts Institute of Technology.
6*7c478bd9Sstevel@tonic-gate  * All Rights Reserved.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
9*7c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
10*7c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
11*7c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
12*7c478bd9Sstevel@tonic-gate  *
13*7c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14*7c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
15*7c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
16*7c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
17*7c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
18*7c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
19*7c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
20*7c478bd9Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
21*7c478bd9Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
22*7c478bd9Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
23*7c478bd9Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
24*7c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
25*7c478bd9Sstevel@tonic-gate  * or implied warranty.
26*7c478bd9Sstevel@tonic-gate  *
27*7c478bd9Sstevel@tonic-gate  *
28*7c478bd9Sstevel@tonic-gate  * Routine to automatically generate a subsession key based on an input key.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <k5-int.h>
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
34*7c478bd9Sstevel@tonic-gate krb5_error_code
35*7c478bd9Sstevel@tonic-gate krb5_generate_subkey(context, key, subkey)
36*7c478bd9Sstevel@tonic-gate     krb5_context context;
37*7c478bd9Sstevel@tonic-gate     krb5_const krb5_keyblock *key;
38*7c478bd9Sstevel@tonic-gate     krb5_keyblock **subkey;
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate     krb5_error_code retval;
41*7c478bd9Sstevel@tonic-gate     krb5_data seed;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate     seed.length = key->length;
44*7c478bd9Sstevel@tonic-gate     seed.data = (char *)key->contents;
45*7c478bd9Sstevel@tonic-gate     if ((retval = krb5_c_random_seed(context, &seed)))
46*7c478bd9Sstevel@tonic-gate 	return(retval);
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate     if ((*subkey = (krb5_keyblock *) malloc(sizeof(krb5_keyblock))) == NULL)
49*7c478bd9Sstevel@tonic-gate 	return(ENOMEM);
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate     (void) memset(*subkey, 0, sizeof(krb5_keyblock));
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate     if ((retval = krb5_c_make_random_key(context, key->enctype, *subkey))) {
54*7c478bd9Sstevel@tonic-gate 	krb5_xfree(*subkey);
55*7c478bd9Sstevel@tonic-gate 	return(retval);
56*7c478bd9Sstevel@tonic-gate     }
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate     return(0);
59*7c478bd9Sstevel@tonic-gate }
60