diff options
author | John Kohl <jtkohl@mit.edu> | 1991-02-22 10:04:10 +0000 |
---|---|---|
committer | John Kohl <jtkohl@mit.edu> | 1991-02-22 10:04:10 +0000 |
commit | 61a93790be124589e4fab07d142c2f6392c74938 (patch) | |
tree | fd1159d1e39ecdc0b54724203c37f8fc3668565c /src/lib/krb5/krb/gen_subkey.c | |
parent | bfc951f3e2aca05623367e5b2350a894e8f332b5 (diff) | |
download | krb5-61a93790be124589e4fab07d142c2f6392c74938.tar.gz krb5-61a93790be124589e4fab07d142c2f6392c74938.tar.xz krb5-61a93790be124589e4fab07d142c2f6392c74938.zip |
*** empty log message ***
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1764 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/krb/gen_subkey.c')
-rw-r--r-- | src/lib/krb5/krb/gen_subkey.c | 53 |
1 files changed, 53 insertions, 0 deletions
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 + * <krb5/copyright.h>. + * + * 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 <krb5/krb5.h> +#include <krb5/ext-proto.h> + +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; +} + |