ec: NFC: Refactor scalar_sum
to eliminate LIMBS_add_mod
use.
Use the pattern we typically use where one argument is passed by value. This lets us use `limbs_add_assign_mod`, eliminating the `unsafe` direct use of `LIMBS_add_mod`. This will make future refactoring easier. This also eliminates the need to construct and zeroize a new scalar `r` for the result.
This commit is contained in:
parent
3afbcc5dc5
commit
bc00f7e58c
@ -266,7 +266,7 @@ impl EcdsaKeyPair {
|
|||||||
// Step 6.
|
// Step 6.
|
||||||
let s = {
|
let s = {
|
||||||
let dr = scalar_ops.scalar_product(&self.d, &r);
|
let dr = scalar_ops.scalar_product(&self.d, &r);
|
||||||
let e_plus_dr = scalar_sum(cops, &e, &dr);
|
let e_plus_dr = scalar_sum(cops, &e, dr);
|
||||||
scalar_ops.scalar_product(&k_inv, &e_plus_dr)
|
scalar_ops.scalar_product(&k_inv, &e_plus_dr)
|
||||||
};
|
};
|
||||||
if cops.is_zero(&s) {
|
if cops.is_zero(&s) {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
use crate::{arithmetic::limbs_from_hex, arithmetic::montgomery::*, c, error, limb::*};
|
use crate::{arithmetic::limbs_from_hex, arithmetic::montgomery::*, error, limb::*};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
pub use self::elem::*;
|
pub use self::elem::*;
|
||||||
@ -326,18 +326,13 @@ pub fn elem_reduced_to_scalar(ops: &CommonOps, elem: &Elem<Unencoded>) -> Scalar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scalar_sum(ops: &CommonOps, a: &Scalar, b: &Scalar) -> Scalar {
|
pub fn scalar_sum(ops: &CommonOps, a: &Scalar, mut b: Scalar) -> Scalar {
|
||||||
let mut r = Scalar::zero();
|
limbs_add_assign_mod(
|
||||||
unsafe {
|
&mut b.limbs[..ops.num_limbs],
|
||||||
LIMBS_add_mod(
|
&a.limbs[..ops.num_limbs],
|
||||||
r.limbs.as_mut_ptr(),
|
&ops.n.limbs[..ops.num_limbs],
|
||||||
a.limbs.as_ptr(),
|
);
|
||||||
b.limbs.as_ptr(),
|
b
|
||||||
ops.n.limbs.as_ptr(),
|
|
||||||
ops.num_limbs,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns (`a` squared `squarings` times) * `b`.
|
// Returns (`a` squared `squarings` times) * `b`.
|
||||||
@ -425,16 +420,6 @@ fn parse_big_endian_fixed_consttime<M>(
|
|||||||
Ok(r)
|
Ok(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
prefixed_extern! {
|
|
||||||
fn LIMBS_add_mod(
|
|
||||||
r: *mut Limb,
|
|
||||||
a: *const Limb,
|
|
||||||
b: *const Limb,
|
|
||||||
m: *const Limb,
|
|
||||||
num_limbs: c::size_t,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user