From 922732a00151c4c81cd6ae1a8710bb46f24c6985 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 12 Aug 2015 12:58:49 +0200 Subject: lib/crypto: sync AES_cfb8_encrypt() from heimdal BUG: https://bugzilla.samba.org/show_bug.cgi?id=11451 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison (cherry picked from commit aaad9e9618686066ed24fef43cb3872fb9861678) --- lib/crypto/aes.c | 35 ++++++++++++++++++----------------- lib/crypto/aes.h | 10 +++++++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c index a47a4565933..f7f96889c12 100644 --- a/lib/crypto/aes.c +++ b/lib/crypto/aes.c @@ -113,24 +113,25 @@ AES_cbc_encrypt(const unsigned char *in, unsigned char *out, } } -void aes_cfb8_encrypt(const uint8_t *in, uint8_t *out, - size_t length, const AES_KEY *key, - uint8_t *iv, int forward) +void +AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, + unsigned long size, const AES_KEY *key, + unsigned char *iv, int forward_encrypt) { - size_t i; + int i; - for (i=0; i < length; i++) { - uint8_t tiv[AES_BLOCK_SIZE*2]; + for (i = 0; i < size; i++) { + unsigned char tmp[AES_BLOCK_SIZE + 1]; - memcpy(tiv, iv, AES_BLOCK_SIZE); - AES_encrypt(iv, iv, key); - if (!forward) { - tiv[AES_BLOCK_SIZE] = in[i]; - } - out[i] = in[i] ^ iv[0]; - if (forward) { - tiv[AES_BLOCK_SIZE] = out[i]; - } - memcpy(iv, tiv+1, AES_BLOCK_SIZE); - } + memcpy(tmp, iv, AES_BLOCK_SIZE); + AES_encrypt(iv, iv, key); + if (!forward_encrypt) { + tmp[AES_BLOCK_SIZE] = in[i]; + } + out[i] = in[i] ^ iv[0]; + if (forward_encrypt) { + tmp[AES_BLOCK_SIZE] = out[i]; + } + memcpy(iv, &tmp[1], AES_BLOCK_SIZE); + } } diff --git a/lib/crypto/aes.h b/lib/crypto/aes.h index 2cfb58786ec..7487486370a 100644 --- a/lib/crypto/aes.h +++ b/lib/crypto/aes.h @@ -42,6 +42,7 @@ #define AES_encrypt samba_AES_encrypt #define AES_decrypt samba_AES_decrypt #define AES_cbc_encrypt samba_AES_cbc_encrypt +#define AES_cfb8_encrypt samba_AES_cfb8_encrypt /* * @@ -72,9 +73,12 @@ void AES_cbc_encrypt(const unsigned char *, unsigned char *, const unsigned long, const AES_KEY *, unsigned char *, int); -void aes_cfb8_encrypt(const uint8_t *in, uint8_t *out, - size_t length, const AES_KEY *key, - uint8_t *iv, int forward); +void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, + unsigned long size, const AES_KEY *key, + unsigned char *iv, int forward_encrypt); + +#define aes_cfb8_encrypt(in, out, size, key, iv, forward_encrypt) \ + AES_cfb8_encrypt(in, out, size, key, iv, forward_encrypt) #ifdef __cplusplus } -- cgit v1.2.1