Skip to content

Commit 480cbb7

Browse files
committed
Add EdwardsPoint::from_uniform_bytes()
1 parent c3a82a8 commit 480cbb7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

curve25519-dalek/src/edwards.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)