Skip to content

Chapter 2: Hardware Security Module (HSM)

2.1 Introduction

A Hardware Security Module (HSM) is a physically and logically tamper-resistant hardware device that safeguards cryptographic keys and performs cryptographic operations within a secure boundary. HSMs are mandatory infrastructure in banking, PKI, code signing, cloud key management, and government classified systems. They enforce the principle that private key material never leaves the hardware boundary in plaintext form.

Key properties of an HSM:

  • Tamper resistance: Active sensors detect intrusion; keys are zeroized on attack

  • Tamper evidence: Visible seals or enclosures that show if the device was opened

  • Secure key generation: On-board TRNG with continuous health tests (NIST SP 800-90B)

  • Cryptographic acceleration: Hardware engines for RSA, ECC, AES, SHA at high throughput

  • Audit logging: Tamper-evident logs for all key operations (required by PCI HSM)

  • Authenticated access: Multi-factor, M-of-N operator authentication with smart cards

Note: Unlike a TPM (which is a passive co-processor bound to one host), an HSM is an active network appliance or PCIe card providing cryptographic services to multiple clients simultaneously via PKCS#11, JCA/JCE, or vendor APIs.

2.2 FIPS 140-3 Security Levels

FIPS 140-3 (superseding FIPS 140-2 in 2019) defines four security levels for cryptographic modules. It aligns with ISO/IEC 19790:2012 and ISO/IEC 24759:2017.

Table 2.1. FIPS 140-3 Security Levels Summary
Level Requirements and Examples
Level 1 Basic cryptographic security; no physical security beyond production-grade components. Allows software-only implementation. Example: OpenSSL FIPS module on generic server.
Level 2 Tamper-evidence: tamper-evident coatings or seals; role-based authentication. Example: Thales Luna T-Series PCIe, Yubico YubiHSM 2.
Level 3 Tamper resistance with response: zeroizes keys on physical attack attempt; identity-based auth; physical/logical separation of interfaces. Example: Thales Luna Network HSM 7, Utimaco CryptoServer Se50.
Level 4 Complete envelope of protection; environmental attack protection (voltage, temperature); EFP/EFT. Example: Thales payShield 10K, IBM 4769, Utimaco SecurityServer.

Warning: FIPS 140-3 Level 3 is the minimum required for most PKI root CA HSMs and banking key management systems. Level 4 is required for PIN-entry device (PED) master keys in payment processing.

2.3 HSM Internal Architecture

2.3.1 Block Diagram

image

2.3.2 Key Management Hierarchy

image

2.3.3 Internal Components

Table 2.2. HSM Internal Hardware Components
Component Typical Implementation Function
Main processor ARM Cortex-A9 @ 800 MHz Command processing, PKCS#11 dispatch, access control
Cryptographic accelerator Custom ASIC / FPGA AES-256, RSA-4096, ECC P-521 at hardware speed
TRNG PTG.2 (BSI AIS-31) ring oscillators Entropy source; continuous health test per SP 800-90B
Secure SRAM Battery-backed 256 KB SRAM Key cache; zeroized on tamper or power loss
Flash storage 64 MB NOR flash (encrypted) Firmware, key blobs, audit logs; MK-encrypted
Tamper sensors Temp, voltage, light, mesh, drill Trigger zeroization; EFP/EFT attack detection
PED interface USB smart card reader PIN entry device for operator authentication (ISO 9564)
Battery Li-Po 3.7V, 5-year life Maintains SRAM key cache when main power removed
Environmental sensors Temperature: -20 to +70 C Detect forced cooling/heating attacks (FIPS L4)

2.4 PKCS#11 API

PKCS#11 (version 3.0, OASIS standard) is the primary API for interacting with HSMs. It defines a platform-independent C interface: CK_FUNCTION_LIST_PTR.

2.4.1 AES Key Generation and Encryption

#include <pkcs11.h>

CK_FUNCTION_LIST_PTR pFunctionList;
CK_SESSION_HANDLE hSession;
CK_OBJECT_HANDLE hKey;

/* Initialize PKCS#11 library (Thales Luna, SoftHSM2) */
C_GetFunctionList(&pFunctionList);
pFunctionList->C_Initialize(NULL_PTR);

/* Open session and login */
CK_SLOT_ID slotId = 0;
pFunctionList->C_OpenSession(slotId, CKF_SERIAL_SESSION|CKF_RW_SESSION,
                             NULL, NULL, &hSession);
CK_UTF8CHAR pin[] = "user-pin-here";
pFunctionList->C_Login(hSession, CKU_USER, pin, strlen((char*)pin));

