Documentation

CslibFrontier.Crypto.Primitives.SLHDSA.MessageCalls

SLH-DSA message hash and pseudorandom function calls #

This module implements the two FIPS 205 hash calls that process an arbitrary-length message: PRF_msg and H_msg. The inputs retain the exact n-byte seed, root, randomizer, and optional randomness boundaries. The output of H_msg uses the six Table 2 digest lengths derived in ParameterShape.digestBytes.

The SHAKE parameter sets use the specified direct SHAKE256 packages. The SHA2 category 1 sets use HMAC-SHA-256 and SHA-256 followed by MGF1-SHA-256; categories 3 and 5 use the corresponding SHA-512 functions. prfMessage and hMessage are total functions. FIPS 180-4 defines SHA-2 only below a message-length limit, and the docstring of each call states the resulting bound on M. These two calls do not choose the optional randomness and cannot abort.

This module is definitions only: its theorems are the length equations of the byte packages. It supplies no counts of hash, compression or permutation calls and no machine, program-size, gate, qubit or query costs (#4987). It does not prove PRF or ITSR security, correctness of digest slicing, signing or verification, constant-time behavior, FIPS validation, or an EUF-CMA/QROM reduction. The test module CslibFrontierTests.Crypto.SLHDSAMessageCalls evaluates both calls against values computed outside Lean.

Main definitions #

References #

@[reducible, inline]

One standardized m-byte message digest.

def Cslib.Crypto.SLHDSA.prfMessageText {p : SecurityBytes} (optionalRandomness : NBytes p) (message : List Byte) :

The HMAC text opt_rand || M used by the SHA2 PRF_msg calls.

def Cslib.Crypto.SLHDSA.shakePRFMessageInput {p : SecurityBytes} (secretPRF optionalRandomness : NBytes p) (message : List Byte) :

The SHAKE input SK.prf || opt_rand || M used by PRF_msg.

def Cslib.Crypto.SLHDSA.hMessageDigestInput {p : SecurityBytes} (randomizer publicSeed publicRoot : NBytes p) (message : List Byte) :

The common H_msg digest input R || PK.seed || PK.root || M.

def Cslib.Crypto.SLHDSA.hMessageMGFSeed {p : SecurityBytes} {digestBytes : ℕ} (randomizer publicSeed : NBytes p) (digest : FixedBytes digestBytes) :

The SHA2 MGF1 seed R || PK.seed || D, where D is the inner SHA-2 digest.

@[simp]
theorem Cslib.Crypto.SLHDSA.length_prfMessageText {p : SecurityBytes} (optionalRandomness : NBytes p) (message : List Byte) :
(prfMessageText optionalRandomness message).length = p.count + message.length
@[simp]
theorem Cslib.Crypto.SLHDSA.length_shakePRFMessageInput {p : SecurityBytes} (secretPRF optionalRandomness : NBytes p) (message : List Byte) :
(shakePRFMessageInput secretPRF optionalRandomness message).length = 2 * p.count + message.length
@[simp]
theorem Cslib.Crypto.SLHDSA.length_hMessageDigestInput {p : SecurityBytes} (randomizer publicSeed publicRoot : NBytes p) (message : List Byte) :
(hMessageDigestInput randomizer publicSeed publicRoot message).length = 3 * p.count + message.length
@[simp]
theorem Cslib.Crypto.SLHDSA.length_hMessageMGFSeed {p : SecurityBytes} {digestBytes : ℕ} (randomizer publicSeed : NBytes p) (digest : FixedBytes digestBytes) :
(hMessageMGFSeed randomizer publicSeed digest).length = 2 * p.count + digestBytes
def Cslib.Crypto.SLHDSA.prfMessage (family : HashFamily) {p : SecurityBytes} (secretPRF optionalRandomness : NBytes p) (message : List Byte) :

FIPS 205 PRF_msg(SK.prf, opt_rand, M) from Sections 11.1--11.2.2.

The SHAKE branch is the FIPS 205 value for every message. In the SHA2 branch the inner HMAC hash reads one padded key block followed by opt_rand ‖ M, and FIPS 180-4 defines SHA-256 only below 2 ^ 61 input bytes and SHA-512 only below 2 ^ 125. The SHA2 branch is therefore the FIPS 205 value when 64 + n + |M| < 2 ^ 61 at n = 16 and when 128 + n + |M| < 2 ^ 125 at n = 24, 32. For a longer message the standards define no value, and this function returns what the total evaluators HMAC.hmacSHA256 and HMAC.hmacSHA512 return.

def Cslib.Crypto.SLHDSA.hMessage (family : HashFamily) {p : SecurityBytes} (shape : ParameterShape) (randomizer publicSeed publicRoot : NBytes p) (message : List Byte) :

FIPS 205 H_msg(R, PK.seed, PK.root, M) from Sections 11.1--11.2.2.

The SHAKE branch is the FIPS 205 value for every message. In the SHA2 branch the inner digest hashes R ‖ PK.seed ‖ PK.root ‖ M, and FIPS 180-4 defines SHA-256 only below 2 ^ 61 input bytes and SHA-512 only below 2 ^ 125. The SHA2 branch is therefore the FIPS 205 value when 3 * n + |M| < 2 ^ 61 at n = 16 and when 3 * n + |M| < 2 ^ 125 at n = 24, 32. For a longer message the standards define no value, and this function returns what the total evaluators SHA2.sha256 and SHA2.sha512 return. The MGF1 step adds no condition: its seed has the fixed length 2 * n + 32 or 2 * n + 64 and its output has at most 49 bytes.