pub struct FieldElement<const LIMBS: usize> {
pub limbs: [u64; LIMBS],
}Expand description
A field element over a prime p, represented as LIMBS x u64
limbs in little-endian order (limbs[0] is least significant).
All arithmetic operations on FieldElement are constant-time
and work modulo a per-call prime p supplied as a &[u64; LIMBS]
(no implicit field association). The same struct is used by
every short-Weierstrass curve in the crate; the LIMBS const tracks
the prime size: 4 for P-256 / secp256k1 / brainpoolP256r1, 6 for
P-384 / brainpoolP384r1, 8 for brainpoolP512r1, 9 for P-521.
Fields§
§limbs: [u64; LIMBS]Limb storage in little-endian order (limbs[0] is least significant).
Implementations§
Source§impl<const LIMBS: usize> FieldElement<LIMBS>
impl<const LIMBS: usize> FieldElement<LIMBS>
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true if every limb is zero. Constant-time across all
limbs (no early-exit branch).
Sourcepub fn from_bytes_be(bytes: &[u8]) -> Self
pub fn from_bytes_be(bytes: &[u8]) -> Self
Encode from big-endian bytes.
Sourcepub fn to_bytes_be(&self) -> Vec<u8> ⓘ
pub fn to_bytes_be(&self) -> Vec<u8> ⓘ
Encode to big-endian bytes.
Sourcepub fn from_bytes_le(bytes: &[u8]) -> Self
pub fn from_bytes_le(bytes: &[u8]) -> Self
Encode from little-endian bytes. Used by X25519 (RFC 7748) which is LE-native throughout, unlike the SEC1-era curves.
Sourcepub fn to_bytes_le(&self) -> Vec<u8> ⓘ
pub fn to_bytes_le(&self) -> Vec<u8> ⓘ
Encode to little-endian bytes (LIMBS*8 bytes).
Trait Implementations§
Source§impl<const LIMBS: usize> Clone for FieldElement<LIMBS>
impl<const LIMBS: usize> Clone for FieldElement<LIMBS>
Source§fn clone(&self) -> FieldElement<LIMBS>
fn clone(&self) -> FieldElement<LIMBS>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more