/* Generate AES-256 key inside HSM */
CK_MECHANISM keyGenMech = { CKM_AES_KEY_GEN, NULL, 0 };
CK_ULONG keyLen = 32;  /* 256 bits */
CK_BBOOL trueVal = CK_TRUE, falseVal = CK_FALSE;
CK_ATTRIBUTE keyTemplate[] = {
    {CKA_VALUE_LEN,   &keyLen,   sizeof(keyLen)},
    {CKA_TOKEN,       &trueVal,  sizeof(trueVal)},
    {CKA_ENCRYPT,     &trueVal,  sizeof(trueVal)},
    {CKA_SENSITIVE,   &trueVal,  sizeof(trueVal)},
    {CKA_EXTRACTABLE, &falseVal, sizeof(falseVal)},
};
pFunctionList->C_GenerateKey(hSession, &keyGenMech, keyTemplate, 5, &hKey);

/* Encrypt data with AES-256-GCM */
CK_GCM_PARAMS gcmParams = { iv, 12, NULL, 0, 128 };  /* 128-bit auth tag */
CK_MECHANISM encMech = { CKM_AES_GCM, &gcmParams, sizeof(gcmParams) };
pFunctionList->C_EncryptInit(hSession, &encMech, hKey);
CK_ULONG cipherLen = plaintextLen + 16;
pFunctionList->C_Encrypt(hSession, plaintext, plaintextLen, ciphertext, &cipherLen);

Tip: Always set CKA_SENSITIVE = TRUE and CKA_EXTRACTABLE = FALSE on sensitive keys. The HSM hardware enforces this: C_GetAttributeValue for the key value will return CKR_ATTRIBUTE_SENSITIVE.

2.4.2 RSA Key Pair Generation and Signing

/* Generate RSA-2048 key pair inside HSM */
CK_MECHANISM rsaGenMech = { CKM_RSA_PKCS_KEY_PAIR_GEN, NULL, 0 };
CK_ULONG modBits = 2048;
CK_BYTE pubExp[] = { 0x01, 0x00, 0x01 };  /* e = 65537 */
CK_OBJECT_HANDLE hPub, hPriv;
CK_ATTRIBUTE pubTmpl[] = {
    {CKA_MODULUS_BITS,     &modBits, sizeof(modBits)},
    {CKA_PUBLIC_EXPONENT,  pubExp,   sizeof(pubExp)},
    {CKA_VERIFY,           &trueVal, sizeof(trueVal)},
};
CK_ATTRIBUTE privTmpl[] = {
    {CKA_SIGN,        &trueVal,  sizeof(trueVal)},
    {CKA_SENSITIVE,   &trueVal,  sizeof(trueVal)},
    {CKA_EXTRACTABLE, &falseVal, sizeof(falseVal)},
};
C_GenerateKeyPair(hSession, &rsaGenMech,
                  pubTmpl, 3, privTmpl, 3, &hPub, &hPriv);

/* Sign with RSA-PSS SHA-256 */
CK_RSA_PKCS_PSS_PARAMS pssParams = { CKM_SHA256, CKG_MGF1_SHA256, 32 };
CK_MECHANISM signMech = { CKM_SHA256_RSA_PKCS_PSS, &pssParams, sizeof(pssParams) };
C_SignInit(hSession, &signMech, hPriv);
CK_ULONG sigLen = 256;
C_Sign(hSession, message, messageLen, signature, &sigLen);

2.5 Commercial HSM Products

Table 2.3. Commercial HSM Products – Network, PCIe, USB, and Payment
Product Vendor Form Factor FIPS Level Performance Key Notes
Luna Network HSM 7 Thales Group 1U Network Appliance FIPS 140-3 L3 20,000 RSA-2048/s PKCS#11, JCA, MS CAPI; HA clustering; PED auth
Luna PCIe HSM 7 Thales Group PCIe card FIPS 140-3 L3 10,000 RSA-2048/s Direct host integration; partitioned; HSMoD
payShield 10K Thales Group 2U Payment HSM FIPS 140-3 L4 10,000 RSA/s PCI HSM v3.0; supports PIN, ZMK, CVV, EMV
CryptoServer Se50 Utimaco PCIe card FIPS 140-3 L3 8,000 RSA-2048/s Multi-partition; JCE; .NET CSP; custom firmware
SecurityServer Se500 Utimaco Network Appliance FIPS 140-3 L4 6,000 RSA-2048/s FIPS L4; payment and general-purpose
nShield Connect 6000+ Entrust (nCipher) Network Appliance FIPS 140-2 L3 6,000 RSA-2048/s CodeSafe: custom firmware; Security World clustering
nShield Solo XC Entrust (nCipher) PCIe card FIPS 140-2 L3 3,000 RSA-2048/s CodeSafe firmware sandbox for custom crypto
IBM 4769 IBM PCIe card (z/OS) FIPS 140-2 L4 custom IBM Z mainframe; CEX7 coprocessor; 4096-bit RSA
YubiHSM 2 Yubico USB nano dongle FIPS 140-2 L3 75 RSA-2048/s $650; 2MB key storage; PKCS#11; libyubihsm
SoftHSM2 (EJBCA) OpenDNSSEC Software (Linux) None (dev/test) CPU-limited Open source; PKCS#11 compatible; used in EJBCA
AWS CloudHSM Amazon Web Services Cloud (dedicated HW) FIPS 140-3 L3 100,000 AES/s Single-tenant Cavium LiquidSecurity; VPC integrated
Azure Dedicated HSM Microsoft Azure Cloud (dedicated HW) FIPS 140-2 L3 custom Thales Luna 7 in Azure DC; full PKCS#11
Azure Managed HSM Microsoft Azure Cloud (managed) FIPS 140-3 L3 custom Multi-tenant HSM pool; Key Vault Premium backend
Google Cloud HSM Google Cloud Cloud (managed) FIPS 140-2 L3 custom Cloud KMS HSM keys; region-specific; audit log

