Expand description
§Authenticated public-key cryptography functions
Implements libsodium’s public-key authenticated crypto boxes.
For details, refer to libsodium docs.
§Classic API example
use dryoc::classic::crypto_box::*;
use dryoc::constants::CRYPTO_BOX_MACBYTES;
use dryoc::types::*;
// Create a random sender keypair
let (sender_pk, sender_sk) = crypto_box_keypair();
// Create a random recipient keypair
let (recipient_pk, recipient_sk) = crypto_box_keypair();
// Generate a random nonce
let nonce = Nonce::gen();
let message = "hello".as_bytes();
// Encrypt message
let mut ciphertext = vec![0u8; message.len() + CRYPTO_BOX_MACBYTES];
crypto_box_easy(&mut ciphertext, message, &nonce, &recipient_pk, &sender_sk)
.expect("encrypt failed");
// Decrypt message
let mut decrypted_message = vec![0u8; ciphertext.len() - CRYPTO_BOX_MACBYTES];
crypto_box_open_easy(
&mut decrypted_message,
&ciphertext,
&nonce,
&sender_pk,
&recipient_sk,
)
.expect("decrypt failed");
assert_eq!(message, decrypted_message);Functions§
- crypto_
box_ beforenm - Computes a shared secret for the given
public_keyandprivate_key. Resulting shared secret can be used with the precalculation interface. - crypto_
box_ detached - Detached variant of
crypto_box_easy. - crypto_
box_ detached_ afternm - Precalculation variant of
crypto_box_easy. - crypto_
box_ detached_ afternm_ inplace - In-place variant of
crypto_box_detached_afternm. - crypto_
box_ detached_ inplace - In-place variant of
crypto_box_detached. - crypto_
box_ easy - Encrypts a message in a box.
- crypto_
box_ easy_ inplace - Encrypts a message in-place in a box.
- crypto_
box_ keypair - Generates a public/secret key pair using OS provided data using
rand_core::OsRng. - crypto_
box_ keypair_ inplace - In-place variant of
crypto_box_keypair - crypto_
box_ open_ detached - Detached variant of
crypto_box_open_easy. - crypto_
box_ open_ detached_ afternm - Precalculation variant of
crypto_box_open_easy. - crypto_
box_ open_ detached_ afternm_ inplace - In-place variant of
crypto_box_open_detached_afternm. - crypto_
box_ open_ detached_ inplace - In-place variant of
crypto_box_open_detached. - crypto_
box_ open_ easy - Decrypts
ciphertextwith recipient’s secret keyrecipient_secret_keyand sender’s public keysender_public_keyusingnonce. - crypto_
box_ open_ easy_ inplace - Decrypts a sealed box in-place.
- crypto_
box_ seal - Encrypts and seals a message in a box.
- crypto_
box_ seal_ open - Decrypts a sealed box.
- crypto_
box_ seed_ keypair - Deterministically derives a keypair from
seed, which can be of arbitrary length. - crypto_
box_ seed_ keypair_ inplace - In-place variant of
crypto_box_seed_keypair