Coverage Report

Created: 2024-02-25 06:16

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