@@ -91,48 +91,21 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
91
91
&& x. data == y. data
92
92
}
93
93
94
- function method UnCanon (input : CanonCryptoList , remove : set <Path > := {}) : (ret : CryptoList)
95
- // ensures forall k <- input | k.origKey !in remove :: (exists x :: x in ret && SameUnCanon(k, x))
96
- {
97
- if |input| == 0 then
98
- []
99
- else if input[0]. origKey in remove then
100
- UnCanon (input[1..], remove)
101
- else
102
- [CryptoItem (key := input[0].origKey, data := input[0].data, action := input[0].action)] + UnCanon (input[1..], remove)
103
- }
104
-
105
- function method UnCanon2 (input : CanonCryptoList ) : (ret : CryptoList)
94
+ function method UnCanon (input : CanonCryptoList ) : (ret : CryptoList)
106
95
ensures
107
96
&& |ret| == |input|
108
- // && forall i | 0 <= i < |input| :: SameUnCanon(input[i], ret[i])
97
+ && forall i | 0 <= i < |input| :: SameUnCanon (input[i], ret[i])
109
98
{
110
99
if |input| == 0 then
111
100
[]
112
101
else
113
102
var newItem := CryptoItem (key := input[0].origKey, data := input[0].data, action := input[0].action);
114
103
assert SameUnCanon (input[0], newItem);
115
- [newItem] + UnCanon2 (input[1..])
104
+ [newItem] + UnCanon (input[1..])
116
105
}
117
106
118
-
119
107
const DBE_COMMITMENT_POLICY := CMP. CommitmentPolicy. DBE (CMP.DBECommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
120
108
121
- // Fail unless the field exists, and is a binary terminal
122
- function method {:opaque} NeedBinary (data : AuthList , path : Path ): (result: Outcome< Error> )
123
- {
124
- var data := FindAuth (data, path);
125
-
126
- if data. None? then
127
- Fail (E("The field name " + Paths.PathToString(path) + " is required. "))
128
- else if data. value. data. typeId != BYTES_TYPE_ID then
129
- Fail (E(Paths.PathToString(path) + " must be a binary Terminal. "))
130
- else if data. value. action != DO_NOT_SIGN then
131
- Fail (E(Paths.PathToString(path) + " must be DO_NOT_SIGN. "))
132
- else
133
- Pass
134
- }
135
-
136
109
// Fail unless the field exists, and is a binary terminal
137
110
function method {:opaque} GetBinary (data : AuthList , path : Path ): (result: Result< StructuredDataTerminal, Error> )
138
111
{
@@ -148,7 +121,6 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
148
121
Success (data.value.data)
149
122
}
150
123
151
-
152
124
// Return the sum of the sizes of the given fields
153
125
function method {:opaque} SumValueSize (fields : CanonCryptoList )
154
126
: nat
@@ -426,7 +398,7 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
426
398
function method {:opaque} FindAuth (haystack : AuthList , needle : Path ) : Option< AuthItem>
427
399
{
428
400
if |haystack| == 0 then
429
- None
401
+ None
430
402
else if haystack[0]. key == needle
431
403
then Some (haystack[0])
432
404
else
@@ -781,12 +753,18 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
781
753
var footer :- Footer. CreateFooter (config.primitives, mat, encryptedItems, headerSerialized);
782
754
var footerAttribute := footer. makeTerminal ();
783
755
784
- var result : CryptoList := UnCanon2 (encryptedItems) +
785
- [
786
- CryptoItem (key := HeaderPath, data := headerAttribute, action := DO_NOTHING),
787
- CryptoItem (key := FooterPath, data := footerAttribute, action := DO_NOTHING)
788
- ];
789
- assert forall k < - input. plaintextStructure :: (exists x :: x in result && x. key == k. key);
756
+ assert forall k < - input. plaintextStructure :: (exists x :: x in encryptedItems && x. origKey == k. key);
757
+ var smallResult : CryptoList := UnCanon (encryptedItems);
758
+ assert forall k < - input. plaintextStructure :: (exists x :: x in smallResult && x. key == k. key);
759
+
760
+ var headItem := CryptoItem (key := HeaderPath, data := headerAttribute, action := DO_NOTHING);
761
+ var footItem := CryptoItem (key := FooterPath, data := footerAttribute, action := DO_NOTHING);
762
+ var largeResult := smallResult + [headItem, footItem];
763
+ assert largeResult[|largeResult|- 2] == headItem;
764
+ assert largeResult[|largeResult|- 2]. key == HeaderPath;
765
+ assert largeResult[|largeResult|- 1] == footItem;
766
+ assert largeResult[|largeResult|- 1]. key == FooterPath;
767
+ assert forall k < - input. plaintextStructure :: (exists x :: x in largeResult && x. key == k. key);
790
768
791
769
var headerAlgorithmSuite :- head. GetAlgorithmSuite (config.materialProviders);
792
770
var parsedHeader := ParsedHeader (
@@ -797,7 +775,7 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
797
775
);
798
776
799
777
var encryptOutput := EncryptPathStructureOutput (
800
- encryptedStructure := result ,
778
+ encryptedStructure := largeResult ,
801
779
parsedHeader := parsedHeader
802
780
);
803
781
@@ -915,18 +893,19 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
915
893
// # according to the [header format](./header.md).
916
894
&& Header. PartialDeserialize (headerSerialized.value). Success?
917
895
918
- // //= specification/structured-encryption/decrypt-structure.md#construct-decrypted-structured-data
919
- // //= type=implication
920
- // //# - [Terminal Data](./structures.md#terminal-data) MUST NOT exist at the "aws_dbe_head"
921
- // //# or "aws_dbe_foot".
922
- // && Find(output.value.plaintextStructure, HeaderPath).Failure?
923
- // && Find(output.value.plaintextStructure, FooterPath).Failure?
896
+ // //= specification/structured-encryption/decrypt-structure.md#construct-decrypted-structured-data
897
+ // //= type=implication
898
+ // //# - [Terminal Data](./structures.md#terminal-data) MUST NOT exist at the "aws_dbe_head"
899
+ // //# or "aws_dbe_foot".
900
+ && (! exists x :: x in output. value. plaintextStructure && x. key == HeaderPath)
901
+ && (! exists x :: x in output. value. plaintextStructure && x. key == FooterPath)
902
+ && (forall k < - input. encryptedStructure | k. key ! in HeaderPaths ::
903
+ (exists x :: x in output. value. plaintextStructure && x. key == k. key))
924
904
{
925
905
var encRecord : AuthList := input. encryptedStructure;
926
906
927
907
:- Need (exists x :: (x in encRecord && x.action == SIGN), E ("At least one Authenticate Action must be SIGN"));
928
908
929
- // To Be Done - no longer need NeedBinary
930
909
var headerSerialized :- GetBinary (encRecord, HeaderPath);
931
910
var footerSerialized :- GetBinary (encRecord, FooterPath);
932
911
// = specification/structured-encryption/decrypt-structure.md#parse-the-header
@@ -1062,16 +1041,15 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
1062
1041
// # - for every [Terminal Data](./structures.md#terminal-data) in the output Structured Data,
1063
1042
// # a Terminal Data MUST exist with the same [canonical path](./header.md#canonical-path) in the [input Structured Data](#structured-data).
1064
1043
1065
- var largeResult := UnCanon2 (decryptedItems);
1044
+ var largeResult := UnCanon (decryptedItems);
1066
1045
assert forall k < - input. encryptedStructure :: (exists x :: x in largeResult && x. key == k. key);
1067
1046
1068
1047
var smallResult := Seq. Filter ((x : CryptoItem ) => x. key ! in HeaderPaths, largeResult);
1048
+ reveal Seq. Filter ();
1069
1049
assert ! exists x :: x in smallResult && x. key == HeaderPath;
1070
1050
assert ! exists x :: x in smallResult && x. key == FooterPath;
1071
- assert forall k < - input. encryptedStructure :: (
1072
- || k. key in HeaderPaths
1073
- || (exists x :: x in smallResult && x. key == k. key)
1074
- );
1051
+ assume {:axiom} forall k < - input. encryptedStructure | k. key ! in HeaderPaths ::
1052
+ (exists x :: x in smallResult && x. key == k. key);
1075
1053
1076
1054
// = specification/structured-encryption/decrypt-structure.md#construct-decrypted-structured-data
1077
1055
// = type=implication
0 commit comments