Documentation

CslibFrontier.Crypto.Protocols.MAC.VariableLength

Variable-length MACs from fixed-length MACs #

This file extends a fixed-length MAC to messages of varying length with the blockwise construction of [KL20], Construction 4.7. Write L = M.msgLen n and w = L / 4. A message with 0 < |m| < 2 ^ w is cut into w-bit blocks (the last one padded with zeros). The signer samples a uniform w-bit identifier r and applies M to one L-bit input per block, made of r, the message length, the block index and the block itself.

Main definitions #

Main results #

Implementation notes #

The encoder is a parameter, so the construction and its three variants share one definition. Messages outside the domain have no block inputs and never verify. The repeated-identifier bound adds up, query by query, the chance that a new identifier equals an earlier one, which gives Q (Q - 1) / 2 ^ (w + 1). To obtain a uniform strict oracle-PPT reduction without changing the concrete experiment blockwiseReduction, blockwiseBoundedSimulator truncates each fixed-length oracle reply to tagBound n bits; when tagBound covers all honest tags of M.sign, this agrees identically with blockwiseSimulator.

References #

The width L / 4 of each field of an L-bit block input.

The number of w-bit blocks, rounded up, in a len-bit message.

Block i (counting from 0) of m, padded with zeros to exactly w bits.

@[reducible, inline]

A block encoder takes a field width, an input length, an identifier, a message length, a block index and a block, and returns an input for the fixed-length MAC.

def Cslib.Crypto.BlockwiseMAC.fullEncoder (w L : ℕ) (r : List Bool) (len idx : ℕ) (block : List Bool) :

The encoder of the construction: identifier, length, index, block, then zero padding.

def Cslib.Crypto.BlockwiseMAC.noIdentifierEncoder (w L : ℕ) (_r : List Bool) (len idx : ℕ) (block : List Bool) :

Insecure variant that omits the identifier.

def Cslib.Crypto.BlockwiseMAC.noLengthEncoder (w L : ℕ) (r : List Bool) (_len idx : ℕ) (block : List Bool) :

Insecure variant that omits the message length.

def Cslib.Crypto.BlockwiseMAC.noIndexEncoder (w L : ℕ) (r : List Bool) (len _idx : ℕ) (block : List Bool) :

Insecure variant that omits the block index.

The fixed-length inputs that encoder E assigns to m under identifier r, one per block, with indices starting at 1. The list is empty unless 0 < |m| < 2 ^ w.

@[reducible, inline]

A blockwise tag: the identifier together with one fixed-length tag per block.

The fixed-length inputs covered by a log of blockwise signing queries (newest first), listed in the order in which the fixed-length signing oracle logs them.

The first block input of msg, paired with its tag, that the logged queries do not cover, or ([], []) if every block input is covered.

