Skip to content

Commit

Permalink
lib/crypto: sync AES_cfb8_encrypt() from heimdal
Browse files Browse the repository at this point in the history
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11451

Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
metze-samba authored and jrasamba committed Aug 27, 2015
1 parent e9d3379 commit aaad9e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
35 changes: 18 additions & 17 deletions lib/crypto/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 7 additions & 3 deletions lib/crypto/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
*
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit aaad9e9

Please sign in to comment.