Skip to content

Commit 300ce4f

Browse files
authored
Field element macro cleanups (RustCrypto#762)
- Renames `primeorder::impl_field_element` to `impl_mont_field_element` to reflect it supports a Montgomery internal representation. - Removes an unused parameter on `impl_field_op` macro. - Removes some unused code in `p521`'s field element module.
1 parent e092afb commit 300ce4f

File tree

7 files changed

+15
-14
lines changed

7 files changed

+15
-14
lines changed

p224/src/arithmetic/field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const MODULUS: Uint =
5151
#[derive(Clone, Copy, Debug)]
5252
pub struct FieldElement(pub(super) Uint);
5353

54-
primeorder::impl_field_element!(
54+
primeorder::impl_mont_field_element!(
5555
NistP224,
5656
FieldElement,
5757
FieldBytes,

p224/src/arithmetic/scalar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use core::ops::{Add, Mul, Sub};
6161
#[derive(Clone, Copy, Debug, PartialOrd, Ord)]
6262
pub struct Scalar(Uint);
6363

64-
primeorder::impl_field_element!(
64+
primeorder::impl_mont_field_element!(
6565
NistP224,
6666
Scalar,
6767
FieldBytes,

p256/src/arithmetic/field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const R_2: U256 =
3636
#[derive(Clone, Copy, Debug)]
3737
pub struct FieldElement(pub(crate) U256);
3838

39-
primeorder::impl_field_element!(
39+
primeorder::impl_mont_field_element!(
4040
NistP256,
4141
FieldElement,
4242
FieldBytes,

p384/src/arithmetic/field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(crate) const MODULUS: U384 = U384::from_be_hex(FieldElement::MODULUS);
4444
#[derive(Clone, Copy, Debug)]
4545
pub struct FieldElement(pub(super) U384);
4646

47-
primeorder::impl_field_element!(
47+
primeorder::impl_mont_field_element!(
4848
NistP384,
4949
FieldElement,
5050
FieldBytes,

p384/src/arithmetic/scalar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use core::ops::{Add, Mul, Sub};
6969
#[derive(Clone, Copy, Debug, PartialOrd, Ord)]
7070
pub struct Scalar(U384);
7171

72-
primeorder::impl_field_element!(
72+
primeorder::impl_mont_field_element!(
7373
NistP384,
7474
Scalar,
7575
FieldBytes,

p521/src/arithmetic/field.rs

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
clippy::identity_op,
2121
rustdoc::bare_urls
2222
)]
23-
// TODO(tarcieri): use all variables
24-
#![allow(unused_variables)]
2523

2624
// TODO(tarcieri): 32-bit backend?
2725
#[path = "field/p521_64.rs"]

primeorder/src/field.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
/// Provides both inherent and trait impls for a field element type which are
2-
/// backed by a core set of arithmetic functions specified as macro arguments.
1+
/// Implements a field element type whose internal representation is in
2+
/// Montgomery form, providing a combination of trait impls and inherent impls
3+
/// which are `const fn` where possible.
4+
///
5+
/// Accepts a set of `const fn` arithmetic operation functions as arguments.
36
///
47
/// # Inherent impls
58
/// - `const ZERO: Self`
@@ -42,7 +45,7 @@
4245
/// - `MulAssign`
4346
/// - `Neg`
4447
#[macro_export]
45-
macro_rules! impl_field_element {
48+
macro_rules! impl_mont_field_element {
4649
(
4750
$curve:tt,
4851
$fe:tt,
@@ -364,9 +367,9 @@ macro_rules! impl_field_element {
364367
}
365368
}
366369

367-
$crate::impl_field_op!($fe, $uint, Add, add, $add);
368-
$crate::impl_field_op!($fe, $uint, Sub, sub, $sub);
369-
$crate::impl_field_op!($fe, $uint, Mul, mul, $mul);
370+
$crate::impl_field_op!($fe, Add, add, $add);
371+
$crate::impl_field_op!($fe, Sub, sub, $sub);
372+
$crate::impl_field_op!($fe, Mul, mul, $mul);
370373

371374
impl AddAssign<$fe> for $fe {
372375
#[inline]
@@ -449,7 +452,7 @@ macro_rules! impl_field_element {
449452
/// which thunk to the given function.
450453
#[macro_export]
451454
macro_rules! impl_field_op {
452-
($fe:tt, $uint:ty, $op:tt, $op_fn:ident, $func:ident) => {
455+
($fe:tt, $op:tt, $op_fn:ident, $func:ident) => {
453456
impl ::core::ops::$op for $fe {
454457
type Output = $fe;
455458

0 commit comments

Comments
 (0)