aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-12-05 21:45:37 -0500
committerJack Lloyd <[email protected]>2018-12-05 21:45:37 -0500
commitfcccdaf40ca342743055cf555eff049d5146c90a (patch)
tree3fcb909069323c96f14d07201956886bc4294552 /src
parent6b22107d40dcd385d42d8ea1adfd1efa0b62626d (diff)
Do swaps in PointGFp instead of copies
Saves 5% for ECDSA
Diffstat (limited to 'src')
-rw-r--r--src/lib/math/bigint/bigint.h2
-rw-r--r--src/lib/pubkey/ec_group/point_gfp.cpp25
2 files changed, 13 insertions, 14 deletions
diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h
index ee8f81719..31eee4c3c 100644
--- a/src/lib/math/bigint/bigint.h
+++ b/src/lib/math/bigint/bigint.h
@@ -350,7 +350,7 @@ class BOTAN_PUBLIC_API(2,0) BigInt final
* Zeroize the BigInt. The size of the underlying register is not
* modified.
*/
- void clear() { m_data.set_to_zero(); }
+ void clear() { m_data.set_to_zero(); m_signedness = Positive; }
/**
* Compare this to another BigInt
diff --git a/src/lib/pubkey/ec_group/point_gfp.cpp b/src/lib/pubkey/ec_group/point_gfp.cpp
index b4b3871cb..df9afa18d 100644
--- a/src/lib/pubkey/ec_group/point_gfp.cpp
+++ b/src/lib/pubkey/ec_group/point_gfp.cpp
@@ -138,9 +138,9 @@ void PointGFp::add_affine(const word x_words[], size_t x_size,
}
// setting to zero:
- m_coord_x = 0;
+ m_coord_x.clear();
m_coord_y = m_curve.get_1_rep();
- m_coord_z = 0;
+ m_coord_z.clear();
return;
}
@@ -158,14 +158,13 @@ void PointGFp::add_affine(const word x_words[], size_t x_size,
T3.mod_sub(m_coord_x, p, sub_ws);
- T2 = m_coord_y;
m_curve.mul(T2, T0, T3, ws);
- m_curve.mul(T3, m_coord_y, T1, ws);
- T2.mod_sub(T3, p, sub_ws);
- m_coord_y = T2;
+ m_curve.mul(T0, m_coord_y, T1, ws);
+ T2.mod_sub(T0, p, sub_ws);
+ m_coord_y.swap(T2);
- m_curve.mul(T3, m_coord_z, T4, ws);
- m_coord_z = T3;
+ m_curve.mul(T0, m_coord_z, T4, ws);
+ m_coord_z.swap(T0);
}
void PointGFp::add(const word x_words[], size_t x_size,
@@ -226,9 +225,9 @@ void PointGFp::add(const word x_words[], size_t x_size,
}
// setting to zero:
- m_coord_x = 0;
+ m_coord_x.clear();
m_coord_y = m_curve.get_1_rep();
- m_coord_z = 0;
+ m_coord_z.clear();
return;
}
@@ -354,13 +353,13 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn)
m_curve.mul(T0, T4, T1, ws);
T0.mod_sub(T3, p, sub_ws);
- m_coord_x = T2;
+ m_coord_x.swap(T2);
m_curve.mul(T2, m_coord_y, m_coord_z, ws);
T2.mod_mul(2, p, sub_ws);
- m_coord_y = T0;
- m_coord_z = T2;
+ m_coord_y.swap(T0);
+ m_coord_z.swap(T2);
}
// arithmetic operators