Coverage Report

Created: 2022-08-24 06:37

/src/cryptofuzz-sp-math/include/cryptofuzz/components.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <cryptofuzz/generic.h>
4
#include <cryptofuzz/util_hexdump.h>
5
#include <fuzzing/datasource/datasource.hpp>
6
#include "../../third_party/json/json.hpp"
7
8
namespace cryptofuzz {
9
namespace component {
10
11
using SymmetricCipherType = Type;
12
using AsymmetricCipherType = Type;
13
using DigestType = Type;
14
using KDFType = Type;
15
using CurveType = Type;
16
using CalcOp = Type;
17
18
using Modifier = Buffer;
19
using Cleartext = Buffer;
20
using Digest = Buffer;
21
using MAC = Buffer;
22
using SymmetricIV = Buffer;
23
using SymmetricKey = Buffer;
24
using AsymmetricPrivKey = Buffer;
25
using Key = Buffer;
26
using Envelope = Buffer;
27
using Signature = Buffer;
28
using PrivateKeyPEM = Buffer;
29
using Tag = Buffer;
30
using AAD = Buffer;
31
using Secret = Buffer;
32
33
using ECC_PrivateKey = Bignum;
34
using Bignum = ::cryptofuzz::Bignum;
35
36
class SymmetricCipher {
37
    public:
38
        const SymmetricIV iv;
39
        const SymmetricKey key;
40
        const SymmetricCipherType cipherType;
41
        SymmetricCipher(Datasource& ds);
42
        SymmetricCipher(nlohmann::json json);
43
        nlohmann::json ToJSON(void) const;
44
45
        bool operator==(const SymmetricCipher& rhs) const;
46
        void Serialize(Datasource& ds) const;
47
};
48
49
class Ciphertext {
50
    public:
51
        Buffer ciphertext;
52
        std::optional<Tag> tag;
53
54
        Ciphertext(Datasource& ds);
55
        Ciphertext(Buffer ciphertext, std::optional<Tag> tag = std::nullopt);
56
57
        bool operator==(const Ciphertext& rhs) const;
58
        void Serialize(Datasource& ds) const;
59
};
60
61
class BignumPair {
62
    public:
63
        Bignum first, second;
64
65
        BignumPair(Datasource& ds);
66
        BignumPair(const std::string first, const std::string second);
67
        BignumPair(nlohmann::json json);
68
69
        bool operator==(const BignumPair& rhs) const;
70
        void Serialize(Datasource& ds) const;
71
        nlohmann::json ToJSON(void) const;
72
};
73
74
using ECC_Point = BignumPair;
75
76
using ECC_PublicKey = BignumPair;
77
78
class ECC_KeyPair {
79
    public:
80
        ECC_PrivateKey priv;
81
        ECC_PublicKey pub;
82
83
        ECC_KeyPair(Datasource& ds);
84
        ECC_KeyPair(ECC_PrivateKey priv, BignumPair pub);
85
86
        bool operator==(const ECC_KeyPair& rhs) const;
87
        void Serialize(Datasource& ds) const;
88
        nlohmann::json ToJSON(void) const;
89
};
90
91
92
class ECDSA_Signature {
93
    public:
94
        BignumPair signature;
95
        ECC_PublicKey pub;
96
97
        ECDSA_Signature(Datasource& ds);
98
        ECDSA_Signature(BignumPair signature, ECC_PublicKey pub);
99
        ECDSA_Signature(nlohmann::json json);
100
101
        bool operator==(const ECDSA_Signature& rhs) const;
102
        void Serialize(Datasource& ds) const;
103
        nlohmann::json ToJSON(void) const;
104
};
105
106
using ECGDSA_Signature = ECDSA_Signature;
107
using ECRDSA_Signature = ECDSA_Signature;
108
using Schnorr_Signature = ECDSA_Signature;
109
110
class MACType {
111
    public:
112
        bool mode;
113
        Type type;
114
115
        MACType(Datasource& ds);
116
        MACType(nlohmann::json json);
117
        nlohmann::json ToJSON(void) const;
118
        bool operator==(const MACType& rhs) const;
119
        void Serialize(Datasource& ds) const;
120
};
121
122
using DH_Key = BignumPair;
123
using DH_KeyPair = BignumPair;
124
125
class G2 {
126
    public:
127
        BignumPair first, second;
128
129
        G2(Datasource& ds) :
130
            first(ds),
131
            second(ds)
132
2.08k
        { }
133
134
        G2(const std::string a_first, const std::string a_second, const std::string b_first, const std::string b_second) :
135
            first(a_first, a_second),
136
            second(b_first, b_second)
137
0
        { }
138
139
0
        inline bool operator==(const G2& rhs) const {
140
0
            return
141
0
                (first == rhs.first) &&
142
0
                (second == rhs.second);
143
0
        }
144
        G2(nlohmann::json json);
145
        nlohmann::json ToJSON(void) const;
146
        void Serialize(Datasource& ds) const;
147
};
148
149
using Fp2 = BignumPair;
150
151
class Fp12 {
152
    public:
153
        Bignum bn1;
154
        Bignum bn2;
155
        Bignum bn3;
156
        Bignum bn4;
157
        Bignum bn5;
158
        Bignum bn6;
159
        Bignum bn7;
160
        Bignum bn8;
161
        Bignum bn9;
162
        Bignum bn10;
163
        Bignum bn11;
164
        Bignum bn12;
165
166
        Fp12(Datasource& ds) :
167
            bn1(ds),
168
            bn2(ds),
169
            bn3(ds),
170
            bn4(ds),
171
            bn5(ds),
172
            bn6(ds),
173
            bn7(ds),
174
            bn8(ds),
175
            bn9(ds),
176
            bn10(ds),
177
            bn11(ds),
178
            bn12(ds)
179
1.42k
        { }
180
181
        Fp12(
182
        std::string bn1,
183
        std::string bn2,
184
        std::string bn3,
185
        std::string bn4,
186
        std::string bn5,
187
        std::string bn6,
188
        std::string bn7,
189
        std::string bn8,
190
        std::string bn9,
191
        std::string bn10,
192
        std::string bn11,
193
        std::string bn12) :
194
            bn1(bn1),
195
            bn2(bn2),
196
            bn3(bn3),
197
            bn4(bn4),
198
            bn5(bn5),
199
            bn6(bn6),
200
            bn7(bn7),
201
            bn8(bn8),
202
            bn9(bn9),
203
            bn10(bn10),
204
            bn11(bn11),
205
            bn12(bn12)
206
0
        { }
207
        Fp12(nlohmann::json json);
208
209
0
        inline bool operator==(const Fp12& rhs) const {
210
0
            return
211
0
                (bn1 == rhs.bn1) &&
212
0
                (bn2 == rhs.bn2) &&
213
0
                (bn3 == rhs.bn3) &&
214
0
                (bn4 == rhs.bn4) &&
215
0
                (bn5 == rhs.bn5) &&
216
0
                (bn6 == rhs.bn6) &&
217
0
                (bn7 == rhs.bn7) &&
218
0
                (bn8 == rhs.bn8) &&
219
0
                (bn9 == rhs.bn9) &&
220
0
                (bn10 == rhs.bn10) &&
221
0
                (bn11 == rhs.bn11) &&
222
0
                (bn12 == rhs.bn12);
223
0
        }
224
        void Serialize(Datasource& ds) const;
225
        nlohmann::json ToJSON(void) const;
226
};
227
228
class BLS_Signature {
229
    public:
230
        G2 signature;
231
        ECC_PublicKey pub;
232
233
        BLS_Signature(Datasource& ds);
234
        BLS_Signature(G2 signature, ECC_PublicKey pub);
235
        BLS_Signature(nlohmann::json json);
236
237
        bool operator==(const BLS_Signature& rhs) const;
238
        void Serialize(Datasource& ds) const;
239
        nlohmann::json ToJSON(void) const;
240
};
241
242
using BLS_PrivateKey = Bignum;
243
using BLS_PublicKey = BignumPair;
244
using G1 = BignumPair;
245
246
class BLS_KeyPair {
247
    public:
248
        BLS_PrivateKey priv;
249
        BLS_PublicKey pub;
250
251
        BLS_KeyPair(Datasource& ds);
252
        BLS_KeyPair(BLS_PrivateKey priv, BignumPair pub);
253
254
        bool operator==(const BLS_KeyPair& rhs) const;
255
        void Serialize(Datasource& ds) const;
256
        nlohmann::json ToJSON(void) const;
257
};
258
259
class BLS_BatchSignature {
260
    public:
261
        std::vector< std::pair<G1, G2> > msgpub;
262
263
        BLS_BatchSignature(std::vector< std::pair<G1, G2> > msgpub);
264
265
        bool operator==(const BLS_BatchSignature& rhs) const;
266
        void Serialize(Datasource& ds) const;
267
        nlohmann::json ToJSON(void) const;
268
};
269
270
class BLS_BatchSign_Vector {
271
    public:
272
        typedef struct {
273
            Bignum priv;
274
            G1 g1;
275
        } BatchSign_single;
276
        std::vector<BatchSign_single> c;
277
278
        BLS_BatchSign_Vector(Datasource& ds);
279
        BLS_BatchSign_Vector(G1 g1, G2 g2);
280
        BLS_BatchSign_Vector(nlohmann::json json);
281
282
        bool operator==(const BLS_BatchSign_Vector& rhs) const;
283
        void Serialize(Datasource& ds) const;
284
        nlohmann::json ToJSON(void) const;
285
};
286
287
class BLS_BatchVerify_Vector {
288
    public:
289
        typedef struct {
290
            G1 g1;
291
            G2 g2;
292
        } BatchVerify_single;
293
        std::vector<BatchVerify_single> c;
294
295
        BLS_BatchVerify_Vector(Datasource& ds);
296
        BLS_BatchVerify_Vector(G1 g1, G2 g2);
297
        BLS_BatchVerify_Vector(nlohmann::json json);
298
299
        bool operator==(const BLS_BatchVerify_Vector& rhs) const;
300
        void Serialize(Datasource& ds) const;
301
        nlohmann::json ToJSON(void) const;
302
};
303
304
class BLS_G1_Vector {
305
    public:
306
        std::vector<component::G1> points;
307
308
        BLS_G1_Vector(Datasource& ds);
309
        BLS_G1_Vector(nlohmann::json json);
310
311
        bool operator==(const BLS_G1_Vector& rhs) const;
312
        void Serialize(Datasource& ds) const;
313
        nlohmann::json ToJSON(void) const;
314
};
315
316
class BLS_G2_Vector {
317
    public:
318
        std::vector<component::G2> points;
319
320
        BLS_G2_Vector(Datasource& ds);
321
        BLS_G2_Vector(nlohmann::json json);
322
323
        bool operator==(const BLS_G2_Vector& rhs) const;
324
        void Serialize(Datasource& ds) const;
325
        nlohmann::json ToJSON(void) const;
326
};
327
328
class SR25519_Signature {
329
    public:
330
        BignumPair signature;
331
        Bignum pub;
332
333
        SR25519_Signature(Datasource& ds);
334
        SR25519_Signature(BignumPair signature, Bignum pub);
335
        SR25519_Signature(nlohmann::json json);
336
337
        bool operator==(const SR25519_Signature& rhs) const;
338
        void Serialize(Datasource& ds) const;
339
        nlohmann::json ToJSON(void) const;
340
};
341
342
} /* namespace component */
343
} /* namespace cryptofuzz */