Skip to Content
oxcrypto

Schnorr

Sign and verify BIP 340 Schnorr signatures over secp256k1.

from oxcrypto.signature.schnorr import SCHNORR

key = SCHNORR.BIP340.generate()
signature = key.sign(b"message")
assert key.public_key().verify(signature, b"message")

sign(data, *, aux_rand=None) returns a 64-byte signature. BIP 340 signs the message itself, of any length, without hashing it first. aux_rand is the 32 bytes of auxiliary randomness from BIP 340; when it is omitted, oxcrypto draws fresh bytes from the operating system CSPRNG. Pass it only to reproduce test vectors.

Private keys are 32-byte scalars (to_bytes(), SCHNORR.BIP340.private_key_from_bytes). Public keys are 32-byte x-only points (to_bytes(), SCHNORR.BIP340.public_key_from_bytes). BIP 340 defines no DER or PEM encoding.

Upstream

  • Standard: BIP 340 (final).
  • Crate: k256 0.14.0 (schnorr feature), stable. The NCC Group review of an earlier release covered the Schnorr implementation; the issue it found has been fixed upstream.
  • Builds with Rust 1.88.
  • Tests use the BIP 340 reference test-vectors.csv.

See Signatures for zeroization notes.

On this page