Expand description
An Schnorr keypair.
Fields
secret: SecretKey
The secret half of this keypair.
public: PublicKey
The public half of this keypair.
Implementations
sourceimpl Keypair
impl Keypair
sourcepub fn to_bytes(&self) -> [u8; 64]
pub fn to_bytes(&self) -> [u8; 64]
Convert this keypair to bytes.
Returns
An array of bytes, [u8; KEYPAIR_LENGTH]
. The first
SECRET_KEY_LENGTH
of bytes is the SecretKey
, and the next
PUBLIC_KEY_LENGTH
bytes is the PublicKey
sourcepub fn from_bytes<'a>(bytes: &'a [u8]) -> Result<Keypair, SignatureError>
pub fn from_bytes<'a>(bytes: &'a [u8]) -> Result<Keypair, SignatureError>
Construct a Keypair
from the bytes of a PublicKey
and SecretKey
.
Inputs
bytes
: an&[u8]
representing the scalar for the secret key, and a compressed Edwards-Y coordinate of a point on curve25519, both as bytes. (As obtained fromKeypair::to_bytes()
.)
Warning
Absolutely no validation is done on the key. If you give this function
bytes which do not represent a valid point, or which do not represent
corresponding parts of the key, then your Keypair
will be broken and
it will be your fault.
Returns
A Result
whose okay value is an Schnorr Keypair
or whose error value
is an SignatureError
describing the error that occurred.
sourcepub fn generate<R>(csprng: &mut R) -> Keypairwhere
R: CryptoRng + Rng,
pub fn generate<R>(csprng: &mut R) -> Keypairwhere
R: CryptoRng + Rng,
Generate an schnorr keypair.
Example
extern crate rand;
extern crate schnorr;
use rand::Rng;
use rand::OsRng;
use schnorr::Keypair;
use schnorr::Signature;
let mut csprng: OsRng = OsRng::new().unwrap();
let keypair: Keypair = Keypair::generate(&mut csprng);
Input
A CSPRNG with a fill_bytes()
method, e.g. rand::ChaChaRng
.
The caller must also supply a hash function which implements the
Digest
and Default
traits, and which returns 512 bits of output.
The standard hash function used is Blake2b-512,