Length-strengthened Merkle–Damgård padding #
This module defines the length-strengthened padding block and n-bit block partition of
[BS23], §8.4, Fig. 8.5 (pp. 296–297), proves that the padded message is block-aligned and
that the partition is suffix-free when the block count fits in the length field, and certifies that
the partition is computable in polynomial time. The hash built from it and Theorem 8.3 (p. 297) for
it are not in this module.
Differences from Boneh–Shoup §8.4 #
- Block and length-field widths: the block width
ℓis taken to equal the parametern, and the length field⟨s⟩hasn / 2bits. In the book⟨s⟩is "a fixed-length bit string" and "Typically this field is 64-bits" (p. 296): its width does not depend on the block width. - Encoded count:
mdLengthBlockCount n msgcounts the blocks of the padded messageM̂ = m_1 ‖ ⋯ ‖ m_s(matchinguandvin the proof of Theorem 8.3, p. 297), whereas p. 296 describes⟨s⟩as the number ofℓ-bit blocks inM. - Total domain:
mdLengthPadandmdLengthBlocksare total overmsg : List Bool. WhenmdLengthBlockCount n msg ≥ 2 ^ (n / 2)(includingn < 2),BitString.binaryWord (n / 2) sexceedsn / 2bits andBitString.listRowsdrops bits pasts * n, so the result outside the non-overflow range is not the book's padded message over{0,1}^{≤L}.
Main definitions #
Cslib.Crypto.mdLengthBlockCount: the number ofn-bit blocks produced by length-strengthened padding.Cslib.Crypto.mdLengthPad: the padded bit stringM ‖ PB, wherePB = 1 ‖ 0^k ‖ ⟨s⟩.Cslib.Crypto.mdLengthBlocks: the firstmdLengthBlockCount n msgblocks ofnbits ofmdLengthPad n msg.
Main results #
Cslib.Crypto.length_mdLengthPad: when the block count fits in the length field, the padded message has exactlymdLengthBlockCount n msg * nbits.Cslib.Crypto.flatten_mdLengthBlocks: in that case the blocks concatenate to the padded message.Cslib.Crypto.mdLengthBlocks_suffix_iff: suffix-freeness on messages whose padded block count is less than2 ^ (n / 2).Cslib.Crypto.computableInPolyTime_mdLengthBlocks:mdLengthBlocksis computable in polynomial time.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, v0.6, §8.4, Fig. 8.5 and Theorem 8.3, pp. 296–297
Length-strengthened Merkle–Damgård padded message M ‖ PB, where PB = 1 ‖ 0^k ‖ ⟨s⟩:
1, the minimal number k < n of zeros making the total length a multiple of n when ⟨s⟩ fits
in n / 2 bits, and the (n / 2)-bit big-endian encoding of s = mdLengthBlockCount n msg.
The first s = mdLengthBlockCount n msg consecutive n-bit blocks of mdLengthPad n msg.
When s < 2 ^ (n / 2) they are all of it (flatten_mdLengthBlocks).
Every block produced by mdLengthBlocks n msg has length n.
Block alignment: when the block count fits in the length field, the padded message consists of
exactly mdLengthBlockCount n msg blocks of n bits.
When the block count fits in the length field, the blocks of mdLengthBlocks n msg concatenate
to mdLengthPad n msg: no bit is dropped.
The length-strengthened blocks are suffix-free: when the longer message's padded block count
is less than 2 ^ (n / 2), mdLengthBlocks n m₁ is a suffix of mdLengthBlocks n m₂ if and only
if m₁ = m₂. The proof of [BS23], Theorem 8.3 (p. 297) uses this property of the padding
when it deduces u = v from equal last blocks; the book does not state it separately.
The length-strengthened block partition mdLengthBlocks n msg is computable in polynomial time
from (n, msg) with n in unary and msg as a raw bit list.