/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 | 20.8k | void Bignum::modify(void) { |
10 | 20.8k | #if defined(CRYPTOFUZZ_BOTAN_IS_ORACLE) |
11 | 20.8k | (void)ds; |
12 | | #else |
13 | | if ( ds == nullptr ) { |
14 | | return; |
15 | | } |
16 | | |
17 | | try { |
18 | | /* Binary encode/decode */ |
19 | | if ( bn >= 0 && ds->Get<bool>() ) { |
20 | | uint8_t* encoded = util::malloc(bn.bytes()); |
21 | | CF_NORET(bn.binary_encode(encoded, bn.bytes())); |
22 | | CF_NORET(bn.binary_decode(encoded, bn.bytes())); |
23 | | util::free(encoded); |
24 | | } |
25 | | |
26 | | /* Invoke copy constructor */ |
27 | | if ( ds->Get<bool>() ) { |
28 | | bn = ::Botan::BigInt(bn); |
29 | | } |
30 | | } catch ( fuzzing::datasource::Datasource::OutOfData ) { } |
31 | | #endif |
32 | 20.8k | } |
33 | | |
34 | 0 | 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 | 5.93k | bn(other) { |
42 | 5.93k | } |
43 | | |
44 | | Bignum::Bignum(const int i) : |
45 | | bn(i) |
46 | 237 | { } |
47 | | |
48 | | Bignum::Bignum(const ::Botan::word w) : |
49 | | bn(w) |
50 | 75 | { } |
51 | | |
52 | | Bignum::Bignum(Datasource* ds, const std::string s) : |
53 | 38.0k | ds(ds), bn(s) { |
54 | 38.0k | } |
55 | | |
56 | | Bignum::Bignum(const std::string s) : |
57 | 63 | bn(s) { |
58 | 63 | } |
59 | | |
60 | 20.8k | ::Botan::BigInt& Bignum::Ref(void) { |
61 | 20.8k | modify(); |
62 | | |
63 | 20.8k | return bn; |
64 | 20.8k | } |
65 | | |
66 | 3.93k | const ::Botan::BigInt& Bignum::ConstRef(void) const { |
67 | 3.93k | return bn; |
68 | 3.93k | } |
69 | | |
70 | | } /* namespace Botan_bignum */ |
71 | | } /* namespace module */ |
72 | | } /* namespace cryptofuzz */ |