1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Schoolbook modular arithmetic for `Copy`-bound types.
//!
//! Use this module when the operand type satisfies `T: Copy + ...` —
//! primitive integers (`u8`, `u16`, `u32`, `u64`, `u128`) and
//! stack-allocated bigints that impl `Copy`.
//!
//! For backends that don't impl `Copy`, see
//! [`modmath::constrained`](crate::constrained) (`Clone`-bound,
//! mixed value/reference parameters) or [`modmath::strict`](crate::strict)
//! (reference-based throughout).
//!
//! ## Pre-reduced variants
//!
//! [`pre_reduced`] re-exports `add` / `sub` / `mul` / `exp` siblings that
//! assume inputs are already in `[0, m)` and skip the `% m` reduction
//! step. Works for backends without `core::ops::Rem` and is the right
//! entry point inside loops where reduction is handled separately.
//! Note: `inv` has no pre-reduced sibling — modular inverse via the
//! extended Euclidean algorithm inside `inv` performs its own
//! magnitude-dependent loop, with no useful "pre-reduced" shortcut.
pub use cratebasic_mod_add as add;
pub use cratebasic_mod_exp as exp;
pub use cratebasic_mod_inv as inv;
pub use cratebasic_mod_mul as mul;
pub use cratebasic_mod_sub as sub;
/// Pre-reduced variants. Caller guarantees inputs are in `[0, m)`;
/// no `Rem` bound.
/// Non-zero-modulus variants. Caller provides `m: T::NonZero` (one
/// boundary-time `m.into_nonzero()?` proof); every `% m` reduction
/// inside collapses to `rem_nonzero` with no divide-by-zero panic
/// path when the carrier's `DivNonZero` impl elides the underlying
/// zero-check.