-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,421 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: cargo | ||
directory: "/" | ||
schedule: | ||
interval: weekly | ||
open-pull-requests-limit: 10 | ||
- package-ecosystem: github-actions | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "libcrux-pqclean" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
||
[build-dependencies] | ||
cc = { version = "1.0", features = ["parallel"] } | ||
bindgen = "0.66" | ||
fs_extra = "1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# PQClean sys | ||
|
||
A simple sys crate to benchmark pqclean clode that is not exposed to Rust, like SHA3. | ||
|
||
The code is taken from https://github.com/PQClean/PQClean/commit/ef80f51badac27b78f8e0ef26f23cbd71ca0f283. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use std::{env, path::Path}; | ||
|
||
fn copy_files(home_path: &Path, out_path: &Path) { | ||
let mut options = fs_extra::dir::CopyOptions::new(); | ||
options.overwrite = true; | ||
fs_extra::dir::copy(home_path.join("c"), out_path, &options).unwrap(); | ||
} | ||
|
||
#[cfg(not(windows))] | ||
fn create_bindings(home_dir: &Path) { | ||
let c_dir = home_dir.join("c"); | ||
let clang_args = vec![format!("-I{}", c_dir.display())]; | ||
|
||
let bindings = bindgen::Builder::default() | ||
// Header to wrap headers | ||
.header("c/fips202.h") | ||
// Set include paths for headers | ||
.clang_args(clang_args) | ||
// Include the things we want | ||
.allowlist_function("shake.*") | ||
.allowlist_function("sha3.*") | ||
.allowlist_type("sha3.*") | ||
.allowlist_type("shake.*") | ||
.allowlist_type("SHAKE.*") | ||
.allowlist_type("SHA3.*") | ||
.allowlist_var("SHAKE.*") | ||
.allowlist_var("SHA3.*") | ||
// Disable tests to avoid warnings and keep it portable | ||
.layout_tests(false) | ||
// Generate bindings | ||
.parse_callbacks(Box::new(bindgen::CargoCallbacks)) | ||
.use_core() | ||
.generate() | ||
.expect("Unable to generate bindings"); | ||
|
||
let home_bindings = home_dir.join("src/bindings.rs"); | ||
bindings | ||
.write_to_file(home_bindings) | ||
.expect("Couldn't write bindings!"); | ||
} | ||
|
||
#[cfg(windows)] | ||
fn create_bindings(_: &Path) {} | ||
|
||
fn compile_files(library_name: &str, files: &[String], out_path: &Path, args: &[String]) { | ||
let c_dir = out_path.join("c"); | ||
|
||
let mut build = cc::Build::new(); | ||
build | ||
.files(files.iter().map(|fname| c_dir.join(fname))) | ||
.warnings_into_errors(true) | ||
.no_default_flags(true); | ||
|
||
build.include(c_dir.join("include")); | ||
build.flag("-O3").flag("-c"); | ||
for arg in args { | ||
build.flag(arg); | ||
} | ||
|
||
build.compile(library_name); | ||
} | ||
|
||
fn build(out_path: &Path) { | ||
let files = vec!["fips202.c".to_string()]; | ||
let args = vec![]; | ||
compile_files("libpqclean.a", &files, out_path, &args); | ||
} | ||
|
||
pub fn main() -> Result<(), u8> { | ||
// Get ENV variables | ||
let home_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
let home_path = Path::new(&home_dir); | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let out_path = Path::new(&out_dir); | ||
|
||
// Moving C/ASM code to output to make build easier. | ||
copy_files(home_path, out_path); | ||
|
||
// Build the C/ASM files | ||
build(out_path); | ||
|
||
// Set library name to look up | ||
let library_name = "pqclean"; | ||
|
||
// Set re-run trigger for all of s | ||
println!("cargo:rerun-if-changed=cs"); | ||
|
||
// Generate new bindings. This is a no-op on Windows. | ||
create_bindings(home_path); | ||
|
||
// Link hacl library. | ||
let mode = "static"; | ||
println!("cargo:rustc-link-lib={}={}", mode, library_name); | ||
println!("cargo:rustc-link-search=native={}", out_path.display()); | ||
println!("cargo:lib={}", out_path.display()); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.