@@ -12,49 +12,65 @@ module {:options "/functionSyntax:4" } CMM {
1212 trait {:termination false } VerifiableInterface
1313 extends Types. ICryptographicMaterialsManager
1414 {
15- method GetEncryptionMaterials'(input: Types. GetEncryptionMaterialsInput)
16- returns (output: Result< Types. GetEncryptionMaterialsOutput, Types. Error> )
17- requires ValidState ()
18- modifies Modifies - {History}
19- // Dafny will skip type parameters when generating a default decreases clause.
20- decreases Modifies - {History}
21- ensures ValidState ()
22- ensures GetEncryptionMaterialsEnsuresPublicly (input, output)
23- ensures unchanged (History)
24- ensures output. Success?
25- ==>
26- && Materials. EncryptionMaterialsHasPlaintextDataKey (output.value.encryptionMaterials)
27- ensures output. Success?
28- ==>
29- && RequiredEncryptionContextKeys?(input. requiredEncryptionContextKeys, output. value. encryptionMaterials)
3015
31- method DecryptMaterials'(input: Types. DecryptMaterialsInput)
32- returns (output: Result< Types. DecryptMaterialsOutput, Types. Error> )
33- requires ValidState ()
34- modifies Modifies - {History}
35- // Dafny will skip type parameters when generating a default decreases clause.
36- decreases Modifies - {History}
37- ensures ValidState ()
38- ensures DecryptMaterialsEnsuresPublicly (input, output)
39- ensures unchanged (History)
40- ensures output. Success?
41- ==>
42- && Materials. DecryptionMaterialsWithPlaintextDataKey (output.value.decryptionMaterials)
43- // = aws-encryption-sdk-specification/framework/cmm-interface.md#decrypt-materials
44- // # The CMM MUST validate the [Encryption Context](structures.md#encryption-context)
45- // # by comparing it to the customer supplied [Reproduced Encryption Context](structures.md#encryption-context)
46- // # in [decrypt materials request](#decrypt-materials-request).
47- // # For every key that exists in both [Reproduced Encryption Context](structures.md#encryption-context)
48- // # and [Encryption Context](structures.md#encryption-context),
49- // # the values MUST be equal or the operation MUST fail.
16+ ghost predicate GetEncryptionMaterialsEnsuresPublicly (input: Types .GetEncryptionMaterialsInput, output: Result <Types .GetEncryptionMaterialsOutput, Types.Error>)
17+ : (outcome: bool )
5018 ensures
51- && (output. Success? ==> ReproducedEncryptionContext?(input))
52- && (! ReproducedEncryptionContext?(input) ==> output. Failure?)
53- // = aws-encryption-sdk-specification/framework/cmm-interface.md#decrypt-materials
54- // # - All key-value pairs that exist in [Reproduced Encryption Context](structures.md#encryption-context)
55- // # but do not exist in encryption context on the [decrypt materials request](#decrypt-materials-request)
56- // # SHOULD be appended to the decryption materials.
57- ensures output. Success? ==> EncryptionContextComplete (input, output.value.decryptionMaterials)
19+ outcome ==>
20+ output. Success?
21+ ==>
22+ // if the output materials are valid then they contain the required fields
23+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#get-encryption-materials
24+ // = type=implication
25+ // # The encryption materials returned MUST include the following:
26+
27+ // See EncryptionMaterialsHasPlaintextDataKey for details
28+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#get-encryption-materials
29+ // = type=implication
30+ // # The CMM MUST ensure that the encryption materials returned are valid.
31+ // # - The encryption materials returned MUST follow the specification for [encryption-materials](structures.md#encryption-materials).
32+ // # - The value of the plaintext data key MUST be non-NULL.
33+ // # - The plaintext data key length MUST be equal to the [key derivation input length](algorithm-suites.md#key-derivation-input-length).
34+ // # - The encrypted data keys list MUST contain at least one encrypted data key.
35+ // # - If the algorithm suite contains a signing algorithm, the encryption materials returned MUST include the generated signing key.
36+ // # - For every key in [Required Encryption Context Keys](structures.md#required-encryption-context-keys)
37+ // # there MUST be a matching key in the [Encryption Context](structures.md#encryption-context-1).
38+ && Materials. EncryptionMaterialsHasPlaintextDataKey (output.value.encryptionMaterials)
39+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#get-encryption-materials
40+ // = type=implication
41+ // # - The [Required Encryption Context Keys](structures.md#required-encryption-context-keys) MUST be
42+ // # a super set of the Required Encryption Context Keys in the [encryption materials request](#encryption-materials-request).
43+ && RequiredEncryptionContextKeys?(input. requiredEncryptionContextKeys, output. value. encryptionMaterials)
44+
45+ ghost predicate DecryptMaterialsEnsuresPublicly (input: Types .DecryptMaterialsInput, output: Result <Types .DecryptMaterialsOutput, Types.Error>)
46+ : (outcome: bool )
47+ ensures
48+ outcome ==>
49+ // if the output materials are valid then they contain the required fields
50+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#decrypt-materials
51+ // = type=implication
52+ // # The decryption materials returned MUST include the following:
53+ && (output. Success?
54+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#decrypt-materials
55+ // = type=implication
56+ // # The CMM MUST ensure that the decryption materials returned are valid.
57+ // # - The decryption materials returned MUST follow the specification for [decryption-materials](structures.md#decryption-materials).
58+ // # - The value of the plaintext data key MUST be non-NULL.
59+ ==> Materials. DecryptionMaterialsWithPlaintextDataKey (output.value.decryptionMaterials))
60+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#decrypt-materials
61+ // # The CMM MUST validate the [Encryption Context](structures.md#encryption-context)
62+ // # by comparing it to the customer supplied [Reproduced Encryption Context](structures.md#encryption-context)
63+ // # in [decrypt materials request](#decrypt-materials-request).
64+ // # For every key that exists in both [Reproduced Encryption Context](structures.md#encryption-context)
65+ // # and [Encryption Context](structures.md#encryption-context),
66+ // # the values MUST be equal or the operation MUST fail.
67+ && (output. Success? ==> ReproducedEncryptionContext?(input))
68+ && (! ReproducedEncryptionContext?(input) ==> output. Failure?)
69+ // = aws-encryption-sdk-specification/framework/cmm-interface.md#decrypt-materials
70+ // # - All key-value pairs that exist in [Reproduced Encryption Context](structures.md#encryption-context)
71+ // # but do not exist in encryption context on the [decrypt materials request](#decrypt-materials-request)
72+ // # SHOULD be appended to the decryption materials.
73+ && (output. Success? ==> EncryptionContextComplete (input, output.value.decryptionMaterials))
5874 }
5975
6076 predicate RequiredEncryptionContextKeys?(requiredEncryptionContextKeys: Option< Types. EncryptionContextKeys> , encryptionMaterials: Types. EncryptionMaterials) {
@@ -64,15 +80,15 @@ module {:options "/functionSyntax:4" } CMM {
6480
6581 predicate EncryptionContextComplete (input: Types .DecryptMaterialsInput, decryptionMaterials: Types .DecryptionMaterials) {
6682 var reproducedEncryptionContext := input. reproducedEncryptionContext. UnwrapOr (map[]);
67- forall k < - reproducedEncryptionContext. Keys
83+ forall k < - reproducedEncryptionContext
6884 ::
6985 && k in decryptionMaterials. encryptionContext
7086 && decryptionMaterials. encryptionContext[k] == reproducedEncryptionContext[k]
7187 }
7288
7389 predicate ReproducedEncryptionContext?(input: Types. DecryptMaterialsInput) {
7490 var reproducedEncryptionContext := input. reproducedEncryptionContext. UnwrapOr (map[]);
75- forall k < - reproducedEncryptionContext. Keys
91+ forall k < - reproducedEncryptionContext
7692 | k in input. encryptionContext
7793 :: input. encryptionContext[k] == reproducedEncryptionContext[k]
7894 }
0 commit comments