Add const fn to create a dalek-ff-group FieldElement

This commit is contained in:
Luke Parker
2025-08-19 13:17:39 -04:00
parent 2c4de3bab4
commit 961f46bc04

View File

@@ -216,6 +216,13 @@ impl PrimeFieldBits for FieldElement {
} }
impl FieldElement { impl FieldElement {
/// Create a FieldElement from a `crypto_bigint::U256`.
///
/// This will reduce the `U256` by the modulus, into a member of the field.
pub const fn from_u256(u256: &U256) -> Self {
FieldElement(Residue::new(u256))
}
/// Interpret the value as a little-endian integer, square it, and reduce it into a FieldElement. /// Interpret the value as a little-endian integer, square it, and reduce it into a FieldElement.
pub fn from_square(value: [u8; 32]) -> FieldElement { pub fn from_square(value: [u8; 32]) -> FieldElement {
let value = U256::from_le_bytes(value); let value = U256::from_le_bytes(value);