Coverage Report

Created: 2024-11-21 07:03

/src/cryptofuzz/modules/libgmp/bn_ops.cpp
Line
Count
Source (jump to first uncovered line)
1
#include <cryptofuzz/util.h>
2
#include <cryptofuzz/repository.h>
3
#include <fuzzing/datasource/id.hpp>
4
5
#include "bn_ops.h"
6
7
8.59k
#define GET_WHICH(max) uint8_t which = 0; try { which = ds.Get<uint8_t>(); which %= ((max)+1); } catch ( ... ) { }
8
9
namespace cryptofuzz {
10
namespace module {
11
#if !defined(HAVE_MINI_GMP)
12
namespace libgmp_detail {
13
    extern gmp_randstate_t rng_state;
14
}
15
#endif
16
namespace libgmp_bignum {
17
18
302
bool Add::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
19
302
    bool ret = false;
20
21
302
    GET_WHICH(1);
22
302
    switch ( which ) {
23
216
        case    0:
24
216
            /* noret */ mpz_add(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
25
216
            CF_NORET(bn.CopyResult(res));
26
216
            break;
27
86
        case    1:
28
86
            {
29
86
                const auto bn1 = bn[1].GetUnsignedLong();
30
86
                CF_CHECK_NE(bn1, std::nullopt);
31
32
11
                /* noret */ mpz_add_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
33
22
                CF_NORET(bn.CopyResult(res));
34
22
            }
35
0
            break;
36
0
        default:
37
0
            return false;
38
302
    }
39
40
238
    ret = true;
41
42
302
end:
43
302
    return ret;
44
238
}
cryptofuzz::module::libgmp_bignum::Add::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
18
151
bool Add::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
19
151
    bool ret = false;
20
21
151
    GET_WHICH(1);
22
151
    switch ( which ) {
23
108
        case    0:
24
108
            /* noret */ mpz_add(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
25
108
            CF_NORET(bn.CopyResult(res));
26
108
            break;
27
43
        case    1:
28
43
            {
29
43
                const auto bn1 = bn[1].GetUnsignedLong();
30
43
                CF_CHECK_NE(bn1, std::nullopt);
31
32
11
                /* noret */ mpz_add_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
33
11
                CF_NORET(bn.CopyResult(res));
34
11
            }
35
0
            break;
36
0
        default:
37
0
            return false;
38
151
    }
39
40
119
    ret = true;
41
42
151
end:
43
151
    return ret;
44
119
}
cryptofuzz::module::libgmp_bignum::Add::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
18
151
bool Add::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
19
151
    bool ret = false;
20
21
151
    GET_WHICH(1);
22
151
    switch ( which ) {
23
108
        case    0:
24
108
            /* noret */ mpz_add(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
25
108
            CF_NORET(bn.CopyResult(res));
26
108
            break;
27
43
        case    1:
28
43
            {
29
43
                const auto bn1 = bn[1].GetUnsignedLong();
30
43
                CF_CHECK_NE(bn1, std::nullopt);
31
32
11
                /* noret */ mpz_add_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
33
11
                CF_NORET(bn.CopyResult(res));
34
11
            }
35
0
            break;
36
0
        default:
37
0
            return false;
38
151
    }
39
40
119
    ret = true;
41
42
151
end:
43
151
    return ret;
44
119
}
45
46
470
bool Sub::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
47
470
    bool ret = false;
48
49
470
    GET_WHICH(2);
50
470
    switch ( which ) {
51
266
        case    0:
52
266
            /* noret */ mpz_sub(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
53
266
            CF_NORET(bn.CopyResult(res));
54
266
            break;
55
68
        case    1:
56
68
            {
57
68
                const auto bn1 = bn[1].GetUnsignedLong();
58
68
                CF_CHECK_NE(bn1, std::nullopt);
59
60
6
                /* noret */ mpz_sub_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
61
12
                CF_NORET(bn.CopyResult(res));
62
12
            }
63
0
            break;
64
136
        case    2:
65
136
            {
66
136
                const auto bn0 = bn[0].GetUnsignedLong();
67
136
                CF_CHECK_NE(bn0, std::nullopt);
68
69
23
                /* noret */ mpz_ui_sub(bn.GetResPtr(), *bn0, bn[1].GetPtr());
70
46
                CF_NORET(bn.CopyResult(res));
71
46
            }
72
0
            break;
73
0
        default:
74
0
            return false;
75
470
    }
76
77
324
    ret = true;
78
79
470
end:
80
470
    return ret;
81
324
}
cryptofuzz::module::libgmp_bignum::Sub::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
46
235
bool Sub::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
47
235
    bool ret = false;
48
49
235
    GET_WHICH(2);
50
235
    switch ( which ) {
51
133
        case    0:
52
133
            /* noret */ mpz_sub(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
53
133
            CF_NORET(bn.CopyResult(res));
54
133
            break;
55
34
        case    1:
56
34
            {
57
34
                const auto bn1 = bn[1].GetUnsignedLong();
58
34
                CF_CHECK_NE(bn1, std::nullopt);
59
60
6
                /* noret */ mpz_sub_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
61
6
                CF_NORET(bn.CopyResult(res));
62
6
            }
63
0
            break;
64
68
        case    2:
65
68
            {
66
68
                const auto bn0 = bn[0].GetUnsignedLong();
67
68
                CF_CHECK_NE(bn0, std::nullopt);
68
69
23
                /* noret */ mpz_ui_sub(bn.GetResPtr(), *bn0, bn[1].GetPtr());
70
23
                CF_NORET(bn.CopyResult(res));
71
23
            }
72
0
            break;
73
0
        default:
74
0
            return false;
75
235
    }
76
77
162
    ret = true;
78
79
235
end:
80
235
    return ret;
81
162
}
cryptofuzz::module::libgmp_bignum::Sub::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
46
235
bool Sub::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
47
235
    bool ret = false;
48
49
235
    GET_WHICH(2);
50
235
    switch ( which ) {
51
133
        case    0:
52
133
            /* noret */ mpz_sub(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
53
133
            CF_NORET(bn.CopyResult(res));
54
133
            break;
55
34
        case    1:
56
34
            {
57
34
                const auto bn1 = bn[1].GetUnsignedLong();
58
34
                CF_CHECK_NE(bn1, std::nullopt);
59
60
6
                /* noret */ mpz_sub_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
61
6
                CF_NORET(bn.CopyResult(res));
62
6
            }
63
0
            break;
64
68
        case    2:
65
68
            {
66
68
                const auto bn0 = bn[0].GetUnsignedLong();
67
68
                CF_CHECK_NE(bn0, std::nullopt);
68
69
23
                /* noret */ mpz_ui_sub(bn.GetResPtr(), *bn0, bn[1].GetPtr());
70
23
                CF_NORET(bn.CopyResult(res));
71
23
            }
72
0
            break;
73
0
        default:
74
0
            return false;
75
235
    }
76
77
162
    ret = true;
78
79
235
end:
80
235
    return ret;
81
162
}
82
83
180
bool Mul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
84
180
    bool ret = false;
85
86
180
    GET_WHICH(2);
87
180
    switch ( which ) {
88
72
        case    0:
89
72
            /* noret */ mpz_mul(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
90
72
            CF_NORET(bn.CopyResult(res));
91
72
            break;
92
28
        case    1:
93
28
            {
94
28
                const auto bn1 = bn[1].GetUnsignedLong();
95
28
                CF_CHECK_NE(bn1, std::nullopt);
96
97
6
                /* noret */ mpz_mul_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
98
12
                CF_NORET(bn.CopyResult(res));
99
12
            }
100
0
            break;
101
80
        case    2:
102
80
            {
103
80
                const auto bn1 = bn[1].GetSignedLong();
104
80
                CF_CHECK_NE(bn1, std::nullopt);
105
106
6
                /* noret */ mpz_mul_si(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
107
12
                CF_NORET(bn.CopyResult(res));
108
12
            }
109
0
            break;
110
0
        default:
111
0
            return false;
112
180
    }
113
114
96
    ret = true;
115
116
180
end:
117
180
    return ret;
118
96
}
cryptofuzz::module::libgmp_bignum::Mul::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
83
90
bool Mul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
84
90
    bool ret = false;
85
86
90
    GET_WHICH(2);
87
90
    switch ( which ) {
88
36
        case    0:
89
36
            /* noret */ mpz_mul(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
90
36
            CF_NORET(bn.CopyResult(res));
91
36
            break;
92
14
        case    1:
93
14
            {
94
14
                const auto bn1 = bn[1].GetUnsignedLong();
95
14
                CF_CHECK_NE(bn1, std::nullopt);
96
97
6
                /* noret */ mpz_mul_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
98
6
                CF_NORET(bn.CopyResult(res));
99
6
            }
100
0
            break;
101
40
        case    2:
102
40
            {
103
40
                const auto bn1 = bn[1].GetSignedLong();
104
40
                CF_CHECK_NE(bn1, std::nullopt);
105
106
6
                /* noret */ mpz_mul_si(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
107
6
                CF_NORET(bn.CopyResult(res));
108
6
            }
109
0
            break;
110
0
        default:
111
0
            return false;
112
90
    }
113
114
48
    ret = true;
115
116
90
end:
117
90
    return ret;
118
48
}
cryptofuzz::module::libgmp_bignum::Mul::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
83
90
bool Mul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
84
90
    bool ret = false;
85
86
90
    GET_WHICH(2);
87
90
    switch ( which ) {
88
36
        case    0:
89
36
            /* noret */ mpz_mul(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
90
36
            CF_NORET(bn.CopyResult(res));
91
36
            break;
92
14
        case    1:
93
14
            {
94
14
                const auto bn1 = bn[1].GetUnsignedLong();
95
14
                CF_CHECK_NE(bn1, std::nullopt);
96
97
6
                /* noret */ mpz_mul_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
98
6
                CF_NORET(bn.CopyResult(res));
99
6
            }
100
0
            break;
101
40
        case    2:
102
40
            {
103
40
                const auto bn1 = bn[1].GetSignedLong();
104
40
                CF_CHECK_NE(bn1, std::nullopt);
105
106
6
                /* noret */ mpz_mul_si(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
107
6
                CF_NORET(bn.CopyResult(res));
108
6
            }
109
0
            break;
110
0
        default:
111
0
            return false;
112
90
    }
113
114
48
    ret = true;
115
116
90
end:
117
90
    return ret;
118
48
}
119
120
228
bool Div::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
121
228
    bool ret = false;
122
123
228
    GET_WHICH(3);
124
228
    switch ( which ) {
125
#if !defined(HAVE_MINI_GMP)
126
96
        case    0:
127
96
            CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
128
129
88
            /* noret */ mpz_div(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
130
88
            CF_NORET(bn.CopyResult(res));
131
88
            break;
132
35
        case    1:
133
35
            {
134
35
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
135
136
33
                const auto bn1 = bn[1].GetUnsignedLong();
137
33
                CF_CHECK_NE(bn1, std::nullopt);
138
139
8
                /* noret */ mpz_div_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
140
8
                CF_NORET(bn.CopyResult(res));
141
8
            }
142
0
            break;
143
0
#endif
144
52
        case    2:
145
52
            {
146
52
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
147
148
50
                CF_CHECK_NE(mpz_divisible_p(bn[0].GetPtr(), bn[1].GetPtr()), 0);
149
150
0
                /* noret */ mpz_divexact(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
151
0
                CF_NORET(bn.CopyResult(res));
152
0
            }
153
0
            break;
154
26
        case    3:
155
26
            {
156
26
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
157
158
23
                const auto bn1 = bn[1].GetUnsignedLong();
159
23
                CF_CHECK_NE(bn1, std::nullopt);
160
161
5
                CF_CHECK_NE(mpz_divisible_ui_p(bn[0].GetPtr(), *bn1), 0);
162
163
0
                /* noret */ mpz_divexact_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
164
0
                CF_NORET(bn.CopyResult(res));
165
0
            }
166
0
            break;
167
19
        default:
168
19
            return false;
169
228
    }
170
171
    /* Negative not supported */
172
96
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
173
96
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
174
175
96
    ret = true;
176
177
209
end:
178
209
    return ret;
179
96
}
cryptofuzz::module::libgmp_bignum::Div::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
120
196
bool Div::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
121
196
    bool ret = false;
122
123
196
    GET_WHICH(3);
124
196
    switch ( which ) {
125
0
#if !defined(HAVE_MINI_GMP)
126
96
        case    0:
127
96
            CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
128
129
88
            /* noret */ mpz_div(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
130
88
            CF_NORET(bn.CopyResult(res));
131
88
            break;
132
35
        case    1:
133
35
            {
134
35
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
135
136
33
                const auto bn1 = bn[1].GetUnsignedLong();
137
33
                CF_CHECK_NE(bn1, std::nullopt);
138
139
8
                /* noret */ mpz_div_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
140
8
                CF_NORET(bn.CopyResult(res));
141
8
            }
142
0
            break;
143
0
#endif
144
44
        case    2:
145
44
            {
146
44
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
147
148
42
                CF_CHECK_NE(mpz_divisible_p(bn[0].GetPtr(), bn[1].GetPtr()), 0);
149
150
0
                /* noret */ mpz_divexact(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
151
0
                CF_NORET(bn.CopyResult(res));
152
0
            }
153
0
            break;
154
21
        case    3:
155
21
            {
156
21
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
157
158
18
                const auto bn1 = bn[1].GetUnsignedLong();
159
18
                CF_CHECK_NE(bn1, std::nullopt);
160
161
5
                CF_CHECK_NE(mpz_divisible_ui_p(bn[0].GetPtr(), *bn1), 0);
162
163
0
                /* noret */ mpz_divexact_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
164
0
                CF_NORET(bn.CopyResult(res));
165
0
            }
166
0
            break;
167
0
        default:
168
0
            return false;
169
196
    }
170
171
    /* Negative not supported */
172
96
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
173
96
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
174
175
96
    ret = true;
176
177
196
end:
178
196
    return ret;
179
96
}
cryptofuzz::module::libgmp_bignum::Div::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
120
32
bool Div::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
121
32
    bool ret = false;
122
123
32
    GET_WHICH(3);
124
32
    switch ( which ) {
125
#if !defined(HAVE_MINI_GMP)
126
        case    0:
127
            CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
128
129
            /* noret */ mpz_div(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
130
            CF_NORET(bn.CopyResult(res));
131
            break;
132
        case    1:
133
            {
134
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
135
136
                const auto bn1 = bn[1].GetUnsignedLong();
137
                CF_CHECK_NE(bn1, std::nullopt);
138
139
                /* noret */ mpz_div_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
140
                CF_NORET(bn.CopyResult(res));
141
            }
142
            break;
143
#endif
144
8
        case    2:
145
8
            {
146
8
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
147
148
8
                CF_CHECK_NE(mpz_divisible_p(bn[0].GetPtr(), bn[1].GetPtr()), 0);
149
150
0
                /* noret */ mpz_divexact(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
151
0
                CF_NORET(bn.CopyResult(res));
152
0
            }
153
0
            break;
154
5
        case    3:
155
5
            {
156
5
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
157
158
5
                const auto bn1 = bn[1].GetUnsignedLong();
159
5
                CF_CHECK_NE(bn1, std::nullopt);
160
161
0
                CF_CHECK_NE(mpz_divisible_ui_p(bn[0].GetPtr(), *bn1), 0);
162
163
0
                /* noret */ mpz_divexact_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
164
0
                CF_NORET(bn.CopyResult(res));
165
0
            }
166
0
            break;
167
19
        default:
168
19
            return false;
169
32
    }
170
171
    /* Negative not supported */
172
0
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
173
0
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
174
175
0
    ret = true;
176
177
13
end:
178
13
    return ret;
179
0
}
180
181
4.44k
bool ExpMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
182
4.44k
    bool ret = false;
183
184
4.44k
    GET_WHICH(2);
185
186
4.44k
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
187
188
#if defined(HAVE_MINI_GMP)
189
    /* Avoid timeouts */
190
301
    CF_CHECK_LTE(mpz_sizeinbase(bn[0].GetPtr(), 2), 2000);
191
298
    CF_CHECK_LTE(mpz_sizeinbase(bn[1].GetPtr(), 2), 2000);
192
230
    CF_CHECK_LTE(mpz_sizeinbase(bn[2].GetPtr(), 2), 2000);
193
109
#endif
194
195
109
    switch ( which ) {
196
3.39k
        case    0:
197
            /* "Negative exp is supported if the inverse base-1 mod mod exists.
198
             *  If an inverse doesn’t exist then a divide by zero is raised."
199
             */
200
3.39k
            CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
201
202
3.31k
            /* noret */ mpz_powm(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
203
3.39k
            CF_NORET(bn.CopyResult(res));
204
3.39k
            break;
205
197
        case    1:
206
197
            {
207
197
                const auto bn1 = bn[1].GetUnsignedLong();
208
197
                CF_CHECK_NE(bn1, std::nullopt);
209
210
31
                /* noret */ mpz_powm_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1, bn[2].GetPtr());
211
31
                CF_NORET(bn.CopyResult(res));
212
31
            }
213
0
            break;
214
#if !defined(HAVE_MINI_GMP)
215
576
        case    2:
216
576
            {
217
576
                CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
218
219
                /* "It is required that exp > 0 and that mod is odd." */
220
576
                CF_CHECK_GT(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
221
222
565
                const auto ptr = bn[2].GetPtr();
223
565
                CF_CHECK_EQ(mpz_odd_p(ptr), 1);
224
225
327
                /* noret */ mpz_powm_sec(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
226
327
                CF_NORET(bn.CopyResult(res));
227
327
            }
228
0
            break;
229
0
#endif
230
20
        default:
231
20
            return false;
232
109
    }
233
234
3.74k
    ret = true;
235
236
4.42k
end:
237
4.42k
    return ret;
238
3.74k
}
cryptofuzz::module::libgmp_bignum::ExpMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
181
4.14k
bool ExpMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
182
4.14k
    bool ret = false;
183
184
4.14k
    GET_WHICH(2);
185
186
4.14k
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
187
188
#if defined(HAVE_MINI_GMP)
189
    /* Avoid timeouts */
190
    CF_CHECK_LTE(mpz_sizeinbase(bn[0].GetPtr(), 2), 2000);
191
    CF_CHECK_LTE(mpz_sizeinbase(bn[1].GetPtr(), 2), 2000);
192
    CF_CHECK_LTE(mpz_sizeinbase(bn[2].GetPtr(), 2), 2000);
193
#endif
194
195
4.07k
    switch ( which ) {
196
3.31k
        case    0:
197
            /* "Negative exp is supported if the inverse base-1 mod mod exists.
198
             *  If an inverse doesn’t exist then a divide by zero is raised."
199
             */
200
3.31k
            CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
201
202
3.31k
            /* noret */ mpz_powm(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
203
3.31k
            CF_NORET(bn.CopyResult(res));
204
3.31k
            break;
205
181
        case    1:
206
181
            {
207
181
                const auto bn1 = bn[1].GetUnsignedLong();
208
181
                CF_CHECK_NE(bn1, std::nullopt);
209
210
31
                /* noret */ mpz_powm_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1, bn[2].GetPtr());
211
31
                CF_NORET(bn.CopyResult(res));
212
31
            }
213
0
            break;
214
0
#if !defined(HAVE_MINI_GMP)
215
576
        case    2:
216
576
            {
217
576
                CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
218
219
                /* "It is required that exp > 0 and that mod is odd." */
220
576
                CF_CHECK_GT(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
221
222
565
                const auto ptr = bn[2].GetPtr();
223
565
                CF_CHECK_EQ(mpz_odd_p(ptr), 1);
224
225
327
                /* noret */ mpz_powm_sec(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
226
327
                CF_NORET(bn.CopyResult(res));
227
327
            }
228
0
            break;
229
0
#endif
230
0
        default:
231
0
            return false;
232
4.07k
    }
233
234
3.67k
    ret = true;
235
236
4.14k
end:
237
4.14k
    return ret;
238
3.67k
}
cryptofuzz::module::libgmp_bignum::ExpMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
181
307
bool ExpMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
182
307
    bool ret = false;
183
184
307
    GET_WHICH(2);
185
186
307
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
187
188
301
#if defined(HAVE_MINI_GMP)
189
    /* Avoid timeouts */
190
301
    CF_CHECK_LTE(mpz_sizeinbase(bn[0].GetPtr(), 2), 2000);
191
298
    CF_CHECK_LTE(mpz_sizeinbase(bn[1].GetPtr(), 2), 2000);
192
230
    CF_CHECK_LTE(mpz_sizeinbase(bn[2].GetPtr(), 2), 2000);
193
109
#endif
194
195
109
    switch ( which ) {
196
73
        case    0:
197
            /* "Negative exp is supported if the inverse base-1 mod mod exists.
198
             *  If an inverse doesn’t exist then a divide by zero is raised."
199
             */
200
73
            CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
201
202
73
            /* noret */ mpz_powm(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
203
73
            CF_NORET(bn.CopyResult(res));
204
73
            break;
205
16
        case    1:
206
16
            {
207
16
                const auto bn1 = bn[1].GetUnsignedLong();
208
16
                CF_CHECK_NE(bn1, std::nullopt);
209
210
0
                /* noret */ mpz_powm_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1, bn[2].GetPtr());
211
0
                CF_NORET(bn.CopyResult(res));
212
0
            }
213
0
            break;
214
#if !defined(HAVE_MINI_GMP)
215
        case    2:
216
            {
217
                CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
218
219
                /* "It is required that exp > 0 and that mod is odd." */
220
                CF_CHECK_GT(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
221
222
                const auto ptr = bn[2].GetPtr();
223
                CF_CHECK_EQ(mpz_odd_p(ptr), 1);
224
225
                /* noret */ mpz_powm_sec(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
226
                CF_NORET(bn.CopyResult(res));
227
            }
228
            break;
229
#endif
230
20
        default:
231
20
            return false;
232
109
    }
233
234
73
    ret = true;
235
236
287
end:
237
287
    return ret;
238
73
}
239
240
enum GCDType : uint8_t {
241
    GCD = 0,
242
    ExtGCD_X = 1,
243
    ExtGCD_Y = 2,
244
};
245
246
366
static void GCD_ExtGCD_SetResult(mpz_ptr res, const mpz_ptr X, const mpz_ptr Y, const GCDType type) {
247
366
    if ( type == GCDType::GCD ) {
248
        /* do nothing */
249
220
    } else if ( type == GCDType::ExtGCD_X ) {
250
160
        /* noret */ mpz_set(res, X);
251
160
    } else if ( type == GCDType::ExtGCD_Y ) {
252
60
        /* noret */ mpz_set(res, Y);
253
60
    } else {
254
0
        CF_UNREACHABLE();
255
0
    }
256
366
}
bn_ops.cpp:cryptofuzz::module::libgmp_bignum::GCD_ExtGCD_SetResult(__mpz_struct*, __mpz_struct*, __mpz_struct*, cryptofuzz::module::libgmp_bignum::GCDType)
Line
Count
Source
246
183
static void GCD_ExtGCD_SetResult(mpz_ptr res, const mpz_ptr X, const mpz_ptr Y, const GCDType type) {
247
183
    if ( type == GCDType::GCD ) {
248
        /* do nothing */
249
110
    } else if ( type == GCDType::ExtGCD_X ) {
250
80
        /* noret */ mpz_set(res, X);
251
80
    } else if ( type == GCDType::ExtGCD_Y ) {
252
30
        /* noret */ mpz_set(res, Y);
253
30
    } else {
254
0
        CF_UNREACHABLE();
255
0
    }
256
183
}
bn_ops.cpp:cryptofuzz::module::libgmp_bignum::GCD_ExtGCD_SetResult(__mpz_struct*, __mpz_struct*, __mpz_struct*, cryptofuzz::module::libgmp_bignum::GCDType)
Line
Count
Source
246
183
static void GCD_ExtGCD_SetResult(mpz_ptr res, const mpz_ptr X, const mpz_ptr Y, const GCDType type) {
247
183
    if ( type == GCDType::GCD ) {
248
        /* do nothing */
249
110
    } else if ( type == GCDType::ExtGCD_X ) {
250
80
        /* noret */ mpz_set(res, X);
251
80
    } else if ( type == GCDType::ExtGCD_Y ) {
252
30
        /* noret */ mpz_set(res, Y);
253
30
    } else {
254
0
        CF_UNREACHABLE();
255
0
    }
256
183
}
257
258
1.25k
static bool GCD_ExtGCD(Datasource& ds, Bignum& res, BignumCluster& bn, const GCDType type) {
259
1.25k
    bool ret = false;
260
261
1.25k
    GET_WHICH(2);
262
1.25k
    switch ( which ) {
263
782
        case    0:
264
782
            CF_CHECK_EQ(type, GCDType::GCD);
265
684
            /* noret */ mpz_gcd(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
266
684
            CF_NORET(bn.CopyResult(res));
267
684
            break;
268
108
        case    1:
269
108
            {
270
108
                CF_CHECK_EQ(type, GCDType::GCD);
271
272
58
                const auto bn1 = bn[1].GetUnsignedLong();
273
58
                CF_CHECK_NE(bn1, std::nullopt);
274
275
8
                /* ignore ret */ mpz_gcd_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
276
16
                CF_NORET(bn.CopyResult(res));
277
16
            }
278
0
            break;
279
366
        case    2:
280
366
            {
281
366
                Bignum t1, t2;
282
283
183
                /* noret */ mpz_gcdext(res.GetPtr(), t1.GetPtr(), t2.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
284
366
                CF_NORET(GCD_ExtGCD_SetResult(res.GetPtr(), t1.GetPtr(), t2.GetPtr(), type));
285
366
            }
286
366
            break;
287
0
        default:
288
0
            return false;
289
1.25k
    }
290
291
1.06k
    ret = true;
292
293
1.25k
end:
294
1.25k
    return ret;
295
1.06k
}
bn_ops.cpp:cryptofuzz::module::libgmp_bignum::GCD_ExtGCD(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&, cryptofuzz::module::libgmp_bignum::GCDType)
Line
Count
Source
258
628
static bool GCD_ExtGCD(Datasource& ds, Bignum& res, BignumCluster& bn, const GCDType type) {
259
628
    bool ret = false;
260
261
628
    GET_WHICH(2);
262
628
    switch ( which ) {
263
391
        case    0:
264
391
            CF_CHECK_EQ(type, GCDType::GCD);
265
342
            /* noret */ mpz_gcd(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
266
342
            CF_NORET(bn.CopyResult(res));
267
342
            break;
268
54
        case    1:
269
54
            {
270
54
                CF_CHECK_EQ(type, GCDType::GCD);
271
272
29
                const auto bn1 = bn[1].GetUnsignedLong();
273
29
                CF_CHECK_NE(bn1, std::nullopt);
274
275
8
                /* ignore ret */ mpz_gcd_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
276
8
                CF_NORET(bn.CopyResult(res));
277
8
            }
278
0
            break;
279
183
        case    2:
280
183
            {
281
183
                Bignum t1, t2;
282
283
183
                /* noret */ mpz_gcdext(res.GetPtr(), t1.GetPtr(), t2.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
284
183
                CF_NORET(GCD_ExtGCD_SetResult(res.GetPtr(), t1.GetPtr(), t2.GetPtr(), type));
285
183
            }
286
183
            break;
287
0
        default:
288
0
            return false;
289
628
    }
290
291
533
    ret = true;
292
293
628
end:
294
628
    return ret;
295
533
}
bn_ops.cpp:cryptofuzz::module::libgmp_bignum::GCD_ExtGCD(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&, cryptofuzz::module::libgmp_bignum::GCDType)
Line
Count
Source
258
628
static bool GCD_ExtGCD(Datasource& ds, Bignum& res, BignumCluster& bn, const GCDType type) {
259
628
    bool ret = false;
260
261
628
    GET_WHICH(2);
262
628
    switch ( which ) {
263
391
        case    0:
264
391
            CF_CHECK_EQ(type, GCDType::GCD);
265
342
            /* noret */ mpz_gcd(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
266
342
            CF_NORET(bn.CopyResult(res));
267
342
            break;
268
54
        case    1:
269
54
            {
270
54
                CF_CHECK_EQ(type, GCDType::GCD);
271
272
29
                const auto bn1 = bn[1].GetUnsignedLong();
273
29
                CF_CHECK_NE(bn1, std::nullopt);
274
275
8
                /* ignore ret */ mpz_gcd_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
276
8
                CF_NORET(bn.CopyResult(res));
277
8
            }
278
0
            break;
279
183
        case    2:
280
183
            {
281
183
                Bignum t1, t2;
282
283
183
                /* noret */ mpz_gcdext(res.GetPtr(), t1.GetPtr(), t2.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
284
183
                CF_NORET(GCD_ExtGCD_SetResult(res.GetPtr(), t1.GetPtr(), t2.GetPtr(), type));
285
183
            }
286
183
            break;
287
0
        default:
288
0
            return false;
289
628
    }
290
291
533
    ret = true;
292
293
628
end:
294
628
    return ret;
295
533
}
296
297
444
bool GCD::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
298
444
    return GCD_ExtGCD(ds, res, bn, GCDType::GCD);
299
444
}
300
301
111
bool ExtGCD_X::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
302
111
    return GCD_ExtGCD(ds, res, bn, GCDType::ExtGCD_X);
303
111
}
304
305
73
bool ExtGCD_Y::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
306
73
    return GCD_ExtGCD(ds, res, bn, GCDType::ExtGCD_Y);
307
73
}
308
309
811
bool Jacobi::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
310
#if !defined(HAVE_MINI_GMP)
311
798
    GET_WHICH(2);
312
798
    switch ( which ) {
313
720
        case    0:
314
720
            res.Set( std::to_string(mpz_jacobi(bn[0].GetPtr(), bn[1].GetPtr())) );
315
720
            return true;
316
27
        case    1:
317
27
            {
318
27
                const auto bn1 = bn[1].GetSignedLong();
319
27
                CF_CHECK_NE(bn1, std::nullopt);
320
9
                res.Set( std::to_string(mpz_kronecker_si(bn[0].GetPtr(), *bn1)) );
321
9
            }
322
0
            return true;
323
51
        case    2:
324
51
            {
325
51
                const auto bn1 = bn[1].GetUnsignedLong();
326
51
                CF_CHECK_NE(bn1, std::nullopt);
327
13
                res.Set( std::to_string(mpz_kronecker_ui(bn[0].GetPtr(), *bn1)) );
328
13
            }
329
0
            return true;
330
0
        default:
331
0
            return false;
332
798
    }
333
334
56
end:
335
56
    return false;
336
#else
337
    (void)ds;
338
    (void)res;
339
    (void)bn;
340
341
    return false;
342
#endif
343
798
}
cryptofuzz::module::libgmp_bignum::Jacobi::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
309
798
bool Jacobi::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
310
798
#if !defined(HAVE_MINI_GMP)
311
798
    GET_WHICH(2);
312
798
    switch ( which ) {
313
720
        case    0:
314
720
            res.Set( std::to_string(mpz_jacobi(bn[0].GetPtr(), bn[1].GetPtr())) );
315
720
            return true;
316
27
        case    1:
317
27
            {
318
27
                const auto bn1 = bn[1].GetSignedLong();
319
27
                CF_CHECK_NE(bn1, std::nullopt);
320
9
                res.Set( std::to_string(mpz_kronecker_si(bn[0].GetPtr(), *bn1)) );
321
9
            }
322
0
            return true;
323
51
        case    2:
324
51
            {
325
51
                const auto bn1 = bn[1].GetUnsignedLong();
326
51
                CF_CHECK_NE(bn1, std::nullopt);
327
13
                res.Set( std::to_string(mpz_kronecker_ui(bn[0].GetPtr(), *bn1)) );
328
13
            }
329
0
            return true;
330
0
        default:
331
0
            return false;
332
798
    }
333
334
56
end:
335
56
    return false;
336
#else
337
    (void)ds;
338
    (void)res;
339
    (void)bn;
340
341
    return false;
342
#endif
343
798
}
cryptofuzz::module::libgmp_bignum::Jacobi::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
309
13
bool Jacobi::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
310
#if !defined(HAVE_MINI_GMP)
311
    GET_WHICH(2);
312
    switch ( which ) {
313
        case    0:
314
            res.Set( std::to_string(mpz_jacobi(bn[0].GetPtr(), bn[1].GetPtr())) );
315
            return true;
316
        case    1:
317
            {
318
                const auto bn1 = bn[1].GetSignedLong();
319
                CF_CHECK_NE(bn1, std::nullopt);
320
                res.Set( std::to_string(mpz_kronecker_si(bn[0].GetPtr(), *bn1)) );
321
            }
322
            return true;
323
        case    2:
324
            {
325
                const auto bn1 = bn[1].GetUnsignedLong();
326
                CF_CHECK_NE(bn1, std::nullopt);
327
                res.Set( std::to_string(mpz_kronecker_ui(bn[0].GetPtr(), *bn1)) );
328
            }
329
            return true;
330
        default:
331
            return false;
332
    }
333
334
end:
335
    return false;
336
#else
337
13
    (void)ds;
338
13
    (void)res;
339
13
    (void)bn;
340
341
13
    return false;
342
13
#endif
343
13
}
344
345
101
bool Cmp::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
346
101
    bool ret = false;
347
348
101
    int cmp;
349
350
101
    GET_WHICH(2);
351
101
    switch ( which ) {
352
46
        case    0:
353
46
            cmp = mpz_cmp(bn[0].GetPtr(), bn[1].GetPtr());
354
46
            break;
355
34
        case    1:
356
34
            {
357
34
                const auto bn1 = bn[1].GetSignedLong();
358
34
                CF_CHECK_NE(bn1, std::nullopt);
359
360
26
                cmp = mpz_cmp_si(bn[0].GetPtr(), *bn1);
361
26
            }
362
0
            break;
363
21
        case    2:
364
21
            {
365
21
                const auto bn1 = bn[1].GetUnsignedLong();
366
21
                CF_CHECK_NE(bn1, std::nullopt);
367
368
7
                cmp = mpz_cmp_ui(bn[0].GetPtr(), *bn1);
369
7
            }
370
0
            break;
371
0
        default:
372
0
            goto end;
373
101
    }
374
375
79
    if ( cmp < 0 ) {
376
20
        res.Set("-1");
377
59
    } else if ( cmp > 0 ) {
378
31
        res.Set("1");
379
31
    } else {
380
28
        res.Set("0");
381
28
    }
382
383
79
    ret = true;
384
385
101
end:
386
101
    return ret;
387
79
}
cryptofuzz::module::libgmp_bignum::Cmp::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
345
88
bool Cmp::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
346
88
    bool ret = false;
347
348
88
    int cmp;
349
350
88
    GET_WHICH(2);
351
88
    switch ( which ) {
352
41
        case    0:
353
41
            cmp = mpz_cmp(bn[0].GetPtr(), bn[1].GetPtr());
354
41
            break;
355
28
        case    1:
356
28
            {
357
28
                const auto bn1 = bn[1].GetSignedLong();
358
28
                CF_CHECK_NE(bn1, std::nullopt);
359
360
22
                cmp = mpz_cmp_si(bn[0].GetPtr(), *bn1);
361
22
            }
362
0
            break;
363
19
        case    2:
364
19
            {
365
19
                const auto bn1 = bn[1].GetUnsignedLong();
366
19
                CF_CHECK_NE(bn1, std::nullopt);
367
368
7
                cmp = mpz_cmp_ui(bn[0].GetPtr(), *bn1);
369
7
            }
370
0
            break;
371
0
        default:
372
0
            goto end;
373
88
    }
374
375
70
    if ( cmp < 0 ) {
376
17
        res.Set("-1");
377
53
    } else if ( cmp > 0 ) {
378
30
        res.Set("1");
379
30
    } else {
380
23
        res.Set("0");
381
23
    }
382
383
70
    ret = true;
384
385
88
end:
386
88
    return ret;
387
70
}
cryptofuzz::module::libgmp_bignum::Cmp::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
345
13
bool Cmp::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
346
13
    bool ret = false;
347
348
13
    int cmp;
349
350
13
    GET_WHICH(2);
351
13
    switch ( which ) {
352
5
        case    0:
353
5
            cmp = mpz_cmp(bn[0].GetPtr(), bn[1].GetPtr());
354
5
            break;
355
6
        case    1:
356
6
            {
357
6
                const auto bn1 = bn[1].GetSignedLong();
358
6
                CF_CHECK_NE(bn1, std::nullopt);
359
360
4
                cmp = mpz_cmp_si(bn[0].GetPtr(), *bn1);
361
4
            }
362
0
            break;
363
2
        case    2:
364
2
            {
365
2
                const auto bn1 = bn[1].GetUnsignedLong();
366
2
                CF_CHECK_NE(bn1, std::nullopt);
367
368
0
                cmp = mpz_cmp_ui(bn[0].GetPtr(), *bn1);
369
0
            }
370
0
            break;
371
0
        default:
372
0
            goto end;
373
13
    }
374
375
9
    if ( cmp < 0 ) {
376
3
        res.Set("-1");
377
6
    } else if ( cmp > 0 ) {
378
1
        res.Set("1");
379
5
    } else {
380
5
        res.Set("0");
381
5
    }
382
383
9
    ret = true;
384
385
13
end:
386
13
    return ret;
387
9
}
388
389
283
bool LCM::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
390
283
    bool ret = false;
391
392
283
    GET_WHICH(1);
393
283
    switch ( which ) {
394
248
        case    0:
395
248
            /* noret */ mpz_lcm(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
396
248
            CF_NORET(bn.CopyResult(res));
397
248
            break;
398
35
        case    1:
399
35
            {
400
35
                const auto bn1 = bn[1].GetUnsignedLong();
401
35
                CF_CHECK_NE(bn1, std::nullopt);
402
403
9
                /* noret */ mpz_lcm_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
404
10
                CF_NORET(bn.CopyResult(res));
405
10
            }
406
0
            break;
407
0
        default:
408
0
            return false;
409
283
    }
410
411
    /* Negative not supported */
412
258
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
413
258
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
414
415
258
    ret = true;
416
417
283
end:
418
283
    return ret;
419
258
}
cryptofuzz::module::libgmp_bignum::LCM::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
389
275
bool LCM::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
390
275
    bool ret = false;
391
392
275
    GET_WHICH(1);
393
275
    switch ( which ) {
394
242
        case    0:
395
242
            /* noret */ mpz_lcm(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
396
242
            CF_NORET(bn.CopyResult(res));
397
242
            break;
398
33
        case    1:
399
33
            {
400
33
                const auto bn1 = bn[1].GetUnsignedLong();
401
33
                CF_CHECK_NE(bn1, std::nullopt);
402
403
9
                /* noret */ mpz_lcm_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
404
9
                CF_NORET(bn.CopyResult(res));
405
9
            }
406
0
            break;
407
0
        default:
408
0
            return false;
409
275
    }
410
411
    /* Negative not supported */
412
251
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
413
251
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
414
415
251
    ret = true;
416
417
275
end:
418
275
    return ret;
419
251
}
cryptofuzz::module::libgmp_bignum::LCM::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
389
8
bool LCM::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
390
8
    bool ret = false;
391
392
8
    GET_WHICH(1);
393
8
    switch ( which ) {
394
6
        case    0:
395
6
            /* noret */ mpz_lcm(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
396
6
            CF_NORET(bn.CopyResult(res));
397
6
            break;
398
2
        case    1:
399
2
            {
400
2
                const auto bn1 = bn[1].GetUnsignedLong();
401
2
                CF_CHECK_NE(bn1, std::nullopt);
402
403
1
                /* noret */ mpz_lcm_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
404
1
                CF_NORET(bn.CopyResult(res));
405
1
            }
406
0
            break;
407
0
        default:
408
0
            return false;
409
8
    }
410
411
    /* Negative not supported */
412
7
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
413
7
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
414
415
7
    ret = true;
416
417
8
end:
418
8
    return ret;
419
7
}
420
421
178
bool Xor::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
422
178
    (void)ds;
423
424
89
    /* noret */ mpz_xor(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
425
178
    CF_NORET(bn.CopyResult(res));
426
427
178
    return true;
428
178
}
cryptofuzz::module::libgmp_bignum::Xor::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
421
89
bool Xor::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
422
89
    (void)ds;
423
424
89
    /* noret */ mpz_xor(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
425
89
    CF_NORET(bn.CopyResult(res));
426
427
89
    return true;
428
89
}
cryptofuzz::module::libgmp_bignum::Xor::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
421
89
bool Xor::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
422
89
    (void)ds;
423
424
89
    /* noret */ mpz_xor(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
425
89
    CF_NORET(bn.CopyResult(res));
426
427
89
    return true;
428
89
}
429
430
150
bool And::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
431
150
    (void)ds;
432
433
75
    /* noret */ mpz_and(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
434
150
    CF_NORET(bn.CopyResult(res));
435
436
150
    return true;
437
150
}
cryptofuzz::module::libgmp_bignum::And::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
430
75
bool And::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
431
75
    (void)ds;
432
433
75
    /* noret */ mpz_and(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
434
75
    CF_NORET(bn.CopyResult(res));
435
436
75
    return true;
437
75
}
cryptofuzz::module::libgmp_bignum::And::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
430
75
bool And::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
431
75
    (void)ds;
432
433
75
    /* noret */ mpz_and(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
434
75
    CF_NORET(bn.CopyResult(res));
435
436
75
    return true;
437
75
}
438
439
84
bool Abs::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
440
84
    (void)ds;
441
442
42
    /* noret */ mpz_abs(bn.GetResPtr(), bn[0].GetPtr());
443
84
    CF_NORET(bn.CopyResult(res));
444
445
84
    return true;
446
84
}
cryptofuzz::module::libgmp_bignum::Abs::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
439
42
bool Abs::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
440
42
    (void)ds;
441
442
42
    /* noret */ mpz_abs(bn.GetResPtr(), bn[0].GetPtr());
443
42
    CF_NORET(bn.CopyResult(res));
444
445
42
    return true;
446
42
}
cryptofuzz::module::libgmp_bignum::Abs::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
439
42
bool Abs::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
440
42
    (void)ds;
441
442
42
    /* noret */ mpz_abs(bn.GetResPtr(), bn[0].GetPtr());
443
42
    CF_NORET(bn.CopyResult(res));
444
445
42
    return true;
446
42
}
447
448
140
bool Neg::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
449
140
    (void)ds;
450
451
70
    /* noret */ mpz_neg(bn.GetResPtr(), bn[0].GetPtr());
452
140
    CF_NORET(bn.CopyResult(res));
453
454
140
    return true;
455
140
}
cryptofuzz::module::libgmp_bignum::Neg::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
448
70
bool Neg::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
449
70
    (void)ds;
450
451
70
    /* noret */ mpz_neg(bn.GetResPtr(), bn[0].GetPtr());
452
70
    CF_NORET(bn.CopyResult(res));
453
454
70
    return true;
455
70
}
cryptofuzz::module::libgmp_bignum::Neg::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
448
70
bool Neg::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
449
70
    (void)ds;
450
451
70
    /* noret */ mpz_neg(bn.GetResPtr(), bn[0].GetPtr());
452
70
    CF_NORET(bn.CopyResult(res));
453
454
70
    return true;
455
70
}
456
457
216
bool Sqrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
458
216
    bool ret = false;
459
216
    (void)ds;
460
461
216
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
462
463
193
    /* noret */ mpz_sqrt(bn.GetResPtr(), bn[0].GetPtr());
464
216
    CF_NORET(bn.CopyResult(res));
465
216
    ret = true;
466
467
216
end:
468
216
    return ret;
469
216
}
cryptofuzz::module::libgmp_bignum::Sqrt::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
457
193
bool Sqrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
458
193
    bool ret = false;
459
193
    (void)ds;
460
461
193
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
462
463
193
    /* noret */ mpz_sqrt(bn.GetResPtr(), bn[0].GetPtr());
464
193
    CF_NORET(bn.CopyResult(res));
465
193
    ret = true;
466
467
193
end:
468
193
    return ret;
469
193
}
cryptofuzz::module::libgmp_bignum::Sqrt::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
457
23
bool Sqrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
458
23
    bool ret = false;
459
23
    (void)ds;
460
461
23
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
462
463
23
    /* noret */ mpz_sqrt(bn.GetResPtr(), bn[0].GetPtr());
464
23
    CF_NORET(bn.CopyResult(res));
465
23
    ret = true;
466
467
23
end:
468
23
    return ret;
469
23
}
470
471
77
bool SqrtCeil::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
472
77
    bool ret = false;
