Coverage Report

Created: 2023-12-08 07:00

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