tc_bigint
Big integers for cryptography in three kinds, each unsigned and signed:
fixed-width on the stack, padded to a width chosen at run time, and arbitrary
precision. no_std, no unsafe, Rust 1.85 or later.
Types
FixedBigUint<N>,FixedBigInt<N>—Nlimbs on the stack, constant time, no allocator.PaddedBigUint,PaddedBigInt(alloc) — a width chosen when built, on the heap, constant time.BigUint,BigInt(alloc) — as many limbs as the value takes, variable time, for public values.Limb,LimbArray<N>,Word,WideWord— the storage, a 64-bit word on 64-bit targets and 32-bit otherwise.ConversionError,ParseBigIntError— a value that does not fit, and text that does not parse.
Traits
- Operators — with an integer or a
u32on the right, panicking on overflow in every build. num-traits—Zero,One,Num, checked, wrapping, saturating and overflowing arithmetic,Pow,Euclid,Signed,Unsigned, andBoundedon the fixed-width types.BitOps,Gcd,ArrayEncoding— bit access, greatest common divisors, and encoding to and from words or bytes.RandomBits,RandomRange(rand_core) — random values below a power of two or in a range.ConstantTimeEq,ConstantTimeOrd,ConditionallySelectable,Zeroize— fromtc_constant_timeandtc_zeroize.
Features
alloc(off by default) — the padded and big types.rand_core(off by default) — random integers from arand_coregenerator.
Usage
use ;
type U256 = 256 / BITS as usize }>;
let x = U256from;
let y = &x * &x + 7u32;
assert_eq!;
Benchmarks of the three kinds are in BENCHES.md.
Security
Constant time covers the fixed-width and padded types; the big ones are for public values only, and every method states which it is. The constant-time types wipe the working values they give up; the values they hand back are the caller's to wipe. This is a learning port with no independent security audit.
License
Licensed under either the MIT license or the Apache License, Version 2.0, at your option.