Coverage Report

Created: 2024-06-28 06:39

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