/src/cryptofuzz/modules/botan/bn_helper.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include <cryptofuzz/util.h> |
2 | | |
3 | | #include "bn_helper.h" |
4 | | |
5 | | namespace cryptofuzz { |
6 | | namespace module { |
7 | | namespace Botan_bignum { |
8 | | |
9 | 24.6k | void Bignum::modify(void) { |
10 | | #if defined(CRYPTOFUZZ_BOTAN_IS_ORACLE) |
11 | | (void)ds; |
12 | | #else |
13 | 24.6k | if ( ds == nullptr ) { |
14 | 8.16k | return; |
15 | 8.16k | } |
16 | | |
17 | 16.5k | try { |
18 | | /* Binary encode/decode */ |
19 | 16.5k | if ( bn >= 0 && ds->Get<bool>() ) { |
20 | 3.68k | uint8_t* encoded = util::malloc(bn.bytes()); |
21 | 3.68k | CF_NORET(bn.binary_encode(encoded, bn.bytes())); |
22 | 3.68k | CF_NORET(bn.binary_decode(encoded, bn.bytes())); |
23 | 3.68k | util::free(encoded); |
24 | 3.68k | } |
25 | | |
26 | | /* Invoke copy constructor */ |
27 | 16.5k | if ( ds->Get<bool>() ) { |
28 | 2.61k | bn = ::Botan::BigInt(bn); |
29 | 2.61k | } |
30 | 16.5k | } catch ( fuzzing::datasource::Datasource::OutOfData ) { } |
31 | 16.5k | #endif |
32 | 16.5k | } |
33 | | |
34 | 179 | Bignum::Bignum() { } |
35 | | |
36 | | Bignum::Bignum(Datasource* ds, const ::Botan::BigInt& other) : |
37 | 0 | ds(ds), bn(other) { |
38 | 0 | } |
39 | | |
40 | | Bignum::Bignum(const ::Botan::BigInt& other) : |
41 | 6.79k | bn(other) { |
42 | 6.79k | } |
43 | | |
44 | | Bignum::Bignum(const int i) : |
45 | | bn(i) |
46 | 1.17k | { } |
47 | | |
48 | | Bignum::Bignum(const ::Botan::word w) : |
49 | | bn(w) |
50 | 227 | { } |
51 | | |
52 | | Bignum::Bignum(Datasource* ds, const std::string s) : |
53 | 63.6k | ds(ds), bn(s) { |
54 | 63.6k | } |
55 | | |
56 | | Bignum::Bignum(const std::string s) : |
57 | 1.58k | bn(s) { |
58 | 1.58k | } |
59 | | |
60 | 24.6k | ::Botan::BigInt& Bignum::Ref(void) { |
61 | 24.6k | modify(); |
62 | | |
63 | 24.6k | return bn; |
64 | 24.6k | } |
65 | | |
66 | 5.83k | const ::Botan::BigInt& Bignum::ConstRef(void) const { |
67 | 5.83k | return bn; |
68 | 5.83k | } |
69 | | |
70 | | } /* namespace Botan_bignum */ |
71 | | } /* namespace module */ |
72 | | } /* namespace cryptofuzz */ |