Coverage Report

Created: 2022-06-23 06:44

/src/botan/src/fuzzer/divide.cpp
Line
Count
Source
1
/*
2
* (C) 2015,2016,2018,2021 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
#include "fuzzers.h"
7
#include <botan/internal/divide.h>
8
9
void fuzz(const uint8_t in[], size_t len)
10
1.14k
   {
11
1.14k
   if(len > 2*4096/8)
12
17
      return;
13
14
   // Save on allocations by making these static
15
1.12k
   static Botan::BigInt x, y, q, r, ct_q, ct_r, z;
16
17
1.12k
   x = Botan::BigInt::decode(in, len / 2);
18
1.12k
   y = Botan::BigInt::decode(in + len / 2, len - (len / 2));
19
20
1.12k
   if(y == 0)
21
2
      return;
22
23
1.12k
   Botan::vartime_divide(x, y, q, r);
24
25
1.12k
   FUZZER_ASSERT_TRUE(r < y);
26
27
1.12k
   z = q*y + r;
28
29
1.12k
   FUZZER_ASSERT_EQUAL(z, x);
30
31
1.12k
   Botan::ct_divide(x, y, ct_q, ct_r);
32
33
1.12k
   FUZZER_ASSERT_EQUAL(q, ct_q);
34
1.12k
   FUZZER_ASSERT_EQUAL(r, ct_r);
35
36
   // Now divide by just low word of y
37
38
1.12k
   y = y.word_at(0);
39
1.12k
   if(y == 0)
40
39
      return;
41
42
1.08k
   Botan::vartime_divide(x, y, q, r);
43
44
1.08k
   FUZZER_ASSERT_TRUE(r < y);
45
1.08k
   z = q*y + r;
46
1.08k
   FUZZER_ASSERT_EQUAL(z, x);
47
48
1.08k
   Botan::word rw;
49
1.08k
   Botan::ct_divide_word(x, y.word_at(0), ct_q, rw);
50
1.08k
   FUZZER_ASSERT_EQUAL(ct_q, q);
51
1.08k
   FUZZER_ASSERT_EQUAL(rw, r.word_at(0));
52
53
1.08k
   }
54