2.6 Key Ceremony Procedures

A key ceremony is a formal, witnessed, and audited procedure for generating, transporting, or destroying cryptographic keys. It is required for Root CA key generation, HSM master key setup, and KMS initialization.

2.6.1 Root CA Key Generation Ceremony

  1. Pre-ceremony preparation:

    • FIPS 140-3 L3+ HSM verified (seal check, firmware hash, certificate chain)

    • Air-gapped room with Faraday shielding; no network connectivity

    • Key custodians selected: 5-of-8 Shamir Secret Sharing threshold

    • Hardware tokens (smart cards or USB security keys) issued to each custodian

    • Video recording, independent auditors, and a notary present

  2. HSM initialization:

    • Factory reset + new partition; generate new HSM domain master key via TRNG

    • Domain master key split into 8 shares using Shamir Secret Sharing

    • Each share encrypted to a custodian smart card (RSA-4096 or ECC P-384)

    • Smart cards distributed to geographically separate custodians

  3. Root CA key generation:

    • 5 of 8 custodians insert smart cards; HSM decrypts and reconstructs domain key

    • C_GenerateKeyPair(RSA-4096) on HSM; CKA_EXTRACTABLE = FALSE

    • Self-signed Root CA certificate generated inside HSM

    • Public key exported; signed ceremony report generated

  4. Verification and documentation:

    • Audit log printed and signed by all participants and auditors

    • Root CA certificate fingerprint verified against HSM log

    • HSM backup created; backup tokens stored in separate secure locations

Warning: The ICANN Root KSK Ceremony for DNSSEC is performed using an Entrust nShield HSM in a highly secure facility. It is publicly webcast and involves 14 Trusted Community Representatives across 7 global sites. Missing the ceremony requires a formal exception report.

2.7 Payment HSM Operations

Payment HSMs (PCI HSM v3.0 certified) implement the ANSI X9.24 retail financial services key management standard. They use a key hierarchy based on Zone Master Keys (ZMK) for inter-bank key exchange.

Table 2.4. Payment HSM Key Types and Operations
Key Type Abbreviation Function
Zone Master Key ZMK Encrypts other keys for inter-bank transport (TR-31 key blocks)
Terminal Master Key TMK Encrypts PIN Encryption Keys; shared between acquiring bank and POS terminal
PIN Encryption Key PEK Encrypts customer PIN blocks (ISO 9564 format) from POS terminal to host
PIN Verification Key PVK Generates/verifies IBM PIN Verification Value (IBM PVV) or Visa PVV
Card Verification Key CVK Generates/verifies CVV/CVC value printed on payment card
Message Authentication Key MAK MAC for ANSI X9.19 transaction authentication
Base Derivation Key BDK Derives DUKPT (Derived Unique Key Per Transaction) device-specific keys

2.7.1 PIN Processing Flow

  1. Customer enters PIN on POS terminal keyboard (encrypted in PEK by HSM inside POS)

  2. Encrypted PIN block transmitted with transaction to acquiring bank

  3. Acquiring bank HSM translates PIN block from PEK to ZMK encryption

  4. Issuing bank HSM translates PIN block from ZMK to PVK encryption

  5. Issuer HSM verifies PIN using PIN Verification Value (IBM PVV or Visa PVV)

  6. Approval or decline sent back through network

2.8 Python Interface: PyKCS11

PyKCS11 is a Python binding for PKCS#11 that works with SoftHSM2, Thales Luna, Utimaco, and any compliant HSM.

import PyKCS11
from PyKCS11 import Mechanism, CKM_RSA_PKCS_KEY_PAIR_GEN, CKM_SHA256_RSA_PKCS_PSS
from PyKCS11.types import CKA_MODULUS_BITS, CKA_TOKEN, CKA_SIGN, CKA_SENSITIVE

# Load PKCS#11 library (SoftHSM2 for testing, Thales/Utimaco for production)
lib = PyKCS11.PyKCS11Lib()
lib.load('/usr/lib/softhsm/libsofthsm2.so')

# Open session and login
slot = lib.getSlotList(tokenPresent=True)[0]
session = lib.openSession(slot, PyKCS11.CKF_SERIAL_SESSION | PyKCS11.CKF_RW_SESSION)
session.login('user-pin')

# Generate RSA-2048 key pair in HSM
pub_template = [
    (CKA_MODULUS_BITS,    2048),
    (CKA_TOKEN,           True),
    (PyKCS11.CKA_VERIFY,  True),
]
priv_template = [
    (CKA_TOKEN,           True),
    (CKA_SIGN,            True),
    (CKA_SENSITIVE,       True),
    (PyKCS11.CKA_EXTRACTABLE, False),
]
pub_key, priv_key = session.generateKeyPair(
    Mechanism(CKM_RSA_PKCS_KEY_PAIR_GEN),
    pub_template, priv_template
)

# Sign a message using RSA-PSS SHA-256
message = b'Hardware Security Module demo message'
pss_params = PyKCS11.RSA_PKCS_PSS_Params('sha256')
signature = session.sign(priv_key, message,
                         Mechanism(CKM_SHA256_RSA_PKCS_PSS, pss_params))
print(f'Signature ({len(signature)} bytes): {bytes(signature).hex()[:32]}...')

session.logout()
session.closeSession()

2.9 FPGA-Based HSM Implementation

2.9.1 Architecture Overview

An FPGA-based HSM uses a system-on-chip (SoC) or discrete FPGA for cryptographic acceleration with a hardened ARM CPU for policy enforcement.

Table 2.5. FPGA HSM Resource Utilization – Xilinx Zynq UltraScale+ (ZU9EG)
Module LUTs FFs BRAMs DSPs Freq (MHz)
AES-256-GCM (pipelined) 3,200 2,100 0 0 300
SHA-256/384/512 4,800 3,200 2 0 250
RSA-4096 (Montgomery) 8,500 4,200 8 64 120
ECC P-384 (radix-4 NAF) 6,200 3,800 4 32 150
TRNG (NIST SP 800-90B) 450 280 0 0 200
PKCS#11 dispatcher (ARM) N/A N/A N/A N/A 1,200 ARM
Tamper response logic 320 180 0 0 200
Key zeroization circuit 80 60 0 0 200
Total FPGA fabric 23,550 13,820 14 96 varies

Note: Xilinx Zynq UltraScale+ ZU9EG has 274,080 LUTs, 548,160 FFs, 912 BRAMs, 2,520 DSPs. The FPGA HSM uses approximately 8.6% LUTs. The ARM Cortex-A53 quad-core runs at 1.2 GHz and handles PKCS#11 protocol. Total RSA-4096 throughput: approximately 180 operations/second at 120 MHz.

2.9.2 ASIC HSM Implementation (Marvell LiquidSecurity)

Table 2.6. Marvell LiquidSecurity NITROX PX ASIC Specifications (AWS CloudHSM Backend)
Parameter Value
Process node TSMC 16nm FinFET
Die area  120 mm\(^2\)
RSA-2048 throughput 100,000 ops/second
RSA-4096 throughput 25,000 ops/second
AES-GCM throughput 100 Gbps
SHA-3 throughput 50 Gbps
ECC P-256 ECDSA 50,000 ops/second
TLS handshakes/s 100,000 TLS 1.3/s
Power consumption 25 W TDP
Key storage 64 MB on-chip encrypted SRAM
FIPS 140-3 Level 3 validated

2.10 HSM Security Attacks and Countermeasures

2.10.1 Differential Power Analysis (DPA) on HSMs

  • Attack: Measure power consumption during AES key schedule; statistical correlation with key bits

  • Countermeasures: Random insertion of dummy operations; balanced logic (DPL); power line filtering

  • Reference: Kocher, Jaffe, Jun 1999 (original DPA paper); ANSSI RGS B3 DPA requirements

2.10.2 Offline PIN Brute Force (ANSI TR-39)

  • Risk: If PIN verification key (PVK) extracted from compromised HSM, offline PINs can be guessed

  • 4-digit PIN space: Only 10,000 combinations; exhaustive search in milliseconds

  • Defense: VISA PVV uses 3DES with 4-bit result from 11-digit PAN+PIN input; limits false positives

  • Countermeasure: HSM access control and PCI HSM require M-of-N for PVK access

2.10.3 API-Level Attack on Thales RG7000

  • Discovery: Anderson and Bond (Cambridge, 2003) found API-level flaws in Thales/IBM HSMs

  • Attack: Combine Exportkey + Translate commands to extract keys in cleartext

  • Principle: HSM commands individually secure; combinations create logical vulnerabilities

  • Fix: API reformulation; explicit key type attribute flags; command access restrictions

2.10.4 Cold Boot Attack on Battery-Backed SRAM

  • Attack: Freeze SRAM battery; remove chip; read key material at -60C (data retention: hours to days)

  • Countermeasure (FIPS L4): Mesh sensor wire over SRAM; voltage/temperature sensors trigger zeroization

  • Additional: Key cache encryption with ephemeral key; SRAM scrambling on power loss

2.11 All HSM Solutions Ecosystem

