ring/
arithmetic.rs

1// Copyright 2017-2023 Brian Smith.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15pub(crate) use self::{constant::limbs_from_hex, limb_slice_error::LimbSliceError};
16use crate::{error::LenMismatchError, limb::LIMB_BITS};
17
18#[macro_use]
19mod ffi;
20
21mod constant;
22
23#[cfg(feature = "alloc")]
24pub mod bigint;
25
26pub(crate) mod inout;
27mod limbs;
28mod limbs512;
29pub mod montgomery;
30
31mod n0;
32
33// The minimum number of limbs allowed for any `&[Limb]` operation.
34//
35// TODO: Use `256 / LIMB_BITS` so that the limit is independent of limb size.
36pub const MIN_LIMBS: usize = 4;
37
38// The maximum number of limbs allowed for any `&[Limb]` operation.
39pub const MAX_LIMBS: usize = 8192 / LIMB_BITS;
40
41cold_exhaustive_error! {
42    enum limb_slice_error::LimbSliceError {
43        len_mismatch => LenMismatch(LenMismatchError),
44        too_short => TooShort(usize),
45        too_long => TooLong(usize),
46    }
47}