1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use digest::generic_array::GenericArray; use digest::Digest; use crate::group::{Affine, Jacobian}; use crate::scalar::Scalar; use crate::ecmult::ECMultContext; impl ECMultContext { pub fn ecdh_raw<D: Digest + Default>(&self, point: &Affine, scalar: &Scalar) -> Option<GenericArray<u8, D::OutputSize>> { let mut digest: D = Default::default(); let mut pt = point.clone(); let s = scalar.clone(); if s.is_zero() { return None; } let mut res = Jacobian::default(); self.ecmult_const(&mut res, &pt, &s); pt.set_gej(&res); pt.x.normalize(); pt.y.normalize(); let x = pt.x.b32(); let y = 0x02 | (if pt.y.is_odd() { 1 } else { 0 }); digest.input(&[y]); digest.input(&x); Some(digest.result_reset()) } }