ddn.api.crypto.cipher

Cipher API.

Types 4

Operation mode for the cipher.

ENCRYPT
DECRYPT
interfaceCipher

Interface for cryptographic ciphers.

Methods
void init(CipherOperation op, Key key, const(ubyte)[] iv = null)Initializes the cipher with a key and optional IV/nonce. Params: op = The operation mode (encryption or decryption). key = The key to use. iv = The initialization vector or nonce (optional).
ubyte[] update(const(ubyte)[] input)Continues a multiple-part encryption or decryption operation. Params: input = The input buffer. Returns: The new buffer with the result, or empty array if not enough data.
ubyte[] finish(const(ubyte)[] input = null)Finishes a multiple-part encryption or decryption operation. Params: input = Optional final input data. Returns: The final result buffer (may include padding).
interfaceBlockCipher

Interface for block ciphers.

Implementations of this interface provide raw block encryption and decryption primitives. These are typically used within a mode of operation (e.g., CBC, CTR) to form a full Cipher.

Methods
size_t blockSize() @property const @safe pure nothrow @nogcReturns: The block size in bytes.
void encrypt(const(ubyte)[] input, ubyte[] output)Encrypts a single block of data.
void decrypt(const(ubyte)[] input, ubyte[] output)Decrypts a single block of data.

Interface for asymmetric ciphers (e.g., RSA encryption).

API Design

Note

This interface uses bool encrypt instead of CipherOperation

enum (as used by Cipher) for the following reasons:

  • Asymmetric ciphers only support two modes: encrypt or decrypt. The CipherOperation

    enum was designed with potential future expansion for symmetric cipher modes.

  • The key type already implies the operation: public keys encrypt, private keys decrypt.

    The bool parameter serves as an explicit confirmation of intent rather than mode selection.

  • Asymmetric operations are fundamentally different from symmetric streaming operations;

    they process complete messages in one call via process() rather than update()/finish().

For new code requiring a unified interface, consider wrapping with an adapter that accepts CipherOperation and converts to bool internally.

Methods
void init(bool encrypt, Key key)Initializes the cipher with the given key.
ubyte[] process(const(ubyte)[] input)Processes the input data (encrypts or decrypts).