Coverage Report

Created: 2023-02-22 06:14

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