aboutsummaryrefslogtreecommitdiffstats
path: root/src/fuzzer/redc_helper.h
blob: 4fc33894af663ad90a4bdf6c6fe125e66c46b72f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* (C) 2015,2016 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_FUZZ_REDC_HELPERS_H__
#define BOTAN_FUZZ_REDC_HELPERS_H__

#include "fuzzers.h"
#include <botan/reducer.h>

namespace {

void check_redc(std::function<void (Botan::BigInt&, Botan::secure_vector<Botan::word>&)> redc_fn,
                const Botan::Modular_Reducer& redc,
                const Botan::BigInt& prime,
                const Botan::BigInt& x)
   {
   const Botan::BigInt v1 = x % prime;
   const Botan::BigInt v2 = redc.reduce(x);

   Botan::secure_vector<Botan::word> ws;
   Botan::BigInt v3 = x;
   redc_fn(v3, ws);

   FUZZER_ASSERT_EQUAL(v1, v2);
   FUZZER_ASSERT_EQUAL(v2, v3);
   }

}

#endif