Unprivileged Architecture: Instructions and Architectural States
Introduction
KLE lets software perform high-performance cryptographic operations without direct access to the keys or other critical derived values. KLE achieves this through the concepts explained next.
Foundational Principles and Definitions
Principles are labeled Pn, where n is a sequential number. The most important ones define what the KLE architecture is about:
These four Principles prompt the definition of a Cryptographic Context:
- Definition: Cryptographic Context.
-
Most KLE instructions run within the constraints set by a Cryptographic Context (CC). A CC is an indivisible structure consisting of a Metadata Header (MDH), with a fixed format and length, and a Content, whose size depends on the MDH. The Content holds the secrets, such as keys, and other sensitive material, as well as public material derived from the secrets, such as public keys. The MDH binds the use of the information in the Content to one set of cryptographic algorithms, and, optionally, to a process, VM, security state, boot cycle, expiration date, or other policies. The MDH requires integrity, except for ADSDropped, an unauthenticated format hint (AuxDataLen and ADSDropped Fields); the Content requires integrity, as well as confidentiality for all the information that is not supposed to be public (such as public keys). KLE and the algorithms it implements enforce these requirements architecturally.
Multiple CCs can be active at the same time; a caller must be able to configure them as needed. This requires an architectural place for them.
| P6 |
Resource management is architectural: resources are managed by software, and their exhaustion is reported by the architecture so that software can take the necessary actions. |
KLE realizes this Principle by defining Cryptographic Lockers and the means by which the architecture manages them.
- Definition: Cryptographic Locker.
-
Cryptographic Lockers (lockers for short) are per-hart architectural containers that safeguard their contents. CCs are created by writing Metadata and Content into a locker, a process called Provisioning, which also binds them to each other. A CC is usable only while in a locker, where only the KLE unit accesses or modifies it, under the rules of the architecture and of the algorithm; no instruction returns its secrets in clear, except where the algorithm allows it.
A KLE implementation supports 32 lockers.
| P7 |
KLE is scalable: it works on small and larger cores, with and without vector registers. |
| P8 |
Instructions perform tasks that are as simple as possible, in accord with the RISC-V philosophy, while code sequences stay short. An instruction performs a complex task only if it is necessary for security reasons, i.e., when breaking it up further would lead to a violation of a security-related Principle, such as P1, P2, P12, P15 and P16. |
| P9 |
Minimize the pressure on the instruction encoding space. |
Embedding the algorithm’s encoding in the MDH is the main mechanism implementing P9.
Algorithms are implemented by KLE Machines:
- Definition: KLE Machine.
-
A KLE Machine (short: Machine) is a state machine that implements one or more cryptographic functions (primitives, modes, protocols) through the interface of this specification. Fields in the MDH fully identify it. A small set of KLE instructions operates all Machines: their inputs and outputs come from vector registers, GPRs, and memory, and their semantics depend on the Machine.
Encapsulating Machine-specific behavior in the MDH rather than the instructions lets different primitives (e.g., AES-128, AES-256 and SM4) be used in the same modes (e.g., ECB, GCM-SIV and XTS) without changing the compiled code, and supports side-channel-resistant variants transparently.
| P11 |
Besides the operations that are always allowed by the architecture, a Machine admits only the sequences of operations that its specification defines. |
Machines use the state of Principle P5 to enforce this Principle.
CCs are saved and restored by generating Sealed Cryptographic Contexts:
- Definition: Sealed Cryptographic Context.
-
For context switching, a CC can be exported from a locker as a Sealed Cryptographic Context (SCC), an authenticated representation, encrypted except for its public values, that can later be imported into a locker. Export and import use a Context Sealing Key (CSK), which M-mode may be able to program. An SCC sealed under one CSK cannot be imported under another, which separates spatial and temporal domains cryptographically. An SCC leaves in clear only its MDH and its clear blocks (Rule GR9), all authenticated except the ADSDropped bit of the MDH; the image of a locker in an Error State is an unauthenticated MDH and carries no Content (Export and Import of a Locker in an Error State).
P16 is the same principle behind NIST’s key-management recommendations on the associations of a key with its usage and related information (NIST SP 800-57 Part 1 Rev. 5 cite:[nist-SP-800-57-p1-r5], §§6.2.1.4 and 6.2.1.6) and on the cryptographic strength, separation and context binding of derived keys (NIST SP 800-108 Rev. 1, Update 1 cite:[nist-SP-800-108-r1], “Security Considerations”).
Finally, KLE instructions are subdivided into classes, each usable only in certain contexts. Instructions that use the secrets in CCs are bounded by usage policies, whereas those that, for instance, save and restore SCCs can be used at any time. Principles P13 and P14 prevent denial of service on the resources of the KLE implementation.
- Definition: Instruction Classes and Usage Control.
-
KLE distinguishes between management operations and usage operations on CCs and lockers. The management operations are provisioning, SCC import, and export of a locker as an SCC; clearing a locker, i.e., freeing it and deleting any secret it contains, is a separate configuration instruction. None of these uses the secrets of a locker for the operations of its Machine. None changes the Machine or the Usage Control policies of a Valid locker, except through the narrowing, provisioning and import defined for it. Usage operations are cryptographic operations and state changes. To prevent denial of service, management operations and clearing are less restricted than usage operations: Usage Control policies restrict only usage operations.
- Definition: Localities.
-
KLE can bind a CC to Localities, which restrict where its exported SCCs can be imported and so where it can be restored and used: specific devices or device classes, hardware configurations, physical or virtual boot cycles, and process domains at various privilege modes.
The entire architecture follows from these Principles and Definitions.
Architectural Model
KLE is architected as an interface to an attached unit: its instructions behave like messages over a tightly coupled coprocessor interface, and the KLE unit executes them independently of the issuing hart and returns the results.
This keeps the hart side simple: software implements the locker-configuration logic, the KLE unit the cryptography, and several cores may share one KLE unit.
The specification defines only architectural behavior, not implementation: KLE may be integrated into a CPU core or be a distinct hardware unit; either way each client hart has separate KLE architectural state, and the same code runs on both.
KLE may be emulated, partly or completely, in M-mode firmware: an implementation may, for example, perform symmetric operations (Symmetric Cryptography) in the KLE unit and emulate public-key cryptography (Elliptic Curve Cryptography, Post-Quantum Public-Key Cryptography), whose very large states then reside in secure memory that meets the requirements of The Cryptographic Locker File and Authentication Information, such as on-chip SRAM reserved for M-mode.
No instruction may make key material or other locker state that the KLE holds accessible in the clear to any privileged mode except M-mode and authenticated Debug mode, which is Debug mode while the External Debug Security extension (Prerequisites) authorizes external debugging of M-mode.
The only locker state exported in the clear is what the software that opened the operation supplied: the Content of a partial provisioning (Management States and Formats), and the data loaded by an unfinished system-specific import (Rule GR50); since any mode can export it, that software clears or completes the operation before another software context runs (Rule SR1).
A misuse that Rule MR15 leaves to the caller, such as the reuse of an IV, can still reveal locker state derived from the key, such as the GHASH key of GCM (Accepted Risks).
KLE implementations in S/VS-mode or HS-mode are forbidden: instructions and Machines may be emulated only in M-mode.
Trap-and-emulate and on-demand (lazy) SCC import rely on the *llockerstatus CSRs (mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking).
Prerequisites
A conformant KLE implementation requires the RISC-V External Debug Security extension cite:[riscvExternalDebugSecurity].
It requires the KLE exceptions of Exceptions Raised by KLE to be implemented and raised as the unprivileged architecture mandates, whether or not the other parts of the KLE Privileged Architecture are implemented.
Where the KLE unit or its Machines need an RBG, they must use an entropy source that meets the requirements of the Zkr extension (chapter “Cryptography Extensions: Scalar & Entropy Source Instructions”, section “Entropy Source” cite:[RISCV-ISA-Unpriv]), used to seed a DRBG compliant with NIST SP 800-90A cite:[nist-SP-800-90-r1] or with another standard that the implementation documents.
The DRBG must be instantiated with a security strength of at least 256 bits and reseeded from that entropy source at the interval its standard prescribes; another standard may replace SP 800-90A only if it provides at least this strength.
Rule GR45 covers RBG failure.
Endianness
As defined in Values, Bits, and Byte Strings, a PI, an SCC and a PCCC (cf. Management States and Formats) are byte strings: a value V of 8n bits in them, the MDH (cf. Metadata) included, occupies n consecutive bytes, byte i holding V[8i+7:8i], whatever the data endianness (mstatus.MBE, SBE and UBE, and with the H extension hstatus.VSBE and vsstatus.UBE) of the hart.
KLE memory instructions follow this mapping, and those bits do not affect them.
Software on a hart with big-endian data accesses that moves an MDH between memory and GPRs, or vector elements wider than 8 bits, converts its byte order, for instance with rev8, or uses byte accesses.
This convention lets CCs migrate between harts of different endianness.
Extensions Overview
The principal KLE instructions, defined in full in Instructions, are:
-
kl.setstmoves the CC in a locker between the states of its Machine. -
kl.mgmtmoves a locker through its management lifecycle, and, with the management transfer instructionskl.load,kl.store,kl.mvin, andkl.mvoutperforms the management operations (Provisioning, Import, and Export), each in several instructions, except on a locker in an Error State (Export and Import of a Locker in an Error State):-
provisioning loads metadata and clear Content into a locker, binding them;
-
export writes a locker to memory as an SCC;
-
import loads an SCC into a locker.
-
-
kl.clearunconfigures and clears a locker. It is a pseudo-instruction ofkl.setst, and never part of a management operation. -
kl.execperforms the cryptographic operations that the Machine configured in a locker defines for the locker’s current state. -
kl.getmd*reads the metadata of a locker. The pseudo-instructionkl.getst, built onkl.getmdl, extracts the state of a locker from its MDH and reports errors.
KLE comprises several sub-extensions. Those that define ISA features are given in Table 1; those that define cryptographic algorithms are listed in Machine Type and Mode Encodings, corresponding Extensions.
Extension |
Features |
Defined in: |
|
Support for vector registers. |
|
|
Support for streaming instructions and the KLIOBUF. |
|
|
Dedicated memory instructions. |
|
|
Dedicated move instructions. |
|
|
Support for the ExpirationDate metadata field. |
Zkl conformance requires:
-
at least one of
ZklvandZklio; -
AES-128, AES-192 and AES-256 in ECB and GCM modes, AES-128 and AES-256 in GCM-SIV mode, and SHA2-224, SHA2-256, SHA2-384, SHA2-512, SHA2-512/224 and SHA2-512/256, as defined in Unprivileged Architecture: Machines; and
-
Zklmem, in hardware or by trap-and-emulate (KLE Emulation Control in mstatus); in the latter caseZklmvin hardware.
KLE instructions may raise the standard RISC-V exceptions and a few KLE-specific exception types, listed in Exception causes in decreasing priority order.
Zklv requires the KLV subset of the vector extension (RVV/KLV) with VLEN ≥ 128, that is, Zvl128b or a larger Zvl*b, which every vector Form that carries an MDH or a 128-bit block needs.
With trap-and-emulate, the hardware raises an illegal-instruction exception for instructions it does not implement, which the platform must deliver to M-mode (medeleg bit 2 zero).
The emulating code moves data between memory and the locker with Zklmv.
kl.load and kl.store are always present; Zklmv and Zklexpire are otherwise optional.
Table 2 gives, for each instruction and for each CSR that software below M-mode accesses through KLE instructions, the extension that defines it and its Forms or availability with Zklv and with Zklio.
| Instruction / CSR | Defined by | With Zklv |
With Zklio |
|---|---|---|---|
|
|
Forms A–C |
Forms A and B |
|
|
Forms A–D |
Form D, natively or as the substitution (Rule GR10) of a Form A–C |
|
|
GPR and vector variants |
GPR and KLIOBUF variants; each only when |
|
|
Forms A–D |
Forms A, B and D |
|
|
Available |
|
|
|
Forms A, C and D |
Forms A and D |
|
|
Available |
|
|
|
Available |
— |
|
|
Available |
|
|
|
— |
Available |
|
|
Available |
|
|
|
Available |
— |
|
|
Available |
|
|
|
Available |
|
|
|
Always present, in hardware or by trap-and-emulate, per the conformance requirements above |
|
|
|
— |
Available |
|
|
— |
Available |
|
|
Always present |
|
|
|
Always present |
|
Architectural State and Operand Sources
Cryptographic Lockers
KLE defines 32 Cryptographic Lockers, K0–K31: per-hart architectural state that, like GPRs and vector registers, is the same in every privilege mode.
Unlike a register, a locker can be unconfigured, holding no CC.
Instructions address a locker by a 5-bit immediate; some may instead name the named locker, KLNL, whose number a CSR holds.
A configured locker K(i) holds a CC: its Metadata Header K(i).MDH and its K(i).Content (Foundational Principles and Definitions).
During import and export, and in an SCC, the content is two consecutive arrays of 128-bit blocks:
Content1, the architected content that Unprivileged Architecture: Machines specifies for each Machine,
and Content2, any implementation-specific content.
The Cryptographic Locker File and Authentication Information
Lockers reside in a per-hart cryptographic locker file (KLF), a memory that only the KLE implementation can access; where the implementation is emulated, in part or in full, only M-mode firmware accesses it, through an implementation-defined mechanism that the implementation must provide.
The KLF protects the confidentiality and integrity of its contents, also against rollback through any access that this specification does not define.
Every path that handles a locker’s secrets, emulated ones included, must resist timing, other side-channel and fault-injection attacks at least as well as the locker’s Machine at its SCProtection level (SCProtection Field), and a path that serves several levels, at the highest of them.
These paths are reconstruction, re-sharing, KLF access, SCC_KeyDeriv, SCC_Encrypt and SCC_Decrypt in export and import (SCC Export and Import Algorithms), system-specific import (Rules for the Import of a System-Specific Format), and every use of the CSK and its derived keys.
Only the implementer’s certifications, if any, establish what an implementation achieves.
The KLE unit computes the functions SCC_KeyDeriv, SCC_Encrypt and SCC_Decrypt with the AES and POLYVAL hardware of its Machines, and
for the import and export of lockers implementing a Machine at a certain SCProtection level, these functions must offer the same or higher level of side-channel and fault-injection attack protection.
One risk is accepted: these keys seal every SCC, so with several levels, each SCC resists differential side-channel and fault-injection attacks only as well as the least-protected engine that uses them (Discussion Points).
|
| Unlike the KLF, an SCC does not resist rollback: while it exists, any party that holds it, such as the software that stores it or any mode that could export the locker, can import it again under the same CSK and Localities and so replay an earlier CC state. This may enable multi-time-pad or nonce-reuse attacks on the Machines that rely on a fresh IV, nonce or counter: CBC, CFB, OFB, CTR, XCTR, GCM, OCB, Ascon-AEAD128 and, for message equality only, GCM-SIV. A CC owner must trust the party that stores its SCCs for freshness, clear its lockers before another software context runs (Rule SR1), use a Machine whose security survives replay, or accept the risk; policies cannot readily tell misuse from legitimate re-import, such as a retry after payload corruption. |
Architecturally, whatever the implementation, the KLF has two parts:
-
32 128-bit blocks, the i-th holding the MDH of
K(i), so that every locker holds its MDH, if only to show that it is unconfigured; and -
an implementation-defined amount of dynamically allocated memory that holds the
Contentof every configured locker.
“KLF capacity” refers only to the second part: a locker that holds only its MDH consumes none, and what a configured locker consumes depends on its MDH (Length of External Formats and KLF Capacity Usage of a Locker). Insufficient capacity may prevent a configuration instruction from executing; unconfiguring other lockers frees capacity. The number of lockers, 32, comes from the 5-bit register fields of the encoding, not from the capacity, and an implementation need not hold 32 configured lockers at once. The capacity must suffice for two fully configured CCs of the largest Machine that the implementation supports, each with the largest ADS that the implementation keeps for it, together with any state that the implementation needs while it operates on them. If system-specific formats, that is, formats other than those of KLE, are supported, it must also cover the largest amount by which the import of a system-specific format needs more memory than the import of a KLE format of the same Machine. Further capacity is desirable, but not required.
Corruption of a hart’s KLF is unrecoverable: it resets the hart’s KLE architectural state (KLE Unit Reset and M-mode-only Harts) and raises a KLE fatal-error exception (Exceptions Raised by KLE).
The KLE unit holds three 128-bit authentication registers, SIV, IMPQUAL and SIV2, with the authentication and identification data of a locker whose import or export is open, without recording which locker that is (Ownership of Authentication Registers); kl.load, kl.store, kl.mvin and kl.mvout access them as the leading bytes of the image (kl.mvin and kl.mvout).
The export-opening kl.mgmt of a Valid locker writes SIV, and also IMPQUAL and SIV2 if the AuxDataLen of the locker’s MDH is at least 2.
An import-opening kl.mgmt, other than the short import of an Error-State locker (Export and Import of a Locker in an Error State), zeroizes all three before the kl.load or kl.mvin that writes them.
RVV/KLV
KLE takes its inputs and outputs from vector registers, from an architectural input/output buffer (KLIOBUF) loaded from and stored to memory, or from both.
Vector registers need only a minimal subset of the V extension, KLV (KLE-subset of V).
KLV must be fully opcode-compatible with RVV: code written for KLV behaves identically under V with Zvbc, for the vector configurations that KLV supports.
KLV comprises:
-
vector registers of at least 128 bits;
-
the CSRs
vstart,vl,vtypeandvlenb, with their RVV 1.0 semantics; -
the configuration-setting instructions
vsetvli,vsetivliandvsetvl, with:-
tail-agnostic and mask-agnostic configurations only, since KLE neither uses vector masking nor defines masked instructions, and always applies a tail-agnostic policy (bit 25 of the
kl.execencoding is reserved for masked operations, should a compelling use case arise); -
SEWvalues 8, 16, 32 and 64, withELEN= 64; -
LMULvalues 1, 2, 4 and 8; and -
for a configuration that KLV does not support,
vtype.villis set andvl= 0, as in RVV; a KLE instruction with a vector operand raises an illegal-instruction exception ifvtype.villis set;
-
-
the unit-stride loads and stores
vle<eew>.vandvse<eew>.vof element widths 8, 16, 32 and 64 whoseEMULis 1, 2, 4 or 8; an implementation that provides KLV without V raises an illegal-instruction exception for such an access whoseEMULis fractional; -
the whole-register loads, stores and moves
vl<n>re<eew>.v,vs<n>r.vandvmv<n>r.v, for context switches; -
vmv.x.s,vmv.s.x, and the slidesvslideup.v[xi],vslidedown.v[xi],vslide1up.vxandvslide1down.vx, to move data into and out of vector registers; -
the logical operations
vand.v[vxi],vor.v[vxi]andvxor.v[vxi](the immediate forms give, for instance, a bitwise NOT); and -
vclmul.v[vx]andvclmulh.v[vx]ofZvbc, forSEW= 64 only, as inZvbc; they may be trap-and-emulated.
KLV requires the listed instructions only with vm = 1; their masked encodings are reserved.
Floating-point, fixed-point and general arithmetic vector operations are not required.
KLE has no concept of an element, and it is not part of the vector unit: it sees a vector register (including a vector register group if LMUL > 1) as a bit string of length KLLEN = VL × SEW, where VL is the vector length in effect (vl).
|
KLE takes the length of a vector operand from VL × SEW alone (VL = 2 with SEW = 64 and VL = 4 with SEW = 32, for example, both give 128 bits): the CPU decode side uses VL and SEW to determine how much data to send to the KLE unit, which needs only their product.
KLIOBUF
When Zklio is implemented, the architectural input/output buffer KLIOBUF may replace vector registers.
The KLIOBUF is per-hart architectural state, not separated by privilege mode, but it is not part of the KLF.
The Zklio instructions kl.input and kl.output transfer data between the KLIOBUF and memory, and the base extension kl.exec then uses Forms whose inputs and outputs are implicitly in the KLIOBUF (Zklio).
kliobuftop defines KLLEN for KLIOBUF operands.
Metadata
An SCC carries two kinds of metadata:
-
the 128-bit MDH, always present, which determines the Machine, the key type and the key’s usage policies; its first 64 bits determine the length of a PI or SCC; and
-
the optional 128-bit Implementation Qualifier
IMPQUAL, which copies the three KLE analogues of the hart’smvendorid,marchidandmimpidCSRs, namelymklvendorid,mklarchidandmklimpid(AuxDataLen and ADSDropped Fields gives the format ofIMPQUAL). It is present when an SCC has AuxDataLen ≥ 2, and lets an implementation determine whether it can use the implementation-specific content of the SCC (AuxDataLen and ADSDropped Fields).
In the rest of the document, “metadata” refers to the first type. The implementation qualifier is always called IMPQUAL.
Table 3 summarizes the MDH fields, which the following subsections describe.
| Field | Size | Name | Description |
|---|---|---|---|
[11:0] |
12 |
Machine |
The Machine the key material is bound to. See Machine and MachinePolicy Fields. |
[13:12] |
2 |
MachinePolicy |
The allowed variants of the Machine, for instance encryption, decryption or both for a symmetric cipher. See Machine and MachinePolicy Fields. |
[15:14] |
2 |
MachineExtension |
Zero, or a variant of the Machine that the Machine defines. See Machine and MachinePolicy Fields. |
[17:16] |
2 |
SCProtection |
Side-channel protection level. See SCProtection Field. |
[23:18] |
6 |
State |
Current state of the locker and its Machine. See State and StateExtension Fields. |
[27:24] |
4 |
StateExtension |
Additional state information. See State and StateExtension Fields. |
[29:28] |
2 |
KeyType |
Key given by value, by a system key, or randomly generated. See KeyType Field. |
[31:30] |
2 |
Reserved |
Reserved. |
[45:32] |
14 |
AuxDataLen |
Length of the ADS in 128-bit blocks, zero if none; with ADSDropped = 1, the length before |
[46:46] |
1 |
Reserved |
Reserved. |
[47:47] |
1 |
ADSDropped |
Set if |
[61:48] |
14 |
MachineUse |
Machine-specific information, or implementation-specific in the bits and States where the Machine does not use it. See MachineUse and AuxInfo Fields. |
[63:62] |
2 |
Version |
MDH format version. See Version Field. |
[68:64] |
5 |
UsagePolicy |
The privilege modes that may use the locker. See UsagePolicy Field. |
[77:69] |
9 |
Locality |
Zero, or the Locality Secrets the CC is bound to. See Locality Field. |
[79:78] |
2 |
Reserved |
Reserved. |
[95:80] |
16 |
AuxInfo |
Machine-specific information, or implementation-specific in the bits and States where the Machine does not use it. See MachineUse and AuxInfo Fields. |
[115:96] |
20 |
ExpirationDate |
If non-zero, the expiration date of the CC. See ExpirationDate Field. |
[127:116] |
12 |
Reserved |
Reserved. |
Machine and MachinePolicy Fields
Machine is a 12-bit field. Values 0–3071 are architecture-defined, with encodings maintained by RVI (Unprivileged Architecture: Machines); the remaining values are for custom Machines.
The meaning of MachinePolicy depends on the Machine:
-
For encryption/decryption primitives and modes, bit 0 of MachinePolicy permits encryption and bit 1 decryption.
-
For asymmetric primitives that support signatures, bit 0 permits their generation and bit 1 verification.
-
For MACs that generate and verify tags, bit 0 permits generation and bit 1 verification.
MachineExtension is zero unless the Machine defines a non-zero value; the values defined are 1 and 2 for the Elliptic Curve Machines, which select their public-points and sealed variants (Elliptic Curve Cryptography), and 1 for ML-KEM, which selects its sealed variant (ML-KEM). Other values are reserved, and may in the future encode more Machines.
Rule MR1 states how MachinePolicy gates the States of a Machine, and which values are valid.
SCProtection Field
KLE defines three side-channel protection levels, Levels A, B and C, encoded in SCProtection as the values 0, 1 and 2. Value 3 is reserved, and makes the Metadata invalid (Validity of Metadata). cite:[riscvPlatformSecurityModel] gives the threat model and security concepts in which these levels are used.
| Value | Level | Description |
|---|---|---|
0 |
A |
No timing leakage: the same cryptographic operation on the same number of input units takes the same time in the KLE unit, whatever the values of the key, of the internal state, of the input data and of any random value drawn for the operation, except for the dependence that the cryptographic method itself requires (below). |
1 |
B |
No timing leakage; differential side-channel protection. |
2 |
C |
The protection of Level B; detection of injected faults, followed either by completion with the correct result and no other physical leakage, or by a transition to a fatal error condition (see Error Handling Architecture). |
A level applies to the export and import of the locker (The Cryptographic Locker File and Authentication Information) and to the operations that need it for security, such as signature generation but not signature verification, and only as far as the cryptographic method of the Machine needs it: the execution time of ML-DSA, for instance, may depend on the number of iterations of its rejection loops (ML-DSA).
A side-channel-protected Machine is an implementation variant of the unprotected one, distinguished architecturally only by the SCProtection field of the MDH.
An implementation must document, for each level it supports, the standard and edition, assessment profile, security level and test metrics it meets, such as acquisition-time limits and trace sample sizes; Level B, resp. C, must offer at least the guarantees documented for Level A, resp. B.
|
This specification gives no assurance profiles for these levels. A CC provider that sends its keys to a secure receiver, such as a TEE applet that forwards the CC to the software consuming it, negotiates the protection level and its assessment profile with it by a system-specific mechanism. Relevant references are ISO/IEC 19790:2025 cite:[ISOIEC-19790-2025] for the security requirements of cryptographic modules, ISO/IEC 24759:2025 cite:[ISOIEC-24759-2025] for their testing, ISO/IEC 17825:2024 cite:[ISOIEC-17825-2024] for testing the mitigation of non-invasive attacks, and FIPS 140-3 cite:[nist-fips-140-3], which adopts ISO/IEC 19790:2012 and ISO/IEC 24759:2017 with CMVP modifications; and NIST SP 800-140F cite:[nist-SP-800-140F]. |
State and StateExtension Fields
State tracks the state of a locker and its Machine: Unconfigured, encrypting or decrypting, initializing, absorbing into or finalizing a hash, computing point multiples, signing or verifying, or in an error state, for instance. StateExtension keeps further state information, usually orthogonal or additional to State. The tables in this section give the values of State and StateExtension common to all Machines, including that of a locker with no Machine, and the States used for CC management.
| Value | Mnemonic | State Name | Description |
|---|---|---|---|
0 |
|
Inert |
The locker holds no Content: it is Unconfigured or in an Error State (Table 7) (see the definition of Definition: Inert Locker.). |
| Value | Mnemonic | State Name | Description |
|---|---|---|---|
1 |
|
Ready |
Ready for operation; also the state of a newly provisioned CC. |
2-53 |
Defined by the Machine encoded in Machine. |
||
54 |
|
Success |
The Machine completed successfully. No further cryptographic operation may be performed until the locker is reconfigured or returned to Ready (Rule GR19.3). |
55 |
|
Failure |
The Machine completed with a negative result; otherwise as in State Success. |
The Valid States are States 1–55: State 1 is Ready, States 54 and 55 are Success and Failure, and the Machine defines States 2–53. The Valid States and the Error States are the Complete States.
States 56–63, used during management operations, are the Configuration States; 61–63 are reserved.
With State set to 0, StateExtension encodes Error State as well as the state when a locker holds no CC, i.e., the Unconfigured State.
| Value | Mnemonic | State Name | Description |
|---|---|---|---|
0 |
|
Unconfigured |
Not an Error State: the locker holds no valid CC. |
1 |
|
Unsupported |
Unsupported Machine or Machine variant, KeyType, protection level, or a field value that the Machine declares unsupported (Validity of Metadata). |
2 |
|
Invalid |
The locker has been invalidated by invalid Metadata, by an operation not permitted in its current State, or by another error that the architecture or the Machine reports as Invalid (Error Handling Architecture). |
3 |
|
Out of Memory |
Insufficient KLF memory for a configuration instruction. A KLE out-of-memory exception handler that cannot free enough memory sets it with |
4 |
|
Authentication Failed |
Authentication failure while completing an SCC import or a locker export, or a failed check that a system-specific format defines, when the format authenticates its data (Rule GR51). |
5 |
|
Privilege Violation |
Narrowing of a policy attempted without sufficient privilege or Locality, or any other failed narrowing, or a transfer to a lower SCProtection (Rules GR30 and GR51). |
6 |
|
Expired |
The locker has expired. Not in effect without |
7-15 |
(Reserved) |
Reserved. |
- Definition: Unconfigured Locker.
-
A locker is Unconfigured when State and StateExtension are 0: every other field of the MDH then reads zero and has no meaning, and the locker has no Usage Policy, Expiration Date or Key Type. An Unconfigured locker holds no Content beyond the MDH.
- Definition: Error State.
-
A locker is in an Error State, which reports a KLE error, when State is 0 and StateExtension is 1–6: StateExtension holds the code of the Error State (Table 7). A locker in an Error State holds no Content beyond the MDH, whose other fields keep their values except as Rule GR15 states. Entering an Error State overwrites StateExtension with its code, and no Machine defines a StateExtension @ State 0. The Error-State image of such a locker (Export and Import of a Locker in an Error State) consists only of the MDH.
- Definition: Inert Locker.
-
An Inert locker is either Unconfigured or in an Error State, or the named locker
KLNLwhileklnamedlocker= 32.
A locker is said to be invalidated when it transitions to Error State Invalid (i.e., State = 0 and StateExtension = kl_stateext_invalid).
Without Zklexpire, no locker can be in Error State Expired, and a PI, SCC or PCCC whose MDH carries StateExtension 6 at State 0 is invalid.
A locker being provisioned, exported or imported is in one of the following Configuration States:
| Value | Mnemonic | Description |
|---|---|---|
56 |
|
The locker is being configured. |
57 |
|
The locker is being exported as an SCC, its contents authenticated and, except for their public values, encrypted. |
58 |
|
An SCC is being imported into the locker. |
59 |
|
The locker, whose base operation is a provisioning (see Management States and Formats), is being exported; its image has the format of a PI. |
60 |
|
Such an image is being re-imported. |
61-63 |
(Reserved) |
Reserved. |
Rules Governing the State and StateExtension Fields and their Transitions defines the behavior of lockers and SCCs in these States.
Figure 1 shows these States and the default transitions between them, which apply to all Machines. The legend of the graph is:
-
Double-bordered ellipses: the Unconfigured State, and all Configuration States.
-
Single-bordered rounded rectangles: the Valid States.
-
Double-bordered rounded rectangles: the Error States.
-
Continuous edges: transitions induced by usage instructions.
-
Dashed edges: transitions induced by reaching the expiration date.
-
Dotted edges: transitions induced by configuration operations.
KeyType Field
KeyType states how the keys of a CC are supplied:
-
0: by value; the keys are provisioned, exported and imported as values.
-
1: by a system-specific, 64-bit System Key Identifier (SKID) (System Keys).
-
2: generated randomly by the
kl.mgmtthat completes a base (non-nested) provisioning, all keys of the Machine at once unless the Machine states otherwise; an RBG failure follows Rule GR45. The PI has the layout of one with KeyType = 0, and the generated values replace its key values. KeyType then becomes 0, so the keys are exported by value; KeyType = 2 occurs only in a PI, in a PCCC of base typepiand in a locker being provisioned from them (Management States and Formats). -
3: reserved; a PI or SCC that carries it is invalid Metadata (Validity of Metadata).
| A SKID may refer to keys with unrelated purposes on different devices; the System Key Store (SKS) therefore supplies a Locality for it (Rule GR55.3). |
AuxDataLen and ADSDropped Fields
AuxDataLen gives the length, in 128-bit blocks, of the Auxiliary Data Section (ADS), the variable-size, implementation-specific part of the content: 0 means no ADS, and the maximum, 214 − 1, is 262,128 bytes.
With ADSDropped = 1, it keeps the length from before Content2 was dropped.
With Version = 3, it instead gives the length of the data of a system-specific format (Rules for the Import of a System-Specific Format), and no rule that reads it as the length of an ADS applies: such an MDH has no ADS, IMPQUAL or SIV2, and its ADSDropped stays 0.
If AuxDataLen ≥ 2, the SCC includes IMPQUAL, a 128-bit copy of the implementation qualifier of the originating implementation (mklvendorid, mklarchid, and mklimpid):
IMPQUAL := zeros(32) @ mklimpid[31:0] @ mklarchid[31:0] @ mklvendorid[31:0].
The importing implementation uses the ADS only if all 128 bits equal its own IMPQUAL; there is no other compatibility rule.
An implementation that produces an ADS must leave KLE unit reset with values of mklvendorid, mklarchid and mklimpid that no implementation with a different ADS format has, and with mklvendorid and mklarchid not both 0.
An M-mode handler that emulates a Machine and writes an ADS for the lockers it holds (Emulation of Unsupported Machines) qualifies that ADS itself, for instance with an IMPQUAL of its own, unique per ADS format as for the KLE unit.
AuxDataLen counts these 16 bytes and the 16-byte authentication tag of the ADS, so, unless it is the payload length of a system-specific format, it is 0 or at least 2; 1 is invalid.
Outside a system-specific format, AuxDataLen is implementation-dependent, but depends only on the other fields of the MDH and on the progress that Rule GR37 allows, never on key material, a secret field, plaintext or ciphertext, or a value drawn for an operation, since kl.getmd* returns it in every mode and State.
ADSDropped, bit 47 of the MDH, is an unauthenticated format hint, ignored in an SCC whose AuxDataLen is 0 and subject to the validity conditions of Validity of Metadata; authentication clears it only in its local copy of the MDH.
-
Set in an SCC, it tells the import to drop the optional
Content2; the import then zeroes the implementation-defined subfields of MachineUse and AuxInfo (MachineUse and AuxInfo Fields). With AuxDataLen ≥ 2,Content2is then absent, andIMPQUALandSIV2remain as non-authoritative padding that keeps the offset ofContent1unchanged. -
Clear, it requests second-segment processing; if that fails, the import drops
Content2, but still accepts the authenticatedContent1(Decryption and Authentication of a Complete SCC into a Locker).
Toggling it cannot affect Content1 or any policy, make an unauthenticated Content2 usable, or bypass first-segment authentication; dropping Content2 can at most force a restart of an interrupted long-running operation (Rule GR38).
After an import, K(i).MDH holds ADSDropped = 0, and an absent or dropped Content2 leaves AuxDataLen = 0 (Decryption and Authentication of a Complete SCC into a Locker); an export uses the AuxDataLen of the MDH, which the implementation keeps up to date (Generation of an SCC from a Fully Configured Locker).
UsagePolicy Field
UsagePolicy determines which modes may use the locker.
Usage Control applies only to the usage instructions that Table 13 lists, which use the Machine in a locker to operate on the locker’s internal state, or to expose it, as a kl.exec that produces output does.
Bits 0–4, when set, allow usage in U-mode (VU-mode included), VS-mode, S-mode (HS-mode with the H extension), M-mode, and Debug mode, respectively.
A clear bit denies its mode, so a zero UsagePolicy admits no mode: software sets each permission deliberately.
mstatus.MPRV is not considered, and the bit of a mode that is unsupported or not enabled has no effect, because it is never checked.
Usage in Debug mode requires bit 4 and, outside authenticated Debug mode (Architectural Model), that bits 0–3 allow the debug access privilege of the External Debug Security extension, that is, the most privileged mode for which that extension allows external debug, and every mode below it: a debugger authorized only for lower privilege modes then gains no usage that those modes lack.
| The Debug-mode rule above is based on a draft of the External Debug Security extension (the debug access privilege). It must be revisited when that extension is ratified. |
Locality Field
Locality names 128-bit Locality Secrets (LSs), listed in Table 9 and stored in a possibly virtual Locality Secrets Table (LST). Some entries are fixed, or configurable only by an implementation-specific, authenticated hardware process, and shared by all KLE units of an SoC; the others are software-programmable, per-hart architectural state.
At SCC export and import, the Localities named in Locality cryptographically bind the SCC to the current hardware and software environments. The binding ends at import: if a Locality Secret changes later, the next export binds its SCC to the new value.
Eleven LST entries are architected: entries 0–5 form the HW Binding Group, which binds SCCs to the hardware; entries 6–7 the Boot Session Group; and entries 8–10 the SW Filter Group.
| Idx | Locality | Description | Domain | Config? | Bits | Value |
|---|---|---|---|---|---|---|
No HW Binding |
Independent of chip, OEM and device |
— |
— |
[3:0] |
0 |
|
0 |
SiPScrt |
Identifies the designer of the SoC. Permanent. |
SoC |
No |
[1:0] |
1 |
1 |
ChipFamScrt |
Identifies the chip (SoC) model. Must also differ when the KLE unit differs, unless the KLE units have the same |
SoC |
No |
[1:0] |
2 |
2 |
ChipScrt |
Unique for each SoC. Permanent. |
SoC |
No |
[1:0] |
3 |
3 |
OEMScrt |
Provisioned by the OEM to differentiate its products. Permanent, or reconfigurable through a custom authenticated hardware mechanism. |
Device |
HW |
[3:2] |
1 |
4 |
ProdScrt |
Identifies the device or system type or model (product). Permanent, or reconfigurable like OEMScrt. |
Device |
HW |
[3:2] |
2 |
5 |
DevScrt |
Unique device (entire system) secret, shared by all harts of an SoC and shareable across the SoCs of a device through an implementation-defined mechanism. Reconfigurable like OEMScrt. |
Device |
HW |
[3:2] |
3 |
No Boot Binding |
Independent of physical or virtual boot session |
— |
— |
[5:4] |
0 |
|
6 |
PhysBootScrt |
Unique per boot session of the host hardware and its firmware stack. Configured by M-mode at the host boot (see mklphysbootscrt). |
Device |
M |
[5:4] |
1 |
7 |
VirtBootScrt |
Unique per boot session of the virtual hardware and its software stack. Regenerated by HS-mode or M-mode at each virtual boot of a VM (see hklvirtbootscrt). |
VM |
HS/M |
[5:4] |
2 |
Binding to Modes |
— |
— |
[8:6] |
— |
||
8 |
MLocality |
Configurable at M; separates Supervisor Domains or Security States. |
< M |
M |
6 |
1 |
9 |
HLocality |
The hypervisor’s tag on its virtual machines, which separates them; it enters the bindings of a guest’s exports and imports, and of the hypervisor’s handling of the loaded VM’s lockers (see hkllocality). Unconfigured without the H extension. |
VM |
HS |
7 |
1 |
10 |
SLocality |
The OS’s Locality: configured via CSR |
< (V)S |
(V)S |
8 |
1 |
In the HW Binding Group, ChipFamScrt and DevScrt must be provisioned, and no provisioned secret of the Group may be zeros(128).
An unconfigured entry of that Group is transparently replaced by the next configured entry of its chain: SiPScrt → ChipFamScrt → ChipScrt, and OEMScrt → ProdScrt → DevScrt.
A Locality Secret is unconfigured if it is not provisioned or holds zeros(128); for the Boot Session and SW Filter Groups, it is not provisioned if its CSR group (Locality Secret CSR groups) is not implemented.
A requested Locality may be substituted but never dropped: a PI or SCC whose Locality names an unconfigured entry without a configured substitute, or carries the reserved value 3 in bits [5:4], is invalid Metadata (Validity of Metadata).
Up to six architected Localities may be active at once: up to two of the HW Binding Group, at most one of PhysBootScrt and VirtBootScrt, and up to three of the SW Filter Group. The SCC generation and import algorithms (Management of Cryptographic Contexts) enforce their policies.
ExpirationDate Field
ExpirationDate is in effect only with Zklexpire, which requires the KLE implementation to access a secure clock.
Without Zklexpire, a non-zero ExpirationDate in a PI or SCC is invalid Metadata (Validity of Metadata).
A non-zero 20-bit ExpirationDate gives the CC’s expiration in whole hours since 00:00 UTC, 1 January 2027, spanning about 119 years and 7 months, independent of time zones. Software below M-mode must not be able to set the clock. A secure clock always reports monotonically non-decreasing time.
|
The assurance of the clock, like that of the SCProtection levels (SCProtection Field), is set by security standards and platform profiles, not by this specification.
It is strongly recommended that a platform with
|
ExpirationDate is evaluated only:
-
at the issue of any usage instruction, for
kl.deriveat both endpoints; and -
when a usage instruction resumes after a halt, but not between the blocks or component operations of one execution.
Each execution reads the clock at most once, before any component operation, and a passed check covers the rest of it, even if the date passes meanwhile. An unavailable clock on resumption leaves the prefix committed before the halt in place (Rule GR16).
The ExpirationDate of a locker that is not in a Valid State is not evaluated: only an expired locker in active use transitions to Error State Expired, and expired contexts can still be managed cleanly.
The evaluation proceeds as follows:
-
If ExpirationDate is zero, the instruction proceeds.
-
If the secure clock cannot be read, the instruction raises a KLE clock-unavailable exception (Exception causes in decreasing priority order) and leaves the State unchanged.
-
The secure clock’s date is converted to the ExpirationDate format, in whole hours rounded down; a reading before the epoch converts to 0, and one at or after 220 − 1 hours converts to 220 − 1.
-
If the converted value is at least ExpirationDate, the locker transitions to Error State Expired; otherwise the instruction proceeds.
MachineUse and AuxInfo Fields
A Machine may use MachineUse and AuxInfo, or subfields of them, to store additional information, in every State or only in some. Each Machine specification identifies the bits it defines and the States in which it defines them. The other bits, including progress in an implementation-defined format (Rule GR37), are implementation-defined: the implementation may use them in the States in which the Machine does not.
Implementation-defined values are disposable: ignoring them preserves the architected semantics, policies and parameters of the Machine, at the cost of a restart at most.
-
An implementation that uses them keeps AuxDataLen ≥ 2 in the MDH, exactly 2 when
Content2is empty, so that every SCC it exports includes an ADS (AuxDataLen and ADSDropped Fields). -
An import, or an export completion that restores a Valid State, interprets them only if both segments authenticate, even with an empty
Content2, and the authenticatedIMPQUALequals that of the importing implementation. Otherwise, if the ADS is absent or discarded (ADSDropped = 1 included), that operation zeroes them after first-segment authentication and before the locker becomes Valid, and the Machine proceeds from the architected fields alone, restarting as Rule GR38 requires. -
kl.clearadszeroes them likewise in a resident locker, so thatkl.getmd*and a later export observe zeros; later computation may set new values, but never restores the discarded ones.
Neither field may hold a value that depends on key material, a secret field, plaintext or a value drawn for the operation, other than the progress that Rule GR37 allows, since the MDH is not confidential and kl.getmd* returns it in every mode and State.
Validity of Metadata checks these fields only through the unsupported condition on values that a Machine specification declares, and by requiring MachineUse to be zero at a system-specific import (Rule GR47). Otherwise a wrong value causes an error of the Machine that uses it, and a discarded implementation-defined value causes none.
Provisioning ignores and zeroes the MachineUse of a PI and the implementation-defined subfields of its AuxInfo (Locker Management Operations), and the completion of a system-specific import (Rule GR51) zeroes the implementation-defined subfields of AuxInfo that the declared MDH supplies. The rules of the Machine decide what happens to the subfields of AuxInfo that it defines upon provisioning, and to both fields on entering State Ready.
A Machine may use AuxInfo to pass initialization parameters at provisioning.
AuxInfo holds, for instance, the modes that an EdDSA CC may use (EdDSA-Specific Rules); the tag length that every verification compares, for GCM, CMAC, HMAC, and Ascon-AEAD128 and its variants (Rule MR12); the segment size u of CFB (Chaining/Feedback Modes (CBC, CFB, and OFB)); and the transfer counter block_base of the Elliptic Curve Machines, which is public (Elliptic Curve Cryptography).
Version Field
Version gives the version of the MDH format:
-
0: the current format;
-
1: reserved for newer revisions of the format, whose further version information is encoded in other MDH fields; unsupported in this revision;
-
2: reserved; and
-
3: a system-specific format, used only for import (Rules for the Import of a System-Specific Format).
A PI, SCC or PCCC with a Version that the implementation does not support is invalid Metadata (Validity of Metadata). It is invalid, not Unsupported: the version fixes the layout of the MDH, so no other field can be interpreted.
Validity of Metadata
In a PI, software keeps all reserved bits, and all bits that the Machine does not use, zero; elsewhere, software passes unchanged the MDH bits that the implementation wrote.
Valid Metadata is unsupported when any of the following holds:
-
the combination of Machine, MachinePolicy, MachineExtension and an SCProtection value of 0 to 2 (Levels A to C) is not implemented;
-
KeyType is 1, resp. 2, and the implementation does not support System Key Identifiers, resp. random key generation, for the Machine (KeyType Field, System Keys); or
-
it holds a value that a Machine specification declares unsupported if not implemented, such as the AuxInfo of EdDSA (EdDSA-Specific Rules).
A supplied MDH is invalid when any of the following holds:
-
Version is unsupported, or is 3 in a PI or in a PCCC of base type
pi; -
Version is 3 at import and any of the following holds: State is not Unconfigured,
kl_cfg_importingorkl_cfg_exporting; AuxDataLen is zero; or one of StateExtension, KeyType, ADSDropped and MachineUse is non-zero (Rules for the Import of a System-Specific Format); -
KeyType is 1 or 2 for a Machine whose Provisioning Input has no key field, for instance the unkeyed hash functions and XOFs, the ECC, ML-KEM and ML-DSA Machines, and the NIK variants of HMAC;
-
KeyType is 3, or 2 outside a PI and a PCCC of base type
pi; -
SCProtection is 3, a reserved value (SCProtection Field);
-
Locality[5:4] is 3, or Locality names an unconfigured Locality Secret without a configured substitute (Locality Field);
-
the MDH carries a custom Machine or a system-specific Version, and its Locality includes none of SiPScrt, ChipFamScrt, ChipScrt, OEMScrt, ProdScrt and DevScrt, which bind the CC to its allowed consumers;
-
State is not 0, or StateExtension is non-zero (an Error State), at provisioning, or State is 0 and StateExtension is 7–15 at import;
-
State is 61–63 at import, or Unconfigured at an import whose Version is not 3 (Rules Governing the State and StateExtension Fields and their Transitions);
-
in an SCC or PCCC, StateExtension @ State is a value that the Machine does not support; for this condition, every Machine supports State 0 with a StateExtension of 1–5, and of 6 with
Zklexpire, and the Configuration States 56–60 with any StateExtension; -
StateExtension is 6 (Expired) at State 0 in an SCC or PCCC when
Zklexpireis not implemented; -
ExpirationDate is non-zero and
Zklexpireis not implemented; -
AuxDataLen = 1 and Version is not 3;
-
AuxDataLen or ADSDropped is non-zero in a PI, or in a PCCC with base type
pi(Management States and Formats); -
MachinePolicy has a value that Rule MR1 does not admit for the Machine, such as zero for a Machine that requires at least one set bit in it;
-
MachineExtension has a value that the Machine does not define (Machine and MachinePolicy Fields); or
-
a Reserved bit is non-zero.
Invalid Metadata takes precedence over unsupported Metadata: the test for unsupported applies only to valid Metadata, as only a valid Version fixes the layout of the fields it reads. The four conditions that depend on the definition of the Machine, those on KeyType for a Machine without a key field, on StateExtension @ State, on MachinePolicy and on MachineExtension, apply only to a Machine that the KLE unit implements, with some MachinePolicy, MachineExtension and SCProtection. For any other Machine, the Metadata is unsupported, and an M-mode handler that emulates the Machine applies those conditions (Emulation of Unsupported Machines).
Narrowing of Metadata
Several operations narrow the policies of a CC by those of another source: the resolution of a SKID (System Keys),
a restricted kl.derive (Rule GR30), the import of a system-specific format (Rules for the Import of a System-Specific Format),
and kl.rstr*, at the request of software (kl.rstrl, kl.rstrh, and kl.rstrv).
The narrowing of an MDH A by the policies of a source B (an MDH, the policies that the SKS associates with a key, or those that a system-specific format carries) is A with the following fields replaced; a policy field that B does not carry leaves that field of A unchanged, and no other field changes:
-
MachinePolicy: for
kl.rstrlandkl.rstrvonly, the AND of both, so that the functions enabled are those that both enable (Rule GR20); every other narrowing leaves it unchanged, even when B is an MDH. -
UsagePolicy: the AND of both, so that the modes that may use the CC are those that both allow.
-
Locality (Table 9): each HW Binding subfield (bits [1:0] and [3:2]) takes the larger value, the stricter entry of its chain, zero meaning no binding; the Boot Session subfield (bits [5:4]) takes the non-zero value if only one is non-zero, and their common value if they are equal; and bits 6–8 are OR-ed.
-
ExpirationDate, with
Zklexpire: the smaller non-zero value, or 0 if both are 0. WithoutZklexpire, an expiration among the policies of the SKS or of a system-specific format makes the narrowing fail.
If both Boot Session subfields are non-zero and differ, if either of them is the reserved value 3, or if the resulting Locality names an unconfigured entry without a configured substitute (Locality Field), the policies cannot be met, and the narrowing fails; each operation that narrows states the outcome.
Narrowing never changes SCProtection.
CSRs
KLE provides the following unprivileged CSRs.
Like vstart and vl, they are unprivileged; the getter and setter instructions are nevertheless the recommended way for software to access them (CSR Getters and Setters: kl.get*, kl.set*, and kl.set*i).
| Address | Privilege | Field | Description |
|---|---|---|---|
TBD |
URW |
( |
Length of the KLIOBUF, in bytes. |
TBD |
URW |
( |
Limit of the KLIOBUF for the current transfers, in bytes. |
TBD |
URW |
|
Start byte index. |
TBD |
URW |
|
Number of the locker named for management transfers and |
Without Zklio, kliobuflen and kliobuftop do not exist: every access to them raises an illegal-instruction exception, as the corresponding getter and setter instructions are reserved (Rule GR1).
The KLS field in effect controls access to these CSRs: while it is Off, every access, including a read of a CSR that M-mode emulates, raises an illegal-instruction exception (KLE Context Status in mstatus and sstatus).
With Smstateen, the KLE bit of the *stateen0 CSRs (CSRs) also gates all of them and the KLE instructions; a denied access raises the exception that Smstateen prescribes for the executing mode and the denying gate.
Context-switch code saves klstart and klnamedlocker first and restores them last, and saves and restores kliobuflen, kliobuftop and the KLIOBUF contents (Software Guidelines, Rule SR3).
The KLE unit does not record which locker the values in the authentication registers belong to: they hold what the last instruction to write them stored (The Cryptographic Locker File and Authentication Information). Their owner is the locker whose import or export is open and that no nested export has saved. Software keeps klnamedlocker at the number of that locker, or at 32, which names no locker, but only while that locker is the only one in State kl_cfg_importing or kl_cfg_exporting (Rules SR7 and SR8). Context-switch code finds the owner this way, exports it before the other lockers and imports it after them, so that its import restores SIV and, if used, IMPQUAL and SIV2 (Context Save Order, Context Restore Order).
A CSR whose description gives a maximum is WARL: writing a larger value sets the maximum, so software must read it back (preferably with the getter instructions of CSR Getters and Setters: kl.get*, kl.set*, and kl.set*i).
Writing a reserved value (33 and above) to klnamedlocker leaves it unchanged (klnamedlocker).
kliobuflen
kliobuflen is an XLEN-bit URW CSR that programs the length of the KLIOBUF, in bytes, for kl.input and kl.output; its maximum is the maximum length of the KLIOBUF (mklmaxiobuflen).
Every write, even of the current value, zeroes the buffer below the new length before it completes, and sets kliobuftop to that length.
Bytes beyond the new length need not be erased, since they stay inaccessible until a later write zeroes them: a write of zero makes the contents inaccessible without erasing them, unless the implementation supports Level C (Destructive Configuration Instructions).
kliobuftop
kliobuftop is an XLEN-bit URW CSR that sets the upper bound, in bytes, of the buffer range that kl.input and kl.output use; its maximum is kliobuflen, and kl.exec never modifies it.
It is the KLIOBUF counterpart of VL in the V extension: it defines the operand length KLLEN as kliobuftop × 8 and the transfer window [0, kliobuftop-1].
Writing kliobuftop leaves the buffer unchanged, so software can set the length per operation without writing kliobuflen, which clears the buffer; this mirrors using VL × SEW to supply a partial last block, or a short IV or nonce, to a Machine.
A value invalid for a Machine is detected only when an instruction that uses the KLIOBUF is later issued or restarted, with the outcomes given in Zklio.
klstart
klstart is an XLEN-bit URW CSR that records, in bytes, the progress of the instructions that honor it:
-
kl.load,kl.store,kl.inputandkl.output: the bytes read or written; -
kl.execwith a vector or KLIOBUF operand, which may be interrupted at its interruption points (Rule GR33.2): the bytes processed; -
kl.derive, which is uninterruptible, requiresklstart= 0 (Rule GR29) and leaves it 0; and -
kl.mvinandkl.mvout, vector or not: the locker transfer point.
KLE has no intrinsic element length and no counterpart of the Element Group Width (EGW) or Element Group Size (EGS) of the vector crypto extension, or the Effective Element Width (EEW) of the vector extension; its instructions, such as kl.exec, are architecturally decoupled from the operations the KLE unit performs for them.
klstart is a byte count; Machines or their implementations record progress that is not byte-structured, such as that of the point multiplications and signature operations of Elliptic Curve Cryptography and Post-Quantum Public-Key Cryptography, in their progress field, in MachineUse (Rule GR37).
Like vstart in the V extension, klstart is the position within the transfer window of kl.exec at which processing starts or resumes: bytes [0, kliobuftop-1] for a KLIOBUF operand, with kliobuflen non-zero, and [0, VL × SEW/8 - 1] for a vector operand.
The memory instructions and kl.mvin and kl.mvout define their own windows (KLIOBUF transfer window, serialized image).
Rule GR14 lists the events that change klstart, Rules GR33.2 and GR18 state how kl.exec checks it, and Appendix: Writing Software for KLE provides guidelines for software.
klnamedlocker
klnamedlocker is an XLEN-bit URW CSR; only 6 of its bits are used.
It holds the number of the locker named for management transfers and KLNL, or 32 if none.
Completing a management operation, even with an error, keeps the number, so that software can inspect the outcome through KLNL before writing 32 or restoring a saved value.
Values 33 and above are reserved; writing one leaves klnamedlocker unchanged.
While the locker it names is in a Configuration State, that locker is under management; klnamedlocker is also the record from which context-switch code finds the locker that owns the authentication registers SIV, IMPQUAL and SIV2 (Ownership of Authentication Registers).
The named locker serves two purposes:
-
a single management routine using the named locker can manage any locker, which reduces code size; and
-
a clear of the named locker sets
klnamedlockerto 32 (Rule GR21), which code that does not rewriteklnamedlockerduring a management operation detects; other code checks the outcome withkl.getst.
Addressing the named locker when klnamedlocker is 32 causes the instruction to fall through: Rule GR13.2.
Rule GR21 lists the events that change klnamedlocker, Rules GR4 and GR13.2 state how instructions use it, and Appendix: Writing Software for KLE provides guidelines for software writers.
Instructions
This section specifies only the semantics and encodings of the unprivileged KLE instructions, not their behavior in the various States of the Machines, how they respect usage policies, how they use randomness, how they access memory, or whether they are interruptible. The rules governing these aspects are grouped in Rules.
Where an instruction’s behavior depends on a rule, its description states that behavior and references the rule.
- Definition: No Operation.
-
An instruction that performs no operation performs none of the operations of the KLE unit, such as cryptographic operations, but may still have the effects that its description or a rule states, such as writing zeros to its output, writing 0 to
klstart, settingklnamedlocker, or raising an exception.
General Rules Governing Encoding and Arguments
The following rules apply to all KLE instructions, unless stated otherwise.
| GR1 |
In every encoding, fields shown with fixed values must hold them. Any other value of such a field, and any unlisted combination of field values, is a reserved encoding and raises an illegal-instruction exception (Second Group of Illegal-Instruction Exception Grounds). |
| GR2 |
Use of multiple GPRs for longer inputs: A 64-bit operand is one GPR on RV64 and the pair |
| GR3 |
If |
| GR4 |
Every instruction that can encode a locker number may encode instead the named locker, written |
| GR5 |
Where a KLE instruction carries the whole 128-bit MDH in a vector register or group, such as the MDH-formatted operand of |
| GR6 |
A vector register operand whose register number is not a multiple of the LMUL in effect is a reserved encoding and raises an illegal-instruction exception, as in RVV 1.0.
Every KLE instruction with a vector operand sets |
| GR7 |
KLE instructions with vector operands that use
|
Provisioning, Import, and Export
Setting aside the handling of lockers in an Error State, a management operation takes three steps: the first and the last are one KLE instruction each, and the second is one or more kl.mvin or kl.mvout (alternatively, kl.load or kl.store) instructions:
-
An opening
kl.mgmt(kl.mgmt) prepares the locker for the management operation. -
One or more
kl.mvin(kl.mvin and kl.mvout) load the rest of the information into the locker, or one or morekl.mvoutmove the locker’s information out. -
A completing
kl.mgmtends the management operation and makes the locker available to software.
kl.avail and kl.size
kl.avail and kl.size, together with kl.getmd, kl.getmdl, and kl.getmdv (kl.getmd, kl.getmdl, and kl.getmdv), are the inspection instructions, i.e., those that examine the MDH without changing any state.
- Synopsis
-
kl.availreturns 1 if the Machine encoded in the MDH is available in the requested variant, and 0 otherwise.kl.sizereturns the size in bytes of the memory buffer needed for the data of a PI, an SCC or a system-specific format, or 0 on error, such as an unsupported Machine or an invalid MDH, or raises an illegal-instruction exception for M-mode emulation (item 5). - Mnemonic
-
kl.availandkl.sizehave three Forms:-
kl.{avail,size} Xd, Ks- Size from a context. -
kl.{avail,size} Xd, Xs- Size from MDH[63:0] in one (RV64) or two (RV32) GPRs. -
kl.{avail,size} Xd, Vs- Size from MDH in one vector register.
-
- Encoding
-
The encoding shares the opcode,
funct3andfunct2(the two msbs offunct7) ofkl.exec, with bit 27 set. Bit 25,q, selectskl.size(q= 0) orkl.avail(q= 1).Field
Fselects the Form:-
F=0b00⇒ Form A, from a contextKs. -
F=0b01⇒ Form B, from an MDH in one (RV64) or two (RV32) GPRs. -
F=0b10⇒ Form C, from an MDH in a 128-bit vector register.
rmust be 0 in Forms B and C;r= 1 there is a reserved encoding. -
- Description
-
kl.avail(q= 1) tells whether the KLE unit implements the Machine fields of an MDH: its Machine, MachinePolicy, MachineExtension, KeyType and SCProtection.kl.size(q= 0) gives the size in bytes of the external image that an MDH describes: a PI, an SCC with its tag(s) and ADS, the MDH of a system-specific format followed by its appended data (Rule GR47), or, for an Error State, the MDH alone (Management States and Formats, Length of External Formats and KLF Capacity Usage of a Locker).The MDH is that of locker
Ksin Form A, whereKsmay beKLNL(Rule GR4); bits [63:0] inXs, orX[s+1] @ Xson RV32, in Form B; and bits [127:0] inVsin Form C. Form B examines only bits [63:0], since no field in bits [127:64] affects the size of any structure (Length of External Formats and KLF Capacity Usage of a Locker); conditions on those fields, such as the Locality binding of a custom Machine (Validity of Metadata) and the AuxInfo of a Machine, are not applied.content1_sizeis the length in bytes of theContent1of an SCC for the given MDH, andpi_content_sizethat of theContentof a PI, both determined according to Length of External Formats and KLF Capacity Usage of a Locker.content2_sizeis 16 * (AuxDataLen - 2) if AuxDataLen ≥ 2 and ADSDropped = 0, and 0 otherwise.The order in which the conditions are checked is given in Rule GR12. The instruction then writes to
Xdthe value of the first item of its list that applies.kl.sizereturns or raises, evaluated in order:-
Form A: 0 if
KsisKLNLwhileklnamedlocker= 32 or the locker is Unconfigured, 16 if the locker is in an Error State, and otherwise the size of item 7; -
Forms B and C: 0 if State is 61–63, or is 0 with a StateExtension of 7–15 (reserved);
-
16 if State is 0 with a StateExtension of 1–5, or 6 with
Zklexpire(an Error State) (Export and Import of a Locker in an Error State); -
0 if Version is 1 or 2, or if SCProtection or KeyType holds a reserved value;
-
if the KLE unit does not natively implement the Machine fields: an illegal-instruction exception if
mstatus.kleemulation= 1 (KLE Emulation Control in mstatus), so that M-mode can supply the value, and 0 otherwise; -
0 if the MDH is unsupported or invalid Metadata (Validity of Metadata), evaluated as at provisioning when State is 0 and Version is not 3, and as at import otherwise;
-
the size:
-
16 + 16 × AuxDataLen if Version is 3, whatever the State;
-
if State is a Valid State or
kl_cfg_{importing|exporting}: 32 +content1_sizeif AuxDataLen = 0, and 64 +content1_size+content2_sizeif AuxDataLen ≥ 2, the 64-byte fixed part includingIMPQUALandSIV2even when ADSDropped = 1; -
16 +
pi_content_sizeif State iskl_cfg_provisioning,kl_cfg_ppi_importingorkl_cfg_ppi_exporting, or if a supplied MDH has State 0 (the MDH of a PI).
-
kl.availreturns or raises, evaluated in order:-
Form A: 0 if
KsisKLNLwhileklnamedlocker= 32 or the locker is Unconfigured, and otherwise 1 if the KLE unit implements the Machine fields of the MDH, and 0 if not; -
Forms B and C: 0 if Version is 1 or 2, or if SCProtection or KeyType holds a reserved value;
-
if the KLE unit does not natively implement the Machine fields: same as item 5 of
kl.size; -
1 otherwise, whatever the other fields hold: a 1 does not exclude a KLE unsupported-Metadata exception that a Machine specification attaches to another field, such as the AuxInfo of EdDSA.
Every item before the lookup is independent of which Machines are implemented, so the lookup traps only when the KLE unit does not natively implement the Machine fields; M-mode then supplies the value of the remaining items.
-
kl.exec
- Synopsis
-
Perform a cryptographic operation in the KLE unit.
- Mnemonic
-
kl.exechas four Forms:-
kl.exec Vd, Kn, Vs2reads an input vector and writes an output vector. -
kl.exec Kn, Vs2reads an input vector and writes no output vector. -
kl.exec Vd, Knreads no input vector and writes an output vector. -
kl.exec Knreads no input vector and writes no output vector.
-
- Encoding
-
kl.execis an R-type instruction.The encodings of Forms A–D are:
-
Form=0b00. -
Form=0b01andrd=0b00000. -
Form=0b10andrs2=0b00000. -
Form=0b11andrd=rs2=0b00000.
Except in the encodings that
Zklmvassigns (kl.mvin and kl.mvout), the locker operand is inrs1, and an unused register field (rdwithout an output vector,rs2without an input vector) must be zero; other non-zero values in it are reserved. -
- Description
-
Performs a cryptographic operation defined by the Machine in locker
Knand its state, possibly taking an input and producing an output;Knmay beKLNL(Rule GR4). Rule GR14 describes its output when it performs no operation or transitions the locker to an Error State.In Form A, each output block has the length of its input block and is written at the same window offset, so
VdandVs2may always be the same register group, each block’s output replacing its input; any other overlap ofVdwithVs2raises an illegal-instruction exception.A future version of this specification may define the semantics of expanding or narrowing multi-block kl.execoperations, whose output blocks are longer, respectively shorter, than their input blocks. No current Machine defines such operations.Without
Zklv, only Form D is supported: Forms A–C raise an illegal-instruction exception, andkl.inputandkl.outputsupply the inputs ofkl.execand extract its outputs (Zklio).
kl.mvin and kl.mvout
The Zklmv subextension adds dedicated move instructions between scalar/vector registers and a locker.
The instructions in this extension are encoded as new forms of kl.exec.
- Synopsis
-
Move content between scalar/vector registers or the KLIOBUF and the named locker, which is in a Configuration State. These instructions do not encode an operand locker (Rule GR4).
- Mnemonics
-
kl.mvinandkl.mvouthave three variants each:-
kl.mvin Xs2copies 128 bits from two or four GPRs into the named locker. -
kl.mvin Vs2copies one or more 128-bit blocks from a vector register into the named locker. -
kl.mvin KLIOBUFcopies one or more 128-bit blocks from the KLIOBUF into the named locker. -
kl.mvout Xs1copies 128 bits from the named locker into two or four GPRs atXs1. -
kl.mvout Vs1copies one or more 128-bit blocks from the named locker into a vector registerVs1. -
kl.mvout KLIOBUFcopies one or more 128-bit blocks from the named locker into the KLIOBUF.
-
- Encodings
-
The encodings are variants of
kl.execForm D (Form=0b11) in whichrd, zero inkl.exec, is non-zero and selects the variant. No locker is encoded, sor= 0; a non-zeroris reserved.-
kl.mvin Xs2:rd=0b00001,rs1=0, andrs2holds the source GPR. -
kl.mvin Vs2:rd=0b00010,rs1=0, andrs2holds the source vector register. -
kl.mvin KLIOBUF:rd=0b00011,rs1=0, andrs2=0b00000. -
kl.mvout Xs1:rd=0b00101,rs2=0, andrs1names the destination GPR. -
kl.mvout Vs1:rd=0b00110,rs2=0, andrs1names the destination vector register. -
kl.mvout KLIOBUF:rd=0b00111,rs2=0, andrs1=0b00000.
Any other non-zero value of
rdin Form D is reserved and raises an illegal-instruction exception. A non-zerors1in variants I–III or VI, or a non-zerors2in variants III–VI, is likewise reserved and raises an illegal-instruction exception. -
- Description
-
kl.mvinmoves the serialized imageSinto, andkl.mvoutout of, the locker thatklnamedlockernames, asKLNLdoes (Rule GR4). Neither transfers the MDH: for a provisioning or an import, the openingkl.mgmthas already loaded it (kl.mgmt), andkl.getmd*reads it.- Transfer
-
kl.mvinandkl.mvoutprocess the operand window in 16-byte blocks, in order: ifklstart<image_end, the block of the serialized imageSat offsetklstartis transferred andklstartadvances by 16; otherwisekl.mvinignores the block,kl.mvoutwrites zeros to it, andklstartis unchanged.klstartis kept across instructions; a sequence of them transfersSpiecewise. A GPR variant transfers exactly one block and is uninterruptible; a vector variant transfers one block per 128/SEWelements and can be interrupted at a block boundary (Rule GR32). If one management operation combineskl.mvinorkl.mvoutwithkl.loadorkl.store, each byte ofSholds the value last written to its offset, by whichever instruction. - Vector variants (II and V)
-
They also track progress in
vstart: each 16-byte block advances it by 128/SEWelements, for instance by 4 for 32-bit and by 2 for 64-bit elements. Element k of the vector operand, for k fromvstarttovl− 1, corresponds to byte offsetklstart+ (k −vstart) ×SEW/8 ofS. The transfer can halt only at a block boundary:klstartthen holds the image offset reached, andvstartthe first unprocessed element; ifvstart≥vl, the instruction, after the checks of Rules GR12 and GR13, transfers nothing and leavesklstartunchanged. - KLIOBUF variants (III and VI)
-
They use the KLIOBUF in place of a vector register: they transfer bytes 0 to
kliobuftop− 1 of the KLIOBUF to or from offsetsklstarttoklstart+kliobuftop− 1 ofS, as a vector variant withvstart= 0 andvl×SEW/8 =kliobuftopdoes. Like the GPR variants (I and IV), they are architecturally uninterruptible (Rule GR32), although they may transfer several blocks: their length is bounded by the maximum length of the KLIOBUF.The KLIOBUF variants give an implementation without Zklvmulti-block transfers:kl.inputfills the KLIOBUF from memory, withklnamedlocker= 32, andkl.mvin KLIOBUFmoves it into the locker, withklnamedlockernaming that locker, askl.inputandkl.execcooperate for the inputs of a Machine (Zklio). Their window is the KLIOBUF up tokliobuftop, so they need no element position, and a transfer of at most that maximum length can be uninterruptible.kl.inputandkl.mvin KLIOBUFshareklstart: the first reads it as its resume point and writes 0 to it, while the second reads and advances it as the offset in the image.kl.outputandkl.mvout KLIOBUFshare it likewise, so software saves and restores it around eachkl.inputorkl.output(Rule SR5). - Exceptions and no-operation cases
-
A vector variant whose vector extension is not enabled, or whose
vl×SEW/8 orvstart×SEW/8 is not a multiple of 16, raises an illegal-instruction exception (Second Group of Illegal-Instruction Exception Grounds), on any locker. So does a KLIOBUF variant ifkliobuftopis not a multiple of 16. The other checks are those of Rules GR12 and GR13, Rule GR24 in a Configuration State, and Rule GR14 gives the outcomes.
kl.setst and kl.setstq
- Synopsis
-
Change the state of the Machine encoded in the CC in a locker.
- Mnemonic
-
kl.setsthas four Forms:-
kl.setst Kd, #immed7with no auxiliary input. -
kl.setst Kd, #immed7, Xswith auxiliary input in one or two GPRs (RV64/RV32). -
kl.setst Kd, #immed7, Vswith auxiliary input in a vector register. -
kl.setstq Kd, #immed7, Xswith auxiliary input in two or four GPRs (RV64/RV32).
-
- Encoding
-
kl.setstis an R-type instruction.The following are separate instructions that share the encoding space of
kl.setst:-
The encodings with
G=0b01define the instructionkl.setste(kl.setste). -
The encodings with
G=0b10belong tokl.set*(CSR Getters and Setters: kl.get*, kl.set*, and kl.set*i). -
The encodings with
G=0b11belong tokl.mgmt(kl.mgmt).
#immed7=kl_cfg_clearall(65) is valid only in Form A, withKd= 0 andr= 0, where it encodeskl.clearall(kl.clearall); every other encoding withG=0b00and#immed7= 65 is reserved.The encodings of the four Forms are:
-
F=0b00,rs1=0b00000: Form A, whose auxiliary operand reads as zero (Rule GR3). -
F=0b00,rs1≠0b00000: Form B, with a 64-bit auxiliary operand inXs=rs1(RV64) or inX[s+1] @ Xs(RV32, Rule GR2). -
F=0b01: Form C. -
F=0b10: Form D, with a 128-bit auxiliary operand in two (RV64) or four (RV32) GPRs starting atXs=rs1(Rule GR2). -
F=0b11is reserved (Rule GR1).
-
- Description
-
kl.setstadvances the Machine of lockerKdfrom one stage to another, for instance from initializing a hash function to absorbing data and finalizing the digest. It normally reaches the State that#immed7names, but some States transition automatically to another State when the instruction completes. Rules Governing the State and StateExtension Fields and their Transitions and each Machine’s specification give the allowed transitions.kl.setstmay set state information orthogonal to these stages, possibly as a prerequisite for entering another State.For all Machines,
#immed7takes these values:-
0 (
kl_state_inert) encodeskl.clear(kl.clear). -
1–53 name the Valid States that Ready and the Machine define (Table 6).
-
54 and 55 name Success and Failure of the Machine, which cannot be set directly (Rule GR19.5); Failure is an outcome, not an error.
-
56–63 are reserved encodings (Rule GR1); with
G=0b11instead of0b00, the values 56–58 and 63 encodekl.mgmt(kl.mgmt), and 59–62 are reserved encodings. -
64 encodes
kl_cfg_clear_ads(kl.clearads). -
65 encodes
kl_cfg_clearall(kl.clearall), in Form A with locker 0 andr= 0 only. -
66–127 are Machine-defined, and may change other state information, such as StateExtension.
Rule GR13 gives the outcome of an immediate in 1–55, 64 or 66–127 by the State class of the locker.
Some values require an auxiliary operand, in GPRs (Forms B and D) or in a vector register
Vs(Form C). -
kl.setste
- Synopsis
-
Set a locker to an Error State.
- Mnemonic
-
kl.setste Kd, #immed7 - Encoding
-
kl.setsteis the encoding ofkl.setst(kl.setst and kl.setstq) withG=0b01, valid only withF=0b00,rs1=0b00000and#immed7in 1–6. Every other encoding withG=0b01is reserved, and so is#immed7= 6 withoutZklexpire. - Description
-
kl.setstesets State to 0 (Inert) and StateExtension to#immed7, the code of an Error State (Table 7). The "e" stands for empty and error. It is a configuration instruction, admitted in every State (Rule GR26).
kl.clear
kl.clear Kd is kl.setst (kl.setst and kl.setstq) with #immed7 = kl_state_inert (State and StateExtension Fields), in any Form; it does not read any auxiliary operand, the locker-state-independent checks of Rule GR12 still applying.
It sets the locker’s State to Unconfigured and releases its KLF resources.
It is a configuration instruction, not a usage instruction: the UsagePolicy does not restrict it, nor can the Machine (Table 13).
Rule GR21 also applies.
A kl.clear sets to Dirty every *llockerstatus field in effect for its locker, and every KLS field in effect, if it changes the locker or if any of those *llockerstatus fields is Off (mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking); it also sets every KLS field in effect to Dirty if it changes klnamedlocker.
kl.clearall
kl.clearall is kl.setst with no auxiliary operand, #immed7 = kl_cfg_clearall, locker number 0 and r = 0.
The locker field names no locker: kl.clearall acts on every locker whatever the State of K0, and is not a usage instruction.
It unconfigures every locker, as kl.clear on each would.
With Zklio, it also unconfigures the KLIOBUF by setting kliobuflen and kliobuftop to 0.
The contents become inaccessible and are erased only as Destructive Configuration Instructions requires.
In every case it sets klstart to 0, zeroizes the three authentication registers of The Cryptographic Locker File and Authentication Information, and writes 32 to klnamedlocker (Rule GR21).
It sets to Dirty the *llockerstatus fields in effect for the current privilege mode, for every locker that it changes or for which any field in effect is Off, as kl.clear does, and the KLS fields in effect if it changes a locker, kliobuflen, kliobuftop, klstart, klnamedlocker or an authentication register, or if any *llockerstatus field in effect is Off.
kl.clearads
kl.clearads Kd deletes any ADS from locker Kd, sets AuxDataLen and ADSDropped to 0, and zeroes the implementation-defined subfields of MachineUse and AuxInfo (MachineUse and AuxInfo Fields).
It is encoded as kl.setst (kl.setst and kl.setstq) with no auxiliary operand and #immed7 = kl_cfg_clear_ads (64). Any other Form of kl.setst with #immed7 = 64 is a wrong Form (Rule GR19.1).
kl.clearads is a usage instruction, admitted in every Valid State (Rule GR19.3).
It leaves State unchanged, and StateExtension, except that it clears the flag of any material that Rule GR38 destroys, such as HasRndNum of the ECC Machines.
It discards the implementation-defined state, in the ADS and in MachineUse and AuxInfo (MachineUse and AuxInfo Fields), including the progress of an interrupted long-running operation (Rule GR38).
Software uses kl.clearads to make the SCC smaller before exporting a locker for another target. A destination with a different KLE unit would drop the ADS anyway.
|
Destructive Configuration Instructions
kl.clear and kl.clearall (kl.clear and kl.clearall) are two of the
destructive configuration instructions, the configuration instructions that discard the CC in a locker without reading it, other than kl.setste.
kl.setste also discards the Content of its locker (Rule GR15), but it is not one of them: it leaves klnamedlocker unchanged (Rule GR21), and it is not exempt from the KLE locker-Off exception.
The other destructive configuration instructions are:
-
a provisioning- or import-opening
kl.mgmt(defined in the next section, kl.mgmt), which zeroizes the locker before configuring it; -
kl.cloneandkl.rename(defined later in kl.clone, kl.rename, and kl.swap), which replace the CC of their destination locker with that of the source; and -
kl.swap(same section), a special case that overwrites both its lockers, each with the CC of the other, so nothing is lost.
A destructive configuration instruction destroys the CC it replaces right after the locker-state-independent checks of Rule GR12, the check of the MDH operand of kl.mgmt included, whatever the outcome, unless it names KLNL while klnamedlocker = 32, when it finds no locker and performs no operation (Rule GR13.2), or it is a kl.clone, kl.rename or kl.swap whose source and destination are the same locker, which performs no operation (kl.clone, kl.rename, and kl.swap).
Item 6 of Rule GR12 gives the accesses exempt from the KLE locker-Off exception; the source access of kl.clone and kl.rename and either access of a kl.swap on two lockers are not.
KLF capacity that kl.mgmt or kl.clone allocates to a locker reads as zero, to the locker’s Machine and to every architectural access, until written.
An implementation that supports Level C (Table 4) must also zeroize at once the Content and any ADS of every locker whose CC is discarded by kl.clear, kl.clearall or as the previous CC of the destination of kl.rename or kl.clone, or that transitions to an Error State (Rule GR15), and the KLIOBUF bytes that a write of kliobuflen or a kl.clearall makes inaccessible (kliobuflen); any other implementation need only release them.
kl.mgmt
- Synopsis
-
Open or complete a management operation on a locker.
- Mnemonics
-
kl.mgmtuses the encoding of only Forms A, C and D ofkl.setst, but is a distinct instruction.-
kl.mgmt Kd, #immed7with no auxiliary input. -
Reserved.
-
kl.mgmt Kd, #immed7, Vswith auxiliary input in a vector register. -
kl.mgmt Kd, #immed7, Xswith auxiliary input in two or four GPRs (RV64/RV32).
-
- Encoding
-
kl.mgmtis an R-type instruction with the encoding ofkl.setst(kl.setst and kl.setstq),G=0b11and#immed7[6:3] =0b0111, that is,#immed7in 56–63. - Description
-
kl.mgmtbrackets the body of a locker management operation (Provisioning, Import, and Export): it opens a provisioning, an export or an import on lockerKd, and completes it. Akl.mgmtthat opens, resp. completes, a management operation is an opening, resp. completing,kl.mgmt, named after its operation: a provisioning-openingkl.mgmt, an export-completingkl.mgmt, and so on.A provisioning- or import-opening
kl.mgmtis allowed in every State (Table 13). It is a destructive configuration instruction, which erases the memory of the locker before using it: this prevents any previous content from leaking into a nested management operation.Like
kl.setst,kl.mgmtchanges the locker’s State, but with different semantics. The State reached depends on both the locker’s previous State and#immed7. Besides the command in#immed7, akl.mgmtthat needs it receives an MDH: when opening a provisioning or an import, it selects the variant of the operation and may become the locker’s MDH; when completing an import or an export, it restores the State recorded inml, the copy of the MDH that the caller saved (Management States and Formats).The Forms supply the MDH as follows:
Locker Management Operations gives the precise semantics of each operation.
kl.getmd, kl.getmdl, and kl.getmdv
- Synopsis
-
Export the MDH of a locker.
- Mnemonics
-
kl.getmdl Xd, Ks
kl.getmd Xd, Ks
kl.getmdv Vd, Ks - Encoding
-
kl.getmd*are R-type instructions that share the opcode andfunct3ofkl.exec, withfunct2=0b11.rnamesKLNLas Rule GR4 specifies.With bit
v(bit 29) = 0, bith(bit 28) selectskl.getmdl(h= 0) orkl.getmd(h= 1), and the result goes to GPRs: one GPR on RV64 and a pair on RV32 forkl.getmdl, a pair on RV64 and a quartet on RV32 forkl.getmd(Rule GR2). Withv= 1, the instruction iskl.getmdv, which writes the entire MDH to the lowest 128 bits of a vector register;hmust then be 0.v=h= 1 encodeskl.getnl(CSR Getters and Setters: kl.get*, kl.set*, and kl.set*i). - Description
-
These instructions copy the MDH of locker
Ks, which is all-zero for an Unconfigured locker:-
kl.getmdlcopies bits [63:0] to GPRXdon RV64, and to the pairX[d+1] @ X[d]on RV32. -
kl.getmdcopies bits [127:0]: on RV64, bits [63:0] toXdand bits [127:64] toX[d+1]; on RV32, to the quartetX[d+3] @ X[d+2] @ X[d+1] @ X[d]. -
kl.getmdvcopies bits [127:0] to vector registerVd, on RV32 as on RV64. Bits [VL×SEW− 1 : 128] are written with zeros, and the tail follows the tail-agnostic policy (RVV/KLV).
They do not check MDH validity (Validity of Metadata).
Ksmay beKLNL(Rule GR4). -
kl.getst and kl.getstx
The pseudo-instructions
kl.getst Xd, Ks
kl.getstx Xd, Ks
return the State, resp. StateExtension, field of the MDH of the source locker, for instance to determine whether it is in an Error State (State and StateExtension Fields).
They read the MDH with kl.getmdl and extract the field by shifting and masking.
Ks may be KLNL; the expansion then uses kl.getmdl with r = 1. With Xd = X0 the instruction writes nothing (Rule GR3).
On RV64, kl.getst expands to
-
kl.getmdl Xd, Ks -
srli Xd, Xd, 18 -
andi Xd, Xd, 0x3F
and kl.getstx by the same code, with the constants in Steps 2 and 3 changed to 24 and 0x0F, respectively.
On RV32 the code is the same, but Xd must be even (Rule GR2) and X[d+1] is also overwritten with MDH bits [63:32].
CSR Getters and Setters: kl.get*, kl.set*, and kl.set*i
Like vsetvl and related instructions of the vector extension, these instructions set and get certain CSR values without a CSR access, which is slow in many implementations.
- Synopsis
-
Get, resp. set, the value of
klnamedlocker,kliobuflen,kliobuftop, andklstart. - Mnemonics
-
kl.getnl/getbl/getbt/getks Xd
kl.setnl/setbl/setbt/setks Xs1
kl.setnli/setbli/setbti/setksi #uimm7 - Encodings
-
The encodings are variants of those of
kl.getmd*(kl.getmd, kl.getmdl, and kl.getmdv) andkl.setst(kl.setst and kl.setstq):-
kl.getnl Xd,kl.getbl Xd,kl.getbt Xd,kl.getks Xd: these instructions use thekl.getmd*encoding withv=h= 1,r= 0 andrs1= 1, 2, 3, and 4, respectively;rdholdsXd. -
kl.setnl Xs1,kl.setbl Xs1,kl.setbt Xs1,kl.setks Xs1: thekl.setstencoding withG=0b10,r= 0,F=0b00,#immed7= 0, andrd= 1, 2, 3, and 4, respectively;rs1holdsXs1. -
kl.setnli #uimm7,kl.setbli #uimm7,kl.setbti #uimm7,kl.setksi #uimm7: thekl.setstencoding withG=0b10,r= 0,F=0b01,rs1= 0, andrd= 1, 2, 3, and 4, respectively;#immed7holds#uimm7.
Every other encoding with
v=h= 1 in thekl.getmd*encoding, or withG=0b10in thekl.setstencoding, is reserved. -
- Description
-
kl.getnl,kl.getbl,kl.getbt, andkl.getkswriteklnamedlocker,kliobuflen,kliobuftop, andklstart, respectively, zero-extended, toXd.kl.setnl,kl.setbl,kl.setbt, andkl.setkswriteX[rs1]toklnamedlocker,kliobuflen,kliobuftop, andklstart, respectively, with the effect of a CSR write.kl.setnli,kl.setbli,kl.setbti, andkl.setksiwrite zero-extended#uimm7toklnamedlocker,kliobuflen,kliobuftop, andklstart, respectively, with the effect of a CSR write.kl.getnl,kl.setnl,kl.setnli,kl.getks,kl.setksandkl.setksiare part ofZklcommon; the ones onkliobuflenandkliobuftopare part ofZklioand reserved (Rule GR1) without it. They are not gated as accesses to the CSRs: the privilege of the CSR is not checked, and software should use them to read or writeklnamedlocker,kliobuflen,kliobuftopandklstart. They behave as reads and writes of the CSRs: the CSRs are WARL: a written value above the maximum of the CSR is replaced by that maximum (a reserved value leavesklnamedlockerunchanged), andmklmaxiobuflen≥kliobuflen≥kliobuftopis enforced (mklmaxiobuflen, kliobuflen, kliobuftop).They are configuration instructions, not usage instructions: Usage Control does not gate them.
kl.rstrl, kl.rstrh, and kl.rstrv
- Synopsis
-
Restrict the policies encoded in a CC in a locker.
- Mnemonics
-
kl.rstrl Kd, Xs1
kl.rstrh Kd, Xs1
kl.rstrv Kd, Vs1 - Encoding
-
kl.rstr*are R-type instructions that share the opcode andfunct3ofkl.exec, withfunct2(the two msbs offunct7) =0b01.rnamesKLNLas Rule GR4 specifies.With bit
v(bit 29) = 0, bith(bit 28) selectskl.rstrl(h= 0) orkl.rstrh(h= 1), and the input comes from a GPR (a GPR pair on RV32). Withv= 1, the instruction iskl.rstrv,hmust be 0, and the input comes from the lowest 128 bits of a vector register;v=h= 1 is reserved.
- Description
-
These instructions narrow the policies of the CC in locker
Kd, whose MDH ismd, as their operand requests:Xs1, orVs1forkl.rstrv, formatted as an MDH.- Operand
-
-
kl.rstrltakes bits [63:0] of the operand, and may change MachinePolicy; -
kl.rstrhtakes bits [127:64], supplied inXs1[63:0], and may change Locality, UsagePolicy and ExpirationDate; -
kl.rstrvtakes both halves, and applies both sets of rules.The request
rqis the 128-bit MDH image that these halves form; the fields of a half that the instruction does not take are not requested and stay unchanged. In a half that the instruction takes, a non-zero field other than these four transitions the locker to Invalid.
-
- Per-field behavior
-
Each field of
rqnarrows the matching field ofmd(Narrowing of Metadata), except as stated below for Locality. A set MachinePolicy or UsagePolicy bit, or an ExpirationDate later than a non-zeromd.ExpirationDate, changes nothing and is not an error. A non-zero Locality subfield ofrqthat differs from that ofmdand is not a permitted replacement below transitions the locker to Privilege Violation.-
MachinePolicy: no disabled function can be re-enabled, and a request that disables the operation associated with the current State takes effect as Rule GR20 states. A Machine with fields that exist only for some values of MachinePolicy, such as the ECC Machines (Elliptic Curve Cryptography), states what a narrowing does to them.
-
Locality: each subfield (Table 9), bits [1:0], [3:2], [5:4], 6, 7 and 8, is treated independently. A subfield of
rqthat is zero or equal to that ofmdchanges nothing, and a zero subfield ofmdtakes the value ofrq. A non-zero HW Binding subfield may be replaced only by a stricter entry of its chain: SiPScrt by ChipFamScrt or ChipScrt, ChipFamScrt by ChipScrt, OEMScrt by ProdScrt or DevScrt, and ProdScrt by DevScrt. Any other change, including a weakening or a change of a non-zero Boot Session or SW Filter subfield, transitions the locker to Privilege Violation instead of overriding the field. A later export binds its SCC to the new Locality.
-
- Validity of the result
-
Validity (Validity of Metadata) is evaluated first, on the changed fields only. A request that would produce an unsupported or invalid value, such as a reserved Locality subfield or a non-zero ExpirationDate without
Zklexpire, transitions the locker to Invalid, even if it also asks for a change that gives Privilege Violation, such as a Locality that names an unconfigured entry without a configured substitute. Only a request with valid values can give Privilege Violation. A request that transitions the locker to an Error State changes no other field ofmdbeyond those of Rule GR15. - States
-
The
kl.rstrinstructions are not usage instructions (Rule GR17). They act only in a Valid State: on an Unconfigured or Error-State locker they perform no operation (Rule GR13.2), and in a Configuration State Rule GR13.3 applies.
A kl.rstr narrows only the CC in Kd. Copies of the same secret made earlier, such as clones made or SCCs exported before the narrowing, keep their wider policies (The Cryptographic Locker File and Authentication Information).
|
|
These instructions let privileged code give different processes customized copies of a CC, bound to per-process Localities or limited to a subset of its functions, such as separate encryption-only and decryption-only copies, which some modes do not keep apart (Accepted Risks). This may avoid repeated expensive round-trips to trusted environments. |
kl.clone, kl.rename, and kl.swap
- Synopsis
-
Copy, move or exchange the CCs of lockers.
- Mnemonics
-
kl.{clone, rename, swap} Kd, KsEither
KdorKs, not both, may beKLNL(Rule GR4). - Encoding
-
These are R-type instructions that share the opcode and
funct3ofkl.exec, withfunct2=0b10.Field
T(bits [28:27]) selects the instruction:-
00encodeskl.clone. -
01encodeskl.rename. -
10encodeskl.swap. -
11encodeskl.derive(kl.derive).
-
- Description
-
kl.clone-
Clones source locker
Ksinto destination lockerKd, either of which, not both, may beKLNL(Rule GR4):-
If source and destination are the same locker, the instruction performs no operation and sets no
*llockerstatusorKLSfield to Dirty (mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking), even if the locker is Unconfigured, Off, or in a Configuration State; in the last case, Rule GR13.3 does not apply. -
If they are different lockers and neither of them is
KLNLwhileklnamedlocker= 32, the instruction first clears the destination, askl.clearwould, even if it then raises an exception (Destructive Configuration Instructions); ifklnamedlockernamed the destination, it becomes 32. Every*llockerstatusfield in effect for the destination and everyKLSfield in effect are set to Dirty, whatever the outcome. The source then decides the result:-
An Unconfigured source leaves the destination Unconfigured.
-
A source in a Configuration State raises a KLE privilege-violation exception (Rule GR13.3).
-
A source in an Error State is cloned as its MDH alone (Rule GR15).
-
Any other source is copied verbatim, with its internal data, MDH and internal state, unless the available KLF capacity cannot hold the clone, in which case the instruction raises a KLE out-of-memory exception. As the one exception, if the source has an interrupted long-running operation, the copy restarts it (Rule GR38): its progress is zeroed and the values drawn or computed for the operation are discarded, as at an import that completes without
Content2. Like the source, the copy stays usable whatever the current Locality Secrets.kl.cloneis not a usage instruction, so no UsagePolicy restricts it (Rule GR17).
-
-
kl.rename-
If
KsandKdname the same locker, throughKLNLtoo, no operation is performed, even if the locker is Off, and no*llockerstatusorKLSfield is set to Dirty. Otherwise the CC ofKs, Configuration State included, becomes the CC ofKd, the previous CC ofKdis discarded, askl.clearwould,Ksbecomes Unconfigured, and the*llockerstatusfields in effect for both lockers and theKLSfields in effect are set to Dirty. With an Unconfigured source,kl.renameacts askl.clear Kd, except that it always sets these fields to Dirty. Ifklnamedlocker=s, it becomesd; otherwise, if it isd, it becomes 32. kl.swap-
If
KsandKdname the same locker, throughKLNLtoo, no operation is performed, even if the locker is Off, and no*llockerstatusorKLSfield is set to Dirty. Otherwise the CCs ofKsandKdare exchanged, and ifklnamedlocker∈ {s,d}, it takes the other index. The*llockerstatusfields in effect for both lockers and theKLSfields in effect are set to Dirty.
With
klnamedlocker= 32, akl.clone,kl.renameorkl.swapwith aKLNLoperand finds no locker and performs no operation, its other locker untouched (Rule GR13.2).Neither
kl.renamenorkl.swapraises a KLE out-of-memory exception or edits the content of any MDH: they move or exchange entire lockers. WhenKsandKdname the same locker,kl.clone,kl.renameandkl.swapstill make the checks of Rule GR12, except that of a locker whose*llockerstatusfield is Off. mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking and Emulation of Unsupported Machines give the behavior under lazy loading and emulation, when the source or destination locker is Off in some*llockerstatus.
kl.derive
- Synopsis
-
Transfer data from one locker into another without exposing it to software.
- Mnemonic
-
kl.derive Kd, Ks1, Xs2Either
KdorKs1, not both, may beKLNL(Rule GR4). - Encoding
-
kl.deriveis an R-type instruction.The auxiliary input is always a GPR:
kl.derivehas no form without one, and no vector form. - Description
-
A
kl.derivetransfers data from a source endpoint to a destination endpoint; the architecture decides which pairs of endpoints are admitted.- Definition: Source endpoint.
-
A source endpoint is what a Machine lists as a source for a State in Derivation Endpoints of the Machines: an exportable field, whose availability may depend on StateExtension or on an MDH field that the Machine names, such as
OutputTypeof ECC (MachineUse bits used by the Elliptic Curve Machines); otherwise thekl.execoutput, the data that a Form Ckl.execpermitted in that State would emit. A field configured by a SKID is never exportable (Rule GR55.1). - Definition: Destination endpoint.
-
A destination endpoint is what a Machine lists as a destination for a State in Derivation Endpoints of the Machines: an importable field that an admitted pair names; or the
kl.execinput, the data that a Form Bkl.execof that State would absorb. It fixes the minimum, upper limit and granularity of the transfer. A key field is a destination only in Ready or in a State that the Machine names for loading it, such as Set_Key of HMAC (HMAC), and never when KeyType is 1 (Rule GR55.1). - Definition: Admitted pairs.
-
An admitted pair consists of a source and a destination endpoint; the MDH of each locker, not an operand of
kl.derive, determines its endpoint. Rules GR31.1 and GR31.2 admit two families of pairs, Rule GR31.3 narrows them for a sealed source, and these Rules state for each whether the transfer is restricted or unrestricted (Table 15). Any other pair is not admitted (Rule GR31). An admitted pair fixes the semantics of the transfer and its updates to the two States and toklstart(Rules GR28–GR31.3);kl.derivechanges no other state of the hart (Table 13).
Let
lengthbe the value provided by the auxiliary GPR, andeff_lengththe number of bytes transferred (Rule GR28): min(length,dest_length) for a destination field ofdest_lengthbytes, andlengthotherwise.kl.derivemoveseff_lengthbytes from an endpoint of the source locker to an endpoint of the destination locker without exposing them to software: the output of one Machine becomes an input of another, possibly into a key field or akl.execinput, as the admitted pairs allow.Xs2=X0giveslength= 0, and Rule GR29 gives the outcome whenlengthis zero or short.A transfer is unrestricted only where software could also obtain the moved data by issuing
kl.execinstructions, as for thekl.execoutputs of Rule GR31.2 and a shared secret that its Machine allows to export throughkl.exec; otherwise it is restricted, as for any other shared secret (Rule GR31.1) and for a sealed source (Rule GR31.3).
KLE Memory Instructions
The checks of the KLE memory instructions and their behavior in the memory model are defined in Memory Instructions and Memory Model.
kl.load and kl.input
- Mnemonics
-
kl.load %offset(Xs), Xl
kl.input %offset(Xs), Xl
kl.inputis an alias forkl.load, for source code in whichklnamedlockeris known to be 32. - Encoding
kl.load/kl.input is an I-type instruction.
%offset is immed12, sign-extended to XLEN bits.
- Description
-
The locker is not an operand: with
klnamedlocker< 32,kl.loadcopies data into the locker thatklnamedlockernames; withklnamedlocker= 32, into the KLIOBUF.- For
klnamedlocker< 32 -
kl.loadimports the Content of a PI or an SCC into the locker, but not its MDH, whichkl.mgmtcarries. A non-zeroXlraises an illegal-instruction exception; otherwise,kl.loadmakes the checks ofkl.mvin(Rule GR24).For each j in
[klstart, image_end-1],kl.loadloads the byte at memory address (Xs + %offset +j) mod 2XLEN into byte j of the serialized imageSof the locker’s Content, in 16-byte blocks from a 16-byte aligned address (Rule GR12).klstarttracks the prefix-complete number of bytes loaded; ifklstart≥image_end, nothing is transferred.With a system-specific format,
kl.loadtransfers the data that follows the MDH unchanged, as the serialized imageS(Rules for the Import of a System-Specific Format). - For
klnamedlocker= 32 -
With
Xl= 0,kl.loadandkl.storedesignate no locker and fall through (Rule GR12, item 5). WithXl≠ 0, askl.inputandkl.output, they requireZklioand a configured KLIOBUF (Third Group of Illegal-Instruction Exception Grounds) and transfer the bytes of the KLIOBUF transfer window. - Definition: KLIOBUF transfer window.
-
Let n = min(
Xl,kliobuftop). The KLIOBUF transfer window ofkl.inputandkl.outputconsists of the offsets j withklstart≤ j < n. For each j in the window,kl.inputcopies the byte at address (Xs + %offset +j) mod 2XLEN to KLIOBUF byte j, andkl.outputcopies KLIOBUF byte j to that address. No other byte is accessed, in memory or in the KLIOBUF; in particular, bytes fromkliobuftopon are never transferred, whateverXl. Ifklstart≥ n, the window is empty: the checks of Rule GR11 are still made, then nothing is transferred andklstartis set to 0.
- For
kl.store and kl.output
- Mnemonics
-
kl.store %offset(Xs), Xl
kl.output %offset(Xs), Xl
kl.outputis an alias forkl.store, for source code in whichklnamedlockeris known to be 32. - Encoding
-
kl.store/kl.outputis an S-type instruction.%offsetisimmed[11:5]@immed[4:0], sign-extended to XLEN bits. - Description
-
The locker is not an operand: with
klnamedlocker< 32,kl.storecopies data out of the locker thatklnamedlockernames; withklnamedlocker= 32, out of the KLIOBUF.- For
klnamedlocker< 32 -
kl.storeexports the serialized imageSof the locker to memory, but not its MDH, whichkl.getmd*extracts. A non-zeroXlraises an illegal-instruction exception; otherwise,kl.storemakes the checks ofkl.mvout(Rule GR24).For each j in
[klstart, image_size-1],kl.storestores byte j ofSat memory address (Xs + %offset +j) mod 2XLEN, in 16-byte blocks to a 16-byte aligned address (Rule GR12); the bytes fromimage_endon are stored as zero.klstarttracks the prefix-complete number of bytes stored; ifklstart≥image_size, nothing is transferred. Software does not usekl.storeon an Error-State locker (Export and Import of a Locker in an Error State). - For
klnamedlocker= 32 -
kl.outputis described withkl.input(kl.load and kl.input): it copies the bytes of the KLIOBUF transfer window from the KLIOBUF to memory.
- For
Rules
This section collects the Rules that govern the behavior of the KLE ISA. Many of them deal only with classes of States, namely Unconfigured, Valid, Error, Configuration, Complete and Inert, and of instructions, namely Usage, Memory and Configuration; Configuration instructions are further inspection, destructive, transfer and narrowing ones. Other Rules are instruction-specific. A Rule GRn.m belongs to the group that Rule GRn opens, and details its principle.
Table 11 names the properties that the Rules establish together. It is informative: the Rules govern.
| Invariant | Rules | |
|---|---|---|
I1 |
Secrets flow downhill (P1, P16): a secret leaves a locker only inside an SCC, as a |
|
I2 |
Exceptions are precise: an exception has no effect beyond those that Rule GR16 lists. |
|
I3 |
Errors live in the locker: an instruction that enters an Error State retires, keeps the committed prefix, zeroes the unwritten output and clears the Content. |
|
I4 |
Inert lockers are no-ops: an instruction on an inert locker falls through, except in the cases that Rule GR13.2 lists. |
|
I5 |
Progress is prefix-complete (P3): an interrupted instruction commits a prefix of its transfer, which |
|
I6 |
Management is always available (P6, P13): every State admits the instructions that inspect, clear or reconfigure a locker, and every Valid, Error or Configuration State admits an export. |
|
I7 |
Asynchrony is invisible to program order: a handler observes a KLE instruction as completed or precisely halted. |
Content Confidentiality
| GR8 |
No extraction (P1, P16). Once the provisioning, or the base import of a system-specific format (Rules for the Import of a System-Specific Format), that binds a key to its Metadata completes, no instruction returns in clear the value of the key, or of any other secret field of the Content, except as an output defined by the Machine for |
| GR9 |
Clear blocks: An SCC carries the first
|
Zklio
With Zklio, the KLIOBUF can replace the vector operands of kl.exec, so that code runs on cores without vector registers; kl.setst and kl.mgmt use Form D instead of Form C.
| GR10 |
With
|
| GR11 |
These instructions access the KLIOBUF and require it to be configured, with a non-zero
Without |
Checks and Outcomes
| GR12 |
The locker-state-independent checks come first, in this order; the first that fails decides the outcome:
|
| GR13 |
Admission by State class. After the locker-state-independent checks (Rule GR12) come the locker-state-dependent checks, which include the Fourth Group of Illegal-Instruction Exception Grounds: the class of the locker’s State decides which instructions are admitted and what the others do, as Rules GR13.1–GR13.5 state. An admitted instruction then has an outcome of Rule GR14.
|
| GR14 |
The checks lead to one of the outcomes of Table 12.
An instruction that falls through performs no operation and raises no exception, makes no check beyond those of Rule GR12, and reads no operand other than its locker designators and those that these checks inspect: it accesses no memory, and needs neither a configured KLIOBUF nor |
| Outcome | Locker and other KLE state | Output window1 | klstart2 |
|---|---|---|---|
Operation |
As the instruction states |
Written |
0 |
Exception |
Unchanged, except as Rule GR16 states |
Unchanged |
Unchanged, except as Rule GR16 states |
Fall through |
Unchanged, except |
Zeros |
0 |
Error State |
The Error State, the Content cleared (Rule GR15) |
Zeros |
0 |
Empty window (Rule GR18, item 1) |
Unchanged |
Unchanged |
0 |
1 The part of the output window that the instruction has not written; only |
|||
| GR15 |
An instruction that transitions a locker to an Error State retires: the prefix that it has committed stays committed, and the unwritten part of its output window, if it has one, is zeroed (Table 12). The locker clears its Content beyond the MDH and releases the internal resources that held it, any ADS included; AuxDataLen and ADSDropped are set to 0, a Version of 3 to 0 (Rules for the Import of a System-Specific Format), and a KeyType of 2 to 0. Every implementation-defined field or subfield (MachineUse and AuxInfo Fields) is set to 0. |
| GR16 |
A KLE fatal-error exception resets the KLE state (KLE fatal-error in Exception causes in decreasing priority order). Any other exception leaves the KLE state unchanged, except for these changes, made even when the instruction then raises an exception:
For a resumed instruction, “unchanged” refers to the state when it is issued again, not at the halt; the prefix committed by earlier attempts is part of that state and is not undone. |
Rules Governing Valid States
| GR17 |
Table 13 states, for every instruction, whether it is a usage instruction, and so subject to the UsagePolicy (UsagePolicy Field), which state it may modify, and whether it is admitted whatever the State of the locker it accesses. An instruction that the UsagePolicy forbids raises a KLE privilege-violation exception, at the point of the check order stated by Rule GR13.5. |
| Instructions | May modify KLE state | May modify other state | Usage instruction | Admitted in every State | Notes |
|---|---|---|---|---|---|
|
No |
Yes |
No |
Yes |
|
|
Yes |
Yes |
Yes |
No |
|
|
Yes |
Yes |
No* |
No |
The direction determines which state changes. Both advance |
|
Yes |
Yes, vector forms reset |
Yes, see note |
No |
Not a usage instruction with the immediates |
|
Yes |
No |
No |
Yes |
|
|
Yes |
Yes, vector Forms reset |
No |
Yes |
Encoding of |
|
Yes |
No |
No |
Yes |
Encoding of |
|
Yes |
No |
Yes |
No |
Encoding of |
|
Yes |
Yes |
No |
Provisioning and import opening |
Vector forms reset |
|
No |
Yes |
No |
Yes |
|
|
No |
Yes |
No |
N/A |
Read the CSR they name. |
|
Yes |
No |
No |
N/A |
Write only the CSR they name, with the effect of a CSR write. |
|
Yes |
Yes |
No |
No |
|
|
Yes |
No |
No |
Yes, see note |
Except from a source in a Configuration State (Rule GR13.3). |
|
Yes |
No |
No |
Yes |
|
|
Yes |
No |
Yes |
No |
The UsagePolicy fields of the source and destination lockers are evaluated separately for the source and the destination (Rule GR27). |
|
Yes |
No |
No* |
No |
Updates |
|
Yes |
Yes |
No* |
No |
Modifies |
|
Yes |
No |
No |
N/A |
Modifies the KLIOBUF and |
|
Yes |
Yes |
No |
N/A |
Modifies |
* Usable only in the States admitted by Rule GR24; on an Unconfigured or Error-State locker they perform no operation (Rule GR13.2). |
|||||
| GR18 |
A Form A–C
|
||||||||||
| GR19 |
Admission by the Machine. In a Valid State, the Machine decides which usage instructions and Forms it admits, and what each does; an instruction that it does not admit performs no operation and transitions the locker to Error State Invalid (Rule GR13.5, item 4). Rules GR19.1–GR19.5, Rule GR38 and Rule MR1 constrain that choice.
|
| GR20 |
A |
Rules Governing the Named Locker
| GR21 |
Besides writes by software, through the CSR or
|
Rules Governing the State and StateExtension Fields and their Transitions
State encodes up to 55 Valid States: Ready, Success, Failure and up to 52 States defined by the Machine.
Figure 1 (State and StateExtension Fields) shows the default state transitions that apply to all Machines.
The following rules apply to all Machines:
Rules Governing Configuration States
| GR24 |
The management transfers into the locker, |
| GR25 |
The completing
|
Rules Governing Inert Lockers
Recall from Definition: Inert Locker. that an inert locker is an Unconfigured locker, a locker in an Error State, or KLNL while klnamedlocker = 32.
Rule GR13.2 states what instructions do on an inert locker, and Table 14 the results of those that fall through.
| Instruction | Error State | Unconfigured locker | KLNL & klnamedlocker = 32 |
|---|---|---|---|
Writes 16 to |
Writes 0 to |
||
Writes to |
Writes 0 to |
||
Writes the MDH, resp. its State or StateExtension field. |
Writes zeros to the destination. |
||
kl.clear † |
Clears the locker; the |
Writes nothing to the locker; every |
Writes nothing. |
† |
|||
| GR26 |
A |
|
Rules GR12 and GR13.2 close a check-then-use race: between a State/StateExtension check and the next instruction, a handler may clear a locker being provisioned or imported, which sets |
Derivation Rules
The Rules of this section apply to kl.derive.
| GR27 |
Each condition of Rule GR13.5, starting with the State class (Rule GR13), is checked first on the source of a |
||||||
| GR28 |
Transfer size and progress:
A destination field of Every check that can raise an exception precedes the first unit. If a field fails a check when its transfer completes (Rule MR3), its locker takes the outcome that its Machine specifies, or else Invalid, and the instruction retires; the source keeps the effects of the units already transferred. |
||||||
| GR29 |
After the checks of Rule GR13.5, the following checks are made in order; a failed check transitions the locker named to Error State Invalid (Rule GR15), and nothing more is transferred:
|
||||||
| GR30 |
Before a nonempty restricted transfer that Rule GR29 admits begins, the destination transitions to Error State Privilege Violation, and nothing is transferred, if its SCProtection is lower than that of the source, or if the narrowing of its MDH by that of the source (Narrowing of Metadata) fails. Otherwise the narrowed policies govern the transfer, but are written only with its first committed unit (Rule GR28). |
||||||
| GR31 |
Admitted pairs. A
|
| Source | Transfer | Destinations, as Derivation Endpoints of the Machines lists them |
|---|---|---|
A shared secret that its Machine allows to export through |
Unrestricted |
A key field of a symmetric Machine, or the |
Any other shared secret, such as the ML-KEM |
Restricted |
|
The |
Unrestricted |
A key field of a symmetric Machine |
A sealed source: the shared secret of a sealed variant, or the Hash_Output of a sealed locker |
Restricted, of at least 16 bytes |
Those of the same source unsealed, except the key of keystream generation, OFB or CMAC, and |
Interruptibility and Resumability of KLE Instructions
| GR32 |
The architecturally resumable instructions are:
Every other KLE instruction is uninterruptible: it completes, raises an exception with only the effects of Rule GR16, or has no architecturally visible effect, except that a long-running operation (Long-Running Operation) halts as Rule GR36 states; an implementation achieves this with option 1, 2 or 5 of Rule GR34, option 1 subject to Rule GR35.
A |
||||||
| GR33 |
Precise halt. On a precise halt of a resumable instruction (Rule GR32), the completed prefix is committed at both endpoints of the transfer,
|
| GR34 |
When a handler accesses an input, output or locker of a preempted instruction, or other KLE state the instruction may affect, the implementation chooses one of:
|
| GR35 |
Under every option of Rule GR34, before the issuing hart performs a conflicting access, the in-flight operation must have completed, or have halted precisely with
Scalar operands in GPRs, |
| Together, Rules GR34 and GR35 make asynchronous execution by the KLE unit invisible to same-hart program order, as Memory Instructions and Memory Model requires. Beyond them, the architecture specifies only the allowed interruption points of its instructions and Machines; an implementation may also preempt a Long-Running Operation at points that it defines itself, as the next section states. |
Implementation-Defined Interruption of Long-Running Operations
- Definition: Long-running operation.
-
A
kl.execorkl.setstthat accesses only its lockers and the values of the operands captured at issue may be long-running, such as a scalar multiplication, a key generation or a signature; so may a component operation of one, a computation on state already in its lockers between the reading of its inputs and the writing of its outputs, such as completing the load of a field.
| GR36 |
On preemption, a long-running operation behaves as an option of Rule GR34 that the interrupt or exception allows; the implementation supports at least one of options 3, 4 and 5.
Whether a long-running |
| GR37 |
A long-running operation that halts at implementation-defined points obeys the following:
|
| GR38 |
A State in which a
|
Memory Instructions and Memory Model
The KLE memory instructions are kl.load, kl.store, kl.input and kl.output; they are RISC-V memory instructions.
kl.mvin and kl.mvout access no memory and are not memory instructions.
| GR39 |
A KLE memory instruction may be decomposed into component accesses of any granularity, none of them required to be atomic, performed in any order that the semantics of the instruction and the memory model allow; among the component accesses of one instruction, ordering follows RVWMO, even with |
| GR40 |
KLE memory instructions appear to execute in program order on the local hart.
Their component accesses are ordinary loads ( |
| GR41 |
After the checks of Rules GR12 and GR13, each component access of a KLE memory instruction checks, in offset order, the address breakpoint, then the page, guest-page and access faults, as per the Privileged Specification.
The address breakpoint of the first component access of a |
| GR42 |
For the syntactic dependencies of RVWMO, each locker, as one unit, and each byte of the KLIOBUF is a register, and a KLE memory instruction has these registers:
Every other KLE instruction carries a dependency from each register, locker and KLIOBUF byte that it reads to each that it writes, so that a dependency passes from a |
| GR43 |
KLE memory instructions support only idempotent memory: a component access whose effective memory attributes (the PMAs, as modified by the page-based memory type where |
| GR44 |
No component operation of a KLE memory instruction draws random bits (Rule MR19) or reads the clock (ExpirationDate Field). |
Randomness
| GR45 |
RBG/DRBG failures. If the entropy source has failed permanently (for |
Rules for the Import of a System-Specific Format
| GR46 |
System-specific formats are optional and only imported: a PI, or a PCCC of base type |
| A system-specific format is imported, not provisioned, because it may authenticate its data: SCC import code already handles an Authentication Failed error, whereas provisioning code does not, since completing a provisioning authenticates nothing. Import is also conceptually right: like SCCs, such formats come from sources external to the caller. As after a provisioning of a KLE format, however, a successful import of a system-specific format ends in Ready with no ADS, and the MDH fields that describe a started Machine are zero (Rule GR47). |
| GR47 |
The base import of a system-specific format opens with a KLE-format MDH:
|
| GR48 |
A system-specific format may carry policies beyond those of the declared MDH; the implementation converts them, in an implementation-defined way, into KLE policies at least as strong, which apply in addition to those of the MDH, never in their place, and a policy that cannot be so converted is a failed translation (Rule GR51). The format defines whether and how its data is protected: this specification requires neither encryption nor authentication. The format and the implementer of its import either prevent the import from producing an inconsistent state or reject the data that would produce one (Rule GR49). |
| GR49 |
A system-specific format and its import circumvent no requirement of this specification or of the referenced standard of the Machine; the architect of the format and the implementer of its import ensure this. The base import leaves a locker whose MDH and Content the following sequence could also have produced: No initialization operation of the format leaves a field with a value that the operations of the Machine could not produce, and no conversion bypasses a check or a derivation of the Machine (Rule MR4). |
| GR50 |
Until the import completes, the locker holds the loaded data as received: authentication, decryption, conversion and policy translation occur only in the completing |
| GR51 |
The
|
| A CC imported from a system-specific format can be bound by its Locality to the implementations meant to use it. Code examples (Appendix: Writing Software for KLE) include no such import. |
Error Handling Architecture
An error condition has one of three outcomes: it raises an exception; it is recorded in the locker as an Error State, which travels with the CC and stays readable until the locker is reconfigured; or, on an inert locker, it lets instructions have only the outcome described in Table 14, i.e., most fall through and raise no exception. This section describes when exceptions are raised and when Error States are set.
Exceptions
The grounds of each KLE exception follow, in the descending priority order of Exception causes in decreasing priority order, except the memory exceptions, listed last.
- First Group of Illegal-Instruction Exception Grounds
-
These grounds depend only on the presence of a KLE unit and of its features, and on the current privilege mode; they raise an illegal-instruction exception, except as items 2 and 3 state:
-
An access denied by
KLS= Off or by a*stateen0gate; -
an
hstateen0denial while V=1, or a guest access for which CSRs prescribes one, raises a virtual-instruction exception instead. -
An access to a KLE CSR unavailable in the current mode (Table 10, CSRs); in VS-mode or VU-mode, where the Privileged Specification prescribes it, a virtual-instruction exception instead.
-
- KLE fatal-error
-
The main fatal condition is an integrity failure of a hart’s KLF (The Cryptographic Locker File and Authentication Information); implementations may define others. Detection and the resulting KLE unit reset (KLE Unit Reset and M-mode-only Harts) may be synchronous or asynchronous; the KLE unit records the condition, and the first KLE instruction or KLE CSR access issued, or in flight, after detection performs no further operation and raises the exception (in the order of Rule GR12), with
xepcholding its address; a prefix that an in-flight instruction has already committed stays (Rule GR33). The reset takes effect as early as the detection, and no later than when that instruction or access is issued. If it takes effect earlier, the KLE unit retains only the internal state needed to raise this exception, none for any other exception, and clears that state when it raises it. Meanwhile no instruction accesses the KLF. - Second Group of Illegal-Instruction Exception Grounds
-
These grounds depend only on the instruction encoding, the GPR numbers, the vector configuration and
kliobuftop; they raise an illegal-instruction exception:-
A reserved encoding, including
KLNLwhere Rule GR4 does not admit it, or a vector operand whilevtype.villis set (RVV/KLV). -
A reserved value of
rorR, or a non-zero locker register field that they replace (Rule GR4), or, in akl.derivewithR=00, equal locker indices (kl.derive). -
A GPR pair or quartet not meeting Rule GR2.
-
A vector operand that Rules GR5 and GR6, kl.exec or kl.mvin and kl.mvout exclude, other than the MDH operand of
kl.mgmt, or a KLIOBUF variant ofkl.mvinorkl.mvoutwithkliobuftopnot a multiple of 16 (kl.mvin and kl.mvout). -
An encoding of an unimplemented extension.
-
- KLE missing-CSK
-
No CSK is active (mklcsk CSR Group); raised by every KLE instruction and KLE CSR access, except as Architectural Requirements on the Context Sealing Key states.
- KLE locker-Off
-
An access to a locker marked Off, except the destination access of a destructive configuration instruction other than
kl.swap, and any access of akl.clone,kl.renameorkl.swapwhose source and destination are the same locker (Destructive Configuration Instructions, kl.clone, kl.rename, and kl.swap, mllockerstatus, sllockerstatus, and vsllockerstatus for Dirtiness Tracking);kl.load,kl.mvinandkl.setsteare not exempt. - Third Group of Illegal-Instruction Exception Grounds
-
These grounds do not depend on the State of a locker (Rule GR12, item 7):
-
An MDH operand of
kl.mgmtinVsshorter than 128 bits, whatever the operation (Rules GR5, GR12, kl.mgmt). -
A Form A–C
kl.execwithklstart≠vstart×SEW/ 8 (Rule GR7). -
A non-zero
Xlwhere KLE Memory Instructions forbids it. -
A
kl.loadorkl.storeissued withklnamedlocker= 32 andXl≠ 0 (kl.input,kl.output) withoutZklio, or with an unconfigured KLIOBUF (Rule GR11). -
A
kl.derivewhoseKLNLoperand names its other locker (kl.derive). -
A
kl.availorkl.sizeof Form B or C whilemstatus.kleemulationis 1, that reaches the lookup of item 5 ofkl.sizewith an MDH whose combination of Machine fields the KLE unit does not natively implement (KLE Emulation Control in mstatus).
-
- Fourth Group of Illegal-Instruction Exception Grounds
-
These grounds depend on the State of the locker (Rule GR13), and none applies to an inert locker:
-
A transfer that the locker’s State does not admit, or a misaligned
klstart(Rules GR13.4, GR24). -
A
kl.mgmtout of sequence (Locker Management Operations). -
An instruction of Rule GR11 other than
kl.inputandkl.output, with an unconfigured KLIOBUF.
-
- KLE unsupported-Metadata
-
Unsupported Metadata at a provisioning- or import-opening
kl.mgmt, which leaves the locker Unconfigured (Provisioning- and Import-Opening kl.mgmt); only an M-mode handler can resolve it, by emulating the Machine (Emulation of Unsupported Machines). Accessing or using a locker in Statekl_stateext_unsupportedraises no such exception. - KLE privilege-violation
-
A usage instruction that the UsagePolicy denies (Rule GR17), or any use, clone or restriction of a locker in a Configuration State (Rule GR13.3).
- KLE clock-unavailable
-
The secure clock cannot be read to check a non-zero ExpirationDate (ExpirationDate Field).
- KLE out-of-memory
-
Insufficient KLF capacity for provisioning, import, or cloning (Locker Management Operations, kl.clone, kl.rename, and kl.swap).
- KLE RBG-unavailable
-
Random bits that an operation needs remain unavailable past the bound of Rule GR45.
- Memory exceptions
-
The load/store address breakpoint, address-misaligned, and page, guest-page and access-fault exceptions of a KLE memory instruction (GR41, Memory Instructions and Memory Model).
Error States
These conditions set an Error State without an exception; the list is informative, and the cited Rules govern:
-
Invalid:
-
invalid Metadata or SKID (Validity of Metadata, System Keys);
-
an instruction that the Machine, its State or MachinePolicy does not admit (Rule GR19, MR1), or a
kl.derivethat fails a check of Rule GR29; -
a transfer window of a length that the Machine does not admit, or a
klstartinside it that is not an interruption point (Rule GR18); -
a permanent RBG failure (Rule GR45);
-
a configuration error of the Machine (Rule MR2);
-
a field that fails its check when a
kl.derivetransfer completes, unless its Machine specifies another outcome (Rule GR28); -
a provisioning completion with a non-zero AuxDataLen or ADSDropped (Locker Management Operations);
-
a system-specific import whose MDH does not match its format, or whose format check fails when the format does not authenticate its data, or whose conversion or policy translation fails (Rules GR47 and GR51).
-
-
Expired: an ExpirationDate that has passed (ExpirationDate Field).
-
Privilege Violation: a failed narrowing (Narrowing of Metadata, kl.rstrl, kl.rstrh, and kl.rstrv, Rule GR30), a SKID resolution below the minimum SCProtection that the SKS associates with the SKID (Rule GR55.2), a restricted
kl.deriveinto a destination of lower SCProtection (Rule GR30), or a system-specific import whose format requires a higher side-channel protection level than the declared SCProtection (Rule GR51). -
Authentication Failed: a failed SCC authentication, at the completion of an import (Decryption and Authentication of a Complete SCC into a Locker) or of an export (Export-Completing kl.mgmt), so software checks the State after both; and a failed check that a system-specific format defines, when the format authenticates its data (Rule GR51).
-
Any Error State: the one that a
kl.setstenames (Rule GR26).
Two outcomes are not Error States: a Machine enters Failure on a data error (Rule MR2) or on a failed verification of an AEAD tag or a signature, which is a result, not an error; and an ADS that fails its check at import is dropped, the SCC accepted (Decryption and Authentication of a Complete SCC into a Locker).
Correspondence of Exceptions to Error States
Table 16 gives, for each KLE exception, the outcome that a handler that neither resolves nor forwards it produces under Rule SR10; the exception itself sets no Error State.
| Exception | Error State |
|---|---|
KLE fatal-error |
None: the condition is not recoverable. |
KLE missing-CSK |
None. |
KLE locker-Off |
None. |
KLE unsupported-Metadata |
Unsupported |
KLE privilege-violation |
Privilege Violation; a locker in a Configuration State keeps its State. |
KLE clock-unavailable |
Expired |
KLE out-of-memory |
Out of Memory |
KLE RBG-unavailable |
Invalid |
Any other exception that an opening |
Invalid |
For kl.clone and kl.derive, which name two lockers, that State is set on the locker on which the exception is raised: for kl.clone, the destination of a KLE out-of-memory exception; for kl.derive, the endpoint where the failing check is detected, the source being checked first (Rule GR27).
Management of Cryptographic Contexts
Following the RISC-V philosophy, KLE splits locker management into sequences of simple instructions, not single instructions that drive large state machines or microcode. As a consequence:
-
the state machines that manage keys and algorithms, which CISC key-protection solutions hide (cite:[IBM-z-arch] “Protection of Cryptographic Keys” or cite:[intel-keylocker]), are exposed to software: the hardware is simpler, though it enforces rules against misuse, and the software more complex;
-
interrupts and exceptions can separate the instructions of a management sequence, so context switching, process and virtual machine migration, hibernation, and interoperability between KLE implementations need explicit support; and
-
so does dynamic locker management, lazy context loading included, where other architectures cache repeated key uses implicitly.
Throughout, KLE preserves the integrity of the MDH and the confidentiality and integrity of the Content of a CC, and binary compatibility holds across implementations that support the same sub-extensions.
Appendix: Writing Software for KLE provides guidelines for system software.
Management States and Formats
A management operation is open from its opening kl.mgmt until its completing kl.mgmt, or until a destructive configuration instruction (Destructive Configuration Instructions) or a transition to an Error State discards the locker’s CC, which ends every open operation on it; kl.rename and kl.swap carry an open operation with the CC they move.
While it is open, the locker is in a Configuration State.
kl.mgmt opens or completes an operation according to its #immed7:
| Value | Mnemonic | Description |
|---|---|---|
56 |
|
Prepare a locker for provisioning. |
57 |
|
Prepare a locker for export. |
58 |
|
Prepare a locker for import. |
63 |
|
Complete the current management operation. |
Management operations use various formats to move a CC. The first two are the Provisioning Input (PI) and the Sealed Cryptographic Context (SCC):
- Definition: Provisioning Input (PI).
-
The MDH, with State and StateExtension zero, followed by the clear
Content. A PI is not a locker, so it is never Unconfigured. - Definition: Sealed Cryptographic Context (SCC).
-
Up to five sections, in this order, section 5 consisting of
Content1followed byContent2:Table 18. Plaintext of the Sealed Cryptographic Context (SCC) Format, all Sections in Order Section Section Name Size Description 1
MDH128 bits
See Metadata.
2
SIV128 bits
Authentication tag for
MDH, the Locality Secrets its Locality names, andContent1(Generation of an SCC from a Fully Configured Locker).3
IMPQUAL128 bits, if present
Identifies the implementation of the KLE unit. Non-authoritative, and ignored when ADSDropped = 1.
4
SIV2128 bits, if present
Authentication tag for
IMPQUAL,SIVandContent2. Non-authoritative, and not verified when ADSDropped = 1.5.a
Content1A multiple of 128 bits. See Length of External Formats and KLF Capacity Usage of a Locker.
Keys and other Machine-specific information that the Machine needs to function correctly. Its first
SCC_ClearLen1blocks are in clear (Rule GR9); the rest is encrypted in memory, and inside the KLE unit while the SCC is imported or exported.5.b
Content2A multiple of 128 bits.
ADS: data that the Machine does not need to function correctly. Its first
SCC_ClearLen2blocks are in clear (Rule GR9); the rest is encrypted in memory, and inside the KLE unit while the SCC is imported or exported.The clear blocks let software read public values, such as a public key, from an SCC in memory; they are authenticated only when the SCC is imported, so software does not rely on a value read from them as authentic (Rule SR19).
Sections 3, 4 and 5.b form the implementation-specific ADS, of size AuxDataLen (AuxDataLen and ADSDropped Fields). KLE generates an image with ADSDropped = 1 only as an SCC-shaped PCCC, when a nested export preserves an interrupted import after
Content2was dropped; since ADSDropped is unauthenticated, import also accepts this layout in an SCC modified to set the bit. - Definition: Base (Management) Operation.
-
A base management operation is a provisioning from a PI, in State
kl_cfg_provisioning; an import of an SCC or of a system-specific format (Rules for the Import of a System-Specific Format), inkl_cfg_importing; or an export of a locker in a Valid State, inkl_cfg_exporting. A provisioning or an import is base whenml.State is not a Configuration State, whatever the State of the locker it opens on; an export is base when it is opened on a locker in a Valid State. - Definition: Nested Management Operation and Base Type.
-
An exception may interrupt an open operation. A handler then saves the locker by a nested export, an export opened on a locker in a Configuration State, and restores it by a nested import of the resulting image, opened whatever the State of the locker; the image is the Partially Configured Cryptographic Context (PCCC) defined below. Nested operations may themselves be interrupted and nested. States
kl_cfg_ppi_exportingandkl_cfg_ppi_importingresult only from nested operations, and are not#immed7values. Each Configuration State (Table 8) encodes the base type of its operation, which fixes the format and length of the locker’s image at every nesting depth (kl.avail and kl.size):-
pi, for a provisioning:kl_cfg_provisioning, andkl_cfg_ppi_exportingandkl_cfg_ppi_importing(“ppi” means “partial provisioning input”) for nested operations; -
sccotherwise:kl_cfg_exportingandkl_cfg_importing, for base and nested operations alike.
-
- Definition: Partially Configured Cryptographic Context (PCCC).
-
The third format is the image that an export produces on a locker already in a Configuration State: an MDH holding a Configuration State, in the format of its base type, without further encryption or authentication:
-
base type
pi: a PI-shaped image, the MDH followed by the clearContentthat software supplied in the PI; software clears such a locker before giving control to another software context, of the same or a lower privilege, which could otherwise export it (Rule SR1); -
base type
scc: an SCC-shaped image, in the format of an SCC: the MDH followed bySIVand, when present,IMPQUALandSIV2, as ContentOffset prescribes (serialized image), and by theContentalready in the locker, in the form of an SCC, its clear blocks in clear and the rest as ciphertext; with Version = 3, the MDH followed only by theContentas software supplied it (Rules for the Import of a System-Specific Format).
-
The fourth format is used for CCs in an Error State.
- Definition: Error-State image.
-
The exported image of an Error-State locker is the MDH alone: its export reads the MDH from the locker and writes it to memory; its import is a single
kl.mgmt(Export and Import of a Locker in an Error State).
Software saves the locker’s MDH as ml before opening an export, and an import takes ml from the image. The completing kl.mgmt restores State from ml, so each nesting level keeps its own State; completing a base operation leaves the locker in a Valid or Error State, and completing a nested operation restores the Configuration State that ml carries (Rule GR25).
- Encryption during management
-
While an SCC is imported, or a locker exported as one, the locker holds its
Contentencrypted, except for its clear blocks (Rule GR9): the base export-openingkl.mgmtencrypts it and generatesSIVand, if AuxDataLen ≥ 2,IMPQUALandSIV2; the base import- or export-completingkl.mgmtdecrypts and authenticates it once the whole image is in place, or restores it from an internal copy (Export-Completing kl.mgmt); with ADSDropped = 1, noContent2is loaded or authenticated. - Definition: Serialized image.
-
content_sizeis the length in bytes of the serializedContentof the locker, as a PI or an SCC according to the base type of its image (Length of External Formats and KLF Capacity Usage of a Locker), as given by the locker’s MDH. In a PI, an SCC or a PCCC, theContentstarts at a ContentOffset that depends on that MDH:-
0 if MDH.Version is 3 (Rules for the Import of a System-Specific Format),
content_sizeandmax_admissiblethen both being 16 × AuxDataLen; -
otherwise, 16 if AuxDataLen = 0, and 48 if AuxDataLen ≥ 2, if MDH.State is a Valid State,
kl_cfg_importingorkl_cfg_exporting; -
0 if MDH.State is 0 (the MDH of a PI),
kl_cfg_provisioning,kl_cfg_ppi_importingorkl_cfg_ppi_exporting.The serialized image
Sof the locker isContent,SIV ‖ Content, orSIV ‖ IMPQUAL ‖ SIV2 ‖ Contentfor ContentOffset = 0, 16 or 48, respectively; while the locker is under management, the authentication registers (The Cryptographic Locker File and Authentication Information) hold its leading fields. Its size isimage_size= ContentOffset +content_size, the value thatkl.sizereports minus 16.max_admissibleis the length in bytes of the longestContentof the locker’s base type that the implementation can hold for the Machine:pi_content_sizefor base typepi, andcontent1_sizeplus the largest supportedcontent2_sizefor base typescc(kl.avail and kl.size); with ADSDropped = 1,content2_sizecounts as zero. Bytes ofContentbeyondmax_admissiblebelong to a discarded ADS (Decryption and Authentication of a Complete SCC into a Locker), and are not transferred. The transferred part ofSends atimage_end= ContentOffset + min(content_size,max_admissible). Accesses toSare 16-byte granular: the management transfer instructions (Rule GR4) transfer whole 16-byte blocks, and all their offsets and lengths,klstart,content_size,max_admissible,image_sizeandimage_end, are multiples of 16.
-
Length of External Formats and KLF Capacity Usage of a Locker
| GR52 |
The length of an external image depends only on fields in bits [63:0] of its MDH, as follows, where the bullets are considered in order:
|
| GR53 |
The KLF capacity used by a locker is fixed when the opening |
Single-Share Key Export Rule for Masked Implementations
| GR54 |
Single-share export: A multi-share implementation of a Machine provisions, imports and exports all its keys and secrets as reconstructed values. Such an implementation may copy System Key material from the SKS into the locker and expand it into shares, but exports the key only as its SKID (Rule GR55.1); no ADS, alone or combined with any other data that KLE exports, including other SCCs of the same CC, may allow or facilitate recovering a key value configured by a SKID. |
| Reconstructing or re-randomizing a key is usually an inexpensive operation, for instance when a block cipher in counter mode generates the masks; an implementation with a slower share generator may keep shares or masks in the ADS. |
System Keys
| GR55 |
System Keys. A System Key is identified by a 64-bit SKID, from which a system-specific SKS retrieves the key: the images of the locker carry the SKID in place of the key (Rule GR55.1), and the SKS resolves the SKID and binds policies to it (Rules GR55.2 and GR55.3).
|
The state mask of Rule GR55.2 hides the capacity part of state, of c bits (Parameters of the SHA-3 family); its rate part is known once a CC in Hash_Output is exported, since that rate holds output.
Whoever holds the CSK can compare masked states, and so learns which CCs of one SKID and Machine absorbed equal block-aligned prefixes.
By importing a masked state XORed with a chosen value, that party also obtains E(w) = P(w xor state_mask) xor state_mask, a single-key Even–Mansour cipher over KECCAK-p[1600, 24] whose unknown key is the capacity part of the mask.
A generic attack then needs D × T ≈ 2c for D queries and time T (Dunkelman, Keller and Shamir, EUROCRYPT 2012), so at least 2c/2 operations: the generic security of the sponge itself, 128 bits for KMAC128.
The SKS may derive state_mask from a secret of its own with a KDF of SP 800-108r1, under a label that no key derivation uses.
A derivation by KMAC or cSHAKE from the key is unsafe: the KMAC Machine does not check cshake_block (KMAC128, KMAC256, KMACXOF128, and KMACXOF256), so anyone allowed to use the SKID with KMAC computes cSHAKE over key_block with any function name and customization string.
|
Locker Management Operations
This section defines the operations that kl.mgmt performs for the #immed7 values of Table 17.
Two steps are common to every operation below and are not repeated in their descriptions; after the checks of Rule GR12, a kl.mgmt with KLNL and klnamedlocker = 32 performs only these two (Rule GR13.2):
The next six subsections describe the semantics of kl.mgmt:
Provisioning- and Import-Opening kl.mgmt
Software first obtains the MDH, ml, and supplies it with a Form C or D kl.mgmt.
For an import, software first saves ml in its local state and supplies it to the import-completing kl.mgmt, to restore the State the locker had when it was exported (Rule GR25).
The kl.mgmt instruction:
-
zeroizes the target locker, as a destructive configuration instruction; bytes of the
Contentof the serialized imageSnot yet written since this opening read as zero through every architectural access (kl.store,kl.mvout, verbatim export); its authentication fields read the current values of the authentication registers (The Cryptographic Locker File and Authentication Information), which an import opening zeroizes;
-
if
#immed7=kl_cfg_importingandmlis in an Error State (State 0, StateExtension 1–6), instead takes the short import path of Export and Import of a Locker in an Error State: it configures the locker immediately in that Error State, or in Invalid if the MDH is invalid, skips the steps below, and opens no management operation; -
for an import, zeroizes the authentication registers
SIV,IMPQUALandSIV2(The Cryptographic Locker File and Authentication Information); -
copies
mlintoM, zeroing MachineUse and the implementation-defined subfields of AuxInfo (MachineUse and AuxInfo Fields) for a provisioning; the checks below are made onM, the locker’s MDH staying zero; -
for a provisioning:
-
requires
ml.State to be 0, else the Metadata is invalid; the locker’s State stays Unconfigured during the checks below, until successful configuration; -
requires
M.AuxDataLen andM.ADSDropped to be 0: if either is non-zero, the locker transitions to Error State Invalid and the instruction terminates;
-
-
transitions the locker to Error State Invalid if
Mis invalid Metadata (Validity of Metadata), an Unconfiguredmlbeing invalid for an import unlessml.Version is 3, and skips the steps below; -
raises a KLE unsupported-Metadata exception if
Mis unsupported Metadata (Validity of Metadata); -
attempts to allocate the KLF capacity that the fields Machine, MachinePolicy, MachineExtension, SCProtection and KeyType of
Mrequire (Length of External Formats and KLF Capacity Usage of a Locker) and, ifM.Version is 3, the capacity for 16 ×M.AuxDataLen bytes of data (Rule GR50), and raises a KLE out-of-memory exception if it cannot; -
for a provisioning, installs
Mas the locker’s MDH, with Statekl_cfg_provisioning; -
for an import:
-
installs
Mas the locker’s MDH, with ADSDropped = 1 ifM.Version is not 3,M.AuxDataLen ≥ 2, and eitherM.ADSDropped = 1 orM.AuxDataLen exceeds the maximum of the implementation for the Machine, and with ADSDropped = 0 otherwise (Step 4 of Decryption and Authentication of a Complete SCC into a Locker); -
sets the locker’s State to
kl_cfg_importingifml.State is a Valid State,kl_cfg_importingorkl_cfg_exporting, orml.Version is 3; -
sets it to
kl_cfg_ppi_importingif the base type ofml.State ispi(Management States and Formats).
-
Whenever a check above fails, raising a KLE exception or transitioning the locker to Error State Invalid, every MDH field other than State and StateExtension remains zero and no KLF capacity is allocated; after a KLE out-of-memory exception, the locker remains Unconfigured until a handler sets Error State Out of Memory (SR10).
This does not apply to configuring a locker directly into an Error State from ml, which installs the MDH as Export and Import of a Locker in an Error State states.
|
Clearing the locker right after the locker-state-independent checks of Rule GR12, before any check of the opening itself, guarantees that any later failure has the same effect: the old content is destroyed and |
Export-Opening kl.mgmt
Software first saves a copy, ml, of the locker’s MDH, to restore the State when completing the export.
kl.mgmt can be of Form A, C or D, and ignores its auxiliary input. Depending on ml.State:
-
Unconfigured: no operation and no exception. No management operation is opened, the authentication registers are unchanged, and only the common steps above take effect (Rule GR13.2).
-
An Error State: the locker is unchanged, and no management operation is opened (Rule GR26); Export and Import of a Locker in an Error State details this short export path.
-
A Valid State: if the Locality of the MDH names an unconfigured entry without a configured substitute (Locality Field), no operation and no exception: no management operation is opened, the State and the authentication registers are unchanged, and only the common steps above take effect. Otherwise the instruction prepares the locker to produce an SCC, encrypting its contents and computing the authentication tag(s) as Generation of an SCC from a Fully Configured Locker specifies, and sets its State to
kl_cfg_exporting. The openingkl.mgmtchanges no MDH field other than State: an implementation that creates or changes an ADS, or uses MachineUse, always keeps AuxDataLen and MachineUse current, so that the MDH software reads before opening the export is the one the export authenticates. -
A Configuration State (the export of a partially configured locker, or a nested export):
-
no encryption or authentication occurs: the locker’s contents are exported verbatim, in their order in the PI (for a partially provisioned locker) or in the SCC (for a partially imported locker, or a locker whose own export was interrupted);
-
the locker’s State is set to
kl_cfg_ppi_exportingorkl_cfg_exporting, according to its base type (Management States and Formats).
-
Common Properties of Completing kl.mgmt
Two special cases:
-
kl_cfg_management_endissued on a locker in a Valid State raises an illegal-instruction exception: no management operation is open on it. -
kl_cfg_management_endissued on an Unconfigured or Error-State locker performs no operation, raises no exception and ignoresml; only the common steps above take effect (Rule GR13.2).
These two special cases aside, a kl.mgmt issued to complete a management operation
first reads the target locker’s MDH, and completes a provisioning if its State is kl_cfg_provisioning, an import if it is kl_cfg_importing or kl_cfg_ppi_importing, and an export if it is kl_cfg_exporting or kl_cfg_ppi_exporting.
When completing an import or an export, it consumes only the State field of the auxiliary operand ml, which restores the locker’s State to the value that ml records; no other MDH field is written from ml.
The locker keeps the StateExtension that it holds during the operation: for an export, the one that it had when the export was opened; for an import, the one carried in the image (Decryption and Authentication of a Complete SCC into a Locker). The completion restores StateExtension @ State without reading ml.StateExtension.
An Error State never reaches a completion: its image is the MDH alone, imported by the short import path, and an export opened on an Error-State locker opens no operation (Export and Import of a Locker in an Error State).
On completing an SCC import or a locker export, authentication is checked only if setting locker.MDH.State to ml.State restores a Valid State; the probability of accepting an incorrect State is negligible.
A nested completion checks only the base type, without authentication.
If a completion that restores a Valid State finds that the Locality of the MDH names an unconfigured entry with no configured substitute (Locality Field), the locker transitions to Error State Invalid without decryption or authentication.
The kl.mgmt completing an import or an export admits these values of ml.State (Management States and Formats); any other, 61–63 included, raises an illegal-instruction exception:
-
a locker whose MDH has Version = 3:
kl_cfg_importingorkl_cfg_exporting, and, for a locker inkl_cfg_importing, also State 0, which completes the system-specific import (Rule GR51); -
otherwise, a locker of base type
scc(kl_cfg_importingorkl_cfg_exporting): a Valid State (1–55),kl_cfg_importingorkl_cfg_exporting; -
a locker of base type
pi(kl_cfg_ppi_importingorkl_cfg_ppi_exporting):kl_cfg_provisioning,kl_cfg_ppi_importingorkl_cfg_ppi_exporting, never a Valid State, so the clearContentof a partially provisioned locker becomes usable only by completing its provisioning.
Provisioning-Completing kl.mgmt
No MDH saved at provisioning start is needed: kl.mgmt can be of Form A, C or D, and ignores its auxiliary input.
It transfers no data to or from memory, vector registers, the KLIOBUF or another locker, so the random generation of keys for KeyType = 2 never waits for, or delays, a data transfer (Rule MR19).
Completing a provisioning requires AuxDataLen = 0 and ADSDropped = 0; if locker.MDH.State is kl_cfg_provisioning and either field is non-zero, the locker transitions to Error State Invalid, and the instruction terminates.
The operation makes the provisioned locker available to software by:
-
for KeyType = 2, generating the key and setting KeyType to 0 (KeyType Field, Rule GR45), and for KeyType = 1, applying the SKID resolution of System Keys;
-
converting the locker’s content into the internal format of the KLE unit;
-
performing any check required by the Machine on the fields of the PI (Rule MR3); a failed check transitions the locker as Rule MR2 classifies it, to Error State Invalid for a configuration error or to Failure for a data error, in place of the step below; and
-
setting State to Ready, with the operations of entering it (Rule MR17), and StateExtension, MachineUse and the implementation-defined subfields of AuxInfo to 0.
If a process is preempted during provisioning, kl.store or kl.mvout exports only the original PI information, unencrypted.
Within a provisioning, only its completing kl.mgmt may generate secret random material needed to configure the locker, retrieve key material from the SKS, or derive, expand or re-share that material, so that no such material is exposed in an unencrypted export of a partially provisioned locker.
Import-Completing kl.mgmt
Software uses Form C or D of kl.mgmt to supply the value ml saved when the import started.
The image authenticated as AD[0] is the MDH held in the target locker, i.e., the one carried in the SCC and loaded when the import started, with its State restored from ml and ADSDropped cleared only in the copy used for authentication (Decryption and Authentication of a Complete SCC into a Locker).
-
If locker.MDH.Version is 3 and
ml.State is 0, the instruction completes the system-specific import as Rules for the Import of a System-Specific Format states. -
If
ml.State is a Valid State (the import of the export of a fully configured locker):-
locker.MDH.State is set to
ml.State. -
The KLE unit decrypts and authenticates the locker’s content.
-
If authentication fails, the target locker transitions to Error State Authentication Failed, without an exception. Otherwise, the ADS is processed, or dropped, as Decryption and Authentication of a Complete SCC into a Locker states; then, if KeyType = 1, the SKID is resolved, and the narrowing of System Keys is applied.
-
The KLE unit converts the locker’s content into its internal format.
-
The KLE unit performs the checks that the Machine attaches to the fields that the import restores (Rule MR3); a failed check transitions the locker as when completing a provisioning (Rule MR2). This makes the locker available to software.
-
-
Otherwise (the import of the export of a partially configured locker, or of a nested export), locker.MDH.State is set to
ml.State.
Export-Completing kl.mgmt
Software uses Form C or D of kl.mgmt to supply the MDH value ml saved when the export began. Then:
-
The State of the locker is set to
ml.State. -
If
ml.State is a Valid State, the instruction restores the locker to the clear format it had when the export began, and makes it accessible to software:-
it decrypts and authenticates the contents as when completing an import, with the MDH held in the locker as
AD[0], and ADSDropped cleared in the copy that first-segment authentication consumes; -
if the
SIVcheck fails, the locker transitions to Error State Authentication Failed, and the instruction terminates without an exception; otherwise it performs Steps 14–15 of Decryption and Authentication of a Complete SCC into a Locker, and then the steps that follow authentication in the import-completingkl.mgmt(Locker Management Operations): SKID resolution and narrowing for KeyType = 1, conversion into the internal format, and the checks of Rule MR3, with the same outcomes.
-
-
If
ml.State is not a Valid State, the locker’s contents are not changed further.
Instead of decrypting and authenticating the locker’s contents in Step 2.a, an implementation may restore the clear contents from an internal copy, made when the export was opened, if the outcome is identical; the specification defines no mechanism for this, and Step 2.b then follows as after a successful SIV check.
The copy is valid only if, since the export was opened:
-
no instruction has written the locker’s MDH or contents, moved its CC, or opened or completed a management operation on it other than this export, so that a nested export or import, a destructive configuration instruction,
kl.setste,kl.renameorkl.swapon the locker invalidates the copy; -
SIVand, if the image carries them,IMPQUALandSIV2still hold the values that the opening generated; and -
the CSK and the
LST_effentry of every Locality that the MDH names (Locality Field), which the decryption and authentication use, are unchanged.
With a valid copy, Step 2.b still performs SKID resolution and narrowing for KeyType = 1 against the current SKS state, so a revoked SKID or a changed SKS policy has the same outcome as on the full path.
Without a valid copy, the instruction decrypts and authenticates as Step 2.a states.
With one, it uses the copy only if ml.State equals the State that the locker had when the export was opened; otherwise it transitions the locker to Error State Authentication Failed, as the failing SIV check would.
SCC Export and Import Algorithms
Section The SCC Authenticated Encryption Scheme defines the authenticated encryption scheme, and Generation of an SCC from a Fully Configured Locker and Decryption and Authentication of a Complete SCC into a Locker the SCC export and import algorithms.
The SCC Authenticated Encryption Scheme
SCC export and import use a variant of AES-GCM-SIV cite:[DBLP-journals-iacr-GueronLL17,RFC8452] that differs from the standard as follows:
the POLYVAL input does not contain the lengths of the associated data and plaintext, since they are already implied by the MDH;
the nonce is omitted, which amounts to the all-zero nonce of RFC 8452;
a domain separation bit, sep, distinguishes the two segments of the content sealed in an SCC: the architected content (sep = 0) and the optional implementation-specific content (sep = 1); sep replaces bit 126 of the tag input and of every counter block; and
for sep = 0, bit 47 of MDH (the first block of the associated data), i.e.,
the unauthenticated ADSDropped bit of the MDH (AuxDataLen and ADSDropped Fields), is cleared before POLYVAL is evaluated.
The clear blocks of a segment (Rule GR9) are appended to its associated data, and only the remaining blocks are encrypted.
The Key Derivation (RFC 8452 Key Derivation) and POLYVAL (POLYVAL Hashing Function) functions are defined first, then SCC generation from a locker (Generation of an SCC from a Fully Configured Locker) and SCC import into a locker (Decryption and Authentication of a Complete SCC into a Locker).
In the pseudocode, AESE256(K, B) denotes the AES-256 encryption of the 128-bit block B under the 256-bit key K (FIPS 197 cite:[nist-fips-197]).
function SCC_KeyDeriv(key : bits(256))
→ struct{enc_key : bits(256), auth_key : bits(128)} =
{
local A : array [0..5] of bits(128);
local i : int;
foreach(i from 0 to 5) do:
A[i] ← AESE256(key, bin(i,128));
return struct { enc_key = A[5][63:0] @ A[4][63:0] @ A[3][63:0] @ A[2][63:0],
auth_key = A[1][63:0] @ A[0][63:0] }
}
function POLYVAL(auth_key : bits(128), blocks[] : array of bits(128), n : int)
→ bits(128) =
{
local tmp : bits(128) ← zeros(128);
local i : int;
foreach(i from 0 to n-1) do:
tmp ← tmp xor blocks[i];
tmp ← Montmul(tmp, auth_key);
return tmp;
}
POLYVAL uses Montgomery multiplication, Montmul(a, b), in the field F = GF(2)[x] modulo x128 + x127 + x126 + x121 + 1.
A 128-bit value V represents the element whose coefficient of xk is V[k];
byte order and bit order both run forward, as in
cite:[RFC8452] §3, under which x0 is the byte string 0x01 followed by
fifteen zero bytes, i.e., the value 1. Then:
Montmul(a, b) = a · b · x-128 in the field F.
The SCC encryption and decryption functions, AES-GCM-SIV Encryption for SCC Generation and AES-GCM-SIV Decryption for SCC Import, use this notation:
-
AD[]denotes the Associated Data as an array oflen_AD128-bit blocks, that isAD[0] ‖ AD[1] ‖ … ‖ AD[len_AD-1], in that order; -
P[], resp.C[], denotes a Plaintext, resp. a Ciphertext, as arrays oflen_PC128-bit blocks, that isP[0] ‖ P[1] ‖ … ‖ P[len_PC-1], resp.C[0] ‖ C[1] ‖ … ‖ C[len_PC-1], in that order; -
Kis a 256-bit Key; and -
SIVis a 128-bit SIV/tag.
function SCC_Encrypt(AD[] : array of bits(128), sep: bits(1),
P[] : array of bits(128), K : bits(256), len_AD : int, len_PC : int)
→ {SIV : bits(128), C[] : array of bits(128)} =
{
local AD_auth : array [0..len_AD-1] of bits(128) ← AD[];
local keys : struct{enc_key : bits(256), auth_key : bits(128)};
local i : int;
keys ← SCC_KeyDeriv(K);
if (sep = 0) then:
AD_auth[0][47] ← 0;
SIV ← POLYVAL(keys.auth_key, AD_auth[] ‖ P[], len_AD + len_PC);
SIV ← AESE256(keys.enc_key, zeros(1) @ sep @ SIV[125:0]);
foreach(i from 0 to len_PC - 1) do:
C[i] ← P[i] xor AESE256(keys.enc_key,
ones(1) @ sep @ SIV[125:32]
@ bin((int(SIV[31:0]) + i) mod 2**32, 32));
return ( SIV, C[] );
}
len_PC never exceeds max_admissible / 16 (serialized image), and len_AD never exceeds 7 plus the number of clear blocks of the segment.
function SCC_Decrypt(AD[] : array of bits(128), sep: bits(1),
SIV : bits(128), C[] : array of bits(128), K : bits(256),
len_AD : int, len_PC : int)
→ {correct : bool, P[] : array of bits(128)} =
{
local AD_auth : array [0..len_AD-1] of bits(128) ← AD[];
local keys : struct{enc_key : bits(256), auth_key : bits(128)};
local s, tmp : bits(128);
local i : int;
keys ← SCC_KeyDeriv(K);
if (sep = 0) then:
AD_auth[0][47] ← 0;
foreach(i from 0 to len_PC - 1) do:
P[i] ← C[i] xor AESE256(keys.enc_key,
ones(1) @ sep @ SIV[125:32]
@ bin((int(SIV[31:0]) + i) mod 2**32, 32));
s ← POLYVAL(keys.auth_key, AD_auth[] ‖ P[], len_AD + len_PC);
tmp ← AESE256(keys.enc_key, zeros(1) @ sep @ s[125:0]);
if (tmp ≠ SIV) then:
foreach(i from 0 to len_PC - 1) do:
P[i] ← zeros(128);
return ( false, P[] );
return ( true, P[] );
}
The comparison tmp ≠ SIV is performed in constant time.
SCC_KeyDeriv, SCC_Encrypt and SCC_Decrypt have the protection of the SCProtection level of the locker that is exported or imported (The Cryptographic Locker File and Authentication Information); at every level, they take a time independent of the CSK, the derived keys, the Locality Secrets and the plaintext.
It is strongly recommended that their memory accesses also be independent of these values.
Generation of an SCC from a Fully Configured Locker
A locker K(i) in a Valid State is fully provisioned, and opening it for export creates the serialized and authenticated SCC, encrypted except for its clear blocks (Rule GR9), by the steps below.
The Locality substitution rules of Locality Field apply: LST_eff[j] is the value of LST entry j after substitution, and replaces LST[j] in the export and import algorithms.
An unconfigured entry (Locality Field) with no configured substitute makes the Metadata invalid at provisioning or import, and makes the export-opening kl.mgmt of a locker in a Valid State perform no operation (Rule SR12). Entry 9 of LST is hkllocality, and entry 10 is skllocality.
After kl.clearads, a fully configured locker has AuxDataLen = 0 and ADSDropped = 0 (kl.clearads); KLE sets ADSDropped = 1 only in an SCC-shaped PCCC, to preserve an interrupted import after Content2 was dropped (Management States and Formats).
K(i)-
Step 1: Read the MDH with
kl.getmd; if it is in an Error State, use the method of Export and Import of a Locker in an Error State instead. -
Step 2: Store the MDH at offset 0 of the SCC buffer, in the byte order of Endianness.
-
The export-opening
kl.mgmt Kd/KLNL, #kl_cfg_exportingperforms Steps 3 and 4:-
Process the architected content:
-
saved_MDH←K(i).MDH,len_AD← 1 -
K(i).MDH.State ←kl_cfg_exporting -
AD[0]←saved_MDH(no need to mask ADSDropped: it is zero in a fully configured locker). -
foreach(j from 0 to 10) do:
-
If
saved_MDH.Locality names Locality #j (Table 9), then-
AD[len_AD]←LST_eff[j],len_AD←len_AD+ 1
-
-
-
n1←SCC_ClearLen1forsaved_MDH(Rule GR9); foreach(j from 0 ton1− 1) do:-
AD[len_AD]←K(i).Content1PT[j],len_AD←len_AD+ 1
-
-
len_PC← the number of 128-bit blocks ofContent1, minusn1. -
SIV,Content1CT[]←
SCC_Encrypt(AD, 0,
K(i).Content1PT[n1..n1+len_PC-1], CSK, len_AD, len_PC)
-
-
If AuxDataLen ≥ 2, process the implementation-specific content:
-
len_AD2← 2,
AD2[0]←IMPQUAL← theIMPQUALof the implementation (AuxDataLen and ADSDropped Fields), formed from the values ofmklvendorid,mklarchidandmklimpidout of KLE unit reset,AD2[1]←SIV. -
n2←SCC_ClearLen2forsaved_MDHandIMPQUAL(Rule GR9); foreach(j from 0 ton2− 1) do:-
AD2[len_AD2]←K(i).Content2PT[j],len_AD2←len_AD2+ 1
-
-
len_PC2← AuxDataLen − 2 −n2, the number of 128-bit blocks ofContent2that are encrypted. -
SIV2,Content2CT[]←
SCC_Encrypt(AD2, 1, K(i).Content2PT[n2..n2+len_PC2-1], CSK, len_AD2, len_PC2)
-
-
-
A loop of
kl.storeorkl.mvoutinstructions saves the serialized imageS(serialized image) at offset 16 of the SCC buffer:-
If AuxDataLen = 0,
S=SIV‖Content1CL‖Content1CT, whereContent1CLisContent1PT[0..n1-1]. -
Otherwise,
S=SIV‖IMPQUAL‖SIV2‖Content1CL‖Content1CT‖Content2CL‖Content2CT, whereContent2CLisContent2PT[0..n2-1], and any of the four parts may be empty. -
Store
Sto memory.
-
-
The completing
kl.mgmtrestores the locker as Export-Completing kl.mgmt specifies.
|
An export completed prematurely fails authentication at import (Decryption and Authentication of a Complete SCC into a Locker) with overwhelming probability, and an import completed prematurely fails it at once; an operation left incomplete keeps the locker in a Configuration State, in which most instructions fail. |
Decryption and Authentication of a Complete SCC into a Locker
The following algorithm imports the SCC of a fully configured locker. For an SCC whose MDH is in an Error State, use the method of Export and Import of a Locker in an Error State.
K(i)-
Step 1: Read
M, the MDH of the SCC, from memory, in the byte order of Endianness. -
The import-opening
kl.mgmt Kd/KLNL, #kl_cfg_importing, Vs/Xs, withMinVsorXs, performs the following Steps:-
Clear and deallocate
K(i), and zeroizeSIV,IMPQUALandSIV2. -
Make the opening checks of Provisioning- and Import-Opening kl.mgmt on
M, stopping with their outcome if one fails. -
K(i).MDH ←M, withK(i).MDH.ADSDropped ← 1 ifM.Version is not 3,M.AuxDataLen ≥ 2, and eitherM.ADSDropped = 1 orM.AuxDataLen exceeds the implementation’s maximum for the Machine, and ← 0 otherwise. -
Determine the SCC layout from
K(i).MDH. -
Set the appropriate Configuration State according to Provisioning- and Import-Opening kl.mgmt.
-
-
A loop around
kl.load/kl.mvininstructions performs the following step:-
Load the rest of the SCC from its offset 16, to the length that the working MDH gives: with ADSDropped = 1,
SIV,IMPQUAL,SIV2andContent1, but noContent2.
-
-
The completing
kl.mgmtdecrypts and authenticates the SCC and makes it available to software:-
saved_MDH← the MDH image held inK(i), that isMwith the working ADSDropped and its State field restored from the auxiliary operand of the completingkl.mgmt. -
AD[0]←saved_MDH,len_AD← 1.SCC_Decryptclears ADSDropped in its local copy ofAD[0]before authenticating it; the MDH held inK(i)is unchanged by that computation. -
foreach (
jfrom 0 to 10) do:-
If
saved_MDH.Locality names Locality #j (Table 9), then:-
AD[len_AD]←LST_eff[j],len_AD←len_AD+ 1
-
-
-
n1←SCC_ClearLen1forsaved_MDH(Rule GR9); -
foreach (
jfrom 0 ton1− 1) do:-
AD[len_AD]←K(i).Content1[j],len_AD←len_AD+ 1; thenlen_PC← the number of 128-bit blocks ofContent1, minusn1.
-
-
correct,K(i).Content1[n1..n1+len_PC-1]←
SCC_Decrypt(AD, 0, SIV,
K(i).Content1[n1..n1+len_PC-1], CSK, len_AD, len_PC). -
If
correct≠true, the SCC is rejected:K(i)transitions to Error Statekl_stateext_mgmt_auth(Authentication Failed, Rule GR15), and the remaining steps are skipped. -
If
K(i).MDH.AuxDataLen ≥ 2 andK(i).MDH.ADSDropped = 0, process the implementation-specific content:-
len_AD2← 2,AD2[0]←K(i).IMPQUAL,AD2[1]←SIV. -
If
K(i).IMPQUAL= theIMPQUALof the implementation (AuxDataLen and ADSDropped Fields), formed from the values ofmklvendorid,mklarchidandmklimpidout of KLE unit reset, then:-
n2←SCC_ClearLen2forsaved_MDHandK(i).IMPQUAL(Rule GR9); -
foreach (
jfrom 0 ton2− 1) do:-
AD2[len_AD2]←K(i).Content2[j],len_AD2←len_AD2+ 1.
-
-
len_PC2←K(i).MDH.AuxDataLen − 2 −n2, the number of encrypted 128-bit blocks ofContent2. -
correct,K(i).Content2[n2..n2+len_PC2-1]←
SCC_Decrypt(AD2, 1, SIV2,
K(i).Content2[n2..n2+len_PC2-1], CSK, len_AD2, len_PC2).
-
-
else:
-
correct←false.
-
-
If
correct≠true, then:-
drop
Content2and setK(i).MDH.ADSDropped to 1.
-
-
-
If
K(i).MDH.AuxDataLen = 0 orK(i).MDH.ADSDropped = 1:-
Zero the implementation-defined subfields of the MDH (MachineUse and AuxInfo Fields);
-
ADSDropped ← 0; and
-
AuxDataLen ← 0 (it may be set to at least 2 again if the implementation generates a replacement ADS right away).
-
-
Design Rationale for the Sealing Construction
This section is informative.
Omitting the nonce shrinks the payload and lets the derived keys be cached; the nonce-misuse resistance of AES-GCM-SIV keeps the construction secure for up to O(264) blocks observed by an adversary. On cloud servers, each virtual machine and supervisor domain should have its own CSK; M-mode firmware moves a CC between them by importing its SCC under the source CSK and exporting it under the target CSK.
The SIV, the GCM-SIV tag, is the encryption of the POLYVAL hash (POLYVAL Hashing Function) of the MDH with ADSDropped cleared, the Locality Secrets and the Content. Including the Locality Secrets in the SIV, instead of deriving keys from them, binds the SCC to the Localities for one Montmul per block, far less than most KDFs, and keeps the keys cacheable, since a change of the set derives no new keys.
Distinct sets give the same SIV with probability at most max(len_AD + len_PC) × 2-126, the maximum taken over the two sets.
Taking SIV as AD2[1] makes SIV2 and the second keystream depend on the first payload, so an ADS cannot be grafted onto another SCC.
As in AES-GCM-SIV, bit 127 separates tag inputs from keystream inputs; bit 126 separates the keystreams of the two segments, at the cost of one bit of security.
The clear blocks (Rule GR9) are associated data, but the POLYVAL input is the same as if they were encrypted; the authenticated MDH and IMPQUAL fix their number, so the lengths stay implied and the bound above holds.
Leaving public fields unencrypted saves one AES-256 evaluation per clear block at export and at import, and lets software read them from the SCC.
They are restricted to values that their role makes public because an export is not gated by UsagePolicy (UsagePolicy Field), and because a clear block is readable on any device and after the CC expires; which fields are clear depends on no value that a kl.rstrl or a transition changes, so a field that held a secret never becomes clear.
Export and Import of a Locker in an Error State
A locker in an Error State is only an MDH (Rule GR15) and uses no KLF capacity.
Its import checks the MDH as any supplied MDH (Validity of Metadata).
There is no Content to encrypt, and KLE does not authenticate the MDH: any software in the current environment can produce any Error State by issuing kl.setste, so authentication would prove nothing.
Neither direction produces an SCC or a PCCC, opens a management operation, uses SIV, SIV2 or IMPQUAL, or takes part in resumption.
Exporting such a locker needs no kl.mgmt: kl.getst (kl.getst and kl.getstx) finds an Error State, and kl.getmd or kl.getmdv (kl.getmd, kl.getmdl, and kl.getmdv) reads the MDH, which software stores; kl.size reports 16.
A kl.mgmt with #immed7 = kl_cfg_exporting on such a locker is permitted but useless: it leaves the locker unchanged and opens no management operation, and only its common steps take effect, klnamedlocker naming the locker and klstart becoming 0 (Locker Management Operations).
Importing the image takes one uninterruptible kl.mgmt with #immed7 = kl_cfg_importing and the 16-byte MDH as the auxiliary operand, carried whole by Form C or D.
It zeroizes the locker that it names; if the MDH is invalid Metadata (Validity of Metadata), it transitions the locker to Error State Invalid, as any import does; otherwise the MDH is installed as is, with only AuxDataLen and ADSDropped set to 0 (Rule GR15), and nothing else is transferred.
A kl.mgmt with #immed7 = kl_cfg_management_end is not needed after it, and performs no operation (Rule GR13.2).
Architectural Requirements on the Context Sealing Key
The KLE unit operates only with an active Context Sealing Key (CSK): with a hardwired CSK it is available from reset, otherwise once the CSK is established.
Without an active CSK, every KLE instruction and KLE CSR access raises a KLE missing-CSK exception, except writes to the mklcsk group and accesses to the Locality Secret CSR groups (Locality Secret CSR Groups), which are configured independently of the CSK.
Each hart holds a CSK, established in exactly one of four ways:
-
M-mode programs it through the
mklcskCSR group (mklcsk CSR Group); M-mode can then read it in clear, and no software can read it in any other way. -
A secure hardware block exclusive to M-mode, such as Caliptra cite:[caliptra], or a port to one, configures it through a dedicated interface based on public-key encryption, at the request of M-mode only, by a handle or a wrapped key; addressing and key transport are platform-specific and outside the scope of this specification.
-
It is hardwired at manufacturing time and cannot be reconfigured or revoked.
-
A secure RBG (Prerequisites) generates it at boot. All harts of a subsystem of an SoC that the platform defines and documents hold the same such CSK, so that processes can migrate among them, and cannot exchange SCCs with other subsystems; the CSK survives the reset or fatal condition of a single hart and is regenerated only at the power-on reset of the subsystem, so the SCCs sealed under it cannot be imported after a power loss.
The third and fourth ways mainly suit specialized embedded deployments. Harts among which processes or CCs migrate must hold the same CSK: under the first and second ways, M-mode establishes it on each. A hart reset or a KLE fatal condition (Error Handling Architecture) resets the hart’s KLE state (KLE Unit Reset and M-mode-only Harts) and, under the first and second ways only, its CSK, which must then be established again.
| When the CSK is shared across devices, CCs meant to be device-bound need to name ChipScrt or DevScrt in their Locality. |
Persistence of a configurable CSK is implementation-specific. Transferring a CSK to another endpoint, such as the M-mode firmware of another device, a local TPM (for instance across suspension or host hibernation), or a cloud-based HSM, requires an authenticated public-key wrapping mechanism, which this specification does not define.
KLE Unprivileged State out of Reset
This section and KLE Privileged State out of Reset are authoritative for the KLE state out of reset:
-
all lockers are in State Unconfigured, with zeroized contents;
-
with
Zklio,kliobuflen= 0 (the KLIOBUF is unconfigured),kliobuftop= 0, and the KLIOBUF is zeroized; -
klstart= 0; -
klnamedlocker= 32; and -
the three authentication registers of The Cryptographic Locker File and Authentication Information are zero.
KLE Unit Reset and M-mode-only Harts
A KLE unit reset of a hart resets that hart’s KLE architectural state (KLE Unprivileged State out of Reset, KLE Privileged State out of Reset) and no other hart’s, and leaves shared Locality Secrets unchanged. A hart reset causes one, and so does a fatal condition (Error Handling Architecture), with the differences of KLE Privileged State out of Reset. It also unconfigures a CSK established under the first or second way (Architectural Requirements on the Context Sealing Key); it neither clears nor regenerates a hardwired or boot-generated CSK.
A non-retentive hart suspend is not a hart reset. Whether it retains the KLE state of the hart (lockers, KLIOBUF, CSRs and authentication registers) is implementation-defined, and retention is strongly recommended; an implementation documents whether and how it retains that state, and software that cannot rely on retention exports its lockers before the suspend (Software Guidelines).
On an M-mode-only hart, every software-programmable Locality Secret whose CSR group is not implemented is unconfigured (Locality Field), and KLS is treated as Initial where the KLE Privileged Architecture is not implemented; Privileged Architecture states which of its CSRs may exist on such a hart.