473
77
    (void)ds;
474
475
77
    libgmp_bignum::Bignum rem;
476
477
77
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
478
479
61
    /* noret */ mpz_sqrt(res.GetPtr(), bn[0].GetPtr());
480
77
    /* noret */ mpz_sqrtrem(bn[1].GetPtr(), rem.GetPtr(), bn[0].GetPtr());
481
77
    if ( mpz_sgn(rem.GetPtr()) != 0 ) {
482
73
        /* noret */ mpz_add_ui(res.GetPtr(), res.GetPtr(), 1);
483
73
    }
484
77
    ret = true;
485
486
77
end:
487
77
    return ret;
488
77
}
cryptofuzz::module::libgmp_bignum::SqrtCeil::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
471
61
bool SqrtCeil::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
472
61
    bool ret = false;
473
61
    (void)ds;
474
475
61
    libgmp_bignum::Bignum rem;
476
477
61
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
478
479
61
    /* noret */ mpz_sqrt(res.GetPtr(), bn[0].GetPtr());
480
61
    /* noret */ mpz_sqrtrem(bn[1].GetPtr(), rem.GetPtr(), bn[0].GetPtr());
481
61
    if ( mpz_sgn(rem.GetPtr()) != 0 ) {
482
57
        /* noret */ mpz_add_ui(res.GetPtr(), res.GetPtr(), 1);
483
57
    }
484
61
    ret = true;
485
486
61
end:
487
61
    return ret;
488
61
}
cryptofuzz::module::libgmp_bignum::SqrtCeil::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
471
16
bool SqrtCeil::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
472
16
    bool ret = false;
473
16
    (void)ds;
474
475
16
    libgmp_bignum::Bignum rem;
476
477
16
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
478
479
16
    /* noret */ mpz_sqrt(res.GetPtr(), bn[0].GetPtr());
480
16
    /* noret */ mpz_sqrtrem(bn[1].GetPtr(), rem.GetPtr(), bn[0].GetPtr());
481
16
    if ( mpz_sgn(rem.GetPtr()) != 0 ) {
482
16
        /* noret */ mpz_add_ui(res.GetPtr(), res.GetPtr(), 1);
483
16
    }
484
16
    ret = true;
485
486
16
end:
487
16
    return ret;
488
16
}
489
490
238
bool Sqr::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
491
238
    (void)ds;
492
493
119
    /* noret */ mpz_pow_ui(bn.GetResPtr(), bn[0].GetPtr(), 2);
494
238
    CF_NORET(bn.CopyResult(res));
495
496
238
    return true;
497
238
}
cryptofuzz::module::libgmp_bignum::Sqr::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
490
119
bool Sqr::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
491
119
    (void)ds;
