summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/crypto/aes.c22
-rw-r--r--lib/crypto/aes.h4
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c
index 7735e8ff37..a47a456593 100644
--- a/lib/crypto/aes.c
+++ b/lib/crypto/aes.c
@@ -112,3 +112,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)
+{
+ size_t i;
+
+ for (i=0; i < length; i++) {
+ uint8_t tiv[AES_BLOCK_SIZE*2];
+
+ 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);
+ }
+}
diff --git a/lib/crypto/aes.h b/lib/crypto/aes.h
index e74d345215..a2b6c077e6 100644
--- a/lib/crypto/aes.h
+++ b/lib/crypto/aes.h
@@ -72,6 +72,10 @@ 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);
+
#ifdef __cplusplus
}
#endif