v/vlib/crypto/ecdsa
2025-03-09 09:59:10 +02:00
..
example crypto.ecdsa: migrate core routines for signing (and verifying), it now requires using OpenSSL 3 (#23705) 2025-02-17 18:49:32 +02:00
ecdsa.c.v crypto.ecdsa: clean out old deprecated keypair opaque from the module, make -cstrict pass for all the tests, and with both gcc and clang (#23887) 2025-03-09 09:59:10 +02:00
ecdsa.v crypto.ecdsa: clean out old deprecated keypair opaque from the module, make -cstrict pass for all the tests, and with both gcc and clang (#23887) 2025-03-09 09:59:10 +02:00
ecdsa_test.v crypto.ecdsa: clean out old deprecated keypair opaque from the module, make -cstrict pass for all the tests, and with both gcc and clang (#23887) 2025-03-09 09:59:10 +02:00
README.md crypto.ecdsa: improve safety checking, unify signing (and verifying) api to accept options (#23463) 2025-01-18 20:07:19 +02:00
util.v crypto.ecdsa: clean out old deprecated keypair opaque from the module, make -cstrict pass for all the tests, and with both gcc and clang (#23887) 2025-03-09 09:59:10 +02:00
util_test.v crypto.ecdsa: migrate core routines for signing (and verifying), it now requires using OpenSSL 3 (#23705) 2025-02-17 18:49:32 +02:00

ecdsa

ecdsa module for V language. Its a wrapper on top of openssl ecdsa functionality. Its currently (expanded) to support the following curves:

  • NIST P-256 curve, commonly referred as prime256v1 or secp256r1
  • NIST P-384 curve, commonly referred as secp384r1
  • NIST P-521 curve, commonly referred as secp521r1
  • A famous Bitcoin curve, commonly referred as secp256k1

Caution

This module using low level OpenSSL opaque methods that mostly has been deprecated in OpenSSL 3.0. Please be aware, likely it would not compile with -cstrict options until its migrated into supported higher level API.

Example

import crypto.ecdsa

fn main() {
	// create default NIST P-256 secp256r1 curve key pair. If you wish to generate another curve,
	// use: `pbkey, pvkey := ecdsa.generate_key(nid: .secp521r1)!` instead.
	pbkey, pvkey := ecdsa.generate_key()!

	message_tobe_signed := 'Hello ecdsa'.bytes()
	// create a signature with the recommended hash
	signature := pvkey.sign(message_tobe_signed)!

	// verify the message with the signature
	verified := pbkey.verify(message_tobe_signed, signature)!
	dump(verified) // should be true

	// free allocated keys when you have done with your work.
	pbkey.free()
	pvkey.free()
}