Expand description
§Public-key signatures
This module implements libsodium’s public-key signature functions. The signatures are based on Ed25519 (EdDSA). It provides both a single-part and multi-part interface.
The single-part interface is convenient for short messages, such as those small enough to fit in memory. The multi-part interface may be more appropriate for lengthy messages, those which don’t fit in memory, or those for which the entire message isn’t known at once (i.e., during network communication, or reading a large file).
The single-part and multi-part variants use slightly different algorithms, and thus they are not compatible with each other.
Use this module when you want to:
- share a message with other parties, and provide a proof that the message is authentic
- verify that the message from another party was signed using their secret key, without having knowledge of the original secret
The public key of the signer must be known to the verifier.
Keep signing and encryption keys separate. Although Ed25519 keys can be converted to X25519 keys or derived from the same seed, doing so couples two distinct security roles.
Signing secret keys include both the seed and public key. Use
secret_key_to_seed, secret_key_to_public_key,
SigningKeyPair::to_seed, or SigningKeyPair::to_public_key to extract
those parts when interoperating with libsodium-style key storage.
§Rustaceous API example, single-part
use dryoc::sign::*;
// Generate a random keypair, using default types
let keypair = SigningKeyPair::<PublicKey, SecretKey>::generate();
let message = b"Fair is foul, and foul is fair: Hover through the fog and filthy air.";
// Sign the message, using default types (stack-allocated byte array, Vec<u8>)
let signed_message = keypair.sign_with_defaults(message).expect("signing failed");
// Verify the message signature
signed_message
.verify(&keypair.public_key)
.expect("verification failed");§Extracting key material
use dryoc::sign::*;
let seed = Seed::from([7u8; dryoc::constants::CRYPTO_SIGN_SEEDBYTES]);
let keypair = SigningKeyPair::<PublicKey, SecretKey>::from_seed(&seed);
let extracted_seed: Seed = keypair.to_seed();
let extracted_public_key: PublicKey = keypair.to_public_key();
assert_eq!(extracted_seed, seed);
assert_eq!(extracted_public_key, keypair.public_key);§Incremental (multi-part) interface
use dryoc::sign::*;
// Generate a random keypair, using default types
let keypair = SigningKeyPair::<PublicKey, SecretKey>::generate();
// Initialize the incremental signer interface
let mut signer = IncrementalSigner::new();
signer.update(b"This above all: to thine ownself be true.");
signer.update(b"And it must follow, as the night the day,");
signer.update(b"Thou canst not then be false to any man.");
let signature: Signature = signer
.finalize(&keypair.secret_key)
.expect("signing failed");§Additional resources
- See https://libsodium.gitbook.io/doc/public-key_cryptography/public-key_signatures for additional details on public-key signatures
- For secret-key based encryption, see
DryocSecretBox - For stream encryption, see
DryocStream - See the protected mod for an example using the protected memory features
Modules§
- protected
protected - Protected memory for
SigningKeyPairandSignedMessage
Structs§
- Incremental
Signer - Multi-part (incremental) interface for
SigningKeyPair. - Signed
Message - A signed message, for use with
SigningKeyPair. - Signing
KeyPair - An Ed25519 keypair for public-key signatures
Functions§
- secret_
key_ to_ public_ key - Extracts the Ed25519 public key from a signing secret key.
- secret_
key_ to_ seed - Extracts the Ed25519 seed from a signing secret key.
Type Aliases§
- Message
- Heap-allocated message for message signing.
- Public
Key - Stack-allocated public key for message signing.
- Secret
Key - Stack-allocated secret key for message signing.
- Seed
- Stack-allocated seed for message signing.
- Signature
- Stack-allocated signature for message signing.
- VecSigned
Message - Vec-based signed message.