A stateless hierarchical key derivation and token exchange protocol for high-security point-of-sale and transactional systems, built on NIST-standardised post-quantum primitives (SHA-3/SHAKE/KMAC).
- Overview
- Protocol Design
- Key Derivation Chain
- Test Suite
- Project Structure
- Building
- Documentation
- License
HKDS is a Hierarchical Key Derivation System that provides secure key management and token exchange between constrained client devices (e.g., POS terminals) and a centralised transaction processing server. The protocol is designed for environments where devices operate with limited connectivity, where each transaction must use a unique key, and where compromise of any single device must not expose the wider device fleet.
HKDS is built exclusively on primitives standardised by NIST:
| Primitive | Role |
|---|---|
| SHAKE-128 / SHAKE-256 / SHAKE-512 | Pseudorandom function (PRF) for key stream generation |
| KMAC-128 / KMAC-256 / KMAC-512 | Message authentication (NIST SP 800-185) |
| SHA-3 | Supporting hash operations |
The SHAKE variant is selected at compile time, scaling security levels across the entire key hierarchy from root material through to transaction keys.
HKDS uses a stateless server architecture inspired by DUKPT. The server re-derives any transaction key on demand from the received Key Serial Number (KSN) and the master key set — no per-device state is stored server-side. This makes the protocol suitable for load-balanced and redundant server deployments.
| Component | Description |
|---|---|
| Master Key Set (MDK) | Held by the server only. Contains the Base Derivation Key (BDK), Secret Token Key (STK), and a Key Identity (KID). |
| Key Serial Number (KSN) | 16-byte identifier per client: Device Identity (DID, 12 bytes) || transaction counter (4 bytes, big-endian). Transmitted with every message. |
| Embedded Device Key (EDK) | SHAKE(DID ‖ BDK) — device-unique, provisioned into the client. Never changes for the device lifetime. |
| Epoch Token (tok) | SHAKE(CTOK ‖ STK) — server-derived, device- and epoch-unique. Delivered encrypted to the client each epoch. |
| Transaction Key Cache (TKC) | SHAKE(tok ‖ EDK) — generates a batch of unique transaction keys. Each key is used once then erased. |
Every transaction key is uniquely determined by the combination of:
- Device identity (DID embedded in EDK and the epoch customisation string)
- Epoch index (
counter / CACHE_SIZE) — changes the epoch tokentok, producing a completely independent key cache - Cache slot (
counter % CACHE_SIZE) — selects a non-overlapping slice of the epoch keystream
The 32-bit KSN counter is the nonce of the system and is the sole authoritative source of per-message uniqueness. The server always reads the current counter directly from the KSN supplied with each received packet.
The server delivers each epoch token encrypted and authenticated:
CTOK = BE32(counter / CACHE_SIZE) ‖ algorithm_name ‖ DID
tok = SHAKE(CTOK ‖ STK)
ks = SHAKE(CTOK ‖ EDK)
etok = ks XOR tok
mac = KMAC(key=EDK, msg=etok, custom=KSN‖mac_name)
send = etok ‖ mac
The client verifies the KMAC tag using its EDK before decrypting the token. A token exchange is required once per epoch (every CACHE_SIZE messages).
BDK ──────────────────────────────────────────────────────► (server only)
│
└─ SHAKE(DID ‖ BDK) ──────────────────────────────────► EDK (on device)
│
STK ──────────────────────────────────────────────────────►│
│ │
└─ SHAKE(CTOK ‖ STK) ────────────────────────────────► tok (delivered encrypted)
│
SHAKE(tok ‖ EDK) ──┘
│
┌─────────────────────┴──────────────────────┐
TK[0] TK[1] TK[2] ... TK[CACHE_SIZE-1]
(each slot used once and erased)
Security properties of the chain:
- Compromise of EDK alone is insufficient to compute any TK (STK is also required, held only server-side).
- Compromise of tok exposes only the current epoch's key cache; other epochs are unaffected.
- Past cache slots cannot be recovered — each slot is securely erased immediately after use.
The HKDSTest project provides comprehensive validation across seven test categories:
| Test Category | Purpose |
|---|---|
| Cycle Tests | Full server ↔ client protocol round-trips, including token exchange and message encrypt/decrypt |
| Known-Answer Tests (KAT) | Output verification against pre-computed reference vectors for all key derivation and encryption operations |
| Authenticated Encryption Tests (KATAE) | Verification of ciphertext and KMAC tag correctness for the authenticated message path |
| Monte Carlo Tests | Repeated cycle execution to verify consistency and detect non-determinism |
| Stress Tests | Sustained full-protocol execution to assess stability under load |
| SIMD / Parallel Tests | Equivalence checks between vectorised (x8, x64) and scalar implementations |
| Benchmark Tests | Timing measurements for cryptographic primitives and complete protocol operations |
HKDS/
├── hkds_client.h / .c Client-side key management, encryption, and token handling
├── hkds_server.h / .c Server-side key derivation, token generation, and decryption
├── hkds_config.h Protocol parameters, key sizes, and compile-time mode selection
├── hkds_queue.h / .c Message queuing for asynchronous batch operations
├── hkds_benchmark.h / .c Performance benchmarking for primitives and protocol operations
├── hkds_test.h / .c Functional correctness and performance test suite
└── keccak.h / .c SHAKE / KMAC / SHA-3 primitive implementations
| Tool | Minimum Version |
|---|---|
| CMake | 3.15 |
| Visual Studio (Windows) | 2022 |
| Clang (macOS) | Via Xcode or Homebrew |
| GCC or Clang (Ubuntu) | Current stable |
- Extract the repository so that the
HKDSlibrary folder and theHKDSTestfolder are siblings at the same directory level. - Open the
HKDSTestVisual Studio solution. - Verify that
HKDSTest→ Project Properties → C/C++ → General → Additional Include Directories points to theHKDSlibrary folder ($(SolutionDir)HKDSby default). - Verify that HKDSTest → References includes the HKDS library project.
- Set both the HKDS library and HKDSTest to the same AVX instruction set in:
Configuration Properties → C/C++ → All Options → Enable Enhanced Instruction Set
Do this for both Debug and Release configurations. - Right-click the HKDS library and select Build.
- Right-click
HKDSTest, select Set as Startup Project, then run.
HKDS supports AVX, AVX2, and AVX-512. Both projects must use the same instruction set family.
- Locate the
Eclipse/UbuntuorEclipse/MacOSsubfolder in the repository. - Copy the
.project,.cproject, and.settingsfiles from that subfolder directly into the folder containing the corresponding source files (do this for both the HKDS library and HKDSTest). - In Eclipse, create a new C/C++ → Empty Project with the same name as each source folder (e.g.,
HKDS,HKDSTest). Eclipse will detect and load the copied project settings automatically. - Repeat for the
HKDSTestproject, selecting the correct OS-specific files.
Default project files target AVX2 with AES-NI and RDRAND enabled. Select the Ubuntu or macOS files as appropriate — compiler settings differ between GCC and Clang.
-msse2 -mavx -maes -mpclmul -mrdrnd -mbmi2
| Flag | Purpose |
|---|---|
-msse2 |
SSE2 baseline (required for x86-64) |
-mavx |
256-bit floating-point and SIMD |
-maes |
AES-NI (hardware AES round instructions) |
-mpclmul |
PCLMUL carry-less multiply |
-mrdrnd |
RDRAND hardware RNG |
-mbmi2 |
BMI2 bit-manipulation (PEXT/PDEP) |
-msse2 -mavx -mavx2 -maes -mpclmul -mrdrnd -mbmi2
| Flag | Purpose |
|---|---|
-msse2 |
SSE2 baseline |
-mavx |
AVX baseline |
-mavx2 |
256-bit integer and FP SIMD |
-maes |
AES-NI |
-mpclmul |
PCLMUL (carry-less multiply for GHASH etc.) |
-mrdrnd |
RDRAND hardware RNG |
-mbmi2 |
BMI2 bit-manipulation |
-msse2 -mavx -mavx2 -mavx512f -mavx512bw -mvaes -mpclmul -mrdrnd -mbmi2 -maes
| Flag | Purpose |
|---|---|
-msse2 |
SSE2 baseline |
-mavx |
AVX baseline |
-mavx2 |
AVX2 baseline (explicit for safety) |
-mavx512f |
512-bit foundation instructions |
-mavx512bw |
512-bit byte/word integer instructions |
-mvaes |
Vector AES in 512-bit registers |
-mpclmul |
PCLMUL carry-less multiply |
-mrdrnd |
RDRAND hardware RNG |
-mbmi2 |
BMI2 bit-manipulation |
-maes |
AES-NI 128-bit rounds |
| Document | Description |
|---|---|
| API Reference | Full online help documentation |
| Summary | High-level protocol overview |
| Protocol Specification | Formal protocol description and message formats |
| Formal Analysis | Cryptographic security proofs and formal model |
| Implementation Analysis | Implementation notes and design rationale |
| Integration Guide | Developer integration reference |
QRCS is currently seeking a corporate investor for this technology.
Parties interested in licensing or investment should contact us at contact@qrcscorp.ca
For a full inventory of our products and services, visit qrcscorp.ca.
One or more patent applications (provisional and/or non-provisional) covering aspects of this software have been filed with the United States Patent and Trademark Office (USPTO). Unauthorized use may result in patent infringement liability.
This repository contains cryptographic reference implementations, test code, and supporting materials published by Quantum Resistant Cryptographic Solutions Corporation (QRCS) for the purposes of public review, cryptographic analysis, interoperability testing, and evaluation.
All source code and materials in this repository are provided under the Quantum Resistant Cryptographic Solutions Public Research and Evaluation License (QRCS-PREL), 2025–2026, unless explicitly stated otherwise.
Permitted use:
- Public access, non-commercial research, evaluation, and testing
Not permitted without a separate written commercial agreement:
- Production deployment or operational use
- Incorporation into any commercial product or service
- Certified or supported builds
The public availability of this repository is intentional and is provided to support cryptographic transparency, independent security assessment, and compliance with applicable cryptographic publication and export regulations.
For commercial licensing, supported implementations, or integration inquiries, contact: licensing@qrcscorp.ca
Quantum Resistant Cryptographic Solutions Corporation — All rights reserved, 2026.