Module validation

Module validation 

Source
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:

§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)).