Files
opaque-vx/src/map_to_curve.rs
T

37 lines
1.3 KiB
Rust
Raw Normal View History

2020-07-22 11:58:00 -04:00
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//! Defines the GroupWithMapToCurve trait to specify how to map a password to a
//! curve point
use crate::group::Group;
use curve25519_dalek::{edwards::EdwardsPoint, ristretto::RistrettoPoint};
use hkdf::Hkdf;
2020-07-27 15:25:04 -07:00
use sha2::{Sha256, Sha512};
2020-07-27 15:25:04 -07:00
/// A subtrait of Group specifying how to hash a password into a point
pub trait GroupWithMapToCurve: Group {
2020-07-22 11:58:00 -04:00
/// transforms a password and optional pepper into a curve point
2020-11-02 13:51:43 -08:00
fn map_to_curve(password: &[u8], dst: Option<&[u8]>) -> Self;
}
2020-11-02 13:51:43 -08:00
// TODO: incorporate expand_message_xmd from https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-10.txt
// instead of using HKDF-extract here
impl GroupWithMapToCurve for RistrettoPoint {
2020-11-02 13:51:43 -08:00
fn map_to_curve(password: &[u8], dst: Option<&[u8]>) -> Self {
let (hashed_input, _) = Hkdf::<Sha512>::extract(dst, password);
2020-09-19 19:16:33 -04:00
<Self as Group>::hash_to_curve(&hashed_input)
}
}
impl GroupWithMapToCurve for EdwardsPoint {
2020-11-02 13:51:43 -08:00
fn map_to_curve(password: &[u8], dst: Option<&[u8]>) -> Self {
let (hashed_input, _) = Hkdf::<Sha256>::extract(dst, password);
2020-09-19 19:16:33 -04:00
<Self as Group>::hash_to_curve(&hashed_input)
}
}