aboutsummaryrefslogtreecommitdiffstats
path: root/src/fuzzer/divide.cpp
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/divide.cpp
parent41e1e7cbc1e4e864ad5d15dd0c09227b04940a91 (diff)
Create new fuzzer build mode
Diffstat (limited to 'src/fuzzer/divide.cpp')
-rw-r--r--src/fuzzer/divide.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/fuzzer/divide.cpp b/src/fuzzer/divide.cpp
new file mode 100644
index 000000000..01ec14e28
--- /dev/null
+++ b/src/fuzzer/divide.cpp
@@ -0,0 +1,29 @@
+/*
+* (C) 2015,2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+#include "fuzzers.h"
+#include <botan/divide.h>
+
+void fuzz(const uint8_t in[], size_t len)
+ {
+ if(len % 2 == 1 || len > 2*4096/8)
+ return;
+
+ const Botan::BigInt x = Botan::BigInt::decode(in, len / 2);
+ const Botan::BigInt y = Botan::BigInt::decode(in + len / 2, len / 2);
+
+ if(y == 0)
+ return;
+
+ Botan::BigInt q, r;
+ Botan::divide(x, y, q, r);
+
+ FUZZER_ASSERT_TRUE(r < y);
+
+ Botan::BigInt z = q*y + r;
+
+ FUZZER_ASSERT_EQUAL(z, x);
+ }
+