Skip to content

Commit 29556dd

Browse files
authored
primefield: field_element_type! now impls Invert (#1163)
The trait is sourced from `crypto-bigint`
1 parent b732fb3 commit 29556dd

File tree

5 files changed

+11
-37
lines changed

5 files changed

+11
-37
lines changed

bign256/src/arithmetic/field.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use crate::{BignP256, FieldBytes, U256};
3434
use elliptic_curve::{
3535
FieldBytesEncoding,
3636
ff::PrimeField,
37-
ops::Invert,
3837
subtle::{Choice, ConstantTimeEq, CtOption},
3938
};
4039

@@ -122,14 +121,6 @@ impl PrimeField for FieldElement {
122121
const DELTA: Self = Self::from_u64(4);
123122
}
124123

125-
impl Invert for FieldElement {
126-
type Output = CtOption<Self>;
127-
128-
fn invert(&self) -> CtOption<Self> {
129-
self.invert()
130-
}
131-
}
132-
133124
#[cfg(test)]
134125
mod tests {
135126
use super::FieldElement;

bign256/src/arithmetic/scalar.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use elliptic_curve::{
2121
Curve as _, Error, FieldBytesEncoding, Result, ScalarPrimitive,
2222
bigint::Limb,
2323
ff::PrimeField,
24-
ops::{Invert, Reduce},
24+
ops::Reduce,
2525
scalar::{FromUintUnchecked, IsHigh},
2626
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, CtOption},
2727
};
@@ -119,14 +119,6 @@ impl FromUintUnchecked for Scalar {
119119
}
120120
}
121121

122-
impl Invert for Scalar {
123-
type Output = CtOption<Self>;
124-
125-
fn invert(&self) -> CtOption<Self> {
126-
self.invert()
127-
}
128-
}
129-
130122
impl IsHigh for Scalar {
131123
fn is_high(&self) -> Choice {
132124
const MODULUS_SHR1: U256 = BignP256::ORDER.shr_vartime(1);

p384/src/arithmetic/field.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use elliptic_curve::{
2929
FieldBytesEncoding,
3030
bigint::U384,
3131
ff::PrimeField,
32-
ops::Invert,
3332
subtle::{Choice, ConstantTimeEq, CtOption},
3433
};
3534

@@ -137,14 +136,6 @@ impl PrimeField for FieldElement {
137136
}
138137
}
139138

140-
impl Invert for FieldElement {
141-
type Output = CtOption<Self>;
142-
143-
fn invert(&self) -> CtOption<Self> {
144-
self.invert()
145-
}
146-
}
147-
148139
#[cfg(test)]
149140
mod tests {
150141
use super::FieldElement;

p384/src/arithmetic/scalar.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use elliptic_curve::{
2828
Curve as _, Error, FieldBytesEncoding, Result, ScalarPrimitive,
2929
bigint::{ArrayEncoding, Limb},
3030
ff::PrimeField,
31-
ops::{Invert, Reduce, ReduceNonZero},
31+
ops::{Reduce, ReduceNonZero},
3232
scalar::{FromUintUnchecked, IsHigh},
3333
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, CtOption},
3434
};
@@ -172,14 +172,6 @@ impl FromUintUnchecked for Scalar {
172172
}
173173
}
174174

175-
impl Invert for Scalar {
176-
type Output = CtOption<Self>;
177-
178-
fn invert(&self) -> CtOption<Self> {
179-
self.invert()
180-
}
181-
}
182-
183175
impl IsHigh for Scalar {
184176
fn is_high(&self) -> Choice {
185177
const MODULUS_SHR1: U384 = NistP384::ORDER.shr_vartime(1);

primefield/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ mod fiat;
4343
/// - `pub fn sqrt`
4444
///
4545
/// # Trait impls
46-
/// - `AsRef<$arr>`
4746
/// - `ConditionallySelectable`
4847
/// - `ConstantTimeEq`
4948
/// - `ConstantTimeGreater`
@@ -64,6 +63,7 @@ mod fiat;
6463
/// - `Neg`
6564
/// - `Shr`
6665
/// - `ShrAssign`
66+
/// - `Invert`
6767
#[macro_export]
6868
macro_rules! field_element_type {
6969
(
@@ -393,6 +393,14 @@ macro_rules! field_element_type {
393393
}
394394
}
395395

396+
impl $crate::bigint::Invert for $fe {
397+
type Output = CtOption<Self>;
398+
399+
fn invert(&self) -> CtOption<Self> {
400+
self.invert()
401+
}
402+
}
403+
396404
impl $crate::subtle::ConditionallySelectable for $fe {
397405
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
398406
Self(<$uint>::conditional_select(&a.0, &b.0, choice))

0 commit comments

Comments
 (0)