NodeCrypto Help

Block Cipher Modes of Operation

A primitive block cipher permutes only a single fixed-size block (16 bytes for AES/SEED/ARIA/Camellia/SM4, 8 bytes for DES/TDES). To securely encrypt arbitrary-length messages, a mode of operation defines how blocks are chained, turned into a keystream, or combined with authentication tags. Symmetric cipher nodes in NodeCrypto expose a Cipher Mode parameter and dynamically show only the input/output ports required by the selected mode.

ModeCategoryStandardAdditional Ports
ECBIndependent BlockNIST SP 800-38A §6.1—
CBCBlock ChainingNIST SP 800-38A §6.2IV
GCMAEADNIST SP 800-38DNonce, AAD (optional), Auth Tag
CCMAEADNIST SP 800-38CNonce, AAD (optional), Auth Tag
CTRStream (Counter)NIST SP 800-38A §6.5IV
CFBStream (Feedback)NIST SP 800-38A §6.3IV
OFBStream (Feedback)NIST SP 800-38A §6.4IV
XTSDisk / Sector EncryptionIEEE 1619-2007 / NIST SP 800-38EIV (Tweak)
KWKey WrappingNIST SP 800-38F / RFC 3394—

Deterministic Default IV / Nonce: If an optional IV or Nonce port is left unconnected, NodeCrypto does not generate a random value; instead, it deterministically supplies an all-zero byte array of the required length (16 bytes for CBC/CTR/CFB/OFB/XTS on 128-bit block ciphers, 8 bytes on DES/TDES, and 12 bytes for GCM/CCM). This guarantees reproducible execution for test vectors and protocol debugging, but in production protocols you must always supply a unique nonce or unpredictable IV.

ECB (Electronic Codebook)

Standard: NIST SP 800-38A §6.1
Additional Ports in NodeCrypto: None (Key and Plaintext/Ciphertext only)
Block-Aligned / Padding No IV

Encrypts each plaintext block independently under the same key. No chaining state, initialization vector, or counter is carried between blocks. Requires the input length to be a multiple of the block size (or a Padding mode other than None).

Security Warning: Identical plaintext blocks always produce identical ciphertext blocks, leaking visual and structural patterns in multi-block data (famously illustrated by the "ECB penguin"). Use ECB only for single-block primitives, building custom constructions, or verifying raw block-cipher test vectors.
PlaintextBlock CipherEncryptKeyCiphertextPlaintextBlock CipherEncryptKeyCiphertextEach block encrypted independently (no chaining between blocks)
PlaintextBlock CipherEncryptKeyCiphertextPlaintextBlock CipherEncryptKeyCiphertextEach block encrypted independently (no chaining between blocks)

CBC (Cipher Block Chaining)

Standard: NIST SP 800-38A §6.2
Additional Ports in NodeCrypto: IV (16 bytes for 128-bit block ciphers; 8 bytes for DES/TDES)
Block-Aligned / Padding Requires 16B/8B IV

XORs each plaintext block with the preceding ciphertext block (or with the Initialization Vector IV for the first block) before applying the block cipher encryption function. Because each block depends on all prior blocks, identical plaintext blocks encrypt to different ciphertext blocks. Requires block alignment or a reversible Padding scheme such as PKCS7.

Security Warning: The IV must be unpredictable (random) for every message encrypted under the same key, and CBC alone does not protect against ciphertext tampering (padding oracle attacks). Prefer an AEAD mode (GCM) or pair CBC with an Encrypt-then-MAC (HMAC) construction.
PlaintextBlock CipherEncryptKeyCiphertextPlaintextBlock CipherEncryptKeyCiphertextIVPrevious ciphertext block XORed into next plaintext block
PlaintextBlock CipherEncryptKeyCiphertextPlaintextBlock CipherEncryptKeyCiphertextIVPrevious ciphertext block XORed into next plaintext block

GCM (Galois/Counter Mode)

Standard: NIST SP 800-38D
Additional Ports in NodeCrypto: Nonce (12B), AAD (optional), Auth Tag (16B output on Encrypt / required input on Decrypt)
AEAD (Confidentiality + Integrity) 12B Nonce · 16B Auth Tag

An Authenticated Encryption with Associated Data (AEAD) mode that combines Counter (CTR) mode encryption with a universal hash function (GHASH) over GF(2128). Provides both confidentiality and integrity in a single operation. No block padding is needed; ciphertext length equals plaintext length, and a separate 16-byte Auth Tag is produced. During decryption, if the supplied Auth Tag does not match the computed tag over AAD and Ciphertext, the node fails immediately with AUTH_TAG_MISMATCH and emits no plaintext.

Catastrophic Nonce Reuse Warning: Never reuse the same 12-byte Nonce with the same key in GCM mode. A single nonce collision leaks the XOR of plaintexts and allows an attacker to recover the GHASH authentication key and forge arbitrary tags.
Counter 0Block CipherEncryptKeyPlaintextCiphertextCounter 1Block CipherEncryptKeyPlaintextCiphertextIndependently incremented counter per block (parallelizable, no feedback)Ciphertext + AADGHASHAuth Tag
Counter 0Block CipherEncryptKeyPlaintextCiphertextCounter 1Block CipherEncryptKeyPlaintextCiphertextIndependently incremented counter per block (parallelizable, no feedback)Ciphertext + AADGHASHAuth Tag

CCM (Counter with CBC-MAC)

Standard: NIST SP 800-38C / RFC 3610
Additional Ports in NodeCrypto: Nonce (12B), AAD (optional), Auth Tag (16B)
AEAD (CTR + CBC-MAC) 12B Nonce · 16B Auth Tag

