Coverage Report

Created: 2023-09-25 06:34

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