492
493
119
    /* noret */ mpz_pow_ui(bn.GetResPtr(), bn[0].GetPtr(), 2);
494
119
    CF_NORET(bn.CopyResult(res));
495
496
119
    return true;
497
119
}
cryptofuzz::module::libgmp_bignum::Sqr::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
490
119
bool Sqr::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
491
119
    (void)ds;
492
493
119
    /* noret */ mpz_pow_ui(bn.GetResPtr(), bn[0].GetPtr(), 2);
494
119
    CF_NORET(bn.CopyResult(res));
495
496
119
    return true;
497
119
}
498
499
54
bool CmpAbs::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
500
54
    bool ret = false;
501
502
54
    int cmp;
503
504
54
    GET_WHICH(1);
505
54
    switch ( which ) {
506
34
        case    0:
507
34
            cmp = mpz_cmpabs(bn[0].GetPtr(), bn[1].GetPtr());
508
34
            break;
509
20
        case    1:
510
20
            {
511
20
                const auto bn1 = bn[1].GetUnsignedLong();
512
20
                CF_CHECK_NE(bn1, std::nullopt);
513
514
6
                cmp = mpz_cmpabs_ui(bn[0].GetPtr(), *bn1);
515
6
            }
516
0
            break;
517
0
        default:
518
0
            goto end;
519
54
    }
520
521
40
    if ( cmp < 0 ) {
522
10
        res.Set("-1");
523
30
    } else if ( cmp > 0 ) {
524
22
        res.Set("1");
525
22
    } else {
526
8
        res.Set("0");
527
8
    }
528
529
40
    ret = true;
530
531
54
end:
532
54
    return ret;
533
40
}
cryptofuzz::module::libgmp_bignum::CmpAbs::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
499
27
bool CmpAbs::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
500
27
    bool ret = false;
501
502
27
    int cmp;
503
504
27
    GET_WHICH(1);
505
27
    switch ( which ) {
506
17
        case    0:
507
17
            cmp = mpz_cmpabs(bn[0].GetPtr(), bn[1].GetPtr());
508
17
            break;
509
10
        case    1:
510
10
            {
511
10
                const auto bn1 = bn[1].GetUnsignedLong();
512
10
                CF_CHECK_NE(bn1, std::nullopt);
513
514
3
                cmp = mpz_cmpabs_ui(bn[0].GetPtr(), *bn1);
515
3
            }
516
0
            break;
517
0
        default:
518
0
            goto end;
519
27
    }
520
521
20
    if ( cmp < 0 ) {
522
5
        res.Set("-1");
523
15
    } else if ( cmp > 0 ) {
524
11
        res.Set("1");
525
11
    } else {
526
4
        res.Set("0");
527
4
    }
528
529
20
    ret = true;
530
531
27
end:
532
27
    return ret;
533
20
}
cryptofuzz::module::libgmp_bignum::CmpAbs::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
499
27
bool CmpAbs::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
500
27
    bool ret = false;
501
502
27
    int cmp;
503
504
27
    GET_WHICH(1);
505
27
    switch ( which ) {
506
17
        case    0:
507
17
            cmp = mpz_cmpabs(bn[0].GetPtr(), bn[1].GetPtr());
508
17
            break;
509
10
        case    1:
510
10
            {
511
10
                const auto bn1 = bn[1].GetUnsignedLong();
512
10
                CF_CHECK_NE(bn1, std::nullopt);
513
514
3
                cmp = mpz_cmpabs_ui(bn[0].GetPtr(), *bn1);
515
3
            }
516
0
            break;
517
0
        default:
518
0
            goto end;
519
27
    }
520
521
20
    if ( cmp < 0 ) {
522
5
        res.Set("-1");
523
15
    } else if ( cmp > 0 ) {
524
11
        res.Set("1");
525
11
    } else {
526
4
        res.Set("0");
527
4
    }
528
529
20
    ret = true;
530
531
27
end:
532
27
    return ret;
533
20
}
534
535
24
bool IsZero::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
536
24
    (void)ds;
537
538
24
    res.Set( std::to_string(mpz_sgn(bn[0].GetPtr()) == 0 ? 1 : 0) );
539
540
24
    return true;
541
24
}
cryptofuzz::module::libgmp_bignum::IsZero::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
535
21
bool IsZero::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
536
21
    (void)ds;
537
538
21
    res.Set( std::to_string(mpz_sgn(bn[0].GetPtr()) == 0 ? 1 : 0) );
539
540
21
    return true;
541
21
}
cryptofuzz::module::libgmp_bignum::IsZero::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
535
3
bool IsZero::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
536
3
    (void)ds;
537
538
3
    res.Set( std::to_string(mpz_sgn(bn[0].GetPtr()) == 0 ? 1 : 0) );
539
540
3
    return true;
541
3
}
542
543
22
bool IsNeg::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
544
22
    (void)ds;
545
546
22
    res.Set( std::to_string(mpz_sgn(bn[0].GetPtr()) < 0 ? 1 : 0) );
547
548
22
    return true;
549
22
}
cryptofuzz::module::libgmp_bignum::IsNeg::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
543
20
bool IsNeg::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
544
20
    (void)ds;
545
546
20
    res.Set( std::to_string(mpz_sgn(bn[0].GetPtr()) < 0 ? 1 : 0) );
547
548
20
    return true;
549
20
}
cryptofuzz::module::libgmp_bignum::IsNeg::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
543
2
bool IsNeg::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
544
2
    (void)ds;
545
546
2
    res.Set( std::to_string(mpz_sgn(bn[0].GetPtr()) < 0 ? 1 : 0) );
547
548
2
    return true;
549
2
}
550
551
113
bool AddMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
552
113
    (void)ds;
553
113
    bool ret = false;
554
555
113
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
556
557
73
    /* noret */ mpz_add(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
558
94
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
559
560
    /* Negative modulus currently not supported */
561
94
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
562
563
94
    ret = true;
564
565
113
end:
566
113
    return ret;
567
94
}
cryptofuzz::module::libgmp_bignum::AddMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
551
87
bool AddMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
552
87
    (void)ds;
553
87
    bool ret = false;
554
555
87
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
556
557
73
    /* noret */ mpz_add(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
558
73
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
559
560
    /* Negative modulus currently not supported */
561
73
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
562
563
73
    ret = true;
564
565
87
end:
566
87
    return ret;
567
73
}
cryptofuzz::module::libgmp_bignum::AddMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
551
26
bool AddMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
552
26
    (void)ds;
553
26
    bool ret = false;
554
555
26
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
556
557
21
    /* noret */ mpz_add(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
558
21
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
559
560
    /* Negative modulus currently not supported */
561
21
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
562
563
21
    ret = true;
564
565
26
end:
566
26
    return ret;
567
21
}
568
569
134
bool SubMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
570
134
    (void)ds;
571
134
    bool ret = false;
572
573
134
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
574
575
91
    /* noret */ mpz_sub(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
576
120
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
577
578
    /* Negative modulus currently not supported */
579
120
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
580
581
120
    ret = true;
582
583
134
end:
584
134
    return ret;
585
120
}
cryptofuzz::module::libgmp_bignum::SubMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
569
103
bool SubMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
570
103
    (void)ds;
571
103
    bool ret = false;
572
573
103
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
574
575
91
    /* noret */ mpz_sub(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
576
91
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
577
578
    /* Negative modulus currently not supported */
579
91
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
580
581
91
    ret = true;
582
583
103
end:
584
103
    return ret;
585
91
}
cryptofuzz::module::libgmp_bignum::SubMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
569
31
bool SubMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
570
31
    (void)ds;
571
31
    bool ret = false;
572
573
31
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
574
575
29
    /* noret */ mpz_sub(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
576
29
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
577
578
    /* Negative modulus currently not supported */
579
29
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
580
581
29
    ret = true;
582
583
31
end:
584
31
    return ret;
585
29
}
586
587
141
bool MulMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
588
141
    (void)ds;
589
141
    bool ret = false;
590
591
141
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
592
593
99
    /* noret */ mpz_mul(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
594
114
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
595
596
    /* Negative modulus currently not supported */
597
114
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
598
599
114
    ret = true;
600
601
141
end:
602
141
    return ret;
603
114
}
cryptofuzz::module::libgmp_bignum::MulMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
587
121
bool MulMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
588
121
    (void)ds;
589
121
    bool ret = false;
590
591
121
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
592
593
99
    /* noret */ mpz_mul(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
594
99
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
595
596
    /* Negative modulus currently not supported */
597
99
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
598
599
99
    ret = true;
600
601
121
end:
602
121
    return ret;
603
99
}
cryptofuzz::module::libgmp_bignum::MulMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
587
20
bool MulMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
588
20
    (void)ds;
589
20
    bool ret = false;
590
591
20
    CF_CHECK_NE(mpz_cmp_ui(bn[2].GetPtr(), 0), 0);
592
593
15
    /* noret */ mpz_mul(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
594
15
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[2].GetPtr());
595
596
    /* Negative modulus currently not supported */
597
15
    CF_CHECK_GTE(mpz_sgn(bn[2].GetPtr()), 0);
598
599
15
    ret = true;
600
601
20
end:
602
20
    return ret;
603
15
}
604
605
61
bool SqrMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
606
61
    (void)ds;
607
61
    bool ret = false;
608
609
61
    CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
610
611
39
    /* noret */ mpz_pow_ui(res.GetPtr(), bn[0].GetPtr(), 2);
612
51
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[1].GetPtr());
613
614
    /* Negative modulus currently not supported */
615
51
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
616
617
51
    ret = true;
618
619
61
end:
620
61
    return ret;
621
51
}
cryptofuzz::module::libgmp_bignum::SqrMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
605
48
bool SqrMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
606
48
    (void)ds;
607
48
    bool ret = false;
608
609
48
    CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
610
611
39
    /* noret */ mpz_pow_ui(res.GetPtr(), bn[0].GetPtr(), 2);
612
39
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[1].GetPtr());
613
614
    /* Negative modulus currently not supported */
615
39
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
616
617
39
    ret = true;
618
619
48
end:
620
48
    return ret;
621
39
}
cryptofuzz::module::libgmp_bignum::SqrMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
605
13
bool SqrMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
606
13
    (void)ds;
607
13
    bool ret = false;
608
609
13
    CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
610
611
12
    /* noret */ mpz_pow_ui(res.GetPtr(), bn[0].GetPtr(), 2);
612
12
    /* noret */ mpz_mod(res.GetPtr(), res.GetPtr(), bn[1].GetPtr());
613
614
    /* Negative modulus currently not supported */
615
12
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
616
617
12
    ret = true;
618
619
13
end:
620
13
    return ret;
621
12
}
622
623
26
bool Mod_NIST_192::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
624
26
    (void)ds;
625
626
26
    Bignum p192;
627
26
    p192.Set("6277101735386680763835789423207666416083908700390324961279");
628
629
13
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p192.GetPtr());
630
631
26
    return true;
632
26
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_192::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
623
13
bool Mod_NIST_192::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
624
13
    (void)ds;
625
626
13
    Bignum p192;
627
13
    p192.Set("6277101735386680763835789423207666416083908700390324961279");
628
629
13
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p192.GetPtr());
630
631
13
    return true;
632
13
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_192::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
623
13
bool Mod_NIST_192::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
624
13
    (void)ds;
625
626
13
    Bignum p192;
627
13
    p192.Set("6277101735386680763835789423207666416083908700390324961279");
628
629
13
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p192.GetPtr());
630
631
13
    return true;
632
13
}
633
634
34
bool Mod_NIST_224::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
635
34
    (void)ds;
636
637
34
    Bignum p224;
638
34
    p224.Set("26959946667150639794667015087019630673557916260026308143510066298881");
639
640
17
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p224.GetPtr());
641
642
34
    return true;
643
34
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_224::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
634
17
bool Mod_NIST_224::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
635
17
    (void)ds;
636
637
17
    Bignum p224;
638
17
    p224.Set("26959946667150639794667015087019630673557916260026308143510066298881");
639
640
17
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p224.GetPtr());
641
642
17
    return true;
643
17
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_224::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
634
17
bool Mod_NIST_224::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
635
17
    (void)ds;
636
637
17
    Bignum p224;
638
17
    p224.Set("26959946667150639794667015087019630673557916260026308143510066298881");
639
640
17
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p224.GetPtr());
641
642
17
    return true;
643
17
}
644
645
38
bool Mod_NIST_256::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
646
38
    (void)ds;
647
648
38
    Bignum p256;
649
38
    p256.Set("115792089210356248762697446949407573530086143415290314195533631308867097853951");
650
651
19
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p256.GetPtr());
652
653
38
    return true;
654
38
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_256::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
645
19
bool Mod_NIST_256::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
646
19
    (void)ds;
647
648
19
    Bignum p256;
649
19
    p256.Set("115792089210356248762697446949407573530086143415290314195533631308867097853951");
650
651
19
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p256.GetPtr());
652
653
19
    return true;
654
19
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_256::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
645
19
bool Mod_NIST_256::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
646
19
    (void)ds;
647
648
19
    Bignum p256;
649
19
    p256.Set("115792089210356248762697446949407573530086143415290314195533631308867097853951");
650
651
19
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p256.GetPtr());
652
653
19
    return true;
654
19
}
655
656
32
bool Mod_NIST_384::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
657
32
    (void)ds;
658
659
32
    Bignum p384;
660
32
    p384.Set("39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319");
661
662
16
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p384.GetPtr());
663
664
32
    return true;
665
32
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_384::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
656
16
bool Mod_NIST_384::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
657
16
    (void)ds;
658
659
16
    Bignum p384;
660
16
    p384.Set("39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319");
661
662
16
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p384.GetPtr());
663
664
16
    return true;
665
16
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_384::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
656
16
bool Mod_NIST_384::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
657
16
    (void)ds;
658
659
16
    Bignum p384;
660
16
    p384.Set("39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319");
661
662
16
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p384.GetPtr());
663
664
16
    return true;
665
16
}
666
667
22
bool Mod_NIST_521::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
668
22
    (void)ds;
669
670
22
    Bignum p521;
671
22
    p521.Set("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151");
672
673
11
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p521.GetPtr());
674
675
22
    return true;
676
22
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_521::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
667
11
bool Mod_NIST_521::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
668
11
    (void)ds;
669
670
11
    Bignum p521;
671
11
    p521.Set("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151");
672
673
11
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p521.GetPtr());
674
675
11
    return true;
676
11
}
cryptofuzz::module::libgmp_bignum::Mod_NIST_521::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
667
11
bool Mod_NIST_521::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
668
11
    (void)ds;
669
670
11
    Bignum p521;
671
11
    p521.Set("6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151");
672
673
11
    /* noret */ mpz_mod(res.GetPtr(), bn[0].GetPtr(), p521.GetPtr());
674
675
11
    return true;
676
11
}
677
678
44
bool SetBit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
679
44
    (void)ds;
680
44
    bool ret = false;
681
682
44
    const auto position_sl = bn[1].GetSignedLong();
683
44
    CF_CHECK_NE(position_sl, std::nullopt);
684
44
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
685
44
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
686
687
43
    /* noret */ mpz_setbit(bn.GetDestPtr(0), *position_sl);
688
44
    /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
689
690
44
    ret = true;
691
692
44
end:
693
44
    return ret;
694
44
}
cryptofuzz::module::libgmp_bignum::SetBit::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
678
43
bool SetBit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
679
43
    (void)ds;
