2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/krb/gen_subkey.c
2N/A *
2N/A * Copyright 1991, 2002 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A *
2N/A *
2N/A * Routine to automatically generate a subsession key based on an input key.
2N/A */
2N/A
2N/A#include "k5-int.h"
2N/A
2N/Astatic inline krb5_data
2N/Akey2data (krb5_keyblock k)
2N/A{
2N/A krb5_data d;
2N/A d.magic = KV5M_DATA;
2N/A d.length = k.length;
2N/A d.data = (char *) k.contents;
2N/A return d;
2N/A}
2N/A
2N/Akrb5_error_code
2N/Akrb5_generate_subkey_extended(krb5_context context,
2N/A const krb5_keyblock *key,
2N/A krb5_enctype enctype,
2N/A krb5_keyblock **subkey)
2N/A{
2N/A krb5_error_code retval;
2N/A /* krb5_data seed; */ /* Solaris Kerberos */
2N/A krb5_keyblock *keyblock;
2N/A
2N/A *subkey = NULL;
2N/A/*
2N/A * Solaris Kerberos: Don't bother with this PRNG stuff,
2N/A * we have /dev/random and PKCS#11 to handle Random Numbers.
2N/A */
2N/A#if 0
2N/A seed = key2data(*key);
2N/A retval = krb5_c_random_add_entropy(context, KRB5_C_RANDSOURCE_TRUSTEDPARTY,
2N/A &seed);
2N/A
2N/A if (retval)
2N/A return retval;
2N/A#endif /* 0 */
2N/A
2N/A keyblock = malloc(sizeof(krb5_keyblock));
2N/A if (!keyblock)
2N/A return ENOMEM;
2N/A
2N/A /* Solaris Kerberos */
2N/A (void) memset(keyblock, 0, sizeof(krb5_keyblock));
2N/A
2N/A retval = krb5_c_make_random_key(context, enctype, keyblock);
2N/A if (retval) {
2N/A free(*subkey);
2N/A return retval;
2N/A }
2N/A
2N/A *subkey = keyblock;
2N/A return 0;
2N/A}
2N/A
2N/Akrb5_error_code
2N/Akrb5_generate_subkey(krb5_context context, const krb5_keyblock *key, krb5_keyblock **subkey)
2N/A{
2N/A return krb5_generate_subkey_extended(context, key, key->enctype, subkey);
2N/A}