Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 1 addition & 49 deletions p521/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use self::scalar_impl::*;
use crate::{FieldBytes, NistP521, U576};
use core::{
iter::{Product, Sum},
ops::{Add, AddAssign, Mul, MulAssign, Neg, Shr, ShrAssign, SubAssign},
ops::{Add, AddAssign, Mul, MulAssign, Neg, SubAssign},
};
use elliptic_curve::{
Curve as _, Error, FieldBytesEncoding, Result,
Expand Down Expand Up @@ -305,32 +305,6 @@ impl Scalar {
res
}

/// Right shifts the scalar.
///
/// Note: not constant-time with respect to the `shift` parameter.
#[cfg(target_pointer_width = "32")]
pub const fn shr_vartime(&self, shift: u32) -> Scalar {
Self(fiat_p521_scalar_montgomery_domain_field_element(
u32x18_to_u64x9(
&U576::from_words(u64x9_to_u32x18(self.as_limbs()))
.wrapping_shr_vartime(shift)
.to_words(),
),
))
}

/// Right shifts the scalar.
///
/// Note: not constant-time with respect to the `shift` parameter.
#[cfg(target_pointer_width = "64")]
pub const fn shr_vartime(&self, shift: u32) -> Scalar {
Self(fiat_p521_scalar_montgomery_domain_field_element(
U576::from_words(self.into_limbs())
.wrapping_shr_vartime(shift)
.to_words(),
))
}

/// Borrow the inner limbs of this scalar.
pub(crate) const fn as_limbs(&self) -> &[u64; 9] {
&self.0.0
Expand Down Expand Up @@ -551,28 +525,6 @@ impl IsHigh for Scalar {
}
}

impl Shr<usize> for Scalar {
type Output = Self;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs as u32)
}
}

impl Shr<usize> for &Scalar {
type Output = Scalar;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs as u32)
}
}

impl ShrAssign<usize> for Scalar {
fn shr_assign(&mut self, rhs: usize) {
*self = *self >> rhs;
}
}

impl PrimeField for Scalar {
type Repr = FieldBytes;

Expand Down
66 changes: 0 additions & 66 deletions primefield/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,6 @@ macro_rules! field_element_type {

res
}

/// Right shifts the [`
#[doc = stringify!($fe)]
/// `].
pub const fn shr(&self, shift: u32) -> Self {
Self(self.0.wrapping_shr(shift))
}

/// Right shifts the [`
#[doc = stringify!($fe)]
/// `].
///
/// Note: not constant-time with respect to the `shift` parameter.
pub const fn shr_vartime(&self, shift: u32) -> Self {
Self(self.0.wrapping_shr_vartime(shift))
}
}

impl $crate::ff::Field for $fe {
Expand Down Expand Up @@ -323,56 +307,6 @@ macro_rules! field_element_type {
}
}

impl ::core::ops::Shr<u32> for $fe {
type Output = Self;

#[inline]
fn shr(self, rhs: u32) -> Self {
Self::shr(&self, rhs)
}
}

impl ::core::ops::Shr<u32> for &$fe {
type Output = Self;

#[inline]
fn shr(self, rhs: u32) -> Self {
Self::shr(self, rhs)
}
}

impl ::core::ops::ShrAssign<u32> for $fe {
#[inline]
fn shr_assign(&mut self, rhs: u32) {
*self = Self::shr(self, rhs)
}
}

impl ::core::ops::Shr<usize> for $fe {
type Output = Self;

#[inline]
fn shr(self, rhs: usize) -> Self {
Self::shr(&self, rhs as u32)
}
}

impl ::core::ops::Shr<usize> for &$fe {
type Output = Self;

#[inline]
fn shr(self, rhs: usize) -> Self {
Self::shr(self, rhs as u32)
}
}

impl ::core::ops::ShrAssign<usize> for $fe {
#[inline]
fn shr_assign(&mut self, rhs: usize) {
*self = Self::shr(self, rhs as u32)
}
}

impl ::core::fmt::Debug for $fe {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
write!(f, "{}(0x{:X})", stringify!($fe), &self.0)
Expand Down