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
// SPDX-FileCopyrightText: 2026 John Moxley
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Naive schoolbook integer squaring algorithm.
//!
//! `sqr_schoolbook` is the naive reference squaring algorithm for
//! [`crate::int::policy::sqr`]. It computes `x²` modulo `2^BITS` for an
//! `N`-limb value by treating squaring as a general `x·x` multiply via
//! the const truncated kernel
//! [`crate::int::algos::mul::mul_schoolbook::mul_low_fixed`].
//!
//! This is the naive reference: every partial product `x_i·x_j` (including
//! symmetric cross terms) is formed separately. The optimised production
//! algorithm [`crate::int::algos::sqr::sqr_half_product::sqr_half_product`] halves
//! the limb-multiply count by exploiting symmetry — but the two are
//! bit-identical on the low `N` limbs.
//!
//! Per the layering rule (see `docs/ARCHITECTURE.md` → "Layering
//! direction"), the algorithm computes via the const KERNEL — it never
//! calls a squaring method back on its own type.
use cratemul_low_fixed;
use crateUint;
/// Naive schoolbook integer square for `Uint<N>`: `x²` modulo `2^BITS`.
///
/// Delegates directly to [`mul_low_fixed`] with both operands set to `x`,
/// forming the full `N×N` outer product and retaining only the low `N`
/// limbs. Bit-identical to [`crate::int::algos::sqr::sqr_half_product::sqr_half_product`];
/// slower by roughly 2× because symmetric cross terms are formed twice.
/// `const fn`, matching the const-ness of the production algorithm.
pub const