680
43
    bool ret = false;
681
682
43
    const auto position_sl = bn[1].GetSignedLong();
683
43
    CF_CHECK_NE(position_sl, std::nullopt);
684
43
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
685
43
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
686
687
43
    /* noret */ mpz_setbit(bn.GetDestPtr(0), *position_sl);
688
43
    /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
689
690
43
    ret = true;
691
692
43
end:
693
43
    return ret;
694
43
}
cryptofuzz::module::libgmp_bignum::SetBit::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
678
1
bool SetBit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
679
1
    (void)ds;
680
1
    bool ret = false;
681
682
1
    const auto position_sl = bn[1].GetSignedLong();
683
1
    CF_CHECK_NE(position_sl, std::nullopt);
684
1
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
685
1
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
686
687
1
    /* noret */ mpz_setbit(bn.GetDestPtr(0), *position_sl);
688
1
    /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
689
690
1
    ret = true;
691
692
1
end:
693
1
    return ret;
694
1
}
695
696
25
bool ClearBit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
697
25
    (void)ds;
698
25
    bool ret = false;
699
700
25
    const auto position_sl = bn[1].GetSignedLong();
701
25
    CF_CHECK_NE(position_sl, std::nullopt);
702
12
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
703
704
10
    /* noret */ mpz_clrbit(bn.GetDestPtr(0), *position_sl);
705
12
    /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
706
707
12
    ret = true;
708
709
25
end:
710
25
    return ret;
711
12
}
cryptofuzz::module::libgmp_bignum::ClearBit::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
696
22
bool ClearBit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
697
22
    (void)ds;
698
22
    bool ret = false;
699
700
22
    const auto position_sl = bn[1].GetSignedLong();
701
22
    CF_CHECK_NE(position_sl, std::nullopt);
702
10
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
703
704
10
    /* noret */ mpz_clrbit(bn.GetDestPtr(0), *position_sl);
705
10
    /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
706
707
10
    ret = true;
708
709
22
end:
710
22
    return ret;
711
10
}
cryptofuzz::module::libgmp_bignum::ClearBit::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
696
3
bool ClearBit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
697
3
    (void)ds;
698
3
    bool ret = false;
699
700
3
    const auto position_sl = bn[1].GetSignedLong();
701
3
    CF_CHECK_NE(position_sl, std::nullopt);
702
2
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
703
704
2
    /* noret */ mpz_clrbit(bn.GetDestPtr(0), *position_sl);
705
2
    /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
706
707
2
    ret = true;
708
709
3
end:
710
3
    return ret;
711
2
}
712
713
48
bool Bit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
714
48
    (void)ds;
715
48
    bool ret = false;
716
717
48
    const auto position_sl = bn[1].GetSignedLong();
718
48
    CF_CHECK_NE(position_sl, std::nullopt);
719
720
    /* Negative not supported */
721
23
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
722
723
23
    res.Set( std::to_string(mpz_tstbit(bn[0].GetPtr(), *position_sl)) );
724
725
23
    ret = true;
726
727
48
end:
728
48
    return ret;
729
23
}
cryptofuzz::module::libgmp_bignum::Bit::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
713
45
bool Bit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
714
45
    (void)ds;
715
45
    bool ret = false;
716
717
45
    const auto position_sl = bn[1].GetSignedLong();
718
45
    CF_CHECK_NE(position_sl, std::nullopt);
719
720
    /* Negative not supported */
721
23
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
722
723
23
    res.Set( std::to_string(mpz_tstbit(bn[0].GetPtr(), *position_sl)) );
724
725
23
    ret = true;
726
727
45
end:
728
45
    return ret;
729
23
}
cryptofuzz::module::libgmp_bignum::Bit::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
713
3
bool Bit::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
714
3
    (void)ds;
715
3
    bool ret = false;
716
717
3
    const auto position_sl = bn[1].GetSignedLong();
718
3
    CF_CHECK_NE(position_sl, std::nullopt);
719
720
    /* Negative not supported */
721
0
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
722
723
0
    res.Set( std::to_string(mpz_tstbit(bn[0].GetPtr(), *position_sl)) );
724
725
0
    ret = true;
726
727
3
end:
728
3
    return ret;
729
0
}
730
731
1.67k
bool InvMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
732
1.67k
    (void)ds;
733
1.67k
    bool ret = false;
734
735
    /* "The behaviour of this function is undefined when op2 is zero." */
736
1.67k
    CF_CHECK_NE(mpz_sgn(bn[1].GetPtr()), 0);
737
738
1.64k
    if ( mpz_invert(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr()) == 0 ) {
739
        /* Modular inverse does not exist */
740
577
        res.Set("0");
741
1.06k
    } else {
742
1.06k
        CF_NORET(bn.CopyResult(res));
743
1.06k
    }
744
745
1.64k
    ret = true;
746
747
1.67k
end:
748
1.67k
    return ret;
749
1.64k
}
cryptofuzz::module::libgmp_bignum::InvMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
731
1.60k
bool InvMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
732
1.60k
    (void)ds;
733
1.60k
    bool ret = false;
734
735
    /* "The behaviour of this function is undefined when op2 is zero." */
736
1.60k
    CF_CHECK_NE(mpz_sgn(bn[1].GetPtr()), 0);
737
738
1.58k
    if ( mpz_invert(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr()) == 0 ) {
739
        /* Modular inverse does not exist */
740
559
        res.Set("0");
741
1.02k
    } else {
742
1.02k
        CF_NORET(bn.CopyResult(res));
743
1.02k
    }
744
745
1.58k
    ret = true;
746
747
1.60k
end:
748
1.60k
    return ret;
749
1.58k
}
cryptofuzz::module::libgmp_bignum::InvMod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
731
67
bool InvMod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
732
67
    (void)ds;
733
67
    bool ret = false;
734
735
    /* "The behaviour of this function is undefined when op2 is zero." */
736
67
    CF_CHECK_NE(mpz_sgn(bn[1].GetPtr()), 0);
737
738
63
    if ( mpz_invert(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr()) == 0 ) {
739
        /* Modular inverse does not exist */
740
18
        res.Set("0");
741
45
    } else {
742
45
        CF_NORET(bn.CopyResult(res));
743
45
    }
744
745
63
    ret = true;
746
747
67
end:
748
67
    return ret;
749
63
}
750
751
42
bool IsOdd::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
752
42
    (void)ds;
753
754
    /* "These macros evaluate their argument more than once." */
755
42
    const auto ptr = bn[0].GetPtr();
756
42
    res.Set( std::to_string(mpz_odd_p(ptr)) );
757
758
42
    return true;
759
42
}
cryptofuzz::module::libgmp_bignum::IsOdd::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
751
21
bool IsOdd::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
752
21
    (void)ds;
753
754
    /* "These macros evaluate their argument more than once." */
755
21
    const auto ptr = bn[0].GetPtr();
756
21
    res.Set( std::to_string(mpz_odd_p(ptr)) );
757
758
21
    return true;
759
21
}
cryptofuzz::module::libgmp_bignum::IsOdd::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
751
21
bool IsOdd::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
752
21
    (void)ds;
753
754
    /* "These macros evaluate their argument more than once." */
755
21
    const auto ptr = bn[0].GetPtr();
756
21
    res.Set( std::to_string(mpz_odd_p(ptr)) );
757
758
21
    return true;
759
21
}
760
761
38
bool IsEven::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
762
38
    (void)ds;
763
764
    /* "These macros evaluate their argument more than once." */
765
38
    const auto ptr = bn[0].GetPtr();
766
38
    res.Set( std::to_string(mpz_even_p(ptr)) );
767
768
38
    return true;
769
38
}
cryptofuzz::module::libgmp_bignum::IsEven::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
761
19
bool IsEven::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
762
19
    (void)ds;
763
764
    /* "These macros evaluate their argument more than once." */
765
19
    const auto ptr = bn[0].GetPtr();
766
19
    res.Set( std::to_string(mpz_even_p(ptr)) );
767
768
19
    return true;
769
19
}
cryptofuzz::module::libgmp_bignum::IsEven::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
761
19
bool IsEven::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
762
19
    (void)ds;
763
764
    /* "These macros evaluate their argument more than once." */
765
19
    const auto ptr = bn[0].GetPtr();
766
19
    res.Set( std::to_string(mpz_even_p(ptr)) );
767
768
19
    return true;
769
19
}
770
771
42
bool IsPow2::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
772
42
    (void)ds;
773
774
42
    if ( mpz_popcount(bn[0].GetPtr()) == 1 ) {
775
4
        res.Set("1");
776
38
    } else {
777
38
        res.Set("0");
778
38
    }
779
780
42
    return true;
781
42
}
cryptofuzz::module::libgmp_bignum::IsPow2::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
771
21
bool IsPow2::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
772
21
    (void)ds;
773
774
21
    if ( mpz_popcount(bn[0].GetPtr()) == 1 ) {
775
2
        res.Set("1");
776
19
    } else {
777
19
        res.Set("0");
778
19
    }
779
780
21
    return true;
781
21
}
cryptofuzz::module::libgmp_bignum::IsPow2::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
771
21
bool IsPow2::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
772
21
    (void)ds;
773
774
21
    if ( mpz_popcount(bn[0].GetPtr()) == 1 ) {
775
2
        res.Set("1");
776
19
    } else {
777
19
        res.Set("0");
778
19
    }
779
780
21
    return true;
781
21
}
782
783
34
bool NumLSZeroBits::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
784
34
    (void)ds;
785
786
34
    auto numBits = mpz_scan1(bn[0].GetPtr(), 0);
787
34
    if ( numBits == (mp_bitcnt_t)-1 ) {
788
8
        numBits = 0;
789
8
    }
790
34
    res.Set( std::to_string(numBits) );
791
792
34
    return true;
793
34
}
cryptofuzz::module::libgmp_bignum::NumLSZeroBits::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
783
17
bool NumLSZeroBits::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
784
17
    (void)ds;
785
786
17
    auto numBits = mpz_scan1(bn[0].GetPtr(), 0);
787
17
    if ( numBits == (mp_bitcnt_t)-1 ) {
788
4
        numBits = 0;
789
4
    }
790
17
    res.Set( std::to_string(numBits) );
791
792
17
    return true;
793
17
}
cryptofuzz::module::libgmp_bignum::NumLSZeroBits::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
783
17
bool NumLSZeroBits::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
784
17
    (void)ds;
785
786
17
    auto numBits = mpz_scan1(bn[0].GetPtr(), 0);
787
17
    if ( numBits == (mp_bitcnt_t)-1 ) {
788
4
        numBits = 0;
789
4
    }
790
17
    res.Set( std::to_string(numBits) );
791
792
17
    return true;
793
17
}
794
795
15
bool Factorial::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
796
15
    (void)ds;
797
15
    bool ret = false;
798
799
15
    const auto bn0 = bn[0].GetUnsignedLong();
800
15
    CF_CHECK_NE(bn0, std::nullopt);
801
10
    CF_CHECK_LTE(*bn0, 1500);
802
803
3
    CF_NORET(mpz_fac_ui(res.GetPtr(), *bn0));
804
805
3
    ret = true;
806
807
15
end:
808
15
    return ret;
809
3
}
810
811
122
bool Cbrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
812
122
    (void)ds;
813
814
61
    /* ignore ret */ mpz_root(bn.GetResPtr(), bn[0].GetPtr(), 3);
815
122
    CF_NORET(bn.CopyResult(res));
816
817
122
    return true;
818
122
}
cryptofuzz::module::libgmp_bignum::Cbrt::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
811
61
bool Cbrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
812
61
    (void)ds;
813
814
61
    /* ignore ret */ mpz_root(bn.GetResPtr(), bn[0].GetPtr(), 3);
815
61
    CF_NORET(bn.CopyResult(res));
816
817
61
    return true;
818
61
}
cryptofuzz::module::libgmp_bignum::Cbrt::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
811
61
bool Cbrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
812
61
    (void)ds;
813
814
61
    /* ignore ret */ mpz_root(bn.GetResPtr(), bn[0].GetPtr(), 3);
815
61
    CF_NORET(bn.CopyResult(res));
816
817
61
    return true;
818
61
}
819
820
25
bool SqrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
821
25
    bool ret = false;
822
25
    (void)ds;
823
824
25
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
825
826
21
    /* noret */ mpz_sqrtrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr());
827
25
    ret = true;
828
829
25
end:
830
25
    return ret;
831
25
}
cryptofuzz::module::libgmp_bignum::SqrtRem::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
820
21
bool SqrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
821
21
    bool ret = false;
822
21
    (void)ds;
823
824
21
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
825
826
21
    /* noret */ mpz_sqrtrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr());
827
21
    ret = true;
828
829
21
end:
830
21
    return ret;
831
21
}
cryptofuzz::module::libgmp_bignum::SqrtRem::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
820
4
bool SqrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
821
4
    bool ret = false;
822
4
    (void)ds;
823
824
4
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
825
826
4
    /* noret */ mpz_sqrtrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr());
827
4
    ret = true;
828
829
4
end:
830
4
    return ret;
831
4
}
832
833
222
bool CbrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
834
222
    (void)ds;
835
836
111
    /* noret */ mpz_rootrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr(), 3);
837
838
222
    return true;
839
222
}
cryptofuzz::module::libgmp_bignum::CbrtRem::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
833
111
bool CbrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
834
111
    (void)ds;
835
836
111
    /* noret */ mpz_rootrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr(), 3);
837
838
111
    return true;
839
111
}
cryptofuzz::module::libgmp_bignum::CbrtRem::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
833
111
bool CbrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
834
111
    (void)ds;
835
836
111
    /* noret */ mpz_rootrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr(), 3);
837
838
111
    return true;
839
111
}
840
841
6
bool Nthrt::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
842
/* Too slow in mini-gmp */
843
6
#if !defined(HAVE_MINI_GMP)
844
6
    (void)ds;
845
6
    bool ret = false;
846
847
6
    const auto bn1 = bn[1].GetUnsignedLong();
848
6
    CF_CHECK_NE(bn1, std::nullopt);
849
1
    CF_CHECK_NE(*bn1, 0);
850
0
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
851
852
0
    /* noret */ mpz_root(res.GetPtr(), bn[0].GetPtr(), *bn1);
853
854
0
    ret = true;
855
6
end:
856
6
    return ret;
857
#else
858
    (void)ds;
859
    (void)res;
860
    (void)bn;
861
862
    return false;
863
#endif
864
0
}
865
866
20
bool NthrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
867
/* Too slow in mini-gmp */
868
#if !defined(HAVE_MINI_GMP)
869
    (void)ds;
870
    bool ret = false;
871
872
    const auto bn1 = bn[1].GetUnsignedLong();
873
19
    CF_CHECK_NE(bn1, std::nullopt);
874
16
    CF_CHECK_NE(*bn1, 0);
875
14
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
876
877
14
    /* noret */ mpz_rootrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr(), *bn1);
878
879
14
    ret = true;
880
19
end:
881
19
    return ret;
882
#else
883
    (void)ds;
884
    (void)res;
885
    (void)bn;
886
887
    return false;
888
#endif
889
14
}
cryptofuzz::module::libgmp_bignum::NthrtRem::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
866
19
bool NthrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
867
/* Too slow in mini-gmp */
868
19
#if !defined(HAVE_MINI_GMP)
869
19
    (void)ds;
870
19
    bool ret = false;
871
872
19
    const auto bn1 = bn[1].GetUnsignedLong();
873
19
    CF_CHECK_NE(bn1, std::nullopt);
874
16
    CF_CHECK_NE(*bn1, 0);
875
14
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
876
877
14
    /* noret */ mpz_rootrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr(), *bn1);
878
879
14
    ret = true;
