Unprivileged Architecture: Machines
This chapter is normative.
All values, bit slices, concatenations, and finite-field operations in this chapter follow the conventions of Notation and Conventions. Specifically, the byte at the lowest address occupies the least significant bits, and the @ operator places its left operand in the more significant bits, opposite to ‖, which places its left operand at the lower offsets (Operators and Control Constructs). No Machine may deviate from these conventions.
This chapter specifies KLE instruction behavior for supported Machines. Some Machines are defined generically for primitives meeting certain properties (e.g., GCM works with AES or SM4), while others are tied to specific primitives (e.g., Ascon).
Table 1 gives the encoding of each Machine of this specification in the MDH field Machine, which has two sub-fields: Type in bits [11:4] and Mode in bits [3:0]. For some classes of Machines, Mode specifies a subtype; other groups of Machines may subdivide Machine differently.
| Type | Mode | Machine name | Extension |
|---|---|---|---|
0 |
0 |
|
|
0 |
1 |
|
|
0 |
2 |
|
|
0 |
3 |
|
|
0 |
4 |
|
|
0 |
5 |
|
|
0 |
6 |
|
|
0 |
7 |
|
|
0 |
8 |
|
|
0 |
9 |
|
|
0 |
10 |
|
|
0 |
11 |
|
|
0 |
12 |
|
|
1 |
0 |
|
|
1 |
1—5, 7—8, 10—12 |
Analogous to the corresponding Modes for |
|
2 |
0 |
|
|
2 |
1—12 |
Analogous to Modes 1—12 for |
|
3 |
0 |
|
|
3 |
1—4, 6—8, 10 |
Analogous to the corresponding Modes for |
|
4 |
0 |
|
|
4 |
1 |
|
|
4 |
2 |
|
|
4 |
3 |
|
|
4 |
4 |
|
|
4 |
5 |
|
|
4/5 |
6 |
|
|
4/5 |
7 |
|
|
4/5 |
8 |
|
|
4/5 |
9 |
|
|
4/5 |
10 |
|
|
4/5 |
11 |
|
|
6 |
0 |
|
|
6 |
1 |
|
|
6 |
2 |
|
|
6 |
3 |
|
|
6 |
4 |
|
|
6 |
5 |
|
|
6/7 |
6 |
|
|
6/7 |
7 |
|
|
6/7 |
8 |
|
|
6/7 |
9 |
|
|
6 |
10 |
|
|
6 |
11 |
|
|
6 |
12 |
|
|
6 |
13 |
|
|
7 |
0 |
|
|
7 |
1 |
|
|
8 |
0 |
|
|
8 |
1 |
|
|
8 |
2 |
|
|
8 |
3 |
|
|
8 |
4 |
|
|
8 |
5 |
|
|
9 |
0 |
|
|
9 |
1 |
|
|
9 |
2 |
|
|
10 |
0 |
Elliptic Curve Cryptography: |
|
10 |
1 |
ECC: |
|
10 |
2 |
ECC: |
|
10 |
3 |
ECC: |
|
10 |
4 |
ECC: |
|
10 |
5 |
ECC: |
|
10 |
6 |
ECC: |
|
10 |
7 |
ECC: |
|
10 |
8 |
ECC: |
|
10 |
9 |
ECC: |
|
10 |
10 |
ECC: |
|
11 |
0 |
Post-Quantum Cryptography (PQC): |
|
11 |
1 |
PQC: |
|
11 |
2 |
PQC: |
|
11 |
3 |
PQC: |
|
11 |
4 |
PQC: |
|
11 |
5 |
PQC: |
|
Note on the HMAC variants. In the SHA-2 and SHA-3 HMAC Machines, the lower Type (4 or 6) selects the “No Initial Key” (NIK)
variant and the higher Type (5 or 7) the “Key In PI” (KIP) variant (HMAC); for |
|||
Definition of a Machine in KLE
The following information fully defines a Machine:
- Parameters
-
These include:
-
the block size
b, the bit length of the basic unit the Machine processes, usually the block size of its main underlying primitive; -
the key size
k, in bits, for Machines that hold a key; -
the granularity, usually equal to
b. “Last blocks”, such as those of the AD or of the plaintext or ciphertext, may be shorter thanb. Where the length of such a block is set explicitly, a longer input that carries it is truncated: its excess most significant bits are ignored; and -
any other parameter needed to instantiate the Machine with compatible primitives.
-
- Data Structures
-
These include:
-
Provisioning Input: its fields, in the order in which they appear in the PI, each with its length. Every table ends with a zero Padding to a multiple of 128 bits, of a size
padas defined for the Serialized Content; provisioning ignores the padding bits.Every PI starts with the MDH, at position i. The Provisioning Input tables of the Machines omit it and start at position ii:
Pos. Size (Bits) Field i
128
MDH
-
Internal State: the information kept in the internal state of a CC, needed to define the Machine and its semantics. It must exist internally, but its representation and format are not prescribed. The Internal State always contains the MDH. A key field of the Internal State holds the key itself, even when the PI or the SCC carries a System Key Identifier in its place (System Keys).
-
Serialized Content: the plaintext of the
Content1of the SCC: its fields, in the order in which they appear in an SCC, each with its length. It does not include the MDH, and ends with a zero Padding to a multiple of 128 bits; a sizepadis (−s) mod 128 bits, s being the total size of the Positions before it, with the sizes in effect. In the formulas forpad,kfis the size of the key field:k, or 64 when it holds a System Key Identifier. The Machine may designate public fields, which it places first and an SCC carries in clear; their number of whole 128-bit blocks isSCC_ClearLen1(Rule GR9), zero where the Machine designates none.
-
- Machine-Specific Functions
-
Any other function specific to the Machine.
- State Machine
-
The state machine is defined by:
-
the list of States the Machine may assume, each with its representation as State and StateExtension Fields specifies;
-
the complete list of allowed state transitions, with the prerequisites of each, the native
kl.setstForm and the meaning of any auxiliary parameter to it, and any other condition that triggers a transition without akl.setst; and -
the allowed or expected instructions in each State, and their semantics. Besides configuration and export sequences, a State typically permits only certain Forms of
kl.execandkl.setst, and may be an endpoint ofkl.derive(Derivation Endpoints of the Machines). WithZklio, a substitution may replace any native Form ofkl.exec, however the Machine words it (Zklio, Rule GR10): a Form Dkl.execreplaces a Form A, B or Ckl.exec. Akl.setstinto a State for which the Machine names no Form is of Form A. Where a State expects a Form B or Dkl.setst, a Form A one is admitted too, with a zero operand; where it expects Form C with anINPUTof at most 128 bits, a Form A or D one is admitted (Rule MR5), and a Form B one where the State says so. A substitution issued without the required KLIOBUF setup fails as Rules GR11 and GR10.2 state. A Form that is neither a native Form of the State nor, withZklio, its substitution is a wrong Form (Rule GR19.1).kl.inputandkl.outputaccess no locker, so the state machine does not restrict them. Rule GR13.5 states the behavior precisely.
-
The non-normative code examples in Appendix: Writing Software for KLE illustrate how software uses the Machines through the KLE ISA; the examples use the vector Forms of the instructions.
Notation in the Machine Descriptions
The following nomenclature is specific to the Machine specifications:
-
INPUTis the input data ofkl.execorkl.setst: the input vector register, the 128-bit GPR operand of a Form Dkl.setst, theXsof a Form Bkl.setstthat a State admits in place of Form C, zero-extended to 128 bits, or the KLIOBUF (Zklio). -
OUTPUTis the output data ofkl.exec: the output vector register, or the KLIOBUF (Zklio). -
Xsis the auxiliary operand of a Form Bkl.setst: a 64-bit value, in one GPR on RV64 and in the pairX[s+1] @ X[s]on RV32 (Rule GR2). A Form Akl.setstis a Form B one withXs= 0. -
KLLENis the operand length in bits:vl×SEWfor a vector operand, andkliobuftop× 8 for a KLIOBUF operand, and 128 for the GPR operand of a Form Dkl.setst, or for the zero-extendedXsof a Form B one.kliobuftop, like every other KLIOBUF CSR andklstart, is a number of bytes. For a KLIOBUF operand,kliobuftopplays the role ofVL, and the transfer window is bytes [0,kliobuftop-1] (kliobuftop). For either operand ofkl.exec,klstartplays the role ofvstart: it is the byte position within the transfer window at which processing starts or resumes (klstart).kl.setstdoes not honorklstart: it reads its whole operand. -
enc_blk(K, p) → canddec_blk(K, c) → p: the encryption of blockp, resp. the decryption of blockc, under keyKby the block cipher of the Machine. -
trunc(V, n), for 0 ≤n≤band a valueVof at leastnbits: theb-bit valuezeros(b-n) @ V[n-1:0], which keeps thenleast significant bits ofVand ignores the others;trunc(V, b)=Vfor ab-bitV. -
pad10(X, n): forna multiple of 8 with 0 ≤n<b, theb-bit value holding then-bit partial blockX[n-1:0]followed, in string order, by a single1bit and then zeros,zeros(b-8-n) @ 0b10000000 @ X[n-1:0]. The terminating1is the most significant bit of byten/8, not bitnof the value: within a byte, the first bit of the string is the most significant (Notation and Conventions). It is the padding of cite:[RFC7253] §4.2 and cite:[nist-SP-800-38B] §6.2.
General Rules for Machines
Besides the General Rules (GR) of Unprivileged Architecture: Instructions and Architectural States, in particular those governing the State field and its transitions (Rules Governing the State and StateExtension Fields and their Transitions), the following Machine Rules (MR) apply to all Machines, unless stated otherwise.
Machine Definition and Checks
| MR1 |
Policy gate and entry conditions. Each Machine states, for each of its States:
Unless the Machine states otherwise, a zero MachinePolicy is invalid Metadata (Validity of Metadata) for a Machine that encrypts and decrypts, or that generates and verifies MACs, and valid for one that generates and verifies signatures: it then disables these operations and leaves the others, if any, available. GCM with Preset IV, OCB with Preset Nonce and Ascon-AEAD128 with Preset Nonce, which carry their IV or nonce in the PI, admit only MachinePolicy = A
|
| MR2 |
Configuration errors and data errors. Each Machine states which of its checks detect a configuration error, and which a data error:
|
| MR3 |
Checks of a field.
A check that the Machine attaches to a field and that depends on that field alone is made whenever the field is written: at the completion of its load (Rule MR14), of a A check that depends on the operation or on more than one field is made by the operation that reads the field, before it changes any state.
Examples are the validity of a point in the role that the operation gives it, the range of |
| MR4 |
System-specific import. A system-specific import never circumvents the referenced standard of the Machine (Rule GR49). The converted Content undergoes the checks of Rule MR3, and a field that the Machine derives from another is derived from the converted Content, or checked against it, never taken from the format unchecked. A Machine whose Provisioning Input does not carry a field that a format may configure states how the import checks and marks that field, as ML-KEM and ML-DSA do. |
Operands, Outputs and Fields
| MR5 |
Form of a |
||
| MR6 |
If |
||
| MR7 |
A field that a Machine can derive inexpensively from other fields of the same CC may be omitted from the Serialized Content.
It is then recomputed when an import completes, by the |
||
| MR8 |
Where a State consumes from |
||
| MR9 |
A State writes |
||
| MR10 |
Final fractional block.
A Machine whose input ends in a fractional block processes it in a State of its own, such as Enc_Last_Block, Dec_Last_Block or Hash_Absorb_Last_Block, the final-block State, as follows, unless the Machine defines otherwise; a
A Machine may require a native Form D
|
||
| MR11 |
A
A value that the Machine does not admit transitions the locker to Error State Invalid. Whether zero is admissible depends on the Machine. |
||
| MR12 |
Verification of a tag. A Machine that verifies a tag or a MAC without disclosing the value it computes does so in constant time, and transitions to Success if the verification succeeds and to Failure otherwise (Rule MR2). The instruction that provides the tag or MAC to verify performs the verification. It is:
CMAC Functions, GCM Mode, GCM with Preset IV, HMAC, Ascon-AEAD128, Ascon-AEAD128 with Preset Nonce and Ascon-AEAD128 with Nonce Masking compare a prefix of the tag or MAC.
Every verification of a locker of these Machines compares the same number of bits,
|
Multi-block Operations
| MR13 |
Single- and Multi-block A State that the Machine describes as processing a single block, such as a last-block, tag-finalize or verify State, or XEX Decrypt during ciphertext stealing (XEX/XTS Modes), processes exactly one block whatever |
| MR14 |
Long fields transferred by several
|
| MR15 |
A Machine enforces only the per-message limits that its correctness needs at practical lengths and that it can track from its own state, such as the 32-bit counters of GCM Mode and GCM-SIV Mode and the bound on the
|
Operations and Transitions
| MR16 |
A Machine may declare a |
| MR17 |
The operations that a Machine performs on entering or leaving a State, or on a change of State, apply only to the transitions between its Valid States that usage instructions make.
A |
| MR18 |
Transitions that a Machine makes.
A Machine may make a transition by itself: on completing a |
Randomness
| MR19 |
A Machine operation that needs random bits from an RBG or DRBG, such as the generation of a nonce, an ephemeral scalar or a signature into the locker, is an instruction of its own. That instruction works only on the locker and on scalar operands captured at issue, transfers no data to or from memory, vector registers, the KLIOBUF or another locker, and may be long-running (Long-Running Operation). If the RBG or DRBG cannot supply the bits, Rule GR45 applies. An instruction that transfers data never waits or fails for lack of random bits, even when resumed, restored or restarted; further randomness that its Machine needs comes from another instruction. Randomness that the implementation needs, such as masks, is supplied in advance, without weakening the required protection. An internal algorithmic random value, such as a signing nonce or an ephemeral scalar, serves only the one instance of the scheme that requires it, and no other instance or purpose. It is never reused, not even when an interrupted operation restarts (Rule GR38). Resuming copies of one interrupted operation, restored from one image, completes that one instance on the same inputs and is not a reuse. |
Input and Output Padding, Truncation, Byte Granularity
Unless the Machine specifies otherwise and pads internally, the caller must pad an input whose length the granularity of the State does not admit to a KLLEN that the Machine admits, and pass its actual length to the Machine, typically through kl.setst.
Cryptographic inputs are normally supplied through vector registers or the KLIOBUF, in whole bytes. For a standard that permits arbitrary bit lengths, the caller specifies the bit length of the final input piece, usually as a kl.setst parameter, and the Machine truncates that input to it. The Machine clears the output bits beyond the final piece, also within its last byte (Rule MR9).
This occurs, for instance, with the last_block_len parameters in GCM Mode, GCM-SIV Mode, OCB Mode, Ascon-AEAD128, and Hash and MAC Functions, and XOFs. Such a parameter gives the length to which the Machine truncates the passed input, not the length KLLEN of that input. Macro PROCESS_VLI receives field lengths in bits, but kl.exec always transfers whole bytes, and the last input may be truncated internally.
Where a standard’s formula requires the bit count of data that the Machine receives in whole bytes, it is the byte count multiplied by 8, as with the length block of GHASH in GCM Mode.
Symmetric Cryptography
This table, with Global CC State Numbers: Inert State, Global CC State Numbers: Valid States and Global StateExtension Codes at State 0: Unconfigured and Error States, defines the States of the symmetric Machines. A Machine may override these values and says so where it does; the public-key Machines define their own mnemonics.
| Value | Mnemonic for the Constant | State Name | Description |
|---|---|---|---|
2 |
|
Operate |
Generic operational state. |
|
Hash_Absorb |
(Same value as Operate, with a mnemonic more intuitive for hash functions.) Absorb data: the message of a hash function, MAC or XOF, or the associated data of an AEAD scheme; on the encryption path of GCM-SIV Mode, also the plaintext. On entering the State, the Machine may initialize its tag or MAC computation. |
|
3 |
|
Hash_Absorb_Last_Block |
Absorb a final input piece whose length the |
4 |
|
Hash_Finalize |
Finalize the internal state of a hash/tag function. |
5 |
|
Hash_Verify |
Compare the internal hash/tag value to the provided one. |
6 |
|
Hash_Output |
Enter the hash output phase of a hash/tag function. |
7 |
|
Encrypt |
Perform encryption, and any associated tag computation. |
8 |
|
Decrypt |
Perform decryption, and any associated tag computation. |
9 |
|
Enc_Last_Block |
Process the last block separately, on the encryption path of an authenticated encryption mode. |
10 |
|
Dec_Last_Block |
Process the last block separately, on the decryption path of an authenticated encryption mode. |
11 |
|
Enc_Tag_Finalize |
Finalize the tag computation for AE mode encryption. |
12 |
|
Dec_Tag_Finalize |
Finalize the internal tag computation for AE mode decryption; where the expected tag was supplied first, as in GCM-SIV Mode, also verify it (Rule MR12). |
13 |
|
Set_Aux_Value |
Set a public/auxiliary value in a cryptographic scheme implemented by the Machine. |
14 |
|
Set_Aux_Value_2 |
Set a second public/auxiliary value in a cryptographic scheme implemented by the Machine. |
15 |
|
Set_Key |
Reconfigure a key field. |
16 |
|
Hash_Output_Bits |
Output the hash a set number of bits at a time. |
Rule MR16 applies to the Machines that use Table 2 and to every Machine-defined immediate; Rules MR17 to MR18 apply to every Machine.
Electronic Codebook Mode
ECB mode cite:[nist-SP-800-38A-1] is the simplest way to use a block cipher.
- Parameters
-
-
b= bit length of a block (ba multiple of 8), withb≥ 64. -
k= bit length of a key (ka multiple of 8). -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
padPadding: (−
kf) mod 128.
-
- Machine-Specific Functions
-
enc_blkanddec_blk(Notation in the Machine Descriptions). - State Machine
-
-
States:
-
Ready: The CC is ready.
-
Encrypt: Encrypting blocks of input.
-
Decrypt: Decrypting blocks of input.
-
-
Allowed State Transitions:
-
Behavior:
-
The Machine allows a same-State
kl.setstinto Encrypt or Decrypt (Rule GR19.2), which changes nothing. -
In Encrypt and Decrypt, (multi-block) Form A
kl.execinstructions are expected. For each block,OUTPUT ← enc_blk(key, INPUT)in Encrypt, andOUTPUT ← dec_blk(key, INPUT)in Decrypt.
-
-
Code examples (one or eight blocks per kl.exec): Simple Example: Encryption with no Authentication, ECB Encryption, Eight Blocks per Instruction.
Chaining/Feedback Modes (CBC, CFB, and OFB)
Cipher Block Chaining (CBC), Cipher Feedback (CFB) and Output Feedback (OFB) cite:[nist-SP-800-38A-1] are defined here for a block cipher of block size b.
CFB has a segment of u bits.
CBC takes no padding or ciphertext stealing: the caller supplies whole blocks.
CBC and CFB process data; OFB, like CTR (CTR/XCTR Keystream Generation), generates a keystream.
- Parameters
-
-
b= block size (ba multiple of 8), with 64 ≤b≤ 128. -
k= key size (ka multiple of 8). -
u= segment size in bits (CFB only), with 0 <u≤b, a parameter of the CC held in AuxInfo (see the Behavior below). -
Granularity:
bbits in CBC and OFB; 8 bits in CFB, where aKLLENbelowuviolates it (Rule MR6).
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
IV:bbits, the chaining value: the initialization vector at first; then the last ciphertext block in CBC, thebrev8of the shift register of cite:[nist-SP-800-38A-1] in CFB (the last bits of the initialization vector followed by the ciphertext segments), and the last keystream block in OFB. -
u: 8 bits (CFB only), held in AuxInfo[7:0] of the MDH, not serialized.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
bIViii
padPadding: (−(
kf+b)) mod 128.
-
- Machine-Specific Functions
-
enc_blkanddec_blk(Notation in the Machine Descriptions). - State Machine
-
-
States:
-
Ready: The CC is ready.
-
Encrypt and Decrypt (CBC and CFB): Encrypting, resp. decrypting, blocks (CBC) or segments (CFB) of input.
-
Operate (OFB): The CC produces a keystream.
-
-
Allowed State Transitions:
-
Behavior:
-
When entering Ready,
IV← 0. -
In CFB, the segment size is fixed at provisioning:
u= AuxInfo[7:0] (MachineUse and AuxInfo Fields), and AuxInfo[15:8] is zero. A provisioning or import whose AuxInfo violates this, or hasuoutside 0 <u≤b, completes into Error State Invalid (Rule MR3). Provisioning keeps the AuxInfo of the PI, and no operation changes it: CFB defines all its bits, so entering Ready,kl.clearadsand an import without ADS leave it unchanged. Withu=bthe Machine is the full-block CFB. -
When entering Encrypt, Decrypt or Operate,
LOAD_FIXED_FIELD(IV, b)(LOAD_FIXED_FIELD(field, w)) loads the initialization vector. The Machine allows a same-Statekl.setstinto these States (Rule GR19.2), which replacesIVand keepskey. -
In Encrypt and Decrypt, (multi-block) Form A
kl.execinstructions are expected. In CBC, for each block, withINPUTthe block of input:Mode Operation Semantics CBC
Encrypt
OUTPUT ← enc_blk(key, INPUT xor IV),IV ← OUTPUTDecrypt
OUTPUT ← dec_blk(key, INPUT) xor IV,IV ← INPUTIn CFB,
INPUTis processed inn= ⌊`KLLEN`/u⌋ segments ofubits; the other bits are ignored, and software shifts them into the nextkl.exec. The standard cite:[nist-SP-800-38A-1] numbers bits from the most significant bit of a byte. For eachjfrom 0 ton-1, in increasing order, withCjthe ciphertext segment,Yjin Encrypt andXjin Decrypt:-
W ← brev8(IV); -
Q ← brev8(enc_blk(key, IV))[u-1:0]; -
Xj ← brev8(INPUT)[(j+1)u-1:ju]; -
Yj ← Xj xor Q; -
IV ← brev8(Cj @ W[b-1:u]), withW[b-1:u]empty ifu=b; and -
OUTPUT=brev8(Y), whereYhasYjin bits[(j+1)u-1:ju]and 0 above bitnu-1.
The iterations of Rule MR13 are over the segments; the interruption points (Rule GR33.2) are the multiples of
lcm(8, u)/8bytes. Forua multiple of 8 thebrev8cancel: for each segment,Q=enc_blk(key, IV)[u-1:0]with the currentIV, andIV←Cj @ IV[b-1:u], withCjthe bytes of the segment inOUTPUTorINPUT.For each block or segment,
INPUTis read beforeOUTPUTis written, soOUTPUTmay be computed in place. -
-
In Operate (OFB), (multi-block) Form C
kl.execinstructions are expected. For each block,IV ← enc_blk(key, IV)andOUTPUT ← IV. As akl.derivesource (Derivation Endpoints of the Machines), Operate supplies the keystream of whole-block Form Ckl.execinstructions, discarding the unused bytes of the last block.
-
-
The decryption of CFB uses enc_blk only. With u = b it is the full-block CFB; u = 8 and u = 1 are CFB8 and CFB1 of cite:[nist-SP-800-38A-1].
The caller ensures the uniqueness and unpredictability of the IV that the standard requires (Rule MR15); a Form A kl.setst sets it to zero.
|
Code examples (CBC, CFB): CBC Encryption, CBC Encryption, Eight Blocks per Instruction, CFB8 Encryption.
CTR/XCTR Keystream Generation
In CTR mode, the IV and the counter are concatenated to form the input block of the underlying keyed PRP or PRF, so their lengths sum to its block size.
In XCTR mode, the IV has the block size; the counter is zero-extended to the block size, and its XOR with the IV forms the input block.
- Parameters
-
-
b= block size (ba multiple of 8), withb≥ 64. -
k= key size (ka multiple of 8). -
j= counter size: 32 in CTR mode, 64 in XCTR mode. -
n= IV size (na multiple of 8). -
In CTR mode,
b = n + j; in XCTR mode,b = n. -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
IV:nbits. -
ctr:jbits.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
nIViii
jctriv
padPadding: (−(
kf+n+j)) mod 128.
-
- Machine-Specific Functions
-
-
keystream_block(p) → c:enc_blk(key, p)(Notation in the Machine Descriptions), the encryption of the counter blockpunderkey. -
tick_ctr(): increasesctrby one, modulo 2j.
-
- State Machine
-
-
States:
-
Ready: The CC is ready.
-
Operate: The CC produces a keystream.
-
-
Allowed State Transitions:
-
Behavior:
-
When entering Ready,
IV← 0, andctr← 0 in CTR mode and 1 in XCTR mode (as in the XCTR of HCTR2 cite:[cryptoeprint-2021-1441]). -
When entering Operate, the
kl.setstwith immediatekl_state_operateinvokesLOAD_FIXED_FIELD(IV, n, B)(LOAD_FIXED_FIELD(field, w)), which loadsIVand leavesctrunchanged. The Machine allows a same-Statekl.setstinto Operate (Rule GR19.2), which does the same. -
In State Operate, (multi-block) Form C
kl.execinstructions are expected. For each block, they perform:-
In CTR mode,
tmp ← keystream_block(bswap(ctr) @ IV); in XCTR mode,tmp ← keystream_block(IV xor (zeros(b - j) @ ctr)). -
tick_ctr(). -
OUTPUT ← tmp.
As a
kl.derivesource (Derivation Endpoints of the Machines), Operate supplies the keystream of whole-block Form Ckl.execinstructions, discarding the unused bytes of the last block. -
-
In States Ready and Operate, the Form B
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandXssets the counter:ctr←bin(Xs, j). It is an operation, not a State (Rule MR16).
-
-
Setting the counter gives random access into a keystream, for example to resume an interrupted stream.
ctr wraps modulo 2j and never carries into IV, so one IV yields at most 2j distinct counter blocks (in CTR mode, the incrementing function of cite:[nist-SP-800-38A-1] Appendix B.1 with m = j).
No check detects the wrap (Rule MR15), since the Machine does not know where a message starts.
In CTR mode, software that follows a protocol incrementing the whole counter block splits the kl.exec at the wrap, then sets the incremented IV and ctr = 0.
|
Code examples (b = 128): Encrypt with Keystream Generation.
XEX/XTS Modes
XEX cite:[DBLP-conf-asiacrypt-Rogaway04] turns a block cipher into a Tweakable Block Cipher (TBC) cite:[DBLP-conf-crypto-LiskovRW02], whose key and tweak together select the permutation that the cipher computes.
Its two-key form builds a TBC Ẽ from a block cipher E, with keys K1 and K2, tweak T, and plaintext P:
Ẽ(K1, K2, T, P) = E(K1, P xor M) xor M where M = E(K2, T) is called a mask.
The single-key XEX of cite:[DBLP-conf-asiacrypt-Rogaway04], whose mask is x · E(K, T), is not architected.
The Machine computes the mask once per tweak, by the kl.setst that sets the tweak; each block uses the current mask and then updates it by a multiplication in GF(2b).
key1 is K1, which encrypts the data, and key2 is K2, which encrypts the tweak.
XTS cite:[DBLP-journals-ieeesp-Martin10], designed for storage confidentiality and a NIST Recommendation since 2010, adds two things to XEX: the tweak identifies the data unit, and a data unit whose length is not a multiple of b is completed by ciphertext stealing.
Software obtains both from the XEX CC (XTS ciphertext stealing).
The variants differ:
-
AES128_XEXandAES256_XEXfollow cite:[nist-SP-800-38E] and cite:[IEEE-1619-2018]:-
update_masktakesV[i]as the coefficient ofxi; -
the tweak, the
INPUTof thekl.setstinto Encrypt or Decrypt, isbin(i, b)(Notation and Conventions), the data unit sequence numberias ab-bit little-endian value; -
a data unit has at most 220 blocks (Rule MR15).
-
-
SM4_XEXfollows cite:[GBT-17964-2021]:-
update_masktakes the bits of each byte in the reverse order; -
the tweak is the 128-bit tweak of cite:[GBT-17964-2021], its first byte in byte 0.
-
The Machine cannot check that the two keys are independent: the provisioner must supply two independently generated keys,
a System Key Identifier must resolve to two independently generated keys in the SKS, and software that derives key1 ‖ key2
(Derivation Endpoints of the Machines) must take it from a source whose two halves are independent, such as a keystream.
- Parameters
-
-
b= 128 = block size. -
k= key size (ka multiple of 8). -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64key1or System Key Identifieriii
kor 0key2, or empty if KeyType = 1 (a single SKID retrieves both keys, Rule GR55.1)iv
padPadding: (−2
k) mod 128, or 64 with a System Key Identifier. -
Internal State:
-
key1:kbits. -
key2:kbits.key2=key1is a configuration error (Rule MR2). It is checked whenever the keys are written: by a provisioning, by an import, and by akl.deriveintokey1 ‖ key2. A provisioning checks them whether the PI gives them by value or by a System Key Identifier, or the provisioning generates them (KeyType = 2). -
mask:bbits. -
StealSkipandStealBack: bits 0 and 1 of StateExtension respectively, which record the two steps of ciphertext stealing in Decrypt (XTS ciphertext stealing). At most one of them is set, and only in Decrypt; the Machine supports no other StateExtension @ State.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64key1or System Key Identifierii
kor 0key2, or empty if KeyType = 1 (a single SKID retrieves both keys, Rule GR55.1)iii
bmaskiv
padPadding: (−2
k) mod 128, or 64 with a System Key Identifier.
-
- Machine-Specific Functions
-
-
update_mask(mask)multipliesmaskby a generator of GF(2128): it is the multiplication byxmodulox128 + x7 + x2 + x + 1. ForAES128_XEXandAES256_XEX(cite:[IEEE-1619-2018] §5.2),update_mask(V)=V << 1ifV[127]=0and
update_mask(V)=(V << 1) xor (zeros(120) @ 0b10000111)otherwise.For
SM4_XEX, withBj=V[8j+7:8j], bytejofV,update_mask(V)=B'15 @…@ B'0, whereB'j=Bj-1[0] @ Bj[7:1]for0 < j < 16,B'0=B0 >> 1ifB15[0]=0,andB'0=(B0 >> 1) xor 0xE1otherwise. -
mask ← update_mask_inv(mask)whereupdate_mask_invinvertsupdate_mask, dividing byx.
ForAES128_XEXandAES256_XEX,update_mask_inv(V)=V >> 1ifV[0]=0and
update_mask_inv(V)=((V xor (zeros(120) @ 0b10000111)) >> 1)
xor (0b1 @ zeros(127))otherwise.For
SM4_XEX, withBjbytejofVas above,c=B0[7], andA=B0ifc=0andA=B0 xor 0xE1otherwise,update_mask_inv(V)=B'15 @…@ B'0, whereB'j=Bj[6:0] @ Bj+1[7]for0 < j < 15,B'0=A[6:0] @ B1[7]andB'15=B15[6:0] @ c.
-
- State Machine
-
-
States: Ready, Encrypt, and Decrypt (defined as before, cf. Electronic Codebook Mode), and Success.
-
Allowed State Transitions:
-
Behavior:
-
Every transition, same-State
kl.setstincluded, clearsStealSkipandStealBack. -
When entering Ready,
mask← 0. -
When entering Encrypt or Decrypt,
LOAD_FIXED_FIELD(mask, b, B)(LOAD_FIXED_FIELD(field, w)) loads the tweak intomask, and thenmask ← enc_blk(key2, mask)computes the initial mask. The Machine allows a same-Statekl.setstinto Encrypt or Decrypt (Rule GR19.2), which does the same: it takes a new tweak and performs both steps. -
In States Encrypt and Decrypt, with
StealSkipandStealBackclear, (multi-block) Form Akl.execinstructions are expected. For each block, they read theINPUTand determine theOUTPUT:-
In State Encrypt,
OUTPUT ← mask xor enc_blk(key1, INPUT xor mask); in State Decrypt,OUTPUT ← mask xor dec_blk(key1, INPUT xor mask). -
mask ← update_mask(mask).
-
-
In State Decrypt, the Form A
kl.setstwith immediatekl_xex_state_steal(66) starts ciphertext stealing. It is an operation (Rule MR16). IfStealSkiporStealBackis set, it transitions the locker to Error State Invalid; otherwise it:-
mask ← update_mask(mask); -
sets
StealSkip.
-
-
In State Decrypt with
StealSkipset, a Form Akl.execprocesses a single block (Rule MR13):-
OUTPUT ← mask xor dec_blk(key1, INPUT xor mask); -
mask ← update_mask_inv(mask); -
it clears
StealSkipand setsStealBack.
-
-
In State Decrypt with
StealBackset, a Form Akl.execprocesses a single block (Rule MR13):-
OUTPUT ← mask xor dec_blk(key1, INPUT xor mask); -
the locker transitions to Success.
-
-
-
Code examples, with ciphertext stealing: XEX Encryption, XEX Decryption.
Ciphertext stealing. A data unit of whole blocks is processed, in both directions, by the plain XEX sequence over its blocks.
Otherwise, let it be m ≥ 1 full blocks P0 … Pm-1 followed by a partial block Pm of s bits,
with 0 < s < b and s a multiple of 8.
The locker is at mask index j when its mask is update_mask applied j times to enc_blk(key2, T), where T is the tweak.
Blocks are processed in order (Rule MR13), so the j-th block after the tweak is set, counting from 0, uses mask index j.
CP @ Pm and CP @ Cm place the partial block in the least significant bits, where the first s/8 bytes of a string are (Notation and Conventions).
Encryption consumes the mask indices in order:
-
Issue
kl.execforP0…Pm-2, obtainingC0…Cm-2(no instruction ifm= 1). -
Issue
kl.execforPm-1, obtainingCCat mask indexm-1;Cm←CC[s-1:0]andCP←CC[b-1:s]. -
Issue
kl.execforCP @ Pm, obtainingCm-1at mask indexm. -
The ciphertext is
C0…Cm-1,Cm, withCmthe finalsbits.
Decryption consumes mask index m before mask index m-1; the stealing steps of the Machine reorder the two:
-
Issue
kl.execforC0…Cm-2, obtainingP0…Pm-2(no instruction ifm= 1); themaskis at indexm-1. -
Issue the Form A
kl.setstwith immediatekl_xex_state_steal, which skips mask indexm-1. -
Issue
kl.execforCm-1, obtainingPPat mask indexm; themaskreturns to indexm-1. -
Pm←PP[s-1:0]andCP←PP[b-1:s]. -
Issue
kl.execforCP @ Cm, obtainingPm-1at mask indexm-1; the locker transitions to Success.
Decryption with stealing adds the kl.setst with immediate kl_xex_state_steal to the data unit.
The data unit ends in Success, so a kl.setst into Ready precedes the kl.setst that sets the next tweak.
Generic Tweakable Block Ciphers
The specification of a generic tweakable block cipher resembles that of a block cipher in ECB mode.
Since kl.exec takes a single input, a separate instruction sets the tweak.
A tweak longer than the block may need the vector length reconfigured between setting the tweak and processing blocks.
Some commonly used TBCs are Deoxys-BC cite:[Deoxys-141], SKINNY cite:[DBLP-conf-crypto-BeierleJKL0PSSS16], QARMA cite:[DBLP-journals-tosc-Avanzi17], and QARMAv2 cite:[DBLP-journals-tosc-AvanziBDEGNR23].
- Parameters
-
-
b= block size (ba multiple of 8), withb≥ 64. -
k= key size (ka multiple of 8). -
t= tweak size (ta multiple of 8). -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
tweak:tbits.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
ttweakiii
padPadding: (−(
kf+t)) mod 128.
-
- State Machine
-
-
States: Ready, Encrypt, and Decrypt (cf. Electronic Codebook Mode). Setting the tweak is an operation, not a State (Rule MR16).
-
Allowed State Transitions:
-
Behavior:
-
When entering Ready, the
tweakfield is cleared. -
The Machine allows a same-State
kl.setstinto Encrypt or Decrypt (Rule GR19.2), which leavestweakunchanged. -
In States Ready, Encrypt and Decrypt, the Form C
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandINPUTis the set-tweak operation: it invokesLOAD_FIXED_FIELD(tweak, t, B)(LOAD_FIXED_FIELD(field, w)), which loadstweak. -
In Encrypt and Decrypt, (multi-block) Form A
kl.execinstructions are expected. For each block, they encrypt, resp. decrypt,INPUTintoOUTPUTunderkeyandtweak. Every block uses the currenttweak; the Machine never updates it by itself.
-
-
Macro: Processing Variable Length Inputs into a Fixed Length Output
Many Machines process variable-length inputs into fixed-length outputs, for instance to hash, or to derive an internal fixed-length IV from a variable-length external one. They do so in specific States, such as Hash_Absorb.
This section describes the semantics of such a State, called Current_State here.
PROCESS_VLI is a macro, not a subroutine: an invocation splices the behavior below into the State Machine of the
calling Machine, with each parameter replaced by the variable or function that it names, and with any change to its steps
that the invoking Machine states, such as the final piece of SHA-2 Family Specific Rules and the postponed step 3.g of BLAKE2 Specific Rules.
The macro defines how the kl.exec instructions of Current_State and last_block_state consume their INPUT.
A kl.setst passes the macro no data. A kl.exec that a State of the macro admits, with an empty transfer window (Rule GR18), does not reach the macro; the macro behaves as if the caller had made extra kl.exec calls that transfer nothing: it changes none of the variables, and the State is kept. The kl.setst that enters Current_State may set max_len (Form B), and the one that enters last_block_state may set last_block_len. Any other operand of a kl.setst is defined by the invoking Machine.
A Machine invokes it as:
PROCESS_VLI(max_len,
block, b, state, n,
input_base, block_base, state_offset, cumul_len,
process_block(), finalize(), mode, granularity,
last_block_state, process_last_block(), last_block_len)
where each parameter is a reference to a variable or function of the calling Machine, or None where the calling Machine does not define it:
-
max_lenis the total length of the data to be absorbed, in bits. If neither software nor the Machine sets it (see State Machine Behavior below),max_lenis zero. -
blockcontains the current block being filled internally before processing. Its size isbbits. -
stateis the output buffer. It may be the same asblock. Its size isnbits. -
input_baseis the offset, within theINPUTof thekl.exec, of the next data to absorb. -
block_baseis the offset, within the current block, of the next data to absorb: withinblockifmodeisassign, and withinstatefromstate_offsetifmodeisxor_accumulate(steps 3.b and 3.c). Each time it reachesb, the block is processed (step 3.g). -
state_offsetis the offset withinstateat which the input is XORed, for instance in sponge constructions. -
cumul_lenis the cumulative length of the data absorbed so far by the macro, orNoneif not tracked. -
modeis eitherassignorxor_accumulate, and selects how incoming data is combined with the destination, as specified in steps 3.b and 3.c below. It is not inferred from whetherblockandstatedenote the same variable. -
last_block_stateis the State in which a final piece of the input is absorbed, orNone. -
last_block_lenis the variable of the calling Machine that contains the bit length of the final piece still to be absorbed, orNoneiflast_block_stateisNone.
|
When When
|
The macro does not initialize the persistent state variables block_base and cumul_len.
The invoking Machine zeroes them where needed.
A Machine that enters a State with mode = assign, and whose destination field must hold a
defined value once loading completes, must zero that field on entry to the State.
The macro leaves block_base and cumul_len alone so that several invocations of it can concatenate their results.
|
Units. max_len, b, n, input_base, block_base, state_offset, cumul_len, last_block_len, and amount are
all counted in bits, to support values of max_len that are not multiples of 8 bits.
However, the macro only supports values of b and n that are multiples of 8 bits,
and all kl.exec instructions transfer whole bytes and never a fraction of a byte.
As a consequence, input_base and block_base are multiples of 8, with two exceptions: after the final transfer of an
input whose max_len is not a multiple of 8, which ends the instruction (step 3.h), and after a final piece absorbed in
last_block_state.
Finally, three parameters are functions of the calling Machine:
-
process_block()=process_block(block, state)processes the current block intostate. It may be given asNone, in which case no such call is made, and the macro usesstateonly in step 3.c. -
finalize()finalizes the processing of the input data, completing the current block where the Machine’s rules require it. It may also be given asNone, in which case no such call is made. -
process_last_block()=process_last_block(block, state)processes the block that holds the final bit of a piece absorbed inlast_block_state, in place ofprocess_block(). It may be given asNone, in which case that block is processed as any other.
The last three parameters may be omitted, and are passed as None:
the steps for last_block_state below do not apply.
Passing None for both process_block() and finalize() reduces the macro to its accounting of partial progress across
kl.exec instructions; a Machine needs this when it only has to fill a long
field from memory and has no per-block processing to perform.
A Machine whose final piece needs a State of its own passes last_block_state.
It also passes process_last_block() if the block that holds the final bit needs processing of its own.
The optional parameter granularity specifies the transfer unit for inputs.
-
Where
max_len= 0,granularityconstrains noKLLEN: everyKLLENthat is a multiple of 8 is absorbed, andgranularityonly restricts the interruption points (step 3.i). -
Where
max_len!= 0, a transfer violates the granularity of the State (Rule MR6) if itsKLLENis not a whole multiple ofgranularityandcumul_len+KLLEN<max_len. In this test,cumul_lenis its value when the instruction is issued, whether the instruction starts or resumes. -
Every other
KLLENmeets the granularity of the State, somax_lenneed not be a multiple ofgranularity. -
Where
last_block_stateisNone, the data beyondmax_lenis ignored (step 3.h, Input and Output Padding, Truncation, Byte Granularity); otherwise step 1 requires each transfer to end beforemax_len. For example, withgranularity= 128, a 96-bit IV is supplied in a single transfer, either as a 96-bit vector or as a 128-bit vector with excess bits truncated. -
Since
KLLENcounts the bytes that a non-zeroklstartskips, a resumed transfer with aKLLENthat is not a whole multiple ofgranularityis also admitted and ends beforemax_lenwith a partial block.
- Internal State Variables
-
Besides the variables that the parameters name, the Machine may define variables for
process_block(),process_last_block()andfinalize().max_lenkeeps its value for the duration of the computation. - State Machine Behavior
-
-
When entering State Current_State:
-
If software sets
max_len, it passes it to a Form Bkl.setst, which setsmax_lento its auxiliary operandXs. -
Otherwise,
max_lenis set by the Machine, and thekl.setstthat enters the State is of Form A, or of Form B where the invoking Machine defines itsXs; such akl.setstdoes not setmax_len.
-
-
While in State Current_State, only
kl.execinstructions of Form B are expected, each of which processes itsINPUT.-
If
max_len!= 0, the locker transitions to Error State Invalid if either:-
cumul_len≥max_len; or -
last_block_stateis notNoneandcumul_len+KLLEN− 8 ×klstart≥max_len.
-
-
input_base ← 8×klstart: 0 when the instruction starts, the point of progress when it resumes. Nothing else distinguishes a start from a resumption. -
while (
input_base<KLLEN) do:-
If
max_len!= 0 thenamount ← min(KLLEN - input_base, b - block_base, max_len - cumul_len), elseamount ← min(KLLEN - input_base, b - block_base).amountis always strictly positive, so the loop terminates. -
if
mode=assignthen:-
block[block_base + amount - 1 : block_base] ← INPUT[input_base + amount - 1 : input_base].
-
-
else, that is if
mode=xor_accumulate:-
XOR
INPUT[input_base + amount - 1 : input_base]tostate[block_base + amount + state_offset - 1 : block_base + state_offset].
-
-
input_base ← input_base + amount. -
block_base ← block_base + amount. -
If
cumul_lenis notNone, thencumul_len ← cumul_len + amount. -
If (
block_base=b) then:-
process_block(block, state), ifprocess_block()is notNone. -
block_base ← 0.
-
-
If
max_len!= 0 andcumul_len = max_lenthen:-
finalize(), iffinalize()is notNone. -
The instruction is terminated, even if
input_base < KLLEN.
-
-
Here, and only here, the instruction may be interrupted while
input_base < KLLEN, if the invocation gives nogranularityorinput_baseis a whole multiple of it, withklstart ← input_base / 8.
-
Architected state alone determines the interruption points of
kl.execin Current_State (Rule GR33.2). They are the byte offsetskfor which 8 ×kis a multiple ofgranularity, or every byte offset if the invocation gives nogranularity. An instruction issued while the locker holdsblock_base≠ 0 admits onlyklstart= 0: any otherklstarttransitions the locker to Error State Invalid, as in Rule GR18.Every pass but the last ends with a full block, so a halt leaves block_base= 0; the last pass may leave a partial block. A halted instruction is resumed withblock_base= 0, whateverblock_baseit started with, and theklstartthat its halt recorded is an interruption point of the resumed instruction. An instruction issued with a non-zeroblock_basecan still halt where step 3.i allows it, once its first iteration has completed the block. At a halt,input_baseis a whole number of bytes, soklstartnever describes a position inside a byte, as is also the case on the output side of Hash_Output (Hash and MAC Functions, and XOFs). -
-
Where
last_block_stateis notNone:-
If
max_len= 0, the invoking Machine setslast_block_len←bon entering Current_State. Software then issues akl.setstnaming eitherlast_block_stateor another State that the invoking Machine admits from Current_State, such as Hash_Output in Hash and MAC Functions, and XOFs. -
If
max_len!= 0, Current_State absorbs fewer thanmax_lenbits (step 1), and software enterslast_block_state, which absorbs the rest.
-
-
When entering
last_block_statefrom Current_State:-
If
max_len= 0, a Form Bkl.setstinvokesFINAL_BLOCK_ENTRY(0, b, unit)(FINAL_BLOCK_ENTRY(lo, hi, unit)), with theunitthat Rule MR11 admits; withXs= 0, akl.execinlast_block_statetransitions the locker to Error State Invalid (step 1 below). -
If
max_len!= 0, thekl.setstis of Form A and setslast_block_len←max_len−cumul_len.-
If this new
last_block_len>b, the locker transitions to Error State Invalid.
-
-
finalize()is not performed.
-
-
In
last_block_state, a single Form Bkl.execabsorbsINPUT[last_block_len-1:0](Rule MR10, item 3), with the only interruption point 0 (Rule MR13), and performs:-
If
last_block_len= 0, the locker transitions to Error State Invalid (Rule MR10). -
input_base← 0. -
while (
input_base<last_block_len) do:-
amount←min(last_block_len - input_base, b - block_base). -
Steps 3.b to 3.f of the
kl.execin Current_State. -
If
block_base=band eitherinput_base<last_block_lenorprocess_last_block()isNone, then:-
process_block(block, state), ifprocess_block()is notNone. -
block_base← 0.
-
-
-
If
process_last_block()is notNone, then:-
process_last_block(block, state), -
block_base← 0.
-
-
last_block_len← 0.
-
-
A
kl.setstthat transitions the locker from Current_State orlast_block_stateto another State performsfinalize()before the transition, iffinalize()is notNoneand step 3.h has not performed it. This does not apply where the destination is:-
Ready or an Error State; or
-
last_block_state, from Current_State.
-
-
The locker transitions to Error State Invalid on:
-
leaving
last_block_state, withlast_block_len!= 0, for a Valid State other than Ready; -
where
max_len!= 0 andlast_block_stateis notNone, leaving Current_State for a Valid State other than Ready orlast_block_state.
-
-
Common Operations
The operations of this section, like PROCESS_VLI (Macro: Processing Variable Length Inputs into a Fixed Length Output), are macros: an invocation splices the behavior stated here into the State or instruction that invokes it, with each parameter replaced by the variable, value or function that the Machine passes, and with any change that the Machine states.
Each one applies the Machine Rules that it cites; a Machine that invokes it does not restate them.
PRESET (PRESET(parent, field)) differs: a Machine invokes it to define itself as a variant of another Machine.
LOAD_FIXED_FIELD(field, w)
Invoked by the kl.setst that enters a State, or that performs an operation (Rule MR16), and takes a value of w bits as INPUT:
-
Its native Form is C. Where
w≤ 128, Forms A and D are admitted too (Rule MR5); where the invocation passesBas a third parameter, Form B is admitted, whateverw. -
field←INPUT[w-1:0]; the other bits ofINPUTare ignored (Rule MR8). -
Where the macro is invoked on entering a State, a same-State
kl.setstinto that State that the Machine allows (Rule GR19.2) does the same: it replacesfieldand performs the steps that the Machine adds, and changes nothing else.
LOAD_LONG_FIELD(len, block, state, n, process_block(), finalize(), mode, g)
Defines a State X that loads a field of len bits over several Form B kl.exec (Rule MR14), with W = cumul_len, in bits:
-
Entering X zeroes
input_base,block_baseandcumul_len, and the field wheremode=assign, and clears its flag, if any. The Machine allows a same-Statekl.setst(Rule GR19.2), which does the same and restarts the load, discarding the part loaded so far. -
Each
kl.execin X invokes
PROCESS_VLI(len, block, b, state, n, input_base, block_base, 0, cumul_len,
process_block(), finalize(), mode, g),
withlast_block_state=None(Macro: Processing Variable Length Inputs into a Fixed Length Output). -
The load is complete once
cumul_len=len; a field stored as loaded then sets its flag, if any (Rule MR14). -
Leaving X before the load is complete leaves the field unconfigured (Rule MR14, item 5).
FINAL_BLOCK_ENTRY(lo, hi, unit)
Invoked by the Form B kl.setst with auxiliary operand Xs that enters a final-block State (Rule MR10):
-
Xsmust be a multiple ofunitwithlo≤Xs≤hi;unitis 8 unless Rule MR11 lets the Machine pass 1. Any otherXstransitions the locker to Error State Invalid (Rule MR11). -
last_block_len←Xs, the bit length of the final block. -
If
Xs= 0, which requireslo= 0, thekl.setstprocesses the empty final block as Rule MR10 item 2 states, unless the Machine states otherwise; withlo> 0, an empty final block takes the bypass of that item instead. -
Otherwise, a single
kl.execin the State processesINPUT[last_block_len-1:0]and setslast_block_len← 0 (Rule MR10 item 3): aKLLENsmaller thanlast_block_lenis not zero-padded but violates the granularity, and an empty transfer window does not reach the Machine.
SET_TAG_LEN(cap, lo) and VERIFY_TAG(expected, len)
SET_TAG_LEN(cap, lo) is invoked by the Form B kl.setst with immediate kl_state_hash_verify and auxiliary operand Xs that enters Hash_Verify (Rule MR12):
-
Xsmust be a multiple of 8 withXs≥lo. -
tag_len←min(Xs, cap), orXswherecapisNone, which must equaltag_len_p(Rule MR12). -
Any other
Xstransitions the locker to Error State Invalid.
VERIFY_TAG(expected, len), with len = tag_len where the invocation omits it, is invoked by the single Form B kl.exec that verifies a tag or MAC (Rule MR12):
PRESET(parent, field)
Defines a Machine that is the Machine parent with field, the IV or nonce that parent takes from software for each message, carried in the Provisioning Input instead, as the Machine’s PI table shows:
-
Provisioning sets
field, or the Internal State that the Machine forms from it, from the PI, and an import from the Serialized Content; no instruction setsfield. The step ofparentthat loadsfieldfromINPUTdoes not apply, and the Machine states what replaces it. -
Entering Ready keeps
field, with any step that the Machine states for it, so a later message is decrypted under the samefield; software that needs anotherfieldprovisions another locker. -
The Machine only decrypts (Rule MR1): the party that provisions the locker encrypts under the key and
fieldonce, by other means (Rule MR15). -
The Machine is not a
kl.derivedestination (Derivation Endpoints of the Machines): its key andfieldare configured together, by provisioning or import.
|
Where
Software holds the same key in another locker when it can provision, by its SKID, a System Key that the SKS allows for that locker’s Machine. |
GCM Mode
The GCM mode was designed by David McGrew and John Viega cite:[DBLP-conf-indocrypt-McGrewV04] and became a NIST Recommendation in 2007 cite:[nist-SP-800-38D]. cite:[nist-SP-800-38D] §5.1 defines GCM only for block ciphers whose block is 128 bits, such as AES and SM4 (Table 1).
- Parameters
-
-
k= key size (ka multiple of 64). -
b= 128 = block size in bits. -
c= 32 = counter size in bits. -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
J0:128bits. The pre-counter block of cite:[nist-SP-800-38D] §7.1, a byte string (Notation and Conventions); its bytes 12 to 15,J0[127:96], hold the big-endian counter of the last counter block used,start_ctrbefore the first block. -
auth_key(derived):128bits. Rule MR7 applies. -
tag:128bits. In Set_Aux_Value, the IV absorbed so far: the running GHASH value over it, or, iflen= 96, the IV itself. Then the running GHASH value over the AD and the ciphertext; once finalized, the tag. -
start_ctr: an integer in the range 0 to 232-1, the counter of the pre-counter blockJ0of cite:[nist-SP-800-38D] §7.1; the first block uses the initial counter blockinc32(J0), of counter (start_ctr+ 1) mod 232. -
last_block_len: 0, or a multiple of 8 from 8 to 120. The bit length of the final, partial block of the plaintext or ciphertext. -
tag_len: the number of bits that Hash_Verify compares, one of 128, 120, 112, 104, 96 and 64, or 0 before it is set; serialized on 16 bits. -
tag_len_p: the length of every tag that the locker outputs, and the number of bits that every verification compares (Rule MR12): one of 128, 120, 112, 104, 96 and 64 (cite:[nist-SP-800-38D] §5.2.1.2), and 128 if KeyType = 1; held in AuxInfo, not serialized. -
len,block_base,cumul_len,input_base: in Set_Aux_Value, themax_len,block_base,cumul_lenandinput_baseof Macro: Processing Variable Length Inputs into a Fixed Length Output for the IV.input_baseis not serialized.
The variables
len,input_base,block_baseandcumul_lenof the internal state may overlap withJ0, or be separate fields, as may be necessary if the implementation of macroPROCESS_VLI(Macro: Processing Variable Length Inputs into a Fixed Length Output) works with integers of a different length. Where they overlap, they hold their values only untilfinalize()writesJ0, and the transition to Hash_Absorb leavesJ0asfinalize()wrote it. -
-
Serialized Content:
Pos. Size (Bits) Field Description i
kor 64keyKey value or System Key Identifier
ii
128
J0The pre-counter block of cite:[nist-SP-800-38D] §7.1, a byte string;
J0[127:96], its bytes 12 to 15, holds the big-endian counter of the last counter block used,start_ctrbefore the first block.iii
128
tagiv
32
start_ctrThe counter of the pre-counter block
J0before the first block, serialized asbin(start_ctr,32).v
16
last_block_lenvi
16
tag_lenZero, or one of 128, 120, 112, 104, 96 and 64, and nonzero exactly in State Hash_Verify; an import that violates this transitions the locker to Error State Invalid (Rule MR3).
vii
padPadding
Zero; (−(
kf+ 320)) mod 128 = (−(kf+ 64)) mod 128 bits.While the locker is in State Set_Aux_Value,
J0is replaced by the following fields:Pos. Size (Bits) Field Description ii.a
16
lenTotal length of the IV, in bits.
ii.b
16
Padding
Zero.
ii.c
16
block_baseAmount of data, in bits, absorbed so far into the current block.
ii.d
48
cumul_lenCumulative length, in bits, of the data absorbed so far.
ii.e
32
Padding
Zero.
-
| There are no fields for the lengths of the AD and of the plaintext, as they are maintained by the calling software. |
- Machine-Specific Functions
-
-
absorb(data)absorbs data into the hash function by performing:-
tag ← tag xor data. -
tag ← Galoismul(tag, auth_key).
-
-
next_ks() → bits(b)steps the counter and returns the next keystream block:-
ctr ← (int(bswap(J0[127:96])) + 1) mod 232, withctra local integer. -
If
ctr=(start_ctr - 1) mod 232(at most 232 − 2 blocks), the locker transitions to Error State Invalid, and the callingkl.execperforms no further step. -
Otherwise,
J0[127:96] ← bswap(bin(ctr,32)), the counter back in big-endian, andnext_ks()returnsenc_blk(key, J0).
-
-
close_tag(L)absorbs the length blockLand masks the tag:-
absorb(L). -
tag ← tag xor enc_blk(key, bswap(bin(start_ctr,32)) @ J0[95:0]).
-
-
Galoismul(a, b)is multiplication in the GHASH field of cite:[nist-SP-800-38D] §6.3, in the representation of that section.The field is GF(2)[x] modulo
x128 + x7 + x2 + x + 1. A 128-bit valueVrepresents the element whose coefficient ofx8i+j, for0≤i<16and0≤j≤7, isV[8i + (7-j)].In other words, the byte order runs forward (“little endian”: the byte at offset 0 contains the coefficients of
x0throughx7, the byte at offset 1 contains the coefficients ofx8throughx15, and so on) while the bit order is reversed within each byte: in the byte at offset 0, bit 0, the least significant bit, is the coefficient ofx7, bit 1 that ofx6, and so on.
-
- State Machine
-
-
States:
Besides Ready, Success, and Failure, the GCM Mode Machines make use of the following States:
-
Set_Aux_Value: Absorb the IV; the
kl.execthat completes it computesJ0. -
Hash_Absorb: Process Associated Data (AD) into the tag.
-
Encrypt: Encrypt the plaintext and absorb the ciphertext into the tag.
-
Enc_Last_Block: Encrypt the final, fractional block of the plaintext.
-
Enc_Tag_Finalize: Finalize the encryption tag, prepare to return its value.
-
Decrypt: Absorb the ciphertext into the tag and decrypt it.
-
Dec_Last_Block: Decrypt the final, fractional block of the ciphertext.
-
Dec_Tag_Finalize: Finalize the computation of the tag and keep it internally.
-
Hash_Verify: Compare the tag against a user-supplied value, without disclosing it.
The Associated Data (AD) and the plaintext or ciphertext are absorbed into
GHASHdifferently; this places two obligations on the caller:-
For the AD, the caller must zero every bit of the final block beyond the actual end of the AD. No State processes a fractional last AD block separately.
-
For the plaintext and ciphertext, the caller must not pass a final block shorter than
b, zero-padded, to Encrypt or Decrypt. Such a block goes through State Enc_Last_Block, resp. Dec_Last_Block.
Such a padded block would be encrypted, emitting keystream, and absorbed, producing a tag that does not conform to cite:[nist-SP-800-38D]. GHASHabsorbs the final AD block whole. -
-
Allowed State Transitions:
-
Ready → Set_Aux_Value → Hash_Absorb; the
kl.execthat completes the IV makes the second transition (Rule MR18). -
Set_Aux_Value → Set_Aux_Value, which restarts the IV (see below).
-
Hash_Absorb → Encrypt, if encryption is allowed (Rule MR1).
-
Hash_Absorb → Decrypt, if decryption is allowed (Rule MR1).
-
Encrypt → { Enc_Last_Block → } Enc_Tag_Finalize → Success.
-
Decrypt → { Dec_Last_Block → } Dec_Tag_Finalize → Hash_Verify → Success or Failure.
-
-
Behavior:
-
When entering State Ready:
-
auth_key ← enc_blk(key, zeros(b)); -
tag ← zeros(b); -
tag_len ← 0; -
last_block_len ← 0.
-
-
When entering State Set_Aux_Value:
-
A Form B
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandXssets the IV length in bits:len ← Xs. -
Xsmust be a multiple of 8 with8≤Xs≤8192; any otherXs,0included, transitions the locker to Error State Invalid. -
tag ← zeros(b). -
A same-State Form B
kl.setstrepeats these operations, restarting the IV (LOAD_LONG_FIELD(len, block, state, n, process_block(), finalize(), mode, g)).
-
-
State Set_Aux_Value is
LOAD_LONG_FIELD(len, tag, tag, b, process_block(), finalize(), xor_accumulate, b)(LOAD_LONG_FIELD(len, block, state, n, process_block(), finalize(), mode, g)): entering it also zeroesinput_base,block_baseandcumul_len, and eachkl.execabsorbs the next part of the IV intotag, where:-
process_block()performstag ← Galoismul(tag, auth_key); a 96-bit IV never fills a block, so it is never multiplied; -
finalize()is defined as:-
If
len = 96, then:-
J0 ← bswap(bin(1,32)) @ tag[95:0].The value of
J0is that of cite:[nist-SP-800-38D] §7.1 for a 96-bit IV, the byte stringIV ‖ bswap(bin(1,32)): the IV occupies bytes 0 to 11 (J0[95:0]), and the counter occupies bytes 12 to 15 as a big-endian integer.
-
-
Otherwise, let
s ← 128 × ceil(len/128) - len, and the computation ofJ0 ← GHASH(IV ‖ 0s+64 ‖ bswap(bin(len,64)), auth_key)is completed by performing:-
if
block_base != 0, thentag ← Galoismul(tag, auth_key). -
tag ← tag xor (bswap(bin(len,64)) @ zeros(64)). -
tag ← Galoismul(tag, auth_key). -
J0 ← tag.
-
-
start_ctr ← int(bswap(J0[127:96])). -
tag ← zeros(b). -
The locker transitions to State Hash_Absorb.
-
-
-
When leaving State Set_Aux_Value:
-
the
kl.execthat completes the IV performsfinalize()(step 3.h of Macro: Processing Variable Length Inputs into a Fixed Length Output), which transitions the locker to Hash_Absorb; -
a
kl.setstnaming Ready discards the partial IV withoutfinalize(), zeroingtag,J0,len,block_baseandcumul_len(Rule MR14); -
a
kl.setstnaming Hash_Absorb transitions the locker to Error State Invalid: entering Hash_Absorb requires a complete IV (Rule MR1).
-
-
-
|
The IV is absorbed into |
-
In State Hash_Absorb, (multi-block) Form B
kl.execinstructions absorb each data block intotag:absorb(INPUT). -
In State Encrypt or Decrypt, (multi-block) Form A
kl.execinstructions encrypt, resp. decrypt,INPUTintoOUTPUTand absorb the ciphertext,OUTPUT, resp.INPUT, intotag, withtmpa localbits(b):-
tmp ← INPUT xor next_ks(), resp.tmp ← INPUT. -
absorb(tmp). -
OUTPUT ← tmp, resp.OUTPUT ← tmp xor next_ks().
-
-
When entering State Enc_Last_Block, resp. Dec_Last_Block, a Form B
kl.setstwith immediatekl_state_enc_last_block, resp.kl_state_dec_last_block, performsFINAL_BLOCK_ENTRY(8, 120, 8)(FINAL_BLOCK_ENTRY(lo, hi, unit)):last_block_len ← Xs, a multiple of 8 from 8 to 120; an empty final block takes the bypass below.cite:[nist-SP-800-38D] admits any bit length, but numbers the bits of a byte from the most significant, so a truncation to the least significant bits would not give its bit string (Rule MR11). -
In State Enc_Last_Block or Dec_Last_Block, a single Form A
kl.execencrypts, resp. decrypts, itsINPUTinto itsOUTPUTand absorbs the zero-padded final block of the ciphertext intotag, withtmpa localbits(b):-
In Enc_Last_Block:
-
tmp ← trunc(INPUT, last_block_len) xor trunc(next_ks(), last_block_len). -
absorb(tmp). -
OUTPUT ← tmp.
-
-
In Dec_Last_Block:
-
tmp ← trunc(INPUT, last_block_len). -
OUTPUT ← tmp xor trunc(next_ks(), last_block_len). -
absorb(tmp).
-
-
-
Rule MR10 applies to Enc_Last_Block and Dec_Last_Block, which have no successor (item 4): Enc_Tag_Finalize, resp. Dec_Tag_Finalize, takes the length block as the operand of a Form C
kl.setst, and thatkl.setstleaves the final-block State after itskl.exec. For an empty final block, a Form Ckl.setstfrom Encrypt into Enc_Tag_Finalize, resp. from Decrypt into Dec_Tag_Finalize, bypasses the final-block State:tagandJ0are unchanged, and the message ends with the blocks already processed. -
When entering State Enc_Tag_Finalize, resp. Dec_Tag_Finalize:
-
A Form C
kl.setstwith immediatekl_state_enc_tag_finalize, resp.kl_state_dec_tag_finalize, and auxiliary operandINPUTsupplies the length block, which software computes:-
INPUT ← bswap(bin(len_in_bits(plaintext), 64)) @ bswap(bin(len_in_bits(AD), 64)), resp.INPUT ← bswap(bin(len_in_bits(ciphertext), 64)) @ bswap(bin(len_in_bits(AD), 64)). -
len_in_bits(plaintext)counts only the plaintext that Encrypt and Enc_Last_Block processed, resp.len_in_bits(ciphertext)only the ciphertext that Decrypt and Dec_Last_Block processed; a final block that akl.setstomitted is not counted.
-
-
close_tag(INPUT[127:0])(Rule MR8) computes the tag and retains it internally.
-
-
In State Enc_Tag_Finalize, a single Form C
kl.execwritestag[tag_len_p-1:0], the truncated tagMSBtag_len_p(T)of cite:[nist-SP-800-38D] §7.1, toOUTPUT(Rule MR12), and the locker transitions to Success. -
When entering State Hash_Verify, a Form B
kl.setstwith immediatekl_state_hash_verifyperformsSET_TAG_LEN(None, 0)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)):tag_len ← Xs, the number of tag bits to compare, which must equaltag_len_p. -
In State Hash_Verify, a single Form B
kl.execperformsVERIFY_TAG(tag)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)): it comparesINPUT[tag_len-1:0]in constant time withtag[tag_len-1:0], theMSBt(T)of cite:[nist-SP-800-38D] §7.2 witht=tag_len, and the locker transitions to Success or Failure. In both casestag_len ← 0.Truncated tags are prefixes of one another. The floor of 64 bits excludes the 32 bits that cite:[nist-SP-800-38D] admits for some applications. Every verification compares tag_len_pbits (Rule MR12), but a forgery attempt with a message of ℓ blocks succeeds with probability about ℓ × 2-tag_len_p, and each success reveals information aboutauth_keythat makes the next attempt easier. Fortag_len_p< 128, the caller applies the limits of cite:[nist-SP-800-38D] Appendix C on message length and on failed verifications per key (Rule MR15). Rule MR15 leaves to the caller a singletacross lockers that hold the same key by value.Decrypt and Dec_Last_Block release the plaintext block by block, before Hash_Verify checks the tag, whereas cite:[nist-SP-800-38D] returns no plaintext when the check fails. The same holds for the other AEAD Machines: GCM with Preset IV, GCM-SIV Mode (whose Dec_Tag_Finalize verifies the tag), OCB Mode, OCB with Preset Nonce, Ascon-AEAD128, Ascon-AEAD128 with Preset Nonce and Ascon-AEAD128 with Nonce Masking. Rule SR18 forbids the caller to use this plaintext before the locker reaches Success, and requires it to discard the plaintext otherwise. In OCB, the released plaintext also enables a forgery (Accepted Risks). Only software that complies with Rule SR18 obtains the authenticated decryption of cite:[nist-SP-800-38D] and of the standards of the other AEAD Machines. Two messages that the caller encrypts under the same keyand IV revealauth_key, which then allows forgeries under every IV until the key is retired (Accepted Risks).
Code examples: GCM Encryption, GCM Decryption.
GCM with Preset IV
The mode of operation “GCM with a Preset IV” is a variant of GCM in which the initialization vector (IV) is provisioned with the key, rather than supplied by software for each message.
This Machine is PRESET(GCM, IV) (PRESET(parent, field), GCM Mode).
Provisioning forms J0 from the 96-bit IV as cite:[nist-SP-800-38D] §7.1 does; J0 itself is never provisioned.
The differences follow.
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field Description ii
kor 64keyKey value or System Key Identifier
iii
96
IVThe IV of cite:[nist-SP-800-38D] §7.1. Only a 96-bit IV is supported.
iv
padPadding
Zero; (−(
kf+ 96)) mod 128 bits. -
Internal State:
Same as for GCM.
Upon provisioning, before the operations of entering Ready (Rule MR17),
J0 ← bswap(bin(1,32)) @ IV, the byte stringIV ‖ bswap(bin(1,32))of cite:[nist-SP-800-38D] §7.1, andstart_ctr ← 1.start_ctris 1 in every CC of this Machine: an import whose Serialized Content holds another value completes into Error State Invalid (Rule MR3). -
Serialized Content:
Same as for GCM.
-
- State Machine
-
-
States and Allowed Transitions:
Same as for GCM, with the following exceptions:
-
There is no State Set_Aux_Value, and nothing that GCM specifies for it applies. The transition is from Ready to Hash_Absorb.
-
-
State Machine Behavior:
The differences with respect to GCM are:
-
Entering State Ready also restores the provisioned
J0, byJ0[127:96] ← bswap(bin(1,32)), which keeps the IV (PRESET(parent, field)).
-
-
|
The rationale of A provisioned |
GCM-SIV Mode
The GCM-SIV mode is described in cite:[DBLP-journals-iacr-GueronLL17] and cite:[RFC8452]. This specification defines GCM-SIV only for AES, whose block is 128 bits, as cite:[RFC8452] does (Table 1); the definition will be extended to other block ciphers if needed.
The decryption path of GCM-SIV resembles that of GCM; the encryption path differs:
-
Encryption: Hash_Absorb absorbs the whole associated data (AD) and plaintext. Enc_Tag_Finalize then absorbs the lengths and produces the SIV, which is also the tag. Encrypt then makes a second pass over the plaintext, with the SIV as its initialization vector.
-
Decryption: Hash_Absorb absorbs only the AD. Decrypt decrypts the ciphertext and absorbs the resulting plaintext. Dec_Tag_Finalize then absorbs the lengths, recomputes the SIV, and compares it internally with the SIV set in Set_Aux_Value_2.
- Parameters
-
-
k= key size, either 128 or 256: cite:[RFC8452] defines AES-GCM-SIV only for these two. -
b= 128 = block size. -
c= 32 = counter size. -
Granularity:
b. -
The authentication tag is
b= 128 bits long. -
A plaintext or ciphertext holds at most 232 blocks, the final partial block included: the
P_MAXof cite:[RFC8452] §6. The caller must keep the AD within theA_MAXof cite:[RFC8452] §6, 236 bytes (Rule MR15).
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
enc_key(derived):kbits. -
auth_key(derived): 128 bits. Rule MR7 applies to both. -
nonce: 96 bits. -
ctr: the number of plaintext or ciphertext blocks encrypted or decrypted, an integer in the range 0 to 232, held and serialized on 33 bits: bits [31:0] in field iii, bit 32 in field vi. -
SIV: 128 bits. -
tmp: 128 bits. -
last_block_len: 7 bits, an integer in the range 0 to 127. The bit length of the final, partial block of the plaintext or ciphertext.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
96
nonceiii
32
ctr[31:0]iv
128
SIVv
128
tmpvi
16
ctr[32]in bit 15,last_block_lenin bits [6:0], the other bits zerovii
padPadding: (−(
kf+ 400)) mod 128 = (−(kf+ 16)) mod 128.
-
- Machine-Specific Functions
-
-
RFC8452_KeyDeriv(k, key, nonce)derives the per-nonce message-encryption and message-authentication keys of cite:[RFC8452] §4:AES-GCM-SIV Key Derivationfunction RFC8452_KeyDeriv(k : int, key : bits(k), nonce : bits(96)) → struct{enc_key : bits(k), auth_key : bits(128)} = { local A : array [0..5] of bits(128); local E : bits(k); local i : int; foreach(i from 0 to k/64 + 1) do: A[i] ← enc_blk(key, nonce @ bin(i,32)); foreach(i from 2 to k/64 + 1) do: E[64*i-65 : 64*i-128] ← A[i][63:0]; return struct { enc_key = E, auth_key = A[1][63:0] @ A[0][63:0] }; }The loop makes
k/64 + 2 calls, four fork= 128 and six fork= 256, and keeps the low 64 bits of each: these are the “first eight bytes” of cite:[RFC8452] under Notation and Conventions. -
absorb(data)absorbs data into the hash function by performing a step of POLYVAL:-
tmp ← tmp xor data. -
tmp ← Montmul(tmp, auth_key), with theMontmulof the POLYVAL of POLYVAL Hashing Function.
-
-
next_ks() → bits(b)returns the keystream block of the next counter and steps the counter:-
If
ctr= 232, the locker transitions to Error State Invalid, and the callingkl.execperforms no further step: the block would be one more than a message may hold. -
Otherwise,
ctr ← ctr + 1, andnext_ks()returnsenc_blk(enc_key, 1 @ SIV[126:32] @ bin((int(SIV[31:0]) + ctr - 1) mod 232, 32)), the block of the counter before the step.
-
-
synth_siv(L)absorbs the length blockLand computes the SIV intotmp:-
absorb(L). -
tmp ← enc_blk(enc_key, 0 @ tmp[126:96] @ (tmp[95:0] xor nonce)).
-
-
- State Machine
-
-
States:
Besides Ready, Success, and Failure, the GCM-SIV Machine makes use of the following States:
-
Set_Aux_Value: Set the value of
nonce. -
Set_Aux_Value_2: Set the SIV.
-
Hash_Absorb: Absorb the AD and, on the encryption path, the plaintext into the partial tag
tmp. -
Encrypt: Encrypt the plaintext.
-
Enc_Last_Block: Encrypt the final, fractional block of the plaintext.
-
Enc_Tag_Finalize: Finalize the SIV with the AD and plaintext lengths, and return it.
-
Decrypt: Decrypt the ciphertext and absorb the resulting plaintext into the partial tag.
-
Dec_Last_Block: Decrypt the final, fractional block of the ciphertext.
-
Dec_Tag_Finalize: Finalize the tag with the AD and plaintext lengths, then compare it against the SIV.
-
-
Allowed State Transitions:
-
Ready → Set_Aux_Value.
-
Set_Aux_Value → Set_Aux_Value_2 or Hash_Absorb.
-
Set_Aux_Value_2 → Hash_Absorb.
-
For encryption: Hash_Absorb → Enc_Tag_Finalize → Encrypt { → Enc_Last_Block }. The path ends in Encrypt or Enc_Last_Block, not in Success; the next message starts with a return to Ready.
-
The
kl.execof Enc_Tag_Finalize synthesizesSIVand transitions the locker to Encrypt (Rule MR18). -
For decryption: Hash_Absorb → Decrypt → { Dec_Last_Block → } Dec_Tag_Finalize → Success or Failure.
-
Rule MR10 applies: the
kl.execof Dec_Last_Block transitions the locker to Dec_Tag_Finalize, which akl.setstfrom Decrypt enters directly for an empty final block (item 2); Enc_Last_Block has no successor. -
A final plaintext or ciphertext block shorter than
bgoes through Enc_Last_Block, resp. Dec_Last_Block.
-
-
Behavior:
-
Upon entering State Ready:
-
The following initialization operations are performed:
-
nonce ← 0,ctr ← 0,tmp ← 0,last_block_len ← 0andSIV ← 0.
-
-
-
When entering State Set_Aux_Value:
-
A Form C
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandINPUTis expected. -
nonce ← INPUT[95:0](Rule MR8). -
(
enc_key,auth_key)←RFC8452_KeyDeriv(k, key, nonce).
-
-
When entering State Set_Aux_Value_2:
-
A Form C
kl.setstwith immediatekl_state_set_aux_value_2and auxiliary operandINPUTis expected. -
SIV ← INPUT[127:0](Rule MR8).This State is meant to serve the decryption path. Entering it during encryption is harmless: an externally set
SIVnever feeds the encryption keystream. The encryption path reaches Encrypt only through the Enc_Tag_Finalizekl.exec, which overwritesSIVwith the synthetic value, and it reaches Enc_Last_Block only from Encrypt. Skipping it during decryption leavesSIVat the zero that entering Ready set.
-
-
In State Set_Aux_Value or Set_Aux_Value_2, a
kl.setstnaming that same State transitions the locker to Error State Invalid (Rule GR19.2):-
The
kl.setstthat enters the State sets the value. -
The State loads no field by
kl.exec.
-
-
In State Hash_Absorb, each (multi-block) Form B
kl.execabsorbs its data blocks intotmp:absorb(INPUT). The caller must zero-pad the following, each separately to a multiple of 16 bytes, as cite:[RFC8452] §4 specifies:-
The AD.
-
On the encryption path, the plaintext.
Every bit of the final partial block beyond the end of its data must be zero.
-
-
In State Enc_Tag_Finalize, a single Form A
kl.execis expected, whoseINPUTthe caller must set tobin(len_in_bits(plaintext), 64) @ bin(len_in_bits(AD), 64). It finalizes the SIV:-
synth_siv(INPUT[127:0])(Rule MR8). -
SIV ← tmpandOUTPUT ← SIV. -
The locker transitions to Encrypt.
-
-
In State Encrypt or Decrypt, (multi-block) Form A
kl.execinstructions are expected, encrypting, resp. decrypting,INPUTintoOUTPUT:-
OUTPUT ← INPUT xor next_ks(). -
In Decrypt only,
absorb(OUTPUT), which absorbs the plaintext intotmp.
-
-
When entering State Enc_Last_Block, resp. Dec_Last_Block, a Form B
kl.setstwith immediatekl_state_enc_last_block, resp.kl_state_dec_last_block, performsFINAL_BLOCK_ENTRY(8, 120, 8)(FINAL_BLOCK_ENTRY(lo, hi, unit)):last_block_len ← Xs, a multiple of 8 from 8 to 120. An empty final block skips Enc_Last_Block: the message ends in Encrypt. -
In State Enc_Last_Block or Dec_Last_Block, a single Form A
kl.execinstruction is expected, encrypting, resp. decrypting,INPUTintoOUTPUTas follows (Rule MR10):-
OUTPUT ← trunc(INPUT, last_block_len) xor trunc(next_ks(), last_block_len). -
In Dec_Last_Block only,
absorb(OUTPUT), which absorbs the zero-padded plaintext into the partial tag. -
In Dec_Last_Block, the locker then transitions to Dec_Tag_Finalize; the Machine names no successor of Enc_Last_Block, so the locker stays in it.
-
-
In State Dec_Tag_Finalize, a single Form B
kl.execis expected, whoseINPUTthe caller must set tobin(len_in_bits(plaintext), 64) @ bin(len_in_bits(AD), 64); it compares the SIV itself (Rule MR12):-
synth_siv(INPUT[127:0])(Rule MR8). -
If
tmp=SIV, the locker transitions to Success; otherwise, it transitions to Failure.
-
-
-
Code examples: GCM-SIV Mode.
OCB Mode
Only OCB3 is architected, following RFC 7253 cite:[RFC7253] and cite:[DBLP-journals-joc-KrovetzR21], and only for AES, as in the AEAD algorithms of cite:[RFC7253] (Table 1).
The state machine follows RFC 7253 except in notation.
Bit positions count from 0 at the least significant bit (Notation and Conventions); RFC 7253 counts them from 1 at the most significant bit.
A block is a little-endian byte string: its byte 0 is the first byte of the RFC 7253 string.
A formula over RFC 7253 bit positions is computed on the bswap view of the block, either with an explicit bswap or in a function or variable whose name ends in _be.
Block indices, index included, start from 1 as in RFC 7253.
- Parameters
-
-
b= 128 = block size. -
k= key size. It must be 128, 192, or 256. -
MAX_BLOCKS= 248 = maximum number of blocks, a final partial block included, in the AD or in the plaintext. This specification sets this bound: cite:[RFC7253] places no limit on the length of a message. The caller keeps the uniqueness of the nonce and the recommendation of cite:[RFC7253] §5 that a key process at most 248 blocks in total, the associated data included (Rule MR15). -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
N: 120 bits. -
N_len: 7 bits. Bit length of the nonce. It must not exceed 120. -
HasN: bit 0 of StateExtension, set onceNholds a loaded nonce (Rule MR14). -
L*,offset,hash_A,checksum_P: 128 bits each. -
L$andL[i](derived): 128 bits each, for0≤i≤ ⌊log2(MAX_BLOCKS)⌋ = 48;L[i]isLiof cite:[RFC7253]. Rule MR7 applies to them. -
tag_len: 8 bits. Bit length of the tag. The allowed values are 64, 96, and 128. -
last_block_len: 7 bits, an integer in the range 0 to 127. The bit length of the final, partial block of the AD, the plaintext or the ciphertext; 0 for an empty final block. -
index: 49 bits, corresponding toiin the loops in RFC 7253. It is 0 from the entry into Ready to the entry into Hash_Absorb, and then ranges from 1 toMAX_BLOCKS+ 1 = 248 + 1.
-
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
120
Niii
7
N_len, the bit length of the nonceiv
1
Padding
v
128
L*; the derivedL$andL[i]are not serialized (Rule MR7)vi
128
offset(current offset)vii
128
hash_Aviii
128
checksum_P(used also for the final tag)ix
49
indexx
2
tag_len, encoded astag_len/32 − 2. The value 3 is not produced; an import that carries it transitions the locker to Error State Invalid (Rule MR3).xi
7
last_block_lenxii
padPadding: (−(
kf+ 698)) mod 128 = (−(kf+ 58)) mod 128.
-
- Machine-Specific Functions
-
-
ntz(n)= the number of trailing zero bits in the base-2 representation of the positive integern. Formally,ntz(n)is the largest integerxfor which2xdividesn. -
double(S): doubling in the OCB3 field of cite:[RFC7253], which is thedoubleof CMAC Functions forb= 128. -
next_offset()advancesoffsetto the next full block:-
If
index>MAX_BLOCKS, the locker transitions to Error State Invalid: the block would be one more than the AD, the plaintext or the ciphertext may hold. -
offset ← offset xor L[ntz(index)]. -
index ← index + 1.
-
-
last_offset()advancesoffsetto the final partial block:-
If
index>MAX_BLOCKS, the locker transitions to Error State Invalid, as innext_offset(). -
offset ← offset xor L*.
-
-
ocb_tag(X)computes intochecksum_Pthe tag, before truncation, from the last checksum inputX:checksum_P ← enc_blk(key, checksum_P xor X xor L$) xor hash_A. -
nonce_be(N, n)= the big-endian view of then-bit nonce bit string held inN. cite:[RFC7253] treats the nonce as a bit string whose first bit is the most significant, so when it is serialized into bytes the final, possibly partial byte is left-aligned: itsr=nmod 8 most significant bits carry nonce and its remaining bits are padding. Withq= ⌈n/8⌉ the number of bytes so occupied,nonce_be(N, n)=(bswap(N[8q-1:0], q) >> 8 - r) mod 8[n-1:0], ann-bit value.The first bit of the nonce string is
nonce_be(N, n)[n-1]and the last is bit0. Forr= 0 this reduces tobswap(N[n-1:0]), so a nonce occupying a whole number of bytes is unaffected.bswapalone cannot express the general case, since it is defined only over byte strings.
-
- State Machine
-
-
States: Besides Ready, Success, and Failure, the Machines implementing OCB Mode use the following States:
-
Set_Aux_Value: Set the length and the value of the nonce.
-
Hash_Absorb: Set the tag length, and process the AD.
-
Hash_Absorb_Last_Block: Set the bit length, possibly zero, of the final block of the AD, and process that block. Every message passes through this State.
-
Encrypt: Process the plaintext by absorbing it into the tag and encrypting it.
-
Enc_Last_Block: Provide the last block of the plaintext, then process it.
-
Enc_Tag_Finalize: Return the tag.
-
Decrypt: Process the ciphertext by decrypting it and absorbing the plaintext into the tag.
-
Dec_Last_Block: Provide the last block of the ciphertext, then process it.
-
Hash_Verify: Compare a user-provided value with the internally computed tag.
-
-
Allowed State Transitions:
-
Ready → Set_Aux_Value → Hash_Absorb → Hash_Absorb_Last_Block.
-
Set_Aux_Value → Set_Aux_Value, which restarts the nonce load (see below).
-
Hash_Absorb_Last_Block → Encrypt or Decrypt.
-
Encrypt → Enc_Last_Block → Enc_Tag_Finalize → Success.
-
Decrypt → Dec_Last_Block → Hash_Verify → Success or Failure.
-
The
kl.execof Enc_Last_Block, resp. Dec_Last_Block, makes the transition to Enc_Tag_Finalize, resp. Hash_Verify (Rule MR18). -
Every message passes through Enc_Last_Block or Dec_Last_Block, with
last_block_lenzero if its last block is a full block, processed in Encrypt or Decrypt.These States are left by their
kl.execor, withlast_block_lenzero, by a Form Akl.setstto Enc_Tag_Finalize, resp. Hash_Verify (see below). Any otherkl.setst, except one naming Ready (Rule GR19.3), transitions the locker to Error State Invalid. -
Gated States: those that Rule MR1 lists for encryption and decryption.
-
-
Behavior:
-
Upon entering State Ready:
-
The following initialization operations are performed:
-
N ← zeros(120). -
N_len ← 0. -
HasNis cleared. -
hash_A ← zeros(128). -
checksum_P ← zeros(128). -
index ← 0. -
last_block_len ← 0. -
tag_len ← 128.
-
-
-
When entering State Set_Aux_Value:
-
A Form B
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandXsis expected, whereXsmust satisfy6≤Xs≤120; any otherXstransitions the locker to Error State Invalid. Every bit length in that range is admissible (Rule MR11): the nonce is a bit string and need not fill whole bytes. -
N_len ← XsandN ← zeros(120), andHasNis cleared.
-
-
-
|
cite:[RFC7253] itself places no lower bound on the nonce length. KLE requires at least 6 bits
because a shorter nonce leaves the |
-
While in State Set_Aux_Value, a Form B
kl.exec, which processes a single block (Rule MR13), loadsNfromINPUT[8q-1:0], withq= ⌈N_len/8⌉; the other bits ofINPUTare ignored (Rule MR8):-
N ← zeros(120 - 8q) @ INPUT[8q-1:0], with the(8 - N_len) mod 8least significant bits of byteq-1cleared: they pad the final, partial byte of the nonce string, are not part of the nonce, and are ignored. -
HasNis set.
A repeated
kl.execrewritesN.A
kl.setstnaming Set_Aux_Value in this State restarts the load (Rule GR19.2): it performs the operations of entering the State with its newXs. -
-
When entering State Hash_Absorb, which requires
HasN(Rule MR1):-
A Form B
kl.setstwith immediatekl_state_hash_absorband auxiliary operandXsis expected, whereXsmust be 64, 96 or 128; any otherXstransitions the locker to Error State Invalid. -
index ← 1andtag_len ← Xs. -
offset ← zeros(b)– this isOffset0in the RFC. -
L* ← enc_blk(key, zeros(b))– this isL*in the RFC. -
L$ ← double(L*),L[0] ← double(L$), andL[i] ← double(L[i-1])for alliwith0 < i≤ 48, possibly lazily.
-
-
In State Hash_Absorb, (multi-block)
kl.execinstructions are expected to be of Form B, absorbing a data blockINPUTintohash_A:-
next_offset(). -
hash_A ← hash_A xor enc_blk(key, INPUT xor offset).
-
-
When entering State Hash_Absorb_Last_Block, a Form B
kl.setstwith immediatekl_state_hash_last_blockinvokesFINAL_BLOCK_ENTRY(0, 120, 8)(FINAL_BLOCK_ENTRY(lo, hi, unit)), which setslast_block_len, the bit length of the final block of the AD. An empty final block needs nokl.exec: the message continues with thekl.setstinto Encrypt or Decrypt. -
In State Hash_Absorb_Last_Block, a single Form B
kl.execabsorbs the last block of the AD intohash_A:-
last_offset(). -
hash_A ← hash_A xor enc_blk(key, pad10(INPUT, last_block_len) xor offset).
-
-
On entering State Encrypt or Decrypt, the Machine computes the nonce-dependent variables of cite:[RFC7253] §4.2:
-
local Nonce_be : bits(128)– this isNoncein the RFC, in the big-endian view. -
local Ktop, Ktop_be : bits(128) -
local Stretch_be : bits(192)– this isStretchin the RFC, in the big-endian view. -
local bottom : int
-
Nonce_be ← bin(tag_len mod 128, 7) @ zeros(120 - N_len) @ 1 @ nonce_be(N, N_len). -
bottom ← int(Nonce_be[5:0]). -
Ktop ← enc_blk(key, bswap(Nonce_be[127:6] @ zeros(6))). -
Ktop_be ← bswap(Ktop). -
Stretch_be ← Ktop_be @ (Ktop_be[127:64] xor Ktop_be[119:56]). -
index ← 1. -
offset ← bswap(Stretch_be[191-bottom : 64-bottom]).
-
-
In State Encrypt, (multi-block)
kl.execinstructions are expected to be of Form A, absorbing the plaintextINPUTintochecksum_Pand encrypting it intoOUTPUT:-
next_offset(). -
checksum_P ← checksum_P xor INPUT. -
OUTPUT ← offset xor enc_blk(key, INPUT xor offset).
-
-
In State Decrypt, (multi-block)
kl.execinstructions are expected to be of Form A, decryptingINPUTintoOUTPUTand absorbing the plaintextOUTPUTintochecksum_P:-
local tmp : bits(b)
-
next_offset(). -
tmp ← offset xor dec_blk(key, INPUT xor offset). -
checksum_P ← checksum_P xor tmp. -
OUTPUT ← tmp.
-
-
When entering State Enc_Last_Block, resp. Dec_Last_Block, a Form B
kl.setstwith immediatekl_state_enc_last_block, resp.kl_state_dec_last_block, invokesFINAL_BLOCK_ENTRY(0, 120, 8)(FINAL_BLOCK_ENTRY(lo, hi, unit)), which setslast_block_len, the bit length of the final block of the plaintext, resp. ciphertext. These States are the exception to item 2 of Rule MR10: withXs= 0, thekl.setstneither processes the final block nor enters the successor, which the Form Dkl.execor the Form Akl.setstbelow enters. -
In State Enc_Last_Block or Dec_Last_Block, if
last_block_lenis nonzero, a single Form Akl.execis expected, which performs the following, whereP, the final block of the plaintext, isINPUTin Enc_Last_Block and theOUTPUTof step 2 in Dec_Last_Block:-
last_offset(). -
OUTPUT ← trunc(INPUT, last_block_len) xor trunc(enc_blk(key, offset), last_block_len). // enc_blk(key, offset) is Pad in RFC 7253 -
ocb_tag(offset xor pad10(P, last_block_len)).
If
last_block_lenis zero, a single Form Dkl.execis expected instead, which performsocb_tag(offset).In both cases
last_block_len ← 0and the locker then transitions to Enc_Tag_Finalize, resp. Hash_Verify.With
last_block_lenzero, a Form Akl.setstwith immediatekl_state_enc_tag_finalize, resp.kl_state_hash_verify, is also admitted: on entering Enc_Tag_Finalize, resp. Hash_Verify, it performs the operation of the Form Dkl.exec, so that both routes leave the samechecksum_P. Withlast_block_lennonzero, thatkl.setsttransitions the locker to Error State Invalid. -
-
In State Enc_Tag_Finalize, a single Form C
kl.execis expected. It performsOUTPUT ← trunc(checksum_P, tag_len), and the locker transitions to Success. AKLLENsmaller thantag_lenviolates the granularity of the State (Rule MR6). -
In State Hash_Verify, a single Form B
kl.execcompletes decryption:VERIFY_TAG(checksum_P)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)) compares thetag_lenleast significant bits ofINPUTwith those ofchecksum_P, with thetag_lenset on entering Hash_Absorb.
Code examples: OCB Mode.
OCB with Preset Nonce
The mode of operation “OCB with Preset Nonce” is a variant of OCB (OCB Mode) in which the nonce is
carried in the Provisioning Input, as the IV is in GCM with Preset IV.
This Machine is PRESET(OCB, N) (PRESET(parent, field)), with N_len preset together with N, and is otherwise the same as OCB, its Parameters and Machine-Specific Functions included, except as follows.
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field Description ii
kor 64keyKey value or System Key Identifier
iii
120
NThe nonce, in the format of the
INPUTof the Set_Aux_Valuekl.execof OCB Mode.iv
7
N_lenThe bit length of the nonce.
v
1
Padding
vi
0 or 64
Padding
-
Internal State:
-
Serialized Content:
Same as for OCB.
-
- State Machine
-
-
States and Allowed Transitions:
Same as for OCB, with the following exceptions:
-
There is no State Set_Aux_Value. The transition is from Ready to Hash_Absorb.
-
-
State Machine Behavior:
The differences with respect to OCB are:
-
The Form B
kl.setstthat setstag_lenand transitions to State Hash_Absorb is issued in State Ready. -
This Machine does not use
HasN: bit 0 of StateExtension stays 0. Entering State Hash_Absorb requires noHasN: every provisioning and import suppliesNandN_len. -
Entering State Ready clears neither
NnorN_len, which keeps the nonce (PRESET(parent, field)).
-
-
|
The rationale of |
CMAC Functions
CMAC is a message authentication code built on a block cipher. Tetsu Iwata and Kaoru Kurosawa designed it, and it became a NIST Recommendation in May 2005 cite:[nist-SP-800-38B].
- Parameters
-
-
b= 64 or 128, the block size of the underlying block cipher (cite:[nist-SP-800-38B] §5.2). -
k= key size (ka multiple of 8). -
Granularity:
b.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
kor 64keyor System Key Identifieriii
padPadding: (−
kf) mod 128. -
Internal State:
-
key:kbits. -
hash:bbits. -
last_block_len: an integer in the range 0 tob, serialized on 32 bits. -
tag_len: the number of bits that Hash_Verify compares, an integer in the range 64 tob, or 0 before it is set; serialized on 32 bits. -
tag_len_p: the length of every MAC that the locker outputs, and the number of bits that every verification compares (Rule MR12): a multiple of 8 from 64 tob, andbif KeyType = 1; held in AuxInfo, not serialized. -
absorbed_any: a boolean, set once a block has been absorbed in Hash_Absorb. -
absorbed_all: a boolean, set once the last block has been absorbed.
-
-
MDH: MachinePolicy: bit 0 permits generating a CMAC (Hash_Output), and bit 1 verifying one (Hash_Verify); at least one bit must be set (Validity of Metadata).
-
Serialized Content:
Pos. Size (Bits) Field i
kor 64keyor System Key Identifierii
bhashiii
32
last_block_leniv
32
tag_lenv
1 (boolean)
absorbed_anyvi
1 (boolean)
absorbed_allvii
padPadding: (−(
kf+b+ 66)) mod 128.
-
- Machine-Specific Functions
-
-
double(S)=bswap(dbl(bswap(S))), the doubling of cite:[nist-SP-800-38B] §6.1, where-
dbl(V)=V << 1ifV[b-1]= 0, else(V << 1) xor (zeros(b-8) @ Rb), with
Rbthe constant of §5.3:R128=0b10000111(x128 + x7 + x2 + x + 1) forb= 128, and
R64=0b00011011(x64 + x4 + x3 + x + 1) forb= 64. -
For every block cipher with
b= 128, SM4 included,dblis theupdate_maskofAES128_XEX(XEX/XTS Modes), anddoubleis the OCB3 doubling of OCB Mode.
-
-
gen_subkeys(K) → (K1,K2)generates subkeysK1andK2fromKas cite:[nist-SP-800-38B] §6.1 does:-
L ← enc_blk(K, zeros(b)) -
K1 ← double(L) -
K2 ← double(K1) -
return
(K1, K2).
-
-
- State Machine
-
-
States:
-
Ready: The CC is ready.
-
Hash_Absorb: Absorb data into the CMAC function.
-
Hash_Absorb_Last_Block: Set the length of the last block to absorb, then absorb it.
-
Hash_Output: Output the CMAC.
-
Hash_Verify: Compare the CMAC with a value supplied by software, without disclosing it.
-
Success: The CC has completed the CMAC operation.
-
Failure: A CMAC verification has failed.
-
-
Allowed State Transitions:
-
Ready → Hash_Absorb → Hash_Absorb_Last_Block → Hash_Output → Success.
-
Hash_Absorb_Last_Block → Hash_Verify → Success or Failure.
-
From any valid state to State Ready (Rule GR19.3).
-
-
Behavior:
-
Entering State Ready:
-
last_block_len ← 0 -
tag_len ← 0 -
hash ← zeros(b) -
absorbed_any ← false -
absorbed_all ← false
-
-
In State Hash_Absorb, a Form B
kl.exec, which may span several blocks, absorbs eachb-bit blockPofINPUTin turn (Rule MR13):-
hash ← enc_blk(key, hash xor P). -
absorbed_any ← true.
-
-
When entering State Hash_Absorb_Last_Block, a Form B
kl.setstwith immediatekl_state_hash_last_blockinvokesFINAL_BLOCK_ENTRY(0, b, 8)(FINAL_BLOCK_ENTRY(lo, hi, unit)), which setslast_block_len, the bit length of the last block, with these changes:-
Xs= 0 denotes the empty message: withabsorbed_any=true, it transitions the locker to Error State Invalid. -
If
Xs= 0, the empty final block is absorbed at once, without akl.exec(Rule MR10):-
(K1, K2) ← gen_subkeys(key), -
hash ← enc_blk(key, hash xor pad10(zeros(b), 0) xor K2), and -
absorbed_all ← true.
-
-
The
kl.execleaveslast_block_lenunchanged:absorbed_allrecords that the last block is absorbed.
-
-
In State Hash_Absorb_Last_Block, a single Form B
kl.execabsorbs the last block:-
(K1, K2) ← gen_subkeys(key). -
if
last_block_len=b, then:-
tmp ← hash xor INPUT[b-1:0] xor K1
-
-
else, that is if
0<last_block_len<b:-
tmp ← hash xor pad10(INPUT, last_block_len) xor K2
-
-
hash ← enc_blk(key, tmp) -
absorbed_all ← true
A
kl.execwithabsorbed_all=truetransitions the locker to Error State Invalid. -
-
A
kl.setstwith immediatekl_state_hash_outputenters State Hash_Output; withabsorbed_all=false, it transitions the locker to Error State Invalid instead. -
In State Hash_Output, a single Form C
kl.exec, which processes a single block (Rule MR13), outputs the CMAC:-
OUTPUT ← trunc(hash, tag_len_p), the firsttag_len_p/8 bytes ofhashand the truncated tag of cite:[nist-SP-800-38B] §6.2 whentag_len_p<b; aKLLENsmaller thantag_len_pviolates the granularity of the State, and a larger one receives the MAC with the bits beyondtag_len_pcleared (Rule MR12). -
The CC transitions to State Success.
-
-
State Hash_Output, as a
kl.derivesource (Derivation Endpoints of the Machines), supplies theb/8 bytes ofhash. -
A Form B
kl.setstwith immediatekl_state_hash_verifyand auxiliary operandXsenters State Hash_Verify by invokingSET_TAG_LEN(b, 64)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)), which setstag_len ← min(Xs, b)and requires it to equaltag_len_p. Withabsorbed_all=false, thekl.setsttransitions the locker to Error State Invalid. -
In State Hash_Verify, a single Form B
kl.execverifies the tag by invokingVERIFY_TAG(hash)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)), which comparesINPUT[tag_len-1:0]withhash[tag_len-1:0], the firsttag_len/8 bytes of the CMAC, MSBTlen of cite:[nist-SP-800-38B] §6.2.
-
-
Code examples: CMAC Functions.
Hash and MAC Functions, and XOFs
This section defines an interface for hash functions, MAC functions and XOFs. No interface fits every construction, but the one defined here covers the most common, such as SHA-2 cite:[nist-fips-180-4], SHA-3, and SHAKE cite:[nist-fips-202].
Every Machine that instantiates it pads the message as its referenced standard prescribes:
the caller supplies the message alone, and the kl.setst that ends the message completes the
padding and applies any length encoding of that standard.
One instruction sequence serves all of them (Hash Functions, MACs and XOFs).
It is highly recommended that a new Machine for a hash function, MAC function or XOF work with the same instruction sequence, unless a reason prevents it.
- Parameters
-
-
b= block size (ba multiple of 8): the size of an absorbed block, which may differ from the size of the internal state. For a sponge function,bis the rate. -
t= output block length (ta multiple of 8): the size of the digest, or of each block that the output stage emits between twoupdate(). This description assumest≤b. -
d= digest length (da multiple of 8) of a fixed-output Machine:t, unless the Machine states otherwise, as Ascon-Hash256 does. An XOF has nod. -
n= size of the internal state kept by the function (na multiple of 8). For a sponge function,n-bis the capacity of the function. -
k= key size (ka multiple of 8). Present only if keyed, i.e., a MAC. -
state_offset= offset into the state at which the block is absorbed. -
tag_offset= offset of the tag into the state, 0 unless the Machine states otherwise. A Machine must satisfystate_offset≤tag_offsetandtag_offset+t≤state_offset+bfor a sponge, so that every output bit comes from the rate, andtag_offset+t≤notherwise. -
g= granularity: 8 bits in Hash_Absorb and Hash_Output, for every instantiation; a State that loads a field, such as Set_Key of HMAC, uses it too unless the Machine states otherwise.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
If keyed:
kor 64keyor System Key IdentifierIf unkeyed: 0
none: the Provisioning Input is the MDH only
iii
padPadding: (−
kf) mod 128 if keyed, 0 if unkeyed. -
MDH: MachinePolicy: unless the instantiating Machine states otherwise, no State is gated by MachinePolicy (Rule MR1), and a non-zero value is unsupported Metadata (Validity of Metadata).
-
Internal State:
-
key:kbits. Present only if keyed, i.e., a MAC. -
state:nbits. -
last_block_len: int. Bit length of the final piece to be absorbed in Hash_Absorb_Last_Block. In Hash_Output_Bits, after the message has ended, the field is calledread_len: the number of bits still to be read before the nextkl.setst. -
input_base/output_base(same field): int. Offset within the input or output at which to read or write. -
block_base: int. Length of the data absorbed so far into the current block or, in Hash_Output and Hash_Output_Bits, emitted so far from the currentt-bit output block. -
out_len: int. In Hash_Output and Hash_Output_Bits, the number of output bits still to be emitted, or 0 for an XOF without bound; zero in every other State. -
cumul_len: int. Cumulative length of the data absorbed so far. -
block:bbits. Present only if a partial block is kept separately, for instance when inputs are not absorbed directly intostate. -
Sealed: Boolean, bit 1 of StateExtension, set when a sealed source (Rule GR31.3) enters the message input, and cleared only on entering Ready. A StateExtension @ State withSealedset in a State other than Hash_Absorb, Hash_Absorb_Last_Block, Hash_Output and Success is not supported by the Machine: an SCC that carries it is invalid Metadata (Validity of Metadata).
-
-
Serialized Content:
Pos. Size (Bits) Field Notes i
If keyed:
kor 64keyor SKID—
If unkeyed: 0
none
—
ii
nstate—
iii
16
last_block_lenThe bit length of the final piece still to be absorbed, 0 once the message ends; in Hash_Output_Bits,
read_len.iv
16
block_baseAmount of data, in bits, stored so far into
blockor accumulated (usually XORed) intostate; in Hash_Output and Hash_Output_Bits, the amount emitted from the current output block.v, vi
32
out_lenUnless the Machine uses these bits otherwise, as BLAKE2 Specific Rules does.
vii
64
cumul_lenCumulative length of the data absorbed so far; its width limits the length of a message (Rule MR15). Present only if the padding or another function of the Machine uses it, or under HMAC (HMAC).
viii
bblockOnly if the block is stored separately from the
state.ix
padPadding
Zero; (−(
kf+n+ 64 +c'+b')) mod 128 bits, wherekfis 0 if unkeyed,c'is 64 ifcumul_lenis present and 0 otherwise, andb'isbifblockis present and 0 otherwise.input_base/output_baseis not serialized: it is set to 8 ×klstartat the start of everykl.exec.
-
- Machine-Specific Functions
-
-
process_block(): Processblockinto the hash or MAC. -
finalize(): Apply to the absorbed message the padding, and any length encoding or final-block processing, of the referenced standard, and processstate, in place, so that it holds the digest, or the firsttbits of output, attag_offset. -
update(): Updatestateduring the output stage. A fixed-output Machine withd≤tneeds none: its output loop enters Success and returns before it reachesupdate().
-
- State Machine
-
-
States: Ready, Hash_Absorb, Hash_Absorb_Last_Block, Hash_Output, Hash_Output_Bits and Success.
-
Ready: The CC is ready.
-
Hash_Absorb: Absorb the message into the hash function.
-
Hash_Absorb_Last_Block: Set the bit length of the final piece of the message, then absorb it.
-
Hash_Output: Output the hash.
-
Hash_Output_Bits: Output the hash a set number of bits at a time.
-
Success: The CC has completed the operation (an XOF reaches it only with a bounded output).
-
-
Allowed State Transitions:
-
Ready → Hash_Absorb → { Hash_Absorb_Last_Block → } Hash_Output → Success.
-
Hash_Absorb, or Hash_Absorb_Last_Block with
last_block_len= 0, → Hash_Output_Bits; Hash_Output → Hash_Output_Bits → Success; and Hash_Output_Bits → Hash_Output_Bits. -
The Machine makes no transition into Hash_Output, Hash_Output_Bits, or the Hash_Verify of a MAC, by itself: a
kl.setstnaming it from Hash_Absorb or Hash_Absorb_Last_Block ends the message. -
From any valid state to State Ready (Rule GR19.3).
-
-
Behavior:
-
Upon entering State Ready:
-
last_block_len,block_base,cumul_len,out_lenandblockare set to zero, andSealedis cleared. -
state: the initial value is set as specified by the Machine.
-
-
The
kl.setstthat enters Hash_Absorb setslast_block_len←b(Macro: Processing Variable Length Inputs into a Fixed Length Output). -
State Hash_Absorb invokes macro
PROCESS_VLI(Macro: Processing Variable Length Inputs into a Fixed Length Output) as:PROCESS_VLI(0, block, b, state, n, input_base, block_base,
state_offset, cumul_len, process_block(), None, mode, 8,
Hash_Absorb_Last_Block, None, last_block_len),where:
-
state_offsetis Machine-defined; -
cumul_lenisNonewhere neither the Machine nor HMAC uses it; -
finalize()isNonein this invocation: it is performed once, by thekl.setstthat ends the message; -
modeis:-
assignfor a construction that fills a separateblockand then processes it intostatethroughprocess_block(), and -
xor_accumulatefor one that absorbs the input directly intostate, as a sponge does; each instantiation states which it uses.
-
A
kl.execabsorbs any whole number of bytes. Its interruption points are those of Macro: Processing Variable Length Inputs into a Fixed Length Output: 0 and, if the locker holdsblock_base= 0 when it is issued, every byte offset. -
-
State Hash_Absorb_Last_Block, entered from Hash_Absorb:
-
A Form B
kl.setstwith immediatekl_state_hash_last_blockand auxiliary operandXs,Xs= 0 for Form A, setslast_block_len ← Xs(Macro: Processing Variable Length Inputs into a Fixed Length Output).Xsmust satisfy:-
0 ≤
Xs≤b; -
Xsis a multiple of 8, unless the Machine admits other bit lengths as Rule MR11 permits.
-
-
Any other
Xstransitions the locker to Error State Invalid. -
If
last_block_len= 0, nothing more happens: the final piece is empty, and the message is what Hash_Absorb absorbed. Nokl.execis needed; anykl.exectransitions the locker to Error State Invalid (Rules MR10 and GR13.5). -
If
last_block_len≠ 0, a single Form Bkl.execabsorbs the final piece as Macro: Processing Variable Length Inputs into a Fixed Length Output specifies forlast_block_state:-
unless the Machine states otherwise, the piece is the
last_block_lenleast significant bits ofINPUT; -
its only interruption point is 0 (Rule MR13).
-
-
-
From Hash_Absorb, or from Hash_Absorb_Last_Block with
last_block_len= 0, thekl.setstnaming Hash_Output ends the message:-
Issued from Hash_Absorb, it gives the result of an empty final piece followed by the same
kl.setst. -
It is of Form A or of Form B, unless the Machine requires Form A.
-
A non-zero auxiliary operand
Xsis the output length in bits, and must:-
be at most
dfor a fixed-output Machine, and below 232 for an XOF; -
be a multiple of 8, unless the Machine states otherwise, as KMAC128, KMAC256, KMACXOF128, and KMACXOF256 does for KMAC128 and KMAC256;
-
be at least the minimum that a MAC may set, as HMAC does with 64 bits and KMAC128, KMAC256, KMACXOF128, and KMACXOF256 with 32 bits for KMAC128 and KMAC256.
-
Any other non-zero
Xstransitions the locker to Error State Invalid, beforefinalize().In Hash_Absorb_Last_Block,
last_block_len≠ 0 means that the final piece is not yet absorbed: akl.setstnaming Hash_Output, Hash_Output_Bits, or the Hash_Verify of a MAC, then transitions the locker to Error State Invalid. -
-
In State Hash_Output:
-
Upon entering the state, the following operations are first performed:
-
finalize() -
block_base ← 0andlast_block_len ← 0 -
out_len ← Xsfor a Form Bkl.setstwithXs≠ 0; otherwiseout_len ← dfor a fixed-output Machine, andout_len ← 0for an XOF.
-
-
For each Form C
kl.execinstruction, the following operations are performed:-
local amount : int,amount of data to copy fromstatetoOUTPUT
-
output_base ← 8 × klstart// 0 when the instruction starts -
while (
output_base<KLLEN) do:-
amount ← min(KLLEN - output_base, t - block_base), and, ifout_len≠ 0,amount ← min(amount, out_len) -
OUTPUT[output_base + amount - 1 : output_base] ←
state[tag_offset + block_base + amount - 1 : tag_offset + block_base] -
output_base ← output_base + amount -
block_base ← block_base + amount -
if
out_len≠ 0 then:-
out_len ← out_len - amount -
if
out_len= 0, any bits ofOUTPUTbeyondoutput_baseare cleared, the locker transitions to Success, and the instruction returns.
-
-
if (
block_base=t) then:-
update() -
block_base ← 0 -
Here, and only here, the instruction can be interrupted while
output_base<KLLEN, withklstart ← output_base / 8. A halt here leavesblock_base= 0.
-
-
The output has as many bits as
out_lenholds on entering the State, or is unbounded for an XOF without bound, and is emitted in any whole number of bytes.The interruption points of
kl.execin Hash_Output (Rule GR33.2) are 0 and, if the locker holdsblock_base= 0 when thekl.execis issued, any byte offset, whateverout_len. -
-
-
In State Hash_Output_Bits:
-
A Form B
kl.setstwith immediatekl_state_hash_output_bitsand auxiliary operandXs, issued in Hash_Output or Hash_Output_Bits, enters or stays in the State and setsread_len ← Xs. It performs nofinalize(), keepsblock_baseandout_len, and discards any bits that an earlierread_lenleft unread. Issued from Hash_Absorb, or from Hash_Absorb_Last_Block withlast_block_len= 0, it ends the message: it gives the result of a Form Akl.setstnaming Hash_Output followed by the samekl.setst. The output is then that of a Form A entry, unbounded for an XOF, and a Machine that requires Form B into Hash_Output, as KMAC128, KMAC256, KMACXOF128, and KMACXOF256 does for KMAC128 and KMAC256, transitions the locker to Error State Invalid. A Form Akl.setst,Xs= 0, orXs≥ 216 transitions the locker to Error State Invalid. -
Each Form C
kl.execruns the loop of Hash_Output with these changes:-
amountis also at mostread_len, andread_len ← read_len - amountfollowsblock_base ← block_base + amount; -
after the
block_base=tstep, ifread_len= 0, any bits ofOUTPUTbeyondoutput_baseare cleared, and the instruction returns, the locker staying in Hash_Output_Bits; -
the instruction can be interrupted wherever
output_baseis a multiple of 8 and less thanKLLENandread_len≠ 0, inside a block too, and nowhere else, withklstart ← output_base / 8.A Form C
kl.execissued withread_len= 0 transitions the locker to Error State Invalid. The interruption points ofkl.execin Hash_Output_Bits are 0 and any byte offset, whateverblock_base. As akl.derivesource (Derivation Endpoints of the Machines), the locker supplies the output that followsblock_base, as in Hash_Output, and keepsread_len.
-
-
-
A sealed locker, one with
Sealedset or, in HMAC,KeySealed, admits nokl.execin Hash_Output and nokl.setstnaming Hash_Output_Bits or Hash_Verify: each transitions it to Error State Invalid. Its output in Hash_Output is a sealed source (Rule GR31.3).
-
-
The following are Machine-specific, and the code example of Hashing a Message uses none of them:
-
the parameters
nnandkkof BLAKE2 Specific Rules, set by an operation in Ready; -
the customization string of Ascon-CXOF128, absorbed in Set_Aux_Value;
-
the key of the NIK variant of HMAC, loaded in Set_Key;
-
the verification of a MAC in Hash_Verify (HMAC, KMAC128, KMAC256, KMACXOF128, and KMACXOF256).
SHA-2 Family Specific Rules
The primitives of the SHA-2 family cite:[nist-fips-180-4] (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256) are instantiations of the algorithm specified in Hash and MAC Functions, and XOFs, and only the differences from the behavior described there are given here.
- Parameters
-
-
The word size
w, andb,n, andt, as given in Table 3; the internal state consists of the eightw-bit chaining variables of cite:[nist-fips-180-4].
-
| Function | w |
b |
n |
t |
|---|---|---|---|---|
SHA-224 |
32 |
512 |
256 |
224 |
SHA-256 |
32 |
512 |
256 |
256 |
SHA-384 |
64 |
1024 |
512 |
384 |
SHA-512 |
64 |
1024 |
512 |
512 |
SHA-512/224 |
64 |
1024 |
512 |
224 |
SHA-512/256 |
64 |
1024 |
512 |
256 |
SM3 (SM3 Specific Rules) |
32 |
512 |
256 |
256 |
- Data Structures
-
-
Provisioning Input: the MDH only (Hash and MAC Functions, and XOFs, unkeyed).
-
Internal State:
-
state:nbits, holding the eight chaining variablesHibig-endian:state[(i+1)w-1 : iw]=bswap(bin(Hi, w)), for0≤i< 8. -
block(bbits). -
block_base,last_block_lenandout_len(Hash and MAC Functions, and XOFs). -
cumul_len, the number of message bits absorbed.
-
-
Serialized Content: as prescribed by Hash and MAC Functions, and XOFs, with
out_lenin Positions v and vi, andcumul_lenandblockpresent.
-
- Machine-Specific Functions
-
-
process_block(): applies the compression function of cite:[nist-fips-180-4] §6 for the selected function to absorb the currentblockintostate, message wordjbeingint(bswap(block[(j+1)w-1 : jw])), for0≤j< 16. -
finalize(): absorbs the rest of the padding of cite:[nist-fips-180-4] §5.1.1 and §5.1.2 for a message of ℓ bits, by steps 3.a to 3.e and 3.g of Macro: Processing Variable Length Inputs into a Fixed Length Output, so thatcumul_lendoes not count it. This rest is the byte0x80ifcumul_lenis a multiple of 8 (otherwise the final piece carries the bit 1 already), then zero bytes untilblock_base=b− 2`w`, thenbswap(bin(ℓ, 2w)). ℓ iscumul_len, or, under HMAC, the length that HMAC states.
-
- State Machine
-
-
States and Allowed State Transitions: those of Hash and MAC Functions, and XOFs.
-
Behavior:
-
Upon entering State Ready,
stateis set to the initial hash value of the selected function per cite:[nist-fips-180-4] §5.3. -
In State Hash_Absorb,
PROCESS_VLIis invoked as in Hash and MAC Functions, and XOFs, withmode=assign,state_offset= 0 andcumul_lentracked.modeisassignbecause the SHA-2 family fills a separateblockand compresses it intostate. -
In State Hash_Absorb_Last_Block:
-
The final piece is the ⌈
last_block_len/8⌉ least significant bytes ofINPUT; the other bits ofINPUTare ignored. -
Let
q=last_block_lenmod 8. Ifq≠ 0:-
the last of these bytes carries the final
qbits of the piece in itsqmost significant positions, since cite:[nist-fips-180-4] orders the bits of a byte from the most significant (Rule MR11, second bullet); -
the Machine replaces the other 8 −
qbits of that byte by the bit 1 that starts the padding, followed by zeros.
-
-
The
kl.execoflast_block_state(Macro: Processing Variable Length Inputs into a Fixed Length Output) absorbs these bytes: its step 3, with all sub-steps, uses 8 × ⌈last_block_len/8⌉ in place oflast_block_len. -
In place of the increments of step 3.f of the
kl.execin Current_State,cumul_lenadvances once bylast_block_lenitself, before step 5 clearslast_block_len.
-
-
In State Hash_Output, the bytes emitted are the chaining variables in the big-endian encoding, truncated to the number of bits that
out_lenholds on entering the State (Hash and MAC Functions, and XOFs).
-
-
SM3 Specific Rules
The ShangMi 3 hash function, standardized as GB/T 32905-2016 cite:[GBT-32905-2016], follows the rules of SHA-256 (SHA-2 Family Specific Rules), with the parameters of row SM3 of Table 3, except that its initial hash value and compression function are those of the SM3 standard.
BLAKE2 Specific Rules
BLAKE2b and BLAKE2s cite:[RFC7693], unkeyed or keyed, instantiate Hash and MAC Functions, and XOFs; only the
differences are given here.
nn and kk are the digest and key lengths in bytes.
- Parameters
-
-
w,r(the rounds ofF),b,n,nnmax,kkmaxand the rotation constants ofG, as in Table 4;t= 8 ×nn.
-
| Function | w |
r |
b |
n |
nnmax |
kkmax |
(R1, R2, R3, R4) |
|---|---|---|---|---|---|---|---|
BLAKE2b |
64 |
12 |
1024 |
512 |
64 |
64 |
(32, 24, 16, 63) |
BLAKE2s |
32 |
10 |
512 |
256 |
32 |
32 |
(16, 12, 8, 7) |
- Data Structures
-
-
Provisioning Input: the MDH only, or, with a system key (KeyType = 1):
Pos. Size (Bits) Field ii
64
System Key Identifier
iii
64
Padding
kkis the length of the key that the SKS returns; a length outside 1 tokkmaxtransitions the locker to Error State Invalid (System Keys). When an import resolves the SKID again, a key whose length differs from the restoredkktransitions the locker to Error State Invalid. KeyType = 2 is invalid: the Machine holds no key by value. A caller with its own key absorbs it (see below). -
MDH: MachinePolicy: without a system key, as in Hash and MAC Functions, and XOFs. With a system key, the Machine is a MAC that only generates tags: bit 0 enables Hash_Output (Rule MR1); MachinePolicy = 0 is invalid Metadata, and any set bit other than bit 0 is unsupported Metadata (Validity of Metadata).
-
Internal State:
-
nn, with 1 ≤nn≤nnmax, andkk, withkk≤kkmax; an import that writes a value outside these ranges transitions the locker to Error State Invalid (Rule MR3). -
state: the wordshiof cite:[RFC7693], little-endian:state[(i+1)w-1 : iw]=bin(hi, w), for0≤i< 8. -
block,block_base,last_block_len,out_len, andcumul_len, which also counts a key block, so thatcumul_len/8 is the counter of cite:[RFC7693] §3.2. -
syskey: with a system key, the key that the SKID resolves to, zero-padded tobbits. It is not serialized: the SKID in Position i of the Serialized Content stands for it (Rule GR55.1).
-
-
Serialized Content: as in Hash and MAC Functions, and XOFs, with
cumul_lenandblockpresent, and:-
the SKID, if any, in Position i;
-
nnin Position v andkkin Position vi, 16 bits each,nnin the lower half; -
in Hash_Output and Hash_Output_Bits,
out_lenin the lower 32 bits of Position vii, the upper 32 bits zero, in place ofcumul_len, whichfinalize()has consumed.
-
-
- Machine-Specific Functions
-
-
F(f): the compression function of cite:[RFC7693] §3.2 onstate, with message wordsmj=int(block[(j+1)w-1 : jw]), the countercumul_len/8, and the final-block flagf. -
process_block():F(false). -
finalize()performs the first of the following that applies, then setsblock_base← 0:-
with
block_base> 0: zeroesblock[b-1 : block_base]and performsF(true); -
with
block_base= 0, which only an empty message leaves, and a system key:block←syskey,cumul_len←b,F(true)andblock←zeros(b); -
with
block_base= 0, no system key andkk= 0:F(true)on the zeroblock; -
with
block_base= 0, no system key andkk≠ 0: the locker transitions to Error State Invalid, since the caller’s key block is missing.
-
-
- State Machine
-
-
States: Ready, Hash_Absorb, Hash_Absorb_Last_Block, Hash_Output, Hash_Output_Bits, and Success.
-
Allowed State Transitions:
-
As in Hash and MAC Functions, and XOFs; the
kl.setstnaming Hash_Output ends the message held inblock, also the empty one. -
From any valid state to State Ready (Rule GR19.3).
-
-
Behavior, where it differs from Hash and MAC Functions, and XOFs:
-
At the completion of a provisioning, before the operations of entering Ready,
nn←nnmaxandkk← the length of the system key, or 0 without one. The completion of a system-specific import does the same for each of them that the converted Content does not configure (Rule GR51). Every other entry into Ready keepsnnandkk. -
When entering State Ready,
stateis the IV of cite:[RFC7693] §2.6, withh0XORed withbin(0x01010000 + kk × 256 + nn, w)(§2.5, §3.3). -
In State Ready, setting the parameters is an operation, not a State (Rule MR16):
-
a Form B
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandXssetsnn←Xs[7:0]and, without a system key,kk←Xs[15:8], and recomputesh0; -
Xsmust satisfy 1 ≤Xs[7:0]≤nnmaxandXs[15:8]≤kkmax, and its bits above bit 15 must be 0. With a system key,Xs[15:8]must be 0.
Any other
Xstransitions the locker to Error State Invalid. -
-
With a system key, the instruction that absorbs the first byte of the message compresses the key block before it absorbs that byte:
block←syskey,cumul_len←b,F(false), andblock←zeros(b). That instruction is akl.execor akl.derivein Hash_Absorb, or thekl.execof Hash_Absorb_Last_Block.cumul_len= 0 records that the key block is still pending; for the empty message,finalize()compresses it as the final block.syskeyis inblockonly between two steps of one instruction, which cannot halt between them, so no Serialized Content holds it (Rule GR55.1). -
A caller with its own key, and no system key:
-
sets
kkto the length of the key in bytes by the Set_Aux_Value operation; -
absorbs the key, zero-padded to
bbits, as the first block of the message (cite:[RFC7693] §3.3); -
for an empty message, absorbs nothing more, and
finalize()compresses the key block as the final block.
The Machine does not tell the key block from the message: it checks neither that kkmatches the length of the key nor that the key is padded with zeros, and a mismatch only yields a different hash. -
-
In State Hash_Absorb,
PROCESS_VLIis invoked withmax_len= 0,state_offset= 0 andmode=assign, with these differences:-
Step 3.g is postponed: a
blockfilled toblock_base=bis kept. -
The iteration of step 3 that absorbs the next byte of the message first compresses that
blockbyF(false)and setsblock_base← 0, before step 3.a, so that the countercumul_len/8 does not yet count that byte. -
With a system key, the key block is compressed first, as stated above.
-
The interruption points of
kl.execin Hash_Absorb are 0 and, if the locker holdsblock_base= 0 orblock_base=bwhen thekl.execis issued, any byte offset. A halt leaves the full block held, withblock_base=b, so that its resumption meets that condition.
-
-
Hash_Absorb_Last_Block follows Hash and MAC Functions, and XOFs, with
Xsa multiple of 8 (Rule MR11). In thekl.execoflast_block_state(Macro: Processing Variable Length Inputs into a Fixed Length Output), step 3.c is postponed in the same way:-
A full block, including one held from Hash_Absorb, is compressed by
F(false), withblock_base← 0, at the start of the loop iteration that absorbs the next byte of the final piece, before itsamountis computed. -
A final piece that fills its block is held for
finalize().
-
-
-
HMAC
Hash function Machines suffice to compute HMACs, but an environment may want to hide the HMAC key. This section extends Hash and MAC Functions, and XOFs accordingly.
finalize() of H pads as in H; for SHA-2 (SHA-2 Family Specific Rules) and SM3 (SM3 Specific Rules) it encodes ℓ = b + cumul_len bits for the inner hash and b + t bits for the outer, since absorb(K0 xor ipad) and absorb(K0 xor opad) are not counted in cumul_len.
- Parameters
-
-
H= the underlying hash function. -
b= the input block size ofH: its parameterb, which for SHA-3 is the rate (Table 5). -
t= the digest size: the parametertofH(Hash and MAC Functions, and XOFs). -
Granularity: same as that of the underlying hash function.
The two padding constants of cite:[nist-fips-198-1] are:
-
ipad= the byte0x36repeatedb/8 times, and -
opad= the byte0x5crepeatedb/8 times,
both
bbits long. All bytes of each constant are equal, so its representation does not depend on the byte order of Notation and Conventions. -
- Data Structures
-
-
Provisioning Input:
Each HMAC Machine has two variants, which the Machine field distinguishes (Table 1): by Type for the SHA-2 and SHA-3 HMACs, and by Mode for
SM3_HMAC.The PI of the “No Initial Key” (NIK) variant is the MDH alone.
The PI of the “Key In PI” (KIP) variant has the following format:
Pos. Size (Bits) Field ii
bor 64K0, the key already reduced tobbits (see below), or a System Key Identifier.iii
0 or 64
Padding
The key provisioned or held in a CC is the value
K0of cite:[nist-fips-198-1] §4, Steps 1 to 3: the keyKpadded with zeros tobbits, or, ifKis longer thanbbits,H(K)padded with zeros tobbits. Whoever provisions the key derivesK0from it. With KeyType = 1, the SKS returnsK, and the KLE unit formsK0from it by the same Steps. A system-specific import (Rule GR51) that configures theK0of a NIK CC forms it by the same Steps from the key that the format carries, and setsHasKey, as a completed load ofK0does (Rule MR4). -
Internal State:
-
hash_fn_state: the entire state ofH, with the following fields:-
state:nbits. -
last_block_len,out_len: int (Hash and MAC Functions, and XOFs). -
input_base: int. Offset within input/output to read from/write to. -
block_base: int. Length of the data absorbed so far into the current block or, in Hash_Output and Hash_Output_Bits, emitted so far from the currentt-bit output block (Hash and MAC Functions, and XOFs). -
cumul_len: int. Cumulative length of data absorbed so far, tracked by every HMAC Machine (for theK0load in Set_Key, and for the padding of SHA-2 and SM3). -
block:bbits. Included only if a partial block is maintained, for instance when the inputs are not directly absorbed intostate.
-
-
K0:bbits, the valueK0as per cite:[nist-fips-198-1] §4, Steps 1 to 3. -
tag_len: the number of bits that Hash_Verify compares, 64 tot, or 0 before it is set. -
tag_len_p: the number of bits that every verification compares (Rule MR12): a multiple of 8 from 64 tot, andtif KeyType = 1; held in AuxInfo, not serialized. -
HasKey(NIK variant only): Boolean, bit 0 of StateExtension, recording thatK0holds a completely loaded key (Rule MR14). -
KeySealed(NIK variant only): Boolean, bit 2 of StateExtension, set when a sealed source (Rule GR31.3) loadsK0, and cleared on entering Set_Key. A StateExtension @ State withKeySealedset andHasKeyclear, or set in Hash_Output_Bits, Hash_Verify or Failure, is not supported by the Machine: an SCC that carries it is invalid Metadata (Validity of Metadata). The KIP variant uses onlySealed(Hash and MAC Functions, and XOFs).
-
-
Serialized Content:
Pos. Size (Bits) Field i
variable
Serialized Content of the underlying hash function, in its entirety, including its Padding.
ii
bor 64K0, or a System Key Identifier.iii
16
tag_leniv
padPadding: (−(
b+ 16)) mod 128, or 48 with a System Key Identifier.If
His a SHA-3 function and KeyType = 1, thestateof position i is masked as in KMAC128, KMAC256, KMACXOF128, and KMACXOF256 (Rule GR55.1).
-
- State Machine
-
The NIK variant inserts State Set_Key between Ready and Hash_Absorb; both variants add States Hash_Verify and Failure.
The two variants differ only in how the key first reaches the CC.
In the KIP variant,
K0is carried in the Provisioning Input. The key is given by value (KeyType = 0), as an SKID (KeyType = 1), or asbrandom bits (KeyType = 2). A KIP CC cannot be re-keyed.In the NIK variant, the Provisioning Input carries no key.
K0must be loaded in State Set_Key before Hash_Absorb can be entered: entering Hash_Absorb requiresHasKey(Rule MR1), and leaving Set_Key before the load completes zeroesK0(Rule MR14). A loaded key is kept across a return to Ready, so that one load ofK0serves any number of messages.-
Allowed State Transitions:
-
For the NIK variant: Ready → Set_Key → Hash_Absorb, and Ready → Hash_Absorb once
K0is loaded (HasKey); then as in the underlying hash function. -
For the NIK variant: Set_Key → Set_Key, which restarts the load (see below).
-
For the KIP variant: Ready → Hash_Absorb; then as in the underlying hash function.
-
Hash_Absorb, or Hash_Absorb_Last_Block with
last_block_len= 0, → Hash_Verify → Success or Failure. -
From any valid state to State Ready (Rule GR19.3).
-
MachinePolicy[0] gates MAC generation, and MachinePolicy[1] MAC verification (Rule MR1).
-
-
Behavior:
-
When entering Ready:
tag_len← 0. -
State Set_Key is
LOAD_LONG_FIELD(b, K0, K0, b, None, None, assign, g)(LOAD_LONG_FIELD(len, block, state, n, process_block(), finalize(), mode, g)), withgthe granularity ofH: Form Bkl.execinstructions load theb-bitK0, and a completed load setsHasKey. Entering Set_Key, also by a same-Statekl.setst, which restarts the load, also clearsKeySealed. Akl.deriveintoK0(Derivation Endpoints of the Machines) transfers a whole keyKofeff_length≤b/8 bytes (Rule GR29 items 1 and 6):-
it requires
klstart= 0 and a source of exactlyeff_lengthbytes: a source field, or the remainingkl.execoutput of the source; -
otherwise, the destination locker transitions to Error State Invalid, and the source is unchanged; a keystream of a keystream Machine (CTR/XCTR Keystream Generation, OFB of Chaining/Feedback Modes (CBC, CFB, and OFB)), or the output of an XOF without bound, has no length of its own and never meets the requirement of the previous step, so its
kl.deriveintoK0always has this outcome; -
it replaces all of
K0, whatever akl.execloaded before it:K0←Kzero-filled tobbits (cite:[nist-fips-198-1] §4, Step 3); -
it sets
block_base← 0 andcumul_len←b, and setsHasKey, andKeySealedfor a sealed source.
-
-
When entering Hash_Absorb:
-
stateis set to the initial value of the underlying hash function. -
block,block_baseandcumul_lenare set to zero, andlast_block_len←b, as inH. -
absorb(K0 xor ipad), not counted incumul_len, whereabsorb(x)absorbsxas akl.execin Hash_Absorb ofHdoes. -
If
Hkeepsblockapart fromstate(SHA-2, SM3),block←zeros(b).K0 xor ipadis inblockonly between two steps of one instruction, so no Serialized Content holds it (Rule GR55.1).
-
-
While in Hash_Absorb and Hash_Absorb_Last_Block, the message is absorbed as in
H, including the length and the bit order of the final piece (Rule MR11). -
When entering State Hash_Output or Hash_Verify, the following steps replace the operations of
Hon entering Hash_Output:-
local
inner : bits(t)
-
finalize()ofH, which leaves the inner hashH((K0 xor ipad) ‖ message)instate[t+tag_offset-1 : tag_offset]. -
inner ← state[t+tag_offset-1 : tag_offset]. -
Reinitialize
stateto the initial value of the underlying hash functionH, and setblock,block_baseandcumul_lento zero. -
absorb(K0 xor opad)as perH, not counted incumul_len. -
absorb(inner)as perH, which leavescumul_len=t, so that the outer hash digests(K0 xor opad) ‖ H((K0 xor ipad) ‖ message), as cite:[nist-fips-198-1] §4 requires. -
finalize()ofH,block_base← 0 andlast_block_len← 0. Thet-bit HMAC value is then output in Hash_Output as byH, without_lenset as in Hash and MAC Functions, and XOFs, or verified in Hash_Verify.
A non-zero
Xsof a Form Bkl.setstinto Hash_Output is at least 64 (Hash and MAC Functions, and XOFs). -
-
To verify an HMAC where MachinePolicy[1] is set (Rule MR1):
-
the Form B
kl.setstthat enters State Hash_Verify invokesSET_TAG_LEN(t, 64)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)):tag_len←min(Xs, t), which must equaltag_len_p; -
in State Hash_Verify, the single Form B
kl.execinvokesVERIFY_TAG(state[tag_offset+t-1 : tag_offset])(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)): it comparesINPUT[tag_len-1:0]withstate[tag_offset+tag_len-1 : tag_offset], the firsttag_len/8 bytes of the HMAC.
-
-
-
SHA-3 Family Specific Rules
The SHA-3 family comprises SHA3-224, SHA3-256, SHA3-384 and SHA3-512, written SHA3-N, and the XOFs SHAKE128 and SHAKE256.
All are parameter choices of KECCAK cite:[DBLP-conf-eurocrypt-BertoniDPA13], standardized by NIST cite:[nist-fips-202].
They are instantiations of the Machine of Hash and MAC Functions, and XOFs; this section gives only the differences.
- Parameters
-
-
n= 1600. -
c= capacity,b= rate = 1600 -c, andt= the number of output bits taken fromstateper squeeze, all as given in Table 5.
-
| Function | c |
b = 1600 - c |
t |
XOF? | Suffix D |
|---|---|---|---|---|---|
SHA3-224 |
448 |
1152 |
224 |
no |
|
SHA3-256 |
512 |
1088 |
256 |
no |
|
SHA3-384 |
768 |
832 |
384 |
no |
|
SHA3-512 |
1024 |
576 |
512 |
no |
|
SHAKE128 |
256 |
1344 |
1344 |
yes |
|
SHAKE256 |
512 |
1088 |
1088 |
yes |
|
bin(2, 2) and bin(15, 4) are the suffixes that cite:[nist-fips-202] writes as 01 and 1111, first bit leftmost: for SHA3-N, D[0] = 0 and D[1] = 1.
For the four fixed-output functions, t is the digest length, which is c/2, and a
single squeeze suffices. For the two extendable-output functions, t is the full rate
b, since a sponge makes exactly b bits available between successive applications of
the permutation.
- Data Structures
-
-
Provisioning Input: the MDH only.
-
Internal State:
-
state:nbits. -
input_base: int. -
block_base: int. -
last_block_len: int. -
out_len: int (Hash and MAC Functions, and XOFs). -
cumul_len: int, under HMAC (HMAC) only.
-
-
Serialized Content:
Pos. Size (Bits) Field i
1600
stateii
16
block_base, in bitsiii
16
last_block_len, in bitsiv
32
out_len, in bitsv
64 or 0
cumul_len, under HMAC (HMAC) onlyvi
0, or 64 with
cumul_lenPadding
This layout replaces that of Hash and MAC Functions, and XOFs, in which
last_block_lenprecedesblock_base.
-
- Machine-Specific Functions
-
-
P(): computesKECCAK-p[1600, 24]onstate, with result in place. -
process_block(): there is no explicit operation to copy data intostate, since the inputs are XORed directly into it; instead,process_blockappliesP()to the state. -
update(): appliesP()to thestateduring the digest output stage.
-
- State Machine
-
-
States and Allowed State Transitions: those of Hash and MAC Functions, and XOFs.
-
Behavior:
-
Upon entering State Ready,
stateis zeroed. -
In State Hash_Absorb, the input data is XORed directly into
state:PROCESS_VLIis invoked as in Hash and MAC Functions, and XOFs, withblock=state,mode=xor_accumulate,state_offset= 0, andcumul_len=Noneexcept under HMAC. -
In State Hash_Absorb_Last_Block, a final piece of 0 to
bbits is absorbed (Hash and MAC Functions, and XOFs), so that the message may have any bit length. cite:[nist-fips-202] orders the bits within a byte as Notation and Conventions does, solast_block_lenneed not be a multiple of 8 (Rule MR11). -
Upon transitioning to State Hash_Output,
finalize():-
forms the bit string
Sof cite:[nist-fips-202] §5.1 and §B.2:-
S[|D|-1:0]holds the suffixDof Table 5, withD[0]inS[0]; -
pad10*1follows: a 1 inS[|D|], zeros, and a 1 inS[|S|-1]; -
|S|is the smallest length ≥|D|+ 2 that makesblock_base+|S|a multiple ofb;
-
-
XORs
S[b-block_base-1 : 0]intostate[b-1 : block_base], and appliesP(); -
if
|S|>b-block_base: XORsS[|S|-1 : b-block_base]intostate[b-1 : 0], and then appliesP(); -
leaves the output in the first
tbits of the rate.block_baseis less thanb, since it returns to 0 when it reachesb. Whenblock_baseis a multiple of 8,Sfits in the current block: it is the bytepad_byteatstate[block_base+7 : block_base], withpad_byte=0x06for SHA3-Nand0x1Ffor SHAKE128 and SHAKE256, XORed with the byte0x80atstate[b-1 : b-8]. Else, after a final piece whose length is not a multiple of 8,Sstarts within a byte, and a second block is needed only whenb-block_base<|D|+ 2.
-
-
In State Hash_Output, output is extracted as in Hash and MAC Functions, and XOFs:
-
SHA3-
N: a digest ofdbits, or ofXsbits after a non-zeroXs, at mosttin either case, after which the locker transitions to Success; -
SHAKE128 and SHAKE256: output of unbounded length, or of
Xsbits after a non-zeroXs, after which the locker transitions to Success.
-
-
-
The rest of the Machine follows Hash and MAC Functions, and XOFs.
KMAC128, KMAC256, KMACXOF128, and KMACXOF256
KMAC is the keyed MAC built on cSHAKE, standardized by NIST in cite:[nist-SP-800-185]. It is defined only over the KECCAK permutation of SHA-3, and this section gives only its differences from SHA-3 Family Specific Rules.
- Parameters
-
-
n= 1600. -
KMAC128 and KMACXOF128 use
c= 256 and rateb= 1344 bits (168 bytes); KMAC256 and KMACXOF256 usec= 512 and rateb= 1088 bits (136 bytes). -
t=b, as for the extendable-output functions of Table 5.
-
- Data Structures
-
A CC does not hold the key
Kand the customization stringSin their raw form. It holds the two rate-sized blocks that cite:[nist-SP-800-185] derives from them. Whoever provisions the CC prepares both, unless the KLE unit formskey_blockfrom a System Key or a randomK(see below):cshake_block=bytepad(encode_string("KMAC") ‖ encode_string(S), b/8), and
key_block=bytepad(encode_string(K), b/8),where
bytepad,encode_stringandleft_encodeare as defined in cite:[nist-SP-800-185] §2.3:Function rate b/8maximum | K|maximum | S|KMAC128/KMACXOF128
168 bytes
163 bytes
157 bytes
KMAC256/KMACXOF256
136 bytes
131 bytes
125 bytes
Only a
Kand anSwithin these maximums fit in one block each. The Machine does not check that acshake_blockorkey_blockcarried by value is well formed.cite:[nist-SP-800-185] admits a longer KorS, whichbytepadspreads over more than one block, and unlike the key of HMAC, no shorter value computes the same function.With KeyType = 1, the PI and the SCC carry a System Key Identifier in place of
key_block(Rule GR55.1). The SKS returns the keyK, and the KLE unit formskey_blockfrom it as above. AKlonger than the maximum in the table above transitions the locker to Error State Invalid (System Keys). With KeyType = 2 (KeyType Field),Kis a random value ofc/2 bits, from whichkey_blockis formed in the same way.cshake_blockis always carried by value. With KeyType = 1, thestatefield of the Serialized Content holdsstate xor state_maskin every State but Ready (Rule GR55.1); an import removes the mask after SKID resolution, when it converts the content into the internal format.-
Provisioning Input:
Pos. Size (Bits) Field ii
bcshake_blockiii
bor 64key_blockor System Key Identifieriv
0
Padding
-
Internal State: as for SHA-3 Family Specific Rules, with the addition of
cshake_blockandkey_block, and withLin place ofout_len:-
cshake_block,key_block:bbits each; and -
L: 32 bits, the output length or bound in bits, or 0 for an unbounded KMACXOF output; in Hash_Output and Hash_Output_Bits, the bits still to be emitted, asout_len(Hash and MAC Functions, and XOFs); from Hash_Verify on, the tag length in bits.
-
-
Serialized Content: as for SHA-3 Family Specific Rules, with
Lin Position iv in place ofout_len, andcshake_blockandkey_blockappended, followed by an empty Padding. Explicitly:Pos. Size (Bits) Field i
1600
stateii
16
block_baseiii
16
last_block_leniv
32
Lv
bcshake_blockvi
bor 64key_blockor System Key Identifiervii
0
Padding
-
- Machine-Specific Functions
-
-
P(),process_block()andupdate()are as in SHA-3 Family Specific Rules. -
right_encode(x), as in cite:[nist-SP-800-185] §2.3, is the valuexwritten as an unsigned big-endian integer on the smallest possible positive numbermof bytes, followed by a single byte holdingm.
-
- State Machine
-
-
States: Ready, Hash_Absorb, Hash_Absorb_Last_Block, Hash_Output, Hash_Output_Bits and Success, and, for
KMAC128andKMAC256only, Hash_Verify and Failure. -
Allowed State Transitions:
-
As in SHA-3 Family Specific Rules.
-
For
KMAC128andKMAC256: Hash_Absorb, or Hash_Absorb_Last_Block withlast_block_len= 0, → Hash_Verify → Success or Failure. -
For
KMAC128andKMAC256, MachinePolicy[0] gates MAC generation, and MachinePolicy[1] MAC verification (Rule MR1). -
KMACXOF128andKMACXOF256, which serve as key derivation functions, gate no State (Rule MR1), and a non-zero MachinePolicy is unsupported Metadata for them (Hash and MAC Functions, and XOFs); akl.derivemoves their output directly into a key (Derivation Endpoints of the Machines).
-
-
Behavior: as in SHA-3 Family Specific Rules, with the following differences.
-
When entering Ready:
L← 0. -
When leaving Ready for Hash_Absorb, the
kl.setstfirst:-
XORs
cshake_blockinto the rate and appliesP(); -
XORs
key_blockinto the rate and appliesP().The key enters stateonly within thatkl.setst, so that the Serialized Content of a CC in Ready is the same on every implementation and holds no key-dependentstate. In Ready,stateis zero, so masking it would outputstate_mask.
-
-
When entering Hash_Output or Hash_Verify from Hash_Absorb or Hash_Absorb_Last_Block, the
kl.setst:-
checks
Xsand setsLas follows; any otherXstransitions the locker to Error State Invalid:-
for
KMAC128andKMAC256, thekl.setstinto Hash_Output is of Form B, and setsL←Xs, the output length in bits, with 32 ≤Xs< 232, the lower bound being that of cite:[nist-SP-800-185] §8.4.2; -
for
KMACXOF128andKMACXOF256, thekl.setstinto Hash_Output is of Form A or of Form B: a non-zeroXs, a multiple of 8 below 232, setsL←Xs, the output bound in bits; a Form Akl.setst, orXs= 0, setsL← 0, for an unbounded output; -
for
KMAC128andKMAC256, where MachinePolicy[1] is set, thekl.setstinto Hash_Verify is of Form B, and setsL←Xs, the tag length in bits, withXsa multiple of 8 and 32 ≤Xs≤b, the lower bound being that of cite:[nist-SP-800-185] §8.4.2;
-
-
then performs
finalize(), which:-
XORs
right_encode(L), orright_encode(0)forKMACXOF128andKMACXOF256, intostatefrom bitblock_baseon, asPROCESS_VLIwithmode=xor_accumulateabsorbs data; the encoding directly follows the last bit of the message, even whenblock_baseis not a multiple of 8; -
then applies the padding of SHA-3 Family Specific Rules with
D=bin(0, 2), the suffix00of cSHAKE (pad_byte=0x04whenblock_baseis a multiple of 8), in place of thebin(15, 4)of SHAKE;
-
-
sets
block_base← 0 andlast_block_len← 0.
-
-
In State Hash_Output,
Lis theout_lenof Hash and MAC Functions, and XOFs, whose output loop applies, with these properties:-
for
KMAC128andKMAC256,Lneed not be a multiple of 8; -
with
L≠ 0 on entering Hash_Output, the output consists of ⌈L/8⌉ bytes, which may span severalt-bit blocks, and its last byte holds the finalLmod 8 bits, if any, in its least significant bits; -
with
L= 0,KMACXOF128andKMACXOF256squeeze arbitrarily many bits and never transition to Success.
-
-
In State Hash_Verify, the single Form B
kl.execinvokesVERIFY_TAG(state, L)(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)): it comparesINPUT[L-1:0]withstate[L-1:0].
-
-
Ascon
Ascon is a public permutation cite:[DBLP-journals-joc-DobraunigEMS21] standardized by NIST cite:[nist-SP-800-232] together with various cryptographic algorithms designed around it.
- Ascon conventions
-
The Ascon Machines share:
-
state[0 .. 4]: the five 64-bit words S0 to S4 of cite:[nist-SP-800-232], 320 bits, withstate[0]in bits [63:0]. Each Machine states its rate, the low bits ofstate. -
ASCON(p), which applies the permutationAscon-p[p]of cite:[nist-SP-800-232], ofprounds, to thestate. -
pad(x,r), which appends the bit 1 to the bit stringx, followed by the bit string0jwherej=(- |x| - 1) mod r:pad(x,r) = 0j @ 1 @ x.
-
Ascon-AEAD128
In Ascon-AEAD128, the caller applies pad( ·, 128) to non-empty associated data, so that the Machine in State Hash_Absorb absorbs a whole number of 128-bit blocks; empty associated data is not padded.
The caller must not pad the final block of the plaintext or ciphertext, which holds 0 to 127 bits (cite:[nist-SP-800-232]) and is empty when the length is a multiple of 128.
The caller gives the bit length of that block as the Xs of the Form B kl.setst into Enc_Last_Block, resp. Dec_Last_Block, and, if the block is non-empty, supplies it by the single kl.exec of that State; the Machine applies pad( ·, 128) to the final plaintext block internally.
A caller that pads the final block in software and supplies it as a whole block in Encrypt, resp. Decrypt, obtains a ciphertext and a tag that differ from those of cite:[nist-SP-800-232].
- Parameters
-
-
b= 128. -
k= 128. -
Granularity: 128 bits.
-
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
128 or 64
keyor System Key Identifieriii
0 or 64
Padding
-
Internal State:
-
key: 128 bits. -
state[0 .. 4](Ascon conventions), with the ratestate[127:0]. -
tag_len: 8 bits as int. -
tag_len_p: the number of bits that every verification compares (Rule MR12): a multiple of 8 from 64 to 128, and 128 if KeyType = 1; held in AuxInfo, not serialized. -
last_block_len: 7 bits as int.
-
-
Serialized Content:
Pos. Size (Bits) Field i
128 or 64
keyor System Key Identifierii
64
state[0]iii
64
state[1]iv
64
state[2]v
64
state[3]vi
64
state[4]vii
16
last_block_lenviii
16
tag_lenix
32, or 96 with a System Key Identifier
Padding
-
- Machine-Specific Functions
-
-
ASCON(p)andpad(x,r)(Ascon conventions). -
absorb_rate(X)XORs the 128-bitXinto the rate:state[0] ← state[0] xor X[63:0], thenstate[1] ← state[1] xor X[127:64]. -
ASCON_TAG()computes the 128-bit tag and returnsstate[4] @ state[3]after:-
state[2] ← state[2] xor key[63:0] -
state[3] ← state[3] xor key[127:64] -
ASCON(12) -
state[3] ← state[3] xor key[63:0] -
state[4] ← state[4] xor key[127:64]
-
-
- State Machine
-
-
States:
-
Ready: The CC is ready.
-
Hash_Absorb: Set the nonce, and process the AD.
-
Encrypt: Encrypt the plaintext.
-
Enc_Last_Block: Encrypt the last block of the plaintext.
-
Hash_Output: Return the tag.
-
Decrypt: Decrypt the ciphertext.
-
Dec_Last_Block: Decrypt the last block of the ciphertext.
-
Hash_Verify: Compare a user-provided value with the internally computed tag.
-
Success: The Machine has completed its operation without errors.
-
Failure: The Machine has completed its operation with an authentication failure.
-
-
Allowed State Transitions:
-
Ready → Hash_Absorb → Encrypt or Decrypt.
-
Encrypt → { Enc_Last_Block → } Hash_Output → Success.
-
Decrypt → { Dec_Last_Block → } Hash_Verify → Success or Failure.
-
The Machine makes these transitions itself (Rule MR18):
-
a
kl.setstinto Enc_Last_Block, resp. Dec_Last_Block, withXs= 0 pads the empty final block and enters Hash_Output, resp. Hash_Verify, directly, as does the Form A bypass naming Hash_Output from Encrypt, resp. Hash_Verify from Decrypt (Rule MR10 item 2); -
the
kl.execof Enc_Last_Block, resp. Dec_Last_Block, enters Hash_Output, resp. Hash_Verify; -
the
kl.execof Hash_Output enters Success; -
the
kl.execof Hash_Verify enters Success or Failure (Rule MR12).
-
-
Gated States: those of Rule MR1, with Hash_Output under encryption and Hash_Verify under decryption.
-
-
Behavior:
-
Upon entering State Ready:
-
state ← zeros(320) -
tag_len ← tag_len_p(Rule MR12) -
last_block_len ← 0
-
-
In State Ready, a Form B
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandXsis an operation, not a State (Rule MR16): it leavestag_lenunchanged, and anXsother thantag_len_ptransitions the locker to Error State Invalid (Rule MR12).A truncated tag is the leftmost tag_lenbits of the 128-bit tag in the bit order of cite:[nist-SP-800-232] §4.2.1, which are thetag_lenleast significant bits ofstate[4] @ state[3]. Entering Ready restorestag_lentotag_len_p(Rule MR12), so every message of the locker uses the same length, and a verification oracle confirms the tag only after about 2tag_len_ptrials. Rule MR15 leaves the bound on failed verifications of cite:[nist-SP-800-232] §4.3 R4–R5, and a singletag_lenacross lockers that hold the same key by value, to the caller. -
The
kl.setstinto Hash_Absorb is of Form C. It takes the nonce fromINPUTand performs:-
state[0] ← 0x00001000808c0001 -
state[1] ← key[63:0] -
state[2] ← key[127:64] -
state[3] ← INPUT[63:0] -
state[4] ← INPUT[127:64] -
ASCON(12) -
state[3] ← state[3] xor key[63:0] -
state[4] ← state[4] xor key[127:64]
Only
INPUT[127:0]is used (Rule MR8).The key enters stateonly within thiskl.setstand withinASCON_TAG(), each of which completes with the key permuted or masked by permutation output, so no Serialized Content holds it (Rule GR55.1). -
-
In State Hash_Absorb, only (multi-block)
kl.execinstructions of Form B are expected, absorbing a data blockINPUTinto the state as follows:-
absorb_rate(INPUT) -
ASCON(8)
If the associated data is empty, the caller absorbs no block, not even a padding block, and no permutation is applied. No
kl.execis then needed in this State (Rule GR18). -
-
Upon entering State Encrypt or Decrypt, the following domain separation operation is performed:
-
state[4] ← state[4] xor (bin(1,64) << 63)
-
-
In State Encrypt, (multi-block)
kl.execinstructions are expected to be of Form A, encryptingINPUTintoOUTPUTas follows:-
absorb_rate(INPUT) -
OUTPUT ← state[1] @ state[0] -
ASCON(8)
-
-
When entering State Enc_Last_Block, resp. Dec_Last_Block, the Form B
kl.setstwith immediatekl_state_enc_last_block, resp.kl_state_dec_last_block, and auxiliary operandXsinvokesFINAL_BLOCK_ENTRY(0, 127, 1)(FINAL_BLOCK_ENTRY(lo, hi, unit)): it admits any bit lengthXsof the final block from 0 to 127 and setslast_block_len ← Xs, which, unlike item 4 of the macro, thekl.execleaves unchanged.Xsneed not be a multiple of 8 (Rule MR11): cite:[nist-SP-800-232] orders the bits within a byte as Notation and Conventions does, sopadplaces the terminating1at bit positionXsfor anyXs. IfXs= 0, thekl.setstpads the empty final block,state[0] ← state[0] xor bin(1,64)(this ispad(∅,128)=zeros(127) @ 1), and transitions the locker to Hash_Output, resp. Hash_Verify; otherwise, the State waits for its single Form Akl.exec, as described next. -
In State Enc_Last_Block, exactly one Form A
kl.execis expected, to encrypt the last block. It performs:-
local tmp : bits(128)
-
tmp ← pad(INPUT[last_block_len-1:0], 128) -
absorb_rate(tmp) -
OUTPUT ← trunc(state[1] @ state[0], last_block_len) -
The state machine then transitions to State Hash_Output.
-
-
In State Hash_Output, only one
kl.execinstruction of Form C is expected, computing the tag intoOUTPUTas follows:-
OUTPUT ← trunc(ASCON_TAG(), tag_len) -
The state machine then transitions to State Success.
-
-
In State Decrypt, (multi-block)
kl.execinstructions are expected to be of Form A, decryptingINPUTintoOUTPUTas follows:-
local tmp : bits(128)
-
tmp ← (state[1] xor INPUT[127:64]) @ (state[0] xor INPUT[63:0]) -
state[0] ← INPUT[63:0] -
state[1] ← INPUT[127:64] -
ASCON(8) -
OUTPUT ← tmp
-
-
In State Dec_Last_Block, exactly one Form A
kl.execis expected, to decrypt the last block. It performs:-
local S_r : bits(128)– the rate part of the state -
local P : bits(128)
-
S_r ← state[1] @ state[0] -
P ← zeros(128-last_block_len) @ (S_r[last_block_len-1:0] xor INPUT[last_block_len-1:0]) -
OUTPUT ← P -
absorb_rate(pad(P[last_block_len-1:0], 128)) -
The state machine then transitions to State Hash_Verify.
-
-
In State Hash_Verify, which the decryption path enters by itself (Rule MR12), a single Form B
kl.execperformsVERIFY_TAG(ASCON_TAG())(SET_TAG_LEN(cap, lo)andVERIFY_TAG(expected, len)): it comparesINPUT[tag_len-1:0]with the computed tag in constant time, and transitions the locker to Success if they match and to Failure otherwise.
-
-
Ascon-AEAD128 with Preset Nonce
Like GCM with Preset IV (GCM with Preset IV), Ascon-AEAD128 has a variant with a preset nonce:
this Machine is PRESET(Ascon-AEAD128, nonce) (PRESET(parent, field), Ascon-AEAD128).
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
128 or 64
keyor System Key Identifieriii
128
nonceiv
0 or 64
Padding
-
Internal State:
Same as for Ascon-AEAD128, with in addition:
-
nonce: 128 bits.
-
-
Serialized Content:
Pos. Size (Bits) Field i
128 or 64
keyor System Key Identifierii
64
state[0]iii
64
state[1]iv
64
state[2]v
64
state[3]vi
64
state[4]vii
16
last_block_lenviii
16
tag_lenix
128
noncex
32, or 96 with a System Key Identifier
Padding
nonceis serialized because every transition into Hash_Absorb, also after an import, loads it intostate.
-
- State Machine
-
-
States and Allowed Transitions:
Same as for Ascon-AEAD128.
-
State Machine Behavior:
As for Ascon-AEAD128, except that:
-
The
kl.setstinto Hash_Absorb is of Form A. It performs the operations of the Form C nonce setup of Ascon-AEAD128, withnoncein place ofINPUT.
-
-
Ascon-AEAD128 with Nonce Masking
cite:[nist-SP-800-232] also describes a version of Ascon-AEAD128 with Nonce Masking:
- Data Structures
-
-
Provisioning Input:
Pos. Size (Bits) Field ii
128 or 64
K1or System Key Identifieriii
128 or 0
K2; absent when Pos. ii holds a System Key Identifier, which retrieves bothK1andK2(Rule GR55.1)iv
0, or 64 with a System Key Identifier
Padding
-
Internal State:
-
K1: 128 bits. -
K2: 128 bits. -
state,tag_len,tag_len_pandlast_block_len: as in Ascon-AEAD128, whose Enc_Last_Block and Dec_Last_Block states this Machine inherits.
-
-
Serialized Content:
Pos. Size (Bits) Field i
128 or 64
K1or System Key Identifierii
128 or 0
K2, or empty (a single SKID in Pos. i retrieves both keys)iii
64
state[0]iv
64
state[1]v
64
state[2]vi
64
state[3]vii
64
state[4]viii
16
last_block_lenix
16
tag_lenx
32, or 96 with a System Key Identifier
Padding
-
The Machine has the Parameters, Machine-Specific Functions, States and behavior of Ascon-AEAD128, with K1 as
the key key. The nonce setup of Ascon-AEAD128 uses
INPUT[127:0] xor K2 in place of INPUT.
K2 enters state only in the nonce setup, inside the masked nonce, before ASCON(12); K1 enters it wherever key does in Ascon-AEAD128.
Nonce masking with a set nonce needs no Machine of its own: the Machine of
Ascon-AEAD128 with Preset Nonce is provisioned with K1 as the key key and
N xor K2 as nonce, which software computes.
This combination needs K2 outside the KLF. It cannot use a K1 and K2 that a System Key Identifier retrieves, since a System Key Identifier of Ascon-AEAD128 with Preset Nonce retrieves key alone (Rule GR55.1).
All rules of Ascon-AEAD128 with Preset Nonce apply to this combination.
Ascon-Hash256
Ascon-Hash256 cite:[nist-SP-800-232] instantiates Hash and MAC Functions, and XOFs; only the differences are given here.
The Machine applies pad(M, 64) of cite:[nist-SP-800-232] §5.1 when the message M ends.
- Parameters
-
-
b= 64,n= 320,t= 64,d= 256,state_offset= 0,tag_offset= 0.
-
- Data Structures
-
The Provisioning Input contains only the MDH.
-
Internal State:
-
state[0 .. 4](Ascon conventions), with the ratestate[63:0]. -
block_base,last_block_lenandout_len(Hash and MAC Functions, and XOFs).
-
-
Serialized Content:
Pos. Size (Bits) Field i
64
state[0]ii
64
state[1]iii
64
state[2]iv
64
state[3]v
64
state[4]vi
16
block_base, in bitsvii
16
last_block_len, in bits;read_lenin Hash_Output_Bitsviii
32
out_lenin Hash_Output and Hash_Output_Bits; in Set_Aux_Value of Ascon-CXOF128,Z_lenin bits [15:0] andcumul_lenin bits [31:16]; zero otherwiseix
0
Padding
This layout replaces that of Hash and MAC Functions, and XOFs.
-
- Machine-Specific Functions
-
-
ASCON(p)(Ascon conventions). -
process_block()andupdate():ASCON(12). -
finalize():state[0] ← state[0] xor (bin(1,64) << block_base), thenASCON(12).
-
- State Machine
-
-
States and Allowed State Transitions: those of Hash and MAC Functions, and XOFs.
-
Behavior:
-
Upon entering State Ready:
-
state[0] ← 0x0000080100cc0002 -
state[1] ← zeros(64) -
state[2] ← zeros(64) -
state[3] ← zeros(64) -
state[4] ← zeros(64) -
ASCON(12) -
block_base,last_block_lenand Position viii (out_len, or theZ_lenandcumul_lenof Ascon-CXOF128) are set to zero.
-
-
In State Hash_Absorb,
PROCESS_VLIis invoked as in Hash and MAC Functions, and XOFs, withblock=state,mode=xor_accumulateandcumul_len=None. -
In State Hash_Absorb_Last_Block, the final piece need not be a whole number of bytes (Rule MR11, first bullet): cite:[nist-SP-800-232] orders the bits within a byte as Notation and Conventions does, as for Ascon-AEAD128.
-
Hash_Output follows Hash and MAC Functions, and XOFs. The digest has 256 bits, or
Xsbits after a Form BXs≠ 0, and is emitted in any whole number of bytes, withASCON(12)between successive 64-bit words and none after the last.
-
-
| A keyed version of this algorithm is not needed. A trusted entity can provide a CC that has already absorbed secret content, and reuse it for multiple invocations by keeping a copy of the original SCC. |
Ascon-XOF128
The Machine is the same as Ascon-Hash256 (Ascon-Hash256) with the following differences:
-
The IV written to
state[0]in State Ready is0x0000080000cc0003. -
It is an XOF (Hash and MAC Functions, and XOFs): it has no
d, and Hash_Output emits output of unbounded length, or ofXsbits after a Form BXs≠ 0. The first output word follows theASCON(12)offinalize(), the first squeezing permutation of cite:[nist-SP-800-232] Algorithm 6.
Ascon-CXOF128
Ascon-CXOF128 differs from Ascon-XOF128 in its IV, 0x0000080000cc0004, and in the customization string Z of
cite:[nist-SP-800-232] §5.3, which precedes the message as the blocks Z0 = bin(len_in_bits(Z), 64) and
pad(Z, 64), each 64-bit block followed by ASCON(12).
The Machine absorbs them:
-
A Form A
kl.setstfrom Ready into Hash_Absorb selects the emptyZ: it absorbsZ0=zeros(64)andpad(Z, 64)=bin(1, 64). -
A Form B
kl.setstwith immediatekl_state_set_aux_valueand auxiliary operandXs, from Ready or from Set_Aux_Value, enters State Set_Aux_Value for aZofXsbits. The State isLOAD_LONG_FIELD(Z_len, state, state, n, process_block(), None, xor_accumulate, 8)(LOAD_LONG_FIELD(len, block, state, n, process_block(), finalize(), mode, g)): Form Bkl.execinstructions loadZas a long field, with W =cumul_len, in bits, absorbing it into the rate as it is loaded, and a same-Statekl.setstrestarts the load. With modexor_accumulate, the macro does not zerostate. The Machine adds:-
Xsmust satisfy 0 ≤Xs≤ 2048; any otherXstransitions the locker to Error State Invalid. -
Entering the State sets
stateto its value in Ready andZ_len←Xs, and thekl.setstthen absorbsZ0=bin(Xs, 64). -
Z_lenneed not be a multiple of 8 (Rule MR11), as for the message: the last transfer is truncated toZ_len−cumul_lenbits (Macro: Processing Variable Length Inputs into a Fixed Length Output). -
With
Z_len= 0, the load is complete on entry, and anykl.exectransitions the locker to Error State Invalid. -
With
Z_len> 0 and the load complete, akl.execwith an empty transfer window does not reach the Machine and the State is kept (Rule GR18); any otherkl.exectransitions the locker to Error State Invalid.
-
-
A Form A
kl.setstfrom Set_Aux_Value into Hash_Absorb:-
requires
cumul_len=Z_len; otherwise, it transitions the locker to Error State Invalid, performing no operation; -
applies
pad(Z, 64):state[0] ← state[0] xor (bin(1,64) << block_base)andASCON(12); -
sets
block_base,Z_lenandcumul_len← 0; -
then performs the operations of entering Hash_Absorb.
-
The States add Set_Aux_Value, which absorbs Z, and the Allowed State Transitions add Ready → Set_Aux_Value → Hash_Absorb.
The Internal State adds Z_len, the bit length of Z, and cumul_len, the number of bits of Z absorbed so far, both serialized in Position viii (Ascon-Hash256).
In Ascon-Hash256 and Ascon-XOF128, a kl.setst naming Set_Aux_Value transitions the locker to Error State Invalid
(Rule GR19.4).
Accepted Risks
This section is informative.
MachinePolicy gates States (Rule MR1): a locker cannot enter a State of a direction that its policy disables. The policy does not prevent the abuse of a mode of operation. In the modes below, the enabled direction computes the disabled one under the IV or nonce of a message, which the caller sets or the PI fixes, since both directions use the same keystream or the same direction of the block cipher. In CBC, decryption computes encryption only under an IV that the computation determines. Preventing this would remove the one-direction policies of these Machines, or require the locker to generate every IV and nonce, so the KLE accepts these risks. Privileged code that narrows MachinePolicy to give a process a one-direction copy of a CC (kl.rstrl, kl.rstrh, and kl.rstrv) obtains separate directions only in the other Machines, such as ECB and XEX/XTS, and in CBC only for an encrypt-only copy.
| Machines | Machine Policy |
What the locker still computes |
|---|---|---|
|
Encryption under an IV that the output determines: software picks the last ciphertext block, decrypts it alone under IV |
|
|
Decryption. For each segment, software computes the input block from the IV and the earlier ciphertext, sets it as |
|
|
Encryption: decrypting a zero segment outputs the keystream segment of the |
|
OFB (Chaining/Feedback Modes (CBC, CFB, and OFB)), CTR and XCTR (CTR/XCTR Keystream Generation) |
|
Both directions: either bit allows Operate, which computes both. |
GCM (GCM Mode) |
|
Decryption without verification: encrypting a ciphertext under the IV of its message outputs the plaintext, since both directions XOR the same counter keystream. |
GCM (GCM Mode, GCM with Preset IV), GCM-SIV (GCM-SIV Mode) |
|
Ciphertext without a tag that verifies: decrypting a plaintext outputs its encryption under the IV, or in GCM-SIV the tag, of the decryption. |
OCB (OCB Mode) |
|
The final partial block |
OCB (OCB Mode, OCB with Preset Nonce) |
|
Ciphertexts that verify, as described below. |
Ascon-AEAD128 (Ascon-AEAD128, Ascon-AEAD128 with Nonce Masking) |
|
Decryption without verification, at a cost linear in the length of the message, with a |
Ascon-AEAD128 (Ascon-AEAD128, Ascon-AEAD128 with Preset Nonce, Ascon-AEAD128 with Nonce Masking) |
|
Ciphertext without a tag that verifies, at a cost linear in the length of the message, with a |
A locker of OCB Mode or OCB with Preset Nonce with MachinePolicy = 0b10 lets software forge.
Decrypt outputs each plaintext block before Hash_Verify checks the tag, and for a fixed nonce and block index i, the map from a ciphertext block to its plaintext block is a fixed permutation fi.
Given a valid message (N, A, C, T) of m full blocks and an optional final partial block, software decrypts chosen m-block ciphertexts under N and A, which no Machine prevents (Rule MR15).
It searches for C' ≠ C such that f1(C'1) xor … xor fm(C'm) equals the checksum of the valid message.
Since the tag depends on the ciphertext only through the checksum, (N, A, C', T) verifies.
Wagner’s generalized birthday algorithm (CRYPTO 2002) finds such a C' with about 223 block decryptions for m ≥ 128, 245 for m = 4 and 264 for m = 2; for m = 1, no such C' exists.
If the final block holds l > 0 bits, software also chooses C' freely, since the checksum depends on P' only in l of its bits: the search then concerns 128 − l bits, about 2128−l decryptions for m = 1 (28 for a 15-byte final block), and fewer for larger m.
A repeated IV or nonce, which Rule MR15 leaves to the caller, can reveal locker state derived from the key.
In GCM Mode, two messages encrypted under one key and one IV give, with their tags, a polynomial in auth_key whose roots software computes, leaving few candidates (the "forbidden attack" of Joux, 2006).
With auth_key, every valid message gives the tag mask of its IV, so software forges under that IV outside the locker.
Since the Machine also accepts IVs of lengths other than 96 bits, whose J0 is a GHASH under auth_key, software can compute an IV whose J0 is the J0 of any chosen IV with its 32-bit counter decremented by one; encrypting or decrypting a zero block under it, in any locker of GCM Mode that holds the key, outputs the tag mask of the chosen IV.
One repeated IV thus allows forgeries under every IV.
Narrowing MachinePolicy, an ExpirationDate and clearing the locker do not revoke them; only retiring the key, in every locker and SCC that holds it, ends them.
GCM-SIV Mode limits the damage of a repeated nonce to revealing whether two messages are equal.
Two Rules limit the remaining risks:
-
Rule MR12 fixes, for the Machines that it lists, the number of bits that every verification of a locker compares, so such a locker that verifies but does not generate confirms a tag only after about 2
tag_len_ptrials; for GCM the bound depends on the message length (GCM Mode). -
Rule SR18 forbids software to use the plaintext that an AEAD Machine outputs before the locker reaches Success, since that plaintext is unauthenticated until then.
Elliptic Curve Cryptography
The Elliptic Curve Machines provide:
-
Scalar multiplication with known and unknown base point.
-
ECDSA, SM2 and EdDSA signature generation and verification.
The x25519 and x448 Machines (X25519- and X448-Specific Rules) provide only the former.
KDFs, hash functions and formats vary too much for general KEM or PKE support; among the elliptic curve standards, only SM2 fully specifies an integrated encryption scheme cite:[GMT-0003-4-2012].
Software builds such schemes on scalar multiplication, and kl.derive moves the shared secret into the hash function of the KDF, and the KDF output into the key of a symmetric Machine, without exposing them.
A key that is exposed anyway should be provisioned into a locker, and its exposed copy erased at once.
|
Provisioning sets the Generator field to the default base point (“generator”) that the standards listed below define for the curve.
Software may overwrite the field; a Form A kl.setst to Set_Generator, or one of Form B with zero in the GPR, restores
the default, as does a Form B kl.setst to Ready with bit 0 of Xs set.
With MachineExtension = 1, the public-points variant, Generator and SecondPt are public fields, which an SCC carries in clear (Rule GR9): Generator always holds the default generator of the curve, so that Point_Mul computes only a public key, and a scalar multiplication of SecondPt, which would make a shared secret, transitions the locker to Error State Invalid (Point_Mul below).
In this variant and the sealed one, a Form B kl.setst to Set_Generator with a non-zero operand, or to Ready with bit 5 of Xs set while HasSecondPt is set, transitions the locker to Error State Invalid, and a provisioning or import whose Generator is not the default completes into Error State Invalid (Rule MR3).
The variant suits signature generation and verification, and key-pair generation; software uses MachineExtension = 0 for a key exchange and for a custom generator.
It is defined for every Elliptic Curve Machine, and is unsupported Metadata where not implemented (Validity of Metadata).
With MachineExtension = 2, the sealed variant, Generator always holds the default generator, as in the public-points variant, but both points are private, Point_Mul may multiply SecondPt, and the shared secret is a sealed source (Rule GR31.3) that no kl.exec emits (Output below).
It suits a key exchange whose key derivation runs in lockers.
It is defined for every Elliptic Curve Machine except those of EdDSA-Specific Rules, and is unsupported Metadata where not implemented.
All values (integers, coordinates, etc.) are in little-endian format, except the shared secret of the Weierstrass curves that Output emits, which follows the byte order of its standard (see Output below).
- Parameters
-
The parameters used in this section are:
-
The bit length
bof the main fields, such as coordinates, signature R and S fields, scalars; -
The bit length
hof the hash used in the signature scheme. TheHashfield holds:-
for the ECDSA curves,
bin(e, h), whereeis the leftmostmin(N, outlen)bits of the message digest, read as a big-endian integer, as cite:[nist-fips-186-5] §6.4 and §6.4.1, step 2, prescribe:-
Nis the bit length of the group ordern, andoutlenthat of the digest; -
the digest is truncated, not reduced modulo
n; -
the caller performs this truncation and chooses an approved hash function;
-
-
for SM2,
bin(e, 256), withethe big-endian integer ofSM3(ZA ‖ M)of cite:[GMT-0003-2-2012], whereZA=SM3(bswap(bin(entlenA, 16)) ‖ IDA ‖ bswap(bin(a, 256)) ‖ bswap(bin(b, 256)) ‖ bswap(bin(xG, 256)) ‖ bswap(bin(yG, 256)) ‖ bswap(bin(xA, 256)) ‖ bswap(bin(yA, 256))):-
entlenAis the bit length of the identityIDA,aandbare the curve coefficients, not the parameterb, and (xA,yA) is the public key; -
the caller computes
ZAande, since every input toZAis public; the KLE unit computes neither;
-
-
for the Edwards curves, the 64-byte
PH(M), used only in pre-hash mode; see EdDSA-Specific Rules;
-
-
The bit length
jof the random number used as nonce in signature generation; -
The number
uof coordinates used to represent a point (uis 1 or 2); and -
The number
vof elements used to represent a signature (vis 0, 1 or 2, wherev= 0 denotes a curve for which no signature scheme is provided).
The granularity of every Elliptic Curve Machine, X25519, X448 and EdDSA included, is 8 bits: a field can be transferred with any
SEWfrom 8 to 64 bits that divides its size, or through the KLIOBUF in any number of bytes.The parameters for the defined curves are:
-
NIST curves cite:[NIST-SP-800-186,nist-fips-186-5]:
-
secp256r1 (NIST P-256):
b=h=j= 256,u=v= 2. -
secp384r1 (NIST P-384):
b=h=j= 384,u=v= 2. -
secp521r1 (NIST P-521):
b= 576 (55 msbs set to zero),h=j= 576 (55 msbs set to zero),u=v= 2.
-
-
Edwards curves for signatures cite:[RFC8032,nist-fips-186-5]:
-
ed25519:
b= 256,h= 512;u= 1,v= 2. -
ed448:
b= 456,h= 512;u= 1,v= 2.
-
-
Montgomery curves, for key exchange only cite:[RFC7748]:
-
x25519 (curve25519):
b= 256;u= 1,v= 0. -
x448 (curve448):
b= 448;u= 1,v= 0.
-
-
Brainpool cite:[RFC5639,RFC8734]:
-
brainpoolP256r1:
b=h=j= 256;u=v= 2. -
brainpoolP384r1:
b=h=j= 384;u=v= 2. -
brainpoolP512r1:
b=h=j= 512;u=v= 2.
-
-
SM2 cite:[GMT-0003-1-2012,GMT-0003-2-2012,GMT-0003-3-2012,GMT-0003-4-2012]:
b=h=j= 256;u=v= 2.
For the Edwards curves, a point is the compressed
b-bit string of cite:[RFC8032] §5 (u= 1), and a signature is the pair (R,S) of such strings (v= 2). Sob= 456 for ed448, whose strings are 57 bytes.h= 512 because, in pre-hash mode,Hashholds the 64-bytePH(M).j= 0, since EdDSA uses noRndNum(EdDSA-Specific Rules).For the Montgomery curves, a point is its u-coordinate alone (cite:[RFC7748] §5,
u= 1). Their Machines provide key exchange only (X25519- and X448-Specific Rules), sov= 0, andhandjare not defined. They are listed apart from the Edwards curves because their points differ, and so doesbfor x448.All curves here are defined over prime fields. For secp521r1, the 55 most significant bits of
Scalar,HashandRndNum, of each coordinate ofGeneratorandSecondPt, and of each component ofSignaturemust be zero. The locker transitions to Error State Invalid if a write sets one of them, or if Point_Mul, Sign_Generate or Sign_Verify finds one set in a value it uses, a resumedRndNumincluded (Rule MR3).A point is valid if:
-
each of its coordinates is less than
p; -
it satisfies the curve equation;
-
it is not the neutral element: the point at infinity of a Weierstrass curve, resp. (0, 1) of an Edwards curve;
-
where the cofactor is not 1, it lies in the prime-order subgroup; and
-
on an Edwards curve, it decodes as cite:[RFC8032] §5.1.3, resp. §5.2.3, prescribes.
Point_Mul, Sign_Generate and Sign_Verify check the validity of
GeneratorandSecondPtwhen they read them (Rule MR3). For the Edwards curves, only Point_Mul usesGenerator, and Sign_Verify checksSecondPtonly as EdDSA-Specific Rules states. An invalid point that an operation checks, and whose encoding satisfies the representation of the curve, is a data error and leads to Failure (Rule MR2), a coordinate not less thanpincluded. A violated representation, such as a set msb of secp521r1, is a configuration error, as stated above. For the Montgomery curves, the check of X25519- and X448-Specific Rules replaces this one. -
- Data Structures
-
-
MDH:
The Elliptic Curve Machines use the StateExtension field as follows:
Table 6. StateExtension bits used by the Elliptic Curve Machines Bit Name Description 0
HasSecondPtA second point has been set.
1
HasSignatureA signature has been set.
2
HasHashA hash has been set.
3
HasRndNumA random number has been set. For the EdDSA Machines this bit is
HasHashStateinstead (EdDSA-Specific Rules).The Elliptic Curve Machines use the MachineUse field as follows:
Table 7. MachineUse bits used by the Elliptic Curve Machines Bits Name Description [1:0]
OutputTypeDetermines what Output emits: 0, a point, the product of
Generator, such as a public key; 1, a signature, fromSignature; 2, a shared secret, the product ofSecondPt, which Point_Mul multiplies wheneverHasSecondPtis set, whether the point was loaded or copied. Points and shared secrets are emitted fromSecondPt. The value 3 is reserved: akl.execorkl.derivein Output with that value transitions the locker to Error State Invalid.[13:2]
ProgressTracks, in an implementation-defined and non-portable unit, the progress of long-running operations such as scalar multiplications. Whenever it is non-zero, the SCC must include an ADS (Rule GR38).
Except in the sealed variant, Output explicitly allows the export of a shared secret through kl.exec, like any other output, so the caller can read it. Too many protocols process the ECDH shared secret themselves to list them askl.derivedestinations. Itskl.derivetransfers are therefore unrestricted (Rule GR31.1), and the exclusion ofK1 ‖ K2of nonce masking as a destination (Derivation Endpoints of the Machines) applies only to a secret thatkl.execcannot read, such as the ML-KEMsharedkeyor a sealed shared secret.For ECC Machines, MachinePolicy[0] gates signature generation and MachinePolicy[1] signature verification, with their Gated States (Rule MR1), and MachinePolicy ≠ 0 gates Set_Hash, since its field
Hashexists only then. All four combinations are admissible, except as X25519- and X448-Specific Rules and EdDSA-Specific Rules restrict them.
-
The Provisioning Input contains only the MDH.
A system-specific import (Rule GR51) checks every Generator, Scalar, SecondPt, Hash and Signature that it converts, with the checks and outcomes of a completed load of that field.
It sets HasSecondPt, HasHash, resp. HasSignature for a converted SecondPt, Hash or Signature (Rule MR4).
-
Internal State:
-
OutputType: 2 bits, held in bits [1:0] of the MDH field MachineUse. -
Progress: integer, held in bits [13:2] of the MDH field MachineUse (Table 7): the implementation-defined progress of a long-running operation. -
block_base: 8 bits, held in bits [15:8] of the MDH field AuxInfo. The field W of Rule MR14, in bytes, of the “set” and “output” operations; it is public, since the instructions that the transfer issues determine it. Provisioning and a system-specific import zero it, and everykl.setstzeroes it; an immediate assignment of Set_Generator or Set_Scalar then sets it to the field size. It is distinct from the countersH.block_baseandH'.block_baseof the hash instances of EdDSA-Specific Rules. -
Generator(X, {Y}): one or twob-bit strings representing the X {and Y} coordinate{s}. -
SecondPt(X, {Y}): one or twob-bit strings representing the X {and Y} coordinate{s}. For signature verification and for multiplication by an unknown point,SecondPtholds the public key, resp. the peer’s point. -
Scalar:b-bit string. -
If signature generation or verification is allowed:
-
Signature(R,S): twob-bit strings representing theRandScomponents. -
Hash: anh-bit string representing the hash.
-
-
If signature generation is allowed:
-
RndNum: aj-bit string representing the random number.
-
-
Additional data, for instance precomputed multiples of the Generator.
A
kl.rstrlorkl.rstrvthat leaves both bits of MachinePolicy clear (kl.rstrl, kl.rstrh, and kl.rstrv) erasesSignatureandHashand clearsHasSignatureandHasHash, since these fields then no longer exist. One that clears MachinePolicy[0] likewise destroysRndNumand clearsHasRndNum. -
-
Serialized Content:
The public fields (Rule GR9) come first:
Signatureand, with MachineExtension = 1,GeneratorandSecondPt. Positions i, i.a, v and vi are present only for the values of MachinePolicy given:Pos. Type Size (Bits) Field i
Public
If MachinePolicy ≠ 0:
vb, else: 0Signature, R value, followed by S value ifv=2.i.a
Public
If MachinePolicy ≠ 0:
p1, else: 0Padding
ii
Public if MachineExtension = 1, else Private
ubGenerator, X coordinate, followed by Y coordinate ifu=2.iii
Public if MachineExtension = 1, else Private
ubSecondPt, X coordinate, followed by Y coordinate ifu=2. Can be the Public Key.iii.a
Public if MachineExtension = 1, else Private
p3Padding
iv
Private
bScalar:b-bit string. Can be the Private Key.v
Private
If MachinePolicy ≠ 0:
h, else: 0Hash: anh-bit string representing the hash.vi
Private
If MachinePolicy[0] = 1:
j, else: 0RndNum. Its width isj, the nonce length, both here and in the Internal State.vi.a
Private
p6Padding
The padding
p1= (−vb) mod 128 andp3= (−2 ×ub) mod 128 endsSignature, resp.Generator‖SecondPt, at a 128-bit boundary; it is 112 for ed448 and 0 for the other curves. The final Paddingp6= (−(b+ (MachinePolicy ≠ 0) ×h+ MachinePolicy[0] ×j)) mod 128 endsContent1. The transfer counterblock_baseis not serialized: it is held in the MDH (AuxInfo[15:8]).SCC_ClearLen1is (MachinePolicy ≠ 0) × ⌈vb/ 128⌉ with MachineExtension ≠ 1, and (MachinePolicy ≠ 0) × ⌈vb/ 128⌉ + ⌈2 ×ub/ 128⌉ with MachineExtension = 1.Signatureholds only a signature loaded for verification, or one that Sign_Generate has completed, or itsRas EdDSA-Specific Rules states, or zero.Which fields are serialized depends only on MachinePolicy, never on State or StateExtension (Length of External Formats and KLF Capacity Usage of a Locker): a field is serialized with whatever it holds, a partial load or an intermediate value included, and its
Hasflag governs only its use.RndNumholds a value only while a signature generation is under way, withHasRndNumset, and is zero otherwise. A StateExtension @ State withHasRndNumset in a State other than Sign_Generate is not supported by the Machine: an SCC that carries it is invalid Metadata (Validity of Metadata).The size in bytes of the Positions other than ii, iv and vi.a is:
varlen← (ub+p3)/8 + (MachinePolicy != 0) × (vb+p1+h)/8 + MachinePolicy[0] ×j/8.If AuxDataLen ≥ 2, the SCC also carries the ADS:
IMPQUALandSIV2precedeContent1, andContent2follows it (Plaintext of the Sealed Cryptographic Context (SCC) Format, all Sections in Order).For ed25519 and ed448 the fields of EdDSA-Specific Rules follow Position vi.a.
- State Machine
-
-
States: Besides Ready (1), Success (54), Failure (55), ECC Machines define:
-
Set_Generator (2)
-
Set_Scalar (3)
-
Point_Mul (4)
-
Sign_Generate (5)
-
Sign_Verify (6)
-
Set_Hash (7)
-
Set_SecondPt (8)
-
Sign_Input (9)
-
Output (10)
-
-
Allowed State Transitions:
The Set states are Set_Generator, Set_Scalar, Set_Hash, Set_SecondPt and Sign_Input.
-
Ready → any Set state.
-
Any Set state → any Set state, itself included.
-
Ready or any Set state → one of the following, with these entry conditions (Rule MR1):
-
Point_Mul:
1≤int(Scalar)<n, wherenis the order of the group; -
Sign_Generate:
HasHashand1≤int(Scalar)<n; for SM2,HasHashand1≤int(Scalar)≤n− 2 (cite:[GMT-0003-2-2012]); -
Sign_Verify:
HasSecondPt,HasHashandHasSignature. -
X25519- and X448-Specific Rules replaces the condition of Point_Mul on
Scalar, and EdDSA-Specific Rules replaces the conditions of all three States.
-
-
Point_Mul or Sign_Generate → Output, made only by the Form D
kl.execof the State (Rule MR18), or → Failure when a point that the operation uses is not valid (Rule MR2). -
Output → Success, when the output is complete (Rule MR14), or on the first committed unit of a
kl.deriveof the shared secret. -
Sign_Verify → Success or Failure.
-
A
kl.setstinto Set_Generator, Set_Scalar or Ready is of Form A or B, as the Behavior states, and one into Set_Ctx or Msg_Absorb of EdDSA-Specific Rules of Form B (Rule GR19.1).
-
Set_Generator sets a group generator, or the default one; Set_Scalar sets a scalar for scalar multiplication, or a private key.
-
HasSecondPt,HasSignatureandHasHashfollow Rule MR14, and are held in StateExtension (Table 6).HasRndNum, also held there, is set only while a signature operation holdsRndNum, which is drawn, never loaded (Rule GR38). -
GeneratorandScalarhave no flag. A load of either that is left incomplete zeroes the field (Rule MR14): a zeroGeneratoris not a valid point, and a zeroScalarnot a configured private key.
-
-
Behavior:
-
Provisioning sets
Generatorto the default of the curve, andScalarto zero. -
The Set states and Output follow Rule MR14, with the progress recorded in
block_base, in bytes. -
Entering Set_Generator:
-
by a Form B
kl.setstwhose operand is zero, Form A included, sets the default generator of the curve, andblock_base←ub/8, which completes the load; -
by a Form B
kl.setstwhose operand is non-zero, erasesGeneratorand starts a load: Form Bkl.execinstructions then load theub/8 bytes ofGenerator; with MachineExtension ≠ 0, it transitions the locker to Error State Invalid instead.
-
-
Entering Set_Scalar, Set_Hash, Set_SecondPt or Sign_Input by a Form A
kl.setststarts a load of the field X that the State sets by Form Bkl.execinstructions (Rule MR14): it erases X,Scalarbecoming zero, and clearsHasX where that flag exists. -
A Form B
kl.setstinto Set_Scalar:-
whose operand is zero, Form A included, acts as the Form A
kl.setstabove; -
whose operand is non-zero sets
Scalarto a random private key, andblock_base←b/8, which completes the load; nokl.execfollows. Rule GR45 applies if the RBG fails. The key is:-
for the NIST and Brainpool curves, an integer d with 1 ≤ d <
n, generated as cite:[nist-fips-186-5] Appendix A.2.1 or A.2.2 prescribes; -
for SM2, one with 1 ≤ d ≤
n− 2 (cite:[GMT-0003-1-2012]), from an RBG of security strength at least 128 bits; -
for the Edwards curves, a
b-bit string obtained as cite:[nist-fips-186-5] Appendix A.2.3, step 1, prescribes, from an RBG of security strength at least 128 bits for ed25519 and 224 bits for ed448; -
for the Montgomery curves, a uniformly random
b-bit string, from an RBG of security strength at least 128 bits for x25519 and 224 bits for x448.The bits of
Scalarbeyond the key are zero.
-
-
-
Retry rules of signature generation:
-
for the NIST and Brainpool curves, the signature is recomputed with a fresh
kwheneverr= 0 ors= 0 (cite:[nist-fips-186-5] §6.4.1); -
for SM2, whenever
r= 0,r+k=n, ors= 0 (cite:[GMT-0003-2-2012]); -
the Edwards curves use no random secret, and have no retry rules.
-
each retry draws
kas Sign_Generate does and setsRndNum←bin(k, j)before it records any further progress.
-
-
In State Point_Mul, a single Form D
kl.execperforms a scalar multiplication:-
The base point
PisSecondPtifHasSecondPtis set, andGeneratorotherwise. -
If
PisSecondPtand MachineExtension = 1, the locker transitions to Error State Invalid. -
If
Pis not a valid point, the state machine transitions to Failure. -
SecondPt←[int(Scalar)]P, encoded as in Elliptic Curve Cryptography, andHasSecondPtis set. -
OutputType← shared secret ifPisSecondPt, and point otherwise, and the locker transitions to Output.
-
-
In State Sign_Generate, a single Form D
kl.execsigns, over the base pointGenerator, with private keyd=int(Scalar)and message valuee=int(Hash):-
If
Generatoris not a valid point, the locker transitions to Failure. -
If
Progressis zero, the per-signature secretk, uniformly distributed in [1,n− 1], is generated from the RBG (Prerequisites, Rule GR45) as cite:[nist-fips-186-5] Appendix A.3.1 or A.3.2 prescribes, also for SM2;RndNum←bin(k, j), andHasRndNumis set. -
If
Progressis non-zero, the interrupted operation is resumed with theRndNumheld, or restarted (Rule GR38). -
The signature (
r,s) is computed as cite:[nist-fips-186-5] §6.4.1 specifies for the NIST and Brainpool curves, and as cite:[GMT-0003-2-2012] specifies for SM2, with the retry rules above. -
Signature← (r,s), andHasSignatureis set;RndNumis destroyed andHasRndNumcleared. -
OutputType← signature, and the locker transitions to Output.
-
-
In State Sign_Verify, a single Form D
kl.execverifiesSignatureagainst the public key held inSecondPtand the message valuee=int(Hash), as cite:[nist-fips-186-5] §6.4.2 specifies for the NIST and Brainpool curves, and as cite:[GMT-0003-2-2012] specifies for SM2:-
it performs every check those specifications require, the ranges of
randsincluded, and checks thatSecondPtandGeneratorare valid points; -
if a check fails, or the signature equation does not hold, the state machine transitions to Failure, else to Success.
-
-
In State Output,
OutputTypedetermines the output and its length:-
point:
SecondPt,ubbits; -
signature:
Signature,vbbits; -
shared secret: the byte string that the standard of the curve defines as the shared secret, in the byte order of that standard, which for the Weierstrass curves is the one exception to the little-endian encoding. It is:
-
for the NIST and Brainpool curves,
Zof cite:[NIST-SP-800-56Ar3] §5.7.1.2: the X coordinatexas a big-endian string ofm= ⌈log2(p)/8⌉ bytes (its Appendix C.2), that isbswap(bin(x, 8m)), 8mbits (66 bytes for secp521r1); -
for SM2,
x2 ‖ y2of cite:[GMT-0003-4-2012], each coordinate a big-endian string of 32 bytes, that isbswap(bin(y, 256)) @ bswap(bin(x, 256)),x2in the 32 least significant bytes, emitted first, 512 bits; -
for the Montgomery curves, the whole
b-bit stringKof cite:[RFC7748] §6, little-endian as that standard defines it; -
for the Edwards curves, whose standard defines no shared secret, the encoded point (cite:[RFC8032] §5.1.2, resp. §5.2.2).
-
-
-
In State Output, Form C
kl.execinstructions emit the output, ending in Success (Rule MR14), in which nokl.deriveis admitted.-
This State allows the export of the shared secret through
kl.exec, except in the sealed variant, where a Form Ckl.execwithOutputType= shared secret transitions the locker to Error State Invalid. The shared secret is also akl.derivesource, unrestricted, or sealed in the sealed variant (Rule GR31.3), as a field (Rule GR31.1), of onekl.derive, and only whileblock_base= 0, before a Form Ckl.exechas emitted any of it: thatkl.derivetransitions the locker to Success (Rule GR28), and one made onceblock_base≠ 0 transitions it to Error State Invalid (Rule GR29 item 2). The transfer reads it from its first byte (Rule GR28): for X25519 and X448, a key field receives the firsteff_lengthbytes of the shared secret; for the other curves, a key field is not a destination (Derivation Endpoints of the Machines); a message input receives the whole shared secret, withlengthequal to the length of the shared secret (Rules GR29 item 6 and GR31.1).
-
-
Entering Ready by a Form B
kl.setst: bits 0 to 6 ofXsselect the fieldsGenerator,Scalar,SecondPt,HashandSignatureto copy, reset, erase or keep; a non-zero bit 7 or above transitions the locker to Error State Invalid.-
First the copies are made, both from the values held before the instruction, so that bits 4 and 5 together exchange the two points:
-
bit 4:
Generatoris copied ontoSecondPt, andHasSecondPtis set; -
bit 5: if
HasSecondPtwas set,SecondPtis copied ontoGenerator, or, with MachineExtension ≠ 0, the locker transitions to Error State Invalid; otherwise bit 5 has no effect.
-
-
Then the fields are reset or erased:
-
bit 0:
Generatoris reset to the default value; -
bit 1:
SecondPtis erased andHasSecondPtis cleared; -
bit 2:
Scalaris erased; -
bit 3:
Hashis erased andHasHashis cleared; -
bit 6:
Signatureis erased andHasSignatureis cleared.
-
-
Every field whose bit is clear is kept. A Form A
kl.setstsets no bit, and keeps all five fields.
-
-
Progress, bits [13:2] of MachineUse, is the field P of Rule GR38 for Point_Mul, Sign_Generate and Sign_Verify, and, in the EdDSA Machines (EdDSA-Specific Rules), for akl.setstthat enters or leaves Msg_Absorb (Rule GR37). Its material isRndNum, where the Machine uses it, and the intermediate values that the operation keeps in the ADS; for akl.setstthat enters or leaves Msg_Absorb, these include the expanded seed, the hash states being finalized, andr,R,k'andAbefore the operation completes. Each event of that Rule that zeroesProgressalso destroys the material and, where the Machine has it, clearsHasRndNum.
-
-
X25519- and X448-Specific Rules
The x25519 and x448 Machines implement the functions X25519 and X448 of cite:[RFC7748] §5, and with them
the Diffie-Hellman key exchange of cite:[RFC7748] §6. Of the operations of Elliptic Curve Cryptography they provide only
scalar multiplication. They differ from the other curves in three respects: a point is a single coordinate,
the scalar is an arbitrary b-bit string, and the input point is not checked for validity, only the result. This subsection states the
consequences; everything not restated here follows Elliptic Curve Cryptography.
- Parameters
-
-
The curves are the Montgomery curves
v2=u3+A·u2+uof cite:[RFC7748] §4: curve25519 for x25519, withp= 2255 - 19 andA= 486662, and curve448 for x448, withp= 2448 - 2224 - 1 andA= 156326. curve25519 is birationally equivalent to the Edwards curve of ed25519; curve448 is related to that of ed448 by an isogeny of degree 4. The Machines are nevertheless distinct, and points and private keys are not interchangeable between them. -
A point is represented in compressed form, by its u-coordinate alone, so the parameter
u= 1. The u-coordinate is held as the X coordinate ofGeneratorandSecondPtof Elliptic Curve Cryptography. A public key and a shared secret are 32 bytes for x25519 and 56 bytes for x448. -
There is no signature scheme:
v= 0, andhandjare not defined. -
X25519(k, u)andX448(k, u)map a scalar and a u-coordinate, bothb-bit strings, to ab-bit string, decoding their inputs as cite:[RFC7748] §5 prescribes:-
the scalar is clamped: for x25519, bits 0, 1, 2 and 255 are cleared and bit 254 is set; for x448, bits 0 and 1 are cleared and bit 447 is set;
-
for x25519, bit 255 of the u-coordinate is ignored; and
-
a u-coordinate not smaller than
pis reduced modulop.
-
-
The private key is the unclamped
b-bit string held inScalar, which holds a configured private key when it is non-zero. It is not compared with the order of the group.
-
- Data Structures
-
Those of Elliptic Curve Cryptography, with the following changes:
-
MDH:
-
MachinePolicy is not used and must be zero; a non-zero value is unsupported Metadata (Validity of Metadata), and a
kl.rstrlorkl.rstrvleaves it zero (kl.rstrl, kl.rstrh, and kl.rstrv). -
Of the StateExtension bits (Table 6) only
HasSecondPtis used: an SCC with any of the bits 1 to 3 set is invalid Metadata (Validity of Metadata). -
OutputType(Table 7) is never signature: a multiplication ofGeneratoroutputs a point, the public key, and one ofSecondPta shared secret,K; both are a singleb-bit string.
-
-
Internal State:
GeneratorandSecondPtare each a singleb-bit string, a u-coordinate.SecondPtholds the peer’s public key and, after a scalar multiplication, the public key of the locker or the shared secret.Signature,HashandRndNumdo not exist. -
Serialized Content: Positions ii to iv and vi.a of Elliptic Curve Cryptography, with
u= 1; Positions i, i.a, v and vi are always empty.varlen←b/8.
-
- State Machine
-
-
States: besides Ready (1), Success (54) and Failure (55), only the following States of Elliptic Curve Cryptography:
-
Set_Generator (2)
-
Set_Scalar (3)
-
Point_Mul (4)
-
Set_SecondPt (8)
-
Output (10)
-
Sign_Generate, Sign_Verify, Set_Hash and Sign_Input are not defined: a
kl.setstthat names one of them transitions the locker to Error State Invalid (Rule GR19.4).-
Allowed State Transitions: the Set states are Set_Generator, Set_Scalar and Set_SecondPt.
-
Ready or any Set state → any Set state, itself included, or → Point_Mul, which requires
Scalarto hold a configured private key (Rule MR1). -
Point_Mul → Output, or → Failure when the result is the all-zero string (Rule MR2); Output → Success, as in Elliptic Curve Cryptography.
-
-
Behavior:
-
Provisioning sets
Generatorto the base point of cite:[RFC7748] §4.1, resp. §4.2, that is, to the u-coordinate 9 for x25519 and 5 for x448, andScalarto zero. -
Generator,SecondPtandScalaraccept everyb-bit string: no check is made when they are written (Rule MR3). -
In State Point_Mul, a single Form D
kl.execperforms a scalar multiplication, in the following steps, which replace those of Elliptic Curve Cryptography:-
The base point
PisSecondPtifHasSecondPtis set, andGeneratorotherwise.Pis not checked for validity:X25519andX448are defined for everyb-bit string. -
R←X25519(Scalar, P), resp.X448(Scalar, P). -
If
Ris the all-zero string, the locker transitions to Failure, andSecondPtandHasSecondPtare left unchanged. The check is made in constant time; cite:[RFC7748] §6 makes it optional. -
Otherwise
SecondPt←R,HasSecondPtis set,OutputType← shared secret ifPisSecondPt, and point otherwise, and the locker transitions to Output.
-
-
Entering Ready by a Form B
kl.setst, bits 3 and 6 ofXshave no effect:HashandSignaturedo not exist. -
Rule GR38 applies to Point_Mul, with no
RndNumto destroy.
-
-
|
A key exchange is two scalar multiplications with the same |
EdDSA-Specific Rules
EdDSA, standardized in cite:[RFC8032] and cite:[nist-fips-186-5], does not fit the division of labor used by the other curves of Elliptic Curve Cryptography, under which the caller hashes the message and the KLE unit performs only the group arithmetic. Both of its hash invocations take material the caller does not hold:
r = int(H(dom ‖ prefix ‖ M)) mod L, where prefix is secret, and
k' = int(H(dom ‖ R ‖ A ‖ M)) mod L, where R = [r]B is computed inside.
The Machine must perform the hashing itself. This subsection states the consequences; everything not restated here follows Elliptic Curve Cryptography.
- Parameters
-
-
HisSHA-512for ed25519 andSHAKE256, with a 114-byte output, for ed448. -
The private key, or seed, is the
b-bit string held inScalar;Scalarholds a configured seed when it is non-zero. -
domisdom2(x, ctx)for ed25519 anddom4(x, ctx)for ed448, as defined in cite:[RFC8032] §5.1 and §5.2, withx= 0 in pure mode and 1 in pre-hash mode. For ed25519 in pure mode with an empty context,domis the empty string.
-
- Pure and pre-hash modes
-
In pure mode the unit hashes the message itself; in pre-hash mode the caller supplies
PH(M), 64 bytes for both curves, in theHashfield. Which modes an implementation offers depends on the hash extensions it provides:Curve extension Also implements Modes available Zkled25519c—
Ed25519ph only
Zkled25519cZklesha2hEd25519, Ed25519ctx and Ed25519ph
Zkled448c—
Ed448ph only
Zkled448cZklesha3hEd448 and Ed448ph
The curve extension alone must provide enough of
Hto hash the fixed-size inputs above, which are a few hundred bytes at most. Absorbing a message of arbitrary length requires the general hashing machinery, and so requiresZklesha2horZklesha3h, respectively.The AuxInfo field of the MDH (MachineUse and AuxInfo Fields) is used as follows: bit 0 records the modes that a CC may use: pre-hash mode only if it is 0, and pure mode as well if it is 1; bits [2:1] hold
msg_pass(see the State Machine below); bits [7:3] are reserved; and bits [15:8] holdblock_base(Elliptic Curve Cryptography). At provisioning and at import, two cases are unsupported Metadata and raise a KLE unsupported-Metadata exception (Validity of Metadata): bit 0 = 1 on an implementation that does not offer pure mode for the curve, and a non-zero reserved bit. This allows an M-mode handler to emulate pure mode where the hardware does not offer it (Error Handling Architecture); a handler that cannot resolve the exception, including for a reserved value, transitions the locker to Error State Unsupported. Provisioning keeps bit 0 of the PI, and a transition to Ready leaves it unchanged. Provisioning ignores and zeroes bits [2:1] of the PI, and entering State Ready zeroes them. - Data Structures
-
In addition to the fields of Elliptic Curve Cryptography:
-
ctx: 255 bytes, andctxlen: 8 bits, the context string of cite:[RFC8032]. It is optional for ed25519 and mandatory, though possibly empty, for ed448. Both are zero upon provisioning and upon entering State Ready, and are set in State Set_Ctx. -
msg_pass: 2 bits, held in bits [2:1] of AuxInfo. In State Msg_Absorb it identifies the open pass: 0 for signing pass 1, 1 for signing pass 2, and 3 for the verification pass. In any other State it records the last completed pass: 0 for none (also once Sign_Generate has used the passes), 1 for signing pass 1, 2 for signing pass 2, and 3 for the verification pass. -
k':bbits,bin(int(H(dom ‖ R ‖ A ‖ M)) mod L, b), the whole hash read as a little-endian integer and reduced moduloL, computed by signing pass 2 or by the verification pass, and zero otherwise; it is always belowL. It is not secret: anyone holdingR,AandMcan compute it. -
r:bbits, the secret scalar produced by the first signing pass, reduced modulo the group orderL.
There is no stored pre-hash mode selector: the mode is inferred from the path taken, as described below.
RndNumis not used: the EdDSA nonce is deterministic by construction, being derived fromprefixand the message. Its absence is deliberate;j= 0, so Position vi of Elliptic Curve Cryptography is always empty. Bit 3 of StateExtension,HasRndNumin the other ECC Machines, is insteadHasHashState(Table 6): it is set on entering State Msg_Absorb and cleared on leaving it, so that it is set exactly while a pass is open, including across the same-State re-entry that ends one pass and opens the next. A StateExtension @ State withHasHashStateset in a State other than Msg_Absorb, or clear in Msg_Absorb, is not supported by the Machine: an SCC that carries it is invalid Metadata (Validity of Metadata). It does not follow the pattern of Rule MR14, since it records no loaded field.The clamped scalar
sand the 32-byte or 57-byteprefix, respectively, are derived from the seed by hashing it withH, as cite:[RFC8032] §5.1.5 and §5.2.5 prescribe. An implementation may recompute them on each use or cache them in the ADS. The public keyAis likewise derived from the seed, or cached in the ADS.-
Serialized Content: the serialized content of Elliptic Curve Cryptography, with the following fields appended.
Pos. Type Size (Bits) Field vii
Private
8
ctxlenviii
Private
2040
ctxix
Private
brx
Private
bk'xi
Private
hsThe state of
H, zero while no pass is openxii
Private
If MachinePolicy[0] = 1:
hs, else: 0The state of
H', zero except in signing pass 2xiii
Private
0 for ed25519, 112 for ed448
Padding
hsis the length of the Serialized Content of the hash Machine ofH, without a key or MDH and withcumul_lenpresent: for ed25519 that of SHA-512 (SHA-2 Family Specific Rules), 1664 bits, and for ed448 that of SHAKE256 (SHA-3 Family Specific Rules), 1792 bits with its padding to a multiple of 128 bits. Positions xi and xii hold the state ofH, resp.H', in that layout, withlast_block_lenandout_lenzero. The state ofHis always present, MachinePolicy being never 0 for EdDSA, and that ofH'whenever MachinePolicy[0] is set, so that the length ofContent1depends only on MachinePolicy (Length of External Formats and KLF Capacity Usage of a Locker). Akl.rstrlorkl.rstrvthat clears MachinePolicy[0] (kl.rstrl, kl.rstrh, and kl.rstrv) destroys the state ofH', and leavesHasHashStateunchanged.randk'are present unconditionally, and hold zero whenever no signing operation, resp. no signing or verification operation, is in progress.The state of an open pass is architected: msg_passidentifies the pass, andContent1carriesr,k'and the hash states, so that an export and import, also to a different implementation, resumes the pass where it stopped. Making the presence ofrandk'conditional onmsg_passwould only complicate the Machine;r, 256 bits for ed25519 and 456 for ed448, adds little to an SCC of this size, and stays confidential in the encrypted part ofContent1. -
- State Machine
-
-
States: those of Elliptic Curve Cryptography, and in addition
-
Msg_Absorb (11), in which message data is absorbed.
-
Set_Ctx (12), in which the context string is set.
-
-
Allowed State Transitions: those of Elliptic Curve Cryptography, with the following changes:
-
Set_Ctx is a Set state: the transitions of Elliptic Curve Cryptography into and out of the Set states apply to it.
-
Msg_Absorb:
-
is entered, by the Form B
kl.setstdescribed below, from Ready, any Set state, Set_Ctx included, or Msg_Absorb itself; the Machine allows this same-Statekl.setst(Rule GR19.2), which marks a pass boundary; -
is left only for Msg_Absorb, Sign_Generate, Sign_Verify, Ready or an Error State; a
kl.setstnaming any other State transitions the locker to Error State Invalid.
-
-
If, in Msg_Absorb, a
kl.rstrlorkl.rstrv(kl.rstrl, kl.rstrh, and kl.rstrv) clears MachinePolicy[0] during signing pass 1 or 2, or MachinePolicy[1] during the verification pass (Rule GR20):-
a
kl.setstthat ends a signing pass is admitted only if it names Ready, which abandons the pass; otherwise Rule MR1 applies.
-
-
MachinePolicy = 0 is invalid for EdDSA (Validity of Metadata), at provisioning and as the result of a
kl.rstr*. -
These entry conditions (Rule MR1) replace those of Elliptic Curve Cryptography, in addition to the gating by MachinePolicy:
-
Point_Mul:
Scalarholds a configured seed. -
Sign_Generate:
Scalarholds a configured seed, and eithermsg_pass= 2 (pure mode) ormsg_pass= 0 andHasHash(pre-hash mode). -
Sign_Verify:
HasSecondPtandHasSignature, and eithermsg_pass= 3 (pure mode) ormsg_pass= 0 andHasHash(pre-hash mode).
-
-
-
Behavior:
-
In State Point_Mul, the Behavior of Elliptic Curve Cryptography applies, except that the multiplier is the secret scalar
sderived from the seed (cite:[RFC8032] §5.1.5, resp. §5.2.5, steps 1 to 3):SecondPt←[s]P. -
Signature generation and verification use the base point
Bof cite:[RFC8032] §5.1, resp. §5.2, whateverGeneratorholds:-
R←[r]B; -
the public key
Aderived from the seed is[s]B; -
verification checks its equation over
B; -
the validity check of
Generator(Elliptic Curve Cryptography) applies only to Point_Mul.
-
-
In pure mode, signature generation takes two passes over the message, and verification one (Msg_Absorb below); for these passes:
-
entering Ready clears
msg_pass,randk'; -
r,k'andSignature, which the passes compute, are not material of Sign_Generate or Sign_Verify under Rule GR38: a restarted operation uses them as held.
-
-
Entering Set_Ctx:
-
A Form B
kl.setstis used, whoseXssetsctxlen; a value greater than 255 transitions the locker to Error State Invalid. -
If
ctxlen≠ 0, Form Bkl.execinstructions then load thectxlenbytes ofctx, whose other bytes stay zero, following Rule MR14 as the Set states of Elliptic Curve Cryptography do, with the progress recorded inblock_base; a load left incomplete zeroesctxandctxlen(Rule MR14).
-
-
Entering Msg_Absorb (pure mode only) is done by a Form B
kl.setstwhoseXsselects the pass:-
The
kl.setstrequires bit 0 of AuxInfo to be 1 (Rule MR1). -
Xsis not themax_lenof Macro: Processing Variable Length Inputs into a Fixed Length Output, which is 0. -
Each pass has its own entry conditions (Rule MR1) and entry operations:
-
Xs= 0, signing pass 1:-
requires that signature generation be allowed and that
Scalarhold a configured seed; -
sets
msg_pass← 0 andk'← 0; -
initializes
Hwithdom ‖ prefix.
-
-
Xs= 1, signing pass 2:-
requires
msg_pass= 1; -
initializes
Hwithdom ‖ R ‖ A, withRfromSignatureandAderived from the seed; -
initializes a second instance
H'withdom ‖ prefix, as in pass 1;H'absorbs the same message bytes and recomputesr, which finalization compares with therof pass 1.
-
-
Xs= 2, verification pass:-
requires that signature verification be allowed and that
HasSignatureandHasSecondPthold; -
sets
msg_pass← 3 andk'← 0; -
initializes
Hwithdom ‖ R ‖ A, withRfromSignatureandA=SecondPt.
-
-
Any other value of
Xstransitions the locker to Error State Invalid.
-
Initializing
H, orH', with a stringxsets that instance as entering Ready of the hash Machine ofHdoes (SHA-2 Family Specific Rules for ed25519, SHA-3 Family Specific Rules for ed448), with all its counters zero,last_block_lenandout_lenincluded, and then absorbsxas akl.execin Hash_Absorb of that Machine would, counting it in thecumul_lenof that instance. At pass finalization, thefinalize()of SHA-2 Family Specific Rules encodes for SHA-512 the length of the whole input of the instance, as cite:[nist-fips-180-4] §5.1.2 requires. -
-
In State Msg_Absorb, Form B
kl.execinstructions absorb message bytes intoH, and in signing pass 2 also intoH':-
Each
kl.execinvokes macroPROCESS_VLI(Macro: Processing Variable Length Inputs into a Fixed Length Output) as
PROCESS_VLI(max_len=0, H.block, H.b, H.state, H.n, input_base, H.block_base, 0, H.cumul_len, H.process_block(), None, mode, granularity=8). -
In signing pass 2, it also invokes it with
H'in place ofH; the two invocations shareinput_baseand run in lock step:-
each byte is absorbed into
Hand intoH'before the next one; -
step 3.i of Macro: Processing Variable Length Inputs into a Fixed Length Output, the interruption point, applies only to the invocation for
H.
-
-
In each invocation:
-
H.block,H.b,H.state,H.n,H.block_baseandH.cumul_lenare the buffer, block size, state, state size, and partial-block and cumulative-length counters, in bits, of the hash instanceH, and likewise forH'; forSHAKE256,H.blockisH.state(SHA-3 Family Specific Rules); -
H.block_baseis distinct from the byte counterblock_baseof Elliptic Curve Cryptography, which Msg_Absorb does not use; -
H.process_block()applies the compression function, resp. the permutation, ofH; -
H.cumul_lenis tracked, since the unit appends the padding, and for SHA-512 the length, at pass finalization; -
modeisassignfor ed25519, whoseHisSHA-512(SHA-2 Family Specific Rules), andxor_accumulatefor ed448, whoseHisSHAKE256.
-
The interruption points of Msg_Absorb are those of the invocation for
H(Macro: Processing Variable Length Inputs into a Fixed Length Output): 0 and, ifH.block_baseis 0 when the instruction is issued, every byte offset. In signing pass 2,H'may then hold a partial block, which is architected (Position xii). -
-
Leaving Msg_Absorb for Msg_Absorb (the same-State re-entry above), Sign_Generate or Sign_Verify finalizes the current pass:
-
after pass
Xs= 0:-
r←bin(int(H(dom ‖ prefix ‖ M)) mod L, b), -
Signature.R←[r]B, andSignature.S← 0, -
msg_pass← 1, and -
HasSignatureis cleared:Signature.Rholds an intermediate value, and a signature loaded before is discarded; being part of the signature,Ris public (Rule GR9), and reveals neitherrnor the key;
-
-
after pass
Xs= 1:-
if
int(H'(dom ‖ prefix ‖ M)) mod L≠int(r), the locker transitions to Error State Invalid; -
otherwise
k'←bin(int(H(dom ‖ R ‖ A ‖ M)) mod L, b)andmsg_pass← 2;
-
-
after pass
Xs= 2:k'as above, andmsg_passremains 3.
Leaving it for Ready abandons the pass without finalizing it: no hash is completed and no binding check is made. A
kl.setstthat enters or leaves Msg_Absorb is long-running; whether it is resumable is implementation-defined (Rule GR36). -
-
In State Sign_Generate, a single Form D
kl.execcompletes the signature per cite:[RFC8032] §5.1.6, resp. §5.2.6:-
In pure mode (
msg_pass= 2):-
RisSignature.R, which signing pass 1 set; -
S←(r + k'×s) mod L.
-
-
In pre-hash mode (
msg_pass= 0), withHashholdingPH(M):-
r←int(H(dom ‖ prefix ‖ Hash)) mod L; -
R←[r]B; -
k'←int(H(dom ‖ R ‖ A ‖ Hash)) mod L; -
S←(r + k'×s) mod L; -
these
r,Randk'are intermediate results of the operation (Rule GR37): the fieldsrandk'stay zero.
-
-
In both modes:
-
Signature← (R,S), andHasSignatureis set; -
randk'are destroyed, andmsg_pass← 0; -
OutputType← signature, and the locker transitions to Output.
-
-
-
In State Sign_Verify, a single Form D
kl.execverifiesSignatureper cite:[RFC8032] §5.1.7, resp. §5.2.7:-
in pure mode if
msg_pass= 3, with thek'of the verification pass; in pre-hash mode ifmsg_pass= 0, withk'computed internally,Hash(holdingPH(M)) standing in for the message; -
the checks of step 1 of those sections are performed:
S<L, andRandAdecode;Aneed not lie in the subgroup of orderL; -
the equation checked is the cofactored one, [2c][S]B = [2c]R + [2c][k']A, with
c= 3 for ed25519 and 2 for ed448 (cite:[nist-fips-186-5] §7.7, step 3, and, in pre-hash mode, §7.8.2, step 4); -
if a check fails, or the equation does not hold, the locker transitions to Failure, else to Success; in either case
k'is zeroed.
-
-
-
|
Post-Quantum Public-Key Cryptography
ML-KEM
NIST announced the Module-Lattice-Based Key-Encapsulation Mechanism Standard in August 2024 cite:[nist-fips-203]. The standard defines several procedures, including:
-
ML-KEM.KeyGen: Generates an encapsulation keyencapskand a corresponding decapsulation keydecapsk. -
ML-KEM.Encaps: Uses the encapsulation keyencapskto generate a shared secret keysharedkeyand an associated ciphertext. -
ML-KEM.Decaps: Uses the decapsulation keydecapskto produce a shared secret keysharedkeyfrom a ciphertext.
ML-KEM comes in three versions, ML-KEM-512, ML-KEM-768, and ML-KEM-1024, with increasing cryptographic strength. They require RBGs of security strength at least 128, 192, and 256 bits, respectively (cite:[nist-fips-203]). The sizes of keys and ciphertexts of the three subtypes of ML-KEM are summarized in Table 8.
| Subtype | encapsk |
decapsk |
ciphertext |
sharedkey |
|---|---|---|---|---|
ML-KEM-512 |
800 |
1632 |
768 |
32 |
ML-KEM-768 |
1184 |
2400 |
1088 |
32 |
ML-KEM-1024 |
1568 |
3168 |
1568 |
32 |
The granularity of the ML-KEM Machines is 8 bits: a field can be transferred with any SEW from 8 to 64 bits that divides its size, or through the KLIOBUF in any number of bytes.
In State sharedkey_Output, one kl.derive (kl.derive) moves the sharedkey that Encapsulate or Decapsulate produced into a second, already provisioned locker.
The destination is a key field of a symmetric Machine, or the kl.exec input of a hash function, MAC or XOF, that Derivation Endpoints of the Machines lists as a destination (Rule GR31.1).
With MachineExtension = 1, the sealed variant, sharedkey is moreover a sealed source (Rule GR31.3); the variant is unsupported Metadata where not implemented (Validity of Metadata).
- Data Structures
-
-
The Provisioning Input contains only the MDH.
-
MachinePolicy is not used and must be zero; a non-zero value is unsupported Metadata (Validity of Metadata). No State is gated by it (Rule MR1), and a
kl.rstrlorkl.rstrvleaves it zero (kl.rstrl, kl.rstrh, and kl.rstrv). -
Internal State:
-
decapsk: 13056 / 19200 / 25344 bits (1632 / 2400 / 3168 bytes), the stringdk_PKE ‖ ek ‖ H(ek) ‖ zof cite:[nist-fips-203] Algorithm 16, wheredk_PKEhas 384·kbytes,ekhas 384·k+ 32 bytes, andH(ek)andzhave 32 bytes each (k= 2, 3, 4). -
encapsk: 6400 / 9472 / 12544 bits (800 / 1184 / 1568 bytes). It is not stored separately: it is theeksub-field ofdecapsk, at byte offset 384·k(768 / 1152 / 1536). When only an encapsulation key is held, the other bytes ofdecapskare zero. -
HasEncapsk,HasDecapsk: Booleans, recording whetherencapsk, resp. a completedecapsk, holds a configured value. They are bits 0 and 1 of StateExtension, resp., and follow the pattern of Rule MR14, with the departures stated below. -
HasCiphertext: Boolean, bit 2 of StateExtension, recording whetherciphertextholds a complete value, loaded and checked, or computed by Encapsulate. It follows the pattern of Rule MR14. -
HasSharedKey: Boolean, bit 3 of StateExtension, recording whethersharedkeyholds the key that Encapsulate or Decapsulate produced, whatever its value, zero included. It is set when that operation completes, and cleared wheneversharedkeyis zeroed. A StateExtension @ State with sharedkey_Output andHasSharedKeyclear is not supported by the Machine: an SCC that carries it is invalid Metadata (Validity of Metadata). -
ciphertext: 6144 / 8704 / 12544 bits (768 / 1088 / 1568 bytes). -
sharedkey: 256 bits.
encapsk,decapsk, resp.sharedkeycorrespond toek,dk, resp.Kin cite:[nist-fips-203].In the States that load a long field (encapsk_Input, decapsk_Input and ciphertext_Input) or emit one (encapsk_Output and ciphertext_Output), MachineUse records the number of bytes transferred so far. It is the transfer counter W of Rule MR14, which the ECC Machines keep in
block_baseinstead (Elliptic Curve Cryptography). -
-
Serialized Content:
Pos. Type Size (Bits)
for ML-KEM-512/768/1024Field i
Public
6400 / 9472 / 12544
The
eksub-field ofdecapsk, that isencapsk.ii
Public
256
The
H(ek)sub-field ofdecapsk.iii
Public
6144 / 8704 / 12544
ciphertextiii.a
Public
0 / 0 / 0
Padding
iv
Private
6144 / 9216 / 12288
The
dk_PKEsub-field ofdecapsk.iv.a
Private
0 / 0 / 0
Padding
v
Private
256
The
zsub-field ofdecapsk.vi
Private
256
sharedkeyvi.a
Private
0 / 0 / 0
Padding
Positions i to iii.a are the public fields and their padding (Rule GR9), and
SCC_ClearLen1is 100, 144 and 198 for ML-KEM-512, ML-KEM-768 and ML-KEM-1024. With onlyencapskheld, Positions ii, iv and v are zero. TheekandH(ek)sub-fields hold only a value loaded or computed for them, a partial load included, or zero, andciphertextonly a ciphertext loaded or computed by Encapsulate: Decapsulate never writes the re-encryption of cite:[nist-fips-203] Algorithm 18 into a field.These contexts are large: for ML-KEM-512, ML-KEM-768 and ML-KEM-1024 the serialized content is 2432, 3520 and 4768 bytes, that is 152, 220 and 298 blocks of 128 bits;
encapsktakes no space of its own, since it is held in theeksub-field ofdecapsk, which the Serialized Content splits into its sub-fields.
-
- Machine-Specific Functions
-
The procedures implemented by ML-KEM are taken directly from cite:[nist-fips-203]:
-
ML-KEM.KeyGen()(cite:[nist-fips-203] Algorithm 19) draws the random seedsd,zand computes the encapsulation keyencapskand the decapsulation keydecapskas (encapsk,decapsk) =ML-KEM.KeyGen_internal(d, z)(Algorithm 16). -
ML-KEM.Encaps(encapsk)(cite:[nist-fips-203] Algorithm 20) draws the randomnessmand computes the shared keysharedkeyand the ciphertextciphertextas (sharedkey,ciphertext) =ML-KEM.Encaps_internal(encapsk, m)(Algorithm 17). -
ML-KEM.Decaps(decapsk, ciphertext)computes the shared keysharedkeyfrom the decapsulation keydecapskand the ciphertextciphertext(cite:[nist-fips-203] Algorithm 21).
The loop of
SampleNTT(cite:[nist-fips-203] Algorithm 7) iterates an indeterminate number of times (cite:[nist-fips-203] Appendix B). An implementation bounds it by an implementation-defined limit of at least 280 iterations (cite:[nist-fips-203] Appendix B, Table 4), which a correct execution reaches with a probability of at most 2-261. As in cite:[nist-fips-203], the execution time need not be independent of the number of iterations (SCProtection Field). When the limit is reached, the operation ends without output: it destroys its intermediate values and any value drawn for it, and zeroes MachineUse. The state machine then transitions to Failure.cite:[nist-fips-203] Appendix B recommends not bounding the loop; KLE requires a bound, as for ML-DSA, so that every operation ends in bounded time. -
- State Machine
-
-
States: Besides Ready (1) and Failure (55), ML-KEM Machines define the following States:
-
GenerateKeyPair (2)
-
Encapsulate (3)
-
Decapsulate (4)
-
encapsk_Input (5)
-
decapsk_Input (6)
-
encapsk_Output (7)
-
ciphertext_Input (8)
-
ciphertext_Output (9)
-
sharedkey_Output (10)
-
-
Allowed State Transitions:
-
By
kl.setst, under the entry conditions given below:-
from Ready or any other State listed above except Failure, to another of Ready, GenerateKeyPair, Encapsulate, Decapsulate, encapsk_Input, decapsk_Input, ciphertext_Input, encapsk_Output or ciphertext_Output;
-
from Failure, only as Rule GR19.3 allows;
-
in encapsk_Input, decapsk_Input and ciphertext_Input, to the same State, which restarts the load (Rule GR19.2).
-
-
On completion of its
kl.exec: GenerateKeyPair → encapsk_Output; Encapsulate → ciphertext_Output; Decapsulate → sharedkey_Output. -
When a
SampleNTTlimit is reached (see above): GenerateKeyPair, Encapsulate or Decapsulate → Failure. -
Once its field has been completely emitted: encapsk_Output → Ready; ciphertext_Output → sharedkey_Output if
HasSharedKeyis set, as after Encapsulate, and → Ready otherwise. -
On the first committed unit of a
kl.deriveofsharedkey: sharedkey_Output → Ready. -
Once its field has been completely loaded: ciphertext_Input → Ready, or → Failure if the ciphertext type check fails; encapsk_Input → Failure if the encapsulation key check fails.
-
When an import restores an
encapskthatHasEncapskmarks and that fails the encapsulation key check: → Failure. -
sharedkey_Output is entered only by these transitions (Rule MR18).
-
ML-KEM Machines never enter Success.
-
-
Behavior:
-
Provisioning:
-
clears
decapsk(and with itencapsk),ciphertextandsharedkey; -
clears
HasEncapsk,HasDecapsk,HasCiphertextandHasSharedKey; -
zeroes MachineUse.
-
-
Entering Ready:
-
zeroes
sharedkeyand MachineUse; -
keeps
decapsk(and with itencapsk),ciphertext,HasEncapsk,HasDecapskandHasCiphertext.
-
-
Leaving:
-
sharedkey_Output zeroes
sharedkey; -
ciphertext_Output for a State other than sharedkey_Output also zeroes
sharedkey.
-
-
Entering:
-
encapsk_Input zeroes the whole
decapskfield and clearsHasEncapskandHasDecapsk; the load writes theencapsksub-field, so that the locker then holds an encapsulation key only; -
decapsk_Input zeroes the whole
decapskfield, with itsencapsksub-field, and clearsHasEncapskandHasDecapsk; -
ciphertext_Input zeroes
ciphertextandsharedkey, and clearsHasCiphertext; -
Encapsulate or Decapsulate zeroes
sharedkey.
-
-
No
kl.setstof this Machine takes an auxiliary parameter. -
The input checks of cite:[nist-fips-203] §7.2 and §7.3 are performed when a field is written (Rule MR3):
-
a field is written when its load completes, and when an import restores a key that
HasEncapskorHasDecapskmarks as configured; -
a system-specific import (Rule GR51) checks a converted
decapsk,encapskorciphertextas a completed load of that field does, with the same outcomes, and setsHasEncapsk,HasDecapskandHasCiphertextas that load sets them (Rule MR4); -
a
kl.setstthat leaves encapsk_Input, decapsk_Input or ciphertext_Input before the field is complete zeroes the field (the wholedecapskfor decapsk_Input; Rule MR14):HasEncapskandHasDecapsk, resp.HasCiphertext, stay clear; -
departing from Rule MR14, excess data in the final loading transfer of
encapsk,decapskorciphertextfails the type check; -
the checks and their outcomes are, for each field:
-
encapsk: the encapsulation key check of cite:[nist-fips-203] §7.2:-
it is the type check (
encapskhas the length required by the parameter set) and the modulus check (encapskre-encodes to itself, that is, every coefficient is reduced moduloq); -
a failure is a data error (Rule MR2) when the
encapskwas loaded in encapsk_Input, or imported withHasEncapskset: the wholedecapskfield is zeroed,HasEncapskandHasDecapskare cleared, and the state machine transitions to Failure.
-
-
decapsk: the decapsulation key check of cite:[nist-fips-203] §7.3:-
it is the type check and the hash check (the copy of
H(encapsk)embedded indecapskmatches the embeddedencapsk); -
a failure is a configuration error: the locker transitions to Error State Invalid;
-
when the load completes, the encapsulation key check is also performed on the embedded
encapsk; -
a completed load that passes the decapsulation key check sets
HasDecapsk, and alsoHasEncapskif the embeddedencapskpasses the encapsulation key check; a failure of that check only leavesHasEncapskclear.
-
-
ciphertext: when the load completes, the ciphertext type check of cite:[nist-fips-203] §7.3:-
a
ciphertextloaded without excess data passes it:HasCiphertextis set, and the state machine transitions to Ready; -
a failure is a data error:
ciphertextis zeroed,HasCiphertextstays clear, and the state machine transitions to Failure.
-
-
These checks do not affect the implicit rejection of ML-KEM.Decaps: a ciphertext that passes the type check but does not decapsulate correctly still yields thez-derived shared key, and the state machine still transitions to sharedkey_Output. -
-
In States GenerateKeyPair, Encapsulate and Decapsulate the operation is long-running:
-
MachineUse is the field P of Rule GR38, and, when it is non-zero, the interrupted operation is resumed or restarted as per that Rule;
-
its random values and intermediate values are kept in the ADS (Rule GR37);
-
on completion, the operation destroys the values drawn for it and its intermediate values, except those that its result holds, such as
zindecapsk; -
values computed from
encapskordecapskalone, in any representation, masked shares included, may be kept in the ADS until that field is replaced or erased (AuxDataLen and ADSDropped Fields); KLE treats them as a representation of that key and protects them as the key itself, although cite:[nist-fips-203] §3.3 names only the seed and the matrix  as values that may be kept.
-
-
In State GenerateKeyPair, a Form D
kl.execgenerates a new key pair withML-KEM.KeyGenof cite:[nist-fips-203] (Algorithm 19):-
besides a
SampleNTTlimit (see above), only the RBG can make it fail: Rule GR45 applies if the RBG fails; -
otherwise
decapsk(and with itencapsk) receives the new key pair,HasEncapskandHasDecapskare set, and the state machine transitions to encapsk_Output, to emit the public key; -
leaving encapsk_Output keeps the key pair, whatever State follows; entering encapsk_Input or decapsk_Input discards it (see above).
-
-
Entering Encapsulate requires
HasEncapsk(Rule MR1). In it, a Form Dkl.execappliesML-KEM.Encapsof cite:[nist-fips-203] (Algorithm 20) toencapsk:-
it draws one random value, from which it derives both the shared key and the ciphertext;
-
besides a
SampleNTTlimit, only the RBG can make it fail: Rule GR45 applies if the RBG fails; -
otherwise it stores the two values in
sharedkeyandciphertext,HasSharedKeyandHasCiphertextare set, and the state machine transitions to ciphertext_Output.
-
-
Entering Decapsulate requires
HasDecapskandHasCiphertext(Rule MR1). In it, a Form Dkl.execappliesML-KEM.Decapsof cite:[nist-fips-203] (Algorithm 21):-
it runs for any ciphertext, and fails only on a
SampleNTTlimit; -
it places in
sharedkeythe shared key derived from the ciphertext or, by implicit rejection, the one derived fromz, setsHasSharedKey, and the state machine transitions to sharedkey_Output; -
nothing but the value of
sharedkeymay depend on which of the two keys it placed:-
not the execution time;
-
not any field of the locker, MachineUse included;
-
not the AuxDataLen of an SCC exported while the operation is under way;
-
-
the SCProtection level of the locker (SCProtection Field) governs the other physical leakage of the operation.
A side channel of the decryption or of the re-encryption within Decapsulate, such as one that shows whether the decrypted message equals a value the caller chose, is a plaintext-checking oracle. With a few thousand chosen ciphertexts, it lets a caller recover dk_PKE, and with it the use ofdecapsk. The SCProtection level of the locker sets how far Decapsulate resists it. The value ofsharedkeyitself, which a caller can test throughkl.derive, is no such oracle: cite:[nist-fips-203]ML-KEM.Decapsreturns it to its caller, and ML-KEM is IND-CCA2 secure under that interface.
-
-
In States encapsk_Input, decapsk_Input and ciphertext_Input, Form B
kl.execinstructions loadencapsk,decapskandciphertext: -
In States encapsk_Output and ciphertext_Output:
-
No
kl.execemitssharedkey:-
besides the instructions that move or copy the whole CC, an export and import,
kl.clone,kl.renameandkl.swap, onlykl.derive(kl.derive) moves it, as a field source (Rule GR31.1), and only in State sharedkey_Output (Derivation Endpoints of the Machines); -
that State admits no
kl.exec, and onekl.derive, which transitions the locker to Ready (Rule GR28); -
the
kl.derivereads the field from its first byte: a key field receives its firsteff_lengthbytes, and a message input the whole field, withlength= 32 (Rules GR28, GR29 item 6 and GR31.1).
-
-
-
ML-DSA
NIST announced the Module-Lattice-Based Digital Signature Standard in August 2024 cite:[nist-fips-204]; it has three variants: ML-DSA-44, ML-DSA-65, and ML-DSA-87.
| Subtype | Private Key | Public Key | Signature Size |
|---|---|---|---|
ML-DSA-44 |
2560 |
1312 |
2420 |
ML-DSA-65 |
4032 |
1952 |
3309 |
ML-DSA-87 |
4896 |
2592 |
4627 |
They require RBGs of security strength at least 128 (192 recommended), 192, and 256 bits, respectively, for xi
(cite:[nist-fips-204] §3.6.1); an ML-DSA-44 CC with a 128-bit RBG has security category 1.
The granularity of the ML-DSA Machines is 8 bits: a field can be transferred with any SEW from 8 to 64 bits that divides its size, or through the KLIOBUF in any number of bytes.
The principal functions offered by ML-DSA are:
-
ML-DSA.KeyGen: Generates a public-private key pair. -
ML-DSA.Sign: Generates a digital signature for a given message. -
ML-DSA.Verify: Verifies a digital signature for a given message. -
HashML-DSA.Sign: Generates a digital signature for a given pre-hashed message. -
HashML-DSA.Verify: Verifies a digital signature for a given pre-hashed message.
The KLE ML-DSA Machines execute the core lattice operations of signing and verification, specifically ML-DSA.Sign_internal and ML-DSA.Verify_internal as defined in cite:[nist-fips-204] (Algorithms 7 and 8), with an external message representative μ:
the caller supplies μ in State mu_Input, and the steps of these algorithms that compute μ from tr and the formatted message M'
are not performed. Consequently the Machine never receives the message or the context string ctx, and holds tr only within privkey.
Message hashing and domain formatting (cite:[nist-fips-204] §5) are structured as follows, with ctx a context string of at most 255 bytes, chosen by the protocol, |ctx| its length in bytes, and OID(PH) the DER encoding of the object identifier of PH (cite:[nist-fips-204] §5.4):
-
Pure ML-DSA: The caller formats the domain-separated message string
M' = 0x00 ‖ bin(|ctx|, 8) ‖ ctx ‖ Mand computes the 64-byte message representativemu = SHAKE256(tr ‖ M', 64), which is supplied to the KLE unit via State mu_Input. -
HashML-DSA (Pre-Hash): The caller pre-hashes message
Mwith the hash functionPHspecified in the AuxInfo field of the MDH, constructsM' = 0x01 ‖ bin(|ctx|, 8) ‖ ctx ‖ OID(PH) ‖ PH(M), and computesmu = SHAKE256(tr ‖ M', 64)to be loaded into State mu_Input. For FIPS conformance, cite:[nist-fips-204] (§5.4 and §5.4.1) requiresPH(M)to be computed within a FIPS 140-validated cryptographic module. That module may be the KLE unit itself, if the unit is FIPS 140-validated. -
Public Key Hash (
tr):tr = SHAKE256(pubkey, 64). It is embedded inprivkey(cite:[nist-fips-204] Algorithm 24), whereML-DSA.KeyGenplaces it; the caller computes it from the public key.
|
The caller’s duties in forming μ.
The message representative μ and the string
The Machine cannot check these steps: a μ formed with a wrong |
- Data Structures
-
-
The Provisioning Input consists only of the MDH.
-
MachinePolicy[0] gates signature generation and MachinePolicy[1] signature verification, with their Gated States (Rule MR1).
-
The AuxInfo field is zero for pure
ML-DSA. ForHashML-DSAit records the pre-hash functionPH, in the format of bits [15:0] of the MDH (Machine, MachinePolicy and MachineExtension), which the caller chooses among the hash functions and XOFs that cite:[nist-fips-204] §5.4 admits for the parameter set. The Machine never reads AuxInfo: it neither computesPHnor checks or enforces its use. It keeps the field unchanged, also through provisioning and transitions to Ready, so that the MDH, in the clear, informs the recipients of the CC, which need not implementPH. The caller always computes μ with SHAKE256, whateverPHis (cite:[nist-fips-204] Algorithm 7). -
Internal State:
-
MachineUse, in the MDH, is the transfer counter W of Rule MR14, in bytes, in the States that load or emit a long field. In States GenerateKeyPair, compute_pubKey, Sign_Generate and Sign_Verify, it is the field P of Rule GR38 for their long-running operations, and encodes their progress in an implementation-defined way.
-
HasPrivKey,HasPubKey: Booleans, recording whetherprivkey, resp.pubkey, holds a configured value. They are bits 0 and 1 of StateExtension, resp., and follow the pattern of Rule MR14, with the departures stated below. -
Hedged: Boolean, bit 2 of StateExtension, recording the signing mode selected on entering Sign_Generate. -
HasMu: Boolean, bit 3 of StateExtension, recording thatmuholds a completely loaded μ. It follows the pattern of Rule MR14. -
privkey: 2560/4032/4896 bytes (20480/32256/39168 bits) for ML-DSA-44/65/87, resp. -
pubkey: 1312/1952/2592 bytes (10496/15616/20736 bits) for ML-DSA-44/65/87, resp. -
signature: 2420/3309/4627 bytes (19360/26472/37016 bits) for ML-DSA-44/65/87, resp. -
mu: 64 bytes (512 bits), the external message representative μ -
rnd: 32 bytes (256 bits), the random value of hedged signing; it is non-zero only while a hedged signing operation is interrupted (Rule GR38), and zero otherwise, including for deterministic signing.
-
-
Besides
rnd, the internal state may contain several additional variables, for instance intermediate values of the computation of the NTT. Their definition and their size are implementation-dependent. An interrupted operation keeps them in the ADS, never in the Serialized Content (Rule GR37), so that it can resume on the same implementation; without them, it restarts (Rule GR38). When an operation completes, it destroys the values drawn for it,xiandrndincluded, and its intermediate values; values computed fromprivkeyorpubkeyalone, in any representation, masked shares included, may be kept in the ADS until that field is replaced or erased (AuxDataLen and ADSDropped Fields); KLE treats them as a representation of that key and protects them as the key itself, although cite:[nist-fips-204] §3.6.3 names only the seed and the matrix  as values that may be kept.
-
Serialized Content:
Pos. Type Size (Bits)
for ML-DSA-44/65/87Field i
Public
10496 / 15616 / 20736
pubkeyii
Public
19360 / 26472 / 37016
signatureii.a
Public
96 / 24 / 104
Padding
iii
Private
20480 / 32256 / 39168
privkey(containstr)iii.a
Private
0 / 0 / 0
Padding
iv
Private
512
muv
Private
256
rndv.a
Private
0 / 0 / 0
Padding
Positions i to ii.a are the public fields and their padding (Rule GR9), and
SCC_ClearLen1is 234, 329 and 452 for ML-DSA-44, ML-DSA-65 and ML-DSA-87.pubkeyholds only a public key loaded or computed, a partial load included, or zero, andsignatureonly a signature loaded or completed, or zero: a rejected iteration ofML-DSA.Sign_internalwrites no field.These contexts are large: for ML-DSA-44, ML-DSA-65 and ML-DSA-87 the serialized content is 6400, 9392 and 12224 bytes, that is 400, 587 and 764 blocks of 128 bits, padding included.
Only
HasPrivKey,HasPubKey,HedgedandHasMu, in StateExtension, record state: nothing records whethersignatureholds a value.
-
- Machine-Specific Functions
-
The procedures implemented by ML-DSA are taken directly from cite:[nist-fips-204]:
-
ML-DSA.KeyGen()(cite:[nist-fips-204] Algorithm 1) draws the random seedxiand computes the public keypubkeyand the private keyprivkeyas (pubkey,privkey) =ML-DSA.KeyGen_internal(xi)(Algorithm 6). -
ML-DSA.Sign_internal(privkey, mu, rnd)generates the digital signaturesignaturefrom private keyprivkey, message representativemu, and randomnessrnd(cite:[nist-fips-204] Algorithm 7). -
ML-DSA.Verify_internal(pubkey, mu, signature)verifies the signaturesignatureagainst public keypubkeyand message representativemu(cite:[nist-fips-204] Algorithm 8).
The loops of
ML-DSA.Sign_internal,RejBoundedPoly,RejNTTPolyandSampleInBalliterate an indeterminate number of times (cite:[nist-fips-204] Appendix C). An implementation bounds each by an implementation-defined limit of at least that of cite:[nist-fips-204] Table 3: 814 iterations of the loop ofML-DSA.Sign_internal; 481 iterations, or 481 bytes of XOF output, forRejBoundedPoly; 298 iterations, or 894 bytes of XOF output, forRejNTTPoly; and, forSampleInBall, 121 iterations of the while loop of its step 8 within one iteration of its for loop, or 221 bytes of XOF output for the whole call. A correct execution reaches these limits with probability of about 2-256 or less (cite:[nist-fips-204] Appendix C). As in cite:[nist-fips-204], the execution time need not be independent of the number of iterations (SCProtection Field). A limit reached ends the operation in Failure, without output: its intermediate values and the values drawn for it,xiandrndincluded, are destroyed, and MachineUse is zeroed.cite:[nist-fips-204] Appendix C recommends not bounding these loops; KLE requires the bound, so that every operation ends in bounded time, and the limits of Table 3 are reached by a correct execution with negligible probability. -
- State Machine
-
-
States: Besides Ready (1), Success (54), Failure (55), ML-DSA Machines define:
-
GenerateKeyPair (2)
-
pubkey_Output (3)
-
pubkey_Input (4)
-
mu_Input (6)
-
Sign_Generate (8)
-
Sign_Output (9)
-
Sign_Verify (10)
-
Sign_Input (11)
-
privkey_Input (12)
-
compute_pubKey (13)
-
-
Allowed State Transitions:
-
By
kl.setst, subject to Rules GR19.3, GR19.2 and GR19.5 and to the entry conditions below: between any two different States listed above, and, in privkey_Input, pubkey_Input, mu_Input and Sign_Input, to the same State, which restarts the load. Sign_Output is entered only on completion of Sign_Generate (Rule MR18). -
On completion of its
kl.exec: GenerateKeyPair → pubkey_Output; compute_pubKey → Ready; Sign_Generate → Sign_Output; Sign_Verify → Success or Failure. -
Once its field has been completely emitted: pubkey_Output → Success; Sign_Output → Success.
-
Once its field has been completely loaded, with excess data in the final transfer: pubkey_Input or Sign_Input → Failure.
-
When an implementation-defined loop limit is reached (see above): → Failure.
-
-
Behavior:
-
Provisioning:
-
clears
privkeyandpubkey, and clearsHasPrivKeyandHasPubKey; -
zeroes MachineUse;
-
leaves the locker in Ready.
-
-
Entering Ready:
-
clears
signature,mu,rndandHasMu, and zeroes MachineUse; -
keeps
privkey,pubkey,HasPrivKeyandHasPubKey.
-
-
In State GenerateKeyPair, a Form D
kl.execgenerates a new key pair withML-DSA.KeyGenof cite:[nist-fips-204] (Algorithm 1), from a seedxidrawn from the RBG (Rule GR45):-
the key pair replaces
privkey(which embedstr) andpubkey, andHasPrivKeyandHasPubKeyare set; -
the state machine transitions to pubkey_Output, with MachineUse zeroed; leaving it keeps the key pair.
-
-
Loading
privkey, and system-specific imports:-
entering privkey_Input clears
HasPrivKeyandHasPubKeyand erasespubkey; -
a system-specific import (Rule GR51) that converts a
privkeychecks it as a completed load does, with the same outcomes, and setsHasPrivKey; -
such an import drops any
pubkeythat the format carries:pubkeystays zero andHasPubKeyclear, as entering privkey_Input leaves them, and compute_pubKey then derivespubkey; -
a system-specific import that converts a
pubkeywithout aprivkeysetsHasPubKey, as a completed load does (Rule MR4).
-
-
Entering pubkey_Input:
-
requires
HasPrivKeyto be clear (Rule MR1), and clearsHasPubKey; -
when the load completes without excess data,
HasPubKeyis set.
-
-
In States privkey_Input, pubkey_Input, mu_Input and Sign_Input, Form B
kl.execinstructions loadprivkey,pubkey,muandsignature, respectively, following Rule MR14, with the progress recorded in MachineUse, in bytes. -
The checks of the loaded fields:
-
a
privkeywith a coefficient ofs1ors2outside [−η, η] (cite:[nist-fips-204] Algorithm 25) is a configuration error: the locker transitions to Error State Invalid whenprivkeyis written, by a completed load or by an import withHasPrivKeyset (Rule MR3); -
every
pubkeyof the correct length is well formed (cite:[nist-fips-204] Algorithm 23); -
departing from Rule MR14, excess data in the final loading transfer of
pubkeyorsignatureis a data error (cite:[nist-fips-204] §3.6.2): the field is zeroed,HasPubKeystays clear for apubkey, and the state machine transitions to Failure (Rule MR2); -
a
signatureis not checked when it is loaded: as in cite:[nist-fips-204] Algorithm 8,ML-DSA.Verify_internaldecodes it (Algorithm 27), and rejects a malformedsignature, for which the decoding returns ⊥, as one that does not verify (Rule MR2).
-
-
Entering compute_pubKey requires
HasPrivKey(Rule MR1). In it, a Form Dkl.exec:-
derives
pubkeyfromprivkey: it decodes it with skDecode (cite:[nist-fips-204] Algorithm 25) and applies steps 3, 5, 6 and 8 of Algorithm 6; -
checks that the public key hashes to
tr, embedded inprivkey; if not, the locker transitions to Error State Invalid; -
writes the derived public key into
pubkeyand setsHasPubKey; -
transitions to Ready, which keeps the key pair.
-
-
When entering Sign_Generate, by a Form B
kl.setstwhoseXsselects the signing mode of cite:[nist-fips-204] §3.4:-
the State requires
HasPrivKeyandHasMu(Rule MR1); -
Xs= 0, for instance withXs=X0, selects hedged signing and setsHedged; -
any other
Xsselects deterministic signing and clearsHedged; -
the
kl.setstzeroes MachineUse, so that its progress is counted from entry and tracks the current operation, not the transfer that preceded it.
-
-
In State Sign_Generate, a Form D
kl.execsigns withML-DSA.Sign_internalof cite:[nist-fips-204] (Algorithm 7):-
the operation is long-running, and MachineUse is its field P (Rule GR38);
-
MachineUse reveals at most the number of completed iterations of the signing loop; the challenge, the response and the failed check of a rejected iteration must not be observable, through MachineUse or otherwise;
-
if MachineUse is zero, the operation starts, with
rnddrawn from an approved RBG (Rule GR45) ifHedgedis set, andrnd=zeros(256)otherwise; -
if MachineUse is non-zero, the interrupted operation is resumed with the
rndheld, or restarted (Rule GR38); -
on completion, the output of
ML-DSA.Sign_internalis written insignature, and the locker transitions to Sign_Output.
-
-
Entering Sign_Verify requires
HasPubKeyandHasMu(Rule MR1). In it, a Form Dkl.execverifiessignaturewithML-DSA.Verify_internalof cite:[nist-fips-204] (Algorithm 8):-
if it returns
true, the state machine transitions to Success, otherwise to Failure; -
nothing is written to
signature; -
departing from Rule MR14, Sign_Verify has no entry condition on
signature; it verifies the value thatsignatureholds:-
the signature last loaded in Sign_Input or computed by Sign_Generate since Ready was last entered;
-
zero, if there is none or if the last load was left incomplete.
-
-
-
In pubkey_Output and Sign_Output:
-
MachinePolicy may be narrowed using
kl.rstrlorkl.rstrv(Rule GR20).
-
-
Derivation Endpoints of the Machines
Table 10 lists the architected kl.derive endpoints of the Machines of this Chapter.
| Machine(s) | Field/Operation | Role | State |
|---|---|---|---|
ECB mode, Chaining/feedback modes, Keystream generation, GCM mode, GCM-SIV mode, CMAC mode, OCB mode, Ascon-AEAD128 |
|
destination |
Ready |
|
destination |
Ready |
|
|
destination |
Ready |
|
HMAC, NIK variant |
|
destination |
Set_Key |
Exactly these hash functions, MACs and XOFs: SHA-2, SM3, BLAKE2, SHA-3 and SHAKE, HMAC on SHA-2, SHA-3 and SM3, KMAC and KMACXOF, Ascon-Hash256, Ascon-XOF128 and Ascon-CXOF128 |
|
destination |
Hash_Absorb |
the shared secret as Output emits it, formed from |
source |
Output with |
|
|
source |
sharedkey_Output |
|
the keystream (Rule GR31.2) |
source |
Operate |
|
CMAC, and the hash functions, MACs and XOFs listed above as destinations |
the |
source |
Hash_Output, and Hash_Output_Bits where the Machine has it |
A source and a destination form a pair only as Rules GR31.1–GR31.2 and GR31.3 admit. For now, the admissible pairs move:
-
an ML-KEM
sharedkey, or the shared secret of an x25519 or x448 Machine (X25519- and X448-Specific Rules), into a listed key of a symmetric Machine; a restricted shared secret does not go intoK1 ‖ K2of nonce masking; -
a shared secret of any ECC or ML-KEM Machine into the input of a listed hash function, HMAC, KMAC or XOF, as the input of a key-derivation method of cite:[NIST-SP-800-56Cr2]; for the other ECC Machines, whose shared secret is not a uniform string, this is the only destination, as cite:[NIST-SP-800-56Ar3] §5.8 requires for
Z; -
the keystream of a keystream Machine, or the output of a CMAC, hash function, MAC or XOF Machine, into a listed key of a symmetric Machine, as the key-derivation methods of cite:[NIST-SP-800-56Cr2] and cite:[nist-SP-800-108-r1] produce it;
-
a sealed source (Rule GR31.3) as above, but never into the key of keystream generation, OFB or CMAC, whose outputs are sources, nor into
K1 ‖ K2; a hash, MAC or XOF input, or an HMACK0, that receives it makes its locker sealed.
A destination key field still sets its own length conditions (Rule GR29 item 6): the K0 of
HMAC takes only a source of exactly eff_length bytes, which a keystream or the output of an XOF without bound is not, so
either one into K0 invalidates the destination alone.
A locker of a Machine that Rule MR12 lists, whose tag_len_p is shorter than the full length, is not a destination.
Every such kl.derive is uninterruptible (Rule GR32).