pub struct Scalar(/* private fields */);
Expand description
Positive 256-bit integer guaranteed to be less than the secp256k1 curve order.
The difference between SecretKey
and Scalar
is that Scalar
doesn’t guarantee being
securely usable as a private key.
Warning: the operations on this type are NOT constant time! Using this with secret values is not advised.
Implementations§
Source§impl Scalar
impl Scalar
Sourcepub fn non_secure_erase(&mut self)
pub fn non_secure_erase(&mut self)
Attempts to erase the contents of the underlying array.
Note, however, that the compiler is allowed to freely copy or move the
contents of this array to other places in memory. Preventing this behavior
is very subtle. For more discussion on this, please see the documentation
of the zeroize
crate.
Source§impl Scalar
impl Scalar
Sourcepub fn random() -> Scalar
Available on crate features rand
and std
only.
pub fn random() -> Scalar
rand
and std
only.Generates a random scalar
Sourcepub fn random_custom<R>(rng: R) -> Scalarwhere
R: Rng,
Available on crate feature rand
only.
pub fn random_custom<R>(rng: R) -> Scalarwhere
R: Rng,
rand
only.Generates a random scalar using supplied RNG
Sourcepub fn from_be_bytes(value: [u8; 32]) -> Result<Scalar, OutOfRangeError>
pub fn from_be_bytes(value: [u8; 32]) -> Result<Scalar, OutOfRangeError>
Tries to deserialize from big endian bytes
Security warning: this function is not constant time! Passing secret data is not recommended.
§Errors
Returns error when the value is above the curve order.
Sourcepub fn from_le_bytes(value: [u8; 32]) -> Result<Scalar, OutOfRangeError>
pub fn from_le_bytes(value: [u8; 32]) -> Result<Scalar, OutOfRangeError>
Tries to deserialize from little endian bytes
Security warning: this function is not constant time! Passing secret data is not recommended.
§Errors
Returns error when the value is above the curve order.
Sourcepub fn to_be_bytes(self) -> [u8; 32]
pub fn to_be_bytes(self) -> [u8; 32]
Serializes to big endian bytes
Sourcepub fn to_le_bytes(self) -> [u8; 32]
pub fn to_le_bytes(self) -> [u8; 32]
Serializes to little endian bytes
Trait Implementations§
Source§impl Ord for Scalar
impl Ord for Scalar
Source§impl PartialOrd for Scalar
impl PartialOrd for Scalar
impl Copy for Scalar
impl Eq for Scalar
impl StructuralPartialEq for Scalar
Auto Trait Implementations§
impl Freeze for Scalar
impl RefUnwindSafe for Scalar
impl Send for Scalar
impl Sync for Scalar
impl Unpin for Scalar
impl UnwindSafe for Scalar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.