|
| 1 | +//! The parameters for NTRU prime as described in section 3.4 |
| 2 | +//! SX is parameters for Streamlined NTRU Prime with `p = x`. |
| 3 | +//! Lx is parameters for `NTRULPRime` with `p = x`; |
| 4 | +
|
| 5 | +use hybrid_array::{ |
| 6 | + sizes::{U1277, U1278, U1305, U1521, U1713, U1905, U2025, U2552}, |
| 7 | + typenum::{U1013, U1014, U653, U654, U761, U762, U857, U858, U953, U954}, |
| 8 | + ArraySize, |
| 9 | +}; |
| 10 | + |
| 11 | +pub trait NtruCommon: 'static { |
| 12 | + type P: ArraySize; |
| 13 | + /// P + 1 |
| 14 | + type P1: ArraySize; |
| 15 | + /// P + P - 1 |
| 16 | + type PPM1: ArraySize; |
| 17 | + const Q: u16; |
| 18 | + const W: i16; |
| 19 | +} |
| 20 | + |
| 21 | +pub trait NtruLRPrime { |
| 22 | + const DELTA: u16; |
| 23 | + const TAU0: i16; |
| 24 | + const TAU1: i32; |
| 25 | + const TAU2: i32; |
| 26 | + const TAU3: i32; |
| 27 | +} |
| 28 | + |
| 29 | +macro_rules! impl_ntru_common { |
| 30 | + ($ty:ident, $p: ident, $p1: ident, $ppm1: ident, $q: literal, $w: literal ) => { |
| 31 | + impl NtruCommon for $ty { |
| 32 | + type P = $p; |
| 33 | + type P1 = $p1; |
| 34 | + type PPM1 = $ppm1; |
| 35 | + const Q: u16 = $q; |
| 36 | + const W: i16 = $w; |
| 37 | + } |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +macro_rules! impl_ntru_lrprime { |
| 42 | + ($ty:ident, $delta: literal, $tau0: literal, $tau1: literal, $tau2: literal, $tau3: literal ) => { |
| 43 | + impl NtruLRPrime for $ty { |
| 44 | + const DELTA: u16 = $delta; |
| 45 | + const TAU0: i16 = $tau0; |
| 46 | + const TAU1: i32 = $tau1; |
| 47 | + const TAU2: i32 = $tau2; |
| 48 | + const TAU3: i32 = $tau3; |
| 49 | + } |
| 50 | + }; |
| 51 | +} |
| 52 | + |
| 53 | +pub struct S653; |
| 54 | +pub struct S761; |
| 55 | +pub struct S857; |
| 56 | +pub struct S953; |
| 57 | +pub struct S1013; |
| 58 | +pub struct S1277; |
| 59 | +pub struct L653; |
| 60 | +pub struct L761; |
| 61 | +pub struct L857; |
| 62 | +pub struct L953; |
| 63 | +pub struct L1013; |
| 64 | +pub struct L1277; |
| 65 | + |
| 66 | +impl_ntru_common!(S653, U653, U654, U1305, 4621, 288); |
| 67 | +impl_ntru_common!(S761, U761, U762, U1521, 4591, 286); |
| 68 | +impl_ntru_common!(S857, U857, U858, U1713, 5167, 322); |
| 69 | +impl_ntru_common!(S953, U953, U954, U1905, 6343, 396); |
| 70 | +impl_ntru_common!(S1013, U1013, U1014, U2025, 7177, 448); |
| 71 | +impl_ntru_common!(S1277, U1277, U1278, U2552, 7879, 429); |
| 72 | +impl_ntru_common!(L653, U653, U654, U1305, 4621, 252); |
| 73 | +impl_ntru_common!(L761, U761, U762, U1521, 4591, 250); |
| 74 | +impl_ntru_common!(L857, U857, U858, U1713, 5167, 281); |
| 75 | +impl_ntru_common!(L953, U953, U954, U1905, 6343, 345); |
| 76 | +impl_ntru_common!(L1013, U1013, U1014, U2025, 7177, 392); |
| 77 | +impl_ntru_common!(L1277, U1277, U1278, U2552, 7879, 429); |
| 78 | +impl_ntru_lrprime!(L653, 289, 2175, 113, 2031, 290); |
| 79 | +impl_ntru_lrprime!(L761, 292, 2156, 114, 2007, 287); |
| 80 | +impl_ntru_lrprime!(L857, 329, 2433, 101, 2265, 324); |
| 81 | +impl_ntru_lrprime!(L953, 404, 2997, 82, 2798, 400); |
| 82 | +impl_ntru_lrprime!(L1013, 450, 3367, 73, 3143, 449); |
| 83 | +impl_ntru_lrprime!(L1277, 502, 3724, 66, 3469, 469); |
0 commit comments