880
19
end:
881
19
    return ret;
882
#else
883
    (void)ds;
884
    (void)res;
885
    (void)bn;
886
887
    return false;
888
#endif
889
14
}
cryptofuzz::module::libgmp_bignum::NthrtRem::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
866
1
bool NthrtRem::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
867
/* Too slow in mini-gmp */
868
#if !defined(HAVE_MINI_GMP)
869
    (void)ds;
870
    bool ret = false;
871
872
    const auto bn1 = bn[1].GetUnsignedLong();
873
    CF_CHECK_NE(bn1, std::nullopt);
874
    CF_CHECK_NE(*bn1, 0);
875
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
876
877
    /* noret */ mpz_rootrem(bn[1].GetPtr(), res.GetPtr(), bn[0].GetPtr(), *bn1);
878
879
    ret = true;
880
end:
881
    return ret;
882
#else
883
1
    (void)ds;
884
1
    (void)res;
885
1
    (void)bn;
886
887
1
    return false;
888
1
#endif
889
1
}
890
891
52
bool IsSquare::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
892
#if !defined(HAVE_MINI_GMP)
893
    (void)ds;
894
895
    res.Set(
896
48
            mpz_perfect_square_p(bn[0].GetPtr()) == 0 ? std::string("0") : std::string("1")
897
    );
898
899
    return true;
900
#else
901
    (void)ds;
902
    (void)res;
903
    (void)bn;
904
905
    return false;
906
#endif
907
52
}
cryptofuzz::module::libgmp_bignum::IsSquare::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
891
48
bool IsSquare::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
892
48
#if !defined(HAVE_MINI_GMP)
893
48
    (void)ds;
894
895
48
    res.Set(
896
48
            mpz_perfect_square_p(bn[0].GetPtr()) == 0 ? std::string("0") : std::string("1")
897
48
    );
898
899
48
    return true;
900
#else
901
    (void)ds;
902
    (void)res;
903
    (void)bn;
904
905
    return false;
906
#endif
907
48
}
cryptofuzz::module::libgmp_bignum::IsSquare::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
891
4
bool IsSquare::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
892
#if !defined(HAVE_MINI_GMP)
893
    (void)ds;
894
895
    res.Set(
896
            mpz_perfect_square_p(bn[0].GetPtr()) == 0 ? std::string("0") : std::string("1")
897
    );
898
899
    return true;
900
#else
901
4
    (void)ds;
902
4
    (void)res;
903
4
    (void)bn;
904
905
4
    return false;
906
4
#endif
907
4
}
908
909
4
bool Exp::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
910
4
    bool ret = false;
911
912
4
    GET_WHICH(1);
913
4
    switch ( which ) {
914
2
        case    0:
915
2
            {
916
2
                const auto bn1 = bn[1].GetUnsignedLong();
917
2
                CF_CHECK_NE(bn1, std::nullopt);
918
919
1
                /* noret */ mpz_pow_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
920
2
                CF_NORET(bn.CopyResult(res));
921
2
            }
922
0
            break;
923
2
        case    1:
924
2
            {
925
2
                const auto bn0 = bn[0].GetUnsignedLong();
926
2
                CF_CHECK_NE(bn0, std::nullopt);
927
928
2
                const auto bn1 = bn[1].GetUnsignedLong();
929
2
                CF_CHECK_NE(bn1, std::nullopt);
930
931
1
                /* noret */ mpz_ui_pow_ui(bn.GetResPtr(), *bn0, *bn1);
932
2
                CF_NORET(bn.CopyResult(res));
933
2
            }
934
0
            break;
935
0
        default:
936
0
            return false;
937
4
    }
938
939
4
    ret = true;
940
941
4
end:
942
4
    return ret;
943
4
}
cryptofuzz::module::libgmp_bignum::Exp::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
909
2
bool Exp::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
910
2
    bool ret = false;
911
912
2
    GET_WHICH(1);
913
2
    switch ( which ) {
914
1
        case    0:
915
1
            {
916
1
                const auto bn1 = bn[1].GetUnsignedLong();
917
1
                CF_CHECK_NE(bn1, std::nullopt);
918
919
1
                /* noret */ mpz_pow_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
920
1
                CF_NORET(bn.CopyResult(res));
921
1
            }
922
0
            break;
923
1
        case    1:
924
1
            {
925
1
                const auto bn0 = bn[0].GetUnsignedLong();
926
1
                CF_CHECK_NE(bn0, std::nullopt);
927
928
1
                const auto bn1 = bn[1].GetUnsignedLong();
929
1
                CF_CHECK_NE(bn1, std::nullopt);
930
931
1
                /* noret */ mpz_ui_pow_ui(bn.GetResPtr(), *bn0, *bn1);
932
1
                CF_NORET(bn.CopyResult(res));
933
1
            }
934
0
            break;
935
0
        default:
936
0
            return false;
937
2
    }
938
939
2
    ret = true;
940
941
2
end:
942
2
    return ret;
943
2
}
cryptofuzz::module::libgmp_bignum::Exp::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
909
2
bool Exp::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
910
2
    bool ret = false;
911
912
2
    GET_WHICH(1);
913
2
    switch ( which ) {
914
1
        case    0:
915
1
            {
916
1
                const auto bn1 = bn[1].GetUnsignedLong();
917
1
                CF_CHECK_NE(bn1, std::nullopt);
918
919
1
                /* noret */ mpz_pow_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
920
1
                CF_NORET(bn.CopyResult(res));
921
1
            }
922
0
            break;
923
1
        case    1:
924
1
            {
925
1
                const auto bn0 = bn[0].GetUnsignedLong();
926
1
                CF_CHECK_NE(bn0, std::nullopt);
927
928
1
                const auto bn1 = bn[1].GetUnsignedLong();
929
1
                CF_CHECK_NE(bn1, std::nullopt);
930
931
1
                /* noret */ mpz_ui_pow_ui(bn.GetResPtr(), *bn0, *bn1);
932
1
                CF_NORET(bn.CopyResult(res));
933
1
            }
934
0
            break;
935
0
        default:
936
0
            return false;
937
2
    }
938
939
2
    ret = true;
940
941
2
end:
942
2
    return ret;
943
2
}
944
945
160
bool Or::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
946
160
    (void)ds;
947
948
80
    /* noret */ mpz_ior(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
949
950
160
    return true;
951
160
}
cryptofuzz::module::libgmp_bignum::Or::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
945
80
bool Or::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
946
80
    (void)ds;
947
948
80
    /* noret */ mpz_ior(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
949
950
80
    return true;
951
80
}
cryptofuzz::module::libgmp_bignum::Or::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
945
80
bool Or::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
946
80
    (void)ds;
947
948
80
    /* noret */ mpz_ior(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
949
950
80
    return true;
951
80
}
952
953
82
bool AddMul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
954
82
    bool ret = false;
955
956
82
    GET_WHICH(1);
957
82
    switch ( which ) {
958
70
        case    0:
959
70
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
960
70
            /* noret */ mpz_addmul(res.GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
961
70
            break;
962
12
        case    1:
963
12
            {
964
12
                const auto bn2 = bn[2].GetUnsignedLong();
965
12
                CF_CHECK_NE(bn2, std::nullopt);
966
967
2
                /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
968
4
                /* noret */ mpz_addmul_ui(res.GetPtr(), bn[1].GetPtr(), *bn2);
969
4
            }
970
0
            break;
971
0
        default:
972
0
            return false;
973
82
    }
974
975
74
    ret = true;
976
977
82
end:
978
82
    return ret;
979
74
}
cryptofuzz::module::libgmp_bignum::AddMul::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
953
41
bool AddMul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
954
41
    bool ret = false;
955
956
41
    GET_WHICH(1);
957
41
    switch ( which ) {
958
35
        case    0:
959
35
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
960
35
            /* noret */ mpz_addmul(res.GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
961
35
            break;
962
6
        case    1:
963
6
            {
964
6
                const auto bn2 = bn[2].GetUnsignedLong();
965
6
                CF_CHECK_NE(bn2, std::nullopt);
966
967
2
                /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
968
2
                /* noret */ mpz_addmul_ui(res.GetPtr(), bn[1].GetPtr(), *bn2);
969
2
            }
970
0
            break;
971
0
        default:
972
0
            return false;
973
41
    }
974
975
37
    ret = true;
976
977
41
end:
978
41
    return ret;
979
37
}
cryptofuzz::module::libgmp_bignum::AddMul::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
953
41
bool AddMul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
954
41
    bool ret = false;
955
956
41
    GET_WHICH(1);
957
41
    switch ( which ) {
958
35
        case    0:
959
35
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
960
35
            /* noret */ mpz_addmul(res.GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
961
35
            break;
962
6
        case    1:
963
6
            {
964
6
                const auto bn2 = bn[2].GetUnsignedLong();
965
6
                CF_CHECK_NE(bn2, std::nullopt);
966
967
2
                /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
968
2
                /* noret */ mpz_addmul_ui(res.GetPtr(), bn[1].GetPtr(), *bn2);
969
2
            }
970
0
            break;
971
0
        default:
972
0
            return false;
973
41
    }
974
975
37
    ret = true;
976
977
41
end:
978
41
    return ret;
979
37
}
980
981
102
bool SubMul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
982
102
    bool ret = false;
983
984
102
    GET_WHICH(1);
985
102
    switch ( which ) {
986
82
        case    0:
987
82
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
988
82
            /* noret */ mpz_submul(res.GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
989
82
            break;
990
20
        case    1:
991
20
            {
992
20
                const auto bn2 = bn[2].GetUnsignedLong();
993
20
                CF_CHECK_NE(bn2, std::nullopt);
994
995
3
                /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
996
6
                /* noret */ mpz_submul_ui(res.GetPtr(), bn[1].GetPtr(), *bn2);
997
6
            }
998
0
            break;
999
0
        default:
1000
0
            return false;
1001
102
    }
1002
1003
88
    ret = true;
1004
1005
102
end:
1006
102
    return ret;
1007
88
}
cryptofuzz::module::libgmp_bignum::SubMul::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
981
51
bool SubMul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
982
51
    bool ret = false;
983
984
51
    GET_WHICH(1);
985
51
    switch ( which ) {
986
41
        case    0:
987
41
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
988
41
            /* noret */ mpz_submul(res.GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
989
41
            break;
990
10
        case    1:
991
10
            {
992
10
                const auto bn2 = bn[2].GetUnsignedLong();
993
10
                CF_CHECK_NE(bn2, std::nullopt);
994
995
3
                /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
996
3
                /* noret */ mpz_submul_ui(res.GetPtr(), bn[1].GetPtr(), *bn2);
997
3
            }
998
0
            break;
999
0
        default:
1000
0
            return false;
1001
51
    }
1002
1003
44
    ret = true;
1004
1005
51
end:
1006
51
    return ret;
1007
44
}
cryptofuzz::module::libgmp_bignum::SubMul::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
981
51
bool SubMul::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
982
51
    bool ret = false;
983
984
51
    GET_WHICH(1);
985
51
    switch ( which ) {
986
41
        case    0:
987
41
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
988
41
            /* noret */ mpz_submul(res.GetPtr(), bn[1].GetPtr(), bn[2].GetPtr());
989
41
            break;
990
10
        case    1:
991
10
            {
992
10
                const auto bn2 = bn[2].GetUnsignedLong();
993
10
                CF_CHECK_NE(bn2, std::nullopt);
994
995
3
                /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
996
3
                /* noret */ mpz_submul_ui(res.GetPtr(), bn[1].GetPtr(), *bn2);
997
3
            }
998
0
            break;
999
0
        default:
1000
0
            return false;
1001
51
    }
1002
1003
44
    ret = true;
1004
1005
51
end:
1006
51
    return ret;
1007
44
}
1008
1009
13
bool Primorial::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1010
#if !defined(HAVE_MINI_GMP)
1011
    (void)ds;
1012
    bool ret = false;
1013
1014
    const auto bn0 = bn[0].GetUnsignedLong();
1015
11
    CF_CHECK_NE(bn0, std::nullopt);
1016
5
    CF_CHECK_LTE(*bn0, 10000);
1017
1018
3
    /* noret */ mpz_primorial_ui(res.GetPtr(), *bn0);
1019
1020
3
    ret = true;
1021
1022
11
end:
1023
11
    return ret;
1024
#else
1025
    (void)ds;
1026
    (void)res;
1027
    (void)bn;
1028
1029
    return false;
1030
#endif
1031
3
}
cryptofuzz::module::libgmp_bignum::Primorial::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1009
11
bool Primorial::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1010
11
#if !defined(HAVE_MINI_GMP)
1011
11
    (void)ds;
1012
11
    bool ret = false;
1013
1014
11
    const auto bn0 = bn[0].GetUnsignedLong();
1015
11
    CF_CHECK_NE(bn0, std::nullopt);
1016
5
    CF_CHECK_LTE(*bn0, 10000);
1017
1018
3
    /* noret */ mpz_primorial_ui(res.GetPtr(), *bn0);
1019
1020
3
    ret = true;
1021
1022
11
end:
1023
11
    return ret;
1024
#else
1025
    (void)ds;
1026
    (void)res;
1027
    (void)bn;
1028
1029
    return false;
1030
#endif
1031
3
}
cryptofuzz::module::libgmp_bignum::Primorial::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1009
2
bool Primorial::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1010
#if !defined(HAVE_MINI_GMP)
1011
    (void)ds;
1012
    bool ret = false;
1013
1014
    const auto bn0 = bn[0].GetUnsignedLong();
1015
    CF_CHECK_NE(bn0, std::nullopt);
1016
    CF_CHECK_LTE(*bn0, 10000);
1017
1018
    /* noret */ mpz_primorial_ui(res.GetPtr(), *bn0);
1019
1020
    ret = true;
1021
1022
end:
1023
    return ret;
1024
#else
1025
2
    (void)ds;
1026
2
    (void)res;
1027
2
    (void)bn;
1028
1029
2
    return false;
1030
2
#endif
1031
2
}
1032
1033
11
bool Lucas::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1034
#if !defined(HAVE_MINI_GMP)
1035
    (void)ds;
1036
    bool ret = false;
1037
1038
    const auto bn0 = bn[0].GetUnsignedLong();
1039
11
    CF_CHECK_NE(bn0, std::nullopt);
1040
7
    CF_CHECK_LTE(*bn0, 10000);
1041
1042
5
    /* noret */ mpz_lucnum_ui(res.GetPtr(), *bn0);
1043
1044
5
    ret = true;
1045
1046
11
end:
1047
11
    return ret;
1048
#else
1049
    (void)ds;
1050
    (void)res;
1051
    (void)bn;
1052
1053
    return false;
1054
#endif
1055
5
}
cryptofuzz::module::libgmp_bignum::Lucas::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1033
11
bool Lucas::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1034
11
#if !defined(HAVE_MINI_GMP)
1035
11
    (void)ds;
1036
11
    bool ret = false;
1037
1038
11
    const auto bn0 = bn[0].GetUnsignedLong();
1039
11
    CF_CHECK_NE(bn0, std::nullopt);
1040
7
    CF_CHECK_LTE(*bn0, 10000);
1041
1042
5
    /* noret */ mpz_lucnum_ui(res.GetPtr(), *bn0);
1043
1044
5
    ret = true;
1045
1046
11
end:
1047
11
    return ret;
1048
#else
1049
    (void)ds;
1050
    (void)res;
1051
    (void)bn;
1052
1053
    return false;
1054
#endif
1055
5
}
Unexecuted instantiation: cryptofuzz::module::libgmp_bignum::Lucas::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
1056
1057
26
bool Fibonacci::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1058
26
    (void)ds;
1059
26
    bool ret = false;
1060
1061
26
    const auto bn0 = bn[0].GetUnsignedLong();
