pub struct NewHope {
pub key: Vec<u8>,
}
impl NewHope {
pub fn new() -> Self {
NewHope {
key: vec![0; 32], }
}
pub fn exchange(&self, public_key: &[u8]) -> Vec<u8> {
self.simple_transform(public_key, |x| x.wrapping_add(1))
}
fn simple_transform<F>(&self, data: &[u8], f: F) -> Vec<u8>
where
F: Fn(u8) -> u8,
{
data.iter().map(|&x| f(x)).collect()
}
}
impl Default for NewHope {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_newhope_key_exchange() {
let newhope = NewHope::new();
let public_key = vec![1, 2, 3, 4];
let shared_secret = newhope.exchange(&public_key);
assert_eq!(shared_secret.len(), public_key.len());
}
}