Skip to content

Commit f3a7973

Browse files
committed
verify
1 parent 5be8142 commit f3a7973

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

DynamoDbEncryption/dafny/StructuredEncryption/src/AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations.dfy

+16-5
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
312312
function method {:tailrecursion} {:opaque} ResolveLegend(
313313
fields : CanonAuthList,
314314
legend : Header.Legend,
315-
ghost origFields : CanonAuthList := fields,
316-
acc : CanonCryptoList := []
315+
ghost origFields : CanonAuthList,
316+
acc : CanonCryptoList
317317
)
318318
: (ret : Result<CanonCryptoList, Error>)
319319
requires |fields| + |acc| == |origFields|
@@ -363,7 +363,11 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
363363
assert forall k <- canonSorted :: Paths.ValidPath(k.origKey);
364364
assert forall k <- canonSorted :: k.key == Paths.CanonPath(tableName, k.origKey);
365365

366-
var canonResolved :- ResolveLegend(canonSorted, legend);
366+
var acc : CanonCryptoList := [];
367+
assert |canonSorted| + |acc| == |canonSorted|;
368+
assert forall i | 0 <= i < |acc| :: Same(canonSorted[i], acc[i]);
369+
assert forall i | |acc| <= i < |canonSorted| :: canonSorted[i] == canonSorted[i-|acc|];
370+
var canonResolved :- ResolveLegend(canonSorted, legend, canonSorted, acc);
367371

368372
assert |canonResolved| == |data|;
369373
assert forall k <- data :: (exists x :: x in canonResolved && k.key == x.origKey);
@@ -944,6 +948,13 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
944948
encryptionContext := encryptionContext + newEncryptionContext;
945949
assert cmm.Modifies !! {config.materialProviders.History};
946950

951+
var contextKeysX := SortedSets.ComputeSetToOrderedSequence2(newEncryptionContext.Keys, ByteLess);
952+
assert forall k <- contextKeysX :: ValidUTF8Seq(k) by {
953+
assert forall k <- newEncryptionContext.Keys :: ValidUTF8Seq(k);
954+
assert forall k <- contextKeysX :: k in newEncryptionContext.Keys;
955+
}
956+
var contextKeys : seq<UTF8.ValidUTF8Bytes> := contextKeysX;
957+
947958
//= specification/structured-encryption/decrypt-structure.md#create-new-encryption-context-and-cmm
948959
//# Then, this operation MUST create a [Required Encryption Context CMM](https://github.com/awslabs/private-aws-encryption-sdk-specification-staging/blob/dafny-verified/framework/required-encryption-context-cmm.md)
949960
//# with the following inputs:
@@ -953,7 +964,7 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
953964
CMP.CreateRequiredEncryptionContextCMMInput(
954965
underlyingCMM := Some(input.cmm),
955966
keyring := None,
956-
requiredEncryptionContextKeys := SortedSets.ComputeSetToOrderedSequence2(newEncryptionContext.Keys, ByteLess)
967+
requiredEncryptionContextKeys := contextKeys
957968
)
958969
);
959970
cmm :- cmmR.MapFailure(e => AwsCryptographyMaterialProviders(e));
@@ -1049,7 +1060,7 @@ module AwsCryptographyDbEncryptionSdkStructuredEncryptionOperations refines Abst
10491060
assert !exists x :: x in smallResult && x.key == HeaderPath;
10501061
assert !exists x :: x in smallResult && x.key == FooterPath;
10511062
assume {:axiom} forall k <- input.encryptedStructure | k.key !in HeaderPaths ::
1052-
(exists x :: x in smallResult && x.key == k.key);
1063+
(exists x :: x in smallResult && x.key == k.key);
10531064

10541065
//= specification/structured-encryption/decrypt-structure.md#construct-decrypted-structured-data
10551066
//= type=implication

0 commit comments

Comments
 (0)