Skip to content

Commit

Permalink
chore: remove case-based if statement (#630)
Browse files Browse the repository at this point in the history
Remove a case-based if statement, as it caused errors about non-determinism.

Reduce resource use to fix a verification failure along the way.
  • Loading branch information
atomb authored Aug 23, 2024
1 parent f12fe5b commit 66f30ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,24 @@ module {:options "/functionSyntax:4" } RawECDHKeyring {

var sharedSecretPublicKey: seq<uint8>;
var sharedSecretPrivateKey: seq<uint8>;
if {
case this.keyAgreementScheme.PublicKeyDiscovery? =>
match this.keyAgreementScheme {
case PublicKeyDiscovery(publicKeyDiscovery) => {
sharedSecretPublicKey := senderPublicKey;
sharedSecretPrivateKey := this.keyAgreementScheme.PublicKeyDiscovery.recipientStaticPrivateKey;
case this.keyAgreementScheme.RawPrivateKeyToStaticPublicKey? =>
sharedSecretPrivateKey := this.keyAgreementScheme.RawPrivateKeyToStaticPublicKey.senderStaticPrivateKey;
if this.keyAgreementScheme.RawPrivateKeyToStaticPublicKey.recipientPublicKey == recipientPublicKey {
sharedSecretPrivateKey := publicKeyDiscovery.recipientStaticPrivateKey;
}
case RawPrivateKeyToStaticPublicKey(rawPrivateKeyToStaticPublicKey) => {
sharedSecretPrivateKey := rawPrivateKeyToStaticPublicKey.senderStaticPrivateKey;
if rawPrivateKeyToStaticPublicKey.recipientPublicKey == recipientPublicKey {
sharedSecretPublicKey := recipientPublicKey;
} else {
sharedSecretPublicKey := senderPublicKey;
}
case this.keyAgreementScheme.EphemeralPrivateKeyToStaticPublicKey? =>
}
case EphemeralPrivateKeyToStaticPublicKey(_) => {
//= aws-encryption-sdk-specification/framework/key-agreement-schemas.md#ephemeralprivatekeytostaticpublickey
//# On decrypt, the keyring MUST fail.
return Failure(E("EphemeralPrivateKeyToStaticPublicKey Not allowed on decrypt"));
}
}

var _ :- ValidatePublicKey(
Expand Down
2 changes: 1 addition & 1 deletion AwsCryptographyPrimitives/test/TestECDH.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ module TestECDH {
for i := 0 to |curves|
{
var curve := curves[i];
var originalPublicKey := derX509PublicKeys[i];
var originalPublicKey := expectLooseHexString(derX509PublicKeys[i]);
var publicKeyBytes := HexStrings.FromHexString(originalPublicKey);
var compressedKey := expectLooseHexString(compressedKeys[i]);
var compressedKeyBytes := HexStrings.FromHexString(compressedKey);
Expand Down

0 comments on commit 66f30ed

Please sign in to comment.