pub struct Scalar(/* private fields */);Expand description
P-224 scalar value for use in elliptic curve operations
Represents integers modulo the curve order n. Used for private keys and scalar multiplication. Automatically zeroized on drop for security.
Implementations§
Source§impl Scalar
impl Scalar
Sourcepub fn new(data: [u8; 28]) -> Result<Self>
pub fn new(data: [u8; 28]) -> Result<Self>
Create a canonical non-zero scalar from raw bytes.
Private keys, nonces, and serialized signature components must be in
1..n. Non-canonical inputs are rejected rather than reduced.
Sourcepub fn from_bytes_reduced(data: [u8; 28]) -> Self
pub fn from_bytes_reduced(data: [u8; 28]) -> Self
Interpret a 224-bit integer modulo the group order, including zero.
This constructor is intended for standards-defined mathematical
intermediates such as ECDSA hash and x-coordinate reduction. Use
Self::new for private scalars, nonces, and serialized signature
components, where zero is invalid.
Sourcepub fn from_secret_buffer(
buffer: SecretBuffer<P224_SCALAR_SIZE>,
) -> Result<Self>
pub fn from_secret_buffer( buffer: SecretBuffer<P224_SCALAR_SIZE>, ) -> Result<Self>
Create a scalar from an existing SecretBuffer
Performs the same canonical validation as new() but starts
from a SecretBuffer instead of a raw byte array.
Sourcepub fn as_secret_buffer(&self) -> &SecretBuffer<P224_SCALAR_SIZE>
pub fn as_secret_buffer(&self) -> &SecretBuffer<P224_SCALAR_SIZE>
Access the underlying SecretBuffer containing the scalar value
Sourcepub fn serialize(&self) -> SecretBuffer<P224_SCALAR_SIZE>
pub fn serialize(&self) -> SecretBuffer<P224_SCALAR_SIZE>
Serialize the scalar to protected exact-size storage.
Returns the scalar in big-endian byte representation. The output clears itself on drop. Callers that deliberately expose a public signature component may copy from its borrowed slice.
Sourcepub fn deserialize(bytes: &[u8]) -> Result<Self>
pub fn deserialize(bytes: &[u8]) -> Result<Self>
Deserialize a scalar from bytes with validation
Parses bytes as a big-endian scalar value and ensures it’s in the valid range for P-224 operations.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Check if the scalar represents zero
Constant-time check to determine if the scalar is the additive identity (which is invalid for most cryptographic operations).
Sourcepub fn sub_mod_n(&self, other: &Self) -> Result<Self>
pub fn sub_mod_n(&self, other: &Self) -> Result<Self>
Subtract two scalars modulo the curve order n
Sourcepub fn mul_mod_n(&self, other: &Self) -> Result<Self>
pub fn mul_mod_n(&self, other: &Self) -> Result<Self>
Multiply two scalars modulo the curve order n
Uses constant-time double-and-add algorithm for correctness and security. Processes bits from MSB to LSB to ensure correct powers of 2.