mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 15:39:07 +00:00
fix bug in kyber
previous commit introduced a bug in Barrett reduction
This commit is contained in:
parent
c98780b4d5
commit
944543c9b9
@ -35,9 +35,8 @@ int16_t kyber_montgomery_reduce(int32_t a) {
|
||||
* Returns: integer in {0,q} congruent to a modulo q.
|
||||
**************************************************/
|
||||
int16_t kyber_barrett_reduce(int16_t a) {
|
||||
int16_t t;
|
||||
static const int32_t v = 20159;
|
||||
int32_t t;
|
||||
t = v*a;
|
||||
t >>= 26;
|
||||
return a - ((int16_t)t)*KYBER_Q;
|
||||
t = ((v * a) + (1 << 25)) >> 26;
|
||||
return a - (t*KYBER_Q);
|
||||
}
|
||||
|
@ -257,7 +257,17 @@ pub const PQC_ALG_KEM_HQCRMRS128: ::std::os::raw::c_uint = 16;
|
||||
pub const PQC_ALG_KEM_HQCRMRS192: ::std::os::raw::c_uint = 17;
|
||||
pub const PQC_ALG_KEM_HQCRMRS256: ::std::os::raw::c_uint = 18;
|
||||
pub const PQC_ALG_KEM_SIKE434: ::std::os::raw::c_uint = 19;
|
||||
pub const PQC_ALG_KEM_MAX: ::std::os::raw::c_uint = 20;
|
||||
pub const PQC_ALG_KEM_MCELIECE348864: ::std::os::raw::c_uint = 20;
|
||||
pub const PQC_ALG_KEM_MCELIECE460896: ::std::os::raw::c_uint = 21;
|
||||
pub const PQC_ALG_KEM_MCELIECE6688128: ::std::os::raw::c_uint = 22;
|
||||
pub const PQC_ALG_KEM_MCELIECE6960119: ::std::os::raw::c_uint = 23;
|
||||
pub const PQC_ALG_KEM_MCELIECE8192128: ::std::os::raw::c_uint = 24;
|
||||
pub const PQC_ALG_KEM_MCELIECE348864F: ::std::os::raw::c_uint = 25;
|
||||
pub const PQC_ALG_KEM_MCELIECE460896F: ::std::os::raw::c_uint = 26;
|
||||
pub const PQC_ALG_KEM_MCELIECE6688128F: ::std::os::raw::c_uint = 27;
|
||||
pub const PQC_ALG_KEM_MCELIECE6960119F: ::std::os::raw::c_uint = 28;
|
||||
pub const PQC_ALG_KEM_MCELIECE8192128F: ::std::os::raw::c_uint = 29;
|
||||
pub const PQC_ALG_KEM_MAX: ::std::os::raw::c_uint = 30;
|
||||
pub type _bindgen_ty_2 = ::std::os::raw::c_uint;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
@ -4,7 +4,7 @@ extern crate bindgen;
|
||||
|
||||
fn main() {
|
||||
let dst = Config::new("../../../")
|
||||
.profile("Release")
|
||||
.profile("Debug")
|
||||
.very_verbose(true)
|
||||
.build();
|
||||
|
||||
|
@ -226,11 +226,14 @@ const KATS: &'static[Register] = &[
|
||||
//REG_SIGN!(PQC_ALG_SIG_RAINBOWIIICLASSIC),
|
||||
];
|
||||
|
||||
fn execute(kat_dir: String, thc: usize) {
|
||||
fn execute(kat_dir: String, thc: usize, file_filter: &str) {
|
||||
// Can't do multi-threads as DRBG context is global
|
||||
let pool = ThreadPool::new(thc);
|
||||
for k in KATS.iter() {
|
||||
let tmp = kat_dir.clone();
|
||||
if !file_filter.is_empty() && !k.kat.kat_file.contains(file_filter) {
|
||||
continue;
|
||||
}
|
||||
pool.execute(move || {
|
||||
DRBGV.lock().unwrap()
|
||||
.insert(thread::current().id(), DrbgCtx::new());
|
||||
@ -266,8 +269,15 @@ fn main() {
|
||||
None => 4 /* by default 4 threads */,
|
||||
};
|
||||
|
||||
// Run only selected name of the KAT file
|
||||
let file_filter = match argmap.get(&"--filter".to_string()) {
|
||||
Some(n) => n,
|
||||
None => ""
|
||||
};
|
||||
|
||||
match argmap.get(&"--katdir".to_string()) {
|
||||
Some(kat_dir) => execute(kat_dir.to_string(), thread_number),
|
||||
Some(kat_dir) => execute(kat_dir.to_string(), thread_number, file_filter),
|
||||
None => panic!("--katdir required")
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user