Просмотр исходного кода

fix bug in kyber

previous commit introduced a bug in Barrett reduction
tags/v0.0.1
Henry Case 3 лет назад
Родитель
Сommit
944543c9b9
4 измененных файлов: 27 добавлений и 8 удалений
  1. +3
    -4
      src/kem/kyber/common/reduce.c
  2. +11
    -1
      src/rustapi/pqc-sys/src/bindings.rs
  3. +1
    -1
      src/rustapi/pqc-sys/src/build.rs
  4. +12
    -2
      test/katrunner/src/main.rs

+ 3
- 4
src/kem/kyber/common/reduce.c Просмотреть файл

@@ -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);
}

+ 11
- 1
src/rustapi/pqc-sys/src/bindings.rs Просмотреть файл

@@ -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)]


+ 1
- 1
src/rustapi/pqc-sys/src/build.rs Просмотреть файл

@@ -4,7 +4,7 @@ extern crate bindgen;

fn main() {
let dst = Config::new("../../../")
.profile("Release")
.profile("Debug")
.very_verbose(true)
.build();



+ 12
- 2
test/katrunner/src/main.rs Просмотреть файл

@@ -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")
};

}

Загрузка…
Отмена
Сохранить