Table 2.7. Comprehensive HSM Ecosystem: Hardware, Software, Cloud, and Open-Source
Solution Type Vendor FIPS Level Interface Notable Use
Thales Luna Network HSM 7 Network HSM Thales Group FIPS 140-3 L3 PKCS#11, JCA, REST PKI, code signing, TLS offload
Thales payShield 10K Payment HSM Thales Group FIPS 140-3 L4 Proprietary API Visa, Mastercard payment processing
Utimaco CryptoServer Se50 PCIe HSM Utimaco FIPS 140-3 L3 PKCS#11, JCE, CSP CA infrastructure, timestamping
Entrust nShield Connect 6000+ Network HSM Entrust FIPS 140-2 L3 PKCS#11, MSCAPI CodeSafe custom firmware capability
IBM 4769 PCIe HSM IBM FIPS 140-2 L4 CCA, PKCS#11 IBM Z mainframe, CEX7 coprocessor
YubiHSM 2 USB HSM Yubico FIPS 140-2 L3 libyubihsm, PKCS#11 SSH CA, small PKI, $650
AWS CloudHSM Cloud HSM Amazon FIPS 140-3 L3 PKCS#11, JCE, OpenSSL Single-tenant Cavium NITROX
Azure Dedicated HSM Cloud HSM Microsoft FIPS 140-2 L3 PKCS#11 Thales Luna 7 in Azure DC
Azure Managed HSM Cloud HSM Microsoft FIPS 140-3 L3 Key Vault API, REST Multi-tenant, pay-per-use
Google Cloud HSM Cloud HSM Google FIPS 140-2 L3 Cloud KMS REST API KMS HSM-backed keys
SoftHSM2 Software HSM OpenDNSSEC None (testing) PKCS#11 v2.40 DNSSEC, EJBCA, development
openHSM (research) FPGA Academic Research PKCS#11 over USB Xilinx SP605; open-source prototype
Tillitis TKey USB Security Key Tillitis None (open HW) USB HID Open hardware; RISC-V based
Xilinx Zynq HSM IP FPGA SoC Xilinx/AMD None (dev) AXI4 PKCS#11 UltraScale+ PS+PL integration

2.12 Standards and Specifications

  • FIPS 140-3 (2019): Security Requirements for Cryptographic Modules (NIST); aligns with ISO/IEC 19790

  • PKCS#11 v3.0 (2020): OASIS Cryptographic Token Interface Standard; C API specification

  • PCI HSM v3.0: Payment Card Industry HSM security requirements; mandatory for payment processing HSMs

  • ANS X9.24-1 (2017): Retail financial services symmetric key management using TDEA

  • ANS X9.24-3 (2017): Retail financial services using AES key management

  • TR-31 (ANSI X9.143-2022): Interoperable secure key blocks for key transport

  • NIST SP 800-57 Part 1 Rev 5: Key management recommendations; key types, lifetimes, transitions

  • ISO 9564-1:2017: PIN management and security in financial services

  • NIST SP 800-131A Rev 2: Transitions from legacy cryptographic algorithms

  • Common Criteria EN 419221: Protection profiles for HSM devices (PP-0084, PP-0085)

2.13 Solved Problems

Solved Problem: FIPS 140-3 Level Selection for PKI Infrastructure

A government agency is deploying a new PKI with the following components: (a) Root CA that signs Intermediate CA certificates (once per year), (b) Intermediate CA that signs subscriber certificates (100/day), (c) OCSP responder signing (10,000 responses/day), (d) Code signing for software releases. Select the appropriate FIPS 140-3 level for each component and justify the choice. Solution:

  1. Root CA – FIPS 140-3 Level 4. The root CA private key is the most critical asset. Compromise would invalidate the entire PKI. Level 4 provides complete physical protection envelope, environmental attack protection (EFP/EFT), and tamper-response zeroization. The low volume (once/year) means performance is not critical. Recommended: Thales payShield 10K or IBM 4769 in an air-gapped facility.

  2. Intermediate CA – FIPS 140-3 Level 3. Level 3 provides tamper resistance with identity-based authentication. Performance at 100 sigs/day is trivially achievable. Physical separation of signing interface from admin interface is required. Recommended: Thales Luna Network HSM 7 or Utimaco CryptoServer Se50.

  3. OCSP Responder – FIPS 140-3 Level 3. 10,000 RSA signatures/day (0.12/s) is easily achievable. The OCSP key is a delegated signer; compromise allows forgery of revocation status but does not compromise CA key. Level 3 is standard for OCSP; Luna PCIe HSM or nShield Solo XC are suitable.

  4. Code Signing – FIPS 140-3 Level 3. Code signing private key compromise would allow malware distribution signed by a trusted key. Level 3 with strict access control (M-of-N authentication) and audit logging is required. YubiHSM 2 (Level 3) is suitable for small teams; Luna for enterprise scale.

Solved Problem: Key Wrapping and TR-31 Key Block Analysis

A payment processor needs to securely transport a new Zone Master Key (ZMK) from their HSM to a partner bank’s HSM. The key is AES-256. (a) What is a TR-31 key block and what fields does it contain? (b) Construct the key block header for this ZMK transport. (c) Why is simple encryption with the KEK insufficient? Solution: (a) TR-31 Key Block Structure: TR-31 (ANSI X9.143-2022) defines a key block format that binds a key to its attributes, preventing repurposing attacks (using a PIN encryption key as a MAC key, for example).

