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

Make signing and key generation C independent #285

Merged
merged 51 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c0d30a7
feat: make signing and key generation C independent
Al-Kindi-0 Mar 4, 2024
1042c9b
ci: fix imports
Al-Kindi-0 Mar 4, 2024
a1b597f
ci: fix imports
Al-Kindi-0 Mar 4, 2024
0ddee4e
ci: fix imports
Al-Kindi-0 Mar 4, 2024
ad23ef3
ci: fix imports
Al-Kindi-0 Mar 4, 2024
c3c63c3
ci: fix imports
Al-Kindi-0 Mar 4, 2024
61c25f6
ci: fix imports
Al-Kindi-0 Mar 4, 2024
574a022
ci: fix imports
Al-Kindi-0 Mar 4, 2024
b4cb9ff
ci: fix imports
Al-Kindi-0 Mar 4, 2024
59c3282
chore: reduce the number of constants used in FFT
Al-Kindi-0 Mar 8, 2024
002ea35
chore: misc. improvements
Al-Kindi-0 Mar 11, 2024
bc41c77
docs: improve documentation
Al-Kindi-0 Mar 12, 2024
9552e6f
chore: refactoring fft in signiture generation
Al-Kindi-0 Mar 12, 2024
243ac65
feat: refactorings and generalizing hash-to-point logic
Al-Kindi-0 Mar 14, 2024
93a375a
refactor: hash-to-point
bobbinth Mar 14, 2024
b450870
refactor: add PubKeyPoly
bobbinth Mar 14, 2024
c41c52c
refactor: improve signature serialization
bobbinth Mar 15, 2024
3a45635
refactor: better encapsulation of signature functions
bobbinth Mar 15, 2024
dbc8f19
fix: validate signature header on deserialization
bobbinth Mar 15, 2024
0104351
refactor: better handling of signature header
bobbinth Mar 15, 2024
208f4b4
chore: minor formatting updates
bobbinth Mar 15, 2024
a95b775
fix: serialization error
Al-Kindi-0 Mar 15, 2024
cdcd988
doc: update signature docs
Al-Kindi-0 Mar 15, 2024
b601df7
chore: refactor serialization and add docs
Al-Kindi-0 Mar 15, 2024
579307d
chore: removed Rpo prefix
Al-Kindi-0 Mar 15, 2024
fae7daa
doc: add comments key pair
Al-Kindi-0 Mar 15, 2024
0d3e9b3
chore: remove HashToPoint and revert to RpoFalcon512
Al-Kindi-0 Mar 18, 2024
5c03ffe
feat: key recovery mode
Al-Kindi-0 Mar 18, 2024
3d31133
chore: fix alloc imports
bobbinth Mar 18, 2024
aa1e687
chore: remove PQClean submodule
bobbinth Mar 18, 2024
cdb81df
chore: rename falcon module back to rpo_falcon512
bobbinth Mar 18, 2024
c8411da
refactor: make helper methods private
bobbinth Mar 18, 2024
7a450da
chore: refactorings and no-std fixes
Al-Kindi-0 Mar 19, 2024
ff7ee24
fix: add js flag
Al-Kindi-0 Mar 19, 2024
2424b98
fix: std in test
Al-Kindi-0 Mar 19, 2024
3eaeb4b
fix: rmv comments and add acknowledgement
Al-Kindi-0 Mar 19, 2024
8d9cad5
chore: nits and code shuffling
Al-Kindi-0 Mar 20, 2024
32a696a
fix: revert .toml changes
Al-Kindi-0 Mar 20, 2024
94ed313
fix: remove num feature
Al-Kindi-0 Mar 20, 2024
6f6906d
refactor: minor code organization improvements
bobbinth Mar 20, 2024
0dc684b
fix: wasm build
bobbinth Mar 20, 2024
1e4e11b
chore: revert back key recovery mode
Al-Kindi-0 Mar 21, 2024
d7b5170
feat: change signature header format and add comment
Al-Kindi-0 Mar 21, 2024
b60807b
feat: RngCore on RpoRandomCoin
Al-Kindi-0 Mar 21, 2024
ebf08fa
fix: warning
Al-Kindi-0 Mar 21, 2024
598ab85
fix: warning
Al-Kindi-0 Mar 21, 2024
83e67b2
fix: warning
Al-Kindi-0 Mar 21, 2024
bc78890
fix: warning
Al-Kindi-0 Mar 21, 2024
8f9ccfa
refactor: minor updates signature tests, comments, and private key co…
bobbinth Mar 22, 2024
1354e0a
chore: update changelog and readme
bobbinth Mar 22, 2024
b751c0f
feat: separate sign() and sign_with_rng()
bobbinth Mar 22, 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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "PQClean"]
path = PQClean
url = https://github.com/PQClean/PQClean.git
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 = [
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 }
rand = {version = "0.8.5"}
num-complex = "0.4.4"
num = "0.4.1"
sha3 = "0.10.8"
hex = "0.4.3"

[dev-dependencies]
seq-macro = { version = "0.3" }
Expand Down
1 change: 0 additions & 1 deletion PQClean
Submodule PQClean deleted from c3abeb
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
50 changes: 31 additions & 19 deletions src/dsa/rpo_falcon512/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::fmt;

use super::{LOG_N, MODULUS, PK_LEN};
use core::fmt;

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FalconError {
Expand All @@ -9,13 +8,9 @@ pub enum FalconError {
PubKeyDecodingInvalidCoefficient(u32),
PubKeyDecodingInvalidLength(usize),
PubKeyDecodingInvalidTag(u8),
SigDecodingTooBigHighBits(u32),
SigDecodingInvalidRemainder,
SigDecodingNonZeroUnusedBitsLastByte,
SigDecodingMinusZero,
SigDecodingIncorrectEncodingAlgorithm,
SigDecodingNotSupportedDegree(u8),
SigGenerationFailed,
InvalidEncodingLength,
InvalidHeaderFormat,
WrongVariant,
}

impl fmt::Display for FalconError {
Expand All @@ -35,22 +30,39 @@ impl fmt::Display for FalconError {
PubKeyDecodingInvalidTag(byte) => {
write!(f, "Failed to decode public key: expected the first byte to be {LOG_N} but was {byte}")
}
SigDecodingTooBigHighBits(m) => {
write!(f, "Failed to decode signature: high bits {m} exceed 2048")
InvalidEncodingLength => {
write!(f, "Failed to decode: length is different from the one expected")
}
SigDecodingInvalidRemainder => {
write!(f, "Failed to decode signature: incorrect remaining data")
InvalidHeaderFormat => write!(f, "Invalid header format"),
WrongVariant => write!(f, "Wrong Falcon DSA variant"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for FalconError {}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FalconSerializationError {
TooBigHighBits(u32),
MinusZero,
NonZeroUnusedBitsLastByte,
}

impl fmt::Display for FalconSerializationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use FalconSerializationError::*;
match self {
TooBigHighBits(m) => {
write!(f, "Failed to decode signature: high bits {m} exceed 2048")
}
SigDecodingNonZeroUnusedBitsLastByte => {
NonZeroUnusedBitsLastByte => {
write!(f, "Failed to decode signature: Non-zero unused bits in the last byte")
}
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"),
MinusZero => write!(f, "Failed to decode signature: -0 is forbidden"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for FalconError {}
impl std::error::Error for FalconSerializationError {}
Loading
Loading