Skip to main content

Module crypto_sign_ed25519

Module crypto_sign_ed25519 

Source
Expand description

§Ed25519 signing helpers

This module implements libsodium’s Ed25519 helper functions, including Ed25519 to Curve25519 conversion and secret-key extraction. You can use the conversion functions when you want to sign messages with the same keys used to encrypt messages (i.e., using a public-key box).

Generally speaking, you should avoid signing and encrypting with the same keypair. Additionally, an encrypted box doesn’t need to be separately signed as it already includes a message authentication code.

§Classic API example

use dryoc::classic::crypto_sign::{
    crypto_sign_ed25519_sk_to_pk, crypto_sign_ed25519_sk_to_seed, crypto_sign_seed_keypair,
};
use dryoc::constants::{CRYPTO_SIGN_PUBLICKEYBYTES, CRYPTO_SIGN_SEEDBYTES};

let seed = [7u8; CRYPTO_SIGN_SEEDBYTES];
let (public_key, secret_key) = crypto_sign_seed_keypair(&seed);

let mut extracted_seed = [0u8; CRYPTO_SIGN_SEEDBYTES];
let mut extracted_public_key = [0u8; CRYPTO_SIGN_PUBLICKEYBYTES];
crypto_sign_ed25519_sk_to_seed(&mut extracted_seed, &secret_key);
crypto_sign_ed25519_sk_to_pk(&mut extracted_public_key, &secret_key);

assert_eq!(extracted_seed, seed);
assert_eq!(extracted_public_key, public_key);

Functions§

crypto_sign_ed25519_pk_to_curve25519
Converts an Ed25519 public key ed25519_public_key into an X25519 public key, placing the result into x25519_public_key upon success.
crypto_sign_ed25519_sk_to_curve25519
Converts an Ed25519 secret key ed25519_secret_key into an X25519 secret key, placing the result into x25519_secret_key.
crypto_sign_ed25519_sk_to_pk
Extracts the Ed25519 public key from secret_key, placing the result into public_key.
crypto_sign_ed25519_sk_to_seed
Extracts the Ed25519 seed from secret_key, placing the result into seed.

Type Aliases§

PublicKey
Type alias for an Ed25519 public key.
SecretKey
Type alias for an Ed25519 secret key with seed bytes.
Signature
Type alias for an Ed25519 signature.