An AEAD mode designed for 128-bit block ciphers (AES, SEED, ARIA) that combines CTR mode encryption with a CBC-MAC authentication tag. Like GCM, it authenticates both the encrypted payload and optional cleartext AAD without requiring block padding, and fails with AUTH_TAG_MISMATCH if verification fails during decryption.

Counter 0Block CipherEncryptKeyPlaintextCiphertextCounter 1Block CipherEncryptKeyPlaintextCiphertextIndependently incremented counter per block (parallelizable, no feedback)Plaintext + AADCBC-MACAuth Tag
Counter 0Block CipherEncryptKeyPlaintextCiphertextCounter 1Block CipherEncryptKeyPlaintextCiphertextIndependently incremented counter per block (parallelizable, no feedback)Plaintext + AADCBC-MACAuth Tag

CTR (Counter Mode)

Standard: NIST SP 800-38A §6.5
Additional Ports in NodeCrypto: IV (16B initial counter block)
Stream Mode (No Padding) Parallelizable

Turns a block cipher into a synchronous stream cipher by encrypting successive values of a 16-byte counter block (initialized from IV) and XORing the resulting keystream with the plaintext. Does not require block padding, allows arbitrary input lengths, and uses the block cipher's encryption function for both encryption and decryption.

Security Warning: Reusing an initial counter (IV) with the same key reuses the keystream, immediately exposing the XOR of the plaintexts. CTR provides no integrity protection on its own (bit-flipping the ciphertext flips the exact same bit in the decrypted plaintext).
Counter 0Block CipherEncryptKeyPlaintextCiphertextCounter 1Block CipherEncryptKeyPlaintextCiphertextIndependently incremented counter per block (parallelizable, no feedback)
Counter 0Block CipherEncryptKeyPlaintextCiphertextCounter 1Block CipherEncryptKeyPlaintextCiphertextIndependently incremented counter per block (parallelizable, no feedback)

CFB (Cipher Feedback)

Standard: NIST SP 800-38A §6.3
Additional Ports in NodeCrypto: IV (16B)
Stream Mode (No Padding) Ciphertext Feedback

A self-synchronizing stream cipher mode that encrypts the previous ciphertext block (starting with IV) using the block cipher and XORs the output with the current plaintext block to produce the next ciphertext block. Does not require block padding.

IVBlock CipherEncryptKeyPlaintextCiphertextBlock CipherEncryptKeyPlaintextCiphertextPrevious ciphertext block fed into next block cipher input
IVBlock CipherEncryptKeyPlaintextCiphertextBlock CipherEncryptKeyPlaintextCiphertextPrevious ciphertext block fed into next block cipher input

OFB (Output Feedback)

Standard: NIST SP 800-38A §6.4
Additional Ports in NodeCrypto: IV (16B)
Stream Mode (No Padding) Keystream Feedback

A synchronous stream cipher mode that repeatedly encrypts the block cipher's own output (starting from IV) to generate a keystream independent of the plaintext and ciphertext, then XORs that keystream with the data. Encryption and decryption are identical operations, and no block padding is required.

IVBlock CipherEncryptKeyPlaintextCiphertextBlock CipherEncryptKeyPlaintextCiphertextPrevious block cipher output fed into next block cipher input
IVBlock CipherEncryptKeyPlaintextCiphertextBlock CipherEncryptKeyPlaintextCiphertextPrevious block cipher output fed into next block cipher input

XTS (XEX-based Tweaked-Codebook Mode with Ciphertext Stealing)

Standard: IEEE Std 1619-2007 / NIST SP 800-38E
Additional Ports in NodeCrypto: IV (16B sector tweak); Double-length Key (32B for AES-128-XTS, 64B for AES-256-XTS)
Sector / Disk Encryption Double-Length Key (K1 || K2)

Specialized mode for encrypting fixed-size storage sectors (such as full-disk encryption). Splits a double-length key into two independent AES keys (K1 || K2): K2 encrypts the 16-byte tweak (supplied via IV), while K1 encrypts the data blocks combined with finite-field powers of the encrypted tweak. Handles non-block-aligned trailing bytes via ciphertext stealing, so no padding is added, but the input must be at least 16 bytes long (otherwise fails with DATA_TOO_SHORT).

PlaintextTweak T0Block CipherEncryptKeyTweak T0CiphertextPlaintextTweak T1Block CipherEncryptKeyTweak T1CiphertextEach block encrypted independently (no chaining between blocks)
PlaintextTweak T0Block CipherEncryptKeyTweak T0CiphertextPlaintextTweak T1Block CipherEncryptKeyTweak T1CiphertextEach block encrypted independently (no chaining between blocks)

KW (AES Key Wrap)

Standard: NIST SP 800-38F / IETF RFC 3394
Additional Ports in NodeCrypto: None (uses RFC 3394 default integrity check value A6A6A6A6A6A6A6A6)
Key Wrapping + 64-bit ICV 8B Semiblock Aligned

Deterministic key-wrapping mode designed to protect cryptographic keys at rest or in transit using another AES Key Encryption Key (KEK). Plaintext key material must be a multiple of 8 bytes (64-bit semiblocks) and at least 16 bytes long. Encrypting appends an 8-byte integrity header (ciphertext is 8 bytes longer than plaintext); decrypting unwraps and verifies the 64-bit integrity check value, failing with AUTH_TAG_MISMATCH if the wrapped key was modified or the wrong KEK was used.

Key Material (n blocks)AES Key Wrap(RFC 3394)KeyWrapped (n+1 blocks)
Key Material (n blocks)AES Key Wrap(RFC 3394)KeyWrapped (n+1 blocks)