1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * Copyright (C) 1998 by the FundsXpress, INC.
7 * Export of this software from the United States of America may require
8 * a specific license from the United States Government. It is the
9 * responsibility of any person or organization contemplating export to
10 * obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of FundsXpress. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. FundsXpress makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 #include "crypto_int.h"
30 krb5_error_code KRB5_CALLCONV
31 krb5_c_string_to_key(krb5_context context, krb5_enctype enctype,
32 const krb5_data *string, const krb5_data *salt,
35 return krb5_c_string_to_key_with_params(context, enctype, string, salt,
39 krb5_error_code KRB5_CALLCONV
40 krb5_c_string_to_key_with_params(krb5_context context, krb5_enctype enctype,
41 const krb5_data *string,
42 const krb5_data *salt,
43 const krb5_data *params, krb5_keyblock *key)
46 krb5_data empty = empty_data();
47 const struct krb5_keytypes *ktp;
50 ktp = find_enctype(enctype);
52 return KRB5_BAD_ENCTYPE;
53 keylength = ktp->enc->keylength;
55 /* For compatibility with past behavior, treat a null salt as empty. */
59 /* Fail gracefully if someone is using the old AFS string-to-key hack. */
60 if (salt->length == SALT_TYPE_AFS_LENGTH)
63 key->contents = malloc(keylength);
64 if (key->contents == NULL)
67 key->magic = KV5M_KEYBLOCK;
68 key->enctype = enctype;
69 key->length = keylength;
71 ret = (*ktp->str2key)(ktp, string, salt, params, key);
73 zapfree(key->contents, keylength);