Struct Scalar
pub struct Scalar(/* private fields */);
Expand description
Positive 256-bit integer guaranteed to be less than the secp256k1 curve order.
The difference between PrivateKey
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§
§impl Scalar
impl Scalar
pub 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.
§impl Scalar
impl Scalar
pub fn random_custom<R>(rng: R) -> Scalarwhere
R: Rng,
pub fn random_custom<R>(rng: R) -> Scalarwhere
R: Rng,
Generates a random scalar using supplied RNG
pub 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.
pub 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.
pub fn to_be_bytes(self) -> [u8; 32]
pub fn to_be_bytes(self) -> [u8; 32]
Serializes to big endian bytes
pub fn to_le_bytes(self) -> [u8; 32]
pub fn to_le_bytes(self) -> [u8; 32]
Serializes to little endian bytes