return;
}
+void cipher_ctr_step(BlockCipher *c, void *block)
+{
+ memcpy(block, c->buf, c->block_len);
+ c->enc_block(c, block);
+ ctr_increment(c->buf, c->block_len);
+}
+
void cipher_ctr_encrypt(BlockCipher *c, void *block)
{
uint8_t temp[c->block_len];
- memcpy(temp, c->buf, c->block_len);
- c->enc_block(c, temp);
+ cipher_ctr_step(c, temp);
xor_block(block, block, temp, c->block_len);
PURGE(temp);
- ctr_increment(c->buf, c->block_len);
}
void cipher_ctr_decrypt(BlockCipher *c, void *block)
}
/**
- * Encrypt a block (in-place) using the current key in CBC mode.
+ * Encrypt a block (in-place) using the current key in CTR mode.
*/
void cipher_ctr_encrypt(BlockCipher *c, void *block);
/**
- * Decrypt a block (in-place) using the current key in CBC mode.
+ * Decrypt a block (in-place) using the current key in CTR mode.
*/
void cipher_ctr_decrypt(BlockCipher *c, void *block);
+/**
+ * Generate the crypted stream block in CTR mode for the current
+ * counter, and then bump it.
+ *
+ * This function is basically the core CTR operation, without the final
+ * XOR pass with the plaintext or ciphertext. For normal CTR usage,
+ * you never need to call it.
+ */
+void cipher_ctr_step(BlockCipher *c, void *block);
+
#endif /* SEC_CIPHER_H */