#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
use crate::bigint;
#[doc(alias = "N")]
pub const LARGE_SAFE_PRIME_LENGTH: u8 = 32;
#[doc(alias = "N")]
pub const LARGE_SAFE_PRIME_BIG_ENDIAN: [u8; LARGE_SAFE_PRIME_LENGTH as usize] = [
0x89, 0x4b, 0x64, 0x5e, 0x89, 0xe1, 0x53, 0x5b, 0xbd, 0xad, 0x5b, 0x8b, 0x29, 0x6, 0x50, 0x53,
0x8, 0x1, 0xb1, 0x8e, 0xbf, 0xbf, 0x5e, 0x8f, 0xab, 0x3c, 0x82, 0x87, 0x2a, 0x3e, 0x9b, 0xb7,
];
#[doc(alias = "N")]
pub const LARGE_SAFE_PRIME_LITTLE_ENDIAN: [u8; LARGE_SAFE_PRIME_LENGTH as usize] = [
0xb7, 0x9b, 0x3e, 0x2a, 0x87, 0x82, 0x3c, 0xab, 0x8f, 0x5e, 0xbf, 0xbf, 0x8e, 0xb1, 0x1, 0x8,
0x53, 0x50, 0x6, 0x29, 0x8b, 0x5b, 0xad, 0xbd, 0x5b, 0x53, 0xe1, 0x89, 0x5e, 0x64, 0x4b, 0x89,
];
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub(crate) struct LargeSafePrime {
prime: [u8; LARGE_SAFE_PRIME_LENGTH as usize],
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
impl Default for LargeSafePrime {
fn default() -> Self {
Self {
prime: LARGE_SAFE_PRIME_LITTLE_ENDIAN,
}
}
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
impl LargeSafePrime {
pub const fn from_le_bytes(prime: [u8; LARGE_SAFE_PRIME_LENGTH as usize]) -> Self {
Self { prime }
}
pub const fn as_le_bytes(&self) -> &[u8; LARGE_SAFE_PRIME_LENGTH as usize] {
&self.prime
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub fn to_bigint(&self) -> bigint::Integer {
bigint::Integer::from_bytes_le(&self.prime)
}
}
#[doc(alias = "g")]
pub const GENERATOR: u8 = 7;
#[doc(alias = "g")]
pub const GENERATOR_LENGTH: u8 = 1;
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub(crate) struct Generator {
generator: u8,
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
impl Default for Generator {
fn default() -> Self {
Self {
generator: GENERATOR,
}
}
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
impl Generator {
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub fn to_bigint(&self) -> bigint::Integer {
bigint::Integer::from(self.generator)
}
pub const fn as_u8(&self) -> u8 {
self.generator
}
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
impl From<u8> for Generator {
fn from(g: u8) -> Self {
Self { generator: g }
}
}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub const K_VALUE: u8 = 3;
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub(crate) struct KValue {}
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
impl KValue {
#[cfg(any(feature = "srp-default-math", feature = "srp-fast-math"))]
pub fn bigint() -> bigint::Integer {
bigint::Integer::from(K_VALUE)
}
}
#[cfg(test)]
mod test {
#[test]
fn large_safe_prime_regression() {
const EXPECTED_BIG_ENDIAN: [u8; super::LARGE_SAFE_PRIME_LENGTH as usize] = [
0x89, 0x4b, 0x64, 0x5e, 0x89, 0xe1, 0x53, 0x5b, 0xbd, 0xad, 0x5b, 0x8b, 0x29, 0x6,
0x50, 0x53, 0x8, 0x1, 0xb1, 0x8e, 0xbf, 0xbf, 0x5e, 0x8f, 0xab, 0x3c, 0x82, 0x87, 0x2a,
0x3e, 0x9b, 0xb7,
];
const EXPECTED_LITTLE_ENDIAN: [u8; super::LARGE_SAFE_PRIME_LENGTH as usize] = [
0xb7, 0x9b, 0x3e, 0x2a, 0x87, 0x82, 0x3c, 0xab, 0x8f, 0x5e, 0xbf, 0xbf, 0x8e, 0xb1,
0x1, 0x8, 0x53, 0x50, 0x6, 0x29, 0x8b, 0x5b, 0xad, 0xbd, 0x5b, 0x53, 0xe1, 0x89, 0x5e,
0x64, 0x4b, 0x89,
];
assert_eq!(EXPECTED_BIG_ENDIAN, super::LARGE_SAFE_PRIME_BIG_ENDIAN);
assert_eq!(
EXPECTED_LITTLE_ENDIAN,
super::LARGE_SAFE_PRIME_LITTLE_ENDIAN
);
}
}