Struct ed25519_dalek::Keypair
[−]
[src]
pub struct Keypair { pub secret: SecretKey, pub public: PublicKey, }
An ed25519 keypair.
Fields
secret: SecretKey
The secret half of this keypair.
public: PublicKey
The public half of this keypair.
Methods
impl Keypair
[src]
fn to_bytes(&self) -> [u8; 64]
[src]
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
(the same as other
libraries, such as Adam Langley's ed25519 Golang
implementation).
fn from_bytes<'a>(bytes: &'a [u8]) -> Result<Keypair, &'static str>
[src]
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 EdDSA Keypair
or whose error value
is an &'static str
describing the error that occurred.
fn generate<D>(csprng: &mut Rng) -> Keypair where
D: Digest<OutputSize = U64> + Default,
[src]
D: Digest<OutputSize = U64> + Default,
Generate an ed25519 keypair.
Example
extern crate rand; extern crate sha2; extern crate ed25519_dalek; use rand::Rng; use rand::OsRng; use sha2::Sha512; use ed25519_dalek::Keypair; use ed25519_dalek::Signature; let mut cspring: OsRng = OsRng::new().unwrap(); let keypair: Keypair = Keypair::generate::<Sha512>(&mut cspring);
Input
A CSPRNG with a fill_bytes()
method, e.g. the one returned
from rand::OsRng::new()
(in the rand
crate).
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 for most ed25519 libraries is SHA-512,
which is available with use sha2::Sha512
as in the example above.
Other suitable hash functions include Keccak-512 and Blake2b-512.
fn sign<D>(&self, message: &[u8]) -> Signature where
D: Digest<OutputSize = U64> + Default,
[src]
D: Digest<OutputSize = U64> + Default,
Sign a message with this keypair's secret key.
fn verify<D>(&self, message: &[u8], signature: &Signature) -> bool where
D: FixedOutput<OutputSize = U64> + BlockInput + Default + Input,
[src]
D: FixedOutput<OutputSize = U64> + BlockInput + Default + Input,
Verify a signature on a message with this keypair's public key.