Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 97 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions crypto_box/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ edition = "2021"
rust-version = "1.85"

[dependencies]
aead = { version = "0.6.0-rc.2", default-features = false }
aead = { version = "=0.6.1", default-features = false }
crypto_secretbox = { version = "=0.2.0-pre.0", default-features = false, path = "../crypto_secretbox" }
curve25519-dalek = { version = "=5.0.0-pre.1", default-features = false, features = ["zeroize"] }
curve25519-dalek = { version = "=5.0.0", default-features = false, features = ["zeroize"] }
subtle = { version = "2", default-features = false }
zeroize = { version = "1", default-features = false }

# optional dependencies
chacha20 = { version = "0.10.0-rc.2", optional = true }
blake2 = { version = "0.11.0-rc.2", optional = true, default-features = false }
salsa20 = { version = "0.11.0-rc.1", optional = true }
salsa20 = { version = "=0.11.0", optional = true }
serdect = { version = "0.4", optional = true, default-features = false }

[dev-dependencies]
hex-literal = "0.4"
rand = "0.9"
rand = "0.10.2"
rmp-serde = "1"
ed25519-dalek = { version = "3.0.0-pre.1", features = ["rand_core"] }
ed25519-dalek = { version = "3.0.0", features = ["rand_core"] }

[features]
default = ["alloc", "os_rng", "rand_core", "salsa20"]
alloc = ["aead/alloc"]
std = ["alloc"]

