github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl@v0.2.0/RawECDHKeyring/RawECDHKeyring.go (about) 1 // Package RawECDHKeyring 2 // Dafny module RawECDHKeyring compiled into Go 3 4 package RawECDHKeyring 5 6 import ( 7 os "os" 8 9 m_ComAmazonawsDynamodbTypes "github.com/aws/aws-cryptographic-material-providers-library/releases/go/dynamodb/ComAmazonawsDynamodbTypes" 10 m_Com_Amazonaws_Dynamodb "github.com/aws/aws-cryptographic-material-providers-library/releases/go/dynamodb/Com_Amazonaws_Dynamodb" 11 m_ComAmazonawsKmsTypes "github.com/aws/aws-cryptographic-material-providers-library/releases/go/kms/ComAmazonawsKmsTypes" 12 m_Com_Amazonaws_Kms "github.com/aws/aws-cryptographic-material-providers-library/releases/go/kms/Com_Amazonaws_Kms" 13 m_AlgorithmSuites "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AlgorithmSuites" 14 m_AwsArnParsing "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsArnParsing" 15 m_AwsCryptographyKeyStoreOperations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsCryptographyKeyStoreOperations" 16 m_AwsCryptographyKeyStoreTypes "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsCryptographyKeyStoreTypes" 17 m_AwsCryptographyMaterialProvidersTypes "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsCryptographyMaterialProvidersTypes" 18 m_AwsKmsDiscoveryKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsDiscoveryKeyring" 19 m_AwsKmsHierarchicalKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsHierarchicalKeyring" 20 m_AwsKmsKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsKeyring" 21 m_AwsKmsMrkAreUnique "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsMrkAreUnique" 22 m_AwsKmsMrkDiscoveryKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsMrkDiscoveryKeyring" 23 m_AwsKmsMrkKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsMrkKeyring" 24 m_AwsKmsMrkMatchForDecrypt "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsMrkMatchForDecrypt" 25 m_AwsKmsRsaKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsRsaKeyring" 26 m_AwsKmsUtils "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/AwsKmsUtils" 27 m_CacheConstants "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/CacheConstants" 28 m_CanonicalEncryptionContext "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/CanonicalEncryptionContext" 29 m_Constants "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/Constants" 30 m_CreateKeyStoreTable "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/CreateKeyStoreTable" 31 m_CreateKeys "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/CreateKeys" 32 m_DDBKeystoreOperations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/DDBKeystoreOperations" 33 m_DiscoveryMultiKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/DiscoveryMultiKeyring" 34 m_EcdhEdkWrapping "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/EcdhEdkWrapping" 35 m_EdkWrapping "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/EdkWrapping" 36 m_ErrorMessages "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/ErrorMessages" 37 m_GetKeys "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/GetKeys" 38 m_IntermediateKeyWrapping "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/IntermediateKeyWrapping" 39 m_KMSKeystoreOperations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/KMSKeystoreOperations" 40 m_KeyStore "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/KeyStore" 41 m_KeyStoreErrorMessages "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/KeyStoreErrorMessages" 42 m_Keyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/Keyring" 43 m_KmsArn "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/KmsArn" 44 m_LocalCMC "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/LocalCMC" 45 m_MaterialWrapping "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/MaterialWrapping" 46 m_Materials "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/Materials" 47 m_MrkAwareDiscoveryMultiKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/MrkAwareDiscoveryMultiKeyring" 48 m_MrkAwareStrictMultiKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/MrkAwareStrictMultiKeyring" 49 m_MultiKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/MultiKeyring" 50 m_StormTracker "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/StormTracker" 51 m_StormTrackingCMC "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/StormTrackingCMC" 52 m_StrictMultiKeyring "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/StrictMultiKeyring" 53 m_Structure "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/Structure" 54 m_SynchronizedLocalCMC "github.com/aws/aws-cryptographic-material-providers-library/releases/go/mpl/SynchronizedLocalCMC" 55 m_AtomicPrimitives "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/AtomicPrimitives" 56 m_AwsCryptographyPrimitivesOperations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/AwsCryptographyPrimitivesOperations" 57 m_AwsCryptographyPrimitivesTypes "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/AwsCryptographyPrimitivesTypes" 58 m_Digest "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/Digest" 59 m_HKDF "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/HKDF" 60 m_KdfCtr "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/KdfCtr" 61 m_Random "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/Random" 62 m_WrappedHKDF "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/WrappedHKDF" 63 m_WrappedHMAC "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/WrappedHMAC" 64 m_Actions "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Actions" 65 m_Base64 "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Base64" 66 m_Base64Lemmas "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Base64Lemmas" 67 m_BoundedInts "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/BoundedInts" 68 m_DivInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivInternals" 69 m_DivInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivInternalsNonlinear" 70 m_DivMod "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivMod" 71 m_FileIO "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/FileIO" 72 m_FloatCompare "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/FloatCompare" 73 m_Functions "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Functions" 74 m_GeneralInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/GeneralInternals" 75 m_GetOpt "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/GetOpt" 76 m_HexStrings "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/HexStrings" 77 m_Logarithm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Logarithm" 78 m__Math "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Math_" 79 m_ModInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/ModInternals" 80 m_ModInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/ModInternalsNonlinear" 81 m_Mul "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Mul" 82 m_MulInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/MulInternals" 83 m_MulInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/MulInternalsNonlinear" 84 m_Power "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Power" 85 m_Relations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Relations" 86 m_Seq "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Seq" 87 m_Seq_MergeSort "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Seq_MergeSort" 88 m_Sorting "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Sorting" 89 m_StandardLibrary "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary" 90 m_StandardLibraryInterop "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibraryInterop" 91 m_StandardLibrary_Sequence "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_Sequence" 92 m_StandardLibrary_String "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_String" 93 m_StandardLibrary_UInt "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_UInt" 94 m_Streams "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Streams" 95 m_UTF8 "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/UTF8" 96 m_UnicodeStrings "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/UnicodeStrings" 97 m__Unicode "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Unicode_" 98 m_Utf16EncodingForm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Utf16EncodingForm" 99 m_Utf8EncodingForm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Utf8EncodingForm" 100 m_Wrappers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers" 101 m__System "github.com/dafny-lang/DafnyRuntimeGo/v4/System_" 102 _dafny "github.com/dafny-lang/DafnyRuntimeGo/v4/dafny" 103 ) 104 105 var _ = os.Args 106 var _ _dafny.Dummy__ 107 var _ m__System.Dummy__ 108 var _ m_Wrappers.Dummy__ 109 var _ m_BoundedInts.Dummy__ 110 var _ m_StandardLibrary_UInt.Dummy__ 111 var _ m_StandardLibrary_Sequence.Dummy__ 112 var _ m_StandardLibrary_String.Dummy__ 113 var _ m_StandardLibrary.Dummy__ 114 var _ m_AwsCryptographyPrimitivesTypes.Dummy__ 115 var _ m_Random.Dummy__ 116 var _ m_Digest.Dummy__ 117 var _ m_WrappedHMAC.Dummy__ 118 var _ m_HKDF.Dummy__ 119 var _ m_WrappedHKDF.Dummy__ 120 var _ m_KdfCtr.Dummy__ 121 var _ m_AwsCryptographyPrimitivesOperations.Dummy__ 122 var _ m_AtomicPrimitives.Dummy__ 123 var _ m_ComAmazonawsDynamodbTypes.Dummy__ 124 var _ m_ComAmazonawsKmsTypes.Dummy__ 125 var _ m_Relations.Dummy__ 126 var _ m_Seq_MergeSort.Dummy__ 127 var _ m__Math.Dummy__ 128 var _ m_Seq.Dummy__ 129 var _ m__Unicode.Dummy__ 130 var _ m_Functions.Dummy__ 131 var _ m_Utf8EncodingForm.Dummy__ 132 var _ m_Utf16EncodingForm.Dummy__ 133 var _ m_UnicodeStrings.Dummy__ 134 var _ m_FileIO.Dummy__ 135 var _ m_GeneralInternals.Dummy__ 136 var _ m_MulInternalsNonlinear.Dummy__ 137 var _ m_MulInternals.Dummy__ 138 var _ m_Mul.Dummy__ 139 var _ m_ModInternalsNonlinear.Dummy__ 140 var _ m_DivInternalsNonlinear.Dummy__ 141 var _ m_ModInternals.Dummy__ 142 var _ m_DivInternals.Dummy__ 143 var _ m_DivMod.Dummy__ 144 var _ m_Power.Dummy__ 145 var _ m_Logarithm.Dummy__ 146 var _ m_StandardLibraryInterop.Dummy__ 147 var _ m_Streams.Dummy__ 148 var _ m_Sorting.Dummy__ 149 var _ m_HexStrings.Dummy__ 150 var _ m_GetOpt.Dummy__ 151 var _ m_FloatCompare.Dummy__ 152 var _ m_Base64.Dummy__ 153 var _ m_Base64Lemmas.Dummy__ 154 var _ m_Actions.Dummy__ 155 var _ m_AwsCryptographyKeyStoreTypes.Dummy__ 156 var _ m_AwsCryptographyMaterialProvidersTypes.Dummy__ 157 var _ m_AwsArnParsing.Dummy__ 158 var _ m_AwsKmsMrkMatchForDecrypt.Dummy__ 159 var _ m_AwsKmsUtils.Dummy__ 160 var _ m_KeyStoreErrorMessages.Dummy__ 161 var _ m_KmsArn.Dummy__ 162 var _ m_Structure.Dummy__ 163 var _ m_KMSKeystoreOperations.Dummy__ 164 var _ m_DDBKeystoreOperations.Dummy__ 165 var _ m_CreateKeys.Dummy__ 166 var _ m_CreateKeyStoreTable.Dummy__ 167 var _ m_GetKeys.Dummy__ 168 var _ m_AwsCryptographyKeyStoreOperations.Dummy__ 169 var _ m_Com_Amazonaws_Kms.Dummy__ 170 var _ m_Com_Amazonaws_Dynamodb.Dummy__ 171 var _ m_KeyStore.Dummy__ 172 var _ m_AlgorithmSuites.Dummy__ 173 var _ m_Materials.Dummy__ 174 var _ m_Keyring.Dummy__ 175 var _ m_MultiKeyring.Dummy__ 176 var _ m_AwsKmsMrkAreUnique.Dummy__ 177 var _ m_Constants.Dummy__ 178 var _ m_MaterialWrapping.Dummy__ 179 var _ m_CanonicalEncryptionContext.Dummy__ 180 var _ m_IntermediateKeyWrapping.Dummy__ 181 var _ m_EdkWrapping.Dummy__ 182 var _ m_ErrorMessages.Dummy__ 183 var _ m_AwsKmsKeyring.Dummy__ 184 var _ m_StrictMultiKeyring.Dummy__ 185 var _ m_AwsKmsDiscoveryKeyring.Dummy__ 186 var _ m_DiscoveryMultiKeyring.Dummy__ 187 var _ m_AwsKmsMrkDiscoveryKeyring.Dummy__ 188 var _ m_MrkAwareDiscoveryMultiKeyring.Dummy__ 189 var _ m_AwsKmsMrkKeyring.Dummy__ 190 var _ m_MrkAwareStrictMultiKeyring.Dummy__ 191 var _ m_LocalCMC.Dummy__ 192 var _ m_SynchronizedLocalCMC.Dummy__ 193 var _ m_StormTracker.Dummy__ 194 var _ m_StormTrackingCMC.Dummy__ 195 var _ m_CacheConstants.Dummy__ 196 var _ m_AwsKmsHierarchicalKeyring.Dummy__ 197 var _ m_AwsKmsRsaKeyring.Dummy__ 198 var _ m_EcdhEdkWrapping.Dummy__ 199 200 type Dummy__ struct{} 201 202 // Definition of class Default__ 203 type Default__ struct { 204 dummy byte 205 } 206 207 func New_Default___() *Default__ { 208 _this := Default__{} 209 210 return &_this 211 } 212 213 type CompanionStruct_Default___ struct { 214 } 215 216 var Companion_Default___ = CompanionStruct_Default___{} 217 218 func (_this *Default__) Equals(other *Default__) bool { 219 return _this == other 220 } 221 222 func (_this *Default__) EqualsGeneric(x interface{}) bool { 223 other, ok := x.(*Default__) 224 return ok && _this.Equals(other) 225 } 226 227 func (*Default__) String() string { 228 return "RawECDHKeyring.Default__" 229 } 230 func (_this *Default__) ParentTraits_() []*_dafny.TraitID { 231 return [](*_dafny.TraitID){} 232 } 233 234 var _ _dafny.TraitOffspring = &Default__{} 235 236 func (_static *CompanionStruct_Default___) ValidPublicKeyLength(p _dafny.Sequence) bool { 237 return (true) && ((((_dafny.IntOfUint32((p).Cardinality())).Cmp(m_Constants.Companion_Default___.ECDH__PUBLIC__KEY__LEN__ECC__NIST__256()) == 0) || ((_dafny.IntOfUint32((p).Cardinality())).Cmp(m_Constants.Companion_Default___.ECDH__PUBLIC__KEY__LEN__ECC__NIST__384()) == 0)) || ((_dafny.IntOfUint32((p).Cardinality())).Cmp(m_Constants.Companion_Default___.ECDH__PUBLIC__KEY__LEN__ECC__NIST__521()) == 0)) 238 } 239 func (_static *CompanionStruct_Default___) ValidCompressedPublicKeyLength(p _dafny.Sequence) bool { 240 return (true) && ((((_dafny.IntOfUint32((p).Cardinality())).Cmp(m_Constants.Companion_Default___.ECDH__PUBLIC__KEY__COMPRESSED__LEN__ECC__NIST__256()) == 0) || ((_dafny.IntOfUint32((p).Cardinality())).Cmp(m_Constants.Companion_Default___.ECDH__PUBLIC__KEY__COMPRESSED__LEN__ECC__NIST__384()) == 0)) || ((_dafny.IntOfUint32((p).Cardinality())).Cmp(m_Constants.Companion_Default___.ECDH__PUBLIC__KEY__COMPRESSED__LEN__ECC__NIST__521()) == 0)) 241 } 242 func (_static *CompanionStruct_Default___) ValidProviderInfoLength(p _dafny.Sequence) bool { 243 return (((_dafny.IntOfUint32((p).Cardinality())).Cmp(_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__256__LEN())) == 0) || ((_dafny.IntOfUint32((p).Cardinality())).Cmp(_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__384__LEN())) == 0)) || ((_dafny.IntOfUint32((p).Cardinality())).Cmp(_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__521__LEN())) == 0) 244 } 245 func (_static *CompanionStruct_Default___) LocalDeriveSharedSecret(senderPrivateKey m_AwsCryptographyPrimitivesTypes.ECCPrivateKey, recipientPublicKey m_AwsCryptographyPrimitivesTypes.ECCPublicKey, curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec, crypto *m_AtomicPrimitives.AtomicPrimitivesClient) m_Wrappers.Result { 246 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 247 _ = res 248 var _0_maybeSharedSecret m_Wrappers.Result 249 _ = _0_maybeSharedSecret 250 var _out0 m_Wrappers.Result 251 _ = _out0 252 _out0 = (crypto).DeriveSharedSecret(m_AwsCryptographyPrimitivesTypes.Companion_DeriveSharedSecretInput_.Create_DeriveSharedSecretInput_(curveSpec, senderPrivateKey, recipientPublicKey)) 253 _0_maybeSharedSecret = _out0 254 var _1_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_DeriveSharedSecretOutput_.Default()) 255 _ = _1_valueOrError0 256 _1_valueOrError0 = (_0_maybeSharedSecret).MapFailure(func(coer110 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 257 return func(arg111 interface{}) interface{} { 258 return coer110(arg111.(m_AwsCryptographyPrimitivesTypes.Error)) 259 } 260 }(func(_2_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error { 261 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_2_e) 262 })) 263 if (_1_valueOrError0).IsFailure() { 264 res = (_1_valueOrError0).PropagateFailure() 265 return res 266 } 267 var _3_sharedSecretOutput m_AwsCryptographyPrimitivesTypes.DeriveSharedSecretOutput 268 _ = _3_sharedSecretOutput 269 _3_sharedSecretOutput = (_1_valueOrError0).Extract().(m_AwsCryptographyPrimitivesTypes.DeriveSharedSecretOutput) 270 res = m_Wrappers.Companion_Result_.Create_Success_((_3_sharedSecretOutput).Dtor_sharedSecret()) 271 return res 272 return res 273 } 274 func (_static *CompanionStruct_Default___) CompressPublicKey(publicKey m_AwsCryptographyPrimitivesTypes.ECCPublicKey, curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec, crypto *m_AtomicPrimitives.AtomicPrimitivesClient) m_Wrappers.Result { 275 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 276 _ = res 277 var _0_maybeCompressedPublicKey m_Wrappers.Result 278 _ = _0_maybeCompressedPublicKey 279 var _out0 m_Wrappers.Result 280 _ = _out0 281 _out0 = (crypto).CompressPublicKey(m_AwsCryptographyPrimitivesTypes.Companion_CompressPublicKeyInput_.Create_CompressPublicKeyInput_(publicKey, curveSpec)) 282 _0_maybeCompressedPublicKey = _out0 283 var _1_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_CompressPublicKeyOutput_.Default()) 284 _ = _1_valueOrError0 285 _1_valueOrError0 = (_0_maybeCompressedPublicKey).MapFailure(func(coer111 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 286 return func(arg112 interface{}) interface{} { 287 return coer111(arg112.(m_AwsCryptographyPrimitivesTypes.Error)) 288 } 289 }(func(_2_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error { 290 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_2_e) 291 })) 292 if (_1_valueOrError0).IsFailure() { 293 res = (_1_valueOrError0).PropagateFailure() 294 return res 295 } 296 var _3_compresedPublicKey m_AwsCryptographyPrimitivesTypes.CompressPublicKeyOutput 297 _ = _3_compresedPublicKey 298 _3_compresedPublicKey = (_1_valueOrError0).Extract().(m_AwsCryptographyPrimitivesTypes.CompressPublicKeyOutput) 299 res = m_Wrappers.Companion_Result_.Create_Success_((_3_compresedPublicKey).Dtor_compressedPublicKey()) 300 return res 301 return res 302 } 303 func (_static *CompanionStruct_Default___) DecompressPublicKey(publicKey _dafny.Sequence, curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec, crypto *m_AtomicPrimitives.AtomicPrimitivesClient) m_Wrappers.Result { 304 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 305 _ = res 306 var _0_maybePublicKey m_Wrappers.Result 307 _ = _0_maybePublicKey 308 var _out0 m_Wrappers.Result 309 _ = _out0 310 _out0 = (crypto).DecompressPublicKey(m_AwsCryptographyPrimitivesTypes.Companion_DecompressPublicKeyInput_.Create_DecompressPublicKeyInput_(publicKey, curveSpec)) 311 _0_maybePublicKey = _out0 312 var _1_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_DecompressPublicKeyOutput_.Default()) 313 _ = _1_valueOrError0 314 _1_valueOrError0 = (_0_maybePublicKey).MapFailure(func(coer112 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 315 return func(arg113 interface{}) interface{} { 316 return coer112(arg113.(m_AwsCryptographyPrimitivesTypes.Error)) 317 } 318 }(func(_2_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error { 319 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_2_e) 320 })) 321 if (_1_valueOrError0).IsFailure() { 322 res = (_1_valueOrError0).PropagateFailure() 323 return res 324 } 325 var _3_publicKey m_AwsCryptographyPrimitivesTypes.DecompressPublicKeyOutput 326 _ = _3_publicKey 327 _3_publicKey = (_1_valueOrError0).Extract().(m_AwsCryptographyPrimitivesTypes.DecompressPublicKeyOutput) 328 res = m_Wrappers.Companion_Result_.Create_Success_(((_3_publicKey).Dtor_publicKey()).Dtor_der()) 329 return res 330 return res 331 } 332 func (_static *CompanionStruct_Default___) SerializeProviderInfo(senderPublicKey _dafny.Sequence, recipientPublicKey _dafny.Sequence) _dafny.Sequence { 333 return _dafny.Companion_Sequence_.Concatenate(_dafny.Companion_Sequence_.Concatenate(_dafny.Companion_Sequence_.Concatenate(_dafny.Companion_Sequence_.Concatenate(Companion_Default___.RAW__ECDH__KEYRING__VERSION(), m_StandardLibrary_UInt.Companion_Default___.UInt32ToSeq(uint32((recipientPublicKey).Cardinality()))), recipientPublicKey), m_StandardLibrary_UInt.Companion_Default___.UInt32ToSeq(uint32((senderPublicKey).Cardinality()))), senderPublicKey) 334 } 335 func (_static *CompanionStruct_Default___) GenerateEphemeralEccKeyPair(curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec, crypto *m_AtomicPrimitives.AtomicPrimitivesClient) m_Wrappers.Result { 336 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_GenerateECCKeyPairOutput_.Default()) 337 _ = res 338 var _0_maybeKeyPair m_Wrappers.Result 339 _ = _0_maybeKeyPair 340 var _out0 m_Wrappers.Result 341 _ = _out0 342 _out0 = (crypto).GenerateECCKeyPair(m_AwsCryptographyPrimitivesTypes.Companion_GenerateECCKeyPairInput_.Create_GenerateECCKeyPairInput_(curveSpec)) 343 _0_maybeKeyPair = _out0 344 var _1_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_GenerateECCKeyPairOutput_.Default()) 345 _ = _1_valueOrError0 346 _1_valueOrError0 = (_0_maybeKeyPair).MapFailure(func(coer113 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 347 return func(arg114 interface{}) interface{} { 348 return coer113(arg114.(m_AwsCryptographyPrimitivesTypes.Error)) 349 } 350 }(func(_2_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error { 351 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_2_e) 352 })) 353 if (_1_valueOrError0).IsFailure() { 354 res = (_1_valueOrError0).PropagateFailure() 355 return res 356 } 357 var _3_keyPair m_AwsCryptographyPrimitivesTypes.GenerateECCKeyPairOutput 358 _ = _3_keyPair 359 _3_keyPair = (_1_valueOrError0).Extract().(m_AwsCryptographyPrimitivesTypes.GenerateECCKeyPairOutput) 360 res = m_Wrappers.Companion_Result_.Create_Success_(_3_keyPair) 361 return res 362 } 363 func (_static *CompanionStruct_Default___) ValidatePublicKey(crypto *m_AtomicPrimitives.AtomicPrimitivesClient, curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec, publicKey _dafny.Sequence) m_Wrappers.Result { 364 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(false) 365 _ = res 366 var _0_maybeValidate m_Wrappers.Result 367 _ = _0_maybeValidate 368 var _out0 m_Wrappers.Result 369 _ = _out0 370 _out0 = (crypto).ValidatePublicKey(m_AwsCryptographyPrimitivesTypes.Companion_ValidatePublicKeyInput_.Create_ValidatePublicKeyInput_(curveSpec, publicKey)) 371 _0_maybeValidate = _out0 372 var _1_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_ValidatePublicKeyOutput_.Default()) 373 _ = _1_valueOrError0 374 _1_valueOrError0 = (_0_maybeValidate).MapFailure(func(coer114 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 375 return func(arg115 interface{}) interface{} { 376 return coer114(arg115.(m_AwsCryptographyPrimitivesTypes.Error)) 377 } 378 }(func(_2_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error { 379 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_2_e) 380 })) 381 if (_1_valueOrError0).IsFailure() { 382 res = (_1_valueOrError0).PropagateFailure() 383 return res 384 } 385 var _3_validate m_AwsCryptographyPrimitivesTypes.ValidatePublicKeyOutput 386 _ = _3_validate 387 _3_validate = (_1_valueOrError0).Extract().(m_AwsCryptographyPrimitivesTypes.ValidatePublicKeyOutput) 388 res = m_Wrappers.Companion_Result_.Create_Success_((_3_validate).Dtor_success()) 389 return res 390 } 391 func (_static *CompanionStruct_Default___) CurveSpecTypeToString(c m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec) _dafny.Sequence { 392 var _source0 m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec = c 393 _ = _source0 394 { 395 if _source0.Is_ECC__NIST__P256() { 396 return _dafny.SeqOfString("p256") 397 } 398 } 399 { 400 if _source0.Is_ECC__NIST__P384() { 401 return _dafny.SeqOfString("p384") 402 } 403 } 404 { 405 if _source0.Is_ECC__NIST__P521() { 406 return _dafny.SeqOfString("p521") 407 } 408 } 409 { 410 return _dafny.SeqOfString("sm2") 411 } 412 } 413 func (_static *CompanionStruct_Default___) E(s _dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error { 414 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(s) 415 } 416 func (_static *CompanionStruct_Default___) RAW__ECDH__KEYRING__VERSION() _dafny.Sequence { 417 return _dafny.SeqOf(uint8(1)) 418 } 419 420 // End of class Default__ 421 422 // Definition of class RawEcdhKeyring 423 type RawEcdhKeyring struct { 424 _cryptoPrimitives *m_AtomicPrimitives.AtomicPrimitivesClient 425 _keyAgreementScheme m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations 426 _curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec 427 _recipientPublicKey m_AwsCryptographyPrimitivesTypes.ECCPublicKey 428 _compressedRecipientPublicKey _dafny.Sequence 429 _senderPublicKey m_AwsCryptographyPrimitivesTypes.ECCPublicKey 430 _senderPrivateKey m_AwsCryptographyPrimitivesTypes.ECCPrivateKey 431 _compressedSenderPublicKey _dafny.Sequence 432 } 433 434 func New_RawEcdhKeyring_() *RawEcdhKeyring { 435 _this := RawEcdhKeyring{} 436 437 _this._cryptoPrimitives = (*m_AtomicPrimitives.AtomicPrimitivesClient)(nil) 438 _this._keyAgreementScheme = m_AwsCryptographyMaterialProvidersTypes.Companion_RawEcdhStaticConfigurations_.Default() 439 _this._curveSpec = m_AwsCryptographyPrimitivesTypes.Companion_ECDHCurveSpec_.Default() 440 _this._recipientPublicKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Default() 441 _this._compressedRecipientPublicKey = _dafny.EmptySeq 442 _this._senderPublicKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Default() 443 _this._senderPrivateKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPrivateKey_.Default() 444 _this._compressedSenderPublicKey = _dafny.EmptySeq 445 return &_this 446 } 447 448 type CompanionStruct_RawEcdhKeyring_ struct { 449 } 450 451 var Companion_RawEcdhKeyring_ = CompanionStruct_RawEcdhKeyring_{} 452 453 func (_this *RawEcdhKeyring) Equals(other *RawEcdhKeyring) bool { 454 return _this == other 455 } 456 457 func (_this *RawEcdhKeyring) EqualsGeneric(x interface{}) bool { 458 other, ok := x.(*RawEcdhKeyring) 459 return ok && _this.Equals(other) 460 } 461 462 func (*RawEcdhKeyring) String() string { 463 return "RawECDHKeyring.RawEcdhKeyring" 464 } 465 466 func Type_RawEcdhKeyring_() _dafny.TypeDescriptor { 467 return type_RawEcdhKeyring_{} 468 } 469 470 type type_RawEcdhKeyring_ struct { 471 } 472 473 func (_this type_RawEcdhKeyring_) Default() interface{} { 474 return (*RawEcdhKeyring)(nil) 475 } 476 477 func (_this type_RawEcdhKeyring_) String() string { 478 return "RawECDHKeyring.RawEcdhKeyring" 479 } 480 func (_this *RawEcdhKeyring) ParentTraits_() []*_dafny.TraitID { 481 return [](*_dafny.TraitID){m_Keyring.Companion_VerifiableInterface_.TraitID_, m_AwsCryptographyMaterialProvidersTypes.Companion_IKeyring_.TraitID_} 482 } 483 484 var _ m_Keyring.VerifiableInterface = &RawEcdhKeyring{} 485 var _ m_AwsCryptographyMaterialProvidersTypes.IKeyring = &RawEcdhKeyring{} 486 var _ _dafny.TraitOffspring = &RawEcdhKeyring{} 487 488 func (_this *RawEcdhKeyring) OnDecrypt(input m_AwsCryptographyMaterialProvidersTypes.OnDecryptInput) m_Wrappers.Result { 489 var _out8 m_Wrappers.Result 490 _ = _out8 491 _out8 = m_AwsCryptographyMaterialProvidersTypes.Companion_IKeyring_.OnDecrypt(_this, input) 492 return _out8 493 } 494 func (_this *RawEcdhKeyring) OnEncrypt(input m_AwsCryptographyMaterialProvidersTypes.OnEncryptInput) m_Wrappers.Result { 495 var _out8 m_Wrappers.Result 496 _ = _out8 497 _out8 = m_AwsCryptographyMaterialProvidersTypes.Companion_IKeyring_.OnEncrypt(_this, input) 498 return _out8 499 } 500 func (_this *RawEcdhKeyring) Ctor__(keyAgreementScheme m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations, curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec, senderPrivateKey m_Wrappers.Option, senderPublicKey m_Wrappers.Option, recipientPublicKey _dafny.Sequence, compressedSenderPublicKey m_Wrappers.Option, compressedRecipientPublicKey _dafny.Sequence, cryptoPrimitives *m_AtomicPrimitives.AtomicPrimitivesClient) { 501 { 502 (_this)._keyAgreementScheme = keyAgreementScheme 503 (_this)._curveSpec = curveSpec 504 (_this)._cryptoPrimitives = cryptoPrimitives 505 (_this)._recipientPublicKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Create_ECCPublicKey_(recipientPublicKey) 506 (_this)._compressedRecipientPublicKey = compressedRecipientPublicKey 507 if (((senderPublicKey).Is_Some()) && ((senderPrivateKey).Is_Some())) && ((compressedSenderPublicKey).Is_Some()) { 508 (_this)._senderPublicKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Create_ECCPublicKey_((senderPublicKey).Dtor_value().(_dafny.Sequence)) 509 (_this)._senderPrivateKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPrivateKey_.Create_ECCPrivateKey_((senderPrivateKey).Dtor_value().(_dafny.Sequence)) 510 (_this)._compressedSenderPublicKey = (compressedSenderPublicKey).Dtor_value().(_dafny.Sequence) 511 } else { 512 (_this)._senderPublicKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Create_ECCPublicKey_(_dafny.SeqOf()) 513 (_this)._senderPrivateKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPrivateKey_.Create_ECCPrivateKey_(_dafny.SeqOf()) 514 (_this)._compressedSenderPublicKey = _dafny.SeqOf() 515 } 516 } 517 } 518 func (_this *RawEcdhKeyring) OnEncrypt_k(input m_AwsCryptographyMaterialProvidersTypes.OnEncryptInput) m_Wrappers.Result { 519 { 520 var res m_Wrappers.Result = m_Wrappers.Result{} 521 _ = res 522 if ((_this).KeyAgreementScheme()).Is_PublicKeyDiscovery() { 523 res = m_Wrappers.Companion_Result_.Create_Failure_(m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("PublicKeyDiscovery Key Agreement Scheme is forbidden on encrypt."))) 524 return res 525 } 526 var _0_operationSenderPrivateKey m_AwsCryptographyPrimitivesTypes.ECCPrivateKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPrivateKey_.Default() 527 _ = _0_operationSenderPrivateKey 528 var _1_operationSenderPublicKey m_AwsCryptographyPrimitivesTypes.ECCPublicKey = m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Default() 529 _ = _1_operationSenderPublicKey 530 var _2_operationCompressedSenderPublicKey _dafny.Sequence = _dafny.EmptySeq 531 _ = _2_operationCompressedSenderPublicKey 532 if ((_this).KeyAgreementScheme()).Is_EphemeralPrivateKeyToStaticPublicKey() { 533 var _3_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyPrimitivesTypes.Companion_GenerateECCKeyPairOutput_.Default()) 534 _ = _3_valueOrError0 535 var _out0 m_Wrappers.Result 536 _ = _out0 537 _out0 = Companion_Default___.GenerateEphemeralEccKeyPair((_this).CurveSpec(), (_this).CryptoPrimitives()) 538 _3_valueOrError0 = _out0 539 if (_3_valueOrError0).IsFailure() { 540 res = (_3_valueOrError0).PropagateFailure() 541 return res 542 } 543 var _4_ephemeralKeyPair m_AwsCryptographyPrimitivesTypes.GenerateECCKeyPairOutput 544 _ = _4_ephemeralKeyPair 545 _4_ephemeralKeyPair = (_3_valueOrError0).Extract().(m_AwsCryptographyPrimitivesTypes.GenerateECCKeyPairOutput) 546 _0_operationSenderPrivateKey = (_4_ephemeralKeyPair).Dtor_privateKey() 547 _1_operationSenderPublicKey = (_4_ephemeralKeyPair).Dtor_publicKey() 548 var _5_valueOrError1 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 549 _ = _5_valueOrError1 550 var _out1 m_Wrappers.Result 551 _ = _out1 552 _out1 = Companion_Default___.CompressPublicKey(m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Create_ECCPublicKey_((_1_operationSenderPublicKey).Dtor_der()), (_this).CurveSpec(), (_this).CryptoPrimitives()) 553 _5_valueOrError1 = _out1 554 if (_5_valueOrError1).IsFailure() { 555 res = (_5_valueOrError1).PropagateFailure() 556 return res 557 } 558 var _6_operationCompressedSenderPublicKey_q _dafny.Sequence 559 _ = _6_operationCompressedSenderPublicKey_q 560 _6_operationCompressedSenderPublicKey_q = (_5_valueOrError1).Extract().(_dafny.Sequence) 561 _2_operationCompressedSenderPublicKey = _6_operationCompressedSenderPublicKey_q 562 } else { 563 _0_operationSenderPrivateKey = (_this).SenderPrivateKey() 564 _1_operationSenderPublicKey = (_this).SenderPublicKey() 565 _2_operationCompressedSenderPublicKey = (_this).CompressedSenderPublicKey() 566 } 567 var _7_materials m_AwsCryptographyMaterialProvidersTypes.EncryptionMaterials 568 _ = _7_materials 569 _7_materials = (input).Dtor_materials() 570 var _8_suite m_AwsCryptographyMaterialProvidersTypes.AlgorithmSuiteInfo 571 _ = _8_suite 572 _8_suite = ((input).Dtor_materials()).Dtor_algorithmSuite() 573 var _9_valueOrError2 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 574 _ = _9_valueOrError2 575 var _out2 m_Wrappers.Result 576 _ = _out2 577 _out2 = Companion_Default___.LocalDeriveSharedSecret(_0_operationSenderPrivateKey, (_this).RecipientPublicKey(), (_this).CurveSpec(), (_this).CryptoPrimitives()) 578 _9_valueOrError2 = _out2 579 if (_9_valueOrError2).IsFailure() { 580 res = (_9_valueOrError2).PropagateFailure() 581 return res 582 } 583 var _10_sharedSecret _dafny.Sequence 584 _ = _10_sharedSecret 585 _10_sharedSecret = (_9_valueOrError2).Extract().(_dafny.Sequence) 586 var _11_valueOrError3 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_UTF8.Companion_ValidUTF8Bytes_.Witness()) 587 _ = _11_valueOrError3 588 _11_valueOrError3 = (m_UTF8.Encode(Companion_Default___.CurveSpecTypeToString((_this).CurveSpec()))).MapFailure(func(coer115 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 589 return func(arg116 interface{}) interface{} { 590 return coer115(arg116.(_dafny.Sequence)) 591 } 592 }(Companion_Default___.E)) 593 if (_11_valueOrError3).IsFailure() { 594 res = (_11_valueOrError3).PropagateFailure() 595 return res 596 } 597 var _12_curveSpecUtf8 _dafny.Sequence 598 _ = _12_curveSpecUtf8 599 _12_curveSpecUtf8 = (_11_valueOrError3).Extract().(_dafny.Sequence) 600 var _13_valueOrError4 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 601 _ = _13_valueOrError4 602 _13_valueOrError4 = m_CanonicalEncryptionContext.Companion_Default___.EncryptionContextToAAD(((input).Dtor_materials()).Dtor_encryptionContext()) 603 if (_13_valueOrError4).IsFailure() { 604 res = (_13_valueOrError4).PropagateFailure() 605 return res 606 } 607 var _14_canonicalizedEC _dafny.Sequence 608 _ = _14_canonicalizedEC 609 _14_canonicalizedEC = (_13_valueOrError4).Extract().(_dafny.Sequence) 610 var _15_fixedInfo _dafny.Sequence 611 _ = _15_fixedInfo 612 _15_fixedInfo = m_EcdhEdkWrapping.Companion_Default___.SerializeFixedInfo(m_Constants.Companion_Default___.ECDH__KDF__UTF8(), _12_curveSpecUtf8, _2_operationCompressedSenderPublicKey, (_this).CompressedRecipientPublicKey(), _14_canonicalizedEC, Companion_Default___.RAW__ECDH__KEYRING__VERSION()) 613 var _16_ecdhGenerateAndWrap *m_EcdhEdkWrapping.EcdhGenerateAndWrapKeyMaterial 614 _ = _16_ecdhGenerateAndWrap 615 var _nw0 *m_EcdhEdkWrapping.EcdhGenerateAndWrapKeyMaterial = m_EcdhEdkWrapping.New_EcdhGenerateAndWrapKeyMaterial_() 616 _ = _nw0 617 _nw0.Ctor__(_10_sharedSecret, _15_fixedInfo, (_this).CryptoPrimitives()) 618 _16_ecdhGenerateAndWrap = _nw0 619 var _17_ecdhWrap *m_EcdhEdkWrapping.EcdhWrapKeyMaterial 620 _ = _17_ecdhWrap 621 var _nw1 *m_EcdhEdkWrapping.EcdhWrapKeyMaterial = m_EcdhEdkWrapping.New_EcdhWrapKeyMaterial_() 622 _ = _nw1 623 _nw1.Ctor__(_10_sharedSecret, _15_fixedInfo, (_this).CryptoPrimitives()) 624 _17_ecdhWrap = _nw1 625 var _18_valueOrError5 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_EdkWrapping.Companion_WrapEdkMaterialOutput_.Default(m_EcdhEdkWrapping.Companion_EcdhWrapInfo_.Default())) 626 _ = _18_valueOrError5 627 var _out3 m_Wrappers.Result 628 _ = _out3 629 _out3 = m_EdkWrapping.Companion_Default___.WrapEdkMaterial(_7_materials, _17_ecdhWrap, _16_ecdhGenerateAndWrap) 630 _18_valueOrError5 = _out3 631 if (_18_valueOrError5).IsFailure() { 632 res = (_18_valueOrError5).PropagateFailure() 633 return res 634 } 635 var _19_wrapOutput m_EdkWrapping.WrapEdkMaterialOutput 636 _ = _19_wrapOutput 637 _19_wrapOutput = (_18_valueOrError5).Extract().(m_EdkWrapping.WrapEdkMaterialOutput) 638 var _20_symmetricSigningKeyList m_Wrappers.Option 639 _ = _20_symmetricSigningKeyList 640 if ((_19_wrapOutput).Dtor_symmetricSigningKey()).Is_Some() { 641 _20_symmetricSigningKeyList = m_Wrappers.Companion_Option_.Create_Some_(_dafny.SeqOf(((_19_wrapOutput).Dtor_symmetricSigningKey()).Dtor_value().(_dafny.Sequence))) 642 } else { 643 _20_symmetricSigningKeyList = m_Wrappers.Companion_Option_.Create_None_() 644 } 645 var _21_valueOrError6 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 646 _ = _21_valueOrError6 647 _21_valueOrError6 = m_Wrappers.Companion_Default___.Need((Companion_Default___.ValidCompressedPublicKeyLength(_2_operationCompressedSenderPublicKey)) && (Companion_Default___.ValidCompressedPublicKeyLength((_this).CompressedRecipientPublicKey())), Companion_Default___.E(_dafny.SeqOfString("Invalid compressed public key length."))) 648 if (_21_valueOrError6).IsFailure() { 649 res = (_21_valueOrError6).PropagateFailure() 650 return res 651 } 652 var _22_edk m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey 653 _ = _22_edk 654 _22_edk = m_AwsCryptographyMaterialProvidersTypes.Companion_EncryptedDataKey_.Create_EncryptedDataKey_(m_Constants.Companion_Default___.RAW__ECDH__PROVIDER__ID(), Companion_Default___.SerializeProviderInfo(_2_operationCompressedSenderPublicKey, (_this).CompressedRecipientPublicKey()), (_19_wrapOutput).Dtor_wrappedMaterial()) 655 if (_19_wrapOutput).Is_GenerateAndWrapEdkMaterialOutput() { 656 var _23_valueOrError7 m_Wrappers.Result = m_Wrappers.Result{} 657 _ = _23_valueOrError7 658 _23_valueOrError7 = m_Materials.Companion_Default___.EncryptionMaterialAddDataKey(_7_materials, (_19_wrapOutput).Dtor_plaintextDataKey(), _dafny.SeqOf(_22_edk), _20_symmetricSigningKeyList) 659 if (_23_valueOrError7).IsFailure() { 660 res = (_23_valueOrError7).PropagateFailure() 661 return res 662 } 663 var _24_result m_AwsCryptographyMaterialProvidersTypes.EncryptionMaterials 664 _ = _24_result 665 _24_result = (_23_valueOrError7).Extract().(m_AwsCryptographyMaterialProvidersTypes.EncryptionMaterials) 666 res = m_Wrappers.Companion_Result_.Create_Success_(m_AwsCryptographyMaterialProvidersTypes.Companion_OnEncryptOutput_.Create_OnEncryptOutput_(_24_result)) 667 return res 668 } else if (_19_wrapOutput).Is_WrapOnlyEdkMaterialOutput() { 669 var _25_valueOrError8 m_Wrappers.Result = m_Wrappers.Result{} 670 _ = _25_valueOrError8 671 _25_valueOrError8 = m_Materials.Companion_Default___.EncryptionMaterialAddEncryptedDataKeys(_7_materials, _dafny.SeqOf(_22_edk), _20_symmetricSigningKeyList) 672 if (_25_valueOrError8).IsFailure() { 673 res = (_25_valueOrError8).PropagateFailure() 674 return res 675 } 676 var _26_result m_AwsCryptographyMaterialProvidersTypes.EncryptionMaterials 677 _ = _26_result 678 _26_result = (_25_valueOrError8).Extract().(m_AwsCryptographyMaterialProvidersTypes.EncryptionMaterials) 679 res = m_Wrappers.Companion_Result_.Create_Success_(m_AwsCryptographyMaterialProvidersTypes.Companion_OnEncryptOutput_.Create_OnEncryptOutput_(_26_result)) 680 return res 681 } 682 return res 683 } 684 } 685 func (_this *RawEcdhKeyring) OnDecrypt_k(input m_AwsCryptographyMaterialProvidersTypes.OnDecryptInput) m_Wrappers.Result { 686 { 687 var res m_Wrappers.Result = m_Wrappers.Result{} 688 _ = res 689 if ((_this).KeyAgreementScheme()).Is_EphemeralPrivateKeyToStaticPublicKey() { 690 res = m_Wrappers.Companion_Result_.Create_Failure_(m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("EphemeralPrivateKeyToStaticPublicKey Key Agreement Scheme is forbidden on decrypt."))) 691 return res 692 } 693 var _0_materials m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials 694 _ = _0_materials 695 _0_materials = (input).Dtor_materials() 696 var _1_suite m_AwsCryptographyMaterialProvidersTypes.AlgorithmSuiteInfo 697 _ = _1_suite 698 _1_suite = ((input).Dtor_materials()).Dtor_algorithmSuite() 699 var _2_valueOrError0 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 700 _ = _2_valueOrError0 701 _2_valueOrError0 = m_Wrappers.Companion_Default___.Need(m_Materials.Companion_Default___.DecryptionMaterialsWithoutPlaintextDataKey(_0_materials), Companion_Default___.E(_dafny.SeqOfString("Keyring received decryption materials that already contain a plaintext data key."))) 702 if (_2_valueOrError0).IsFailure() { 703 res = (_2_valueOrError0).PropagateFailure() 704 return res 705 } 706 var _3_operationCompressedSenderPublicKey m_Wrappers.Option 707 _ = _3_operationCompressedSenderPublicKey 708 if _dafny.Companion_Sequence_.Equal((_this).CompressedSenderPublicKey(), _dafny.SeqOf()) { 709 _3_operationCompressedSenderPublicKey = m_Wrappers.Companion_Option_.Create_None_() 710 } else { 711 _3_operationCompressedSenderPublicKey = m_Wrappers.Companion_Option_.Create_Some_((_this).CompressedSenderPublicKey()) 712 } 713 var _4_filter *OnDecryptEcdhDataKeyFilter 714 _ = _4_filter 715 var _nw0 *OnDecryptEcdhDataKeyFilter = New_OnDecryptEcdhDataKeyFilter_() 716 _ = _nw0 717 _nw0.Ctor__((_this).KeyAgreementScheme(), (_this).CompressedRecipientPublicKey(), _3_operationCompressedSenderPublicKey) 718 _4_filter = _nw0 719 var _5_valueOrError1 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 720 _ = _5_valueOrError1 721 var _out0 m_Wrappers.Result 722 _ = _out0 723 _out0 = m_Actions.Companion_Default___.FilterWithResult(_4_filter, (input).Dtor_encryptedDataKeys()) 724 _5_valueOrError1 = _out0 725 if (_5_valueOrError1).IsFailure() { 726 res = (_5_valueOrError1).PropagateFailure() 727 return res 728 } 729 var _6_edksToAttempt _dafny.Sequence 730 _ = _6_edksToAttempt 731 _6_edksToAttempt = (_5_valueOrError1).Extract().(_dafny.Sequence) 732 if (_dafny.IntOfUint32((_6_edksToAttempt).Cardinality())).Sign() == 0 { 733 var _7_valueOrError2 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq.SetString()) 734 _ = _7_valueOrError2 735 _7_valueOrError2 = m_ErrorMessages.Companion_Default___.IncorrectDataKeys((input).Dtor_encryptedDataKeys(), ((input).Dtor_materials()).Dtor_algorithmSuite(), _dafny.SeqOfString("")) 736 if (_7_valueOrError2).IsFailure() { 737 res = (_7_valueOrError2).PropagateFailure() 738 return res 739 } 740 var _8_errorMessage _dafny.Sequence 741 _ = _8_errorMessage 742 _8_errorMessage = (_7_valueOrError2).Extract().(_dafny.Sequence) 743 res = m_Wrappers.Companion_Result_.Create_Failure_(Companion_Default___.E(_8_errorMessage)) 744 return res 745 } 746 var _9_decryptClosure m_Actions.ActionWithResult 747 _ = _9_decryptClosure 748 var _nw1 *DecryptSingleEncryptedDataKey = New_DecryptSingleEncryptedDataKey_() 749 _ = _nw1 750 _nw1.Ctor__(_0_materials, (_this).CryptoPrimitives(), (_this).CompressedSenderPublicKey(), (_this).CompressedRecipientPublicKey(), (_this).KeyAgreementScheme(), (_this).CurveSpec()) 751 _9_decryptClosure = _nw1 752 var _10_outcome m_Wrappers.Result 753 _ = _10_outcome 754 var _out1 m_Wrappers.Result 755 _ = _out1 756 _out1 = m_Actions.Companion_Default___.ReduceToSuccess(_9_decryptClosure, _6_edksToAttempt) 757 _10_outcome = _out1 758 var _11_valueOrError3 m_Wrappers.Result = m_Wrappers.Result{} 759 _ = _11_valueOrError3 760 _11_valueOrError3 = (_10_outcome).MapFailure(func(coer116 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} { 761 return func(arg117 interface{}) interface{} { 762 return coer116(arg117.(_dafny.Sequence)) 763 } 764 }(func(_12_errors _dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error { 765 return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_CollectionOfErrors_(_12_errors, _dafny.SeqOfString("No Configured Key was able to decrypt the Data Key. The list of encountered Exceptions is available via `list`.")) 766 })) 767 if (_11_valueOrError3).IsFailure() { 768 res = (_11_valueOrError3).PropagateFailure() 769 return res 770 } 771 var _13_SealedDecryptionMaterials m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials 772 _ = _13_SealedDecryptionMaterials 773 _13_SealedDecryptionMaterials = (_11_valueOrError3).Extract().(m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials) 774 res = m_Wrappers.Companion_Result_.Create_Success_(m_AwsCryptographyMaterialProvidersTypes.Companion_OnDecryptOutput_.Create_OnDecryptOutput_(_13_SealedDecryptionMaterials)) 775 return res 776 return res 777 } 778 } 779 func (_this *RawEcdhKeyring) CryptoPrimitives() *m_AtomicPrimitives.AtomicPrimitivesClient { 780 { 781 return _this._cryptoPrimitives 782 } 783 } 784 func (_this *RawEcdhKeyring) KeyAgreementScheme() m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations { 785 { 786 return _this._keyAgreementScheme 787 } 788 } 789 func (_this *RawEcdhKeyring) CurveSpec() m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec { 790 { 791 return _this._curveSpec 792 } 793 } 794 func (_this *RawEcdhKeyring) RecipientPublicKey() m_AwsCryptographyPrimitivesTypes.ECCPublicKey { 795 { 796 return _this._recipientPublicKey 797 } 798 } 799 func (_this *RawEcdhKeyring) CompressedRecipientPublicKey() _dafny.Sequence { 800 { 801 return _this._compressedRecipientPublicKey 802 } 803 } 804 func (_this *RawEcdhKeyring) SenderPublicKey() m_AwsCryptographyPrimitivesTypes.ECCPublicKey { 805 { 806 return _this._senderPublicKey 807 } 808 } 809 func (_this *RawEcdhKeyring) SenderPrivateKey() m_AwsCryptographyPrimitivesTypes.ECCPrivateKey { 810 { 811 return _this._senderPrivateKey 812 } 813 } 814 func (_this *RawEcdhKeyring) CompressedSenderPublicKey() _dafny.Sequence { 815 { 816 return _this._compressedSenderPublicKey 817 } 818 } 819 820 // End of class RawEcdhKeyring 821 822 // Definition of class OnDecryptEcdhDataKeyFilter 823 type OnDecryptEcdhDataKeyFilter struct { 824 _keyAgreementScheme m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations 825 _compressedRecipientPublicKey _dafny.Sequence 826 _compressedSenderPublicKey _dafny.Sequence 827 } 828 829 func New_OnDecryptEcdhDataKeyFilter_() *OnDecryptEcdhDataKeyFilter { 830 _this := OnDecryptEcdhDataKeyFilter{} 831 832 _this._keyAgreementScheme = m_AwsCryptographyMaterialProvidersTypes.Companion_RawEcdhStaticConfigurations_.Default() 833 _this._compressedRecipientPublicKey = _dafny.EmptySeq 834 _this._compressedSenderPublicKey = _dafny.EmptySeq 835 return &_this 836 } 837 838 type CompanionStruct_OnDecryptEcdhDataKeyFilter_ struct { 839 } 840 841 var Companion_OnDecryptEcdhDataKeyFilter_ = CompanionStruct_OnDecryptEcdhDataKeyFilter_{} 842 843 func (_this *OnDecryptEcdhDataKeyFilter) Equals(other *OnDecryptEcdhDataKeyFilter) bool { 844 return _this == other 845 } 846 847 func (_this *OnDecryptEcdhDataKeyFilter) EqualsGeneric(x interface{}) bool { 848 other, ok := x.(*OnDecryptEcdhDataKeyFilter) 849 return ok && _this.Equals(other) 850 } 851 852 func (*OnDecryptEcdhDataKeyFilter) String() string { 853 return "RawECDHKeyring.OnDecryptEcdhDataKeyFilter" 854 } 855 856 func Type_OnDecryptEcdhDataKeyFilter_() _dafny.TypeDescriptor { 857 return type_OnDecryptEcdhDataKeyFilter_{} 858 } 859 860 type type_OnDecryptEcdhDataKeyFilter_ struct { 861 } 862 863 func (_this type_OnDecryptEcdhDataKeyFilter_) Default() interface{} { 864 return (*OnDecryptEcdhDataKeyFilter)(nil) 865 } 866 867 func (_this type_OnDecryptEcdhDataKeyFilter_) String() string { 868 return "RawECDHKeyring.OnDecryptEcdhDataKeyFilter" 869 } 870 func (_this *OnDecryptEcdhDataKeyFilter) ParentTraits_() []*_dafny.TraitID { 871 return [](*_dafny.TraitID){m_Actions.Companion_DeterministicActionWithResult_.TraitID_, m_Actions.Companion_DeterministicAction_.TraitID_} 872 } 873 874 var _ m_Actions.DeterministicActionWithResult = &OnDecryptEcdhDataKeyFilter{} 875 var _ m_Actions.DeterministicAction = &OnDecryptEcdhDataKeyFilter{} 876 var _ _dafny.TraitOffspring = &OnDecryptEcdhDataKeyFilter{} 877 878 func (_this *OnDecryptEcdhDataKeyFilter) Ctor__(keyAgreementScheme m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations, compressedRecipientPublicKey _dafny.Sequence, compressedSenderPublicKey m_Wrappers.Option) { 879 { 880 (_this)._keyAgreementScheme = keyAgreementScheme 881 (_this)._compressedRecipientPublicKey = compressedRecipientPublicKey 882 if (compressedSenderPublicKey).Is_Some() { 883 (_this)._compressedSenderPublicKey = (compressedSenderPublicKey).Dtor_value().(_dafny.Sequence) 884 } else { 885 (_this)._compressedSenderPublicKey = _dafny.SeqOf() 886 } 887 } 888 } 889 func (_this *OnDecryptEcdhDataKeyFilter) Invoke(edk interface{}) interface{} { 890 { 891 var edk m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey = edk.(m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey) 892 _ = edk 893 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(false) 894 _ = res 895 var _0_providerInfo _dafny.Sequence 896 _ = _0_providerInfo 897 _0_providerInfo = (edk).Dtor_keyProviderInfo() 898 var _1_providerId _dafny.Sequence 899 _ = _1_providerId 900 _1_providerId = (edk).Dtor_keyProviderId() 901 if (!_dafny.Companion_Sequence_.Equal(_1_providerId, m_Constants.Companion_Default___.RAW__ECDH__PROVIDER__ID())) && (!_dafny.Companion_Sequence_.Equal(_1_providerId, m_Constants.Companion_Default___.KMS__ECDH__PROVIDER__ID())) { 902 res = m_Wrappers.Companion_Result_.Create_Success_(false) 903 return res 904 } 905 var _2_valueOrError0 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 906 _ = _2_valueOrError0 907 _2_valueOrError0 = m_Wrappers.Companion_Default___.Need(((_dafny.IntOfUint32((_0_providerInfo).Cardinality())).Cmp(_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__521__LEN())) <= 0) && (Companion_Default___.ValidProviderInfoLength(_0_providerInfo)), Companion_Default___.E(_dafny.SeqOfString("EDK ProviderInfo longer than expected"))) 908 if (_2_valueOrError0).IsFailure() { 909 res = (_2_valueOrError0).PropagateFailure() 910 return res 911 } 912 var _3_keyringVersion uint8 913 _ = _3_keyringVersion 914 _3_keyringVersion = (_0_providerInfo).Select(0).(uint8) 915 var _4_valueOrError1 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 916 _ = _4_valueOrError1 917 _4_valueOrError1 = m_Wrappers.Companion_Default___.Need(_dafny.Companion_Sequence_.Equal(_dafny.SeqOf(_3_keyringVersion), Companion_Default___.RAW__ECDH__KEYRING__VERSION()), Companion_Default___.E(_dafny.SeqOfString("Incorrect Keyring version found in provider info."))) 918 if (_4_valueOrError1).IsFailure() { 919 res = (_4_valueOrError1).PropagateFailure() 920 return res 921 } 922 var _5_recipientPublicKeyLength _dafny.Int 923 _ = _5_recipientPublicKeyLength 924 _5_recipientPublicKeyLength = _dafny.IntOfUint32(m_StandardLibrary_UInt.Companion_Default___.SeqToUInt32((_0_providerInfo).Subsequence(uint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPL__INDEX()), uint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPK__INDEX())))) 925 var _6_recipientPublicKeyLengthIndex _dafny.Int 926 _ = _6_recipientPublicKeyLengthIndex 927 _6_recipientPublicKeyLengthIndex = (_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPK__INDEX())).Plus(_5_recipientPublicKeyLength) 928 var _7_senderPublicKeyIndex _dafny.Int 929 _ = _7_senderPublicKeyIndex 930 _7_senderPublicKeyIndex = (_6_recipientPublicKeyLengthIndex).Plus(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__PUBLIC__KEY__LEN()) 931 var _8_valueOrError2 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 932 _ = _8_valueOrError2 933 _8_valueOrError2 = m_Wrappers.Companion_Default___.Need(((_6_recipientPublicKeyLengthIndex).Plus(_dafny.IntOfInt64(4))).Cmp(_dafny.IntOfUint32((_0_providerInfo).Cardinality())) < 0, Companion_Default___.E(_dafny.SeqOfString("Key Provider Info Serialization Error. Serialized length less than expected."))) 934 if (_8_valueOrError2).IsFailure() { 935 res = (_8_valueOrError2).PropagateFailure() 936 return res 937 } 938 var _9_providerInfoRecipientPublicKey _dafny.Sequence 939 _ = _9_providerInfoRecipientPublicKey 940 _9_providerInfoRecipientPublicKey = (_0_providerInfo).Subsequence(uint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPK__INDEX()), (_6_recipientPublicKeyLengthIndex).Uint32()) 941 var _10_providerInfoSenderPublicKey _dafny.Sequence 942 _ = _10_providerInfoSenderPublicKey 943 _10_providerInfoSenderPublicKey = (_0_providerInfo).Drop((_7_senderPublicKeyIndex).Uint32()) 944 if ((_this).KeyAgreementScheme()).Is_PublicKeyDiscovery() { 945 res = m_Wrappers.Companion_Result_.Create_Success_(_dafny.Companion_Sequence_.Equal((_this).CompressedRecipientPublicKey(), _9_providerInfoRecipientPublicKey)) 946 return res 947 } else { 948 res = m_Wrappers.Companion_Result_.Create_Success_(((_dafny.Companion_Sequence_.Equal((_this).CompressedSenderPublicKey(), _10_providerInfoSenderPublicKey)) && (_dafny.Companion_Sequence_.Equal((_this).CompressedRecipientPublicKey(), _9_providerInfoRecipientPublicKey))) || ((_dafny.Companion_Sequence_.Equal((_this).CompressedSenderPublicKey(), _9_providerInfoRecipientPublicKey)) && (_dafny.Companion_Sequence_.Equal((_this).CompressedRecipientPublicKey(), _10_providerInfoSenderPublicKey)))) 949 return res 950 } 951 return res 952 } 953 } 954 func (_this *OnDecryptEcdhDataKeyFilter) KeyAgreementScheme() m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations { 955 { 956 return _this._keyAgreementScheme 957 } 958 } 959 func (_this *OnDecryptEcdhDataKeyFilter) CompressedRecipientPublicKey() _dafny.Sequence { 960 { 961 return _this._compressedRecipientPublicKey 962 } 963 } 964 func (_this *OnDecryptEcdhDataKeyFilter) CompressedSenderPublicKey() _dafny.Sequence { 965 { 966 return _this._compressedSenderPublicKey 967 } 968 } 969 970 // End of class OnDecryptEcdhDataKeyFilter 971 972 // Definition of class DecryptSingleEncryptedDataKey 973 type DecryptSingleEncryptedDataKey struct { 974 _materials m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials 975 _cryptoPrimitives *m_AtomicPrimitives.AtomicPrimitivesClient 976 _recipientPublicKey _dafny.Sequence 977 _senderPublicKey _dafny.Sequence 978 _keyAgreementScheme m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations 979 _curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec 980 } 981 982 func New_DecryptSingleEncryptedDataKey_() *DecryptSingleEncryptedDataKey { 983 _this := DecryptSingleEncryptedDataKey{} 984 985 _this._materials = m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials{} 986 _this._cryptoPrimitives = (*m_AtomicPrimitives.AtomicPrimitivesClient)(nil) 987 _this._recipientPublicKey = _dafny.EmptySeq 988 _this._senderPublicKey = _dafny.EmptySeq 989 _this._keyAgreementScheme = m_AwsCryptographyMaterialProvidersTypes.Companion_RawEcdhStaticConfigurations_.Default() 990 _this._curveSpec = m_AwsCryptographyPrimitivesTypes.Companion_ECDHCurveSpec_.Default() 991 return &_this 992 } 993 994 type CompanionStruct_DecryptSingleEncryptedDataKey_ struct { 995 } 996 997 var Companion_DecryptSingleEncryptedDataKey_ = CompanionStruct_DecryptSingleEncryptedDataKey_{} 998 999 func (_this *DecryptSingleEncryptedDataKey) Equals(other *DecryptSingleEncryptedDataKey) bool { 1000 return _this == other 1001 } 1002 1003 func (_this *DecryptSingleEncryptedDataKey) EqualsGeneric(x interface{}) bool { 1004 other, ok := x.(*DecryptSingleEncryptedDataKey) 1005 return ok && _this.Equals(other) 1006 } 1007 1008 func (*DecryptSingleEncryptedDataKey) String() string { 1009 return "RawECDHKeyring.DecryptSingleEncryptedDataKey" 1010 } 1011 1012 func Type_DecryptSingleEncryptedDataKey_() _dafny.TypeDescriptor { 1013 return type_DecryptSingleEncryptedDataKey_{} 1014 } 1015 1016 type type_DecryptSingleEncryptedDataKey_ struct { 1017 } 1018 1019 func (_this type_DecryptSingleEncryptedDataKey_) Default() interface{} { 1020 return (*DecryptSingleEncryptedDataKey)(nil) 1021 } 1022 1023 func (_this type_DecryptSingleEncryptedDataKey_) String() string { 1024 return "RawECDHKeyring.DecryptSingleEncryptedDataKey" 1025 } 1026 func (_this *DecryptSingleEncryptedDataKey) ParentTraits_() []*_dafny.TraitID { 1027 return [](*_dafny.TraitID){m_Actions.Companion_ActionWithResult_.TraitID_, m_Actions.Companion_Action_.TraitID_} 1028 } 1029 1030 var _ m_Actions.ActionWithResult = &DecryptSingleEncryptedDataKey{} 1031 var _ m_Actions.Action = &DecryptSingleEncryptedDataKey{} 1032 var _ _dafny.TraitOffspring = &DecryptSingleEncryptedDataKey{} 1033 1034 func (_this *DecryptSingleEncryptedDataKey) Ctor__(materials m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials, cryptoPrimitives *m_AtomicPrimitives.AtomicPrimitivesClient, senderPublicKey _dafny.Sequence, recipientPublicKey _dafny.Sequence, keyAgreementScheme m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations, curveSpec m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec) { 1035 { 1036 (_this)._materials = materials 1037 (_this)._cryptoPrimitives = cryptoPrimitives 1038 (_this)._recipientPublicKey = recipientPublicKey 1039 (_this)._senderPublicKey = senderPublicKey 1040 (_this)._keyAgreementScheme = keyAgreementScheme 1041 (_this)._curveSpec = curveSpec 1042 } 1043 } 1044 func (_this *DecryptSingleEncryptedDataKey) Invoke(edk interface{}) interface{} { 1045 { 1046 var edk m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey = edk.(m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey) 1047 _ = edk 1048 var res m_Wrappers.Result = m_Wrappers.Result{} 1049 _ = res 1050 var _0_valueOrError0 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 1051 _ = _0_valueOrError0 1052 _0_valueOrError0 = m_Wrappers.Companion_Default___.Need(m_UTF8.Companion_Default___.ValidUTF8Seq((edk).Dtor_keyProviderId()), m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("Received invalid EDK provider id for AWS KMS ECDH Keyring"))) 1053 if (_0_valueOrError0).IsFailure() { 1054 res = (_0_valueOrError0).PropagateFailure() 1055 return res 1056 } 1057 var _1_suite m_AwsCryptographyMaterialProvidersTypes.AlgorithmSuiteInfo 1058 _ = _1_suite 1059 _1_suite = ((_this).Materials()).Dtor_algorithmSuite() 1060 var _2_keyProviderId _dafny.Sequence 1061 _ = _2_keyProviderId 1062 _2_keyProviderId = (edk).Dtor_keyProviderId() 1063 var _3_providerInfo _dafny.Sequence 1064 _ = _3_providerInfo 1065 _3_providerInfo = (edk).Dtor_keyProviderInfo() 1066 var _4_ciphertext _dafny.Sequence 1067 _ = _4_ciphertext 1068 _4_ciphertext = (edk).Dtor_ciphertext() 1069 var _5_valueOrError1 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 1070 _ = _5_valueOrError1 1071 _5_valueOrError1 = m_EdkWrapping.Companion_Default___.GetProviderWrappedMaterial(_4_ciphertext, _1_suite) 1072 if (_5_valueOrError1).IsFailure() { 1073 res = (_5_valueOrError1).PropagateFailure() 1074 return res 1075 } 1076 var _6_providerWrappedMaterial _dafny.Sequence 1077 _ = _6_providerWrappedMaterial 1078 _6_providerWrappedMaterial = (_5_valueOrError1).Extract().(_dafny.Sequence) 1079 var _7_valueOrError2 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 1080 _ = _7_valueOrError2 1081 _7_valueOrError2 = m_Wrappers.Companion_Default___.Need(((_dafny.IntOfUint32((_3_providerInfo).Cardinality())).Cmp(_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__521__LEN())) <= 0) && (Companion_Default___.ValidProviderInfoLength(_3_providerInfo)), Companion_Default___.E(_dafny.SeqOfString("EDK ProviderInfo longer than expected"))) 1082 if (_7_valueOrError2).IsFailure() { 1083 res = (_7_valueOrError2).PropagateFailure() 1084 return res 1085 } 1086 var _8_keyringVersion uint8 1087 _ = _8_keyringVersion 1088 _8_keyringVersion = (_3_providerInfo).Select(0).(uint8) 1089 var _9_valueOrError3 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 1090 _ = _9_valueOrError3 1091 _9_valueOrError3 = m_Wrappers.Companion_Default___.Need(_dafny.Companion_Sequence_.Equal(_dafny.SeqOf(_8_keyringVersion), Companion_Default___.RAW__ECDH__KEYRING__VERSION()), Companion_Default___.E(_dafny.SeqOfString("Incorrect Keyring version found in provider info."))) 1092 if (_9_valueOrError3).IsFailure() { 1093 res = (_9_valueOrError3).PropagateFailure() 1094 return res 1095 } 1096 var _10_recipientPublicKeyLength _dafny.Int 1097 _ = _10_recipientPublicKeyLength 1098 _10_recipientPublicKeyLength = _dafny.IntOfUint32(m_StandardLibrary_UInt.Companion_Default___.SeqToUInt32((_3_providerInfo).Subsequence(uint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPL__INDEX()), uint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPK__INDEX())))) 1099 var _11_recipientPublicKeyLengthIndex _dafny.Int 1100 _ = _11_recipientPublicKeyLengthIndex 1101 _11_recipientPublicKeyLengthIndex = (_dafny.IntOfUint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPK__INDEX())).Plus(_10_recipientPublicKeyLength) 1102 var _12_senderPublicKeyIndex _dafny.Int 1103 _ = _12_senderPublicKeyIndex 1104 _12_senderPublicKeyIndex = (_11_recipientPublicKeyLengthIndex).Plus(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__PUBLIC__KEY__LEN()) 1105 var _13_valueOrError4 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 1106 _ = _13_valueOrError4 1107 _13_valueOrError4 = m_Wrappers.Companion_Default___.Need(((_11_recipientPublicKeyLengthIndex).Plus(_dafny.IntOfInt64(4))).Cmp(_dafny.IntOfUint32((_3_providerInfo).Cardinality())) < 0, Companion_Default___.E(_dafny.SeqOfString("Key Provider Info Serialization Error. Serialized length less than expected."))) 1108 if (_13_valueOrError4).IsFailure() { 1109 res = (_13_valueOrError4).PropagateFailure() 1110 return res 1111 } 1112 var _14_providerInfoRecipientPublicKey _dafny.Sequence 1113 _ = _14_providerInfoRecipientPublicKey 1114 _14_providerInfoRecipientPublicKey = (_3_providerInfo).Subsequence(uint32(m_Constants.Companion_Default___.ECDH__PROVIDER__INFO__RPK__INDEX()), (_11_recipientPublicKeyLengthIndex).Uint32()) 1115 var _15_providerInfoSenderPublicKey _dafny.Sequence 1116 _ = _15_providerInfoSenderPublicKey 1117 _15_providerInfoSenderPublicKey = (_3_providerInfo).Drop((_12_senderPublicKeyIndex).Uint32()) 1118 var _16_valueOrError5 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 1119 _ = _16_valueOrError5 1120 var _out0 m_Wrappers.Result 1121 _ = _out0 1122 _out0 = Companion_Default___.DecompressPublicKey(_15_providerInfoSenderPublicKey, (_this).CurveSpec(), (_this).CryptoPrimitives()) 1123 _16_valueOrError5 = _out0 1124 if (_16_valueOrError5).IsFailure() { 1125 res = (_16_valueOrError5).PropagateFailure() 1126 return res 1127 } 1128 var _17_senderPublicKey _dafny.Sequence 1129 _ = _17_senderPublicKey 1130 _17_senderPublicKey = (_16_valueOrError5).Extract().(_dafny.Sequence) 1131 var _18_valueOrError6 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 1132 _ = _18_valueOrError6 1133 var _out1 m_Wrappers.Result 1134 _ = _out1 1135 _out1 = Companion_Default___.DecompressPublicKey(_14_providerInfoRecipientPublicKey, (_this).CurveSpec(), (_this).CryptoPrimitives()) 1136 _18_valueOrError6 = _out1 1137 if (_18_valueOrError6).IsFailure() { 1138 res = (_18_valueOrError6).PropagateFailure() 1139 return res 1140 } 1141 var _19_recipientPublicKey _dafny.Sequence 1142 _ = _19_recipientPublicKey 1143 _19_recipientPublicKey = (_18_valueOrError6).Extract().(_dafny.Sequence) 1144 var _20_valueOrError7 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(false) 1145 _ = _20_valueOrError7 1146 var _out2 m_Wrappers.Result 1147 _ = _out2 1148 _out2 = Companion_Default___.ValidatePublicKey((_this).CryptoPrimitives(), (_this).CurveSpec(), _17_senderPublicKey) 1149 _20_valueOrError7 = _out2 1150 if (_20_valueOrError7).IsFailure() { 1151 res = (_20_valueOrError7).PropagateFailure() 1152 return res 1153 } 1154 var _21___v0 bool 1155 _ = _21___v0 1156 _21___v0 = (_20_valueOrError7).Extract().(bool) 1157 var _22_valueOrError8 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(false) 1158 _ = _22_valueOrError8 1159 var _out3 m_Wrappers.Result 1160 _ = _out3 1161 _out3 = Companion_Default___.ValidatePublicKey((_this).CryptoPrimitives(), (_this).CurveSpec(), _19_recipientPublicKey) 1162 _22_valueOrError8 = _out3 1163 if (_22_valueOrError8).IsFailure() { 1164 res = (_22_valueOrError8).PropagateFailure() 1165 return res 1166 } 1167 var _23___v1 bool 1168 _ = _23___v1 1169 _23___v1 = (_22_valueOrError8).Extract().(bool) 1170 var _24_sharedSecretPublicKey _dafny.Sequence = _dafny.EmptySeq 1171 _ = _24_sharedSecretPublicKey 1172 var _25_sharedSecretPrivateKey _dafny.Sequence = _dafny.EmptySeq 1173 _ = _25_sharedSecretPrivateKey 1174 var _source0 m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations = (_this).KeyAgreementScheme() 1175 _ = _source0 1176 { 1177 { 1178 if _source0.Is_PublicKeyDiscovery() { 1179 var _26_publicKeyDiscovery m_AwsCryptographyMaterialProvidersTypes.PublicKeyDiscoveryInput = _source0.Get_().(m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations_PublicKeyDiscovery).PublicKeyDiscovery 1180 _ = _26_publicKeyDiscovery 1181 { 1182 _24_sharedSecretPublicKey = _17_senderPublicKey 1183 _25_sharedSecretPrivateKey = (_26_publicKeyDiscovery).Dtor_recipientStaticPrivateKey() 1184 } 1185 goto Lmatch0 1186 } 1187 } 1188 { 1189 if _source0.Is_RawPrivateKeyToStaticPublicKey() { 1190 var _27_rawPrivateKeyToStaticPublicKey m_AwsCryptographyMaterialProvidersTypes.RawPrivateKeyToStaticPublicKeyInput = _source0.Get_().(m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations_RawPrivateKeyToStaticPublicKey).RawPrivateKeyToStaticPublicKey 1191 _ = _27_rawPrivateKeyToStaticPublicKey 1192 { 1193 _25_sharedSecretPrivateKey = (_27_rawPrivateKeyToStaticPublicKey).Dtor_senderStaticPrivateKey() 1194 if _dafny.Companion_Sequence_.Equal((_27_rawPrivateKeyToStaticPublicKey).Dtor_recipientPublicKey(), _19_recipientPublicKey) { 1195 _24_sharedSecretPublicKey = _19_recipientPublicKey 1196 } else { 1197 _24_sharedSecretPublicKey = _17_senderPublicKey 1198 } 1199 } 1200 goto Lmatch0 1201 } 1202 } 1203 { 1204 { 1205 res = m_Wrappers.Companion_Result_.Create_Failure_(Companion_Default___.E(_dafny.SeqOfString("EphemeralPrivateKeyToStaticPublicKey Not allowed on decrypt"))) 1206 return res 1207 } 1208 } 1209 goto Lmatch0 1210 } 1211 Lmatch0: 1212 var _28_valueOrError9 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(false) 1213 _ = _28_valueOrError9 1214 var _out4 m_Wrappers.Result 1215 _ = _out4 1216 _out4 = Companion_Default___.ValidatePublicKey((_this).CryptoPrimitives(), (_this).CurveSpec(), _24_sharedSecretPublicKey) 1217 _28_valueOrError9 = _out4 1218 if (_28_valueOrError9).IsFailure() { 1219 res = (_28_valueOrError9).PropagateFailure() 1220 return res 1221 } 1222 var _29___v3 bool 1223 _ = _29___v3 1224 _29___v3 = (_28_valueOrError9).Extract().(bool) 1225 var _30_valueOrError10 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 1226 _ = _30_valueOrError10 1227 var _out5 m_Wrappers.Result 1228 _ = _out5 1229 _out5 = Companion_Default___.LocalDeriveSharedSecret(m_AwsCryptographyPrimitivesTypes.Companion_ECCPrivateKey_.Create_ECCPrivateKey_(_25_sharedSecretPrivateKey), m_AwsCryptographyPrimitivesTypes.Companion_ECCPublicKey_.Create_ECCPublicKey_(_24_sharedSecretPublicKey), (_this).CurveSpec(), (_this).CryptoPrimitives()) 1230 _30_valueOrError10 = _out5 1231 if (_30_valueOrError10).IsFailure() { 1232 res = (_30_valueOrError10).PropagateFailure() 1233 return res 1234 } 1235 var _31_sharedSecret _dafny.Sequence 1236 _ = _31_sharedSecret 1237 _31_sharedSecret = (_30_valueOrError10).Extract().(_dafny.Sequence) 1238 var _32_ecdhUnwrap *m_EcdhEdkWrapping.EcdhUnwrap 1239 _ = _32_ecdhUnwrap 1240 var _nw0 *m_EcdhEdkWrapping.EcdhUnwrap = m_EcdhEdkWrapping.New_EcdhUnwrap_() 1241 _ = _nw0 1242 _nw0.Ctor__(_15_providerInfoSenderPublicKey, _14_providerInfoRecipientPublicKey, _31_sharedSecret, Companion_Default___.RAW__ECDH__KEYRING__VERSION(), (_this).CurveSpec(), (_this).CryptoPrimitives()) 1243 _32_ecdhUnwrap = _nw0 1244 var _33_unwrapOutputRes m_Wrappers.Result 1245 _ = _33_unwrapOutputRes 1246 var _out6 m_Wrappers.Result 1247 _ = _out6 1248 _out6 = m_EdkWrapping.Companion_Default___.UnwrapEdkMaterial((edk).Dtor_ciphertext(), (_this).Materials(), _32_ecdhUnwrap) 1249 _33_unwrapOutputRes = _out6 1250 var _34_valueOrError11 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_EdkWrapping.Companion_UnwrapEdkMaterialOutput_.Default(m_EcdhEdkWrapping.Companion_EcdhUnwrapInfo_.Default())) 1251 _ = _34_valueOrError11 1252 _34_valueOrError11 = _33_unwrapOutputRes 1253 if (_34_valueOrError11).IsFailure() { 1254 res = (_34_valueOrError11).PropagateFailure() 1255 return res 1256 } 1257 var _35_unwrapOutput m_EdkWrapping.UnwrapEdkMaterialOutput 1258 _ = _35_unwrapOutput 1259 _35_unwrapOutput = (_34_valueOrError11).Extract().(m_EdkWrapping.UnwrapEdkMaterialOutput) 1260 var _36_valueOrError12 m_Wrappers.Result = m_Wrappers.Result{} 1261 _ = _36_valueOrError12 1262 _36_valueOrError12 = m_Materials.Companion_Default___.DecryptionMaterialsAddDataKey((_this).Materials(), (_35_unwrapOutput).Dtor_plaintextDataKey(), (_35_unwrapOutput).Dtor_symmetricSigningKey()) 1263 if (_36_valueOrError12).IsFailure() { 1264 res = (_36_valueOrError12).PropagateFailure() 1265 return res 1266 } 1267 var _37_result m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials 1268 _ = _37_result 1269 _37_result = (_36_valueOrError12).Extract().(m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials) 1270 res = m_Wrappers.Companion_Result_.Create_Success_(_37_result) 1271 return res 1272 return res 1273 } 1274 } 1275 func (_this *DecryptSingleEncryptedDataKey) Materials() m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials { 1276 { 1277 return _this._materials 1278 } 1279 } 1280 func (_this *DecryptSingleEncryptedDataKey) CryptoPrimitives() *m_AtomicPrimitives.AtomicPrimitivesClient { 1281 { 1282 return _this._cryptoPrimitives 1283 } 1284 } 1285 func (_this *DecryptSingleEncryptedDataKey) RecipientPublicKey() _dafny.Sequence { 1286 { 1287 return _this._recipientPublicKey 1288 } 1289 } 1290 func (_this *DecryptSingleEncryptedDataKey) SenderPublicKey() _dafny.Sequence { 1291 { 1292 return _this._senderPublicKey 1293 } 1294 } 1295 func (_this *DecryptSingleEncryptedDataKey) KeyAgreementScheme() m_AwsCryptographyMaterialProvidersTypes.RawEcdhStaticConfigurations { 1296 { 1297 return _this._keyAgreementScheme 1298 } 1299 } 1300 func (_this *DecryptSingleEncryptedDataKey) CurveSpec() m_AwsCryptographyPrimitivesTypes.ECDHCurveSpec { 1301 { 1302 return _this._curveSpec 1303 } 1304 } 1305 1306 // End of class DecryptSingleEncryptedDataKey