aboutsummaryrefslogtreecommitdiffstats
path: root/src/fuzzer/ecc_helper.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-07-31 15:13:15 -0400
committerJack Lloyd <[email protected]>2017-08-25 17:36:51 -0400
commit3baa546d70bcd078b23be07069d755a5f130fb0f (patch)
treed626d73fdf845987e2d1783e8493593501378a07 /src/fuzzer/ecc_helper.h
parent41e1e7cbc1e4e864ad5d15dd0c09227b04940a91 (diff)
Create new fuzzer build mode
Diffstat (limited to 'src/fuzzer/ecc_helper.h')
-rw-r--r--src/fuzzer/ecc_helper.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/fuzzer/ecc_helper.h b/src/fuzzer/ecc_helper.h
new file mode 100644
index 000000000..c9b3a6604
--- /dev/null
+++ b/src/fuzzer/ecc_helper.h
@@ -0,0 +1,58 @@
+/*
+* (C) 2015,2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef ECC_HELPERS_H__
+#define ECC_HELPERS_H__
+
+#include "fuzzers.h"
+#include <botan/curve_gfp.h>
+#include <botan/ec_group.h>
+#include <botan/reducer.h>
+
+namespace {
+
+inline std::ostream& operator<<(std::ostream& o, const Botan::PointGFp& point)
+ {
+ o << point.get_affine_x() << "," << point.get_affine_y();
+ return o;
+ }
+
+void check_ecc_math(const Botan::EC_Group& group,
+ const uint8_t in[], size_t len)
+ {
+ // These depend only on the group, which is also static
+ static const Botan::PointGFp base_point = group.get_base_point();
+ static Botan::Blinded_Point_Multiply blind(base_point, group.get_order(), 4);
+
+ const size_t hlen = len / 2;
+ const Botan::BigInt a = Botan::BigInt::decode(in, hlen);
+ const Botan::BigInt b = Botan::BigInt::decode(in + hlen, len - hlen);
+
+ const Botan::BigInt c = a + b;
+
+ const Botan::PointGFp P = base_point * a;
+ const Botan::PointGFp Q = base_point * b;
+ const Botan::PointGFp R = base_point * c;
+
+ const Botan::PointGFp A1 = P + Q;
+ const Botan::PointGFp A2 = Q + P;
+
+ FUZZER_ASSERT_EQUAL(A1, A2);
+
+ const Botan::PointGFp P1 = blind.blinded_multiply(a, fuzzer_rng());
+ const Botan::PointGFp Q1 = blind.blinded_multiply(b, fuzzer_rng());
+ const Botan::PointGFp R1 = blind.blinded_multiply(c, fuzzer_rng());
+
+ const Botan::PointGFp S1 = P1 + Q1;
+ const Botan::PointGFp S2 = Q1 + P1;
+
+ FUZZER_ASSERT_EQUAL(S1, S2);
+ FUZZER_ASSERT_EQUAL(S1, A1);
+ }
+
+}
+
+#endif