Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Dec 19, 2024
1 parent 3666c35 commit d7b13da
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 87 deletions.
10 changes: 3 additions & 7 deletions chacha20poly1305/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ edition.workspace = true
repository.workspace = true
readme.workspace = true

[features]
default = ["hacl"]
hacl = ["dep:libcrux-poly1305", "dep:libcrux-hacl-rs", "dep:libcrux-macros"]

[dependencies]
libcrux-poly1305 = { version = "=0.0.2-beta.2", path = "../poly1305/", features = [
"expose-hacl",
], optional = true }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true }
] }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/" }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
5 changes: 1 addition & 4 deletions chacha20poly1305/src/impl_hacl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AeadError, MacError, KEY_LEN, NONCE_LEN, TAG_LEN};
use crate::{AeadError, KEY_LEN, NONCE_LEN, TAG_LEN};

/// The ChaCha20-Poly1305 AEAD encryption function. Writes the concatenation of the ciphertexoft
/// produced by ChaCha20 and the MAC tag into `ctxt` and returns the two pieces separately.
Expand All @@ -24,9 +24,6 @@ pub fn encrypt<'a>(
}

// ensure destination slice has just the right length
let ctxt_len = ptxt.len() + TAG_LEN;
let ctxtu32 = &mut ctxt[..ctxt_len];

let (ctxt_cpa, tag) = ctxt.split_at_mut(ptxt.len());
let tag: &mut [u8; TAG_LEN] = tag.try_into().unwrap();

Expand Down
3 changes: 0 additions & 3 deletions chacha20poly1305/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub enum MacError {
InvalidMacTag,
}

#[cfg(feature = "hacl")]
mod hacl {
pub(crate) use libcrux_poly1305::hacl::mac_poly1305;

Expand All @@ -44,8 +43,6 @@ mod hacl {
pub(crate) mod chacha20_vec32;
}

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::*;
11 changes: 2 additions & 9 deletions curve25519/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ edition.workspace = true
repository.workspace = true
readme.workspace = true

[features]
default = ["hacl"]
hacl = ["dep:libcrux-sha2", "dep:libcrux-hacl-rs", "dep:libcrux-macros"]

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true }
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", optional = true, features = [
"hacl",
] }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/" }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
8 changes: 3 additions & 5 deletions curve25519/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![no_std]

#[cfg(feature = "hacl")]
pub use libcrux_hacl_rs::curve25519_51 as hacl;

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::{ecdh, secret_to_public};

/// The length of Curve25519 secret keys.
Expand All @@ -22,8 +19,9 @@ pub const SHK_LEN: usize = 32;
pub struct Error;

/// This trait is implemented by the backing implementations.
/// Only used for implementation agility.
pub trait Curve25519 {
/// Only used for ensuring implementations follow the same interface, not really consumed.
#[allow(dead_code)]
trait Curve25519 {
/// Computes a public key from a secret key.
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]);

Expand Down
12 changes: 4 additions & 8 deletions ed25519/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ edition.workspace = true
repository.workspace = true
readme.workspace = true

[features]
default = ["hacl"]
hacl = ["dep:libcrux-sha2", "dep:libcrux-hacl-rs", "dep:libcrux-macros"]

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true }
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", optional = true, features = [
"hacl",
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/" }
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", features = [
"expose-hacl",
] }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
3 changes: 0 additions & 3 deletions ed25519/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#![no_std]

#[cfg(feature = "hacl")]
pub mod hacl {
//! This module contains generated hacl code.
pub mod ed25519;
pub mod ed25519_precomptable;
}

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::*;
4 changes: 1 addition & 3 deletions libcrux-ecdh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ path = "src/ecdh.rs"
[dependencies]
rand = { version = "0.8" }
libcrux-hacl = { version = "=0.0.2-beta.2", path = "../sys/hacl" }
libcrux-curve25519 = { version = "=0.0.2-beta.2", path = "../curve25519", features = [
"hacl",
] }
libcrux-curve25519 = { version = "=0.0.2-beta.2", path = "../curve25519" }

[dev-dependencies]
rand_core = { version = "0.6" }
Expand Down
9 changes: 2 additions & 7 deletions libcrux-hkdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ description = "Libcrux HKDF implementation"
path = "src/hkdf.rs"

