lib/crypto: add aes_cfb8_encrypt()
authorStefan Metzmacher <metze@samba.org>
Thu, 17 Sep 2009 23:04:02 +0000 (01:04 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 3 Jan 2011 16:32:07 +0000 (17:32 +0100)
metze

Autobuild-User: Stefan Metzmacher <metze@samba.org>
Autobuild-Date: Mon Jan  3 17:32:07 CET 2011 on sn-devel-104

lib/crypto/aes.c
lib/crypto/aes.h

index 7735e8ff375d9b7042f6c7c5c8c27ac2b81ccb0b..a47a45659332a0c29e5348a5fb8e6777d433e82b 100644 (file)
@@ -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);
+       }
+}
index e74d3452152bbe41428a03d00143d04a6ea65321..a2b6c077e66956748092967bc4e77dab40eb555d 100644 (file)
@@ -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