summaryrefslogtreecommitdiff
path: root/lib/crypto/aes.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2015-08-12 12:58:49 +0200
committerJeremy Allison <jra@samba.org>2015-08-27 20:23:20 +0200
commitaaad9e9618686066ed24fef43cb3872fb9861678 (patch)
tree3e6ce2e6deb4e2bff196c47c476a0b76ee1fb74a /lib/crypto/aes.c
parente9d3379d72f5698d579842d2f1aafa4fd0dde56f (diff)
downloadsamba-aaad9e9618686066ed24fef43cb3872fb9861678.tar.gz
lib/crypto: sync AES_cfb8_encrypt() from heimdal
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11451 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/crypto/aes.c')
-rw-r--r--lib/crypto/aes.c35
1 files changed, 18 insertions, 17 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);
+ }
}