use crate::common::concat;
use crate::opaque::config::OpaqueCipherSuite;
pub fn blind(suite: &OpaqueCipherSuite, password: &[u8], blind_scalar: &[u8]) -> Vec<u8> {
let oprf = suite.oprf_suite();
let gs = oprf.group_spec();
let h = gs.hash_to_group(password, oprf.hash_to_group_dst());
assert!(
!gs.is_identity_element(&h),
"InvalidInputError: HashToGroup returned identity element (RFC 9497 §3.3.1)"
);
gs.scalar_multiply(blind_scalar, &h)
.expect("blind: hashed point must be a valid group element")
}
pub fn blind_evaluate(
suite: &OpaqueCipherSuite,
oprf_key: &[u8],
blinded_element: &[u8],
) -> Result<Vec<u8>, &'static str> {
suite
.oprf_suite()
.group_spec()
.scalar_multiply(oprf_key, blinded_element)
}
pub fn finalize(
suite: &OpaqueCipherSuite,
password: &[u8],
blind_scalar: &[u8],
evaluated_element: &[u8],
) -> Result<Vec<u8>, &'static str> {
suite
.oprf_suite()
.finalize(password, blind_scalar, evaluated_element)
}
pub fn derive_oprf_key(
suite: &OpaqueCipherSuite,
oprf_seed: &[u8],
credential_identifier: &[u8],
) -> Vec<u8> {
let info = concat(&[credential_identifier, b"OprfKey"]);
let seed = suite.hkdf_expand(oprf_seed, &info, suite.nok());
suite
.oprf_suite()
.derive_key_pair(&seed, b"OPAQUE-DeriveKeyPair")
}