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