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
// SPDX-FileCopyrightText: 2026 John Moxley
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Naive repeated-multiply integer power algorithm.
//!
//! `pow_schoolbook` is the naive reference exponentiation algorithm for
//! [`crate::int::policy::pow`]. It computes `base^exp` modulo `2^BITS` by
//! performing `exp - 1` sequential multiplications of the accumulator by
//! `base`, starting from `base` itself (or 1 for `exp == 0`).
//!
//! This is the naive reference: O(exp) multiplications. The optimised
//! production algorithm
//! [`crate::int::algos::pow::pow_square_and_multiply::pow_square_and_multiply`]
//! uses binary exponentiation by squaring (O(log exp) multiplications) --
//! but the two are numerically identical modulo `2^BITS`.
//!
//! Per the layering rule (see `docs/ARCHITECTURE.md` -> "Layering
//! direction"), the algorithm computes via the const KERNEL
//! [`crate::int::algos::mul::mul_schoolbook::mul_low_fixed`] -- it never calls
//! `pow`/`wrapping_pow`/`wrapping_mul`/`wrapping_sqr` methods back on
//! its own type.
use cratemul_low_fixed;
use crateUint;
/// Naive repeated-multiply integer power for `Uint<N>`: `base^exp` modulo
/// `2^BITS`; `base^0 == 1`.
///
/// Performs `exp - 1` sequential multiplications of an accumulator by
/// `base` via the const [`mul_low_fixed`] kernel: `acc = base`, then
/// `acc = acc * base` repeated `exp - 1` times. For `exp == 0` returns 1
/// directly (no multiplications). `const fn`, matching the const-ness of
/// the production algorithm.
pub const