Crate ed448_rust[]

EdDSA implementation for ed448

This is a Edwards-Curve Digital Signature Algorithm (EdDSA) for ed448 only in pure rust.

Usage

There is two variants that can be combined to sign/verify:

  1. PrivateKey::sign to sign all the content as-it and PrivateKey::sign_ph to pre-hash the message internaly before signing it. It will be hashed using Shake256 and the result of 64 byte will be signed/verified.

    Note: use the same variant for verifying the signature.

  2. The second parameter of sign/ sign_ph and the third of verify/ verify_ph if an optional context of 255 byte length max.

    The context can be used to facilitate different signature over different protocol, but it must be immuable over the protocol. More information about this can be found at RFC 8032 Use of Contexts.

Examples

Generating a new key pair

use rand_core::OsRng;
use ed448_rust::{PrivateKey, PublicKey};
let private_key = PrivateKey::new(&mut OsRng);
let public_key = PublicKey::from(&private_key);

Sign a message

use ed448_rust::{PrivateKey, Ed448Error};
let message = b"Message to sign";
let private_key = retrieve_pkey();
match private_key.sign(message, None) {
    Ok(signature) => {
        // Signature OK, use it
        // This is a slice of 144 byte length
    }
    Err(Ed448Error::ContextTooLong) => {
        // The used context is more than 255 bytes length
    }
    Err(_) => unreachable!()
}

Verify a signature

use ed448_rust::{PublicKey, Ed448Error};
let message = b"Signed message to verify";
let public_key = retrieve_pubkey(); // A slice or array of KEY_LENGTH byte length
let signature = retrieve_signature(); // A slice or array of SIG_LENGTH byte length
match public_key.verify(message, &signature, None) {
    Ok(()) => {
        // Signature OK, use the message
    }
    Err(Ed448Error::InvalidSignature) => {
        // The verification of the signature is invalid
    }
    Err(Ed448Error::ContextTooLong) => {
        // The used context is more than 255 bytes length
    }
    Err(Ed448Error::WrongSignatureLength) => {
        // The signature is not 144 bytes length
    }
    Err(_) => unreachable!()
}

Structs

PrivateKey

This represent a private key. Must be kept secret.

PublicKey

This is a public key. Should be distributed.

Enums

Ed448Error

Errors of this crate

Constants

KEY_LENGTH

Length of either a public or a private key length in byte.

SIG_LENGTH

Length of the signature length in byte.

Type Definitions

Result

Specialized Result for this crate.