os_rng = ["aead/os_rng"]
os_rng = ["aead/getrandom"]
chacha20 = ["dep:chacha20", "crypto_secretbox/chacha20"]
heapless = ["aead/heapless"]
heapless = ["aead/arrayvec"]
rand_core = ["aead/rand_core"]
salsa20 = ["dep:salsa20", "crypto_secretbox/salsa20"]
seal = ["dep:blake2", "alloc"]
Expand Down
26 changes: 16 additions & 10 deletions crypto_box/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#![cfg_attr(not(all(feature = "os_rng", feature = "std")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use crypto_box::{
//! aead::{Aead, AeadCore, rand_core::{OsRng, TryRngCore}},
//! aead::{
//! common::getrandom::{rand_core::UnwrapErr, SysRng},
//! Aead, Generate, Nonce,
//! },
//! SalsaBox, PublicKey, SecretKey
//! };
//!
Expand All @@ -23,7 +26,7 @@
//!
//! // Generate a random secret key.
//! // NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()`
//! let alice_secret_key = SecretKey::generate(&mut OsRng.unwrap_err());
//! let alice_secret_key = SecretKey::generate(&mut UnwrapErr(SysRng));
//!
//! // Get the public key for the secret key we just generated
//! let alice_public_key_bytes = alice_secret_key.public_key().as_bytes().clone();
Expand All @@ -41,7 +44,7 @@
//! let alice_box = SalsaBox::new(&bob_public_key, &alice_secret_key);
//!
//! // Get a random nonce to encrypt the message under
//! let nonce = SalsaBox::generate_nonce_with_rng(&mut OsRng.unwrap_err());
//! let nonce = Nonce::<SalsaBox>::generate();
//!
//! // Message to encrypt
//! let plaintext = b"Top secret message we're encrypting";
Expand Down Expand Up @@ -96,11 +99,14 @@
)]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use crypto_box::{
//! aead::{Aead, AeadCore, Payload, rand_core::{OsRng, TryRngCore}},
//! aead::{
//! common::getrandom::{rand_core::UnwrapErr, SysRng},
//! Aead, Generate, Nonce,
//! },
//! ChaChaBox, PublicKey, SecretKey
//! };
//!
//! let alice_secret_key = SecretKey::generate(&mut OsRng.unwrap_err());
//! let alice_secret_key = SecretKey::generate(&mut UnwrapErr(SysRng));
//! let alice_public_key_bytes = alice_secret_key.public_key().as_bytes().clone();
//! let bob_public_key = PublicKey::from([
//! 0xe8, 0x98, 0xc, 0x86, 0xe0, 0x32, 0xf1, 0xeb,
Expand All @@ -109,7 +115,7 @@
//! 0x67, 0x8a, 0x53, 0x78, 0x9d, 0x92, 0xc7, 0x54,
//! ]);
//! let alice_box = ChaChaBox::new(&bob_public_key, &alice_secret_key);
//! let nonce = ChaChaBox::generate_nonce_with_rng(&mut OsRng.unwrap_err());
//! let nonce = Nonce::<ChaChaBox>::generate();
//!
//! // Message to encrypt
//! let plaintext = b"Top secret message we're encrypting".as_ref();
Expand Down Expand Up @@ -143,13 +149,13 @@
//! This crate has an optional `alloc` feature which can be disabled in e.g.
//! microcontroller environments that don't have a heap.
//!
//! The [`AeadInPlace::encrypt_in_place`] and [`AeadInPlace::decrypt_in_place`]
//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
//! methods accept any type that impls the [`aead::Buffer`] trait which
//! contains the plaintext for encryption or ciphertext for decryption.
//!
//! Note that if you enable the `heapless` feature of this crate,
//! you will receive an impl of `aead::Buffer` for [`heapless::Vec`]
//! (re-exported from the `aead` crate as `aead::heapless::Vec`),
//! you will receive an impl of `aead::Buffer` for [`arrayvec::ArrayVec`]
//! (re-exported from the `aead` crate as `aead::arrayvec::ArrayVec`),
//! which can then be passed as the `buffer` parameter to the in-place encrypt
//! and decrypt methods.
//!
Expand All @@ -163,7 +169,7 @@
//! [X25519]: https://cr.yp.to/ecdh.html
//! [XSalsa20Poly1305]: https://nacl.cr.yp.to/secretbox.html
//! [ECIES]: https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme
//! [`heapless::Vec`]: https://docs.rs/heapless/latest/heapless/struct.Vec.html
//! [`arrayvec::ArrayVec`]: https://docs.rs/arrayvec/latest/arrayvec/struct.ArrayVec.html

#[cfg(feature = "seal")]
extern crate alloc;
Expand Down
11 changes: 5 additions & 6 deletions crypto_box/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crypto_box::{
};
use curve25519_dalek::EdwardsPoint;
use hex_literal::hex;
use rand::{rngs::OsRng, TryRngCore};
use rand::{rand_core::UnwrapErr, rngs::SysRng};

// Alice's keypair
const ALICE_SECRET_KEY: [u8; 32] =
Expand Down Expand Up @@ -45,7 +45,7 @@ const PLAINTEXT: &[u8] = &[

#[test]
fn generate_secret_key() {
SecretKey::generate(&mut OsRng.unwrap_err());
SecretKey::generate(&mut UnwrapErr(SysRng));
}

#[test]
Expand Down Expand Up @@ -242,7 +242,7 @@ fn seal() {
];

let pk = PublicKey::from(SEAL_PUBLIC_KEY);
let encrypted = pk.seal(&mut OsRng.unwrap_err(), SEAL_PLAINTEXT).unwrap();
let encrypted = pk.seal(&mut UnwrapErr(SysRng), SEAL_PLAINTEXT).unwrap();

let sk = SecretKey::from(SEAL_SECRET_KEY);
assert_eq!(SEAL_PLAINTEXT, sk.unseal(&encrypted).unwrap());
Expand All @@ -269,11 +269,10 @@ fn test_seal_regression() {

#[cfg(feature = "chacha20")]
fn seal_open_roundtrip(this: &ed25519_dalek::SigningKey, other: &ed25519_dalek::SigningKey) {
use aead::AeadCore;
use aead::{Generate, Nonce};

let msg = b"super secret message!!!!".to_vec();
let nonce = crypto_box::ChaChaBox::try_generate_nonce_with_rng(&mut rand::rngs::OsRng)
.expect("not enough randomness");
let nonce = Nonce::<crypto_box::ChaChaBox>::generate_from_rng(&mut UnwrapErr(SysRng));

let shared_a = {
let secret_key = crypto_box::SecretKey::from(this.to_scalar());
Expand Down
16 changes: 9 additions & 7 deletions crypto_secretbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ categories = ["cryptography", "no-std"]
rust-version = "1.85"

[dependencies]
aead = { version = "=0.6.0-rc.2", default-features = false }
cipher = { version = "=0.5.0-rc.1", default-features = false }
aead = { version = "=0.6.1", default-features = false }
cipher = { version = "=0.5.2", default-features = false }
hybrid-array = { version = "0.4.4", features = ["zeroize"] }
poly1305 = "=0.9.0-rc.2"
poly1305 = "=0.9.1"
subtle = { version = "2", default-features = false }
zeroize = { version = "1", default-features = false }

# optional dependencies
chacha20 = { version = "=0.10.0-rc.2", optional = true, features = ["zeroize", "xchacha", "legacy"] }
salsa20 = { version = "=0.11.0-rc.1", optional = true, features = ["zeroize"] }
chacha20 = { version = "=0.10.0", optional = true, features = ["zeroize", "xchacha", "legacy"] }
salsa20 = { version = "=0.11.0", optional = true, features = ["zeroize"] }

[dev-dependencies]
hex-literal = "0.4"
Expand All @@ -37,9 +37,11 @@ default = ["alloc", "os_rng", "rand_core", "salsa20"]
alloc = ["aead/alloc"]
std = ["alloc"]

heapless = ["aead/heapless"]
chacha20 = ["dep:chacha20"]
heapless = ["aead/arrayvec"]
rand_core = ["aead/rand_core"]
os_rng = ["aead/os_rng"]
os_rng = ["aead/getrandom"]
salsa20 = ["dep:salsa20"]

[package.metadata.docs.rs]
all-features = true
26 changes: 13 additions & 13 deletions crypto_secretbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#![cfg_attr(not(all(feature = "os_rng", feature = "std")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use crypto_secretbox::{
//! aead::{Aead, AeadCore, KeyInit, rand_core::{OsRng, TryRngCore}},
//! aead::{Aead, Generate, Key, KeyInit},
//! XSalsa20Poly1305, Nonce
//! };
//!
//! let key = XSalsa20Poly1305::generate_key_with_rng(&mut OsRng.unwrap_err());
//! let key = Key::<XSalsa20Poly1305>::generate();
//! let cipher = XSalsa20Poly1305::new(&key);
//! let nonce = XSalsa20Poly1305::generate_nonce_with_rng(&mut OsRng.unwrap_err()); // unique per message
//! let nonce = Nonce::generate(); // unique per message
//! let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?;
//! let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?;
//! assert_eq!(&plaintext, b"plaintext message");
Expand All @@ -33,13 +33,13 @@
//! This crate has an optional `alloc` feature which can be disabled in e.g.
//! microcontroller environments that don't have a heap.
//!
//! The [`AeadInPlace::encrypt_in_place`] and [`AeadInPlace::decrypt_in_place`]
//! The [`AeadInOut::encrypt_in_place`] and [`AeadInOut::decrypt_in_place`]
//! methods accept any type that impls the [`aead::Buffer`] trait which
//! contains the plaintext for encryption or ciphertext for decryption.
//!
//! Note that if you enable the `heapless` feature of this crate,
//! you will receive an impl of [`aead::Buffer`] for `heapless::Vec`
//! (re-exported from the `aead` crate as [`aead::heapless::Vec`]),
//! you will receive an impl of [`aead::Buffer`] for `arrayvec::ArrayVec`
//! (re-exported from the `aead` crate as [`aead::arrayvec::ArrayVec`]),
//! which can then be passed as the `buffer` parameter to the in-place encrypt
//! and decrypt methods:
//!
Expand All @@ -53,26 +53,26 @@
)]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use crypto_secretbox::{
//! aead::{AeadCore, AeadInPlace, KeyInit, rand_core::{OsRng, TryRngCore}, heapless::Vec},
//! aead::{arrayvec::ArrayVec, AeadInOut, Generate, Key, KeyInit},
//! XSalsa20Poly1305, Nonce,
//! };
//!
//! let key = XSalsa20Poly1305::generate_key_with_rng(&mut OsRng.unwrap_err());
//! let key = Key::<XSalsa20Poly1305>::generate();
//! let cipher = XSalsa20Poly1305::new(&key);
//! let nonce = XSalsa20Poly1305::generate_nonce_with_rng(&mut OsRng.unwrap_err()); // unique per message
//! let nonce = Nonce::generate(); // unique per message
//!
//! let mut buffer: Vec<u8, 128> = Vec::new(); // Note: buffer needs 16-bytes overhead for auth tag
//! buffer.extend_from_slice(b"plaintext message");
//! let mut buffer: ArrayVec<u8, 128> = ArrayVec::new(); // Note: buffer needs 16-bytes overhead for auth tag
//! buffer.try_extend_from_slice(b"plaintext message").unwrap();
//!
//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
//! cipher.encrypt_in_place(&nonce, b"", &mut buffer)?;
//!
//! // `buffer` now contains the message ciphertext
//! assert_ne!(&buffer, b"plaintext message");
//! assert_ne!(buffer.as_slice(), b"plaintext message");
//!
//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
//! cipher.decrypt_in_place(&nonce, b"", &mut buffer)?;
//! assert_eq!(&buffer, b"plaintext message");
//! assert_eq!(buffer.as_slice(), b"plaintext message");
//! # Ok(())
//! # }
//! ```
Expand Down
8 changes: 4 additions & 4 deletions crypto_secretstream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ edition = "2021"
rust-version = "1.85"

[dependencies]
aead = { version = "=0.6.0-rc.2", default-features = false }
chacha20 = { version = "=0.10.0-rc.2", features = ["xchacha"] }
poly1305 = "0.9.0-rc.2"
aead = { version = "=0.6.1", default-features = false }
chacha20 = { version = "=0.10.0", features = ["xchacha"] }
poly1305 = "=0.9.1"
subtle = { version = "2", default-features = false }

rand_core = { version = "0.9", optional = true }
Expand All @@ -32,7 +32,7 @@ default = ["std", "rand_core"]
alloc = ["aead/alloc"]
std = ["alloc", "rand_core?/std"]

heapless = ["aead/heapless"]
heapless = ["aead/arrayvec"]
rand_core = ["dep:rand_core"]

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions crypto_secretstream/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ mod tests {

#[test]
fn can_be_constructed_by_serialized() {
let header = Header::generate(&mut OsRng.unwrap_err());
let header = Header::generate(OsRng.unwrap_err());

let reconstructed_header = Header::from(header);
let reconstructed_header = Header::from(*header.as_ref());

assert_eq!(header.as_ref(), reconstructed_header.as_ref());
}
Expand Down
2 changes: 1 addition & 1 deletion crypto_secretstream/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod tests {

#[test]
fn can_be_constructed_by_serialized() {
let key = Key::generate(&mut OsRng.unwrap_err());
let key = Key::generate(OsRng.unwrap_err());

let reconstructed_key = Key::from(*key.as_ref());

Expand Down
2 changes: 1 addition & 1 deletion crypto_secretstream/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use chacha20::{
use core::{mem, slice};
use poly1305::{
universal_hash::{
crypto_common::{BlockSizeUser, IvSizeUser},
common::{BlockSizeUser, IvSizeUser},
UniversalHash,
},
Poly1305,
Expand Down
21 changes: 11 additions & 10 deletions crypto_secretstream/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ const ASSOCIATED_DATA: &[u8] = b"beware of giving it away";
#[test]
#[cfg(feature = "heapless")]
fn two_pushstreams_dont_generate_same_ciphertext() {
use aead::heapless::Vec;
use aead::arrayvec::ArrayVec;
use rand_core::TryRngCore;

let key = Key::generate(&mut OsRng.unwrap_err());
let key = Key::generate(OsRng.unwrap_err());

let (_, mut first_stream) = PushStream::init(&mut OsRng.unwrap_err(), &key);
let (_, mut second_stream) = PushStream::init(&mut OsRng.unwrap_err(), &key);
let (_, mut first_stream) = PushStream::init(OsRng.unwrap_err(), &key);
let (_, mut second_stream) = PushStream::init(OsRng.unwrap_err(), &key);

let mut first_ciphertext = Vec::<u8, 256>::from_slice(PLAINTEXT).expect("create first vec");
let mut first_ciphertext = ArrayVec::<u8, 256>::try_from(PLAINTEXT).expect("create first vec");
first_stream
.push(&mut first_ciphertext, ASSOCIATED_DATA, Tag::Message)
.expect("push in first stream");

let mut second_ciphertext = Vec::<u8, 256>::from_slice(PLAINTEXT).expect("create second vec");
let mut second_ciphertext =
ArrayVec::<u8, 256>::try_from(PLAINTEXT).expect("create second vec");
second_stream
.push(&mut second_ciphertext, ASSOCIATED_DATA, Tag::Message)
.expect("push in second stream");
Expand All @@ -35,9 +36,9 @@ fn two_pushstreams_dont_generate_same_ciphertext() {
fn pushstream_doesnt_generate_same_ciphertext_for_same_plaintext() {
use rand_core::TryRngCore;

let key = Key::generate(&mut OsRng.unwrap_err());
let key = Key::generate(OsRng.unwrap_err());

let (_, mut stream) = PushStream::init(&mut OsRng.unwrap_err(), &key);
let (_, mut stream) = PushStream::init(OsRng.unwrap_err(), &key);

let mut first_ciphertext = Vec::from(PLAINTEXT);
stream
Expand All @@ -57,9 +58,9 @@ fn pushstream_doesnt_generate_same_ciphertext_for_same_plaintext() {
fn pushed_can_be_pulled() {
use rand_core::TryRngCore;

let key = Key::generate(&mut OsRng.unwrap_err());
let key = Key::generate(OsRng.unwrap_err());

let (header, mut push_stream) = PushStream::init(&mut rand_core::OsRng.unwrap_err(), &key);
let (header, mut push_stream) = PushStream::init(rand_core::OsRng.unwrap_err(), &key);
let mut pull_stream = PullStream::init(header, &key);

let mut message = Vec::from(PLAINTEXT);
Expand Down
Loading