diff options
author | Sam Hartman <hartmans@mit.edu> | 2008-12-01 16:44:21 +0000 |
---|---|---|
committer | Sam Hartman <hartmans@mit.edu> | 2008-12-01 16:44:21 +0000 |
commit | ce3096bed2784699499e0bc944a8f4ad08c0d199 (patch) | |
tree | 9862d67e8454302dff5d20f7a3f745c0f6f06b80 | |
parent | 6825e547791ed41a16bc29de99f862d091e3b50d (diff) | |
download | krb5-ce3096bed2784699499e0bc944a8f4ad08c0d199.zip krb5-ce3096bed2784699499e0bc944a8f4ad08c0d199.tar.gz krb5-ce3096bed2784699499e0bc944a8f4ad08c0d199.tar.bz2 |
Only a single padding buffer is required
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/mskrb-integ-crypto-iov@21247 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r-- | src/lib/crypto/dk/dk_aead.c | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/src/lib/crypto/dk/dk_aead.c b/src/lib/crypto/dk/dk_aead.c index e5aca0b..3280c5d 100644 --- a/src/lib/crypto/dk/dk_aead.c +++ b/src/lib/crypto/dk/dk_aead.c @@ -70,12 +70,13 @@ krb5int_dk_encrypt_iov(const struct krb5_aead_provider *aead, krb5_error_code ret; unsigned char constantdata[K5CLENGTH]; krb5_data d1, d2; - krb5_crypto_iov *header, *trailer; + krb5_crypto_iov *header, *trailer, *padding; krb5_keyblock ke, ki; size_t i; size_t blocksize = 0; size_t plainlen = 0; size_t hmacsize = 0; + size_t padsize = 0; unsigned char *cksum = NULL; ke.contents = ki.contents = NULL; @@ -94,27 +95,19 @@ krb5int_dk_encrypt_iov(const struct krb5_aead_provider *aead, for (i = 0; i < num_data; i++) { krb5_crypto_iov *iov = &data[i]; - if (!ENCRYPT_DATA_IOV(iov)) /* DATA | PADDING */ - continue; - - if (iov->flags == KRB5_CRYPTO_TYPE_PADDING) { - size_t padlen = 0; - - if (i > 0 && blocksize != 0) { - const krb5_crypto_iov *data_to_pad = &data[i - 1]; - - padlen = blocksize - (data_to_pad->data.length % blocksize); + if (iov->flags == KRB5_CRYPTO_TYPE_DATA) + plainlen += iov->data.length; + } - if (iov->data.length < padlen) - return KRB5_BAD_MSIZE; - } + /* Validate header and trailer lengths. */ - memset(iov->data.data, 0, padlen); - iov->data.length = padlen; - } + header = krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_HEADER); + if (header == NULL || header->data.length < enc->block_size) + return KRB5_BAD_MSIZE; - plainlen += iov->data.length; - } + trailer = krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_TRAILER); + if (trailer == NULL || trailer->data.length < hmacsize) + return KRB5_BAD_MSIZE; if (blocksize == 0) { /* Check for correct input length in CTS mode */ @@ -122,19 +115,17 @@ krb5int_dk_encrypt_iov(const struct krb5_aead_provider *aead, return KRB5_BAD_MSIZE; } else { /* Check that the input data is correctly padded */ - if (plainlen % blocksize != 0) - return KRB5_BAD_MSIZE; + padsize = blocksize - (plainlen % blocksize); } - /* Validate header and trailer lengths. */ - - header = krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_HEADER); - if (header == NULL || header->data.length < enc->block_size) + padding = krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_PADDING); + if (padsize && (padding == NULL || padding->data.length < padsize)) return KRB5_BAD_MSIZE; - trailer = krb5int_c_locate_iov(data, num_data, KRB5_CRYPTO_TYPE_TRAILER); - if (trailer == NULL || trailer->data.length < hmacsize) - return KRB5_BAD_MSIZE; + if (padding != NULL) { + memset(padding->data.data, 0, padsize); + padding->data.length = padsize; + } ke.length = enc->keylength; ke.contents = malloc(ke.length); |