[features]
default = ["hacl"]
hacl = ["dep:libcrux-hmac", "dep:libcrux-hacl-rs"]

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true }
libcrux-hmac = { version = "=0.0.2-beta.2", path = "../libcrux-hmac", optional = true, features = [
"hacl",
libcrux-hmac = { version = "=0.0.2-beta.2", path = "../libcrux-hmac", features = [
"expose-hacl",

] }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/" }
6 changes: 0 additions & 6 deletions libcrux-hkdf/src/hkdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ extern crate alloc;

use alloc::vec::Vec;

#[cfg(feature = "hacl")]
pub mod hacl;

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::{HkdfSha2_256, HkdfSha2_384, HkdfSha2_512};

pub trait HkdfMode<const HASH_LEN: usize> {
Expand Down Expand Up @@ -115,7 +112,6 @@ pub enum Error {

/// HKDF extract using hash function `mode`, `salt`, and the input key material `ikm`.
/// Returns the pre-key material in a vector of tag length.
#[cfg(feature = "hacl")]
#[inline(always)]
pub fn extract(
alg: Algorithm,
Expand All @@ -134,7 +130,6 @@ pub fn extract(
/// HKDF expand using hash function `mode`, pre-key material `prk`, `info`, and output length `okm_len`.
/// Returns the key material in a vector of length `okm_len` or [`Error::OkmLengthTooLarge`]
/// if the requested output length is too large.
#[cfg(feature = "hacl")]
#[inline(always)]
pub fn expand(
alg: Algorithm,
Expand All @@ -155,7 +150,6 @@ pub fn expand(
/// Calls `extract` and `expand` with the given input.
/// Returns the key material in a vector of length `okm_len` or [`Error::OkmLengthTooLarge`]
/// if the requested output length is too large.
#[cfg(feature = "hacl")]
#[inline(always)]
pub fn hkdf(
mode: Algorithm,
Expand Down
10 changes: 4 additions & 6 deletions libcrux-hmac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ description = "Libcrux HMAC implementation"
path = "src/hmac.rs"

[features]
default = ["hacl"]
hacl = ["dep:libcrux-sha2", "dep:libcrux-hacl-rs", "dep:libcrux-macros"]
expose-hacl = ["hacl"]
expose-hacl = []

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true }
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", optional = true, features = [
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/" }
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", features = [
"expose-hacl",
] }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
4 changes: 1 addition & 3 deletions libcrux-hmac/src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate alloc;

use alloc::vec::Vec;

#[cfg(all(feature = "hacl", not(feature = "expose-hacl")))]
#[cfg(not(feature = "expose-hacl"))]
mod hacl {
pub(crate) mod hash_sha1;
pub(crate) mod hmac;
Expand All @@ -19,10 +19,8 @@ pub mod hacl {
pub mod hmac;
}

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::*;

/// The HMAC algorithm defining the used hash function.
Expand Down
8 changes: 3 additions & 5 deletions poly1305/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ repository.workspace = true
readme.workspace = true

[features]
default = ["hacl"]
hacl = ["dep:libcrux-hacl-rs", "dep:libcrux-macros"]
expose-hacl = ["hacl"]
expose-hacl = []

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/" }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
4 changes: 1 addition & 3 deletions poly1305/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Error {
InvalidMacTag,
}

#[cfg(all(feature = "hacl", not(feature = "expose-hacl")))]
#[cfg(not(feature = "expose-hacl"))]
mod hacl {
pub(crate) mod mac_poly1305;
}
Expand All @@ -25,8 +25,6 @@ pub mod hacl {
pub mod mac_poly1305;
}

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::*;
6 changes: 2 additions & 4 deletions rsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ repository.workspace = true
readme.workspace = true

[features]
default = ["hacl"]
hacl = ["dep:libcrux-hacl-rs"]
expose-hacl = ["hacl"]
expose-hacl = []

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs", optional = true }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs" }
libcrux-traits = { version = "=0.0.2-beta.2", path = "../traits/" }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", features = [
Expand Down
6 changes: 2 additions & 4 deletions rsa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

#[cfg(all(feature = "hacl", not(feature = "expose-hacl")))]
#[cfg(not(feature = "expose-hacl"))]
mod hacl {
pub(crate) mod rsapss;

Expand Down Expand Up @@ -38,12 +38,10 @@ impl DigestAlgorithm {
pub enum Error {
SaltTooLarge,
MessageTooLarge,
SigningFailed,
VerificationFailed,
SigningFailed,
}

#[cfg(feature = "hacl")]
mod impl_hacl;

#[cfg(feature = "hacl")]
pub use impl_hacl::*;
6 changes: 2 additions & 4 deletions sha2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ repository.workspace = true
readme.workspace = true

[features]
default = ["hacl"]
hacl = ["dep:libcrux-hacl-rs"]
expose-hacl = ["hacl"]
expose-hacl = []

[dependencies]
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs", optional = true }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs" }
libcrux-traits = { version = "=0.0.2-beta.2", path = "../traits/" }
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros" }
5 changes: 2 additions & 3 deletions sha2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ pub const SHA384_LENGTH: usize = 48;
pub const SHA512_LENGTH: usize = 64;

/// The generated hacl code
#[cfg(all(feature = "hacl", not(feature = "expose-hacl")))]
#[cfg(not(feature = "expose-hacl"))]
mod hacl;

/// The generated hacl code
#[cfg(feature = "expose-hacl")]
pub mod hacl;

/// The implementation of our types using that hacl code
#[cfg(feature = "hacl")]
mod impl_hacl;

/// use it if we want to use hacl
#[cfg(feature = "hacl")]
pub use impl_hacl::*;

0 comments on commit d7b13da

Please sign in to comment.