aboutsummaryrefslogtreecommitdiffstats
path: root/src/fuzzer/ressol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fuzzer/ressol.cpp')
-rw-r--r--src/fuzzer/ressol.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/fuzzer/ressol.cpp b/src/fuzzer/ressol.cpp
new file mode 100644
index 000000000..17ba88b8b
--- /dev/null
+++ b/src/fuzzer/ressol.cpp
@@ -0,0 +1,45 @@
+/*
+* (C) 2015,2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "fuzzers.h"
+#include <botan/numthry.h>
+#include <botan/reducer.h>
+
+void fuzz(const uint8_t in[], size_t len)
+ {
+ // Ressol is mostly used for ECC point decompression so best to test smaller sizes
+ static const size_t p_bits = 256;
+ static const Botan::BigInt p = random_prime(fuzzer_rng(), p_bits);
+ static const Botan::Modular_Reducer mod_p(p);
+
+ if(len > p_bits / 8)
+ return;
+
+ try
+ {
+ const Botan::BigInt a = Botan::BigInt::decode(in, len);
+ Botan::BigInt a_sqrt = Botan::ressol(a, p);
+
+ if(a_sqrt > 0)
+ {
+ const Botan::BigInt a_redc = mod_p.reduce(a);
+ const Botan::BigInt z = mod_p.square(a_sqrt);
+
+ if(z != a_redc)
+ {
+ std::cout << "A = " << a << "\n";
+ std::cout << "P = " << p << "\n";
+ std::cout << "R = " << a_sqrt << "\n";
+ std::cout << "Z = " << z << "\n";
+ abort();
+ }
+ }
+ }
+ catch(Botan::Exception& e) {}
+
+ return;
+ }
+