crypto.ecdsa: improve safety checking, unify signing (and verifying) api to accept options (#23463)

This commit is contained in:
blackshirt 2025-01-19 01:07:19 +07:00 committed by GitHub
parent 3c4878063e
commit c2b7dbf9b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 752 additions and 109 deletions

View file

@ -0,0 +1,16 @@
import crypto.ecdsa
fn main() {
// create secp256r1, NIST P-256 curve key pair
pbkey, pvkey := ecdsa.generate_key()!
message_tobe_signed := 'Hello ecdsa'.bytes()
// create signature with recommended hash
signature := pvkey.sign(message_tobe_signed, hash_config: .with_recommended_hash)!
// verified the message with signature
verified := pbkey.verify(message_tobe_signed, signature, hash_config: .with_recommended_hash)!
dump(verified) // should true
pbkey.free()
pvkey.free()
}