Protocol Demo P-256 ECDH → SHA-256 → AES-128-CBC Part 2 of 4 · Client Response

DID Auth: client

Client side of a challenge-response over ECDH: derives the MAC that answers the server's nonce.

For explaining a protocol only. Do not use this in a real service. The keys shown are public demo keys.

Open in app Download .ncw

DID Auth: client

Overview & Cryptographic Context

This workflow is Part 2 of the four-part DID Auth learning suite (Key Pairs → Client → Server → End-to-End Demo). It models the client side of an ECDH challenge-response authentication protocol: the server sends its P-256 public key and a 32-byte challenge Nonce, and the client must prove possession of the private key corresponding to its DID document public key without ever transmitting the private key.

The client computes the P-256 ECDH shared secret Z (raw_x, 32 B), hashes D = SHA-256(Z) (32 B), splits D into a 16-byte AES-128 key (D[0..16]) and a 16-byte IV (D[16..32]), encrypts the 32-byte challenge nonce with AES-128-CBC (Padding = None), and extracts the first 8 bytes of the final 16-byte ciphertext block (offset = -16, length = 8) as an 8-byte response MAC.

Pipeline Architecture & Wiring Flow

ECDH (P-256) ──► SHA-256 (32B) ──► Byte Slicer (Key 16B / IV 16B) ──► AES-128-CBC (Nonce 32B) ──► Byte Slicer (MAC 8B)
  1. Shared Secret Agreement (ECDH Key Agreement): Combines Client Private Key (32 B) and Server Public Key (65 B) on curve p256 to output the 32-byte X coordinate.
  2. Key & IV Partitioning (Cryptographic Hash + Byte Slicer × 2): Hashes the shared secret with SHA-256 and slices bytes 0..16 as Key and bytes 16..32 as IV.
  3. Challenge Encryption & Truncation (AES Encrypt + Byte Slicer): Encrypts the 32-byte Nonce in CBC mode (Padding = None) and slices 8 bytes from the start of the last ciphertext block (offset = -16, length = 8) to emit MAC alongside Client Public Key.

Nodes & Configuration

NodeNode Role & Key ParametersCount
Workflow InputSupplies Client Private Key, Client Public Key, Server Public Key, and Nonce1
ECDH Key Agreementcurve = "p256", format = "raw_x" (32-byte shared secret)1
Cryptographic Hashalgorithm = "SHA-256"1
Byte SlicerThree instances: Key (0, 16), IV (16, 16), and MAC (-16, 8)3
AES EncryptLabeled AES-128-CBC; configured with mode = "CBC", padding = "None"1
Workflow OutputEmits Client Public Key (65 B) and MAC (8 B)1

Node reference →

Inputs, Outputs & Test Vector Verification

Verification Source: independent implementation: Node crypto (reference/did-auth/did-auth.mjs), no published vector

Inputs

NameTypeValue (Hex)
Client Private Keybytes (32 B)2ad39d172118c0802359e6806b8939881b6a3fbcc9e89e307499a862acd4e3c9
Client Public Keybytes (65 B)0415dc193b8e2a688d603303e85ec8fcc15dcba44ef2156a128c386b66b4f5e1d2188e7ca9d0385c02e72c6899f2771e86bb017a2d2903d89a2892c2199aec8f4d
Server Public Keybytes (65 B)0447edf45c2c402ae4cfe8460fb208fbc0d6af18efa4b3d78d44c73fcb0c250ec08222f152af03468af65a74fbf89ecc763f19b0dadec5fd8df5cf76d7da097ae5
Noncebytes (32 B)000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f

Expected Outputs

NameTypeValue (Hex)
Client Public Keybytes (65 B)0415dc193b8e2a688d603303e85ec8fcc15dcba44ef2156a128c386b66b4f5e1d2188e7ca9d0385c02e72c6899f2771e86bb017a2d2903d89a2892c2199aec8f4d
MACbytes (8 B)39b415c1dfeb8f52