Field Length Example Value
Version ID 1 char D (AES key derivation binding)
Key Block Length 4 char 0112 (total block length)
Key Usage 2 char K0 (Key Encryption Key / Zone Master Key)
Algorithm 1 char A (AES)
Mode of Use 1 char X (Key used for key derivation)
Key Version Number 2 char 00 (no version assigned)
Exportability 1 char S (Sensitive – exportable under KEK only)
Number of Optional Blocks 2 char 00
Reserved 2 char 00

(b) Example TR-31 header for AES-256 ZMK transport: D0112K0AX0000000 Breakdown: Version D, Length 0112, Key Usage K0, Algorithm A (AES), Mode X, Version 00, Export S, Optional 00, Reserved 00.

(c) Why simple KEK encryption is insufficient:

  • No attribute binding: A simply-encrypted AES key can be repurposed as any key type

  • No integrity: Bit flips in the wrapped key are undetectable

  • No version management: Cannot distinguish key versions

  • Regulatory: PCI HSM v3.0 requires TR-31 format for all key exchange

TR-31 uses AES-CMAC to authenticate the header + key, preventing tampering.

Solved Problem: HSM Performance Design: Cloud HSM Cluster

A cloud application requires HSM-backed TLS certificates for 50,000 concurrent HTTPS connections. Peak new connection rate: 5,000 TLS 1.3 handshakes/second. Key type: ECDSA P-256 (used for TLS certificate private key). How many Thales Luna Network HSM 7 units are needed? Design the HA cluster. Solution: Performance Analysis:

Thales Luna Network HSM 7 specifications:

  • ECDSA P-256 sign throughput: approximately 10,000 signs/second per HSM

  • TLS 1.3 handshake with ECDSA P-256 requires: 1 ECDSA sign (server) + 1 ECDH derivation

  • ECDH P-256 throughput: approximately 8,000 derivations/second

  • Combined TLS ops: min(10,000, 8,000) = 8,000 handshakes/second per HSM

Capacity calculation:

\[\begin{align*} \text{HSMs needed} &= \lceil \frac{5{,}000}{8{,}000} \rceil = \lceil 0.625 \rceil = 1 \text{ for peak load} \end{align*}\]

For high availability (no single point of failure) and 100% overhead for failures:

  • Minimum: 2 HSMs in active-active cluster (Luna HA group)

  • Recommended: 3 HSMs (N+1 redundancy); 2 active + 1 standby

  • Geographic distribution: 2 units in primary DC, 1 in DR site

  • Luna HA group: automatic key synchronization; transparent failover in \(<\)1 second

  • Total capacity: 24,000 TLS 1.3 handshakes/second (3x HSM)

Architecture: Application servers connect via TLS to Luna Network HSM 7 using PKCS#11. Private key CKA_EXTRACTABLE = FALSE; certificate private key never leaves HSM. Luna HA library handles load balancing and failover transparently to the application.

Solved Problem: SoftHSM2 Development Workflow

You need to prototype an application that uses PKCS#11 for key storage before deploying on a real HSM. Set up SoftHSM2 on Ubuntu, generate an RSA-2048 key pair, sign a message, and verify it. Identify the limitations of SoftHSM2 versus a physical FIPS 140-3 Level 3 HSM. Solution:

# Install SoftHSM2 (PKCS#11 software HSM for development)
sudo apt-get install softhsm2 openssl gnutls-bin

# Initialize a new token
softhsm2-util --init-token --slot 0 --label 'DevHSM' \
              --so-pin 'admin-pin' --pin 'user-pin'

# List available slots
softhsm2-util --show-slots

# Generate RSA-2048 key pair using p11tool (gnutls)
p11tool --provider /usr/lib/softhsm/libsofthsm2.so \
        --login --set-pin 'user-pin' \
        --generate-rsa --bits 2048 --label 'MyRSAKey' \
        'pkcs11:model=SoftHSM

# Sign a file with the HSM key via pkcs11-tool
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so \
            --login --pin 'user-pin' \
            --sign --mechanism SHA256-RSA-PKCS \
            --id 01 -i message.bin -o signature.bin

# Verify signature with OpenSSL
openssl dgst -sha256 -verify public.pem -signature signature.bin message.bin

Limitations of SoftHSM2 vs Physical FIPS HSM:

Property SoftHSM2 Physical HSM (FIPS L3)
FIPS certification None FIPS 140-3 Level 3
Physical tamper protection None (pure software) Tamper-responsive envelope
Key material protection AES-encrypted SQLite DB Battery-backed SRAM + mesh
TRNG quality OS entropy (getrandom) Hardware RNG (BSI PTG.2)
DPA/SCA resistance None Balanced logic, power filtering
Audit logging None Tamper-evident audit log
Performance CPU-limited (100s RSA/s) 10,000+ RSA-2048/s

