clock_bigint/
lib.rs

1//! # clock-bigint
2//!
3//! Deterministic constant-time big integers for blockchain consensus engines.
4//!
5//! This crate implements the ClockinChain Big Integer specifications:
6//! - Representation Specification v1.0
7//! - Arithmetic Algorithm Specification v1.0
8//! - Montgomery & Modular Exponentiation Specification v1.0
9//! - Gas Schedule Specification v1.0
10//!
11//! ## Features
12//!
13//! - **Deterministic**: Bit-for-bit identical results across all platforms
14//! - **Constant-time**: All operations execute in constant time to prevent timing attacks
15//! - **Canonical encoding**: Unique representation for each integer value
16//! - **Gas metering**: Precomputable gas costs for VM execution
17//! - **Montgomery arithmetic**: Full support for cryptographic operations
18//!
19//! ## Example
20//!
21//! ```rust
22//! use clock_bigint::U256;
23//!
24//! let a = U256::from_u64(10);
25//! let b = U256::from_u64(20);
26//! // Operations will be implemented...
27//! ```
28
29#![no_std]
30#![warn(missing_docs)]
31#![warn(clippy::all)]
32
33#[cfg(feature = "alloc")]
34extern crate alloc;
35
36pub mod ct;
37pub mod error;
38pub mod gas;
39pub mod limbs;
40pub mod types;
41
42#[cfg(feature = "alloc")]
43pub mod add;
44#[cfg(feature = "alloc")]
45pub mod div;
46#[cfg(feature = "alloc")]
47pub mod encode;
48#[cfg(feature = "alloc")]
49pub mod modexp;
50#[cfg(feature = "alloc")]
51pub mod montgomery;
52#[cfg(feature = "alloc")]
53pub mod mul;
54#[cfg(feature = "alloc")]
55pub mod sub;
56#[cfg(feature = "alloc")]
57pub mod timeboxed;
58
59#[cfg(feature = "zk")]
60pub mod zk;
61
62// Re-export commonly used types
63pub use error::{BigIntError, Result};
64pub use gas::{G_BASE, Gas, MAX_LIMBS};
65pub use limbs::{Limb, WideLimb};
66#[cfg(feature = "alloc")]
67pub use types::BigInt;
68pub use types::{BigIntCore, BigIntFixed, U256, U512, U1024, U2048};
69
70// Re-export arithmetic operations
71#[cfg(feature = "alloc")]
72pub use add::{add, add_assign, add_magnitude};
73#[cfg(feature = "alloc")]
74pub use div::{div, div_assign, div_rem, rem, rem_assign};
75#[cfg(feature = "alloc")]
76pub use mul::{mul, mul_assign, sqr};
77#[cfg(feature = "alloc")]
78pub use sub::{sub, sub_assign, sub_magnitude};
79
80// Re-export encoding operations
81#[cfg(feature = "alloc")]
82pub use encode::{decode, encode};
83
84// Re-export Montgomery operations
85#[cfg(feature = "alloc")]
86pub use modexp::mod_pow;
87#[cfg(feature = "alloc")]
88pub use montgomery::{
89    MontgomeryContext, from_mont, mont_add, mont_mul, mont_reduce, mont_sub, to_mont,
90};
91
92// Re-export timeboxed operations
93#[cfg(feature = "alloc")]
94pub use timeboxed::{modexp_timeboxed, mul_timeboxed, resume};
95#[cfg(feature = "alloc")]
96pub use timeboxed::{ContinuationState, OpType, PartialResult};
97
98#[cfg(feature = "zk")]
99pub use zk::{ZKBackend, ZKBigInt};