#[non_exhaustive]pub enum BigIntError {
Overflow,
InvalidEncoding,
DivisionByZero,
InvalidModulus,
InvalidState,
}Expand description
Errors that can occur during BigInt operations.
All variants are designed to be constant-time and provide minimal information to prevent side-channel attacks while still being useful for debugging.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Overflow
Operation would exceed the maximum capacity.
This error occurs when a BigInt operation would require more limbs than the configured maximum capacity. This prevents unbounded memory allocation and ensures constant-time behavior.
§Examples
use clock_bigint::{BigInt, add_magnitude};
// Create BigInts with values that need 1 limb each
let a = BigInt::from_u64(u64::MAX, 10);
let b = BigInt::from_u64(u64::MAX, 10);
// Try to add into a result with insufficient capacity (only 1 limb max)
let mut result = BigInt::new(1); // Only 1 limb capacity
let add_result = add_magnitude(&a, &b, &mut result);
assert!(add_result.is_err());InvalidEncoding
Invalid encoding detected (non-canonical form).
This error occurs when attempting to decode malformed or non-canonical binary representations of BigInt values. The encoding format requires specific structure and canonical forms for security and correctness.
§Examples
use clock_bigint::BigInt;
// Empty data cannot be decoded
let result = clock_bigint::decode(&[]);
assert!(matches!(result, Err(clock_bigint::BigIntError::InvalidEncoding)));
// Invalid length prefix
let invalid_data = vec![0u8; 10]; // Too short for valid encoding
let result = clock_bigint::decode(&invalid_data);
assert!(matches!(result, Err(clock_bigint::BigIntError::InvalidEncoding)));DivisionByZero
Division by zero attempted.
This error occurs when attempting to divide by zero or compute modulo zero. These operations are mathematically undefined.
§Examples
use clock_bigint::{BigInt, div};
let a = BigInt::from_u64(10, 10);
let zero = BigInt::from_u64(0, 10);
// Division by zero
let result = div(&a, &zero);
assert!(matches!(result, Err(clock_bigint::BigIntError::DivisionByZero)));InvalidModulus
Invalid modulus for Montgomery arithmetic.
This error occurs when attempting to use Montgomery arithmetic with an unsupported modulus. Montgomery operations require the modulus to be odd and non-zero for the algorithms to work correctly.
§Examples
use clock_bigint::{BigInt, MontgomeryContext};
let even_modulus = BigInt::from_u64(10, 10); // Even modulus
// Creating Montgomery context with even modulus fails
let result = MontgomeryContext::new(even_modulus);
assert!(matches!(result, Err(clock_bigint::BigIntError::InvalidModulus)));
let zero_modulus = BigInt::from_u64(0, 10); // Zero modulus
let result = MontgomeryContext::new(zero_modulus);
assert!(matches!(result, Err(clock_bigint::BigIntError::InvalidModulus)));InvalidState
Invalid internal state.
This error occurs when an operation is attempted but the BigInt is in an invalid internal state, such as having non-canonical representation when canonical form is required.
§Examples
use clock_bigint::BigInt;
let mut bi = BigInt::from_u64(10, 10);
// Manually corrupt internal state (normally not possible through public API)
// This would cause InvalidState if the corruption were detectedTrait Implementations§
Source§impl Clone for BigIntError
impl Clone for BigIntError
Source§fn clone(&self) -> BigIntError
fn clone(&self) -> BigIntError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more