SoftHSM2 is suitable for PKCS#11 API development and testing only; never use for production key material.

2.14 Recent Developments (2024–2026)

2.14.1 Entrust nShield 5s and 5c (2024): FIPS 140-3 Level 3 with PQC

Entrust released the nShield 5s (network appliance) and nShield 5c (PCIe card) in 2024, the first nShield generation achieving FIPS 140-3 Level 3 validation. Key improvements over the nShield Connect 6000+ include post-quantum algorithm support and updated CodeSafe sandbox:

Table 2.8. Entrust nShield 5s Specifications (2024)
Parameter Value
FIPS validation FIPS 140-3 Level 3 (CMVP #4600+)
RSA-2048 throughput 20,000 ops/s
ECC P-256 throughput 40,000 ops/s
Post-quantum algorithms ML-DSA-44/65/87, ML-KEM-512/768/1024 (firmware)
Hybrid signing ECDSA P-256 + ML-DSA-44 dual-algorithm certificates
CodeSafe SDK Version 13: RISC-V sandbox replacing ARM SC300
Key management Security World v14; backward-compatible with nShield 6000+
Throughput (AES-GCM) 20 Gbps hardware-accelerated

Note: Entrust Security World technology allows nShield 5s HSMs to share keys with older nShield Connect 6000+ units in the same cluster during migration. This enables zero-downtime hardware refresh for production PKI deployments.

2.14.2 AWS CloudHSM v3 and External Key Store (XKS) Integration (2024)

Amazon Web Services released CloudHSM v3 in 2024 and the External Key Store (XKS) integration for AWS KMS, enabling customer-managed HSMs to serve as the key authority for KMS:

  • CloudHSM v3: Multi-AZ cluster management improvements; automatic firmware update to FIPS 140-3 Level 3 hardware; new cloudhsm-cli replacing legacy CLI

  • XKS (External Key Store): KMS API calls proxied through customer VPC endpoint to on-premises or co-located FIPS HSM; key material never leaves customer hardware

  • XKS protocol: HTTPS proxy (TLS 1.3); PKCS#11 on customer HSM; KMS Encrypt/Decrypt translated to C_Encrypt/C_Decrypt

  • Latency: XKS adds \(\approx 5\)–20 ms per call versus \(<1\) ms for KMS-managed keys

  • Use case: Regulated sectors (financial, healthcare, EU data sovereignty) where key material must reside in customer-controlled hardware

Tip: XKS is not a substitute for performance-sensitive workloads. For bulk S3 server-side encryption, keep DEKs in KMS. Use XKS only for the root wrapping key (KEK) that protects data encryption keys, reducing call frequency to infrequent key wrap/unwrap operations.

2.14.3 PKCS#11 3.0 Standard (2023): Post-Quantum Mechanism IDs

OASIS published PKCS#11 Version 3.0 (officially OASIS PKCS11-v3.0) with formal post-quantum mechanism identifiers:

Table 2.9. PKCS#11 3.0 Post-Quantum Mechanism IDs (OASIS PKCS11-v3.0)
Mechanism CKM ID Algorithm
CKM_ML_KEM_KEY_PAIR_GEN 0x00004200 ML-KEM-512/768/1024 keygen
CKM_ML_KEM_ENCAPSULATE 0x00004201 ML-KEM encapsulation
CKM_ML_KEM_DECAPSULATE 0x00004202 ML-KEM decapsulation
CKM_ML_DSA_KEY_PAIR_GEN 0x00004210 ML-DSA-44/65/87 keygen
CKM_ML_DSA 0x00004211 ML-DSA sign/verify
CKM_SLH_DSA 0x00004220 SLH-DSA (SPHINCS+) sign/verify

The CKA_PARAMETER_SET attribute on key objects specifies the parameter set (e.g., CKP_ML_KEM_768 or CKP_ML_DSA_65).

2.14.4 HSM-as-a-Service: Azure Managed HSM and GCP Cloud HSM (2024)

The HSM-as-a-Service model matured in 2024 with significant updates:

Table 2.10. HSM-as-a-Service Platforms Comparison (2024)
Service FIPS Level PQC Support 2024 Updates
Azure Managed HSM FIPS 140-3 L3 Preview (ML-DSA) Sovereign key rotation; Managed Identity binding
AWS CloudHSM v3 FIPS 140-3 L3 No (roadmap) Multi-AZ auto-failover; new CLI
GCP Cloud HSM FIPS 140-2 L3 No Cloud KMS Autokey; HSM key attestation
IBM Cloud HSM FIPS 140-2 L4 No z/OS CEX8 integration

Warning: FIPS 140-2 L3 vs. FIPS 140-3 L3 is not equivalent. The newer 140-3 standard aligns with ISO/IEC 19790:2012 and adds stricter entropy source requirements, software/firmware security, and physical attack testing. Verify the exact CMVP certificate number for each deployment, not just the self-reported level.

2.14.5 Thales Luna Network HSM 7.x PQC Firmware (2024)

Thales released a post-quantum firmware update for existing Luna Network HSM 7 hardware in mid-2024, enabling field upgrade of deployed units without hardware replacement:

  • PQC algorithms added: ML-DSA-44, ML-DSA-65, ML-DSA-87; ML-KEM-512, ML-KEM-768; SLH-DSA-SHA2-128s

  • Hybrid certificate support: Luna SDK 8.5 generates X.509 certificates carrying both an ECDSA P-256 public key and an ML-DSA-65 public key in a SubjectAltName extension

  • Migration tooling: lunacm command hagroup addmember transparently replicates PQC keys to all cluster members

  • FIPS status: PQC mechanisms are non-FIPS pending CMVP validation; existing FIPS-approved mechanisms remain available in parallel

2.14.6 HSM Post-Quantum Migration Strategy: Hybrid Keys and Dual-Algorithm Signing

Industry consensus (NIST IR 8547, 2024) recommends a hybrid approach during the transition to post-quantum cryptography in HSM deployments:

Table 2.11. Hybrid PQC Migration Strategy for HSMs
Phase Timeline Action
Inventory 2024 Audit all HSM-protected key types; classify by longevity requirement
Hybrid KEM 2024–2025 Implement X-Wing (ECDH + ML-KEM-768) for TLS key exchange
Hybrid signing 2025–2026 Generate dual-algorithm CA certs (ECDSA + ML-DSA)
Validation 2026 Await CMVP validation of PQC mechanisms in HSM firmware
Classical sunset 2028+ Deprecate RSA-2048 / ECDSA P-256 for long-lived keys

Note: The X-Wing hybrid KEM (IETF draft-irtf-cfrg-xwing) combines X25519 with ML-KEM-768 into a single KEM mechanism. It is the recommended hybrid for TLS 1.3 supported_groups extension in the 2024–2026 transition window.

2.15 Exercises

Exercises

  1. Explain the difference between tamper evidence, tamper resistance, and tamper response in FIPS 140-3 terminology. Give a physical mechanism example for each concept, specifying which FIPS level each mechanism corresponds to.

  2. A bank deploys a Thales payShield 10K HSM for PIN processing. The HSM uses 3DES for legacy PIN block encryption (ISO 9564 Format 0). PCI DSS 3.2.1 requires migration to AES by 2024. Describe the key migration procedure including key types, TR-31 key blocks, and HSM commands required.

  3. Describe the M-of-N smart card authentication scheme used in HSM key ceremonies. If N=7 and M=4, how many distinct groups of custodians can reconstruct the key? What are the security properties of Shamir Secret Sharing used to implement this?

  4. Compare the security architecture of AWS CloudHSM, Azure Dedicated HSM, and Azure Managed HSM. For each: (a) which physical hardware is used, (b) FIPS level, (c) who holds the HSM admin credentials, (d) network isolation model.

  5. You discover that a deployed HSM has PKCS#11 attribute CKA_EXTRACTABLE = TRUE on the TLS private key. What are the security implications? How would an attacker exploit this? What procedure should be followed to remediate?

  6. Design a PKCS#11-based code signing service for a software company signing 500 releases per day. Requirements: (a) air-gapped signing workstation, (b) dual control (two engineers must approve each signing), (c) audit log with date/time/signer. Specify the HSM product, authentication mechanism, and workflow.

  7. Explain the Anderson-Bond HSM API attack discovered at Cambridge in 2003. What two specific PKCS#11 commands were combined to extract key material? What PKCS#11 attribute was missing that would have prevented this attack?

  8. A retail payment terminal uses DUKPT (Derived Unique Key Per Transaction) with Base Derivation Key (BDK) stored in an acquiring bank HSM. Explain: (a) how DUKPT derives unique keys per transaction, (b) what happens if the BDK is compromised, (c) why DUKPT is preferred over a shared PEK for large terminal deployments.

  9. Calculate the number of RSA-4096 sign operations per second possible on a Thales Luna PCIe HSM 7 (10,000 RSA-2048/s). Justify your estimate using operation count analysis. How many such HSMs are needed for a Certificate Authority signing 1 million certificates per day with RSA-4096?

  10. A post-quantum migration plan requires adding ML-DSA-65 (Dilithium3) support to an existing Thales Luna HSM infrastructure. What are the firmware update requirements, key size implications (1,952 B public key, 4,000 B private key), and PKCS#11 mechanism IDs? How would hybrid classical+PQC signing be implemented?

  11. Write a complete PyKCS11 Python script that: (a) initializes the PKCS#11 library, (b) generates an AES-256 key with CKA_EXTRACTABLE=False, (c) encrypts a 64-byte message with AES-CBC, (d) decrypts and verifies. Include error handling for CKR_PIN_INCORRECT and CKR_TOKEN_NOT_PRESENT.

  12. Describe the zeroization process for an HSM upon tamper detection. What triggers zeroization (list 5 sensors)? What is zeroized? What is the minimum time specification for zeroization in FIPS 140-3? After zeroization, what is the device state and recovery procedure?