use super::{Level5, SecurityLevel};
use hybrid_array::sizes::{U128, U129, U257, U292, U420, U576, U64, U8, U9};
pub const PRIME_LE_BYTES: [u8; 64] = {
let mut bytes = [0xffu8; 64];
bytes[62] = 0xAF;
bytes[63] = 0x01;
bytes
};
impl SecurityLevel for Level5 {
type FpLimbs = U9;
type MpLimbs = U8;
type FpEncodedBytes = U64;
type Fp2EncodedBytes = U128;
type PkLen = U129;
type SigLen = U292;
type ExpandedSigLen = U420;
type CompressedSigLen = U257;
type SkLen = U576;
fn prime_le_bytes() -> &'static [u8] {
&PRIME_LE_BYTES
}
const LAMBDA: u32 = 256;
const F_CHR: u32 = 500;
const E_RSP: u32 = 253;
const E_CHL: u32 = 256;
const HASH_ITERATIONS: u32 = 512;
const NWORDS_ORDER: usize = 8;
const TORSION_EVEN_POWER: u32 = 500;
const P_COFACTOR_FOR_2F_BITLENGTH: usize = 5;
const SQISIGN_RESPONSE_LENGTH: u32 = 253;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn level5_prime_is_correct() {
let bytes = Level5::prime_le_bytes();
assert_eq!(bytes.len(), 64);
for &b in &bytes[..62] {
assert_eq!(b, 0xFF, "low 62 bytes of p must all be 0xFF");
}
assert_eq!(bytes[62], 0xAF, "byte 62 of p must be 0xAF");
assert_eq!(bytes[63], 0x01, "top byte of p must be 0x01");
}
#[test]
fn level5_prime_is_3_mod_4() {
let bytes = Level5::prime_le_bytes();
assert_eq!(bytes[0] & 0b11, 3, "p mod 4 must be 3");
}
#[test]
fn level5_prime_bitlength() {
let bytes = Level5::prime_le_bytes();
assert_eq!(bytes[63], 0x01);
assert_eq!(bytes[62] & 0x80, 0x80, "bit 503 must be set");
}
const _: () = assert!(Level5::F_CHR > Level5::LAMBDA);
const _: () = assert!(Level5::E_RSP > 0);
#[test]
fn level5_protocol_exponents_in_range() {
assert_eq!(Level5::LAMBDA, 256);
assert_eq!(Level5::F_CHR, 500);
assert_eq!(Level5::E_RSP, 253);
}
}