def encode_injective
qasim-bend-kit@0.1.0.2 · proof/AES_IdentityProof.bend:103
import qasim-bend-kit@0.1.0.2/proof/AES_IdentityProof.bend as AESIdentityProof
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_ConstructorProof.bend as Constructor
import qasim-bend-kit@0.1.0.2/proof/AES_KnownAnswerProof.bend as Known
103def encode_injective(+first: AES.Envelope, +second: AES.Envelope,
104 same: {AES.encode(first) == AES.encode(second) : String}) -> {first == second : AES.Envelope}:
105 match first second:
106 case AES.Envelope{AES.Nonce{+bytes_a, +size_a, +nonce_valid_a},
107 +cipher_a, AES.Tag{+tag_bytes_a, +tag_size_a, +tag_valid_a}, +valid_a}
108 AES.Envelope{AES.Nonce{+bytes_b, +size_b, +nonce_valid_b},
109 +cipher_b, AES.Tag{+tag_bytes_b, +tag_size_b, +tag_valid_b}, +valid_b}:
110 +size_a_copy = size_a
111 +size_b_copy = size_b
112 +nonce_valid_a_copy = nonce_valid_a
113 +nonce_valid_b_copy = nonce_valid_b
114 +nonce_a = {AES.Nonce{bytes_a, size_a_copy, nonce_valid_a_copy} : AES.Nonce}
115 +nonce_b = {AES.Nonce{bytes_b, size_b_copy, nonce_valid_b_copy} : AES.Nonce}
116 +tag_a = {AES.Tag{tag_bytes_a, tag_size_a, tag_valid_a} : AES.Tag}
117 +tag_b = {AES.Tag{tag_bytes_b, tag_size_b, tag_valid_b} : AES.Tag}
118 +parts_same = fields_equal(first, second, same)
119 nonce_hex = Equal.cong(List<&2, String>, String, parts => field_text(1n, parts),
120 fields(first), fields(second), parts_same)
121 tag_hex = Equal.cong(List<&2, String>, String, parts => field_text(2n, parts),
122 fields(first), fields(second), parts_same)
123 cipher_hex = Equal.cong(List<&2, String>, String, parts => field_text(3n, parts),
124 fields(first), fields(second), parts_same)
125 nonce_bytes_same = hex_injective(bytes_a, bytes_b, nonce_valid_a_copy, nonce_valid_b_copy,
126 fixed_hex_equal(12n, bytes_a, bytes_b, size_a_copy, size_b_copy, nonce_hex))
127 tag_bytes_same = hex_injective(tag_bytes_a, tag_bytes_b, tag_valid_a, tag_valid_b,
128 fixed_hex_equal(16n, tag_bytes_a, tag_bytes_b, tag_size_a, tag_size_b, tag_hex))
129 cipher_same = hex_injective(cipher_a, cipher_b, valid_a, valid_b, cipher_hex)
130 nonce_same = Constructor.nonce_equal(bytes_a, size_a_copy, nonce_valid_a_copy, bytes_b,
131 nonce_bytes_same, size_b_copy, nonce_valid_b_copy)
132 tag_same = Known.tag_equal(tag_bytes_a, tag_size_a, tag_valid_a, tag_bytes_b,
133 tag_bytes_same, tag_size_b, tag_valid_b)
134 fields_same = Known.envelope_equal(nonce_a, cipher_a, tag_a, valid_a,
135 cipher_b, tag_b, cipher_same, tag_same, valid_b)
136 Equal.trans(AES.Envelope, first, AES.Envelope{nonce_a, cipher_b, tag_b, valid_b}, second,
137 fields_same, Equal.cong(AES.Nonce, AES.Envelope,
138 nonce => AES.Envelope{nonce, cipher_b, tag_b, valid_b}, nonce_a, nonce_b, nonce_same))