use p256_curve::{Point, ShortWeierstrass};
pub use p256_curve::AffinePoint;
pub use p256_field::a_256::A256;

mod p256_field;
mod p256_curve;

#[cfg(test)]
mod p256_field_test;
#[cfg(test)]
mod p256_curve_test;

/// Generacja klucza ECDHE NIST-P256
pub fn gen_keys(rnd: [u32; 8]) -> (A256, AffinePoint) {
    let key_prv = A256::new(rnd);
    let key_pub = Point::to_affine(ShortWeierstrass::mul(key_prv, AffinePoint::to_projective(ShortWeierstrass::P256.g)));
    return (key_prv, key_pub);
}

/// Obliczenie wspólnego klucza ECDHE NIST-P256
pub fn gen_secret(key_prv: A256, key_pub: AffinePoint) -> A256 {
    return Point::to_affine(ShortWeierstrass::mul(key_prv, AffinePoint::to_projective(key_pub))).x;
}
