aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-02-25 19:58:35 +0000
committerlloyd <[email protected]>2010-02-25 19:58:35 +0000
commit08fd8d3f4718cbe42ec29c1cf97e36206e748b68 (patch)
treeadb4dc523dd5a5a6378db3b5824ed34b0754ec38 /src
parentbb8112e7b5fd018b3c653c139a03cf14f163e3cb (diff)
Make PointGFp::mult2_in_place private
Diffstat (limited to 'src')
-rw-r--r--src/math/gfpmath/point_gfp.cpp34
-rw-r--r--src/math/gfpmath/point_gfp.h11
2 files changed, 25 insertions, 20 deletions
diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp
index 1515e6759..e1992da70 100644
--- a/src/math/gfpmath/point_gfp.cpp
+++ b/src/math/gfpmath/point_gfp.cpp
@@ -123,16 +123,24 @@ PointGFp& PointGFp::operator-=(const PointGFp& rhs)
PointGFp& PointGFp::operator*=(const BigInt& scalar)
{
- if(scalar == 0)
+ if(scalar.abs() <= 2) // special cases for small values
{
- *this = PointGFp(curve);
- return *this;
- }
- else if(scalar == 1)
- return *this;
- else if(scalar == -1)
- {
- this->negate();
+ u32bit value = scalar.abs().to_u32bit();
+
+ if(value == 0)
+ *this = PointGFp(curve); // set to zero point
+ else if(value == 1)
+ {
+ if(scalar.is_negative())
+ this->negate();
+ }
+ else if(value == 2)
+ {
+ this->mult2_in_place();
+ if(scalar.is_negative())
+ this->negate();
+ }
+
return *this;
}
@@ -182,14 +190,14 @@ PointGFp& PointGFp::negate()
}
// *this *= 2
-PointGFp& PointGFp::mult2_in_place()
+void PointGFp::mult2_in_place()
{
if(is_zero())
- return *this;
+ return;
else if(coord_y.is_zero())
{
*this = PointGFp(curve); // setting myself to zero
- return *this;
+ return;
}
Modular_Reducer mod_p(curve.get_p());
@@ -218,8 +226,6 @@ PointGFp& PointGFp::mult2_in_place()
coord_x = x;
coord_y = y;
coord_z = z;
-
- return *this;
}
BigInt PointGFp::get_affine_x() const
diff --git a/src/math/gfpmath/point_gfp.h b/src/math/gfpmath/point_gfp.h
index 40feb3fa8..e78188759 100644
--- a/src/math/gfpmath/point_gfp.h
+++ b/src/math/gfpmath/point_gfp.h
@@ -101,12 +101,6 @@ class BOTAN_DLL PointGFp
PointGFp& negate();
/**
- * Multiply the point by two
- * @return *this
- */
- PointGFp& mult2_in_place();
-
- /**
* Return base curve of this point
* @result the curve over GF(p) of this point
*/
@@ -167,6 +161,11 @@ class BOTAN_DLL PointGFp
*/
bool operator==(const PointGFp& other) const;
private:
+ /**
+ * Multiply the point by two
+ */
+ void mult2_in_place();
+
CurveGFp curve;
BigInt coord_x, coord_y, coord_z;
};