tc_modular 0.1.0

Modular arithmetic and Montgomery forms for cryptography over the integers of tc_bigint, constant time over the fixed-width and padded ones.
Documentation
//! The signed digit of safegcd, sized to the word: 62 bits in `i64` on
//! 64-bit targets and 30 bits in `i32` otherwise, two bits short of the
//! word, with products in the type twice as wide.

use tc_bigint::Word;

#[cfg(target_pointer_width = "64")]
/// One signed digit, of [`DIGIT_BITS`] bits but the top one, which keeps
/// the sign and whatever lies above.
pub(crate) type Digit = i64;
#[cfg(not(target_pointer_width = "64"))]
/// One signed digit, of [`DIGIT_BITS`] bits but the top one, which keeps
/// the sign and whatever lies above.
pub(crate) type Digit = i32;

#[cfg(target_pointer_width = "64")]
/// Twice the width of [`Digit`], for products and carries.
pub(super) type WideDigit = i128;
#[cfg(not(target_pointer_width = "64"))]
/// Twice the width of [`Digit`], for products and carries.
pub(super) type WideDigit = i64;

/// The bits a digit holds below the top one.
pub(super) const DIGIT_BITS: u32 = Word::BITS - 2;

// A digit is as wide as the word, so that one converts to the other.
const _: () = assert!(Digit::BITS == Word::BITS);