Skip to content

Commit

Permalink
move hacl-rs algorithms to individual crates and make composite crate…
Browse files Browse the repository at this point in the history
…s use these
  • Loading branch information
keks committed Nov 7, 2024
1 parent a1363a8 commit 193f95f
Show file tree
Hide file tree
Showing 39 changed files with 7,796 additions and 268 deletions.
50 changes: 48 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 41 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
[workspace]
members = [
"sys/hacl",
"sys/libjade",
"sys/platform",
"sys/pqclean",
"sys/lib25519",
"benchmarks",
"fuzz",
"libcrux-ml-kem",
"libcrux-sha3",
"libcrux-ml-dsa",
"libcrux-intrinsics",
"libcrux-kem",
"libcrux-hmac",
"libcrux-hkdf",
"libcrux-ecdh",
"libcrux-psq",
"libcrux-hacl-rs-krml",
"cavp",
"sys/hacl",
"sys/libjade",
"sys/platform",
"sys/pqclean",
"sys/lib25519",
"benchmarks",
"fuzz",
"libcrux-ml-kem",
"libcrux-sha3",
"libcrux-ml-dsa",
"libcrux-intrinsics",
"libcrux-kem",
"libcrux-hmac",
"libcrux-hkdf",
"libcrux-ecdh",
"libcrux-psq",
"libcrux-hacl-rs-krml",
"cavp",
"libcrux-sha1",
"libcrux-traits",
"libcrux-sha2",
"libcrux-ed25519", "libcrux-curve25519",
]

[workspace.package]
Expand All @@ -44,15 +48,15 @@ readme.workspace = true
documentation = "https://docs.rs/libcrux/"
description = "The Formally Verified Cryptography Library"
exclude = [
"/tests",
"/specs",
"/proofs",
"/*.py",
"/wasm-demo",
"/fuzz",
"/git-hooks",
"/architecture",
"/libcrux.fst.config.json",
"/tests",
"/specs",
"/proofs",
"/*.py",
"/wasm-demo",
"/fuzz",
"/git-hooks",
"/architecture",
"/libcrux.fst.config.json",
]

[lib]
Expand All @@ -63,11 +67,14 @@ bench = false # so libtest doesn't eat the argumen
libcrux-platform = { version = "=0.0.2-beta.2", path = "sys/platform" }

[dependencies]
libcrux-traits = { path = "libcrux-traits" }
libcrux-hacl-rs = { path = "libcrux-hacl-rs" }
libcrux-hacl = { version = "=0.0.2-beta.2", path = "sys/hacl" }
libcrux-platform = { version = "=0.0.2-beta.2", path = "sys/platform" }
libcrux-hkdf = { version = "=0.0.2-beta.2", path = "libcrux-hkdf" }
libcrux-hmac = { version = "=0.0.2-beta.2", path = "libcrux-hmac" }
libcrux-sha2 = { path = "libcrux-sha2" }
libcrux-ed25519 = { path = "libcrux-ed25519" }
libcrux-ecdh = { version = "=0.0.2-beta.2", path = "libcrux-ecdh" }
libcrux-ml-kem = { version = "=0.0.2-beta.2", path = "libcrux-ml-kem" }
libcrux-kem = { version = "=0.0.2-beta.2", path = "libcrux-kem" }
Expand Down Expand Up @@ -115,11 +122,11 @@ panic = "abort"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(hax)',
'cfg(eurydice)',
'cfg(doc_cfg)',
'cfg(libjade)',
'cfg(simd128)',
'cfg(simd256)',
'cfg(aes_ni)',
'cfg(hax)',
'cfg(eurydice)',
'cfg(doc_cfg)',
'cfg(libjade)',
'cfg(simd128)',
'cfg(simd256)',
'cfg(aes_ni)',
] }
21 changes: 21 additions & 0 deletions libcrux-curve25519/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "libcrux-curve25519"
version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
edition.workspace = true
repository.workspace = true
readme.workspace = true

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

[dependencies]
libcrux-hacl-rs = { path = "../libcrux-hacl-rs/", optional = true }
libcrux-sha2 = { path = "../libcrux-sha2", optional = true, features = [
"hacl",
] }
krml = { package = "libcrux-hacl-rs-krml", path = "../libcrux-hacl-rs-krml", optional = true }
18 changes: 18 additions & 0 deletions libcrux-curve25519/src/impl_hacl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use super::*;

/// Implementation of Curve25519 backed by Hacl.
pub struct HaclCurve25519;

impl Curve25519 for HaclCurve25519 {
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]) {
crate::hacl::secret_to_public(pk, sk)
}

fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error> {
if crate::hacl::ecdh(out, sk, pk) {
Ok(())
} else {
Err(Error)
}
}
}
37 changes: 37 additions & 0 deletions libcrux-curve25519/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#[cfg(feature = "hacl")]
pub use libcrux_hacl_rs::curve25519_51 as hacl;

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

#[cfg(feature = "portable_hacl")]
pub use impl_hacl::HaclCurve25519 as Impl;

/// The length of Curve25519 secret keys.
pub const SK_LEN: usize = 32;

/// The length of Curve25519 public keys.
pub const PK_LEN: usize = 32;

/// The length of Curve25519 shared keys.
pub const SHK_LEN: usize = 32;

/// Indicates that an error occurred
pub struct Error;

/// This trait is implemented by the backing implementations.
/// Only used for implementation agility.
trait Curve25519 {
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]);
fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error>;
}

/// Computes and writes the public key from the secret key `sk` and writes it into `pk`.
pub fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]) {
Impl::secret_to_public(pk, sk)
}

/// Performs the ECDH computation and writes the key shared betweem `pk` and `sk` into `shk`.
pub fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error> {
Impl::ecdh(out, pk, sk)
}
1 change: 1 addition & 0 deletions libcrux-ecdh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ path = "src/ecdh.rs"
[dependencies]
rand = { version = "0.8" }
libcrux-hacl = { version = "=0.0.2-beta.2", path = "../sys/hacl" }
libcrux-curve25519 = { path = "../libcrux-curve25519", features = ["hacl"] }

[dev-dependencies]
rand_core = { version = "0.6" }
Expand Down
Loading

0 comments on commit 193f95f

Please sign in to comment.