BigInt
Source: std/bigint.mw.
Unsigned big integers on 32-bit limbs, enough for RSA and the elliptic curves used by TLS. Operations allocate their result.
Arbitrary-precision unsigned integers (little-endian 32-bit limbs) with the modular arithmetic needed for RSA and elliptic curves. Every function that returns a *Big returns a fresh value the caller releases with big_free. Reduction is shift-and-subtract: simple and constant-memory, adequate for signature *verification* (public data); it is not constant time.
struct Big { d: *u32; n: i64;}Functions
Section titled “Functions”big_alloc
Section titled “big_alloc”fn big_alloc(n: i64) -> *Bigbig_free
Section titled “big_free”fn big_free(b: *Big)big_trim
Section titled “big_trim”fn big_trim(b: *Big)big_from_u64
Section titled “big_from_u64”fn big_from_u64(v: u64) -> *Bigbig_copy
Section titled “big_copy”fn big_copy(a: *Big) -> *Bigbig_from_bytes
Section titled “big_from_bytes”fn big_from_bytes(p: *u8, len: i64) -> *Bigbig_to_bytes
Section titled “big_to_bytes”fn big_to_bytes(a: *Big, out: *u8, len: i64) -> boolWrites a big-endian, left-padded with zeros to exactly len bytes. Returns false if it does not fit.
big_is_zero
Section titled “big_is_zero”fn big_is_zero(a: *Big) -> boolbig_bits
Section titled “big_bits”fn big_bits(a: *Big) -> i64big_bit
Section titled “big_bit”fn big_bit(a: *Big, i: i64) -> i64big_is_odd
Section titled “big_is_odd”fn big_is_odd(a: *Big) -> boolbig_cmp
Section titled “big_cmp”fn big_cmp(a: *Big, b: *Big) -> i64big_add
Section titled “big_add”fn big_add(a: *Big, b: *Big) -> *Bigbig_sub
Section titled “big_sub”fn big_sub(a: *Big, b: *Big) -> *Biga - b, requires a >= b.
big_mul
Section titled “big_mul”fn big_mul(a: *Big, b: *Big) -> *Bigbig_mod
Section titled “big_mod”fn big_mod(a: *Big, m: *Big) -> *Biga mod m (m > 0).
big_modmul
Section titled “big_modmul”fn big_modmul(a: *Big, b: *Big, m: *Big) -> *Bigbig_modadd
Section titled “big_modadd”fn big_modadd(a: *Big, b: *Big, m: *Big) -> *Bigbig_modsub
Section titled “big_modsub”fn big_modsub(a: *Big, b: *Big, m: *Big) -> *Big(a - b) mod m for a, b < m.
big_modexp
Section titled “big_modexp”fn big_modexp(base: *Big, exp: *Big, m: *Big) -> *Bigbig_modinv_prime
Section titled “big_modinv_prime”fn big_modinv_prime(a: *Big, p: *Big) -> *Biga^-1 mod p for prime p (Fermat).