Coverage Report

Created: 2023-09-25 06:33

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