summaryrefslogtreecommitdiff
path: root/lib/crypto
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
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')
-rw-r--r--lib/crypto/aes.c35
-rw-r--r--lib/crypto/aes.h10
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
}