Documentation

CslibFrontier.Crypto.Computational.Encryption.IVStream.Malleability

Malleability of stream encryption under a random initial value #

A ciphertext of ivStreamEncrypt is an n-bit initial value followed by the message XORed with a keystream. XORing a mask delta at least as long as msg into the part after the initial value (ivStreamXorBody) therefore gives a ciphertext in the support of the encryption of msg ⊕ delta, whatever the keystream (ivStreamXorBody_mem_support_ivStreamEncrypt). On whole-block messages, when the keystream from every n-bit initial value has blocks * n bits, it decrypts to msg ⊕ delta (ivStreamDecrypt_ivStreamXorBody). The transformation needs neither the key nor the keystream, and it is computable in polynomial time (computableInPolyTime_ivStreamXorBody).

Boneh and Shoup exploit this malleability against randomized counter mode in Section 9.2.1 ([BS23], printed pp. 360–361): "define ĉ to be the same as c except that ĉ[1] := c[1] ⊕ u ⊕ v", which is the mask (u ⊕ v) ‖ 0. In Section 9.10, Attack 3 (printed p. 391), they state it as "given the encryption of m, an attacker can create a valid encryption of m ⊕ Δ for any Δ of his choice." Counter mode (ctrWordEncrypt), output feedback mode (ofbWordEncrypt) and the one-block cipher prfCipher all encrypt by ivStreamEncrypt. Since ctrWordEncrypt and ofbWordEncrypt are not exposed, a module client states its hypotheses for ivStreamEncrypt (ctrWordKeystream family) and ivStreamEncrypt (ofbWordKeystream family). The randomized CBC half of Section 9.2.1 is not covered.

Main definitions #

Main results #

References #

XOR the mask delta into the part of the ciphertext ct after its first n bits, the initial value of ivStreamEncrypt at parameter n.

theorem Cslib.Crypto.ivStreamXorBody_mem_support_ivStreamEncrypt {keystream : ℕ → List Bool → List Bool → ℕ → List Bool} {n : ℕ} {k msg delta ct : List Bool} (hdelta : msg.length ≤ delta.length) (hct : ct ∈ (ivStreamEncrypt keystream n k msg).eval.support) :
ivStreamXorBody n delta ct ∈ (ivStreamEncrypt keystream n k (List.zipWith xor msg delta)).eval.support

Malleability of stream encryption ([BS23], Section 9.2.1 and Section 9.10, Attack 3): XORing a mask delta at least as long as msg into an encryption of msg after its initial value gives an encryption of msg ⊕ delta, for every keystream.

theorem Cslib.Crypto.ivStreamDecrypt_ivStreamXorBody {keystream : ℕ → List Bool → List Bool → ℕ → List Bool} {n : ℕ} {k msg delta ct : List Bool} (hkeystream : ∀ (iv : List Bool), iv.length = n → (keystream n k iv (msg.length / n)).length = msg.length / n * n) (hmsg : msg.length % n = 0) (hdelta : msg.length ≤ delta.length) (hct : ct ∈ (ivStreamEncrypt keystream n k msg).eval.support) :
ivStreamDecrypt keystream n k (ivStreamXorBody n delta ct) = some (List.zipWith xor msg delta)

The modified ciphertext of ivStreamXorBody_mem_support_ivStreamEncrypt decrypts to msg ⊕ delta when msg is a whole number of n-bit blocks and the keystream from every n-bit initial value has blocks * n bits.