Skip to content

Commit

Permalink
Add Schnorr signatures module
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibo-lg committed Sep 25, 2020
1 parent cf2e54e commit 7923629
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/constants.rs
Expand Up @@ -34,6 +34,15 @@ pub const MAX_SIGNATURE_SIZE: usize = 72;
/// The maximum size of a compact signature
pub const COMPACT_SIGNATURE_SIZE: usize = 64;

/// Size of a schnorr signature
pub const SCHNORR_SIGNATURE_SIZE: usize = 64;

/// Size of a x-only public key
pub const SCHNORR_PUBLIC_KEY_SIZE: usize = 32;

/// Size of a key pair
pub const KEY_PAIR_SIZE: usize = 96;

/// The Prime for the secp256k1 field element.
pub const FIELD_SIZE: [u8; 32] = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Expand Up @@ -169,6 +169,7 @@ mod context;
pub mod constants;
pub mod ecdh;
pub mod key;
pub mod schnorrsig;
#[cfg(feature = "recovery")]
pub mod recovery;

Expand Down Expand Up @@ -550,6 +551,12 @@ pub enum Error {
InvalidTweak,
/// Didn't pass enough memory to context creation with preallocated memory
NotEnoughMemory,
/// Bad Schnorr signature
InvalidSchnorrSignature,
/// Bad Schnorr public key
InvalidSchnorrPublicKey,
/// Bad key pair
InvalidKeyPair,
}

impl Error {
Expand All @@ -563,6 +570,9 @@ impl Error {
Error::InvalidRecoveryId => "secp: bad recovery id",
Error::InvalidTweak => "secp: bad tweak",
Error::NotEnoughMemory => "secp: not enough memory allocated",
Error::InvalidSchnorrSignature => "secp: malformed Schnorr signature",
Error::InvalidSchnorrPublicKey => "secp: malformed x-only public key",
Error::InvalidKeyPair => "secp: malformed key pair",
}
}
}
Expand Down

0 comments on commit 7923629

Please sign in to comment.