SEC: add OFB mode to symmetric ciphers.
authorrasky <rasky@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 4 Oct 2010 18:43:14 +0000 (18:43 +0000)
committerrasky <rasky@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 4 Oct 2010 18:43:14 +0000 (18:43 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4401 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/sec/cipher.c
bertos/sec/cipher.h

index 7977cc4632b83460dbc1cb59da77e5c22dc50773..ba4ae981d6da8298447671086022d77927fac872 100644 (file)
@@ -85,3 +85,19 @@ void cipher_ctr_decrypt(BlockCipher *c, void *block)
 {
        cipher_ctr_encrypt(c, block);
 }
+
+static void ofb_step(BlockCipher *c)
+{
+       c->enc_block(c, c->buf);
+}
+
+void cipher_ofb_encrypt(BlockCipher *c, void *block)
+{
+       ofb_step(c);
+       xor_block(block, block, c->buf, c->block_len);
+}
+
+void cipher_ofb_decrypt(BlockCipher *c, void *block)
+{
+       cipher_ofb_encrypt(c, block);
+}
index 24c24b0da656f1ae6d32f5f666db5155a7811eff..845a32d24a72b890eec5437f6299b6128cfbcfab 100644 (file)
@@ -188,4 +188,32 @@ void cipher_ctr_decrypt(BlockCipher *c, void *block);
  */
 void cipher_ctr_step(BlockCipher *c, void *block);
 
+
+/*********************************************************************************/
+/* OFB mode                                                                      */
+/*********************************************************************************/
+
+/**
+ * Initialize OFB by setting the IV.
+ *
+ * \note the memory pointed by \a iv will be used and modified by the CBC
+ * functions. It is caller's responsibility to keep it available until there is
+ * no more OFB work to do.
+ */
+INLINE void cipher_ofb_begin(BlockCipher *c, void *iv)
+{
+       c->buf = iv;
+}
+
+/**
+ * Encrypt a block (in-place) using the current key in OFB mode.
+ */
+void cipher_ofb_encrypt(BlockCipher *c, void *block);
+
+/**
+ * Decrypt a block (in-place) using the current key in OFB mode.
+ */
+void cipher_ofb_decrypt(BlockCipher *c, void *block);
+
+
 #endif /* SEC_CIPHER_H */