ddn.crypto.legacy.cipher.des

DES Block Cipher (FIPS 46-3).

WARNING: DEPRECATED ALGORITHM

DES is cryptographically broken due to its 56-bit key size, which is vulnerable to brute-force attacks. It is provided only for backward compatibility with legacy systems that require it, primarily as a building block for Triple DES (3DES).

Do NOT use DES for new encryption. Use AES-256 instead.

Standards

FIPS 46-3 (withdrawn 2005), NIST SP 800-67
class DES

Types 1

DES block cipher implementation (FIPS 46-3).

DEPRECATED: Do not use for new encryption.

DES encrypts 64-bit blocks using a 56-bit key (stored in 8 bytes with parity bits). This implementation is provided for legacy compatibility, primarily as a building block for Triple DES.

Example:

auto des = new DES(key);  // 8-byte key
ubyte[8] ciphertext;
des.encrypt(plaintext, ciphertext);

Fields
private ulong[16] _subkeys
private ubyte[64] IP_TABLEInitial Permutation (IP)
private ubyte[64] FP_TABLEFinal Permutation (IP^-1)
private ubyte[48] E_TABLEExpansion permutation (E)
private ubyte[32] P_TABLEP-box permutation
private ubyte[56] PC1_TABLEPermuted Choice 1 (PC-1)
private ubyte[48] PC2_TABLEPermuted Choice 2 (PC-2)
private ubyte[16] ROTATION_SCHEDULEKey schedule rotation amounts
private ubyte[64][8] S_BOXESS-boxes (8 boxes, each 4 rows × 16 columns)
Methods
size_t blockSize() @property const @safe pure nothrow @nogcReturns: The block size in bytes (always 8 for DES).
void encrypt(const(ubyte)[] input, ubyte[] output)Encrypts a single 8-byte block.
void decrypt(const(ubyte)[] input, ubyte[] output)Decrypts a single 8-byte block.
private ulong processBlock(ulong block, bool decrypt)Process a 64-bit block through the DES Feistel network.
private void generateSubkeys(const(ubyte)[] key)Generate 16 48-bit subkeys from the 64-bit key.
private uint feistel(uint right, ulong subkey) staticThe Feistel function f(R, K).
private ulong expansion(uint right) staticExpansion permutation E: 32 bits -> 48 bits.
private uint sboxSubstitution(ulong input) staticS-box substitution: 48 bits -> 32 bits.
private uint pboxPermutation(uint input) staticP-box permutation.
private ulong initialPermutation(ulong block) staticInitial permutation IP.
private ulong finalPermutation(ulong block) staticFinal permutation IP^-1.
private ulong permutedChoice1(ulong key) staticPermuted Choice 1 (PC-1): 64 bits -> 56 bits.
private ulong permutedChoice2(ulong combined) staticPermuted Choice 2 (PC-2): 56 bits -> 48 bits.
private uint leftRotate28(uint value, int count) staticLeft rotate a 28-bit value.
private ulong bytesToUlong(const(ubyte)[] bytes) staticConvert 8 bytes to a 64-bit unsigned integer (big-endian).
private void ulongToBytes(ulong value, ubyte[] bytes) staticConvert a 64-bit unsigned integer to 8 bytes (big-endian).
Constructors
this(const(ubyte)[] key)Constructs a DES cipher with the given key.