Expand description
Input validation utilities for clock-curve-math.
This module provides comprehensive validation functions for all public APIs to ensure inputs are within valid ranges and prevent invalid operations.
§Validation Functions
The validation functions check that inputs conform to the mathematical constraints of the cryptographic primitives:
- Field elements must be in the range [0, p) where p = 2^255 - 19
- Scalars must be in the range [0, l) where l = 2^252 + 27_742_317_777_372_353_535_851_937_790_883_648_493
- Exponents must be non-negative (though BigInt always represents non-negative values)
- Moduli must be positive and non-zero
- Buffers must have the correct size for the operation
§Error Conditions
All validation functions return MathError variants that precisely
describe the validation failure:
MathError::InvalidFieldElement: Value not in [0, p)MathError::InvalidScalar: Value not in [0, l)MathError::InvalidExponent: Negative exponent providedMathError::InvalidModulus: Zero or negative modulusMathError::BufferTooSmall: Input buffer smaller than requiredMathError::BufferTooLarge: Input buffer larger than required
§Usage
use clock_curve_math::validation::*;
// Validate a field element byte representation
let bytes = [42u8; 32];
assert!(validate_field_bytes(&bytes).is_ok());
// Validate a scalar BigInt value
let scalar_value = clock_curve_math::BigInt::from_u64(12345);
assert!(validate_scalar_bigint(&scalar_value).is_ok());Functions§
- validate_
buffer_ size - Validate buffer size for byte array operations.
- validate_
exponent - Validate that a BigInt is a valid exponent for modular exponentiation.
- validate_
field_ bigint - Validate that a BigInt represents a valid field element (in [0, p)).
- validate_
field_ bytes - Validate that a byte array represents a valid field element (in [0, p)).
- validate_
modulus - Validate that a BigInt is a valid modulus for modular operations.
- validate_
non_ zero - Validate that a value is not zero (for operations that require non-zero inputs).
- validate_
scalar_ bigint - Validate that a BigInt represents a valid scalar (in [0, l)).
- validate_
scalar_ bytes - Validate that a byte array represents a valid scalar (in [0, l)).