def successful_encrypt_plaintext_valid

qasim-bend-kit@0.1.0.2 · proof/AES_EncryptProof.bend:149

import qasim-bend-kit@0.1.0.2/proof/AES_EncryptProof.bend as AESEncryptProof
import Base
import qasim-bend-kit@0.1.0.2/libs/AES256GCM.bend as AES
import qasim-bend-kit@0.1.0.2/proof/AES_ZipLengthProof.bend as ZipLengthProof

149def successful_encrypt_plaintext_valid(+key: AES.SecretKey,
150    +nonce: AES.Nonce, +aad: List<&2, U32>, +plaintext: List<&2, U32>,
151    +aad_flag: Bool, +plaintext_flag: Bool,
152    aad_ok: {AES.aad_valid(aad) == aad_flag : Bool},
153    plaintext_ok: {AES.plaintext_valid(plaintext) == plaintext_flag : Bool},
154    +envelope: AES.Envelope,
155    encrypted: {AES.encrypt(key, nonce, aad, plaintext) == Done{envelope} :
156        Result<&2, &2, AES.Error, AES.Envelope>}) ->
157    {plaintext_flag == True{} : Bool}:
158    match aad_flag plaintext_flag:
159        case True{} True{}: {==}
160        case True{} False{}:
161            checked = encrypt_checked_with_flags(key, nonce, aad, plaintext,
162                aad_flag, plaintext_flag, aad_ok, plaintext_ok, envelope,
163                encrypted)
164            Equal.trans(Bool, False{},
165                Result.is_done(&2, &2, AES.Error, AES.Envelope,
166                    AES.encrypt_checked(key, nonce, aad, plaintext,
167                        aad_flag, plaintext_flag)),
168                True{}, {==},
169                Equal.cong(Result<&2, &2, AES.Error, AES.Envelope>, Bool,
170                    result => Result.is_done(&2, &2, AES.Error, AES.Envelope,
171                        result),
172                    AES.encrypt_checked(key, nonce, aad, plaintext,
173                        aad_flag, plaintext_flag), Done{envelope}, checked))
174        case False{} _:
175            checked = encrypt_checked_with_flags(key, nonce, aad, plaintext,
176                aad_flag, plaintext_flag, aad_ok, plaintext_ok, envelope,
177                encrypted)
178            Empty.absurd({plaintext_flag == True{} : Bool},
179                ZipLengthProof.false_true(Equal.trans(Bool, False{},
180                    Result.is_done(&2, &2, AES.Error, AES.Envelope,
181                        AES.encrypt_checked(key, nonce, aad, plaintext,
182                            aad_flag, plaintext_flag)),
183                    True{}, {==},
184                    Equal.cong(Result<&2, &2, AES.Error, AES.Envelope>, Bool,
185                        result => Result.is_done(&2, &2, AES.Error, AES.Envelope,
186                            result),
187                        AES.encrypt_checked(key, nonce, aad, plaintext,
188                            aad_flag, plaintext_flag), Done{envelope}, checked))))

Uses (18)

Used by (3)