Skip to content

Commit 1baeefb

Browse files
Merge branch 'main' into primitives-name
2 parents 83711fd + d51d648 commit 1baeefb

File tree

7 files changed

+51
-19981
lines changed

7 files changed

+51
-19981
lines changed

AwsCryptographyPrimitives/src/Digest.dfy

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ module Digest {
1313
function method Length(digestAlgorithm: Types.DigestAlgorithm): nat
1414
{
1515
match digestAlgorithm
16-
case SHA_512 => 64
17-
case SHA_384 => 48
18-
case SHA_256 => 32
19-
case SHA_1 => 20
16+
case SHA_512() => 64
17+
case SHA_384() => 48
18+
case SHA_256() => 32
2019
}
2120

2221
method Digest(input: Types.DigestInput)

AwsCryptographyPrimitives/src/ECDH.dfy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,37 +107,54 @@ module {:extern "ECDH"} ECDH {
107107
));
108108
}
109109

110+
// Generate an ECDH key pair
111+
// Return the private key as UTF8 PEM-encoded Rfc5915 format,
112+
// Return the public key as DER-encoded X.509 SubjectPublicKeyInfo bytes
110113
method {:extern "ECDH.KeyGeneration", "GenerateKeyPair"} ExternEccKeyGen(
111114
s: Types.ECDHCurveSpec
112115
) returns (res: Result<EccKeyPair, Types.Error>)
113116
ensures res.Success? ==> 1 < |res.value.publicKey| <= 8192
114117

118+
// Given a private key, return the associated public key
119+
// Input private key is in PEM format
120+
// Output public key is DER-encoded X.509 SubjectPublicKeyInfo
115121
method {:extern "ECDH.ECCUtils", "GetPublicKey"} ExternGetPublicKeyFromPrivate(
116122
curveAlgorithm: Types.ECDHCurveSpec,
117123
privateKey: Types.ECCPrivateKey
118124
) returns (res: Result<seq<uint8>, Types.Error>)
119125

126+
// Ensure that this public key follows 5.6.2.3.3 ECC Full Public-Key Validation Routine from
127+
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Ar3.pdf#page=55
128+
// Input public key is DER-encoded X.509 SubjectPublicKeyInfo bytes
129+
// Result is never Success(false), it's either Success(true) or Failure()
120130
method {:extern "ECDH.ECCUtils", "ValidatePublicKey"} ExternValidatePublicKey(
121131
curveAlgorithm: Types.ECDHCurveSpec,
122132
publicKey: seq<uint8>
123133
) returns (res: Result<bool, Types.Error>)
124134

135+
// Calculate a shared secret from the keys
136+
// Private key is PEM formatted UTF8
137+
// Input public key is DER-encoded X.509 SubjectPublicKeyInfo bytes
125138
method {:extern "ECDH.DeriveSharedSecret", "CalculateSharedSecret"} ExternDeriveSharedSecret(
126139
curveAlgorithm: Types.ECDHCurveSpec,
127140
privateKey: Types.ECCPrivateKey,
128141
publicKey: Types.ECCPublicKey
129142
) returns (res: Result<seq<uint8>, Types.Error>)
130143

144+
// Convert DER-encoded X.509 SubjectPublicKeyInfo public key bytes to compressed X9.62 format
131145
method {:extern "ECDH.ECCUtils", "CompressPublicKey"} ExternCompressPublicKey(
132146
publicKey: seq<uint8>,
133147
curveAlgorithm: Types.ECDHCurveSpec
134148
) returns (res: Result<seq<uint8>, Types.Error>)
135149

150+
// Convert X9.62 encoded public key bytes to DER-encoded X.509 SubjectPublicKeyInfo format
151+
// input is not PEM-encoded
136152
method {:extern "ECDH.ECCUtils", "DecompressPublicKey"} ExternDecompressPublicKey(
137153
publicKey: seq<uint8>,
138154
curveAlgorithm: Types.ECDHCurveSpec
139155
) returns (res: Result<seq<uint8>, Types.Error>)
140156

157+
// Ensure that this public key is DER-encoded X.509 SubjectPublicKeyInfo format
141158
method {:extern "ECDH.ECCUtils", "ParsePublicKey"} ExternParsePublicKey(
142159
publicKey: seq<uint8>
143160
) returns (res: Result<seq<uint8>, Types.Error>)

AwsCryptographyPrimitives/src/Signature.dfy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,26 @@ module {:extern "Signature"} Signature {
5555
));
5656
}
5757

58+
// Generate an ECDSA key pair
59+
// Verification key, a.k.a public key, is in X9.62 compressed format
60+
// Signing Key, a.k.a private key, is in DER-encoded
5861
method {:extern "Signature.ECDSA", "ExternKeyGen"} ExternKeyGen(
5962
s: Types.ECDSASignatureAlgorithm
6063
) returns (res: Result<SignatureKeyPair, Types.Error>)
6164
ensures res.Success? ==> IsValidSignatureKeyPair(res.value)
6265

66+
// sign the message with the private key
67+
// private signing key is DER-encoded
6368
method {:extern "Signature.ECDSA", "Sign"} Sign(
6469
s: Types.ECDSASignatureAlgorithm,
6570
key: seq<uint8>,
6671
msg: seq<uint8>
6772
) returns (sig: Result<seq<uint8>, Types.Error>)
6873
ensures sig.Success? ==> IsSigned(key, msg, sig.value)
6974

75+
// Verify that these bytes created this signature
76+
// Public verification key is DER-encoded X9.62 format
77+
// If signature does not match Success(false) is returned
7078
// This is a valid function
7179
// because the same inputs will result in the same outputs.
7280
function method {:extern "Signature.ECDSA", "Verify"} Verify(

0 commit comments

Comments
 (0)