Padding Standards
Block ciphers in ECB and CBC modes operate only on whole blocks (16 bytes for AES/SEED/ARIA/Camellia/SM4, 8 bytes for DES/TDES). When the plaintext length is not an exact multiple of the block size—or when the padding scheme requires unambiguous removal—padding bytes are appended to reach a block boundary. In NodeCrypto, symmetric Encrypt/Decrypt nodes and the standalone Block Padding and Block Unpadding nodes share the same padding standard names.
| Standard | Block Size | When Input Is Already Block-Aligned | Unpad (Reversible) |
|---|---|---|---|
| None | Input length must already be a multiple of the block size | Used as-is (throws an error if unaligned) | Supported (no-op) |
| ISO 9797-1 M1 | Any block size | Adds nothing (0 bytes added) | Not supported |
| ISO 9797-1 M2 | Any block size | Appends a full padding block (80 00 … 00) | Supported |
| ISO 9797-1 M3 | Any block size (length block uses the same byte width as the block size) | Prepends a full length block and applies Method 1 | Supported |
| PKCS#5/7 | PKCS#5 is defined for 8-byte (DES) blocks; PKCS#7 generalizes the identical algorithm to 1–255 byte blocks | Appends a full padding block | Supported |
| NIST 800-38B | Any block size | Adds nothing (0 bytes added) | Not supported |
| ANSI X9.23 | Any block size (1–255 bytes) | Appends a full padding block | Supported |
Padding methods that do not support unpadding (Zero and NIST80038B) cannot distinguish trailing data bytes from padding bytes when the original input was already block-aligned. Consequently, they are omitted from symmetric Decrypt nodes and the Block Unpadding node.
None (No Padding)
Applies no padding bytes. In block modes (ECB and CBC), if the input length is not an exact multiple of the cipher's block size, execution fails with PLAINTEXT_NOT_BLOCK_ALIGNED (or CIPHERTEXT_NOT_BLOCK_ALIGNED). Use None when your data is already block-aligned, when using stream/AEAD modes (CTR, GCM, CCM, CFB, OFB), or when you apply padding manually with an upstream Block Padding node.
ISO/IEC 9797-1 Method 1 (Zero Padding)
Appends 0x00 bytes to the end of the data until it reaches a block boundary. If the input length is already a multiple of the block size (and non-empty), no bytes are added.
0x00 from padding bytes, it is fundamentally non-reversible and is not offered in Decrypt or Block Unpadding nodes.ISO/IEC 9797-1 Method 2 (ISO/IEC 7816-4)
Appends a mandatory 0x80 delimiter byte (a single 1 bit followed by seven 0 bits) and then fills the remainder of the block with 0x00 bytes. Even when the input is already block-aligned, a full new block starting with 0x80 is appended, making unpadding completely unambiguous by scanning backward for the last 0x80 byte.
ISO/IEC 9797-1 Method 3
Prepends a full block containing the original message bit length encoded as a big-endian unsigned integer, and then pads the trailing message block with 0x00 bytes (Method 1). During unpadding, the leading length block is read to recover the exact byte length of the original message.
PKCS#5 (8-Byte Block) / PKCS#7 (Arbitrary Block)
Appends N padding bytes (where 1 ≤ N ≤ blockSize), with every added byte set to the value N. If the input length is already a multiple of the block size, a full block of blockSize bytes (each equal to blockSize, e.g. sixteen 0x10 bytes for AES) is appended. During unpadding, the last byte specifies how many trailing bytes to strip and verify.
NIST SP 800-38B
Padding function defined for CMAC block preparation. Like ISO/IEC 9797-1 Method 2, it appends 0x80 followed by 0x00 bytes when the data is not block-aligned. Unlike Method 2, if the data is already a non-empty multiple of the block size, it appends nothing.
80 00 … cannot be distinguished from a padded shorter plaintext. Therefore, NIST SP 800-38B padding cannot be unpadded and is available only for encryption/padding.ANSI X9.23
Fills all padding bytes except the final byte with 0x00, and writes the padding length N (1 ≤ N ≤ blockSize) into the very last byte. Like PKCS#7, it always appends a full padding block when the input is already block-aligned.