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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
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
33 changes: 32 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"libcrux-hkdf",
"libcrux-ecdh",
"libcrux-psq",
"libcrux-hacl-rs-krml",
"cavp",
]

Expand Down Expand Up @@ -62,6 +63,7 @@ bench = false # so libtest doesn't eat the argumen
libcrux-platform = { version = "=0.0.2-beta.2", path = "sys/platform" }

[dependencies]
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" }
Expand Down Expand Up @@ -92,6 +94,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
11 changes: 11 additions & 0 deletions libcrux-hacl-rs-krml/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "libcrux-hacl-rs-krml"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[lib]
proc-macro=true
46 changes: 46 additions & 0 deletions libcrux-hacl-rs-krml/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use proc_macro::{Delimiter, TokenStream, TokenTree};

fn skip_comma<T: Iterator<Item = TokenTree>>(ts: &mut T) {
match ts.next() {
Some(TokenTree::Punct(p)) => assert_eq!(p.as_char(), ','),
_ => panic!("Expected comma"),
}
}

fn accept_token<T: Iterator<Item = TokenTree>>(ts: &mut T) -> TokenTree {
match ts.next() {
Some(t) => t,
_ => panic!("early end"),
}
}

fn brace(ts: TokenStream) -> TokenTree {
TokenTree::Group(proc_macro::Group::new(Delimiter::Brace, ts))
}

#[proc_macro]
pub fn unroll_for(ts: TokenStream) -> TokenStream {
let mut i = ts.into_iter();
let n_loops = accept_token(&mut i).to_string().parse::<u32>().unwrap();
skip_comma(&mut i);
let var = accept_token(&mut i).to_string();
let var = &var[1..var.len() - 1];
skip_comma(&mut i);
let start = accept_token(&mut i).to_string();
skip_comma(&mut i);
let increment = accept_token(&mut i).to_string();
skip_comma(&mut i);
let grouped_body = brace(TokenStream::from_iter(i));
let chunks = (0..n_loops).map(|i| {
let chunks = [
format!("const {}: u32 = {} + {} * {};", var, start, i, increment)
.parse()
.unwrap(),
TokenStream::from(grouped_body.clone()),
";".parse().unwrap(),
];
TokenStream::from(brace(TokenStream::from_iter(chunks)))
});
TokenStream::from(brace(TokenStream::from_iter(chunks.into_iter().flatten())))
// "{ let i = 0; println!(\"FROM MACRO{}\", i); }".parse().unwrap()
}
11 changes: 11 additions & 0 deletions libcrux-hacl-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "libcrux-hacl-rs"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krml = { package = "libcrux-hacl-rs-krml", path = "../libcrux-hacl-rs-krml" }

[lib]
12 changes: 12 additions & 0 deletions libcrux-hacl-rs/src/bignum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod bignum;
pub mod bignum256;
pub mod bignum256_32;
pub mod bignum32;
pub mod bignum4096;
pub mod bignum4096_32;
pub mod bignum64;
pub mod bignum_base;

pub mod test {
// pub mod bignum4096;
}
Loading
Loading