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
Copyright
Copyright © 2025, Dejan Lekić
License
BSD-3-Clause
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
Cipher | The block cipher implementation (e.g., AES, DES). |
segmentBits | Segment 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 _cipherprivate ubyte[] _shiftRegisterprivate size_t _blockSizeprivate size_t _segmentBytesMethods
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.aliasCFB8(Cipher : BlockCipher) = CFB!(Cipher, 8)
CFB-8 mode (8-bit feedback) - required for ODF 1.0/1.1 compatibility.
aliasCFB64(Cipher : BlockCipher) = CFB!(Cipher, 64)
CFB-64 mode (64-bit feedback) - suitable for 64-bit block ciphers like DES.
aliasCFB128(Cipher : BlockCipher) = CFB!(Cipher, 128)
CFB-128 mode (128-bit feedback) - full block mode for AES.