pub struct Ed25519;Expand description
Ed25519 signature scheme
§Security Considerations
- Always use a cryptographically secure RNG for key generation
- Protect secret keys using platform security features when available
- Verify public key authenticity through secure channels
- Never reuse seeds across different applications or purposes
- Clear sensitive data from memory after use (automatic for secret keys)
Implementations§
Source§impl Ed25519
impl Ed25519
Sourcepub fn derive_public_from_secret(
secret_key: &Ed25519SecretKey,
) -> ApiResult<Ed25519PublicKey>
pub fn derive_public_from_secret( secret_key: &Ed25519SecretKey, ) -> ApiResult<Ed25519PublicKey>
Derive the public key from an existing secret key
This is useful when you have a secret key loaded from storage and need to reconstruct the corresponding public key.
§Example
use dcrypt_sign::eddsa::Ed25519;
use dcrypt_api::Signature;
use rand::rngs::OsRng;
let mut rng = OsRng;
let (original_public, secret) = Ed25519::keypair(&mut rng)?;
// Later, derive public key from secret
let derived_public = Ed25519::derive_public_from_secret(&secret)?;
assert_eq!(original_public.0, derived_public.0);Trait Implementations§
Source§impl Signature for Ed25519
impl Signature for Ed25519
Source§fn keypair<R: CryptoRng + RngCore>(rng: &mut R) -> ApiResult<Self::KeyPair>
fn keypair<R: CryptoRng + RngCore>(rng: &mut R) -> ApiResult<Self::KeyPair>
Generate an Ed25519 key pair
This follows the key generation process from RFC 8032:
- Generate a 32-byte random seed
- Hash the seed with SHA-512 to get 64 bytes
- Clear/set specific bits in the first 32 bytes (scalar clamping)
- Use the clamped scalar to derive the public key
Source§fn sign(
message: &[u8],
secret_key: &Self::SecretKey,
) -> ApiResult<Self::SignatureData>
fn sign( message: &[u8], secret_key: &Self::SecretKey, ) -> ApiResult<Self::SignatureData>
Sign a message using Ed25519
The signing process follows RFC 8032:
- r = SHA-512(prefix || message) mod L
- R = [r]B
- k = SHA-512(R || A || message) mod L
- s = (r + k*a) mod L
- Return (R, s)
Source§fn verify(
message: &[u8],
signature: &Self::SignatureData,
public_key: &Self::PublicKey,
) -> ApiResult<()>
fn verify( message: &[u8], signature: &Self::SignatureData, public_key: &Self::PublicKey, ) -> ApiResult<()>
Verify an Ed25519 signature
The verification process checks that: [s]B = R + [k]A where k = SHA-512(R || A || message) mod L
Source§type PublicKey = Ed25519PublicKey
type PublicKey = Ed25519PublicKey
Public key type for this algorithm
Source§type SecretKey = Ed25519SecretKey
type SecretKey = Ed25519SecretKey
Secret key type - must be zeroizable but not byte-accessible Read more
Source§type SignatureData = Ed25519Signature
type SignatureData = Ed25519Signature
Signature data type
Source§type KeyPair = (<Ed25519 as Signature>::PublicKey, <Ed25519 as Signature>::SecretKey)
type KeyPair = (<Ed25519 as Signature>::PublicKey, <Ed25519 as Signature>::SecretKey)
Key pair type (typically a tuple of public and secret keys)
Source§fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey
fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey
Extract the public key from a key pair
Source§fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey
fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey
Extract the secret key from a key pair
Auto Trait Implementations§
impl Freeze for Ed25519
impl RefUnwindSafe for Ed25519
impl Send for Ed25519
impl Sync for Ed25519
impl Unpin for Ed25519
impl UnwindSafe for Ed25519
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more