use p256::{AffinePoint, ProjectivePoint, Scalar};
use crate::hash::hash_to_scalar;
fn derive_e(cert: &[u8]) -> Scalar {
hash_to_scalar(cert)
}
pub fn reconstruction_point(request_pk: &AffinePoint, k: &Scalar) -> AffinePoint {
AffinePoint::from(ProjectivePoint::from(*request_pk) + ProjectivePoint::GENERATOR * k)
}
pub fn issue_private_value(cert: &[u8], k: &Scalar, d_ca: &Scalar) -> Scalar {
let e = derive_e(cert);
e * k + d_ca
}
pub fn requester_private_key(cert: &[u8], k_u: &Scalar, r: &Scalar) -> Scalar {
let e = derive_e(cert);
e * k_u + r
}
pub fn user_public_key(cert: &[u8], p_u: &AffinePoint, q_ca: &AffinePoint) -> AffinePoint {
let e = derive_e(cert);
AffinePoint::from(ProjectivePoint::from(*p_u) * e + ProjectivePoint::from(*q_ca))
}
pub fn public_from_private(d: &Scalar) -> AffinePoint {
AffinePoint::from(ProjectivePoint::GENERATOR * d)
}