From: John Kohl Date: Fri, 22 Feb 1991 10:04:10 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: krb5-1.0-alpha4~208 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=61a93790be124589e4fab07d142c2f6392c74938;p=krb5.git *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1764 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/gen_subkey.c b/src/lib/krb5/krb/gen_subkey.c new file mode 100644 index 000000000..38cba542f --- /dev/null +++ b/src/lib/krb5/krb/gen_subkey.c @@ -0,0 +1,53 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1991 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * For copying and distribution information, please see the file + * . + * + * Routine to automatically generate a subsession key based on an input key. + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_gen_subkey_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include + +krb5_error_code +krb5_generate_subkey(key, subkey) +const krb5_keyblock *key; +krb5_keyblock **subkey; +{ + krb5_pointer random_state; + krb5_encrypt_block eblock; + krb5_error_code retval; + + if (!valid_keytype(key->keytype)) + return KRB5_PROG_KEYTYPE_NOSUPP; + + krb5_use_keytype(&eblock, key->keytype); + + if (retval = krb5_init_random_key(&eblock, key, &random_state)) + return(retval); + *subkey = (krb5_keyblock *)malloc(sizeof(**subkey)); + if (!*subkey) { + (void) krb5_finish_random_key(&eblock, random_state); + return ENOMEM; + } + + if (retval = krb5_random_key(&eblock, random_state, subkey)) { + (void) krb5_finish_random_key(&eblock, random_state); + xfree(*subkey); + return retval; + } + /* ignore the error if any, since we've already gotten the key out */ + (void) krb5_finish_random_key(&eblock, &random_state); + return 0; +} +