Skip to content

Commit

Permalink
NFC EC: DRY oneRR_mod_n.
Browse files Browse the repository at this point in the history
Avoid repeating the value of `oneRR_mod_n` twice in each file.
  • Loading branch information
briansmith committed Oct 17, 2023
1 parent 20672b2 commit 2a0e495
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/ec/suite_b/ops/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ fn p256_scalar_inv_to_mont(a: &Scalar<Unencoded>) -> Scalar<R> {
}

fn to_mont(a: &Scalar) -> Scalar<R> {
const N_RR: Scalar<Unencoded> =
Scalar::from_hex("66e12d94f3d956202845b2392b6bec594699799c49bd6fa683244c95be79eea2");
static N_RR: Scalar<Unencoded> = Scalar {
limbs: PRIVATE_SCALAR_OPS.oneRR_mod_n.limbs,
m: PhantomData,
encoding: PhantomData,
};
binary_op(p256_scalar_mul_mont, a, &N_RR)
}

Expand Down
11 changes: 7 additions & 4 deletions src/ec/suite_b/ops/p384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ pub static PUBLIC_SCALAR_OPS: PublicScalarOps = PublicScalarOps {
pub static PRIVATE_SCALAR_OPS: PrivateScalarOps = PrivateScalarOps {
scalar_ops: &SCALAR_OPS,

oneRR_mod_n: Scalar::from_hex(N_RR_HEX),
oneRR_mod_n: Scalar::from_hex("c84ee012b39bf213fb05b7a28266895d40d49174aab1cc5bc3e483afcb82947ff3d81e5df1aa4192d319b2419b409a9"),

};

fn p384_scalar_inv_to_mont(a: &Scalar<Unencoded>) -> Scalar<R> {
Expand Down Expand Up @@ -176,7 +177,11 @@ fn p384_scalar_inv_to_mont(a: &Scalar<Unencoded>) -> Scalar<R> {
}

fn to_mont(a: &Scalar<Unencoded>) -> Scalar<R> {
const N_RR: Scalar<Unencoded> = Scalar::from_hex(N_RR_HEX);
static N_RR: Scalar<Unencoded> = Scalar {
limbs: PRIVATE_SCALAR_OPS.oneRR_mod_n.limbs,
m: PhantomData,
encoding: PhantomData,
};
binary_op(p384_scalar_mul_mont, a, &N_RR)
}

Expand Down Expand Up @@ -272,8 +277,6 @@ unsafe extern "C" fn p384_elem_sqr_mont(
p384_elem_mul_mont(r, a, a);
}

const N_RR_HEX: &str = "0c84ee012b39bf213fb05b7a28266895d40d49174aab1cc5bc3e483afcb82947ff3d81e5df1aa4192d319b2419b409a9";

prefixed_extern! {
fn p384_elem_mul_mont(
r: *mut Limb, // [COMMON_OPS.num_limbs]
Expand Down

0 comments on commit 2a0e495

Please sign in to comment.