1062
26
    CF_CHECK_NE(bn0, std::nullopt);
1063
10
    CF_CHECK_LTE(*bn0, 10000);
1064
1065
3
    /* noret */ mpz_fac_ui(res.GetPtr(), *bn0);
1066
1067
6
    ret = true;
1068
1069
26
end:
1070
26
    return ret;
1071
6
}
cryptofuzz::module::libgmp_bignum::Fibonacci::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1057
13
bool Fibonacci::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1058
13
    (void)ds;
1059
13
    bool ret = false;
1060
1061
13
    const auto bn0 = bn[0].GetUnsignedLong();
1062
13
    CF_CHECK_NE(bn0, std::nullopt);
1063
5
    CF_CHECK_LTE(*bn0, 10000);
1064
1065
3
    /* noret */ mpz_fac_ui(res.GetPtr(), *bn0);
1066
1067
3
    ret = true;
1068
1069
13
end:
1070
13
    return ret;
1071
3
}
cryptofuzz::module::libgmp_bignum::Fibonacci::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1057
13
bool Fibonacci::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1058
13
    (void)ds;
1059
13
    bool ret = false;
1060
1061
13
    const auto bn0 = bn[0].GetUnsignedLong();
1062
13
    CF_CHECK_NE(bn0, std::nullopt);
1063
5
    CF_CHECK_LTE(*bn0, 10000);
1064
1065
3
    /* noret */ mpz_fac_ui(res.GetPtr(), *bn0);
1066
1067
3
    ret = true;
1068
1069
13
end:
1070
13
    return ret;
1071
3
}
1072
1073
132
bool Set::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1074
132
    bool ret = false;
1075
1076
132
    GET_WHICH(3);
1077
132
    switch ( which ) {
1078
30
        case    0:
1079
30
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1080
30
            break;
1081
30
        case    1:
1082
30
            {
1083
30
                const auto bn0 = bn[0].GetUnsignedLong();
1084
30
                CF_CHECK_NE(bn0, std::nullopt);
1085
1086
2
                /* noret */ mpz_clear(res.GetPtr());
1087
4
                /* noret */ mpz_init_set_ui(res.GetPtr(), *bn0);
1088
4
            }
1089
0
            break;
1090
50
        case    2:
1091
50
            {
1092
50
                const auto bn0 = bn[0].GetSignedLong();
1093
50
                CF_CHECK_NE(bn0, std::nullopt);
1094
1095
4
                /* noret */ mpz_clear(res.GetPtr());
1096
8
                /* noret */ mpz_init_set_si(res.GetPtr(), *bn0);
1097
8
            }
1098
0
            break;
1099
22
        case    3:
1100
22
            /* noret */ mpz_swap(res.GetPtr(), bn[0].GetPtr());
1101
22
            break;
1102
0
        default:
1103
0
            return false;
1104
132
    }
1105
1106
64
    ret = true;
1107
1108
132
end:
1109
132
    return ret;
1110
64
}
cryptofuzz::module::libgmp_bignum::Set::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1073
66
bool Set::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1074
66
    bool ret = false;
1075
1076
66
    GET_WHICH(3);
1077
66
    switch ( which ) {
1078
15
        case    0:
1079
15
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1080
15
            break;
1081
15
        case    1:
1082
15
            {
1083
15
                const auto bn0 = bn[0].GetUnsignedLong();
1084
15
                CF_CHECK_NE(bn0, std::nullopt);
1085
1086
2
                /* noret */ mpz_clear(res.GetPtr());
1087
2
                /* noret */ mpz_init_set_ui(res.GetPtr(), *bn0);
1088
2
            }
1089
0
            break;
1090
25
        case    2:
1091
25
            {
1092
25
                const auto bn0 = bn[0].GetSignedLong();
1093
25
                CF_CHECK_NE(bn0, std::nullopt);
1094
1095
4
                /* noret */ mpz_clear(res.GetPtr());
1096
4
                /* noret */ mpz_init_set_si(res.GetPtr(), *bn0);
1097
4
            }
1098
0
            break;
1099
11
        case    3:
1100
11
            /* noret */ mpz_swap(res.GetPtr(), bn[0].GetPtr());
1101
11
            break;
1102
0
        default:
1103
0
            return false;
1104
66
    }
1105
1106
32
    ret = true;
1107
1108
66
end:
1109
66
    return ret;
1110
32
}
cryptofuzz::module::libgmp_bignum::Set::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1073
66
bool Set::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1074
66
    bool ret = false;
1075
1076
66
    GET_WHICH(3);
1077
66
    switch ( which ) {
1078
15
        case    0:
1079
15
            /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1080
15
            break;
1081
15
        case    1:
1082
15
            {
1083
15
                const auto bn0 = bn[0].GetUnsignedLong();
1084
15
                CF_CHECK_NE(bn0, std::nullopt);
1085
1086
2
                /* noret */ mpz_clear(res.GetPtr());
1087
2
                /* noret */ mpz_init_set_ui(res.GetPtr(), *bn0);
1088
2
            }
1089
0
            break;
1090
25
        case    2:
1091
25
            {
1092
25
                const auto bn0 = bn[0].GetSignedLong();
1093
25
                CF_CHECK_NE(bn0, std::nullopt);
1094
1095
4
                /* noret */ mpz_clear(res.GetPtr());
1096
4
                /* noret */ mpz_init_set_si(res.GetPtr(), *bn0);
1097
4
            }
1098
0
            break;
1099
11
        case    3:
1100
11
            /* noret */ mpz_swap(res.GetPtr(), bn[0].GetPtr());
1101
11
            break;
1102
0
        default:
1103
0
            return false;
1104
66
    }
1105
1106
32
    ret = true;
1107
1108
66
end:
1109
66
    return ret;
1110
32
}
1111
1112
31
bool BinCoeff::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1113
31
    bool ret = false;
1114
1115
31
    std::optional<unsigned long int> bn0, bn1;
1116
1117
31
    GET_WHICH(1);
1118
1119
31
    bn0 = bn[0].GetUnsignedLong();
1120
31
    CF_CHECK_NE(bn0, std::nullopt);
1121
#if !defined(HAVE_MINI_GMP)
1122
20
    CF_CHECK_LTE(*bn0, 100000);
1123
#else
1124
    /* Too slow otherwise */
1125
1
    CF_CHECK_LTE(*bn0, 1000);
1126
0
#endif
1127
1128
0
    bn1 = bn[1].GetUnsignedLong();
1129
17
    CF_CHECK_NE(bn1, std::nullopt);
1130
#if !defined(HAVE_MINI_GMP)
1131
14
    CF_CHECK_LTE(*bn1, 100000);
1132
#else
1133
    /* Too slow otherwise */
1134
0
    CF_CHECK_LTE(*bn0, 1000);
1135
0
#endif
1136
1137
0
    switch ( which ) {
1138
#if !defined(HAVE_MINI_GMP)
1139
14
        case    0:
1140
14
            /* noret */ mpz_bin_ui(res.GetPtr(), bn[0].GetPtr(), *bn1);
1141
14
            break;
1142
0
#endif
1143
0
        case    1:
1144
0
            /* noret */ mpz_bin_uiui(res.GetPtr(), *bn0, *bn1);
1145
0
            break;
1146
0
        default:
1147
0
            goto end;
1148
0
    }
1149
1150
14
    ret = true;
1151
1152
31
end:
1153
31
    return ret;
1154
14
}
cryptofuzz::module::libgmp_bignum::BinCoeff::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1112
29
bool BinCoeff::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1113
29
    bool ret = false;
1114
1115
29
    std::optional<unsigned long int> bn0, bn1;
1116
1117
29
    GET_WHICH(1);
1118
1119
29
    bn0 = bn[0].GetUnsignedLong();
1120
29
    CF_CHECK_NE(bn0, std::nullopt);
1121
20
#if !defined(HAVE_MINI_GMP)
1122
20
    CF_CHECK_LTE(*bn0, 100000);
1123
#else
1124
    /* Too slow otherwise */
1125
    CF_CHECK_LTE(*bn0, 1000);
1126
#endif
1127
1128
17
    bn1 = bn[1].GetUnsignedLong();
1129
17
    CF_CHECK_NE(bn1, std::nullopt);
1130
14
#if !defined(HAVE_MINI_GMP)
1131
14
    CF_CHECK_LTE(*bn1, 100000);
1132
#else
1133
    /* Too slow otherwise */
1134
    CF_CHECK_LTE(*bn0, 1000);
1135
#endif
1136
1137
14
    switch ( which ) {
1138
0
#if !defined(HAVE_MINI_GMP)
1139
14
        case    0:
1140
14
            /* noret */ mpz_bin_ui(res.GetPtr(), bn[0].GetPtr(), *bn1);
1141
14
            break;
1142
0
#endif
1143
0
        case    1:
1144
0
            /* noret */ mpz_bin_uiui(res.GetPtr(), *bn0, *bn1);
1145
0
            break;
1146
0
        default:
1147
0
            goto end;
1148
14
    }
1149
1150
14
    ret = true;
1151
1152
29
end:
1153
29
    return ret;
1154
14
}
cryptofuzz::module::libgmp_bignum::BinCoeff::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1112
2
bool BinCoeff::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1113
2
    bool ret = false;
1114
1115
2
    std::optional<unsigned long int> bn0, bn1;
1116
1117
2
    GET_WHICH(1);
1118
1119
2
    bn0 = bn[0].GetUnsignedLong();
1120
2
    CF_CHECK_NE(bn0, std::nullopt);
1121
#if !defined(HAVE_MINI_GMP)
1122
    CF_CHECK_LTE(*bn0, 100000);
1123
#else
1124
    /* Too slow otherwise */
1125
1
    CF_CHECK_LTE(*bn0, 1000);
1126
0
#endif
1127
1128
0
    bn1 = bn[1].GetUnsignedLong();
1129
0
    CF_CHECK_NE(bn1, std::nullopt);
1130
#if !defined(HAVE_MINI_GMP)
1131
    CF_CHECK_LTE(*bn1, 100000);
1132
#else
1133
    /* Too slow otherwise */
1134
0
    CF_CHECK_LTE(*bn0, 1000);
1135
0
#endif
1136
1137
0
    switch ( which ) {
1138
#if !defined(HAVE_MINI_GMP)
1139
        case    0:
1140
            /* noret */ mpz_bin_ui(res.GetPtr(), bn[0].GetPtr(), *bn1);
1141
            break;
1142
#endif
1143
0
        case    1:
1144
0
            /* noret */ mpz_bin_uiui(res.GetPtr(), *bn0, *bn1);
1145
0
            break;
1146
0
        default:
1147
0
            goto end;
1148
0
    }
1149
1150
0
    ret = true;
1151
1152
2
end:
1153
2
    return ret;
1154
0
}
1155
1156
54
bool HamDist::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1157
54
    (void)ds;
1158
1159
54
    res.Set( std::to_string(mpz_hamdist(bn[0].GetPtr(), bn[1].GetPtr())) );
1160
1161
54
    return true;
1162
54
}
cryptofuzz::module::libgmp_bignum::HamDist::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1156
27
bool HamDist::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1157
27
    (void)ds;
1158
1159
27
    res.Set( std::to_string(mpz_hamdist(bn[0].GetPtr(), bn[1].GetPtr())) );
1160
1161
27
    return true;
1162
27
}
cryptofuzz::module::libgmp_bignum::HamDist::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1156
27
bool HamDist::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1157
27
    (void)ds;
1158
1159
27
    res.Set( std::to_string(mpz_hamdist(bn[0].GetPtr(), bn[1].GetPtr())) );
1160
1161
27
    return true;
1162
27
}
1163
1164
123
bool Mod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1165
123
    bool ret = false;
1166
1167
123
    GET_WHICH(1);
1168
123
    switch ( which ) {
1169
89
        case    0:
1170
89
            CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
1171
1172
44
            /* noret */ mpz_mod(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1173
62
            CF_NORET(bn.CopyResult(res));
1174
62
            break;
1175
34
        case    1:
1176
34
            {
1177
34
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
1178
1179
30
                const auto bn1 = bn[1].GetUnsignedLong();
1180
30
                CF_CHECK_NE(bn1, std::nullopt);
1181
1182
3
                /* ignore ret */ mpz_mod_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
1183
3
                CF_NORET(bn.CopyResult(res));
1184
3
            }
1185
0
            break;
1186
0
        default:
1187
0
            return false;
1188
123
    }
1189
1190
    /* Negative not supported */
1191
65
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
1192
65
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
1193
1194
65
    ret = true;
1195
1196
123
end:
1197
123
    return ret;
1198
65
}
cryptofuzz::module::libgmp_bignum::Mod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1164
90
bool Mod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1165
90
    bool ret = false;
1166
1167
90
    GET_WHICH(1);
1168
90
    switch ( which ) {
1169
64
        case    0:
1170
64
            CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
1171
1172
44
            /* noret */ mpz_mod(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1173
44
            CF_NORET(bn.CopyResult(res));
1174
44
            break;
1175
26
        case    1:
1176
26
            {
1177
26
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
1178
1179
24
                const auto bn1 = bn[1].GetUnsignedLong();
1180
24
                CF_CHECK_NE(bn1, std::nullopt);
1181
1182
3
                /* ignore ret */ mpz_mod_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
1183
3
                CF_NORET(bn.CopyResult(res));
1184
3
            }
1185
0
            break;
1186
0
        default:
1187
0
            return false;
1188
90
    }
1189
1190
    /* Negative not supported */
1191
47
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
1192
47
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
1193
1194
47
    ret = true;
1195
1196
90
end:
1197
90
    return ret;
1198
47
}
cryptofuzz::module::libgmp_bignum::Mod::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1164
33
bool Mod::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1165
33
    bool ret = false;
1166
1167
33
    GET_WHICH(1);
1168
33
    switch ( which ) {
1169
25
        case    0:
1170
25
            CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
1171
1172
18
            /* noret */ mpz_mod(bn.GetResPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1173
18
            CF_NORET(bn.CopyResult(res));
1174
18
            break;
1175
8
        case    1:
1176
8
            {
1177
8
                CF_CHECK_NE(mpz_cmp_ui(bn[1].GetPtr(), 0), 0);
1178
1179
6
                const auto bn1 = bn[1].GetUnsignedLong();
1180
6
                CF_CHECK_NE(bn1, std::nullopt);
1181
1182
0
                /* ignore ret */ mpz_mod_ui(bn.GetResPtr(), bn[0].GetPtr(), *bn1);
1183
0
                CF_NORET(bn.CopyResult(res));
1184
0
            }
1185
0
            break;
1186
0
        default:
1187
0
            return false;
1188
33
    }
1189
1190
    /* Negative not supported */
1191
18
    CF_CHECK_GTE(mpz_sgn(bn[0].GetPtr()), 0);
1192
18
    CF_CHECK_GTE(mpz_sgn(bn[1].GetPtr()), 0);
1193
1194
18
    ret = true;
1195
1196
33
end:
1197
33
    return ret;
1198
18
}
1199
1200
216
bool IsPower::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1201
#if !defined(HAVE_MINI_GMP)
1202
    (void)ds;
1203
1204
    res.Set(
1205
213
            mpz_perfect_power_p(bn[0].GetPtr()) == 0 ? std::string("0") : std::string("1")
1206
    );
1207
1208
    return true;
1209
#else
1210
    (void)ds;
1211
    (void)res;
1212
    (void)bn;
1213
1214
    return false;
1215
#endif
1216
216
}
cryptofuzz::module::libgmp_bignum::IsPower::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1200
213
bool IsPower::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1201
213
#if !defined(HAVE_MINI_GMP)
1202
213
    (void)ds;
