MAC · Built-in Script GF(2^128) Doubling RFC 4493 §2.3 & §4 Verified

CMAC subkey generation

Derives the CMAC subkeys K1 and K2 from an AES key with an AES block and a built-in script node.

Open in app Download .ncw

Overview & Cryptographic Context

In RFC 4493 §2.3 (NIST SP 800-38B), AES-CMAC derives two 128-bit subkeys K1 and K2 from the block cipher key K. First, the cipher encrypts a 128-bit all-zero block L = AESK(0128). Then K1 = L · x and K2 = K1 · x are computed by multiplying by x (left-shifting by 1 bit) in the finite field GF(2128) modulo the irreducible polynomial x128 + x7 + x2 + x + 1 (whose reduction constant is R128 = 0x00…0087).

This workflow demonstrates how to combine standard cryptographic primitives with the deterministic Script node to express custom byte-level finite-field arithmetic and inspect intermediate values (L, K1, K2) directly on the canvas.

Pipeline Architecture & Script Logic

Static Value (Key + Zero block) ──► AES-128-ECB (L = AES(K, 0^128)) ──► Script Node (k1 = dbl(l), k2 = dbl(k1))

The Script node receives the 16-byte ciphertext L on input port l and executes the following built-in script:

def dbl(x: bytes) -> bytes:
    rb = h"00" * (len(x) - 1) + (h"87" if len(x) == 16 else h"1b")
    r = x << 1
    if x[0] & 0x80 != 0:
        r ^= rb
    return r

k1 = dbl(l)
k2 = dbl(k1)

Nodes & Configuration

NodeNode Role & Key ParametersCount
Static ValueTwo instances supplying the 16B AES Key and the 16B Zero block (00...00)2
AES EncryptLabeled AES-128-ECB; encrypts 0128 to produce L = 7df76b0c1ab899b33e42f047b91b546f1
ScriptLabeled CMAC subkeys; computes k1 and k2 via GF(2128) doubling1

Node reference → · Built-in Script language reference →

Inputs, Outputs & Test Vector Verification

Verification Source: RFC 4493 §4 (Subkey Generation: K1, K2)

Static Node Inputs

NameTypeValue (Hex)
Keybytes (16 B)2b7e151628aed2a6abf7158809cf4f3c
Zero blockbytes (16 B)00000000000000000000000000000000

Expected Outputs

Script Output PortTypeValue (Hex)
k1 (K1)bytes (16 B)fbeed618357133667c85e08f7236a8de
k2 (K2)bytes (16 B)f7ddac306ae266ccf90bc11ee46d513b