pairing_plus/
hash_to_curve.rs1use bls12_381::{ClearH, IsogenyMap, OSSWUMap};
6use hash_to_field::{hash_to_field, ExpandMsg, FromRO};
7use CurveProjective;
8
9type CoordT<PtT> = <PtT as CurveProjective>::Base;
10
11pub trait HashToCurve<X>
13where
14 X: ExpandMsg
15{
16 fn hash_to_curve<Mt: AsRef<[u8]>, Dt: AsRef<[u8]>>(msg: Mt, dst: Dt) -> Self;
18
19 fn encode_to_curve<Mt: AsRef<[u8]>, Dt: AsRef<[u8]>>(msg: Mt, dst: Dt) -> Self;
21}
22
23impl<PtT, X> HashToCurve<X> for PtT
24where
25 PtT: ClearH + IsogenyMap + OSSWUMap,
26 CoordT<PtT>: FromRO,
27 X: ExpandMsg,
28{
29 fn hash_to_curve<Mt: AsRef<[u8]>, Dt: AsRef<[u8]>>(msg: Mt, dst: Dt) -> PtT {
30 let mut p = {
31 let u = hash_to_field::<CoordT<PtT>, X>(msg.as_ref(), dst.as_ref(), 2);
32 let mut tmp = PtT::osswu_map(&u[0]);
33 tmp.add_assign(&PtT::osswu_map(&u[1]));
34 tmp
35 };
36 p.isogeny_map();
37 p.clear_h();
38 p
39 }
40
41 fn encode_to_curve<Mt: AsRef<[u8]>, Dt: AsRef<[u8]>>(msg: Mt, dst: Dt) -> PtT {
42 let mut p = {
43 let u = hash_to_field::<CoordT<PtT>, X>(msg.as_ref(), dst.as_ref(), 1);
44 PtT::osswu_map(&u[0])
45 };
46 p.isogeny_map();
47 p.clear_h();
48 p
49 }
50}