@@ -107,37 +107,54 @@ module {:extern "ECDH"} ECDH {
107
107
));
108
108
}
109
109
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
110
113
method {:extern "ECDH. KeyGeneration", "GenerateKeyPair"} ExternEccKeyGen (
111
114
s: Types .ECDHCurveSpec
112
115
) returns (res: Result< EccKeyPair, Types. Error> )
113
116
ensures res. Success? ==> 1 < |res. value. publicKey| <= 8192
114
117
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
115
121
method {:extern "ECDH. ECCUtils", "GetPublicKey"} ExternGetPublicKeyFromPrivate (
116
122
curveAlgorithm: Types .ECDHCurveSpec,
117
123
privateKey: Types .ECCPrivateKey
118
124
) returns (res: Result< seq < uint8> , Types. Error> )
119
125
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()
120
130
method {:extern "ECDH. ECCUtils", "ValidatePublicKey"} ExternValidatePublicKey (
121
131
curveAlgorithm: Types .ECDHCurveSpec,
122
132
publicKey: seq <uint8 >
123
133
) returns (res: Result< bool , Types. Error> )
124
134
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
125
138
method {:extern "ECDH. DeriveSharedSecret", "CalculateSharedSecret"} ExternDeriveSharedSecret (
126
139
curveAlgorithm: Types .ECDHCurveSpec,
127
140
privateKey: Types .ECCPrivateKey,
128
141
publicKey: Types .ECCPublicKey
129
142
) returns (res: Result< seq < uint8> , Types. Error> )
130
143
144
+ // Convert DER-encoded X.509 SubjectPublicKeyInfo public key bytes to compressed X9.62 format
131
145
method {:extern "ECDH. ECCUtils", "CompressPublicKey"} ExternCompressPublicKey (
132
146
publicKey: seq <uint8 >,
133
147
curveAlgorithm: Types .ECDHCurveSpec
134
148
) returns (res: Result< seq < uint8> , Types. Error> )
135
149
150
+ // Convert X9.62 encoded public key bytes to DER-encoded X.509 SubjectPublicKeyInfo format
151
+ // input is not PEM-encoded
136
152
method {:extern "ECDH. ECCUtils", "DecompressPublicKey"} ExternDecompressPublicKey (
137
153
publicKey: seq <uint8 >,
138
154
curveAlgorithm: Types .ECDHCurveSpec
139
155
) returns (res: Result< seq < uint8> , Types. Error> )
140
156
157
+ // Ensure that this public key is DER-encoded X.509 SubjectPublicKeyInfo format
141
158
method {:extern "ECDH. ECCUtils", "ParsePublicKey"} ExternParsePublicKey (
142
159
publicKey: seq <uint8 >
143
160
) returns (res: Result< seq < uint8> , Types. Error> )
0 commit comments