File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -763,6 +763,34 @@ impl EdwardsPoint {
763763 }
764764 }
765765 }
766+
767+ /// Construct a `EdwardsPoint` from 64 bytes of data.
768+ ///
769+ /// If the input bytes are uniformly distributed, the resulting
770+ /// point will be uniformly distributed over the group, and its
771+ /// discrete log with respect to other points should be unknown.
772+ ///
773+ /// # Implementation
774+ ///
775+ /// This function splits the input array into two 32-byte halves,
776+ /// takes the low 255 bits of each half mod p, applies the Elligator2
777+ /// map to each, and adds the results.
778+ pub fn from_uniform_bytes ( bytes : & [ u8 ; 64 ] ) -> EdwardsPoint {
779+ // https://www.rfc-editor.org/rfc/rfc9380.html#section-3-4.1.2
780+
781+ let mut q = [ 0u8 ; 32 ] ;
782+
783+ q. copy_from_slice ( & bytes[ 0 ..32 ] ) ;
784+ let q0 = FieldElement :: from_bytes ( & q) ;
785+ let Q0 = Self :: map_to_curve ( q0) ;
786+
787+ q. copy_from_slice ( & bytes[ 32 ..64 ] ) ;
788+ let q1 = FieldElement :: from_bytes ( & q) ;
789+ let Q1 = Self :: map_to_curve ( q1) ;
790+
791+ let R = Q0 + Q1 ;
792+ R . mul_by_cofactor ( )
793+ }
766794}
767795
768796// ------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments