Module dryoc::crypto_box[][src]

Authenticated public-key cryptography functions

Implements libsodium’s public-key authenticated crypto boxes.

For details, refer to libsodium docs.

Classic API example

use dryoc::prelude::*;
use dryoc::rng::randombytes_buf; // Not included in prelude
use dryoc::constants::CRYPTO_BOX_NONCEBYTES; // Not included in prelude
use std::convert::TryInto;

// Create a random sender keypair
let keypair_sender = crypto_box_keypair();

// Create a random recipient keypair
let keypair_recipient = crypto_box_keypair();

// Generate a random nonce
let nonce: Nonce = randombytes_buf(CRYPTO_BOX_NONCEBYTES).try_into().unwrap();

let message = "hello".as_bytes();
// Encrypt message
let ciphertext = crypto_box_easy(
    message,
    &nonce,
    &keypair_recipient.public_key.0,
    &keypair_sender.secret_key.0,
)
.unwrap();

// Decrypt message
let decrypted_message = crypto_box_open_easy(
    &ciphertext,
    &nonce,
    &keypair_sender.public_key.0,
    &keypair_recipient.secret_key.0,
)
.unwrap();

assert_eq!(message, decrypted_message);

Functions

crypto_box_beforenm

Computes a shared secret for the given public_key and private_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 crate::crypto_box::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 message with recipient’s public key recipient_public_key and sender’s secret key sender_secret_key using nonce

crypto_box_easy_inplace

Encrypts message with recipient’s public key recipient_public_key and sender’s secret key sender_secret_key using nonce in-place, without allocated additional memory for the message

crypto_box_keypair

Generates a public/secret key pair using OS provided data using rand_core::OsRng

crypto_box_open_detached

Detached variant of crate::crypto_box::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 ciphertext with recipient’s secret key recipient_secret_key and sender’s public key sender_public_key using nonce

crypto_box_open_easy_inplace

Decrypts ciphertext with recipient’s secret key recipient_secret_key and sender’s public key sender_public_key using nonce in-place, without allocated additional memory for the message

crypto_box_seed_keypair

Deterministically derives a keypair from seed.