/src/cryptofuzz/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 Key3 = std::array<Key, 3>; |
27 | | using Envelope = Buffer; |
28 | | using Signature = Buffer; |
29 | | using PrivateKeyPEM = Buffer; |
30 | | using Tag = Buffer; |
31 | | using AAD = Buffer; |
32 | | using Secret = Buffer; |
33 | | |
34 | | using ECC_PrivateKey = Bignum; |
35 | | using Bignum = ::cryptofuzz::Bignum; |
36 | | |
37 | | class SymmetricCipher { |
38 | | public: |
39 | | const SymmetricIV iv; |
40 | | const SymmetricKey key; |
41 | | const SymmetricCipherType cipherType; |
42 | | SymmetricCipher(Datasource& ds); |
43 | | SymmetricCipher(nlohmann::json json); |
44 | | nlohmann::json ToJSON(void) const; |
45 | | |
46 | | bool operator==(const SymmetricCipher& rhs) const; |
47 | | void Serialize(Datasource& ds) const; |
48 | | }; |
49 | | |
50 | | class Ciphertext { |
51 | | public: |
52 | | Buffer ciphertext; |
53 | | std::optional<Tag> tag; |
54 | | |
55 | | Ciphertext(Datasource& ds); |
56 | | Ciphertext(Buffer ciphertext, std::optional<Tag> tag = std::nullopt); |
57 | | |
58 | | bool operator==(const Ciphertext& rhs) const; |
59 | | void Serialize(Datasource& ds) const; |
60 | | }; |
61 | | |
62 | | class BignumPair { |
63 | | public: |
64 | | Bignum first, second; |
65 | | |
66 | | BignumPair(Datasource& ds); |
67 | | BignumPair(const std::string first, const std::string second); |
68 | | BignumPair(nlohmann::json json); |
69 | | |
70 | | bool operator==(const BignumPair& rhs) const; |
71 | | void Serialize(Datasource& ds) const; |
72 | | nlohmann::json ToJSON(void) const; |
73 | | }; |
74 | | |
75 | | using ECC_Point = BignumPair; |
76 | | |
77 | | using ECC_PublicKey = BignumPair; |
78 | | |
79 | | class ECC_KeyPair { |
80 | | public: |
81 | | ECC_PrivateKey priv; |
82 | | ECC_PublicKey pub; |
83 | | |
84 | | ECC_KeyPair(Datasource& ds); |
85 | | ECC_KeyPair(ECC_PrivateKey priv, BignumPair pub); |
86 | | ECC_KeyPair(nlohmann::json json); |
87 | | |
88 | | bool operator==(const ECC_KeyPair& rhs) const; |
89 | | void Serialize(Datasource& ds) const; |
90 | | nlohmann::json ToJSON(void) const; |
91 | | }; |
92 | | |
93 | | class ECCSI_Signature { |
94 | | public: |
95 | | BignumPair signature; |
96 | | ECC_PublicKey pub; |
97 | | BignumPair pvt; |
98 | | |
99 | | ECCSI_Signature(Datasource& ds); |
100 | | ECCSI_Signature(BignumPair signature, ECC_PublicKey pub, BignumPair pvt); |
101 | | ECCSI_Signature(nlohmann::json json); |
102 | | |
103 | | bool operator==(const ECCSI_Signature& rhs) const; |
104 | | void Serialize(Datasource& ds) const; |
105 | | nlohmann::json ToJSON(void) const; |
106 | | }; |
107 | | |
108 | | class ECDSA_Signature { |
109 | | public: |
110 | | BignumPair signature; |
111 | | ECC_PublicKey pub; |
112 | | |
113 | | ECDSA_Signature(Datasource& ds); |
114 | | ECDSA_Signature(BignumPair signature, ECC_PublicKey pub); |
115 | | ECDSA_Signature(nlohmann::json json); |
116 | | |
117 | | bool operator==(const ECDSA_Signature& rhs) const; |
118 | | void Serialize(Datasource& ds) const; |
119 | | nlohmann::json ToJSON(void) const; |
120 | | }; |
121 | | |
122 | | using ECGDSA_Signature = ECDSA_Signature; |
123 | | using ECRDSA_Signature = ECDSA_Signature; |
124 | | using Schnorr_Signature = ECDSA_Signature; |
125 | | |
126 | | class MACType { |
127 | | public: |
128 | | bool mode; |
129 | | Type type; |
130 | | |
131 | | MACType(Datasource& ds); |
132 | | MACType(nlohmann::json json); |
133 | | nlohmann::json ToJSON(void) const; |
134 | | bool operator==(const MACType& rhs) const; |
135 | | void Serialize(Datasource& ds) const; |
136 | | }; |
137 | | |
138 | | using DH_Key = BignumPair; |
139 | | using DH_KeyPair = BignumPair; |
140 | | |
141 | | class DSA_Parameters { |
142 | | public: |
143 | | Bignum p, q, g; |
144 | | |
145 | | DSA_Parameters(Datasource& ds) : |
146 | | p(ds), |
147 | | q(ds), |
148 | | g(ds) |
149 | 4.10k | { } |
150 | | |
151 | | DSA_Parameters( |
152 | | std::string p, |
153 | | std::string q, |
154 | | std::string g) : |
155 | | p(p), |
156 | | q(q), |
157 | | g(g) |
158 | 0 | { } |
159 | | DSA_Parameters(nlohmann::json json); |
160 | | |
161 | 0 | inline bool operator==(const DSA_Parameters& rhs) const { |
162 | 0 | return |
163 | 0 | (p == rhs.p) && |
164 | 0 | (q == rhs.q) && |
165 | 0 | (g == rhs.g); |
166 | 0 | } |
167 | | void Serialize(Datasource& ds) const; |
168 | | nlohmann::json ToJSON(void) const; |
169 | | }; |
170 | | |
171 | | class DSA_Signature { |
172 | | public: |
173 | | BignumPair signature; |
174 | | Bignum pub; |
175 | | |
176 | | DSA_Signature(Datasource& ds); |
177 | | DSA_Signature(BignumPair signature, Bignum pub); |
178 | | DSA_Signature(nlohmann::json json); |
179 | | |
180 | | bool operator==(const DSA_Signature& rhs) const; |
181 | | void Serialize(Datasource& ds) const; |
182 | | nlohmann::json ToJSON(void) const; |
183 | | }; |
184 | | |
185 | | using DSA_KeyPair = BignumPair; |
186 | | |
187 | | class G2 { |
188 | | public: |
189 | | BignumPair first, second; |
190 | | |
191 | | G2(Datasource& ds) : |
192 | | first(ds), |
193 | | second(ds) |
194 | 32.8k | { } |
195 | | |
196 | | G2(const std::string a_first, const std::string a_second, const std::string b_first, const std::string b_second) : |
197 | | first(a_first, a_second), |
198 | | second(b_first, b_second) |
199 | 0 | { } |
200 | | |
201 | 0 | inline bool operator==(const G2& rhs) const { |
202 | 0 | return |
203 | 0 | (first == rhs.first) && |
204 | 0 | (second == rhs.second); |
205 | 0 | } |
206 | | G2(nlohmann::json json); |
207 | | nlohmann::json ToJSON(void) const; |
208 | | void Serialize(Datasource& ds) const; |
209 | | }; |
210 | | |
211 | | using Fp2 = BignumPair; |
212 | | |
213 | | class Fp12 { |
214 | | public: |
215 | | Bignum bn1; |
216 | | Bignum bn2; |
217 | | Bignum bn3; |
218 | | Bignum bn4; |
219 | | Bignum bn5; |
220 | | Bignum bn6; |
221 | | Bignum bn7; |
222 | | Bignum bn8; |
223 | | Bignum bn9; |
224 | | Bignum bn10; |
225 | | Bignum bn11; |
226 | | Bignum bn12; |
227 | | |
228 | | Fp12(Datasource& ds) : |
229 | | bn1(ds), |
230 | | bn2(ds), |
231 | | bn3(ds), |
232 | | bn4(ds), |
233 | | bn5(ds), |
234 | | bn6(ds), |
235 | | bn7(ds), |
236 | | bn8(ds), |
237 | | bn9(ds), |
238 | | bn10(ds), |
239 | | bn11(ds), |
240 | | bn12(ds) |
241 | 10.8k | { } |
242 | | |
243 | | Fp12( |
244 | | std::string bn1, |
245 | | std::string bn2, |
246 | | std::string bn3, |
247 | | std::string bn4, |
248 | | std::string bn5, |
249 | | std::string bn6, |
250 | | std::string bn7, |
251 | | std::string bn8, |
252 | | std::string bn9, |
253 | | std::string bn10, |
254 | | std::string bn11, |
255 | | std::string bn12) : |
256 | | bn1(bn1), |
257 | | bn2(bn2), |
258 | | bn3(bn3), |
259 | | bn4(bn4), |
260 | | bn5(bn5), |
261 | | bn6(bn6), |
262 | | bn7(bn7), |
263 | | bn8(bn8), |
264 | | bn9(bn9), |
265 | | bn10(bn10), |
266 | | bn11(bn11), |
267 | | bn12(bn12) |
268 | 0 | { } |
269 | | Fp12(nlohmann::json json); |
270 | | |
271 | 0 | inline bool operator==(const Fp12& rhs) const { |
272 | 0 | return |
273 | 0 | (bn1 == rhs.bn1) && |
274 | 0 | (bn2 == rhs.bn2) && |
275 | 0 | (bn3 == rhs.bn3) && |
276 | 0 | (bn4 == rhs.bn4) && |
277 | 0 | (bn5 == rhs.bn5) && |
278 | 0 | (bn6 == rhs.bn6) && |
279 | 0 | (bn7 == rhs.bn7) && |
280 | 0 | (bn8 == rhs.bn8) && |
281 | 0 | (bn9 == rhs.bn9) && |
282 | 0 | (bn10 == rhs.bn10) && |
283 | 0 | (bn11 == rhs.bn11) && |
284 | 0 | (bn12 == rhs.bn12); |
285 | 0 | } |
286 | | void Serialize(Datasource& ds) const; |
287 | | nlohmann::json ToJSON(void) const; |
288 | | }; |
289 | | |
290 | | class BLS_Signature { |
291 | | public: |
292 | | G2 signature; |
293 | | ECC_PublicKey pub; |
294 | | |
295 | | BLS_Signature(Datasource& ds); |
296 | | BLS_Signature(G2 signature, ECC_PublicKey pub); |
297 | | BLS_Signature(nlohmann::json json); |
298 | | |
299 | | bool operator==(const BLS_Signature& rhs) const; |
300 | | void Serialize(Datasource& ds) const; |
301 | | nlohmann::json ToJSON(void) const; |
302 | | }; |
303 | | |
304 | | using BLS_PrivateKey = Bignum; |
305 | | using BLS_PublicKey = BignumPair; |
306 | | using G1 = BignumPair; |
307 | | |
308 | | class BLS_KeyPair { |
309 | | public: |
310 | | BLS_PrivateKey priv; |
311 | | BLS_PublicKey pub; |
312 | | |
313 | | BLS_KeyPair(Datasource& ds); |
314 | | BLS_KeyPair(BLS_PrivateKey priv, BignumPair pub); |
315 | | |
316 | | bool operator==(const BLS_KeyPair& rhs) const; |
317 | | void Serialize(Datasource& ds) const; |
318 | | nlohmann::json ToJSON(void) const; |
319 | | }; |
320 | | |
321 | | class BLS_BatchSignature { |
322 | | public: |
323 | | std::vector< std::pair<G1, G2> > msgpub; |
324 | | |
325 | | BLS_BatchSignature(std::vector< std::pair<G1, G2> > msgpub); |
326 | | |
327 | | bool operator==(const BLS_BatchSignature& rhs) const; |
328 | | void Serialize(Datasource& ds) const; |
329 | | nlohmann::json ToJSON(void) const; |
330 | | }; |
331 | | |
332 | | class BLS_BatchSign_Vector { |
333 | | public: |
334 | | typedef struct { |
335 | | Bignum priv; |
336 | | G1 g1; |
337 | | } BatchSign_single; |
338 | | std::vector<BatchSign_single> c; |
339 | | |
340 | | BLS_BatchSign_Vector(Datasource& ds); |
341 | | BLS_BatchSign_Vector(G1 g1, G2 g2); |
342 | | BLS_BatchSign_Vector(nlohmann::json json); |
343 | | |
344 | | bool operator==(const BLS_BatchSign_Vector& rhs) const; |
345 | | void Serialize(Datasource& ds) const; |
346 | | nlohmann::json ToJSON(void) const; |
347 | | }; |
348 | | |
349 | | class BLS_BatchVerify_Vector { |
350 | | public: |
351 | | typedef struct { |
352 | | G1 g1; |
353 | | G2 g2; |
354 | | } BatchVerify_single; |
355 | | std::vector<BatchVerify_single> c; |
356 | | |
357 | | BLS_BatchVerify_Vector(Datasource& ds); |
358 | | BLS_BatchVerify_Vector(G1 g1, G2 g2); |
359 | | BLS_BatchVerify_Vector(nlohmann::json json); |
360 | | |
361 | | bool operator==(const BLS_BatchVerify_Vector& rhs) const; |
362 | | void Serialize(Datasource& ds) const; |
363 | | nlohmann::json ToJSON(void) const; |
364 | | }; |
365 | | |
366 | | class BLS_G1_Vector { |
367 | | public: |
368 | | std::vector<component::G1> points; |
369 | | |
370 | | BLS_G1_Vector(Datasource& ds); |
371 | | BLS_G1_Vector(nlohmann::json json); |
372 | | |
373 | | bool operator==(const BLS_G1_Vector& rhs) const; |
374 | | void Serialize(Datasource& ds) const; |
375 | | nlohmann::json ToJSON(void) const; |
376 | | }; |
377 | | |
378 | | class BLS_G2_Vector { |
379 | | public: |
380 | | std::vector<component::G2> points; |
381 | | |
382 | | BLS_G2_Vector(Datasource& ds); |
383 | | BLS_G2_Vector(nlohmann::json json); |
384 | | |
385 | | bool operator==(const BLS_G2_Vector& rhs) const; |
386 | | void Serialize(Datasource& ds) const; |
387 | | nlohmann::json ToJSON(void) const; |
388 | | }; |
389 | | |
390 | | class BLS_G1_Scalar_Vector { |
391 | | public: |
392 | | std::vector< std::pair<component::G1, component::Bignum> > points_scalars; |
393 | | |
394 | | BLS_G1_Scalar_Vector(Datasource& ds); |
395 | | BLS_G1_Scalar_Vector(nlohmann::json json); |
396 | | |
397 | | bool operator==(const BLS_G1_Scalar_Vector& rhs) const; |
398 | | void Serialize(Datasource& ds) const; |
399 | | nlohmann::json ToJSON(void) const; |
400 | | }; |
401 | | |
402 | | class SR25519_Signature { |
403 | | public: |
404 | | BignumPair signature; |
405 | | Bignum pub; |
406 | | |
407 | | SR25519_Signature(Datasource& ds); |
408 | | SR25519_Signature(BignumPair signature, Bignum pub); |
409 | | SR25519_Signature(nlohmann::json json); |
410 | | |
411 | | bool operator==(const SR25519_Signature& rhs) const; |
412 | | void Serialize(Datasource& ds) const; |
413 | | nlohmann::json ToJSON(void) const; |
414 | | }; |
415 | | |
416 | | } /* namespace component */ |
417 | | } /* namespace cryptofuzz */ |