aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-06-19 11:14:10 -0400
committerJack Lloyd <[email protected]>2018-06-19 11:14:10 -0400
commit2de5e91c986699038f2c743d894e1a699452689c (patch)
treebdbeba135339619f043bf03aee6a7b0566772141 /src/lib/pubkey
parentfc5156247ac9152fbe6f20f2ab6d1b09a9751652 (diff)
Ensure that trying to add points from different groups fails.
Producing garbage instead is asking for trouble.
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/ec_group/curve_gfp.h29
-rw-r--r--src/lib/pubkey/ec_group/point_gfp.cpp3
2 files changed, 19 insertions, 13 deletions
diff --git a/src/lib/pubkey/ec_group/curve_gfp.h b/src/lib/pubkey/ec_group/curve_gfp.h
index 865bb68f8..888f87d46 100644
--- a/src/lib/pubkey/ec_group/curve_gfp.h
+++ b/src/lib/pubkey/ec_group/curve_gfp.h
@@ -201,6 +201,22 @@ class BOTAN_UNSTABLE_API CurveGFp final
std::swap(m_repr, other.m_repr);
}
+ /**
+ * Equality operator
+ * @param lhs a curve
+ * @param rhs a curve
+ * @return true iff lhs is the same as rhs
+ */
+ inline bool operator==(const CurveGFp& other) const
+ {
+ if(m_repr.get() == other.m_repr.get())
+ return true;
+
+ return (get_p() == other.get_p()) &&
+ (get_a() == other.get_a()) &&
+ (get_b() == other.get_b());
+ }
+
private:
static std::shared_ptr<CurveGFp_Repr>
choose_repr(const BigInt& p, const BigInt& a, const BigInt& b);
@@ -208,19 +224,6 @@ class BOTAN_UNSTABLE_API CurveGFp final
std::shared_ptr<CurveGFp_Repr> m_repr;
};
-/**
-* Equality operator
-* @param lhs a curve
-* @param rhs a curve
-* @return true iff lhs is the same as rhs
-*/
-inline bool operator==(const CurveGFp& lhs, const CurveGFp& rhs)
- {
- return (lhs.get_p() == rhs.get_p()) &&
- (lhs.get_a() == rhs.get_a()) &&
- (lhs.get_b() == rhs.get_b());
- }
-
inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs)
{
return !(lhs == rhs);
diff --git a/src/lib/pubkey/ec_group/point_gfp.cpp b/src/lib/pubkey/ec_group/point_gfp.cpp
index 8f53bb079..b1c921a51 100644
--- a/src/lib/pubkey/ec_group/point_gfp.cpp
+++ b/src/lib/pubkey/ec_group/point_gfp.cpp
@@ -87,6 +87,7 @@ inline bool all_zeros(const word x[], size_t len)
void PointGFp::add_affine(const PointGFp& rhs, std::vector<BigInt>& workspace)
{
+ BOTAN_ASSERT_NOMSG(m_curve == rhs.m_curve);
BOTAN_DEBUG_ASSERT(rhs.is_affine());
const size_t p_words = m_curve.get_p_words();
@@ -180,6 +181,8 @@ void PointGFp::add_affine(const word x_words[], size_t x_size,
// Point addition
void PointGFp::add(const PointGFp& rhs, std::vector<BigInt>& ws_bn)
{
+ BOTAN_ASSERT_NOMSG(m_curve == rhs.m_curve);
+
if(rhs.is_zero())
return;