Documentation

CslibFrontier.Crypto.Computational.Encryption.IVStream

Encryption under a random initial value #

A random-IV mode draws a uniform n-bit initial value iv and outputs iv followed by a body computed from the key, iv and the message. ivModeEncrypt body is this envelope for a body body n k iv msg; it is efficient whenever the body is computable in polynomial time (isPPTOn_ivModeEncrypt).

Randomized counter mode ([BS23], Section 5.4.2) and output feedback mode (Exercise 5.15(b)) are the stream case: derive a keystream of whole n-bit blocks from the key and iv, and XOR it with the message. They differ only in the keystream. ivStreamEncrypt keystream and ivStreamDecrypt keystream are this construction for a keystream generator keystream n k iv blocks; ivStreamEncrypt keystream is defined as ivModeEncrypt with the XOR body. Decryption accepts an n-bit initial value followed by whole blocks.

Decryption inverts encryption on whole-block messages whenever the keystream has blocks * n bits (ivStreamDecrypt_ivStreamEncrypt). Both algorithms are efficient whenever the keystream generator is computable in polynomial time (isPPTOn_ivStreamEncrypt, computableInPolyTime_ivStreamDecrypt).

Main definitions #

Main results #

References #

noncomputable def Cslib.Crypto.ivModeEncrypt (body : ℕ → List Bool → List Bool → List Bool → List Bool) (n : ℕ) (k msg : List Bool) :

Encryption under a random initial value with body body: draw a uniform n-bit iv and output iv followed by body n k iv msg.

def Cslib.Crypto.ivModeDecrypt (decBody : ℕ → List Bool → List Bool → List Bool → List Bool) (n : ℕ) (k ct : List Bool) :

Decryption envelope for an n-bit initial value with body decryptor decBody: accept a ciphertext of at least n bits whose body length is a multiple of n, and run decBody on (n, k, ct.take n, ct.drop n).

theorem Cslib.Crypto.ivModeDecrypt_ivModeEncrypt {encBody decBody : ℕ → List Bool → List Bool → List Bool → List Bool} {n : ℕ} {k msg : List Bool} (hlen : ∀ (iv : List Bool), iv.length = n → (encBody n k iv msg).length = msg.length) (hinv : ∀ (iv : List Bool), iv.length = n → decBody n k iv (encBody n k iv msg) = msg) (hmsg : msg.length % n = 0) {ct : List Bool} (hct : ct ∈ (ivModeEncrypt encBody n k msg).eval.support) :
ivModeDecrypt decBody n k ct = some msg

ivModeDecrypt inverts ivModeEncrypt on whole-block messages whenever encBody preserves message length and decBody left-inverts encBody on every n-bit initial value.

noncomputable def Cslib.Crypto.ivStreamEncrypt (keystream : ℕ → List Bool → List Bool → ℕ → List Bool) (n : ℕ) (k msg : List Bool) :

Stream encryption under a random initial value: the random-IV mode ivModeEncrypt whose body is the message XORed with the keystream keystream n k iv (msg.length / n).

def Cslib.Crypto.ivStreamDecrypt (keystream : ℕ → List Bool → List Bool → ℕ → List Bool) (n : ℕ) (k ct : List Bool) :

Stream decryption: accept an n-bit initial value followed by whole blocks, and XOR the blocks with the keystream from that initial value.

theorem Cslib.Crypto.ivStreamDecrypt_ivStreamEncrypt {keystream : ℕ → List Bool → List Bool → ℕ → List Bool} {n : ℕ} {k msg : 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) {ct : List Bool} (hct : ct ∈ (ivStreamEncrypt keystream n k msg).eval.support) :
ivStreamDecrypt keystream n k ct = some msg

Decryption inverts encryption on whole-block messages when the keystream from every n-bit initial value has blocks * n bits.

Decryption under an initial value is computable in polynomial time on (n, k, ct) when the body decryptor is computable in polynomial time on (n, k, iv, body).

Encryption under a random initial value is uniformly strict PPT in (n, k, msg) when the body is computable in polynomial time on (n, k, iv, msg).

Stream encryption is uniformly strict PPT in (n, k, msg) when the keystream generator is computable in polynomial time on (n, k, iv, blocks).

Stream decryption is computable in polynomial time on (n, k, ct) when the keystream generator is computable in polynomial time on (n, k, iv, blocks).