@@ -54,6 +54,7 @@ fn (nid Nid) str() string {
54
54
}
55
55
}
56
56
57
+ // CurveOptions represents configuration options to drive keypair generation.
57
58
@[params]
58
59
pub struct CurveOptions {
59
60
pub mut :
@@ -94,7 +95,7 @@ enum KeyFlag {
94
95
}
95
96
96
97
// generate_key generates a new key pair. If opt was not provided, its default to prime256v1 curve.
97
- // If you want another curve, use in the following manner: `pubkey, pivkey := ecdsa.generate_key(nid: .secp384r1)!`
98
+ // If you want another curve, use `pubkey, pivkey := ecdsa.generate_key(nid: .secp384r1)!` instead.
98
99
pub fn generate_key (opt CurveOptions) ! (PublicKey, PrivateKey) {
99
100
// This can be simplified to just more simpler one
100
101
pv := PrivateKey.new (opt)!
@@ -111,7 +112,7 @@ pub fn generate_key(opt CurveOptions) !(PublicKey, PrivateKey) {
111
112
// You should make sure, the seed bytes come from a cryptographically secure random generator,
112
113
// likes the `crypto.rand` or other trusted sources.
113
114
// Internally, the seed size's would be checked to not exceed the key size of underlying curve,
114
- // ie, 32 bytes length for p-256 and secp256k1, 48 bytes length for p-384 and 64 bytes length for p-521.
115
+ // ie, 32 bytes length for p-256 and secp256k1, 48 bytes length for p-384 and 66 bytes length for p-521.
115
116
// Its recommended to use seed with bytes length matching with underlying curve key size.
116
117
pub fn new_key_from_seed (seed []u8 , opt CurveOptions) ! PrivateKey {
117
118
// Early exit check
@@ -276,9 +277,6 @@ pub fn (pv PrivateKey) seed() ![]u8 {
276
277
277
278
// public_key gets the PublicKey from private key.
278
279
pub fn (pv PrivateKey) public_key () ! PublicKey {
279
- // Check if EVP_PKEY opaque was availables or not.
280
- // TODO: removes this check when its ready
281
-
282
280
bo := C.BIO_new (C.BIO_s_mem ())
283
281
n := C.i2d_PUBKEY_bio (bo, pv.evpkey)
284
282
assert n != 0
@@ -292,17 +290,13 @@ pub fn (pv PrivateKey) public_key() !PublicKey {
292
290
}
293
291
}
294
292
295
- // equal compares two private keys was equal. Its checks for two things, ie:
296
- //
297
- // - whether both of private keys lives under the same group (curve),
298
- // - compares if two private key bytes was equal.
293
+ // equal compares two private keys was equal.
299
294
pub fn (priv_key PrivateKey) equal (other PrivateKey) bool {
300
295
eq := C.EVP_PKEY_eq (voidptr (priv_key.evpkey), voidptr (other.evpkey))
301
296
return eq == 1
302
297
}
303
298
304
- // free clears out allocated memory for PrivateKey
305
- // Dont use PrivateKey after calling `.free()`
299
+ // free clears out allocated memory for PrivateKey. Dont use PrivateKey after calling `.free()`
306
300
pub fn (pv &PrivateKey) free () {
307
301
C.EVP_PKEY_free (pv.evpkey)
308
302
}
@@ -321,14 +315,13 @@ pub fn (pb PublicKey) verify(message []u8, sig []u8, opt SignerOpts) !bool {
321
315
return verify_signature (pb.evpkey, sig, digest)
322
316
}
323
317
324
- // Compare two public keys
318
+ // equal compares two public keys was equal.
325
319
pub fn (pub_key PublicKey) equal (other PublicKey) bool {
326
320
eq := C.EVP_PKEY_eq (voidptr (pub_key.evpkey), voidptr (other.evpkey))
327
321
return eq == 1
328
322
}
329
323
330
- // free clears out allocated memory for PublicKey.
331
- // Dont use PublicKey after calling `.free()`
324
+ // free clears out allocated memory for PublicKey. Dont use PublicKey after calling `.free()`
332
325
pub fn (pb &PublicKey) free () {
333
326
C.EVP_PKEY_free (pb.evpkey)
334
327
}
0 commit comments