Struct ed448_rust::PrivateKey[]

pub struct PrivateKey(_);

This represent a private key. Must be kept secret.

Could be used to generate a new one or restore an older already saved.

Implementations

impl PrivateKey

pub fn new<T>(rnd: &mut T) -> Self where
    T: CryptoRng + RngCore

Generate a random key.

Example

use rand_core::OsRng;
use ed448_rust::PrivateKey;
let private_key = PrivateKey::new(&mut OsRng);

#[must_use]pub const fn as_bytes(&self) -> &[u8; 57]

Convert the private key to a format exportable.

Example

let exportable_pkey = private_key.as_bytes();

pub fn sign(&self, msg: &[u8], ctx: Option<&[u8]>) -> Result<[u8; 114]>

Sign with key pair.

It’s possible to indicate a context. More information in RFC8032 8.3 Use of contexts.

Examples

Without any context.

use ed448_rust::PrivateKey;
let pkey = PrivateKey::from([0xcd, 0x23, 0xd2, 0x4f, 0x71, 0x42, 0x74, 0xe7, 0x44, 0x34, 0x32, 0x37, 0xb9,
            0x32, 0x90, 0xf5, 0x11, 0xf6, 0x42, 0x5f, 0x98, 0xe6, 0x44, 0x59, 0xff, 0x20, 0x3e, 0x89, 0x85,
            0x08, 0x3f, 0xfd, 0xf6, 0x05, 0x00, 0x55, 0x3a, 0xbc, 0x0e, 0x05, 0xcd, 0x02, 0x18, 0x4b, 0xdb,
            0x89, 0xc4, 0xcc, 0xd6, 0x7e, 0x18, 0x79, 0x51, 0x26, 0x7e, 0xb3, 0x28]);
let msg = &[0x0c, 0x3e, 0x54, 0x40, 0x74, 0xec, 0x63, 0xb0, 0x26, 0x5e, 0x0c];
let sig = pkey.sign(msg, None).unwrap();

assert_eq!(
    sig.iter().map(|b| format!("{:02x}", b)).collect::<Vec<String>>().concat(),
    "1f0a8888ce25e8d458a21130879b840a9089d999aaba039eaf3e3afa090a09d389dba82c4ff2ae8a\
        c5cdfb7c55e94d5d961a29fe0109941e00b8dbdeea6d3b051068df7254c0cdc129cbe62db2dc9\
        57dbb47b51fd3f213fb8698f064774250a5028961c9bf8ffd973fe5d5c206492b140e00"
);

With a context.

use ed448_rust::PrivateKey;
let pkey = PrivateKey::from([0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6, 0x32, 0xf3, 0xdb, 0xb4, 0x84,
            0x89, 0x92, 0x4d, 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d, 0x4a, 0x1f, 0x00, 0xac, 0xda,
            0x2c, 0x46, 0x3a, 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c, 0x5e, 0x3b, 0xc3, 0x97, 0xa6,
            0x59, 0x94, 0x9e, 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27, 0x4e]);
let msg = &[03];
let sig = pkey.sign(msg, Some(&[0x66, 0x6f, 0x6f])).unwrap();

assert_eq!(
    sig.iter().map(|b| format!("{:02x}", b)).collect::<Vec<String>>().concat(),
    "d4f8f6131770dd46f40867d6fd5d5055de43541f8c5e35abbcd001b32a89f7d2151f7647f11d8ca2\
        ae279fb842d607217fce6e042f6815ea000c85741de5c8da1144a6a1aba7f96de42505d7a7298\
        524fda538fccbbb754f578c1cad10d54d0d5428407e85dcbc98a49155c13764e66c3c00"
);

Errors

pub fn sign_ph(&self, msg: &[u8], ctx: Option<&[u8]>) -> Result<[u8; 114]>

Sign with key pair. Message is pre-hashed before signed.

The message is hashed before being signed. The size of the signed message in this case is always 64 bytes length.

See PrivateKey::sign.

Errors

Trait Implementations

impl Clone for PrivateKey

impl Copy for PrivateKey

impl Debug for PrivateKey

impl From<&'_ [u8; 57]> for PrivateKey

impl From<&'_ PrivateKey> for PublicKey

Instantiate a PublicKey from the PrivateKey.

impl From<[u8; 57]> for PrivateKey

Restore the private key from the slice.

impl TryFrom<&'_ [u8]> for PrivateKey

Restore the private key from an array.

Error

Could return Ed448Error::WrongKeyLength if the array’s length is not KEY_LENGTH.

type Error = Ed448Error

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.