1203
1204
213
    res.Set(
1205
213
            mpz_perfect_power_p(bn[0].GetPtr()) == 0 ? std::string("0") : std::string("1")
1206
213
    );
1207
1208
213
    return true;
1209
#else
1210
    (void)ds;
1211
    (void)res;
1212
    (void)bn;
1213
1214
    return false;
1215
#endif
1216
213
}
cryptofuzz::module::libgmp_bignum::IsPower::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1200
3
bool IsPower::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1201
#if !defined(HAVE_MINI_GMP)
1202
    (void)ds;
1203
1204
    res.Set(
1205
            mpz_perfect_power_p(bn[0].GetPtr()) == 0 ? std::string("0") : std::string("1")
1206
    );
1207
1208
    return true;
1209
#else
1210
3
    (void)ds;
1211
3
    (void)res;
1212
3
    (void)bn;
1213
1214
3
    return false;
1215
3
#endif
1216
3
}
1217
1218
2.15k
bool Prime::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1219
#if !defined(HAVE_MINI_GMP)
1220
    (void)bn;
1221
1222
    uint16_t bits = 0;
1223
1224
2.15k
    try {
1225
2.15k
        bits = ds.Get<uint16_t>();
1226
2.15k
    } catch ( ... ) { }
1227
1228
2.15k
    bits %= (512+1);
1229
1230
2.15k
    if ( bits == 0 ) {
1231
90
        bits = 1;
1232
90
    }
1233
1234
2.15k
    /* noret */ mpz_urandomb(res.GetPtr(), libgmp_detail::rng_state, bits);
1235
2.15k
    /* noret */ mpz_nextprime(res.GetPtr(), res.GetPtr());
1236
1237
2.15k
    return true;
1238
#else
1239
    (void)ds;
1240
    (void)res;
1241
    (void)bn;
1242
1243
    return false;
1244
#endif
1245
2.15k
}
cryptofuzz::module::libgmp_bignum::Prime::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1218
2.15k
bool Prime::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1219
2.15k
#if !defined(HAVE_MINI_GMP)
1220
2.15k
    (void)bn;
1221
1222
2.15k
    uint16_t bits = 0;
1223
1224
2.15k
    try {
1225
2.15k
        bits = ds.Get<uint16_t>();
1226
2.15k
    } catch ( ... ) { }
1227
1228
2.15k
    bits %= (512+1);
1229
1230
2.15k
    if ( bits == 0 ) {
1231
90
        bits = 1;
1232
90
    }
1233
1234
2.15k
    /* noret */ mpz_urandomb(res.GetPtr(), libgmp_detail::rng_state, bits);
1235
2.15k
    /* noret */ mpz_nextprime(res.GetPtr(), res.GetPtr());
1236
1237
2.15k
    return true;
1238
#else
1239
    (void)ds;
1240
    (void)res;
1241
    (void)bn;
1242
1243
    return false;
1244
#endif
1245
2.15k
}
cryptofuzz::module::libgmp_bignum::Prime::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1218
3
bool Prime::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1219
#if !defined(HAVE_MINI_GMP)
1220
    (void)bn;
1221
1222
    uint16_t bits = 0;
1223
1224
    try {
1225
        bits = ds.Get<uint16_t>();
1226
    } catch ( ... ) { }
1227
1228
    bits %= (512+1);
1229
1230
    if ( bits == 0 ) {
1231
        bits = 1;
1232
    }
1233
1234
    /* noret */ mpz_urandomb(res.GetPtr(), libgmp_detail::rng_state, bits);
1235
    /* noret */ mpz_nextprime(res.GetPtr(), res.GetPtr());
1236
1237
    return true;
1238
#else
1239
3
    (void)ds;
1240
3
    (void)res;
1241
3
    (void)bn;
1242
1243
3
    return false;
1244
3
#endif
1245
3
}
1246
1247
715
bool IsPrime::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1248
715
    (void)ds;
1249
715
    bool ret = false;
1250
1251
#if defined(HAVE_MINI_GMP)
1252
57
    CF_CHECK_LTE(mpz_sizeinbase(bn[0].GetPtr(), 2), 2000);
1253
55
#endif
1254
1255
55
    {
1256
658
        const bool isprime = mpz_probab_prime_p(bn[0].GetPtr(), 15) != 0;
1257
1258
658
        if ( mpz_sgn(bn[0].GetPtr()) < 0 ) {
1259
0
            return false;
1260
0
        }
1261
1262
713
        if ( isprime ) {
1263
149
            res.Set("1");
1264
564
        } else {
1265
564
            res.Set("0");
1266
564
        }
1267
658
    }
1268
1269
0
    ret = true;
1270
#if defined(HAVE_MINI_GMP)
1271
57
end:
1272
57
#endif
1273
57
    return ret;
1274
55
}
cryptofuzz::module::libgmp_bignum::IsPrime::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1247
658
bool IsPrime::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1248
658
    (void)ds;
1249
658
    bool ret = false;
1250
1251
#if defined(HAVE_MINI_GMP)
1252
    CF_CHECK_LTE(mpz_sizeinbase(bn[0].GetPtr(), 2), 2000);
1253
#endif
1254
1255
658
    {
1256
658
        const bool isprime = mpz_probab_prime_p(bn[0].GetPtr(), 15) != 0;
1257
1258
658
        if ( mpz_sgn(bn[0].GetPtr()) < 0 ) {
1259
0
            return false;
1260
0
        }
1261
1262
658
        if ( isprime ) {
1263
132
            res.Set("1");
1264
526
        } else {
1265
526
            res.Set("0");
1266
526
        }
1267
658
    }
1268
1269
0
    ret = true;
1270
#if defined(HAVE_MINI_GMP)
1271
end:
1272
#endif
1273
658
    return ret;
1274
658
}
cryptofuzz::module::libgmp_bignum::IsPrime::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1247
57
bool IsPrime::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1248
57
    (void)ds;
1249
57
    bool ret = false;
1250
1251
57
#if defined(HAVE_MINI_GMP)
1252
57
    CF_CHECK_LTE(mpz_sizeinbase(bn[0].GetPtr(), 2), 2000);
1253
55
#endif
1254
1255
55
    {
1256
55
        const bool isprime = mpz_probab_prime_p(bn[0].GetPtr(), 15) != 0;
1257
1258
55
        if ( mpz_sgn(bn[0].GetPtr()) < 0 ) {
1259
0
            return false;
1260
0
        }
1261
1262
55
        if ( isprime ) {
1263
17
            res.Set("1");
1264
38
        } else {
1265
38
            res.Set("0");
1266
38
        }
1267
55
    }
1268
1269
0
    ret = true;
1270
55
#if defined(HAVE_MINI_GMP)
1271
57
end:
1272
57
#endif
1273
57
    return ret;
1274
55
}
1275
1276
36
bool Rand::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1277
#if !defined(HAVE_MINI_GMP)
1278
    (void)bn;
1279
1280
    uint16_t bits = 0;
1281
1282
25
    try {
1283
25
        bits = ds.Get<uint16_t>();
1284
25
    } catch ( ... ) { }
1285
1286
25
    bits %= (10000+1);
1287
1288
25
    if ( bits == 0 ) {
1289
5
        bits = 1;
1290
5
    }
1291
1292
25
    /* noret */ mpz_urandomb(res.GetPtr(), libgmp_detail::rng_state, 512);
1293
1294
25
    return true;
1295
#else
1296
    (void)ds;
1297
    (void)res;
1298
    (void)bn;
1299
1300
    return false;
1301
#endif
1302
36
}
cryptofuzz::module::libgmp_bignum::Rand::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1276
25
bool Rand::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1277
25
#if !defined(HAVE_MINI_GMP)
1278
25
    (void)bn;
1279
1280
25
    uint16_t bits = 0;
1281
1282
25
    try {
1283
25
        bits = ds.Get<uint16_t>();
1284
25
    } catch ( ... ) { }
1285
1286
25
    bits %= (10000+1);
1287
1288
25
    if ( bits == 0 ) {
1289
5
        bits = 1;
1290
5
    }
1291
1292
25
    /* noret */ mpz_urandomb(res.GetPtr(), libgmp_detail::rng_state, 512);
1293
1294
25
    return true;
1295
#else
1296
    (void)ds;
1297
    (void)res;
1298
    (void)bn;
1299
1300
    return false;
1301
#endif
1302
25
}
cryptofuzz::module::libgmp_bignum::Rand::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1276
11
bool Rand::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1277
#if !defined(HAVE_MINI_GMP)
1278
    (void)bn;
1279
1280
    uint16_t bits = 0;
1281
1282
    try {
1283
        bits = ds.Get<uint16_t>();
1284
    } catch ( ... ) { }
1285
1286
    bits %= (10000+1);
1287
1288
    if ( bits == 0 ) {
1289
        bits = 1;
1290
    }
1291
1292
    /* noret */ mpz_urandomb(res.GetPtr(), libgmp_detail::rng_state, 512);
1293
1294
    return true;
1295
#else
1296
11
    (void)ds;
1297
11
    (void)res;
1298
11
    (void)bn;
1299
1300
11
    return false;
1301
11
#endif
1302
11
}
1303
1304
17
bool NumBits::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1305
17
    (void)ds;
1306
1307
    /* libgmp returns bit size of 1 of the value 0,
1308
     * whereas other libraries return 0
1309
     */
1310
17
    if ( mpz_sgn(bn[0].GetPtr()) == 0 ) {
1311
4
        return false;
1312
4
    }
1313
1314
13
    res.Set( std::to_string( mpz_sizeinbase(bn[0].GetPtr(), 2) ) );
1315
1316
13
    return true;
1317
17
}
cryptofuzz::module::libgmp_bignum::NumBits::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1304
13
bool NumBits::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1305
13
    (void)ds;
1306
1307
    /* libgmp returns bit size of 1 of the value 0,
1308
     * whereas other libraries return 0
1309
     */
1310
13
    if ( mpz_sgn(bn[0].GetPtr()) == 0 ) {
1311
3
        return false;
1312
3
    }
1313
1314
10
    res.Set( std::to_string( mpz_sizeinbase(bn[0].GetPtr(), 2) ) );
1315
1316
10
    return true;
1317
13
}
cryptofuzz::module::libgmp_bignum::NumBits::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1304
4
bool NumBits::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1305
4
    (void)ds;
1306
1307
    /* libgmp returns bit size of 1 of the value 0,
1308
     * whereas other libraries return 0
1309
     */
1310
4
    if ( mpz_sgn(bn[0].GetPtr()) == 0 ) {
1311
1
        return false;
1312
1
    }
1313
1314
3
    res.Set( std::to_string( mpz_sizeinbase(bn[0].GetPtr(), 2) ) );
1315
1316
3
    return true;
1317
4
}
1318
1319
10
bool CondAdd::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1320
10
    (void)ds;
1321
1322
10
    if ( !mpz_sgn(bn[2].GetPtr()) ) {
1323
1
        /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1324
9
    } else {
1325
9
        /* noret */ mpz_add(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1326
9
    }
1327
1328
10
    return true;
1329
10
}
cryptofuzz::module::libgmp_bignum::CondAdd::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1319
9
bool CondAdd::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1320
9
    (void)ds;
1321
1322
9
    if ( !mpz_sgn(bn[2].GetPtr()) ) {
1323
1
        /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1324
8
    } else {
1325
8
        /* noret */ mpz_add(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1326
8
    }
1327
1328
9
    return true;
1329
9
}
cryptofuzz::module::libgmp_bignum::CondAdd::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1319
1
bool CondAdd::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1320
1
    (void)ds;
1321
1322
1
    if ( !mpz_sgn(bn[2].GetPtr()) ) {
1323
0
        /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1324
1
    } else {
1325
1
        /* noret */ mpz_add(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1326
1
    }
1327
1328
1
    return true;
1329
1
}
1330
1331
15
bool CondSub::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1332
15
    (void)ds;
1333
1334
15
    if ( !mpz_sgn(bn[2].GetPtr()) ) {
1335
2
        /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1336
13
    } else {
1337
13
        /* noret */ mpz_sub(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1338
13
    }
1339
1340
15
    return true;
1341
15
}
cryptofuzz::module::libgmp_bignum::CondSub::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1331
12
bool CondSub::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1332
12
    (void)ds;
1333
1334
12
    if ( !mpz_sgn(bn[2].GetPtr()) ) {
1335
1
        /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1336
11
    } else {
1337
11
        /* noret */ mpz_sub(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1338
11
    }
1339
1340
12
    return true;
1341
12
}
cryptofuzz::module::libgmp_bignum::CondSub::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1331
3
bool CondSub::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1332
3
    (void)ds;
1333
1334
3
    if ( !mpz_sgn(bn[2].GetPtr()) ) {
1335
1
        /* noret */ mpz_set(res.GetPtr(), bn[0].GetPtr());
1336
2
    } else {
1337
2
        /* noret */ mpz_sub(res.GetPtr(), bn[0].GetPtr(), bn[1].GetPtr());
1338
2
    }
1339
1340
3
    return true;
1341
3
}
1342
1343
17
bool RandRange::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1344
#if !defined(HAVE_MINI_GMP)
1345
    (void)ds;
1346
1347
    bool ret = false;
1348
1349
13
    CF_CHECK_EQ(mpz_sgn(bn[0].GetPtr()), 0);
1350
3
    CF_CHECK_NE(mpz_sgn(bn[1].GetPtr()), 0);
1351
1352
3
    /* noret */ mpz_urandomm(res.GetPtr(), libgmp_detail::rng_state, bn[1].GetPtr());
1353
1354
3
    ret = true;
1355
1356
13
end:
1357
13
    return ret;
1358
#else
1359
    (void)ds;
1360
    (void)res;
1361
    (void)bn;
1362
1363
    return false;
1364
#endif
1365
3
}
cryptofuzz::module::libgmp_bignum::RandRange::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1343
13
bool RandRange::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1344
13
#if !defined(HAVE_MINI_GMP)
1345
13
    (void)ds;
1346
1347
13
    bool ret = false;
1348
1349
13
    CF_CHECK_EQ(mpz_sgn(bn[0].GetPtr()), 0);
1350
3
    CF_CHECK_NE(mpz_sgn(bn[1].GetPtr()), 0);
1351
1352
3
    /* noret */ mpz_urandomm(res.GetPtr(), libgmp_detail::rng_state, bn[1].GetPtr());
1353
1354
3
    ret = true;
1355
1356
13
end:
1357
13
    return ret;
1358
#else
1359
    (void)ds;
1360
    (void)res;
1361
    (void)bn;
1362
1363
    return false;
1364
#endif
1365
3
}
cryptofuzz::module::libgmp_bignum::RandRange::Run(fuzzing::datasource::Datasource&, cryptofuzz::module::libgmp_bignum::Bignum&, cryptofuzz::module::libgmp_bignum::BignumCluster&) const
Line
Count
Source
1343
4
bool RandRange::Run(Datasource& ds, Bignum& res, BignumCluster& bn) const {
1344
#if !defined(HAVE_MINI_GMP)
1345
    (void)ds;
1346
1347
    bool ret = false;
1348
1349
    CF_CHECK_EQ(mpz_sgn(bn[0].GetPtr()), 0);
1350
    CF_CHECK_NE(mpz_sgn(bn[1].GetPtr()), 0);
1351
1352
    /* noret */ mpz_urandomm(res.GetPtr(), libgmp_detail::rng_state, bn[1].GetPtr());
1353
1354
    ret = true;
1355
1356
end:
1357
    return ret;
1358
#else
1359
4
    (void)ds;
1360
4
    (void)res;
1361
4
    (void)bn;
1362
1363
4
    return false;
1364
4
#endif
1365
4
}
1366
1367
} /* namespace libgmp_bignum */
1368
} /* namespace module */
1369
} /* namespace cryptofuzz */