diff options
author | Greg Hudson <ghudson@mit.edu> | 2009-10-03 16:03:15 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2009-10-03 16:03:15 +0000 |
commit | 8025c33f6285b8773a927351c0b3503d878565f1 (patch) | |
tree | fe8100e32b4efb5b03a88e065d0bcbc88691c303 /src/lib/crypto/krb/string_to_key.c | |
parent | 0faf98575f91452efee9f4c8d100c83fa9971e46 (diff) | |
download | krb5-8025c33f6285b8773a927351c0b3503d878565f1.zip krb5-8025c33f6285b8773a927351c0b3503d878565f1.tar.gz krb5-8025c33f6285b8773a927351c0b3503d878565f1.tar.bz2 |
Update the crypto API glue to conform to most of the current coding
practices (except lack of tabs). Use the helper functions k5alloc,
zapfree, and find_enctype to reduce code size.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22839 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/krb/string_to_key.c')
-rw-r--r-- | src/lib/crypto/krb/string_to_key.c | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/lib/crypto/krb/string_to_key.c b/src/lib/crypto/krb/string_to_key.c index 71d9db6..bf8f8ce 100644 --- a/src/lib/crypto/krb/string_to_key.c +++ b/src/lib/crypto/krb/string_to_key.c @@ -51,23 +51,20 @@ krb5_c_string_to_key_with_params(krb5_context context, krb5_enctype enctype, const krb5_data *salt, const krb5_data *params, krb5_keyblock *key) { - int i; krb5_error_code ret; - const struct krb5_enc_provider *enc; - size_t keybytes, keylength; + const struct krb5_keytypes *ktp; + size_t keylength; - for (i=0; i<krb5_enctypes_length; i++) { - if (krb5_enctypes_list[i].etype == enctype) - break; - } + ktp = find_enctype(enctype); + if (ktp == NULL) + return KRB5_BAD_ENCTYPE; + keylength = ktp->enc->keylength; - if (i == krb5_enctypes_length) - return(KRB5_BAD_ENCTYPE); - - enc = krb5_enctypes_list[i].enc; -/* xxx AFS string2key function is indicated by a special length in - * the salt in much of the code. However only the DES enctypes can - * deal with this. Using s2kparams would be a much better solution.*/ + /* + * xxx AFS string2key function is indicated by a special length in + * the salt in much of the code. However only the DES enctypes can + * deal with this. Using s2kparams would be a much better solution. + */ if (salt && salt->length == SALT_TYPE_AFS_LENGTH) { switch (enctype) { case ENCTYPE_DES_CBC_CRC: @@ -75,27 +72,24 @@ krb5_c_string_to_key_with_params(krb5_context context, krb5_enctype enctype, case ENCTYPE_DES_CBC_MD5: break; default: - return (KRB5_CRYPTO_INTERNAL); + return KRB5_CRYPTO_INTERNAL; } } - keybytes = enc->keybytes; - keylength = enc->keylength; - - if ((key->contents = (krb5_octet *) malloc(keylength)) == NULL) - return(ENOMEM); + key->contents = malloc(keylength); + if (key->contents == NULL) + return ENOMEM; key->magic = KV5M_KEYBLOCK; key->enctype = enctype; key->length = keylength; - ret = (*krb5_enctypes_list[i].str2key)(enc, string, salt, params, key); + ret = (*ktp->str2key)(ktp->enc, string, salt, params, key); if (ret) { - memset(key->contents, 0, keylength); - free(key->contents); + zapfree(key->contents, keylength); key->length = 0; key->contents = NULL; } - return(ret); + return ret; } |