Expand description
Provides various number types, including small primitive-based integers, memory-sharing integer unions, and fixed-size big integers.
§Introduction
This module defines the foundational numeric types used throughout the
cryptocol ecosystem, categorized by their size and intended use:
- Small Numbers: Primitive-sized integers (up to 128-bit) and specialized unions for bit manipulation.
- Big Numbers: High-precision, fixed-size unsigned integers designed for cryptographic operations.
§Architectural Background
§Generic Programming for Primitives
Rust lacks a unified trait for all primitive numeric types (e.g., u8
through u128, usize). The SmallUInt trait provides this abstraction,
enabling the implementation of generic algorithms across unsigned primitive
types.
§Extended Primitive Functionality
Beyond standard arithmetic, SmallUInt introduces auxiliary methods for
common cryptographic and low-level tasks not natively provided by Rust
primitives.
§Arithmetic for Big Numbers
Cryptographic algorithms, such as RSA, require integers far exceeding the 128-bit limit of standard types. This module provides highly optimized algorithms for calculating 256-bit, 1024-bit, and even larger integers.
§Documentation Policy
Parts of the documentation for this module are adapted from the Rust
standard library. This applies specifically to methods that implement
standard operations (e.g., arithmetic operators, from_str, to_be) to
maintain consistency with familiar interfaces and semantics.
§1. Small Numbers
Foundational types for Big Numbers and other cryptographic modules.
SmallUInt: Trait providing a generic interface and additional methods for unsigned primitive integers.
§Integer Unions
Unions designed for efficient type conversion and byte-level manipulation between different integer sizes and arrays.
ShortUnion: Interop betweenu16,i16,[u8; 2], and[i8; 2].IntUnion: Interop betweenu32,i32, and 16/8-bit components.LongUnion: Interop betweenu64,i64, and 32/16/8-bit components.LongerUnion: Interop betweenu128,i128, and 64/32/16/8-bit components.SizeUnion: Interop betweenusize,isize, and platform-dependent components.SharedValues: Memory-sharing for cross-type truncation or zero-filling.SharedArrays: Memory-sharing for cross-type array conversions.
§2. Big Numbers
Essential for Asymmetric-Key Algorithms and high-precision calculations.
BigUInt: Fixed-size big unsigned integers with user-defined bit-widths.BigUInt_More: Auxiliary methods for advanced calculations.BigUInt_Modular: Specialized modular arithmetic operations.BigUInt_Panic_Free: Safe, non-panicking arithmetic operations.BigUInt_Prime: Methods for primality testing and generation.
§Predefined Big Unsigned Types
Commonly used bit-widths are available as aliases:
U256,U512,U1024,U2048,U3072,U4096,U5120,U6144,U7168,U8192, andU16384.- Synonyms like
UU32(256-bit) throughUU2048(16384-bit) are also provided.
§Quick Start
- For
SmallUInt, see here. - For integer unions, see their respective
#quick-startsections (e.g.,ShortUnion#quick-start). - For
BigUInt, see here.
Modules§
- big_
uint_ arithmetic - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_arithmetic.rs. - big_
uint_ arithmetic_ uint - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_arithmetic_uint.rs. - big_
uint_ basic_ operation - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_basic_operation.rs. - big_
uint_ binary_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_binary_impl.rs. - big_
uint_ display_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_display_impl.rs. - big_
uint_ lowerexp_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_lowerexp_impl.rs. - big_
uint_ lowerhex_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_lowerhex_impl.rs. - big_
uint_ modular - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_modular.rs. - big_
uint_ more - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_more.rs. - big_
uint_ octal_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to pub mod big_uint_octal_impl.rs. - big_
uint_ other_ calculation - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_other_calculation.rs. - big_
uint_ other_ calculation_ uint - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_other_calculation_uint.rs. - big_
uint_ panic_ free - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_panic_free.rs. - big_
uint_ pointer_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_pointer_impl.rs. - big_
uint_ prime - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_prime.rs. - big_
uint_ shift_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_shift_impl.rs. - big_
uint_ traits_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_traits_impl.rs. - big_
uint_ traits_ impl_ uint - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_traits_impl_uint.rs. - big_
uint_ upperexp_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_upperexp_impl.rs. - big_
uint_ upperhex_ impl - big_uint.rs was too big because of documentation and plenty of examples
So, in order to provide documentation without
docs.rs’s failing generating documentation, dummy codes were made and documentation and examples were moved to big_uint_upperhex_impl.rs.
Structs§
- BigUInt
- A Generic Fixed-Size Big Unsigned Integer
Enums§
- Number
Err - In operation of BigUInt, BigInt, and LargeInt, errors can occur. In this
case, the enumerator
NumberErrwill indicate what kind of error occurred.
Traits§
- BigU
Int_ Modular - Introduction
- BigU
Int_ More - Introduction
- BigU
Int_ Panic_ Free - Introduction
- BigU
Int_ Prime - Introduction
- SmallS
Int - For generic type of primitive signed integral data types for the counter part of uint.
- SmallU
Int - Introduction
Type Aliases§
- U256_
with_ u8 - 256-bit unsigned integer implemented as
BigUInt<u8, 32>(comprising 32 xu8). - U256_
with_ u16 - 256-bit unsigned integer implemented as
BigUInt<u16, 16>(comprising 16 xu16). - U256_
with_ u32 - 256-bit unsigned integer implemented as
BigUInt<u32, 8>(comprising 8 xu32). - U256_
with_ u64 - 256-bit unsigned integer implemented as
BigUInt<u64, 4>(comprising 4 xu64). - U256_
with_ u128 - 256-bit unsigned integer implemented as
BigUInt<u128, 2>(comprising 2 xu128). - U384_
with_ u8 - 384-bit unsigned integer implemented as
BigUInt<u8, 48>(comprising 48 xu8). - U384_
with_ u16 - 384-bit unsigned integer implemented as
BigUInt<u16, 24>(comprising 24 xu16). - U384_
with_ u32 - 384-bit unsigned integer implemented as
BigUInt<u32, 12>(comprising 12 xu32). - U384_
with_ u64 - 384-bit unsigned integer implemented as
BigUInt<u64, 6>(comprising 6 xu64). - U384_
with_ u128 - 384-bit unsigned integer implemented as
BigUInt<u128, 3>(comprising 3 xu128). - U512_
with_ u8 - 512-bit unsigned integer implemented as
BigUInt<u8, 64>(comprising 64 xu8). - U512_
with_ u16 - 512-bit unsigned integer implemented as
BigUInt<u16, 32>(comprising 32 xu16). - U512_
with_ u32 - 512-bit unsigned integer implemented as
BigUInt<u32, 16>(comprising 16 xu32). - U512_
with_ u64 - 512-bit unsigned integer implemented as
BigUInt<u64, 8>(comprising 8 xu64). - U512_
with_ u128 - 512-bit unsigned integer implemented as
BigUInt<u128, 4>(comprising 4 xu128). - U768_
with_ u8 - 768-bit unsigned integer implemented as
BigUInt<u8, 96>(comprising 96 xu8). - U768_
with_ u16 - 768-bit unsigned integer implemented as
BigUInt<u16, 48>(comprising 48 xu16). - U768_
with_ u32 - 768-bit unsigned integer implemented as
BigUInt<u32, 24>(comprising 24 xu32). - U768_
with_ u64 - 768-bit unsigned integer implemented as
BigUInt<u64, 12>(comprising 12 xu64). - U768_
with_ u128 - 768-bit unsigned integer implemented as
BigUInt<u128, 6>(comprising 6 xu128). - U1024_
with_ u8 - 1024-bit unsigned integer implemented as
BigUInt<u8, 128>(comprising 128 xu8). - U1024_
with_ u16 - 1024-bit unsigned integer implemented as
BigUInt<u16, 64>(comprising 64 xu16). - U1024_
with_ u32 - 1024-bit unsigned integer implemented as
BigUInt<u32, 32>(comprising 32 xu32). - U1024_
with_ u64 - 1024-bit unsigned integer implemented as
BigUInt<u64, 16>(comprising 16 xu64). - U1024_
with_ u128 - 1024-bit unsigned integer implemented as
BigUInt<u128, 8>(comprising 8 xu128). - U2048_
with_ u8 - 2048-bit unsigned integer implemented as
BigUInt<u8, 256>(comprising 256 xu8). - U2048_
with_ u16 - 2048-bit unsigned integer implemented as
BigUInt<u16, 128>(comprising 128 xu16). - U2048_
with_ u32 - 2048-bit unsigned integer implemented as
BigUInt<u32, 64>(comprising 64 xu32). - U2048_
with_ u64 - 2048-bit unsigned integer implemented as
BigUInt<u64, 32>(comprising 32 xu64). - U2048_
with_ u128 - 2048-bit unsigned integer implemented as
BigUInt<u128, 16>(comprising 16 xu128). - U3072_
with_ u8 - 3072-bit unsigned integer implemented as
BigUInt<u8, 384>(comprising 384 xu8). - U3072_
with_ u16 - 3072-bit unsigned integer implemented as
BigUInt<u16, 192>(comprising 192 xu16). - U3072_
with_ u32 - 3072-bit unsigned integer implemented as
BigUInt<u32, 96>(comprising 96 xu32). - U3072_
with_ u64 - 3072-bit unsigned integer implemented as
BigUInt<u64, 48>(comprising 48 xu64). - U3072_
with_ u128 - 3072-bit unsigned integer implemented as
BigUInt<u128, 24>(comprising 24 xu128). - U4096_
with_ u8 - 4096-bit unsigned integer implemented as
BigUInt<u8, 512>(comprising 512 xu8). - U4096_
with_ u16 - 4096-bit unsigned integer implemented as
BigUInt<u16, 256>(comprising 256 xu16). - U4096_
with_ u32 - 4096-bit unsigned integer implemented as
BigUInt<u32, 128>(comprising 128 xu32). - U4096_
with_ u64 - 4096-bit unsigned integer implemented as
BigUInt<u64, 64>(comprising 64 xu64). - U4096_
with_ u128 - 4096-bit unsigned integer implemented as
BigUInt<u128, 32>(comprising 32 xu128). - U5120_
with_ u8 - 5120-bit unsigned integer implemented as
BigUInt<u8, 640>(comprising 640 xu8). - U5120_
with_ u16 - 5120-bit unsigned integer implemented as
BigUInt<u16, 320>(comprising 320 xu16). - U5120_
with_ u32 - 5120-bit unsigned integer implemented as
BigUInt<u32, 160>(comprising 160 xu32). - U5120_
with_ u64 - 5120-bit unsigned integer implemented as
BigUInt<u64, 80>(comprising 80 xu64). - U5120_
with_ u128 - 5120-bit unsigned integer implemented as
BigUInt<u128, 40>(comprising 40 xu128). - U6144_
with_ u8 - 6144-bit unsigned integer implemented as
BigUInt<u8, 768>(comprising 768 xu8). - U6144_
with_ u16 - 6144-bit unsigned integer implemented as
BigUInt<u16, 384>(comprising 384 xu16). - U6144_
with_ u32 - 6144-bit unsigned integer implemented as
BigUInt<u32, 192>(comprising 192 xu32). - U6144_
with_ u64 - 6144-bit unsigned integer implemented as
BigUInt<u64, 96>(comprising 96 xu64). - U6144_
with_ u128 - 6144-bit unsigned integer implemented as
BigUInt<u128, 48>(comprising 48 xu128). - U7168_
with_ u8 - 7168-bit unsigned integer implemented as
BigUInt<u8, 896>(comprising 896 xu8). - U7168_
with_ u16 - 7168-bit unsigned integer implemented as
BigUInt<u16, 448>(comprising 448 xu16). - U7168_
with_ u32 - 7168-bit unsigned integer implemented as
BigUInt<u32, 224>(comprising 224 xu32). - U7168_
with_ u64 - 7168-bit unsigned integer implemented as
BigUInt<u64, 112>(comprising 112 xu64). - U7168_
with_ u128 - 7168-bit unsigned integer implemented as
BigUInt<u128, 56>(comprising 56 xu128). - U8192_
with_ u8 - 8192-bit unsigned integer implemented as
BigUInt<u8, 1024>(comprising 1024 xu8). - U8192_
with_ u16 - 8192-bit unsigned integer implemented as
BigUInt<u16, 512>(comprising 512 xu16). - U8192_
with_ u32 - 8192-bit unsigned integer implemented as
BigUInt<u32, 256>(comprising 256 xu32). - U8192_
with_ u64 - 8192-bit unsigned integer implemented as
BigUInt<u64, 128>(comprising 128 xu64). - U8192_
with_ u128 - 8192-bit unsigned integer implemented as
BigUInt<u128, 64>(comprising 64 xu128). - U16384_
with_ u8 - 16384-bit unsigned integer implemented as
BigUInt<u8, 2048>(comprising 2048 xu8). - U16384_
with_ u16 - 16384-bit unsigned integer implemented as
BigUInt<u16, 1024>(comprising 1024 xu16). - U16384_
with_ u32 - 16384-bit unsigned integer implemented as
BigUInt<u32, 512>(comprising 512 xu32). - U16384_
with_ u64 - 16384-bit unsigned integer implemented as
BigUInt<u64, 256>(comprising 256 xu64). - U16384_
with_ u128 - 16384-bit unsigned integer implemented as
BigUInt<u128, 128>(comprising 128 xu128).
Unions§
- IntUnion
- A 32-bit integer union that enables bit-level slicing and seamless
conversion between various primitive types, including
u32,i32,u16,i16,u8, andi8. - Long
Union - A 64-bit integer union that enables bit-level slicing and seamless
conversion between various primitive types, including
u64,i64,u32,i32,u16,i16,u8, andi8. - Longer
Union - A 128-bit integer union that enables bit-level slicing and seamless
conversion between various primitive types, including
u128,i128,u64,i64,u32,i32,u16,i16,u8, andi8. - Shared
Arrays - union for transforming from an array of one type into another array of anther type
- Shared
Values - union for transforming from one type into anther type
- Short
Union - A 16-bit integer union that enables bit-level slicing and seamless
conversion between various primitive types, including
u16,i16,u8, andi8. - Size
Union - A pointer-sized integer union that enables bit-level slicing and seamless conversion between various primitive types, based on the system’s architecture.