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