ddn.crypto.legacy.cipher.modes

Legacy Cipher Modes (CFB).

WARNING: DEPRECATED MODE

CFB mode is rarely used in modern cryptography. Prefer authenticated encryption modes like GCM or ChaCha20-Poly1305 for new encryption.

Standards

NIST SP 800-38A
class CFB

Types 4

classCFB(Cipher : BlockCipher, size_t segmentBits = 0)

Cipher Feedback (CFB) Mode with configurable segment size.

WARNING: DEPRECATED MODE

CFB mode is a stream cipher mode that converts a block cipher into a self-synchronizing stream cipher. It is provided for legacy compatibility, particularly for ODF 1.0/1.1 which uses CFB-8.

The segment size determines how many bits are processed at a time:

  • CFB-8: Processes 1 byte at a time (required for ODF 1.0/1.1)
  • CFB-64: Processes 8 bytes at a time (for 64-bit block ciphers like DES)
  • CFB-128: Processes 16 bytes at a time (full block for AES)

Parameters

CipherThe block cipher implementation (e.g., AES, DES).
segmentBitsSegment size in bits. Default (0) uses the cipher's block size.

Standards

NIST SP 800-38A, Section 6.3

Example:

import ddn.crypto.cipher.aes : AES;

auto cfb = new CFB!AES(new AES(key), iv);
ubyte[] ciphertext = cfb.encrypt(plaintext);

cfb.reset(iv);
ubyte[] decrypted = cfb.decrypt(ciphertext);

Fields
private Cipher _cipher
private ubyte[] _shiftRegister
private size_t _blockSize
private size_t _segmentBytes
Methods
ubyte[] encrypt(const(ubyte)[] input)Encrypts data using CFB mode.
ubyte[] decrypt(const(ubyte)[] input)Decrypts data using CFB mode.
void reset(const(ubyte)[] iv)Resets the cipher with a new IV.
private void shiftIn(const(ubyte)[] data)Shift the register left by segmentBytes, inserting new data on the right.
Constructors
this(Cipher cipher, const(ubyte)[] iv)Constructs a CFB mode cipher.

CFB-8 mode (8-bit feedback) - required for ODF 1.0/1.1 compatibility.

CFB-64 mode (64-bit feedback) - suitable for 64-bit block ciphers like DES.

CFB-128 mode (128-bit feedback) - full block mode for AES.