/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  | 10.9k  | void Bignum::modify(void) { | 
10  | 10.9k  | #if defined(CRYPTOFUZZ_BOTAN_IS_ORACLE)  | 
11  | 10.9k  |     (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  | 10.9k  | }  | 
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  | 4.13k  |     bn(other) { | 
42  | 4.13k  | }  | 
43  |  |  | 
44  |  | Bignum::Bignum(const int i) :  | 
45  |  |     bn(i)  | 
46  | 151  | { } | 
47  |  |  | 
48  |  | Bignum::Bignum(const ::Botan::word w) :  | 
49  |  |     bn(w)  | 
50  | 14  | { } | 
51  |  |  | 
52  |  | Bignum::Bignum(Datasource* ds, const std::string s) :  | 
53  | 22.1k  |     ds(ds), bn(s) { | 
54  | 22.1k  | }  | 
55  |  |  | 
56  |  | Bignum::Bignum(const std::string s) :  | 
57  | 0  |     bn(s) { | 
58  | 0  | }  | 
59  |  |  | 
60  | 10.9k  | ::Botan::BigInt& Bignum::Ref(void) { | 
61  | 10.9k  |     modify();  | 
62  |  |  | 
63  | 10.9k  |     return bn;  | 
64  | 10.9k  | }  | 
65  |  |  | 
66  | 3.34k  | const ::Botan::BigInt& Bignum::ConstRef(void) const { | 
67  | 3.34k  |     return bn;  | 
68  | 3.34k  | }  | 
69  |  |  | 
70  |  | } /* namespace Botan_bignum */  | 
71  |  | } /* namespace module */  | 
72  |  | } /* namespace cryptofuzz */  |