2N/A/*
2N/A * COPYRIGHT (c) 2006
2N/A * The Regents of the University of Michigan
2N/A * ALL RIGHTS RESERVED
2N/A *
2N/A * Permission is granted to use, copy, create derivative works
2N/A * and redistribute this software and such derivative works
2N/A * for any purpose, so long as the name of The University of
2N/A * Michigan is not used in any advertising or publicity
2N/A * pertaining to the use of distribution of this software
2N/A * without specific, written prior authorization. If the
2N/A * above copyright notice or any other identification of the
2N/A * University of Michigan is included in any copy of any
2N/A * portion of this software, then the disclaimer below must
2N/A * also be included.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
2N/A * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
2N/A * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
2N/A * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
2N/A * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
2N/A * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
2N/A * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
2N/A * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
2N/A * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
2N/A * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
2N/A * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
2N/A * SUCH DAMAGES.
2N/A */
2N/A
2N/A
2N/A/*
2N/A * Create a key given random data. It is assumed that random_key has
2N/A * already been initialized and random_key->contents have been allocated
2N/A * with the correct length.
2N/A */
2N/A#include "k5-int.h"
2N/A#include "etypes.h"
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_c_random_to_key(krb5_context context, krb5_enctype enctype,
2N/A krb5_data *random_data, krb5_keyblock *random_key)
2N/A{
2N/A int i;
2N/A krb5_error_code ret;
2N/A const struct krb5_enc_provider *enc;
2N/A
2N/A if (random_data == NULL || random_key == NULL)
2N/A return(EINVAL);
2N/A
2N/A if (random_key->contents == NULL)
2N/A return(EINVAL);
2N/A
2N/A for (i=0; i<krb5_enctypes_length; i++) {
2N/A if (krb5_enctypes_list[i].etype == enctype)
2N/A break;
2N/A }
2N/A
2N/A if (i == krb5_enctypes_length)
2N/A return(KRB5_BAD_ENCTYPE);
2N/A
2N/A enc = krb5_enctypes_list[i].enc;
2N/A
2N/A if (random_key->length != enc->keylength)
2N/A return(KRB5_BAD_KEYSIZE);
2N/A
2N/A /* Solaris Kerberos */
2N/A ret = ((*(enc->make_key))(context, random_data, random_key));
2N/A
2N/A if (ret) {
2N/A memset(random_key->contents, 0, random_key->length);
2N/A }
2N/A
2N/A return(ret);
2N/A}