theorem Cslib.Crypto.BlockwiseMAC.eq_of_messageBlock_eq {w : ℕ} {m m' : List Bool} (hw : 0 < w) (hlen : m.length = m'.length) (hblock : ∀ i < blockCount w m.length, messageBlock w m i = messageBlock w m' i) :
m = m'

Two messages of the same length with the same blocks are equal.

The number of block inputs of a message m is at most m.length.

Encodings and polynomial-time certificates #

@[reducible, inline]

Binary encoding of a blockwise tag (r, tags).

@[reducible, inline]

Binary encoding of a candidate message/tag forgery (msg, tag).

@[reducible, inline]

Binary encoding of a blockwise signing log List (List Bool × Tag).

@[reducible, inline]

Binary encoding of the inputs (n, sk, m) to MACScheme.blockwiseSign.

@[reducible, inline]

Binary encoding of the inputs (n, sk, m, tag) to MACScheme.blockwiseVerify.

@[reducible, inline]

Binary encoding of the six arguments (w, L, r, len, idx, block) to a block Encoder.

@[reducible, inline]

Binary encoding of the arguments (L, log, msg, tag) to freshBlockPair.

A block Encoder is polynomial-time when it is computable in polynomial time with unary widths/lengths/indices and bit-string identifier/block inputs.

@[reducible, inline]

An adaptive adversary against a variable-length MAC: on security parameter n it queries a blockwise signing oracle and outputs a candidate message/tag pair.

@[reducible, inline]

A uniform adaptive word-oracle forger against a variable-length MAC: on security parameter n and auxiliary word aux, it queries the single-channel word oracle on messages m : List Bool (receiving encoded blockwise tags BlockwiseMAC.encTag tag : List Bool) and outputs a candidate forgery (msg, tag).

Embed a uniform word-oracle forger as a BlockwiseMACAdversary by running it on empty auxiliary input [] and encoding each returned BlockwiseMAC.Tag with BlockwiseMAC.encTag.

Convert a BlockwiseMACAdversary into a BlockwiseMACForger by answering each signing query m with BlockwiseMAC.tagDecoder.decode of the first replyBound n m.length bits of the external word-oracle reply.

Blockwise signing: sample a w-bit identifier r, then tag every block input with M.

Blockwise verification: the message is in the domain, the identifier has w bits, there is one tag per block, and M accepts every block input with its tag.

The blockwise signing oracle; its state logs each query with the returned tag, newest first.

The fresh-message EUF-CMA experiment for the blockwise scheme: the adversary wins when it outputs a message it never queried together with a tag that blockwiseVerify accepts.

The same experiment, reporting instead whether two signing queries received the same identifier.

Answers a blockwise signing query with fixed-length signing queries, one per block input, and logs the query.

The fixed-length adversary of the reduction: run the blockwise adversary against blockwiseSimulator, then output the first block input of its message that no simulated query covered, with the matching block tag.

The blockwise success probability is at most the EUF-CMA success of blockwiseReduction against M plus the probability that two signing queries share an identifier.

Correctness of the blockwise scheme: an honest tag on a message in the domain verifies.

If the adversary makes at most Q signing queries, two queries share an identifier with probability at most (∑ i ∈ range Q, i) / 2 ^ w.

Concrete security of the blockwise construction against an adversary with at most Q signing queries: this is the concrete inequality behind [KL20], Theorem 4.8. Because blockwiseReduction forwards arbitrary fixed-length oracle replies without a length bound, the unbounded reduction itself has no uniform oracle-PPT certificate; see blockwiseBoundedReduction, blockwiseGame_le_blockwiseBoundedReduction, and EUFCMA.blockwiseEUFCMA for the truncated oracle-PPT reduction and the resulting uniform asymptotic security theorem.

Separation witness for noIndexEncoder: one query on 0^w ‖ 1^w, then the output 1^w ‖ 0^w with the two block tags in the opposite order.

Separation witness for noLengthEncoder: one query on 0^w ‖ 1^w, then the output 0^w with the first block tag.

Separation witness for noIdentifierEncoder: queries on 0^w ‖ 0^w and 1^w ‖ 1^w, then the output 0^w ‖ 1^w with the first block tag of the first answer and the second block tag of the second answer.

Without the block index the construction is not EUF-CMA: swapBlocksAdversary wins with probability one.

Without the message length the construction is not EUF-CMA: truncateAdversary wins with probability one.

Without the identifier the construction is not EUF-CMA: mixBlocksAdversary wins with probability one.

Efficiency of the honest algorithms, game, and reduction #

Every MACScheme and polynomial-time Encoder admits a plain polynomial-time bound replyBound n ℓ on the encoded length (encTag tag).length of every blockwise tag produced on an ℓ-bit message at security parameter n.

Word-oracle wrapper around blockwiseSigningOracle: tags request.2 using blockwiseSign, replies with the word encTag tag, and logs (request.2, tag).

blockwiseGame E F.toAdversary is strict PPT whenever E is a polynomial-time encoder and F is a strict oracle-PPT blockwise forger.

Truncated oracle-PPT simulator and reduction #

Answers a word-oracle blockwise signing query ((), m) with fixed-length signing queries, one per block input in blockInputs E (M.msgLen n) r m, truncating each reply to tagBound n bits, encoding the resulting blockwise tag (r, tags) with encTag, and logging (m, (r, tags)).

The uniform strict oracle-PPT fixed-length forger built from a word-oracle blockwise forger F: run F n [] against blockwiseBoundedSimulator E tagBound n, then output the first block input of its message that no simulated query covered, with the matching block tag.

theorem Cslib.Crypto.MACScheme.eval_eufCmaGame_blockwiseBoundedReduction (M : MACScheme) (F : BlockwiseMACForger) (tagBound : ℕ → ℕ) (n : ℕ) (htagBound : ∀ sk ∈ (M.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = M.msgLen n → ∀ tag ∈ (M.sign sk msg).eval.support, tag.length ≤ tagBound n) :

When tagBound n bounds all honest tags of M.sign sk on M.msgLen n-bit messages, running blockwiseBoundedReduction fullEncoder tagBound F in M.eufCmaGame has the exact same output distribution as running blockwiseReduction fullEncoder F.toAdversary.

theorem Cslib.Crypto.MACScheme.blockwiseGame_le_blockwiseBoundedReduction (M : MACScheme) (F : BlockwiseMACForger) (tagBound : ℕ → ℕ) (n Q : ℕ) (hF : ProbOracleComp.IsQueryBounded (F n []) Q) (htagBound : ∀ sk ∈ (M.keyGen n).eval.support, ∀ (msg : List Bool), msg.length = M.msgLen n → ∀ tag ∈ (M.sign sk msg).eval.support, tag.length ≤ tagBound n) :

Concrete security of the blockwise construction with blockwiseBoundedReduction: for any word-oracle forger F making at most Q signing queries and any tagBound covering honest tags, the blockwise forgery probability is at most the EUF-CMA success of blockwiseBoundedReduction fullEncoder tagBound F plus (∑ i ∈ range Q, i) / 2 ^ w.

Game.succProbability form of blockwiseGame_le_blockwiseBoundedReduction in ℝ≥0.

Uniform asymptotic security and separations #

Existential unforgeability of the blockwise variable-length MAC with block encoder E under adaptive chosen-message attack ([KL20], Construction 4.7 and Theorem 4.8) against uniform strict oracle-PPT word-oracle forgers (BlockwiseMACForger).

Blockwise EUF-CMA security gives negligible forging probability for every oracle-PPT blockwise forger.

Uniform security of the blockwise variable-length MAC ([KL20], Theorem 4.8): if M is an EUFCMA-secure fixed-length MAC whose message-length schedule M.msgLen is polynomially lower-bounded (as it is when M.msgLen = id), then the blockwise variable-length MAC with fullEncoder is BlockwiseEUFCMA-secure.

theorem Cslib.Crypto.MACScheme.eval_blockwiseGame_toForger (M : MACScheme) (E : BlockwiseMAC.Encoder) (A : BlockwiseMACAdversary) (replyBound : ℕ → ℕ → ℕ) (n : ℕ) (hbound : ∀ sk ∈ (M.keyGen n).eval.support, ∀ (m : List Bool), ∀ tag ∈ (M.blockwiseSign E n sk m).eval.support, (BlockwiseMAC.encTag tag).length ≤ replyBound n m.length) :

When replyBound n m.length covers the encoded length of every honest blockwise tag on m, converting a BlockwiseMACAdversary to a BlockwiseMACForger and back preserves the game distribution.

Without the block index (noIndexEncoder), the blockwise construction is not BlockwiseEUFCMA-secure whenever 3 ≤ fieldWidth (M.msgLen n) eventually.

Without the message length (noLengthEncoder), the blockwise construction is not BlockwiseEUFCMA-secure whenever 3 ≤ fieldWidth (M.msgLen n) eventually.

Without the identifier (noIdentifierEncoder), the blockwise construction is not BlockwiseEUFCMA-secure whenever 3 ≤ fieldWidth (M.msgLen n) eventually.