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/crypto_length.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/crypto_length.c')
-rw-r--r-- | src/lib/crypto/krb/crypto_length.c | 73 |
1 files changed, 24 insertions, 49 deletions
diff --git a/src/lib/crypto/krb/crypto_length.c b/src/lib/crypto/krb/crypto_length.c index d99d18b..23e8c1c 100644 --- a/src/lib/crypto/krb/crypto_length.c +++ b/src/lib/crypto/krb/crypto_length.c @@ -29,25 +29,15 @@ #include "aead.h" krb5_error_code KRB5_CALLCONV -krb5_c_crypto_length(krb5_context context, - krb5_enctype enctype, - krb5_cryptotype type, - unsigned int *size) +krb5_c_crypto_length(krb5_context context, krb5_enctype enctype, + krb5_cryptotype type, unsigned int *size) { - int i; - const struct krb5_keytypes *ktp = NULL; + const struct krb5_keytypes *ktp; krb5_error_code ret; - for (i = 0; i < krb5_enctypes_length; i++) { - if (krb5_enctypes_list[i].etype == enctype) { - ktp = &krb5_enctypes_list[i]; - break; - } - } - - if (ktp == NULL || ktp->aead == NULL) { + ktp = find_enctype(enctype); + if (ktp == NULL || ktp->aead == NULL) return KRB5_BAD_ENCTYPE; - } switch (type) { case KRB5_CRYPTO_TYPE_EMPTY: @@ -63,7 +53,8 @@ krb5_c_crypto_length(krb5_context context, case KRB5_CRYPTO_TYPE_PADDING: case KRB5_CRYPTO_TYPE_TRAILER: case KRB5_CRYPTO_TYPE_CHECKSUM: - ret = ktp->aead->crypto_length(ktp->aead, ktp->enc, ktp->hash, type, size); + ret = (*ktp->aead->crypto_length)(ktp->aead, ktp->enc, ktp->hash, + type, size); break; default: ret = EINVAL; @@ -74,55 +65,37 @@ krb5_c_crypto_length(krb5_context context, } krb5_error_code KRB5_CALLCONV -krb5_c_padding_length(krb5_context context, - krb5_enctype enctype, - size_t data_length, - unsigned int *pad_length) +krb5_c_padding_length(krb5_context context, krb5_enctype enctype, + size_t data_length, unsigned int *pad_length) { - int i; - const struct krb5_keytypes *ktp = NULL; + const struct krb5_keytypes *ktp; - for (i = 0; i < krb5_enctypes_length; i++) { - if (krb5_enctypes_list[i].etype == enctype) { - ktp = &krb5_enctypes_list[i]; - break; - } - } - - if (ktp == NULL || ktp->aead == NULL) { + ktp = find_enctype(enctype); + if (ktp == NULL || ktp->aead == NULL) return KRB5_BAD_ENCTYPE; - } - return krb5int_c_padding_length(ktp->aead, ktp->enc, ktp->hash, data_length, pad_length); + return krb5int_c_padding_length(ktp->aead, ktp->enc, ktp->hash, + data_length, pad_length); } krb5_error_code KRB5_CALLCONV -krb5_c_crypto_length_iov(krb5_context context, - krb5_enctype enctype, - krb5_crypto_iov *data, - size_t num_data) +krb5_c_crypto_length_iov(krb5_context context, krb5_enctype enctype, + krb5_crypto_iov *data, size_t num_data) { krb5_error_code ret = 0; size_t i; - const struct krb5_keytypes *ktp = NULL; + const struct krb5_keytypes *ktp; unsigned int data_length = 0, pad_length; krb5_crypto_iov *padding = NULL; /* * XXX need to rejig internal interface so we can accurately - * report variable header lengths + * report variable header lengths. */ - for (i = 0; i < (size_t)krb5_enctypes_length; i++) { - if (krb5_enctypes_list[i].etype == enctype) { - ktp = &krb5_enctypes_list[i]; - break; - } - } - - if (ktp == NULL || ktp->aead == NULL) { + ktp = find_enctype(enctype); + if (ktp == NULL || ktp->aead == NULL) return KRB5_BAD_ENCTYPE; - } for (i = 0; i < num_data; i++) { krb5_crypto_iov *iov = &data[i]; @@ -140,7 +113,8 @@ krb5_c_crypto_length_iov(krb5_context context, case KRB5_CRYPTO_TYPE_HEADER: case KRB5_CRYPTO_TYPE_TRAILER: case KRB5_CRYPTO_TYPE_CHECKSUM: - ret = ktp->aead->crypto_length(ktp->aead, ktp->enc, ktp->hash, iov->flags, &iov->data.length); + ret = (*ktp->aead->crypto_length)(ktp->aead, ktp->enc, ktp->hash, + iov->flags, &iov->data.length); break; case KRB5_CRYPTO_TYPE_EMPTY: case KRB5_CRYPTO_TYPE_SIGN_ONLY: @@ -155,7 +129,8 @@ krb5_c_crypto_length_iov(krb5_context context, if (ret != 0) return ret; - ret = krb5int_c_padding_length(ktp->aead, ktp->enc, ktp->hash, data_length, &pad_length); + ret = krb5int_c_padding_length(ktp->aead, ktp->enc, ktp->hash, + data_length, &pad_length); if (ret != 0) return ret; |