Skip to content

Commit

Permalink
feat: make signing and key generation C independent
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Mar 4, 2024
1 parent d94e6fe commit a216bed
Show file tree
Hide file tree
Showing 19 changed files with 8,784 additions and 1,701 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ serde = { version = "1.0", features = ["derive"], default-features = false, opti
winter_crypto = { version = "0.8", package = "winter-crypto", default-features = false }
winter_math = { version = "0.8", package = "winter-math", default-features = false }
winter_utils = { version = "0.8", package = "winter-utils", default-features = false }
num-complex = "0.4.4"
num = "0.4.1"
rand = "0.8.5"
sha3 = "0.10.8"
hex = "0.4.3"

[dev-dependencies]
seq-macro = { version = "0.3" }
Expand Down
31 changes: 0 additions & 31 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
fn main() {
#[cfg(feature = "std")]
compile_rpo_falcon();

#[cfg(target_feature = "sve")]
compile_arch_arm64_sve();
}

#[cfg(feature = "std")]
fn compile_rpo_falcon() {
use std::path::PathBuf;

const RPO_FALCON_PATH: &str = "src/dsa/rpo_falcon512/falcon_c";

println!("cargo:rerun-if-changed={RPO_FALCON_PATH}/falcon.h");
println!("cargo:rerun-if-changed={RPO_FALCON_PATH}/falcon.c");
println!("cargo:rerun-if-changed={RPO_FALCON_PATH}/rpo.h");
println!("cargo:rerun-if-changed={RPO_FALCON_PATH}/rpo.c");

let target_dir: PathBuf = ["PQClean", "crypto_sign", "falcon-512", "clean"].iter().collect();
let common_dir: PathBuf = ["PQClean", "common"].iter().collect();

let scheme_files = glob::glob(target_dir.join("*.c").to_str().unwrap()).unwrap();
let common_files = glob::glob(common_dir.join("*.c").to_str().unwrap()).unwrap();

cc::Build::new()
.include(&common_dir)
.include(target_dir)
.files(scheme_files.into_iter().map(|p| p.unwrap().to_string_lossy().into_owned()))
.files(common_files.into_iter().map(|p| p.unwrap().to_string_lossy().into_owned()))
.file(format!("{RPO_FALCON_PATH}/falcon.c"))
.file(format!("{RPO_FALCON_PATH}/rpo.c"))
.flag("-O3")
.compile("rpo_falcon512");
}

#[cfg(target_feature = "sve")]
fn compile_arch_arm64_sve() {
const RPO_SVE_PATH: &str = "arch/arm64-sve/rpo";
Expand Down
8 changes: 6 additions & 2 deletions src/dsa/rpo_falcon512/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub enum FalconError {
SigDecodingMinusZero,
SigDecodingIncorrectEncodingAlgorithm,
SigDecodingNotSupportedDegree(u8),
SigGenerationFailed,
BadEncodingLength,
InvalidHeaderFormat,
WrongVariant,
}

impl fmt::Display for FalconError {
Expand Down Expand Up @@ -47,7 +49,9 @@ impl fmt::Display for FalconError {
SigDecodingMinusZero => write!(f, "Failed to decode signature: -0 is forbidden"),
SigDecodingIncorrectEncodingAlgorithm => write!(f, "Failed to decode signature: not supported encoding algorithm"),
SigDecodingNotSupportedDegree(log_n) => write!(f, "Failed to decode signature: only supported irreducible polynomial degree is 512, 2^{log_n} was provided"),
SigGenerationFailed => write!(f, "Failed to generate a signature"),
BadEncodingLength => write!(f, "Failed to decode: length is different from the one expected"),
InvalidHeaderFormat => write!(f, "Invalid header format"),
WrongVariant => write!(f, "Wrong Falcon DSA variant"),
}
}
}
Expand Down
Loading

0 comments on commit a216bed

Please sign in to comment.