bigint: Remove Nonnegative
.
Inline and simplify the logic into the one test-only function that uses it.
This commit is contained in:
parent
fbb8cf62f5
commit
6c29bf61cd
@ -20,9 +20,6 @@ pub mod bigint;
|
||||
pub mod montgomery;
|
||||
mod n0;
|
||||
|
||||
#[cfg(all(test, feature = "alloc"))]
|
||||
mod nonnegative;
|
||||
|
||||
#[allow(dead_code)]
|
||||
const BIGINT_MODULUS_MAX_LIMBS: usize = 8192 / crate::limb::LIMB_BITS;
|
||||
|
||||
|
@ -773,7 +773,7 @@ prefixed_extern! {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::nonnegative::Nonnegative, *};
|
||||
use super::*;
|
||||
use crate::test;
|
||||
|
||||
// Type-level representation of an arbitrary modulus.
|
||||
@ -923,9 +923,10 @@ mod tests {
|
||||
name: &str,
|
||||
num_limbs: usize,
|
||||
) -> Elem<M, Unencoded> {
|
||||
let value = consume_nonnegative(test_case, name);
|
||||
let bytes = test_case.consume_bytes(name);
|
||||
let mut limbs = BoxedLimbs::zero(num_limbs);
|
||||
limbs[0..value.limbs().len()].copy_from_slice(value.limbs());
|
||||
limb::parse_big_endian_and_pad_consttime(untrusted::Input::from(&bytes), &mut limbs)
|
||||
.unwrap();
|
||||
Elem {
|
||||
limbs,
|
||||
encoding: PhantomData,
|
||||
@ -941,13 +942,6 @@ mod tests {
|
||||
OwnedModulus::from_be_bytes(untrusted::Input::from(&value), cpu_features).unwrap()
|
||||
}
|
||||
|
||||
fn consume_nonnegative(test_case: &mut test::TestCase, name: &str) -> Nonnegative {
|
||||
let bytes = test_case.consume_bytes(name);
|
||||
let (r, _r_bits) =
|
||||
Nonnegative::from_be_bytes_with_bit_length(untrusted::Input::from(&bytes)).unwrap();
|
||||
r
|
||||
}
|
||||
|
||||
fn assert_elem_eq<M, E>(a: &Elem<M, E>, b: &Elem<M, E>) {
|
||||
if elem_verify_equal_consttime(a, b).is_err() {
|
||||
panic!("{:x?} != {:x?}", &*a.limbs, &*b.limbs);
|
||||
|
@ -1,44 +0,0 @@
|
||||
// Copyright 2015-2023 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
use crate::{
|
||||
bits, error,
|
||||
limb::{self, Limb, LIMB_BYTES},
|
||||
};
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
/// Nonnegative integers.
|
||||
pub(crate) struct Nonnegative {
|
||||
limbs: Vec<Limb>,
|
||||
}
|
||||
|
||||
impl Nonnegative {
|
||||
pub fn from_be_bytes_with_bit_length(
|
||||
input: untrusted::Input,
|
||||
) -> Result<(Self, bits::BitLength), error::Unspecified> {
|
||||
let mut limbs = vec![0; (input.len() + LIMB_BYTES - 1) / LIMB_BYTES];
|
||||
// Rejects empty inputs.
|
||||
limb::parse_big_endian_and_pad_consttime(input, &mut limbs)?;
|
||||
while limbs.last() == Some(&0) {
|
||||
let _ = limbs.pop();
|
||||
}
|
||||
let r_bits = limb::limbs_minimal_bits(&limbs);
|
||||
Ok((Self { limbs }, r_bits))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn limbs(&self) -> &[Limb] {
|
||||
&self.limbs
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user