ring::signature

Struct Ed25519KeyPair

Source
pub struct Ed25519KeyPair { /* private fields */ }
Expand description

An Ed25519 key pair, for signing.

Implementations§

Source§

impl Ed25519KeyPair

Source

pub fn generate_pkcs8(rng: &dyn SecureRandom) -> Result<Document, Unspecified>

Generates a new key pair and returns the key pair serialized as a PKCS#8 document.

The PKCS#8 document will be a v2 OneAsymmetricKey with the public key, as described in RFC 5958 Section 2; see RFC 8410 Section 10.3 for an example.

Source

pub fn from_pkcs8(pkcs8: &[u8]) -> Result<Self, KeyRejected>

Constructs an Ed25519 key pair by parsing an unencrypted PKCS#8 v2 Ed25519 private key.

openssl genpkey -algorithm ED25519 generates PKCS# v1 keys, which require the use of Ed25519KeyPair::from_pkcs8_maybe_unchecked() instead of Ed25519KeyPair::from_pkcs8().

The input must be in PKCS#8 v2 format, and in particular it must contain the public key in addition to the private key. from_pkcs8() will verify that the public key and the private key are consistent with each other.

Some early implementations of PKCS#8 v2, including earlier versions of ring and other implementations, wrapped the public key in the wrong ASN.1 tags. Both that incorrect form and the standardized form are accepted.

If you need to parse PKCS#8 v1 files (without the public key) then use Ed25519KeyPair::from_pkcs8_maybe_unchecked() instead.

Source

pub fn from_pkcs8_maybe_unchecked(pkcs8: &[u8]) -> Result<Self, KeyRejected>

Constructs an Ed25519 key pair by parsing an unencrypted PKCS#8 v1 or v2 Ed25519 private key.

openssl genpkey -algorithm ED25519 generates PKCS# v1 keys.

It is recommended to use Ed25519KeyPair::from_pkcs8(), which accepts only PKCS#8 v2 files that contain the public key. from_pkcs8_maybe_unchecked() parses PKCS#2 files exactly like from_pkcs8(). It also accepts v1 files. PKCS#8 v1 files do not contain the public key, so when a v1 file is parsed the public key will be computed from the private key, and there will be no consistency check between the public key and the private key.

Some early implementations of PKCS#8 v2, including earlier versions of ring and other implementations, wrapped the public key in the wrong ASN.1 tags. Both that incorrect form and the standardized form are accepted.

PKCS#8 v2 files are parsed exactly like Ed25519KeyPair::from_pkcs8().

Source

pub fn from_seed_and_public_key( seed: &[u8], public_key: &[u8], ) -> Result<Self, KeyRejected>

Constructs an Ed25519 key pair from the private key seed seed and its public key public_key.

It is recommended to use Ed25519KeyPair::from_pkcs8() instead.

The private and public keys will be verified to be consistent with each other. This helps avoid misuse of the key (e.g. accidentally swapping the private key and public key, or using the wrong private key for the public key). This also detects any corruption of the public or private key.

Source

pub fn from_seed_unchecked(seed: &[u8]) -> Result<Self, KeyRejected>

Constructs a Ed25519 key pair from the private key seed seed.

It is recommended to use Ed25519KeyPair::from_pkcs8() instead. When that is not practical, it is recommended to use Ed25519KeyPair::from_seed_and_public_key() instead.

Since the public key is not given, the public key will be computed from the private key. It is not possible to detect misuse or corruption of the private key since the public key isn’t given as input.

Source

pub fn sign(&self, msg: &[u8]) -> Signature

Returns the signature of the message msg.

Trait Implementations§

Source§

impl Debug for Ed25519KeyPair

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl KeyPair for Ed25519KeyPair

Source§

type PublicKey = PublicKey

The type of the public key.
Source§

fn public_key(&self) -> &Self::PublicKey

The public key for the key pair.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 96 bytes