Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back implementations of SHA2, HMAC-SHA1, HMAC-SHA2 and HKDF-SHA2 by hacl-rs #659

Merged
merged 32 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5920c3a
add proc-macro helper crate from hacl-rs
keks Nov 5, 2024
0e0243e
add hacl-rs hashing code, make libcrux use hacl-rs impl for sha2
keks Nov 5, 2024
a23ffcf
no hacl-c sha2 anymore
keks Nov 5, 2024
70dc04c
completely remove hacl-c sha2
keks Nov 5, 2024
f74ddcb
remove hash state wrapper for sha2
keks Nov 5, 2024
6d0f6d5
move hacl-rs to own subcrate
keks Nov 5, 2024
9a3cff8
make hmac crate use hacl-rs
keks Nov 5, 2024
ed655da
use ed25519 from hacl-rs
keks Nov 5, 2024
ba70ee0
use ed25519 better
keks Nov 5, 2024
418e508
fix length checks in hmac and sha2
keks Nov 6, 2024
1ade700
add hacl-rs hkdf
keks Nov 6, 2024
6653e08
fix cargo toml indent depth
keks Nov 6, 2024
50422b7
fix hmac lengths
keks Nov 6, 2024
8f9dd3a
fix name and add comment
keks Nov 6, 2024
ba561b3
impl Default for Sha2 hash states
keks Nov 6, 2024
45d1278
fmt rest of generated code
keks Nov 6, 2024
5e781bc
fix mishap
keks Nov 6, 2024
1f634b9
add wycheproof test for ed25519, hkdf and hmac
keks Nov 6, 2024
ece0107
move hacl-rs algorithms to individual crates and make composite crate…
keks Nov 7, 2024
1ca3ced
remove sha1 crate stub
keks Nov 7, 2024
ae73f50
remove remaining traces of sha1 crate stub
keks Nov 7, 2024
deefc26
fmt Cargo.toml
keks Nov 7, 2024
4a1026a
fmt more Cargo.toml
keks Nov 7, 2024
238e1fb
remove unuzed generated memzero function
keks Nov 7, 2024
97bf4b0
address PR feedback
keks Nov 11, 2024
e77f3a5
fix toml indent
keks Nov 11, 2024
05f1652
more cleanup
keks Nov 11, 2024
9caa0ff
rename bignum module
keks Nov 13, 2024
3c5be34
slight api change, more comments
keks Nov 13, 2024
f0f3d0e
fix ci error
keks Nov 14, 2024
a216c87
Merge branch 'main' into keks/hacl-rs
keks Nov 14, 2024
7584c13
Apply suggestions from code review
keks Nov 14, 2024
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
73 changes: 70 additions & 3 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ members = [
"libcrux-hkdf",
"libcrux-ecdh",
"libcrux-psq",
"macros",
"cavp",
"traits",
"sha2",
"ed25519",
"curve25519",
]

[workspace.package]
Expand Down Expand Up @@ -63,10 +68,14 @@ bench = false # so libtest doesn't eat the argumen
libcrux-platform = { version = "=0.0.2-beta.2", path = "sys/platform" }

[dependencies]
libcrux-traits = { version = "=0.0.2-beta.2", path = "traits" }
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "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 = { version = "=0.0.2-beta.2", path = "sha2" }
libcrux-ed25519 = { version = "=0.0.2-beta.2", path = "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 All @@ -93,6 +102,7 @@ serde_json = { version = "1.0" }
serde = { version = "1.0", features = ["derive"] }
hex = { version = "0.4.3", features = ["serde"] }
clap = { version = "4.5", features = ["derive"] }
wycheproof = "0.6.0"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3"
Expand Down
23 changes: 23 additions & 0 deletions curve25519/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "libcrux-curve25519"
description = "Formally verified curve25519 ECDH library"

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: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 }
18 changes: 18 additions & 0 deletions 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> {
keks marked this conversation as resolved.
Show resolved Hide resolved
if crate::hacl::ecdh(out, sk, pk) {
Ok(())
} else {
Err(Error)
}
}
}
37 changes: 37 additions & 0 deletions 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)
}
23 changes: 23 additions & 0 deletions ed25519/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "libcrux-ed25519"
description = "Formally verified ed25519 signature library"

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: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 }
Loading
Loading