Coverage Report

Created: 2022-08-24 06:37

/src/cryptofuzz-sp-math-all/include/cryptofuzz/operations.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <cryptofuzz/components.h>
4
#include <cryptofuzz/repository.h>
5
#include <fuzzing/datasource/datasource.hpp>
6
#include "../../third_party/json/json.hpp"
7
8
namespace cryptofuzz {
9
namespace operation {
10
11
using fuzzing::datasource::Datasource;
12
13
class Operation {
14
    public:
15
        component::Modifier modifier;
16
17
        Operation(component::Modifier modifier) :
18
            modifier(std::move(modifier))
19
171k
        { }
20
21
        Operation(nlohmann::json modifier) :
22
            modifier(modifier)
23
0
        { }
24
25
        virtual std::string Name(void) const = 0;
26
        virtual std::string ToString(void) const = 0;
27
        virtual nlohmann::json ToJSON(void) const = 0;
28
0
        virtual std::string GetAlgorithmString(void) const {
29
0
            return "(no algorithm)";
30
0
        }
31
};
32
33
class Digest : public Operation {
34
    public:
35
        const component::Cleartext cleartext;
36
        const component::DigestType digestType;
37
38
        Digest(Datasource& ds, component::Modifier modifier) :
39
            Operation(std::move(modifier)),
40
            cleartext(ds),
41
            digestType(ds)
42
952
        { }
43
44
        Digest(nlohmann::json json) :
45
            Operation(json["modifier"]),
46
            cleartext(json["cleartext"]),
47
            digestType(json["digestType"])
48
0
        { }
49
50
51
936
        static size_t MaxOperations(void) { return 20; }
52
        std::string Name(void) const override;
53
        std::string ToString(void) const override;
54
        nlohmann::json ToJSON(void) const override;
55
0
        std::string GetAlgorithmString(void) const override {
56
0
            return repository::DigestToString(digestType.Get());
57
0
        }
58
0
        inline bool operator==(const Digest& rhs) const {
59
0
            return
60
0
                (cleartext == rhs.cleartext) &&
61
0
                (digestType == rhs.digestType) &&
62
0
                (modifier == rhs.modifier);
63
0
        }
64
0
        void Serialize(Datasource& ds) const {
65
0
            cleartext.Serialize(ds);
66
0
            digestType.Serialize(ds);
67
0
        }
68
};
69
70
class HMAC : public Operation {
71
    public:
72
        const component::Cleartext cleartext;
73
        const component::DigestType digestType;
74
        const component::SymmetricCipher cipher;
75
76
        HMAC(Datasource& ds, component::Modifier modifier) :
77
            Operation(std::move(modifier)),
78
            cleartext(ds),
79
            digestType(ds),
80
            cipher(ds)
81
731
        { }
82
        HMAC(nlohmann::json json) :
83
            Operation(json["modifier"]),
84
            cleartext(json["cleartext"]),
85
            digestType(json["digestType"]),
86
            cipher(json["cipher"])
87
0
        { }
88
89
722
        static size_t MaxOperations(void) { return 20; }
90
        std::string Name(void) const override;
91
        std::string ToString(void) const override;
92
        nlohmann::json ToJSON(void) const override;
93
0
        std::string GetAlgorithmString(void) const override {
94
0
            return repository::DigestToString(digestType.Get());
95
0
        }
96
0
        inline bool operator==(const HMAC& rhs) const {
97
0
            return
98
0
                (cleartext == rhs.cleartext) &&
99
0
                (digestType == rhs.digestType) &&
100
0
                (cipher == rhs.cipher) &&
101
0
                (modifier == rhs.modifier);
102
0
        }
103
0
        void Serialize(Datasource& ds) const {
104
0
            cleartext.Serialize(ds);
105
0
            digestType.Serialize(ds);
106
0
            cipher.Serialize(ds);
107
0
        }
108
};
109
110
class UMAC : public Operation {
111
    public:
112
        const component::Cleartext cleartext;
113
        const component::Cleartext key;
114
        const component::Cleartext iv;
115
        uint8_t type;
116
        const uint64_t outSize;
117
118
        UMAC(Datasource& ds, component::Modifier modifier) :
119
            Operation(std::move(modifier)),
120
            cleartext(ds),
121
            key(ds),
122
            iv(ds),
123
            type(ds.Get<uint64_t>() % 4),
124
            outSize(ds.Get<uint64_t>() % 1024)
125
145
        { }
126
        UMAC(nlohmann::json json) :
127
            Operation(json["modifier"]),
128
            cleartext(json["cleartext"]),
129
            key(json["key"]),
130
            iv(json["iv"]),
131
            type(json["type"].get<uint64_t>()),
132
            outSize(json["outSize"].get<uint64_t>())
133
0
        { }
134
135
133
        static size_t MaxOperations(void) { return 20; }
136
        std::string Name(void) const override;
137
        std::string ToString(void) const override;
138
        nlohmann::json ToJSON(void) const override;
139
0
        inline bool operator==(const UMAC& rhs) const {
140
0
            return
141
0
                (cleartext == rhs.cleartext) &&
142
0
                (key == rhs.key) &&
143
0
                (iv == rhs.iv) &&
144
0
                (type == rhs.type) &&
145
0
                (outSize == rhs.outSize) &&
146
0
                (modifier == rhs.modifier);
147
0
        }
148
0
        void Serialize(Datasource& ds) const {
149
0
            cleartext.Serialize(ds);
150
0
            key.Serialize(ds);
151
0
            iv.Serialize(ds);
152
0
            ds.Put<>(type);
153
0
            ds.Put<>(outSize);
154
0
        }
155
};
156
157
class SymmetricEncrypt : public Operation {
158
    public:
159
        const component::Cleartext cleartext;
160
        const component::SymmetricCipher cipher;
161
        const std::optional<component::AAD> aad;
162
163
        const uint64_t ciphertextSize;
164
        const std::optional<uint64_t> tagSize;
165
166
        SymmetricEncrypt(Datasource& ds, component::Modifier modifier) :
167
            Operation(std::move(modifier)),
168
            cleartext(ds),
169
            cipher(ds),
170
            aad(ds.Get<bool>() ? std::nullopt : std::make_optional<component::AAD>(ds)),
171
            ciphertextSize(ds.Get<uint64_t>() % (10*1024*1024)),
172
            tagSize( ds.Get<bool>() ?
173
                    std::nullopt :
174
                    std::make_optional<uint64_t>(ds.Get<uint64_t>() % (10*1024*1024)) )
175
894
        { }
176
        SymmetricEncrypt(nlohmann::json json) :
177
            Operation(json["modifier"]),
178
            cleartext(json["cleartext"]),
179
            cipher(json["cipher"]),
180
            aad(
181
                    json["aad_enabled"].get<bool>() ?
182
                        std::optional<component::AAD>(json["aad"]) :
183
                        std::optional<component::AAD>(std::nullopt)
184
            ),
185
            ciphertextSize(json["ciphertextSize"].get<uint64_t>()),
186
            tagSize(
187
                    json["tagSize_enabled"].get<bool>() ?
188
                        std::optional<uint64_t>(json["tagSize"].get<uint64_t>()) :
189
                        std::optional<uint64_t>(std::nullopt)
190
            )
191
0
        { }
192
193
876
        static size_t MaxOperations(void) { return 20; }
194
        std::string Name(void) const override;
195
        std::string ToString(void) const override;
196
        nlohmann::json ToJSON(void) const override;
197
0
        std::string GetAlgorithmString(void) const override {
198
0
            return repository::CipherToString(cipher.cipherType.Get());
199
0
        }
200
0
        inline bool operator==(const SymmetricEncrypt& rhs) const {
201
0
            return
202
0
                (cleartext == rhs.cleartext) &&
203
0
                (cipher == rhs.cipher) &&
204
0
                (aad == rhs.aad) &&
205
0
                (ciphertextSize == rhs.ciphertextSize) &&
206
0
                (tagSize == rhs.tagSize) &&
207
0
                (modifier == rhs.modifier);
208
0
        }
209
0
        void Serialize(Datasource& ds) const {
210
0
            cleartext.Serialize(ds);
211
0
            cipher.Serialize(ds);
212
0
            if ( aad == std::nullopt ) {
213
0
                ds.Put<bool>(true);
214
0
            } else {
215
0
                ds.Put<bool>(false);
216
0
                aad->Serialize(ds);
217
0
            }
218
0
            ds.Put<>(ciphertextSize);
219
0
            if ( tagSize == std::nullopt ) {
220
0
                ds.Put<bool>(true);
221
0
            } else {
222
0
                ds.Put<bool>(false);
223
0
                ds.Put<>(*tagSize);
224
0
            }
225
0
        }
226
};
227
228
class SymmetricDecrypt : public Operation {
229
    public:
230
        const Buffer ciphertext;
231
        const component::SymmetricCipher cipher;
232
        const std::optional<component::Tag> tag;
233
        const std::optional<component::AAD> aad;
234
235
        const uint64_t cleartextSize;
236
237
        SymmetricDecrypt(Datasource& ds, component::Modifier modifier) :
238
            Operation(std::move(modifier)),
239
            ciphertext(ds),
240
            cipher(ds),
241
            tag(ds.Get<bool>() ? std::nullopt : std::make_optional<component::Tag>(ds)),
242
            aad(ds.Get<bool>() ? std::nullopt : std::make_optional<component::AAD>(ds)),
243
            cleartextSize(ds.Get<uint64_t>() % (10*1024*1024))
244
932
        { }
245
        SymmetricDecrypt(const SymmetricEncrypt& opSymmetricEncrypt, const component::Ciphertext ciphertext, const uint64_t cleartextSize, std::optional<component::AAD> aad, component::Modifier modifier);
246
        SymmetricDecrypt(nlohmann::json json) :
247
            Operation(json["modifier"]),
248
            ciphertext(json["ciphertext"]),
249
            cipher(json["cipher"]),
250
            tag(
251
                    json["tag_enabled"].get<bool>() ?
252
                        std::optional<component::Tag>(json["tag"]) :
253
                        std::optional<component::Tag>(std::nullopt)
254
            ),
255
            aad(
256
                    json["aad_enabled"].get<bool>() ?
257
                        std::optional<component::AAD>(json["aad"]) :
258
                        std::optional<component::AAD>(std::nullopt)
259
            ),
260
            cleartextSize(json["cleartextSize"].get<uint64_t>())
261
0
        { }
262
263
915
        static size_t MaxOperations(void) { return 20; }
264
        std::string Name(void) const override;
265
        std::string ToString(void) const override;
266
        nlohmann::json ToJSON(void) const override;
267
0
        std::string GetAlgorithmString(void) const override {
268
0
            return repository::CipherToString(cipher.cipherType.Get());
269
0
        }
270
0
        inline bool operator==(const SymmetricDecrypt& rhs) const {
271
0
            return
272
0
                (ciphertext == rhs.ciphertext) &&
273
0
                (cipher == rhs.cipher) &&
274
0
                (tag == rhs.tag) &&
275
0
                (aad == rhs.aad) &&
276
0
                (cleartextSize == rhs.cleartextSize) &&
277
0
                (modifier == rhs.modifier);
278
0
        }
279
0
        void Serialize(Datasource& ds) const {
280
0
            ciphertext.Serialize(ds);
281
0
            cipher.Serialize(ds);
282
0
            if ( tag == std::nullopt ) {
283
0
                ds.Put<bool>(true);
284
0
            } else {
285
0
                ds.Put<bool>(false);
286
0
                tag->Serialize(ds);
287
0
            }
288
0
            if ( aad == std::nullopt ) {
289
0
                ds.Put<bool>(true);
290
0
            } else {
291
0
                ds.Put<bool>(false);
292
0
                aad->Serialize(ds);
293
0
            }
294
0
            ds.Put<>(cleartextSize);
295
0
        }
296
};
297
298
class KDF_SCRYPT : public Operation {
299
    public:
300
        const component::Cleartext password;
301
        const component::Cleartext salt;
302
        const uint64_t N;
303
        const uint64_t r;
304
        const uint64_t p;
305
306
        const uint64_t keySize;
307
308
        KDF_SCRYPT(Datasource& ds, component::Modifier modifier) :
309
            Operation(std::move(modifier)),
310
            password(ds),
311
            salt(ds),
312
            N(ds.Get<uint64_t>() % 5),
313
            r(ds.Get<uint64_t>() % 9),
314
            p(ds.Get<uint64_t>() % 5),
315
            keySize(ds.Get<uint64_t>() % 1024)
316
249
        { }
317
        KDF_SCRYPT(nlohmann::json json) :
318
            Operation(json["modifier"]),
319
            password(json["password"]),
320
            salt(json["salt"]),
321
            N(json["N"].get<uint64_t>()),
322
            r(json["r"].get<uint64_t>()),
323
            p(json["p"].get<uint64_t>()),
324
            keySize(json["keySize"].get<uint64_t>())
325
0
        { }
326
327
235
        static size_t MaxOperations(void) { return 20; }
328
        std::string Name(void) const override;
329
        std::string ToString(void) const override;
330
        nlohmann::json ToJSON(void) const override;
331
0
        inline bool operator==(const KDF_SCRYPT& rhs) const {
332
0
            return
333
0
                (password == rhs.password) &&
334
0
                (salt == rhs.salt) &&
335
0
                (N == rhs.N) &&
336
0
                (r == rhs.r) &&
337
0
                (p == rhs.p) &&
338
0
                (keySize == rhs.keySize) &&
339
0
                (modifier == rhs.modifier);
340
0
        }
341
0
        void Serialize(Datasource& ds) const {
342
0
            password.Serialize(ds);
343
0
            salt.Serialize(ds);
344
0
            ds.Put<>(N);
345
0
            ds.Put<>(r);
346
0
            ds.Put<>(p);
347
0
            ds.Put<>(keySize);
348
0
        }
349
};
350
351
class KDF_HKDF : public Operation {
352
    public:
353
        const component::DigestType digestType;
354
        const component::Cleartext password;
355
        const component::Cleartext salt;
356
        const component::Cleartext info;
357
358
        const uint64_t keySize;
359
360
        KDF_HKDF(Datasource& ds, component::Modifier modifier) :
361
            Operation(std::move(modifier)),
362
            digestType(ds),
363
            password(ds),
364
            salt(ds),
365
            info(ds),
366
            keySize(ds.Get<uint64_t>() % 17000)
367
319
        { }
368
        KDF_HKDF(nlohmann::json json) :
369
            Operation(json["modifier"]),
370
            digestType(json["digestType"]),
371
            password(json["password"]),
372
            salt(json["salt"]),
373
            info(json["info"]),
374
            keySize(json["keySize"].get<uint64_t>())
375
0
        { }
376
377
301
        static size_t MaxOperations(void) { return 20; }
378
        std::string Name(void) const override;
379
        std::string ToString(void) const override;
380
        nlohmann::json ToJSON(void) const override;
381
0
        inline bool operator==(const KDF_HKDF& rhs) const {
382
0
            return
383
0
                (digestType == rhs.digestType) &&
384
0
                (password == rhs.password) &&
385
0
                (salt == rhs.salt) &&
386
0
                (info == rhs.info) &&
387
0
                (keySize == rhs.keySize) &&
388
0
                (modifier == rhs.modifier);
389
0
        }
390
0
        void Serialize(Datasource& ds) const {
391
0
            digestType.Serialize(ds);
392
0
            password.Serialize(ds);
393
0
            salt.Serialize(ds);
394
0
            info.Serialize(ds);
395
0
            ds.Put<>(keySize);
396
0
        }
397
};
398
399
class KDF_TLS1_PRF : public Operation {
400
    public:
401
        const component::DigestType digestType;
402
        const component::Cleartext secret;
403
        const component::Cleartext seed;
404
405
        const uint64_t keySize;
406
407
        KDF_TLS1_PRF(Datasource& ds, component::Modifier modifier) :
408
            Operation(std::move(modifier)),
409
            digestType(ds),
410
            secret(ds),
411
            seed(ds),
412
            keySize(ds.Get<uint64_t>() % 1024)
413
284
        { }
414
        KDF_TLS1_PRF(nlohmann::json json) :
415
            Operation(json["modifier"]),
416
            digestType(json["digestType"]),
417
            secret(json["secret"]),
418
            seed(json["seed"]),
419
            keySize(json["keySize"].get<uint64_t>())
420
0
        { }
421
422
267
        static size_t MaxOperations(void) { return 20; }
423
        std::string Name(void) const override;
424
        std::string ToString(void) const override;
425
        nlohmann::json ToJSON(void) const override;
426
0
        inline bool operator==(const KDF_TLS1_PRF& rhs) const {
427
0
            return
428
0
                (digestType == rhs.digestType) &&
429
0
                (secret == rhs.secret) &&
430
0
                (seed == rhs.seed) &&
431
0
                (modifier == rhs.modifier);
432
0
        }
433
0
        void Serialize(Datasource& ds) const {
434
0
            digestType.Serialize(ds);
435
0
            secret.Serialize(ds);
436
0
            seed.Serialize(ds);
437
0
            ds.Put<>(keySize);
438
0
        }
439
};
440
441
class KDF_PBKDF : public Operation {
442
    public:
443
        const component::DigestType digestType;
444
        const component::Cleartext password;
445
        const component::Cleartext salt;
446
        const uint64_t iterations;
447
448
        const uint64_t keySize;
449
450
        KDF_PBKDF(Datasource& ds, component::Modifier modifier) :
451
            Operation(std::move(modifier)),
452
            digestType(ds),
453
            password(ds),
454
            salt(ds),
455
            iterations(ds.Get<uint64_t>() % 5),
456
            keySize(ds.Get<uint64_t>() % 1024)
457
297
        { }
458
        KDF_PBKDF(nlohmann::json json) :
459
            Operation(json["modifier"]),
460
            digestType(json["digestType"]),
461
            password(json["password"]),
462
            salt(json["salt"]),
463
            iterations(json["iterations"].get<uint64_t>()),
464
            keySize(json["keySize"].get<uint64_t>())
465
0
        { }
466
467
285
        static size_t MaxOperations(void) { return 20; }
468
        std::string Name(void) const override;
469
        std::string ToString(void) const override;
470
        nlohmann::json ToJSON(void) const override;
471
0
        inline bool operator==(const KDF_PBKDF& rhs) const {
472
0
            return
473
0
                (digestType == rhs.digestType) &&
474
0
                (password == rhs.password) &&
475
0
                (salt == rhs.salt) &&
476
0
                (iterations == rhs.iterations) &&
477
0
                (keySize == rhs.keySize) &&
478
0
                (modifier == rhs.modifier);
479
0
        }
480
0
        void Serialize(Datasource& ds) const {
481
0
            digestType.Serialize(ds);
482
0
            password.Serialize(ds);
483
0
            salt.Serialize(ds);
484
0
            ds.Put<>(iterations);
485
0
            ds.Put<>(keySize);
486
0
        }
487
};
488
489
class KDF_PBKDF1 : public Operation {
490
    public:
491
        const component::DigestType digestType;
492
        const component::Cleartext password;
493
        const component::Cleartext salt;
494
        const uint64_t iterations;
495
496
        const uint64_t keySize;
497
498
        KDF_PBKDF1(Datasource& ds, component::Modifier modifier) :
499
            Operation(std::move(modifier)),
500
            digestType(ds),
501
            password(ds),
502
            salt(ds),
503
            iterations(ds.Get<uint64_t>() % 5),
504
            keySize(ds.Get<uint64_t>() % 1024)
505
313
        { }
506
        KDF_PBKDF1(nlohmann::json json) :
507
            Operation(json["modifier"]),
508
            digestType(json["digestType"]),
509
            password(json["password"]),
510
            salt(json["salt"]),
511
            iterations(json["iterations"].get<uint64_t>()),
512
            keySize(json["keySize"].get<uint64_t>())
513
0
        { }
514
515
299
        static size_t MaxOperations(void) { return 20; }
516
        std::string Name(void) const override;
517
        std::string ToString(void) const override;
518
        nlohmann::json ToJSON(void) const override;
519
0
        inline bool operator==(const KDF_PBKDF1& rhs) const {
520
0
            return
521
0
                (digestType == rhs.digestType) &&
522
0
                (password == rhs.password) &&
523
0
                (salt == rhs.salt) &&
524
0
                (iterations == rhs.iterations) &&
525
0
                (keySize == rhs.keySize) &&
526
0
                (modifier == rhs.modifier);
527
0
        }
528
0
        void Serialize(Datasource& ds) const {
529
0
            digestType.Serialize(ds);
530
0
            password.Serialize(ds);
531
0
            salt.Serialize(ds);
532
0
            ds.Put<>(iterations);
533
0
            ds.Put<>(keySize);
534
0
        }
535
};
536
537
class KDF_PBKDF2 : public Operation {
538
    public:
539
        const component::DigestType digestType;
540
        const component::Cleartext password;
541
        const component::Cleartext salt;
542
        const uint64_t iterations;
543
544
        const uint64_t keySize;
545
546
        KDF_PBKDF2(Datasource& ds, component::Modifier modifier) :
547
            Operation(std::move(modifier)),
548
            digestType(ds),
549
            password(ds),
550
            salt(ds),
551
            iterations(ds.Get<uint64_t>() % 5),
552
            keySize(ds.Get<uint64_t>() % 1024)
553
190
        { }
554
        KDF_PBKDF2(nlohmann::json json) :
555
            Operation(json["modifier"]),
556
            digestType(json["digestType"]),
557
            password(json["password"]),
558
            salt(json["salt"]),
559
            iterations(json["iterations"].get<uint64_t>()),
560
            keySize(json["keySize"].get<uint64_t>())
561
0
        { }
562
563
179
        static size_t MaxOperations(void) { return 20; }
564
        std::string Name(void) const override;
565
        std::string ToString(void) const override;
566
        nlohmann::json ToJSON(void) const override;
567
0
        inline bool operator==(const KDF_PBKDF2& rhs) const {
568
0
            return
569
0
                (digestType == rhs.digestType) &&
570
0
                (password == rhs.password) &&
571
0
                (salt == rhs.salt) &&
572
0
                (iterations == rhs.iterations) &&
573
0
                (keySize == rhs.keySize) &&
574
0
                (modifier == rhs.modifier);
575
0
        }
576
0
        void Serialize(Datasource& ds) const {
577
0
            digestType.Serialize(ds);
578
0
            password.Serialize(ds);
579
0
            salt.Serialize(ds);
580
0
            ds.Put<>(iterations);
581
0
            ds.Put<>(keySize);
582
0
        }
583
};
584
585
class KDF_ARGON2 : public Operation {
586
    public:
587
        const component::Cleartext password;
588
        const component::Cleartext salt;
589
        const uint8_t type;
590
        const uint8_t threads;
591
        const uint32_t memory;
592
        const uint32_t iterations;
593
        const uint32_t keySize;
594
595
        KDF_ARGON2(Datasource& ds, component::Modifier modifier) :
596
            Operation(std::move(modifier)),
597
            password(ds),
598
            salt(ds),
599
            type(ds.Get<uint8_t>()),
600
            threads(ds.Get<uint8_t>()),
601
            memory(ds.Get<uint32_t>() % (64*1024)),
602
            iterations(ds.Get<uint32_t>() % 3),
603
            keySize(ds.Get<uint32_t>() % 1024)
604
60
        { }
605
        KDF_ARGON2(nlohmann::json json) :
606
            Operation(json["modifier"]),
607
            password(json["password"]),
608
            salt(json["salt"]),
609
            type(json["type"].get<uint8_t>()),
610
            threads(json["threads"].get<uint8_t>()),
611
            memory(json["memory"].get<uint32_t>()),
612
            iterations(json["iterations"].get<uint32_t>()),
613
            keySize(json["keySize"].get<uint32_t>())
614
0
        { }
615
616
50
        static size_t MaxOperations(void) { return 3; }
617
        std::string Name(void) const override;
618
        std::string ToString(void) const override;
619
        nlohmann::json ToJSON(void) const override;
620
0
        inline bool operator==(const KDF_ARGON2& rhs) const {
621
0
            return
622
0
                (password == rhs.password) &&
623
0
                (salt == rhs.salt) &&
624
0
                (type == rhs.type) &&
625
0
                (threads == rhs.threads) &&
626
0
                (memory == rhs.memory) &&
627
0
                (iterations == rhs.iterations) &&
628
0
                (keySize == rhs.keySize) &&
629
0
                (modifier == rhs.modifier);
630
0
        }
631
0
        void Serialize(Datasource& ds) const {
632
0
            password.Serialize(ds);
633
0
            salt.Serialize(ds);
634
0
            ds.Put<>(type);
635
0
            ds.Put<>(threads);
636
0
            ds.Put<>(memory);
637
0
            ds.Put<>(iterations);
638
0
            ds.Put<>(keySize);
639
0
        }
640
};
641
642
class KDF_SSH : public Operation {
643
    public:
644
        const component::DigestType digestType;
645
        const component::Cleartext key;
646
        const component::Cleartext xcghash;
647
        const component::Cleartext session_id;
648
        const component::Cleartext type;
649
        const uint64_t keySize;
650
651
        KDF_SSH(Datasource& ds, component::Modifier modifier) :
652
            Operation(std::move(modifier)),
653
            digestType(ds),
654
            key(ds),
655
            xcghash(ds),
656
            session_id(ds),
657
            type(ds),
658
            keySize(ds.Get<uint64_t>() % 1024)
659
225
        { }
660
        KDF_SSH(nlohmann::json json) :
661
            Operation(json["modifier"]),
662
            digestType(json["digestType"]),
663
            key(json["key"]),
664
            xcghash(json["xcghash"]),
665
            session_id(json["session_id"]),
666
            type(json["type"]),
667
            keySize(json["keySize"].get<uint64_t>())
668
0
        { }
669
670
203
        static size_t MaxOperations(void) { return 20; }
671
        std::string Name(void) const override;
672
        std::string ToString(void) const override;
673
        nlohmann::json ToJSON(void) const override;
674
0
        inline bool operator==(const KDF_SSH& rhs) const {
675
0
            return
676
0
                (digestType == rhs.digestType) &&
677
0
                (key == rhs.key) &&
678
0
                (xcghash == rhs.xcghash) &&
679
0
                (session_id == rhs.session_id) &&
680
0
                (type == rhs.type) &&
681
0
                (keySize == rhs.keySize) &&
682
0
                (modifier == rhs.modifier);
683
0
        }
684
0
        void Serialize(Datasource& ds) const {
685
0
            digestType.Serialize(ds);
686
0
            key.Serialize(ds);
687
0
            xcghash.Serialize(ds);
688
0
            session_id.Serialize(ds);
689
0
            type.Serialize(ds);
690
0
            ds.Put<>(keySize);
691
0
        }
692
};
693
694
class KDF_X963 : public Operation {
695
    public:
696
        const component::DigestType digestType;
697
        const component::Cleartext secret;
698
        const component::Cleartext info;
699
        const uint64_t keySize;
700
701
        KDF_X963(Datasource& ds, component::Modifier modifier) :
702
            Operation(std::move(modifier)),
703
            digestType(ds),
704
            secret(ds),
705
            info(ds),
706
            keySize(ds.Get<uint64_t>() % 1024)
707
349
        { }
708
        KDF_X963(nlohmann::json json) :
709
            Operation(json["modifier"]),
710
            digestType(json["digestType"]),
711
            secret(json["secret"]),
712
            info(json["info"]),
713
            keySize(json["keySize"].get<uint64_t>())
714
0
        { }
715
716
333
        static size_t MaxOperations(void) { return 20; }
717
        std::string Name(void) const override;
718
        std::string ToString(void) const override;
719
        nlohmann::json ToJSON(void) const override;
720
0
        inline bool operator==(const KDF_X963& rhs) const {
721
0
            return
722
0
                (digestType == rhs.digestType) &&
723
0
                (secret == rhs.secret) &&
724
0
                (info == rhs.info) &&
725
0
                (keySize == rhs.keySize) &&
726
0
                (modifier == rhs.modifier);
727
0
        }
728
0
        void Serialize(Datasource& ds) const {
729
0
            digestType.Serialize(ds);
730
0
            secret.Serialize(ds);
731
0
            info.Serialize(ds);
732
0
            ds.Put<>(keySize);
733
0
        }
734
};
735
736
class KDF_BCRYPT : public Operation {
737
    public:
738
        const component::DigestType digestType;
739
        const component::Cleartext secret;
740
        const component::Cleartext salt;
741
        const uint32_t iterations;
742
        const uint64_t keySize;
743
744
        KDF_BCRYPT(Datasource& ds, component::Modifier modifier) :
745
            Operation(std::move(modifier)),
746
            digestType(ds),
747
            secret(ds),
748
            salt(ds),
749
            iterations(ds.Get<uint32_t>() % 3),
750
            keySize(ds.Get<uint64_t>() % 1024)
751
19
        { }
752
        KDF_BCRYPT(nlohmann::json json) :
753
            Operation(json["modifier"]),
754
            digestType(json["digestType"]),
755
            secret(json["secret"]),
756
            salt(json["salt"]),
757
            iterations(json["iterations"].get<uint32_t>()),
758
            keySize(json["keySize"].get<uint64_t>())
759
0
        { }
760
761
12
        static size_t MaxOperations(void) { return 2; }
762
        std::string Name(void) const override;
763
        std::string ToString(void) const override;
764
        nlohmann::json ToJSON(void) const override;
765
0
        inline bool operator==(const KDF_BCRYPT& rhs) const {
766
0
            return
767
0
                (digestType == rhs.digestType) &&
768
0
                (secret == rhs.secret) &&
769
0
                (salt == rhs.salt) &&
770
0
                (iterations == rhs.iterations) &&
771
0
                (keySize == rhs.keySize) &&
772
0
                (modifier == rhs.modifier);
773
0
        }
774
};
775
776
class KDF_SP_800_108 : public Operation {
777
    public:
778
        const component::MACType mech;
779
        const component::Cleartext secret;
780
        const component::Cleartext salt;
781
        const component::Cleartext label;
782
        const uint8_t mode;
783
        const uint64_t keySize;
784
785
        KDF_SP_800_108(Datasource& ds, component::Modifier modifier) :
786
            Operation(std::move(modifier)),
787
            mech(ds),
788
            secret(ds),
789
            salt(ds),
790
            label(ds),
791
            mode(ds.Get<uint8_t>()),
792
            keySize(ds.Get<uint64_t>() % 17000)
793
304
        { }
794
        KDF_SP_800_108(nlohmann::json json) :
795
            Operation(json["modifier"]),
796
            mech(json["mech"]),
797
            secret(json["secret"]),
798
            salt(json["salt"]),
799
            label(json["label"]),
800
            mode(json["mode"].get<uint8_t>()),
801
            keySize(json["keySize"].get<uint64_t>())
802
0
        { }
803
804
288
        static size_t MaxOperations(void) { return 20; }
805
        std::string Name(void) const override;
806
        std::string ToString(void) const override;
807
        nlohmann::json ToJSON(void) const override;
808
0
        inline bool operator==(const KDF_SP_800_108& rhs) const {
809
0
            return
810
0
                (mech == rhs.mech) &&
811
0
                (secret == rhs.secret) &&
812
0
                (salt == rhs.salt) &&
813
0
                (label == rhs.label) &&
814
0
                (mode == rhs.mode) &&
815
0
                (keySize == rhs.keySize) &&
816
0
                (modifier == rhs.modifier);
817
0
        }
818
0
        void Serialize(Datasource& ds) const {
819
0
            mech.Serialize(ds);
820
0
            secret.Serialize(ds);
821
0
            salt.Serialize(ds);
822
0
            label.Serialize(ds);
823
0
            ds.Put<>(mode);
824
0
            ds.Put<>(keySize);
825
0
        }
826
};
827
828
class CMAC : public Operation {
829
    public:
830
        const component::Cleartext cleartext;
831
        const component::SymmetricCipher cipher;
832
833
        CMAC(Datasource& ds, component::Modifier modifier) :
834
            Operation(std::move(modifier)),
835
            cleartext(ds),
836
            cipher(ds)
837
153
        { }
838
        CMAC(nlohmann::json json) :
839
            Operation(json["modifier"]),
840
            cleartext(json["cleartext"]),
841
            cipher(json["cipher"])
842
0
        { }
843
844
142
        static size_t MaxOperations(void) { return 20; }
845
        std::string Name(void) const override;
846
        std::string ToString(void) const override;
847
        nlohmann::json ToJSON(void) const override;
848
0
        inline bool operator==(const CMAC& rhs) const {
849
0
            return
850
0
                (cleartext == rhs.cleartext) &&
851
0
                (cipher == rhs.cipher) &&
852
0
                (modifier == rhs.modifier);
853
0
        }
854
0
        void Serialize(Datasource& ds) const {
855
0
            cleartext.Serialize(ds);
856
0
            cipher.Serialize(ds);
857
0
        }
858
};
859
860
class ECC_PrivateToPublic : public Operation {
861
    public:
862
        const component::CurveType curveType;
863
        const component::ECC_PrivateKey priv;
864
865
        ECC_PrivateToPublic(Datasource& ds, component::Modifier modifier) :
866
            Operation(std::move(modifier)),
867
            curveType(ds),
868
            priv(ds)
869
7.84k
        { }
870
        ECC_PrivateToPublic(nlohmann::json json) :
871
            Operation(json["modifier"]),
872
            curveType(json["curveType"]),
873
            priv(json["priv"])
874
0
        { }
875
876
7.71k
        static size_t MaxOperations(void) { return 5; }
877
        std::string Name(void) const override;
878
        std::string ToString(void) const override;
879
        nlohmann::json ToJSON(void) const override;
880
0
        inline bool operator==(const ECC_PrivateToPublic& rhs) const {
881
0
            return
882
0
                (curveType == rhs.curveType) &&
883
0
                (priv == rhs.priv) &&
884
0
                (modifier == rhs.modifier);
885
0
        }
886
0
        void Serialize(Datasource& ds) const {
887
0
            curveType.Serialize(ds);
888
0
            priv.Serialize(ds);
889
0
        }
890
};
891
892
class ECC_ValidatePubkey : public Operation {
893
    public:
894
        const component::CurveType curveType;
895
        const component::ECC_PublicKey pub;
896
897
        ECC_ValidatePubkey(Datasource& ds, component::Modifier modifier) :
898
            Operation(std::move(modifier)),
899
            curveType(ds),
900
            pub(ds)
901
8.49k
        { }
902
        ECC_ValidatePubkey(nlohmann::json json) :
903
            Operation(json["modifier"]),
904
            curveType(json["curveType"]),
905
            pub(json["pub_x"], json["pub_y"])
906
0
        { }
907
908
8.18k
        static size_t MaxOperations(void) { return 5; }
909
        std::string Name(void) const override;
910
        std::string ToString(void) const override;
911
        nlohmann::json ToJSON(void) const override;
912
0
        inline bool operator==(const ECC_ValidatePubkey& rhs) const {
913
0
            return
914
0
                (curveType == rhs.curveType) &&
915
0
                (pub == rhs.pub) &&
916
0
                (modifier == rhs.modifier);
917
0
        }
918
0
        void Serialize(Datasource& ds) const {
919
0
            curveType.Serialize(ds);
920
0
            pub.Serialize(ds);
921
0
        }
922
};
923
924
class ECC_GenerateKeyPair : public Operation {
925
    public:
926
        const component::CurveType curveType;
927
928
        ECC_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
929
            Operation(std::move(modifier)),
930
            curveType(ds)
931
9.04k
        { }
932
933
        ECC_GenerateKeyPair(nlohmann::json json) :
934
            Operation(json["modifier"]),
935
            curveType(json["curveType"])
936
0
        { }
937
938
8.94k
        static size_t MaxOperations(void) { return 5; }
939
        std::string Name(void) const override;
940
        std::string ToString(void) const override;
941
        nlohmann::json ToJSON(void) const override;
942
0
        inline bool operator==(const ECC_GenerateKeyPair& rhs) const {
943
0
            return
944
0
                (curveType == rhs.curveType) &&
945
0
                (modifier == rhs.modifier);
946
0
        }
947
0
        void Serialize(Datasource& ds) const {
948
0
            curveType.Serialize(ds);
949
0
        }
950
};
951
952
class ECDSA_Sign : public Operation {
953
    public:
954
        const component::CurveType curveType;
955
        const component::ECC_PrivateKey priv;
956
        const component::Bignum nonce;
957
        const component::Cleartext cleartext;
958
        const uint8_t nonceSource;
959
        const component::DigestType digestType;
960
961
        ECDSA_Sign(Datasource& ds, component::Modifier modifier) :
962
            Operation(std::move(modifier)),
963
            curveType(ds),
964
            priv(ds),
965
            nonce(ds),
966
            cleartext(ds),
967
            nonceSource(ds.Get<uint8_t>()),
968
            digestType(ds)
969
11.6k
        { }
970
        ECDSA_Sign(nlohmann::json json) :
971
            Operation(json["modifier"]),
972
            curveType(json["curveType"]),
973
            priv(json["priv"]),
974
            nonce(json["nonce"]),
975
            cleartext(json["cleartext"]),
976
            nonceSource(json["nonceSource"].get<uint8_t>()),
977
            digestType(json["digestType"])
978
0
        { }
979
980
11.4k
        static size_t MaxOperations(void) { return 5; }
981
        std::string Name(void) const override;
982
        std::string ToString(void) const override;
983
        nlohmann::json ToJSON(void) const override;
984
0
        inline bool operator==(const ECDSA_Sign& rhs) const {
985
0
            return
986
0
                (curveType == rhs.curveType) &&
987
0
                (priv == rhs.priv) &&
988
0
                (nonce == rhs.nonce) &&
989
0
                (cleartext == rhs.cleartext) &&
990
0
                (nonceSource == rhs.nonceSource ) &&
991
0
                (digestType == rhs.digestType ) &&
992
0
                (modifier == rhs.modifier);
993
0
        }
994
0
        void Serialize(Datasource& ds) const {
995
0
            curveType.Serialize(ds);
996
0
            priv.Serialize(ds);
997
0
            nonce.Serialize(ds);
998
0
            cleartext.Serialize(ds);
999
0
            ds.Put<>(nonceSource);
1000
0
            digestType.Serialize(ds);
1001
0
        }
1002
6.77k
        bool UseRandomNonce(void) const {
1003
6.77k
            return nonceSource == 0;
1004
6.77k
        }
1005
4.50k
        bool UseRFC6979Nonce(void) const {
1006
4.50k
            return nonceSource == 1;
1007
4.50k
        }
1008
15.9k
        bool UseSpecifiedNonce(void) const {
1009
15.9k
            return nonceSource == 2;
1010
15.9k
        }
1011
};
1012
1013
class ECGDSA_Sign : public Operation {
1014
    public:
1015
        const component::CurveType curveType;
1016
        const component::ECC_PrivateKey priv;
1017
        const component::Bignum nonce;
1018
        const component::Cleartext cleartext;
1019
        const uint8_t nonceSource;
1020
        const component::DigestType digestType;
1021
1022
        ECGDSA_Sign(Datasource& ds, component::Modifier modifier) :
1023
            Operation(std::move(modifier)),
1024
            curveType(ds),
1025
            priv(ds),
1026
            nonce(ds),
1027
            cleartext(ds),
1028
            nonceSource(ds.Get<uint8_t>()),
1029
            digestType(ds)
1030
63
        { }
1031
        ECGDSA_Sign(nlohmann::json json) :
1032
            Operation(json["modifier"]),
1033
            curveType(json["curveType"]),
1034
            priv(json["priv"]),
1035
            nonce(json["nonce"]),
1036
            cleartext(json["cleartext"]),
1037
            nonceSource(json["nonceSource"].get<uint8_t>()),
1038
            digestType(json["digestType"])
1039
0
        { }
1040
1041
53
        static size_t MaxOperations(void) { return 5; }
1042
        std::string Name(void) const override;
1043
        std::string ToString(void) const override;
1044
        nlohmann::json ToJSON(void) const override;
1045
0
        inline bool operator==(const ECGDSA_Sign& rhs) const {
1046
0
            return
1047
0
                (curveType == rhs.curveType) &&
1048
0
                (priv == rhs.priv) &&
1049
0
                (nonce == rhs.nonce) &&
1050
0
                (cleartext == rhs.cleartext) &&
1051
0
                (nonceSource == rhs.nonceSource ) &&
1052
0
                (digestType == rhs.digestType ) &&
1053
0
                (modifier == rhs.modifier);
1054
0
        }
1055
0
        void Serialize(Datasource& ds) const {
1056
0
            curveType.Serialize(ds);
1057
0
            priv.Serialize(ds);
1058
0
            nonce.Serialize(ds);
1059
0
            cleartext.Serialize(ds);
1060
0
            ds.Put<>(nonceSource);
1061
0
            digestType.Serialize(ds);
1062
0
        }
1063
0
        bool UseRandomNonce(void) const {
1064
0
            return nonceSource == 0;
1065
0
        }
1066
0
        bool UseRFC6979Nonce(void) const {
1067
0
            return nonceSource == 1;
1068
0
        }
1069
0
        bool UseSpecifiedNonce(void) const {
1070
0
            return nonceSource == 2;
1071
0
        }
1072
};
1073
1074
class ECRDSA_Sign : public Operation {
1075
    public:
1076
        const component::CurveType curveType;
1077
        const component::ECC_PrivateKey priv;
1078
        const component::Bignum nonce;
1079
        const component::Cleartext cleartext;
1080
        const uint8_t nonceSource;
1081
        const component::DigestType digestType;
1082
1083
        ECRDSA_Sign(Datasource& ds, component::Modifier modifier) :
1084
            Operation(std::move(modifier)),
1085
            curveType(ds),
1086
            priv(ds),
1087
            nonce(ds),
1088
            cleartext(ds),
1089
            nonceSource(ds.Get<uint8_t>()),
1090
            digestType(ds)
1091
90
        { }
1092
        ECRDSA_Sign(nlohmann::json json) :
1093
            Operation(json["modifier"]),
1094
            curveType(json["curveType"]),
1095
            priv(json["priv"]),
1096
            nonce(json["nonce"]),
1097
            cleartext(json["cleartext"]),
1098
            nonceSource(json["nonceSource"].get<uint8_t>()),
1099
            digestType(json["digestType"])
1100
0
        { }
1101
1102
79
        static size_t MaxOperations(void) { return 5; }
1103
        std::string Name(void) const override;
1104
        std::string ToString(void) const override;
1105
        nlohmann::json ToJSON(void) const override;
1106
0
        inline bool operator==(const ECRDSA_Sign& rhs) const {
1107
0
            return
1108
0
                (curveType == rhs.curveType) &&
1109
0
                (priv == rhs.priv) &&
1110
0
                (nonce == rhs.nonce) &&
1111
0
                (cleartext == rhs.cleartext) &&
1112
0
                (nonceSource == rhs.nonceSource ) &&
1113
0
                (digestType == rhs.digestType ) &&
1114
0
                (modifier == rhs.modifier);
1115
0
        }
1116
0
        void Serialize(Datasource& ds) const {
1117
0
            curveType.Serialize(ds);
1118
0
            priv.Serialize(ds);
1119
0
            nonce.Serialize(ds);
1120
0
            cleartext.Serialize(ds);
1121
0
            ds.Put<>(nonceSource);
1122
0
            digestType.Serialize(ds);
1123
0
        }
1124
0
        bool UseRandomNonce(void) const {
1125
0
            return nonceSource == 0;
1126
0
        }
1127
0
        bool UseRFC6979Nonce(void) const {
1128
0
            return nonceSource == 1;
1129
0
        }
1130
0
        bool UseSpecifiedNonce(void) const {
1131
0
            return nonceSource == 2;
1132
0
        }
1133
};
1134
1135
class Schnorr_Sign : public Operation {
1136
    public:
1137
        const component::CurveType curveType;
1138
        const component::ECC_PrivateKey priv;
1139
        const component::Bignum nonce;
1140
        const component::Cleartext cleartext;
1141
        const uint8_t nonceSource;
1142
        const component::DigestType digestType;
1143
1144
        Schnorr_Sign(Datasource& ds, component::Modifier modifier) :
1145
            Operation(std::move(modifier)),
1146
            curveType(ds),
1147
            priv(ds),
1148
            nonce(ds),
1149
            cleartext(ds),
1150
            nonceSource(ds.Get<uint8_t>()),
1151
            digestType(ds)
1152
80
        { }
1153
        Schnorr_Sign(nlohmann::json json) :
1154
            Operation(json["modifier"]),
1155
            curveType(json["curveType"]),
1156
            priv(json["priv"]),
1157
            nonce(json["nonce"]),
1158
            cleartext(json["cleartext"]),
1159
            nonceSource(json["nonceSource"].get<uint8_t>()),
1160
            digestType(json["digestType"])
1161
0
        { }
1162
1163
71
        static size_t MaxOperations(void) { return 5; }
1164
        std::string Name(void) const override;
1165
        std::string ToString(void) const override;
1166
        nlohmann::json ToJSON(void) const override;
1167
0
        inline bool operator==(const Schnorr_Sign& rhs) const {
1168
0
            return
1169
0
                (curveType == rhs.curveType) &&
1170
0
                (priv == rhs.priv) &&
1171
0
                (nonce == rhs.nonce) &&
1172
0
                (cleartext == rhs.cleartext) &&
1173
0
                (nonceSource == rhs.nonceSource ) &&
1174
0
                (digestType == rhs.digestType ) &&
1175
0
                (modifier == rhs.modifier);
1176
0
        }
1177
0
        void Serialize(Datasource& ds) const {
1178
0
            curveType.Serialize(ds);
1179
0
            priv.Serialize(ds);
1180
0
            nonce.Serialize(ds);
1181
0
            cleartext.Serialize(ds);
1182
0
            ds.Put<>(nonceSource);
1183
0
            digestType.Serialize(ds);
1184
0
        }
1185
0
        bool UseRandomNonce(void) const {
1186
0
            return nonceSource == 0;
1187
0
        }
1188
0
        bool UseBIP340Nonce(void) const {
1189
0
            return nonceSource == 1;
1190
0
        }
1191
0
        bool UseSpecifiedNonce(void) const {
1192
0
            return nonceSource == 2;
1193
0
        }
1194
};
1195
1196
class ECDSA_Verify : public Operation {
1197
    public:
1198
        const component::CurveType curveType;
1199
        const component::Cleartext cleartext;
1200
        const component::ECDSA_Signature signature;
1201
        const component::DigestType digestType;
1202
1203
        ECDSA_Verify(Datasource& ds, component::Modifier modifier) :
1204
            Operation(std::move(modifier)),
1205
            curveType(ds),
1206
            cleartext(ds),
1207
            signature(ds),
1208
            digestType(ds)
1209
7.03k
        { }
1210
        ECDSA_Verify(const ECDSA_Sign& opECDSA_Sign, const component::ECDSA_Signature signature, component::Modifier modifier);
1211
        ECDSA_Verify(nlohmann::json json) :
1212
            Operation(json["modifier"]),
1213
            curveType(json["curveType"]),
1214
            cleartext(json["cleartext"]),
1215
            signature(json["signature"]),
1216
            digestType(json["digestType"])
1217
0
        { }
1218
1219
6.92k
        static size_t MaxOperations(void) { return 5; }
1220
        std::string Name(void) const override;
1221
        std::string ToString(void) const override;
1222
        nlohmann::json ToJSON(void) const override;
1223
0
        inline bool operator==(const ECDSA_Verify& rhs) const {
1224
0
            return
1225
0
                (curveType == rhs.curveType) &&
1226
0
                (cleartext == rhs.cleartext) &&
1227
0
                (signature == rhs.signature) &&
1228
0
                (digestType == rhs.digestType) &&
1229
0
                (modifier == rhs.modifier);
1230
0
        }
1231
0
        void Serialize(Datasource& ds) const {
1232
0
            curveType.Serialize(ds);
1233
0
            cleartext.Serialize(ds);
1234
0
            signature.Serialize(ds);
1235
0
            digestType.Serialize(ds);
1236
0
        }
1237
};
1238
1239
class ECGDSA_Verify : public Operation {
1240
    public:
1241
        const component::CurveType curveType;
1242
        const component::Cleartext cleartext;
1243
        const component::ECGDSA_Signature signature;
1244
        const component::DigestType digestType;
1245
1246
        ECGDSA_Verify(Datasource& ds, component::Modifier modifier) :
1247
            Operation(std::move(modifier)),
1248
            curveType(ds),
1249
            cleartext(ds),
1250
            signature(ds),
1251
            digestType(ds)
1252
76
        { }
1253
        ECGDSA_Verify(nlohmann::json json) :
1254
            Operation(json["modifier"]),
1255
            curveType(json["curveType"]),
1256
            cleartext(json["cleartext"]),
1257
            signature(json["signature"]),
1258
            digestType(json["digestType"])
1259
0
        { }
1260
1261
69
        static size_t MaxOperations(void) { return 5; }
1262
        std::string Name(void) const override;
1263
        std::string ToString(void) const override;
1264
        nlohmann::json ToJSON(void) const override;
1265
0
        inline bool operator==(const ECGDSA_Verify& rhs) const {
1266
0
            return
1267
0
                (curveType == rhs.curveType) &&
1268
0
                (cleartext == rhs.cleartext) &&
1269
0
                (signature == rhs.signature) &&
1270
0
                (digestType == rhs.digestType) &&
1271
0
                (modifier == rhs.modifier);
1272
0
        }
1273
0
        void Serialize(Datasource& ds) const {
1274
0
            curveType.Serialize(ds);
1275
0
            cleartext.Serialize(ds);
1276
0
            signature.Serialize(ds);
1277
0
            digestType.Serialize(ds);
1278
0
        }
1279
};
1280
1281
class ECRDSA_Verify : public Operation {
1282
    public:
1283
        const component::CurveType curveType;
1284
        const component::Cleartext cleartext;
1285
        const component::ECRDSA_Signature signature;
1286
        const component::DigestType digestType;
1287
1288
        ECRDSA_Verify(Datasource& ds, component::Modifier modifier) :
1289
            Operation(std::move(modifier)),
1290
            curveType(ds),
1291
            cleartext(ds),
1292
            signature(ds),
1293
            digestType(ds)
1294
58
        { }
1295
        ECRDSA_Verify(nlohmann::json json) :
1296
            Operation(json["modifier"]),
1297
            curveType(json["curveType"]),
1298
            cleartext(json["cleartext"]),
1299
            signature(json["signature"]),
1300
            digestType(json["digestType"])
1301
0
        { }
1302
1303
51
        static size_t MaxOperations(void) { return 5; }
1304
        std::string Name(void) const override;
1305
        std::string ToString(void) const override;
1306
        nlohmann::json ToJSON(void) const override;
1307
0
        inline bool operator==(const ECRDSA_Verify& rhs) const {
1308
0
            return
1309
0
                (curveType == rhs.curveType) &&
1310
0
                (cleartext == rhs.cleartext) &&
1311
0
                (signature == rhs.signature) &&
1312
0
                (digestType == rhs.digestType) &&
1313
0
                (modifier == rhs.modifier);
1314
0
        }
1315
0
        void Serialize(Datasource& ds) const {
1316
0
            curveType.Serialize(ds);
1317
0
            cleartext.Serialize(ds);
1318
0
            signature.Serialize(ds);
1319
0
            digestType.Serialize(ds);
1320
0
        }
1321
};
1322
1323
class ECDSA_Recover : public Operation {
1324
    public:
1325
        const component::CurveType curveType;
1326
        const component::Cleartext cleartext;
1327
        const component::BignumPair signature;
1328
        const component::DigestType digestType;
1329
        const uint8_t id;
1330
1331
        ECDSA_Recover(Datasource& ds, component::Modifier modifier) :
1332
            Operation(std::move(modifier)),
1333
            curveType(ds),
1334
            cleartext(ds),
1335
            signature(ds),
1336
            digestType(ds),
1337
            id(ds.Get<uint8_t>())
1338
79
        { }
1339
        ECDSA_Recover(nlohmann::json json) :
1340
            Operation(json["modifier"]),
1341
            curveType(json["curveType"]),
1342
            cleartext(json["cleartext"]),
1343
            signature(json["signature"]),
1344
            digestType(json["digestType"]),
1345
            id(json["id"].get<uint8_t>())
1346
0
        { }
1347
1348
69
        static size_t MaxOperations(void) { return 5; }
1349
        std::string Name(void) const override;
1350
        std::string ToString(void) const override;
1351
        nlohmann::json ToJSON(void) const override;
1352
0
        inline bool operator==(const ECDSA_Recover& rhs) const {
1353
0
            return
1354
0
                (curveType == rhs.curveType) &&
1355
0
                (cleartext == rhs.cleartext) &&
1356
0
                (signature == rhs.signature) &&
1357
0
                (digestType == rhs.digestType) &&
1358
0
                (id == rhs.id) &&
1359
0
                (modifier == rhs.modifier);
1360
0
        }
1361
0
        void Serialize(Datasource& ds) const {
1362
0
            curveType.Serialize(ds);
1363
0
            cleartext.Serialize(ds);
1364
0
            signature.Serialize(ds);
1365
0
            digestType.Serialize(ds);
1366
0
            ds.Put<>(id);
1367
0
        }
1368
};
1369
1370
class Schnorr_Verify : public Operation {
1371
    public:
1372
        const component::CurveType curveType;
1373
        const component::Cleartext cleartext;
1374
        const component::ECDSA_Signature signature;
1375
        const component::DigestType digestType;
1376
1377
        Schnorr_Verify(Datasource& ds, component::Modifier modifier) :
1378
            Operation(std::move(modifier)),
1379
            curveType(ds),
1380
            cleartext(ds),
1381
            signature(ds),
1382
            digestType(ds)
1383
59
        { }
1384
        Schnorr_Verify(nlohmann::json json) :
1385
            Operation(json["modifier"]),
1386
            curveType(json["curveType"]),
1387
            cleartext(json["cleartext"]),
1388
            signature(json["signature"]),
1389
            digestType(json["digestType"])
1390
0
        { }
1391
1392
52
        static size_t MaxOperations(void) { return 5; }
1393
        std::string Name(void) const override;
1394
        std::string ToString(void) const override;
1395
        nlohmann::json ToJSON(void) const override;
1396
0
        inline bool operator==(const Schnorr_Verify& rhs) const {
1397
0
            return
1398
0
                (curveType == rhs.curveType) &&
1399
0
                (cleartext == rhs.cleartext) &&
1400
0
                (signature == rhs.signature) &&
1401
0
                (digestType == rhs.digestType) &&
1402
0
                (modifier == rhs.modifier);
1403
0
        }
1404
0
        void Serialize(Datasource& ds) const {
1405
0
            curveType.Serialize(ds);
1406
0
            cleartext.Serialize(ds);
1407
0
            signature.Serialize(ds);
1408
0
            digestType.Serialize(ds);
1409
0
        }
1410
};
1411
1412
class ECDH_Derive : public Operation {
1413
    public:
1414
        const component::CurveType curveType;
1415
        const component::ECC_PrivateKey priv;
1416
        const component::ECC_PublicKey pub;
1417
1418
        ECDH_Derive(Datasource& ds, component::Modifier modifier) :
1419
            Operation(std::move(modifier)),
1420
            curveType(ds),
1421
            priv(ds),
1422
            pub(ds)
1423
1.49k
        { }
1424
        ECDH_Derive(nlohmann::json json) :
1425
            Operation(json["modifier"]),
1426
            curveType(json["curveType"]),
1427
            priv(json["priv"]),
1428
            pub(json["pub_x"], json["pub_y"])
1429
0
        { }
1430
        ECDH_Derive(
1431
                component::Modifier modifier,
1432
                component::CurveType curveType,
1433
                component::ECC_PrivateKey priv,
1434
                component::ECC_PublicKey pub) :
1435
            Operation(std::move(modifier)),
1436
            curveType(curveType),
1437
            priv(priv),
1438
            pub(pub)
1439
0
        { }
1440
1441
1442
1.42k
        static size_t MaxOperations(void) { return 5; }
1443
        std::string Name(void) const override;
1444
        std::string ToString(void) const override;
1445
        nlohmann::json ToJSON(void) const override;
1446
0
        inline bool operator==(const ECDH_Derive& rhs) const {
1447
0
            return
1448
0
                (curveType == rhs.curveType) &&
1449
0
                (priv == rhs.priv) &&
1450
0
                (pub == rhs.pub) &&
1451
0
                (modifier == rhs.modifier);
1452
0
        }
1453
0
        void Serialize(Datasource& ds) const {
1454
0
            curveType.Serialize(ds);
1455
0
            priv.Serialize(ds);
1456
0
            pub.Serialize(ds);
1457
0
        }
1458
};
1459
1460
class ECIES_Encrypt : public Operation {
1461
    public:
1462
        const component::Cleartext cleartext;
1463
        const component::CurveType curveType;
1464
        const component::ECC_PrivateKey priv;
1465
        const component::ECC_PublicKey pub;
1466
        const component::SymmetricCipherType cipherType;
1467
        const std::optional<component::SymmetricIV> iv;
1468
        /* TODO kdf type */
1469
        /* TODO mac type */
1470
1471
        ECIES_Encrypt(Datasource& ds, component::Modifier modifier) :
1472
            Operation(std::move(modifier)),
1473
            cleartext(ds),
1474
            curveType(ds),
1475
            priv(ds),
1476
            pub(ds),
1477
            cipherType(ds),
1478
            iv(ds.Get<bool>() ? std::nullopt : std::make_optional<component::SymmetricIV>(ds))
1479
2.56k
        { }
1480
        ECIES_Encrypt(nlohmann::json json) :
1481
            Operation(json["modifier"]),
1482
            cleartext(json["cleartext"]),
1483
            curveType(json["curveType"]),
1484
            priv(json["priv"]),
1485
            pub(json["pub_x"], json["pub_y"]),
1486
            cipherType(json["cipherType"]),
1487
            iv(
1488
                    json["iv_enabled"].get<bool>() ?
1489
                        std::optional<component::SymmetricIV>(json["iv"]) :
1490
                        std::optional<component::SymmetricIV>(std::nullopt)
1491
            )
1492
0
        { }
1493
1494
2.42k
        static size_t MaxOperations(void) { return 5; }
1495
        std::string Name(void) const override;
1496
        std::string ToString(void) const override;
1497
        nlohmann::json ToJSON(void) const override;
1498
0
        inline bool operator==(const ECIES_Encrypt& rhs) const {
1499
0
            return
1500
0
                (cleartext == rhs.cleartext) &&
1501
0
                (curveType == rhs.curveType) &&
1502
0
                (priv == rhs.priv) &&
1503
0
                (pub == rhs.pub) &&
1504
0
                (cipherType == rhs.cipherType) &&
1505
0
                (iv == rhs.iv) &&
1506
0
                (modifier == rhs.modifier);
1507
0
        }
1508
0
        void Serialize(Datasource& ds) const {
1509
0
            cleartext.Serialize(ds);
1510
0
            curveType.Serialize(ds);
1511
0
            priv.Serialize(ds);
1512
0
            pub.Serialize(ds);
1513
0
            cipherType.Serialize(ds);
1514
0
            if ( iv == std::nullopt ) {
1515
0
                ds.Put<bool>(true);
1516
0
            } else {
1517
0
                ds.Put<bool>(false);
1518
0
                iv->Serialize(ds);
1519
0
            }
1520
0
        }
1521
};
1522
1523
class ECIES_Decrypt : public Operation {
1524
    public:
1525
        const Buffer ciphertext;
1526
        const component::CurveType curveType;
1527
        const component::ECC_PrivateKey priv;
1528
        const component::ECC_PublicKey pub;
1529
        const component::SymmetricCipherType cipherType;
1530
        const std::optional<component::SymmetricIV> iv;
1531
        /* TODO kdf type */
1532
        /* TODO mac type */
1533
1534
        ECIES_Decrypt(Datasource& ds, component::Modifier modifier) :
1535
            Operation(std::move(modifier)),
1536
            ciphertext(ds),
1537
            curveType(ds),
1538
            priv(ds),
1539
            pub(ds),
1540
            cipherType(ds),
1541
            iv(ds.Get<bool>() ? std::nullopt : std::make_optional<component::SymmetricIV>(ds))
1542
2.09k
        { }
1543
        ECIES_Decrypt(nlohmann::json json) :
1544
            Operation(json["modifier"]),
1545
            ciphertext(json["ciphertext"]),
1546
            curveType(json["curveType"]),
1547
            priv(json["priv"]),
1548
            pub(json["pub_x"], json["pub_y"]),
1549
            cipherType(json["cipherType"]),
1550
            iv(
1551
                    json["iv_enabled"].get<bool>() ?
1552
                        std::optional<component::SymmetricIV>(json["iv"]) :
1553
                        std::optional<component::SymmetricIV>(std::nullopt)
1554
            )
1555
0
        { }
1556
1557
1.95k
        static size_t MaxOperations(void) { return 5; }
1558
        std::string Name(void) const override;
1559
        std::string ToString(void) const override;
1560
        nlohmann::json ToJSON(void) const override;
1561
0
        inline bool operator==(const ECIES_Decrypt& rhs) const {
1562
0
            return
1563
0
                (ciphertext == rhs.ciphertext) &&
1564
0
                (curveType == rhs.curveType) &&
1565
0
                (priv == rhs.priv) &&
1566
0
                (pub == rhs.pub) &&
1567
0
                (cipherType == rhs.cipherType) &&
1568
0
                (iv == rhs.iv) &&
1569
0
                (modifier == rhs.modifier);
1570
0
        }
1571
0
        void Serialize(Datasource& ds) const {
1572
0
            ciphertext.Serialize(ds);
1573
0
            curveType.Serialize(ds);
1574
0
            priv.Serialize(ds);
1575
0
            pub.Serialize(ds);
1576
0
            cipherType.Serialize(ds);
1577
0
            if ( iv == std::nullopt ) {
1578
0
                ds.Put<bool>(true);
1579
0
            } else {
1580
0
                ds.Put<bool>(false);
1581
0
                iv->Serialize(ds);
1582
0
            }
1583
0
        }
1584
};
1585
1586
class ECC_Point_Add : public Operation {
1587
    public:
1588
        const component::CurveType curveType;
1589
        const component::ECC_Point a, b;
1590
1591
        ECC_Point_Add(Datasource& ds, component::Modifier modifier) :
1592
            Operation(std::move(modifier)),
1593
            curveType(ds),
1594
            a(ds),
1595
            b(ds)
1596
4.18k
        { }
1597
        ECC_Point_Add(nlohmann::json json) :
1598
            Operation(json["modifier"]),
1599
            curveType(json["curveType"]),
1600
            a(json["a_x"], json["a_y"]),
1601
            b(json["b_x"], json["b_y"])
1602
0
        { }
1603
1604
3.89k
        static size_t MaxOperations(void) { return 5; }
1605
        std::string Name(void) const override;
1606
        std::string ToString(void) const override;
1607
        nlohmann::json ToJSON(void) const override;
1608
0
        inline bool operator==(const ECC_Point_Add& rhs) const {
1609
0
            return
1610
0
                (curveType == rhs.curveType) &&
1611
0
                (a == rhs.a) &&
1612
0
                (b == rhs.b) &&
1613
0
                (modifier == rhs.modifier);
1614
0
        }
1615
0
        void Serialize(Datasource& ds) const {
1616
0
            curveType.Serialize(ds);
1617
0
            a.Serialize(ds);
1618
0
            b.Serialize(ds);
1619
0
        }
1620
};
1621
1622
class ECC_Point_Mul : public Operation {
1623
    public:
1624
        const component::CurveType curveType;
1625
        const component::ECC_Point a;
1626
        const component::Bignum b;
1627
1628
        ECC_Point_Mul(Datasource& ds, component::Modifier modifier) :
1629
            Operation(std::move(modifier)),
1630
            curveType(ds),
1631
            a(ds),
1632
            b(ds)
1633
5.45k
        { }
1634
        ECC_Point_Mul(nlohmann::json json) :
1635
            Operation(json["modifier"]),
1636
            curveType(json["curveType"]),
1637
            a(json["a_x"], json["a_y"]),
1638
            b(json["b"])
1639
0
        { }
1640
1641
5.28k
        static size_t MaxOperations(void) { return 5; }
1642
        std::string Name(void) const override;
1643
        std::string ToString(void) const override;
1644
        nlohmann::json ToJSON(void) const override;
1645
0
        inline bool operator==(const ECC_Point_Mul& rhs) const {
1646
0
            return
1647
0
                (curveType == rhs.curveType) &&
1648
0
                (a == rhs.a) &&
1649
0
                (b == rhs.b) &&
1650
0
                (modifier == rhs.modifier);
1651
0
        }
1652
0
        void Serialize(Datasource& ds) const {
1653
0
            curveType.Serialize(ds);
1654
0
            a.Serialize(ds);
1655
0
            b.Serialize(ds);
1656
0
        }
1657
};
1658
1659
class ECC_Point_Neg : public Operation {
1660
    public:
1661
        const component::CurveType curveType;
1662
        const component::ECC_Point a;
1663
1664
        ECC_Point_Neg(Datasource& ds, component::Modifier modifier) :
1665
            Operation(std::move(modifier)),
1666
            curveType(ds),
1667
            a(ds)
1668
63
        { }
1669
        ECC_Point_Neg(nlohmann::json json) :
1670
            Operation(json["modifier"]),
1671
            curveType(json["curveType"]),
1672
            a(json["a_x"], json["a_y"])
1673
0
        { }
1674
1675
51
        static size_t MaxOperations(void) { return 5; }
1676
        std::string Name(void) const override;
1677
        std::string ToString(void) const override;
1678
        nlohmann::json ToJSON(void) const override;
1679
0
        inline bool operator==(const ECC_Point_Neg& rhs) const {
1680
0
            return
1681
0
                (curveType == rhs.curveType) &&
1682
0
                (a == rhs.a) &&
1683
0
                (modifier == rhs.modifier);
1684
0
        }
1685
0
        void Serialize(Datasource& ds) const {
1686
0
            curveType.Serialize(ds);
1687
0
            a.Serialize(ds);
1688
0
        }
1689
};
1690
1691
class ECC_Point_Dbl : public Operation {
1692
    public:
1693
        const component::CurveType curveType;
1694
        const component::ECC_Point a;
1695
1696
        ECC_Point_Dbl(Datasource& ds, component::Modifier modifier) :
1697
            Operation(std::move(modifier)),
1698
            curveType(ds),
1699
            a(ds)
1700
74
        { }
1701
        ECC_Point_Dbl(nlohmann::json json) :
1702
            Operation(json["modifier"]),
1703
            curveType(json["curveType"]),
1704
            a(json["a_x"], json["a_y"])
1705
0
        { }
1706
1707
70
        static size_t MaxOperations(void) { return 5; }
1708
        std::string Name(void) const override;
1709
        std::string ToString(void) const override;
1710
        nlohmann::json ToJSON(void) const override;
1711
0
        inline bool operator==(const ECC_Point_Dbl& rhs) const {
1712
0
            return
1713
0
                (curveType == rhs.curveType) &&
1714
0
                (a == rhs.a) &&
1715
0
                (modifier == rhs.modifier);
1716
0
        }
1717
0
        void Serialize(Datasource& ds) const {
1718
0
            curveType.Serialize(ds);
1719
0
            a.Serialize(ds);
1720
0
        }
1721
};
1722
1723
class DH_GenerateKeyPair : public Operation {
1724
    public:
1725
        const component::Bignum prime;
1726
        const component::Bignum base;
1727
1728
        DH_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
1729
            Operation(std::move(modifier)),
1730
            prime(ds),
1731
            base(ds)
1732
7.12k
        { }
1733
        DH_GenerateKeyPair(nlohmann::json json) :
1734
            Operation(json["modifier"]),
1735
            prime(json["prime"]),
1736
            base(json["base"])
1737
0
        { }
1738
        DH_GenerateKeyPair(
1739
                component::Modifier modifier,
1740
                component::Bignum prime,
1741
                component::Bignum base) :
1742
            Operation(std::move(modifier)),
1743
            prime(prime),
1744
            base(base)
1745
0
        { }
1746
1747
6.84k
        static size_t MaxOperations(void) { return 5; }
1748
        std::string Name(void) const override;
1749
        std::string ToString(void) const override;
1750
        nlohmann::json ToJSON(void) const override;
1751
0
        inline bool operator==(const DH_GenerateKeyPair& rhs) const {
1752
0
            return
1753
0
                (prime == rhs.prime) &&
1754
0
                (base  == rhs.base) &&
1755
0
                (modifier == rhs.modifier);
1756
0
        }
1757
0
        void Serialize(Datasource& ds) const {
1758
0
            prime.Serialize(ds);
1759
0
            base.Serialize(ds);
1760
0
        }
1761
};
1762
1763
class DH_Derive : public Operation {
1764
    public:
1765
        const component::Bignum prime;
1766
        const component::Bignum base;
1767
        const component::Bignum pub;
1768
        const component::Bignum priv;
1769
1770
        DH_Derive(Datasource& ds, component::Modifier modifier) :
1771
            Operation(std::move(modifier)),
1772
            prime(ds),
1773
            base(ds),
1774
            pub(ds),
1775
            priv(ds)
1776
3.97k
        { }
1777
        DH_Derive(nlohmann::json json) :
1778
            Operation(json["modifier"]),
1779
            prime(json["prime"]),
1780
            base(json["base"]),
1781
            pub(json["pub"]),
1782
            priv(json["priv"])
1783
0
        { }
1784
        DH_Derive(
1785
                component::Modifier modifier,
1786
                component::Bignum prime,
1787
                component::Bignum base,
1788
                component::Bignum pub,
1789
                component::Bignum priv) :
1790
            Operation(std::move(modifier)),
1791
            prime(prime),
1792
            base(base),
1793
            pub(pub),
1794
            priv(priv)
1795
0
        { }
1796
1797
3.72k
        static size_t MaxOperations(void) { return 5; }
1798
        std::string Name(void) const override;
1799
        std::string ToString(void) const override;
1800
        nlohmann::json ToJSON(void) const override;
1801
0
        inline bool operator==(const DH_Derive& rhs) const {
1802
0
            return
1803
0
                (prime == rhs.prime) &&
1804
0
                (base  == rhs.base) &&
1805
0
                (pub == rhs.pub) &&
1806
0
                (priv == rhs.priv) &&
1807
0
                (modifier == rhs.modifier);
1808
0
        }
1809
0
        void Serialize(Datasource& ds) const {
1810
0
            prime.Serialize(ds);
1811
0
            base.Serialize(ds);
1812
0
            pub.Serialize(ds);
1813
0
            priv.Serialize(ds);
1814
0
        }
1815
};
1816
1817
class BignumCalc : public Operation {
1818
    public:
1819
        const component::CalcOp calcOp;
1820
        const component::Bignum bn0;
1821
        const component::Bignum bn1;
1822
        const component::Bignum bn2;
1823
        const component::Bignum bn3;
1824
        std::optional<component::Bignum> modulo;
1825
1826
        BignumCalc(Datasource& ds, component::Modifier modifier) :
1827
            Operation(std::move(modifier)),
1828
            calcOp(ds),
1829
            bn0(ds),
1830
            bn1(ds),
1831
            bn2(ds),
1832
            bn3(ds)
1833
81.6k
        { }
1834
        BignumCalc(nlohmann::json json) :
1835
            Operation(json["modifier"]),
1836
            calcOp(json["calcOp"]),
1837
            bn0(json["bn1"]),
1838
            bn1(json["bn2"]),
1839
            bn2(json["bn3"]),
1840
            bn3(json["bn4"])
1841
0
        { }
1842
        BignumCalc(
1843
                component::Modifier modifier,
1844
                component::CurveType calcOp,
1845
                component::Bignum bn0,
1846
                component::Bignum bn1,
1847
                component::Bignum bn2,
1848
                component::Bignum bn3) :
1849
            Operation(std::move(modifier)),
1850
            calcOp(calcOp),
1851
            bn0(bn0),
1852
            bn1(bn1),
1853
            bn2(bn2),
1854
            bn3(bn3)
1855
0
        { }
1856
1857
1858
81.4k
        static size_t MaxOperations(void) { return 5; }
1859
        std::string Name(void) const override;
1860
        std::string ToString(void) const override;
1861
        nlohmann::json ToJSON(void) const override;
1862
0
        inline bool operator==(const BignumCalc& rhs) const {
1863
0
            return
1864
0
                (calcOp == rhs.calcOp) &&
1865
0
                (bn0 == rhs.bn0) &&
1866
0
                (bn1 == rhs.bn1) &&
1867
0
                (bn2 == rhs.bn2) &&
1868
0
                (bn3 == rhs.bn3) &&
1869
0
                (modifier == rhs.modifier);
1870
0
        }
1871
0
        void Serialize(Datasource& ds) const {
1872
0
            calcOp.Serialize(ds);
1873
0
            bn0.Serialize(ds);
1874
0
            bn1.Serialize(ds);
1875
0
            bn2.Serialize(ds);
1876
0
            bn3.Serialize(ds);
1877
0
        }
1878
        void SetModulo(component::Bignum& modulo);
1879
};
1880
1881
class BignumCalc_Fp2 : public Operation {
1882
    public:
1883
        const component::CalcOp calcOp;
1884
        const component::Fp2 bn0;
1885
        const component::Fp2 bn1;
1886
        const component::Fp2 bn2;
1887
        const component::Fp2 bn3;
1888
        std::optional<component::Fp2> modulo;
1889
1890
        BignumCalc_Fp2(Datasource& ds, component::Modifier modifier) :
1891
            Operation(std::move(modifier)),
1892
            calcOp(ds),
1893
            bn0(ds),
1894
            bn1(ds),
1895
            bn2(ds),
1896
            bn3(ds)
1897
115
        { }
1898
        BignumCalc_Fp2(nlohmann::json json) :
1899
            Operation(json["modifier"]),
1900
            calcOp(json["calcOp"]),
1901
            bn0(json["bn1"]),
1902
            bn1(json["bn2"]),
1903
            bn2(json["bn3"]),
1904
            bn3(json["bn4"])
1905
0
        { }
1906
        BignumCalc_Fp2(
1907
                component::Modifier modifier,
1908
                component::CurveType calcOp,
1909
                component::Fp2 bn0,
1910
                component::Fp2 bn1,
1911
                component::Fp2 bn2,
1912
                component::Fp2 bn3) :
1913
            Operation(std::move(modifier)),
1914
            calcOp(calcOp),
1915
            bn0(bn0),
1916
            bn1(bn1),
1917
            bn2(bn2),
1918
            bn3(bn3)
1919
0
        { }
1920
1921
1922
109
        static size_t MaxOperations(void) { return 5; }
1923
        std::string Name(void) const override;
1924
        std::string ToString(void) const override;
1925
        nlohmann::json ToJSON(void) const override;
1926
0
        inline bool operator==(const BignumCalc_Fp2& rhs) const {
1927
0
            return
1928
0
                (calcOp == rhs.calcOp) &&
1929
0
                (bn0 == rhs.bn0) &&
1930
0
                (bn1 == rhs.bn1) &&
1931
0
                (bn2 == rhs.bn2) &&
1932
0
                (bn3 == rhs.bn3) &&
1933
0
                (modifier == rhs.modifier);
1934
0
        }
1935
0
        void Serialize(Datasource& ds) const {
1936
0
            calcOp.Serialize(ds);
1937
0
            bn0.Serialize(ds);
1938
0
            bn1.Serialize(ds);
1939
0
            bn2.Serialize(ds);
1940
0
            bn3.Serialize(ds);
1941
0
        }
1942
        void SetModulo(component::Fp2& modulo);
1943
};
1944
1945
class BignumCalc_Fp12 : public Operation {
1946
    public:
1947
        const component::CalcOp calcOp;
1948
        const component::Fp12 bn0;
1949
        const component::Fp12 bn1;
1950
        const component::Fp12 bn2;
1951
        const component::Fp12 bn3;
1952
        std::optional<component::Fp12> modulo;
1953
1954
        BignumCalc_Fp12(Datasource& ds, component::Modifier modifier) :
1955
            Operation(std::move(modifier)),
1956
            calcOp(ds),
1957
            bn0(ds),
1958
            bn1(ds),
1959
            bn2(ds),
1960
            bn3(ds)
1961
340
        { }
1962
        BignumCalc_Fp12(nlohmann::json json) :
1963
            Operation(json["modifier"]),
1964
            calcOp(json["calcOp"]),
1965
            bn0(json["bn1"]),
1966
            bn1(json["bn2"]),
1967
            bn2(json["bn3"]),
1968
            bn3(json["bn4"])
1969
0
        { }
1970
        BignumCalc_Fp12(
1971
                component::Modifier modifier,
1972
                component::CurveType calcOp,
1973
                component::Fp12 bn0,
1974
                component::Fp12 bn1,
1975
                component::Fp12 bn2,
1976
                component::Fp12 bn3) :
1977
            Operation(std::move(modifier)),
1978
            calcOp(calcOp),
1979
            bn0(bn0),
1980
            bn1(bn1),
1981
            bn2(bn2),
1982
            bn3(bn3)
1983
0
        { }
1984
1985
1986
318
        static size_t MaxOperations(void) { return 5; }
1987
        std::string Name(void) const override;
1988
        std::string ToString(void) const override;
1989
        nlohmann::json ToJSON(void) const override;
1990
0
        inline bool operator==(const BignumCalc_Fp12& rhs) const {
1991
0
            return
1992
0
                (calcOp == rhs.calcOp) &&
1993
0
                (bn0 == rhs.bn0) &&
1994
0
                (bn1 == rhs.bn1) &&
1995
0
                (bn2 == rhs.bn2) &&
1996
0
                (bn3 == rhs.bn3) &&
1997
0
                (modifier == rhs.modifier);
1998
0
        }
1999
0
        void Serialize(Datasource& ds) const {
2000
0
            calcOp.Serialize(ds);
2001
0
            bn0.Serialize(ds);
2002
0
            bn1.Serialize(ds);
2003
0
            bn2.Serialize(ds);
2004
0
            bn3.Serialize(ds);
2005
0
        }
2006
        void SetModulo(component::Fp12& modulo);
2007
};
2008
2009
class BLS_PrivateToPublic : public Operation {
2010
    public:
2011
        const component::CurveType curveType;
2012
        const component::BLS_PrivateKey priv;
2013
2014
        BLS_PrivateToPublic(Datasource& ds, component::Modifier modifier) :
2015
            Operation(std::move(modifier)),
2016
            curveType(ds),
2017
            priv(ds)
2018
113
        { }
2019
        BLS_PrivateToPublic(nlohmann::json json) :
2020
            Operation(json["modifier"]),
2021
            curveType(json["curveType"]),
2022
            priv(json["priv"])
2023
0
        { }
2024
2025
104
        static size_t MaxOperations(void) { return 5; }
2026
        std::string Name(void) const override;
2027
        std::string ToString(void) const override;
2028
        nlohmann::json ToJSON(void) const override;
2029
0
        inline bool operator==(const BLS_PrivateToPublic& rhs) const {
2030
0
            return
2031
0
                (curveType == rhs.curveType) &&
2032
0
                (priv == rhs.priv) &&
2033
0
                (modifier == rhs.modifier);
2034
0
        }
2035
0
        void Serialize(Datasource& ds) const {
2036
0
            curveType.Serialize(ds);
2037
0
            priv.Serialize(ds);
2038
0
        }
2039
};
2040
2041
class BLS_PrivateToPublic_G2 : public Operation {
2042
    public:
2043
        const component::CurveType curveType;
2044
        const component::BLS_PrivateKey priv;
2045
2046
        BLS_PrivateToPublic_G2(Datasource& ds, component::Modifier modifier) :
2047
            Operation(std::move(modifier)),
2048
            curveType(ds),
2049
            priv(ds)
2050
98
        { }
2051
        BLS_PrivateToPublic_G2(nlohmann::json json) :
2052
            Operation(json["modifier"]),
2053
            curveType(json["curveType"]),
2054
            priv(json["priv"])
2055
0
        { }
2056
2057
86
        static size_t MaxOperations(void) { return 5; }
2058
        std::string Name(void) const override;
2059
        std::string ToString(void) const override;
2060
        nlohmann::json ToJSON(void) const override;
2061
0
        inline bool operator==(const BLS_PrivateToPublic_G2& rhs) const {
2062
0
            return
2063
0
                (curveType == rhs.curveType) &&
2064
0
                (priv == rhs.priv) &&
2065
0
                (modifier == rhs.modifier);
2066
0
        }
2067
0
        void Serialize(Datasource& ds) const {
2068
0
            curveType.Serialize(ds);
2069
0
            priv.Serialize(ds);
2070
0
        }
2071
};
2072
2073
class BLS_Sign : public Operation {
2074
    public:
2075
        const component::CurveType curveType;
2076
        const component::BLS_PrivateKey priv;
2077
        const bool hashOrPoint;
2078
        const component::G2 point;
2079
        const component::Cleartext cleartext;
2080
        const component::Cleartext dest;
2081
        const component::Cleartext aug;
2082
2083
        BLS_Sign(Datasource& ds, component::Modifier modifier) :
2084
            Operation(std::move(modifier)),
2085
            curveType(ds),
2086
            priv(ds),
2087
            hashOrPoint(ds.Get<bool>()),
2088
            point(ds),
2089
            cleartext(ds),
2090
            dest(ds),
2091
            aug(ds)
2092
91
        { }
2093
        BLS_Sign(nlohmann::json json) :
2094
            Operation(json["modifier"]),
2095
            curveType(json["curveType"]),
2096
            priv(json["priv"]),
2097
            hashOrPoint(json["hashOrPoint"]),
2098
            point(json["point_v"], json["point_w"], json["point_x"], json["point_y"]),
2099
            cleartext(json["cleartext"]),
2100
            dest(json["dest"]),
2101
            aug(json["aug"])
2102
0
        { }
2103
2104
79
        static size_t MaxOperations(void) { return 5; }
2105
        std::string Name(void) const override;
2106
        std::string ToString(void) const override;
2107
        nlohmann::json ToJSON(void) const override;
2108
0
        inline bool operator==(const BLS_Sign& rhs) const {
2109
0
            return
2110
0
                (curveType == rhs.curveType) &&
2111
0
                (priv == rhs.priv) &&
2112
0
                (hashOrPoint == rhs.hashOrPoint) &&
2113
0
                (point == rhs.point) &&
2114
0
                (cleartext == rhs.cleartext) &&
2115
0
                (dest == rhs.dest) &&
2116
0
                (aug == rhs.aug) &&
2117
0
                (modifier == rhs.modifier);
2118
0
        }
2119
0
        void Serialize(Datasource& ds) const {
2120
0
            curveType.Serialize(ds);
2121
0
            priv.Serialize(ds);
2122
0
            ds.Put<bool>(hashOrPoint);
2123
0
            point.Serialize(ds);
2124
0
            cleartext.Serialize(ds);
2125
0
            dest.Serialize(ds);
2126
0
            aug.Serialize(ds);
2127
0
        }
2128
};
2129
2130
class BLS_Verify : public Operation {
2131
    public:
2132
        const component::CurveType curveType;
2133
        const component::BLS_PublicKey pub;
2134
        const bool hashOrPoint;
2135
        const component::G2 point;
2136
        const component::Cleartext cleartext;
2137
        const component::Cleartext dest;
2138
        const component::G2 signature;
2139
2140
        BLS_Verify(Datasource& ds, component::Modifier modifier) :
2141
            Operation(std::move(modifier)),
2142
            curveType(ds),
2143
            pub(ds),
2144
            hashOrPoint(ds.Get<bool>()),
2145
            point(ds),
2146
            cleartext(ds),
2147
            dest(ds),
2148
            signature(ds)
2149
65
        { }
2150
        BLS_Verify(nlohmann::json json) :
2151
            Operation(json["modifier"]),
2152
            curveType(json["curveType"]),
2153
            pub(json["pub_x"], json["pub_y"]),
2154
            hashOrPoint(json["hashOrPoint"]),
2155
            point(json["point_v"], json["point_w"], json["point_x"], json["point_y"]),
2156
            cleartext(json["cleartext"]),
2157
            dest(json["dest"]),
2158
            signature(json["sig_v"], json["sig_w"], json["sig_x"], json["sig_y"])
2159
0
        { }
2160
2161
53
        static size_t MaxOperations(void) { return 5; }
2162
        std::string Name(void) const override;
2163
        std::string ToString(void) const override;
2164
        nlohmann::json ToJSON(void) const override;
2165
0
        inline bool operator==(const BLS_Verify& rhs) const {
2166
0
            return
2167
0
                (curveType == rhs.curveType) &&
2168
0
                (pub == rhs.pub) &&
2169
0
                (hashOrPoint == rhs.hashOrPoint) &&
2170
0
                (point == rhs.point) &&
2171
0
                (cleartext == rhs.cleartext) &&
2172
0
                (dest == rhs.dest) &&
2173
0
                (signature == rhs.signature) &&
2174
0
                (modifier == rhs.modifier);
2175
0
        }
2176
0
        void Serialize(Datasource& ds) const {
2177
0
            curveType.Serialize(ds);
2178
0
            pub.Serialize(ds);
2179
0
            ds.Put<bool>(hashOrPoint);
2180
0
            point.Serialize(ds);
2181
0
            cleartext.Serialize(ds);
2182
0
            dest.Serialize(ds);
2183
0
            signature.Serialize(ds);
2184
0
        }
2185
};
2186
2187
class BLS_BatchSign : public Operation {
2188
    public:
2189
        component::BLS_BatchSign_Vector bf;
2190
2191
        BLS_BatchSign(Datasource& ds, component::Modifier modifier) :
2192
            Operation(std::move(modifier)),
2193
            bf(ds)
2194
125
        { }
2195
        BLS_BatchSign(nlohmann::json json) :
2196
            Operation(json["modifier"]),
2197
            bf(json["bf"])
2198
0
        { }
2199
2200
75
        static size_t MaxOperations(void) { return 5; }
2201
        std::string Name(void) const override;
2202
        std::string ToString(void) const override;
2203
        nlohmann::json ToJSON(void) const override;
2204
0
        inline bool operator==(const BLS_BatchSign& rhs) const {
2205
0
            return
2206
0
                (bf == rhs.bf) &&
2207
0
                (modifier == rhs.modifier);
2208
0
        }
2209
0
        void Serialize(Datasource& ds) const {
2210
0
            bf.Serialize(ds);
2211
0
        }
2212
};
2213
2214
class BLS_BatchVerify : public Operation {
2215
    public:
2216
        component::BLS_BatchVerify_Vector bf;
2217
2218
        BLS_BatchVerify(Datasource& ds, component::Modifier modifier) :
2219
            Operation(std::move(modifier)),
2220
            bf(ds)
2221
50
        { }
2222
        BLS_BatchVerify(nlohmann::json json) :
2223
            Operation(json["modifier"]),
2224
            bf(json["bf"])
2225
0
        { }
2226
2227
26
        static size_t MaxOperations(void) { return 5; }
2228
        std::string Name(void) const override;
2229
        std::string ToString(void) const override;
2230
        nlohmann::json ToJSON(void) const override;
2231
0
        inline bool operator==(const BLS_BatchVerify& rhs) const {
2232
0
            return
2233
0
                (bf == rhs.bf) &&
2234
0
                (modifier == rhs.modifier);
2235
0
        }
2236
0
        void Serialize(Datasource& ds) const {
2237
0
            bf.Serialize(ds);
2238
0
        }
2239
};
2240
2241
class BLS_Aggregate_G1 : public Operation {
2242
    public:
2243
        const component::CurveType curveType;
2244
        component::BLS_G1_Vector points;
2245
2246
        BLS_Aggregate_G1(Datasource& ds, component::Modifier modifier) :
2247
            Operation(std::move(modifier)),
2248
            curveType(ds),
2249
            points(ds)
2250
91
        { }
2251
        BLS_Aggregate_G1(nlohmann::json json) :
2252
            Operation(json["modifier"]),
2253
            curveType(json["curveType"]),
2254
            points(json["points"])
2255
0
        { }
2256
2257
69
        static size_t MaxOperations(void) { return 5; }
2258
        std::string Name(void) const override;
2259
        std::string ToString(void) const override;
2260
        nlohmann::json ToJSON(void) const override;
2261
0
        inline bool operator==(const BLS_Aggregate_G1& rhs) const {
2262
0
            return
2263
0
                (curveType == rhs.curveType) &&
2264
0
                (points == rhs.points) &&
2265
0
                (modifier == rhs.modifier);
2266
0
        }
2267
0
        void Serialize(Datasource& ds) const {
2268
0
            curveType.Serialize(ds);
2269
0
            points.Serialize(ds);
2270
0
        }
2271
};
2272
2273
class BLS_Aggregate_G2 : public Operation {
2274
    public:
2275
        const component::CurveType curveType;
2276
        component::BLS_G2_Vector points;
2277
2278
        BLS_Aggregate_G2(Datasource& ds, component::Modifier modifier) :
2279
            Operation(std::move(modifier)),
2280
            curveType(ds),
2281
            points(ds)
2282
97
        { }
2283
        BLS_Aggregate_G2(nlohmann::json json) :
2284
            Operation(json["modifier"]),
2285
            curveType(json["curveType"]),
2286
            points(json["points"])
2287
0
        { }
2288
2289
70
        static size_t MaxOperations(void) { return 5; }
2290
        std::string Name(void) const override;
2291
        std::string ToString(void) const override;
2292
        nlohmann::json ToJSON(void) const override;
2293
0
        inline bool operator==(const BLS_Aggregate_G2& rhs) const {
2294
0
            return
2295
0
                (curveType == rhs.curveType) &&
2296
0
                (points == rhs.points) &&
2297
0
                (modifier == rhs.modifier);
2298
0
        }
2299
0
        void Serialize(Datasource& ds) const {
2300
0
            curveType.Serialize(ds);
2301
0
            points.Serialize(ds);
2302
0
        }
2303
};
2304
2305
class BLS_Pairing : public Operation {
2306
    public:
2307
        const component::CurveType curveType;
2308
        const component::G1 g1;
2309
        const component::G2 g2;
2310
2311
        BLS_Pairing(Datasource& ds, component::Modifier modifier) :
2312
            Operation(std::move(modifier)),
2313
            curveType(ds),
2314
            g1(ds),
2315
            g2(ds)
2316
92
        { }
2317
        BLS_Pairing(nlohmann::json json) :
2318
            Operation(json["modifier"]),
2319
            curveType(json["curveType"]),
2320
            g1(json["g1_x"], json["g1_y"]),
2321
            g2(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
2322
0
        { }
2323
2324
83
        static size_t MaxOperations(void) { return 5; }
2325
        std::string Name(void) const override;
2326
        std::string ToString(void) const override;
2327
        nlohmann::json ToJSON(void) const override;
2328
0
        inline bool operator==(const BLS_Pairing& rhs) const {
2329
0
            return
2330
0
                (curveType == rhs.curveType) &&
2331
0
                (g1 == rhs.g1) &&
2332
0
                (g2 == rhs.g2) &&
2333
0
                (modifier == rhs.modifier);
2334
0
        }
2335
0
        void Serialize(Datasource& ds) const {
2336
0
            curveType.Serialize(ds);
2337
0
            g1.Serialize(ds);
2338
0
            g2.Serialize(ds);
2339
0
        }
2340
};
2341
2342
class BLS_MillerLoop : public Operation {
2343
    public:
2344
        const component::CurveType curveType;
2345
        const component::G1 g1;
2346
        const component::G2 g2;
2347
2348
        BLS_MillerLoop(Datasource& ds, component::Modifier modifier) :
2349
            Operation(std::move(modifier)),
2350
            curveType(ds),
2351
            g1(ds),
2352
            g2(ds)
2353
88
        { }
2354
        BLS_MillerLoop(nlohmann::json json) :
2355
            Operation(json["modifier"]),
2356
            curveType(json["curveType"]),
2357
            g1(json["g1_x"], json["g1_y"]),
2358
            g2(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
2359
0
        { }
2360
2361
78
        static size_t MaxOperations(void) { return 5; }
2362
        std::string Name(void) const override;
2363
        std::string ToString(void) const override;
2364
        nlohmann::json ToJSON(void) const override;
2365
0
        inline bool operator==(const BLS_MillerLoop& rhs) const {
2366
0
            return
2367
0
                (curveType == rhs.curveType) &&
2368
0
                (g1 == rhs.g1) &&
2369
0
                (g2 == rhs.g2) &&
2370
0
                (modifier == rhs.modifier);
2371
0
        }
2372
0
        void Serialize(Datasource& ds) const {
2373
0
            curveType.Serialize(ds);
2374
0
            g1.Serialize(ds);
2375
0
            g2.Serialize(ds);
2376
0
        }
2377
};
2378
2379
class BLS_FinalExp : public Operation {
2380
    public:
2381
        const component::CurveType curveType;
2382
        const component::Fp12 fp12;
2383
2384
        BLS_FinalExp(Datasource& ds, component::Modifier modifier) :
2385
            Operation(std::move(modifier)),
2386
            curveType(ds),
2387
            fp12(ds)
2388
95
        { }
2389
        BLS_FinalExp(nlohmann::json json) :
2390
            Operation(json["modifier"]),
2391
            curveType(json["curveType"]),
2392
            fp12(json["fp12"])
2393
0
        { }
2394
2395
75
        static size_t MaxOperations(void) { return 5; }
2396
        std::string Name(void) const override;
2397
        std::string ToString(void) const override;
2398
        nlohmann::json ToJSON(void) const override;
2399
0
        inline bool operator==(const BLS_FinalExp& rhs) const {
2400
0
            return
2401
0
                (curveType == rhs.curveType) &&
2402
0
                (fp12 == rhs.fp12) &&
2403
0
                (modifier == rhs.modifier);
2404
0
        }
2405
0
        void Serialize(Datasource& ds) const {
2406
0
            curveType.Serialize(ds);
2407
0
            fp12.Serialize(ds);
2408
0
        }
2409
};
2410
2411
class BLS_HashToG1 : public Operation {
2412
    public:
2413
        const component::CurveType curveType;
2414
        const component::Cleartext cleartext;
2415
        const component::Cleartext dest;
2416
        const component::Cleartext aug;
2417
2418
        BLS_HashToG1(Datasource& ds, component::Modifier modifier) :
2419
            Operation(std::move(modifier)),
2420
            curveType(ds),
2421
            cleartext(ds),
2422
            dest(ds),
2423
            aug(ds)
2424
80
        { }
2425
        BLS_HashToG1(const component::CurveType curveType, const component::Cleartext cleartext, const component::Cleartext dest, const component::Cleartext aug, component::Modifier modifier) :
2426
            Operation(std::move(modifier)),
2427
            curveType(curveType),
2428
            cleartext(cleartext),
2429
            dest(dest),
2430
            aug(aug)
2431
0
        { }
2432
        BLS_HashToG1(nlohmann::json json) :
2433
            Operation(json["modifier"]),
2434
            curveType(json["curveType"]),
2435
            cleartext(json["cleartext"]),
2436
            dest(json["dest"]),
2437
            aug(json["aug"])
2438
0
        { }
2439
2440
70
        static size_t MaxOperations(void) { return 5; }
2441
        std::string Name(void) const override;
2442
        std::string ToString(void) const override;
2443
        nlohmann::json ToJSON(void) const override;
2444
0
        inline bool operator==(const BLS_HashToG1& rhs) const {
2445
0
            return
2446
0
                (curveType == rhs.curveType) &&
2447
0
                (cleartext == rhs.cleartext) &&
2448
0
                (dest == rhs.dest) &&
2449
0
                (aug == rhs.aug) &&
2450
0
                (modifier == rhs.modifier);
2451
0
        }
2452
0
        void Serialize(Datasource& ds) const {
2453
0
            curveType.Serialize(ds);
2454
0
            cleartext.Serialize(ds);
2455
0
            dest.Serialize(ds);
2456
0
            aug.Serialize(ds);
2457
0
        }
2458
};
2459
2460
class BLS_HashToG2 : public Operation {
2461
    public:
2462
        const component::CurveType curveType;
2463
        const component::Cleartext cleartext;
2464
        const component::Cleartext dest;
2465
        const component::Cleartext aug;
2466
2467
        BLS_HashToG2(Datasource& ds, component::Modifier modifier) :
2468
            Operation(std::move(modifier)),
2469
            curveType(ds),
2470
            cleartext(ds),
2471
            dest(ds),
2472
            aug(ds)
2473
92
        { }
2474
        BLS_HashToG2(const component::CurveType curveType, const component::Cleartext cleartext, const component::Cleartext dest, const component::Cleartext aug, component::Modifier modifier) :
2475
            Operation(std::move(modifier)),
2476
            curveType(curveType),
2477
            cleartext(cleartext),
2478
            dest(dest),
2479
            aug(aug)
2480
0
        { }
2481
        BLS_HashToG2(nlohmann::json json) :
2482
            Operation(json["modifier"]),
2483
            curveType(json["curveType"]),
2484
            cleartext(json["cleartext"]),
2485
            dest(json["dest"]),
2486
            aug(json["aug"])
2487
0
        { }
2488
2489
82
        static size_t MaxOperations(void) { return 5; }
2490
        std::string Name(void) const override;
2491
        std::string ToString(void) const override;
2492
        nlohmann::json ToJSON(void) const override;
2493
0
        inline bool operator==(const BLS_HashToG2& rhs) const {
2494
0
            return
2495
0
                (curveType == rhs.curveType) &&
2496
0
                (cleartext == rhs.cleartext) &&
2497
0
                (dest == rhs.dest) &&
2498
0
                (aug == rhs.aug) &&
2499
0
                (modifier == rhs.modifier);
2500
0
        }
2501
0
        void Serialize(Datasource& ds) const {
2502
0
            curveType.Serialize(ds);
2503
0
            cleartext.Serialize(ds);
2504
0
            dest.Serialize(ds);
2505
0
            aug.Serialize(ds);
2506
0
        }
2507
};
2508
2509
class BLS_MapToG1 : public Operation {
2510
    public:
2511
        const component::CurveType curveType;
2512
        const component::Bignum u;
2513
        const component::Bignum v;
2514
2515
        BLS_MapToG1(Datasource& ds, component::Modifier modifier) :
2516
            Operation(std::move(modifier)),
2517
            curveType(ds),
2518
            u(ds),
2519
            v(ds)
2520
74
        { }
2521
        BLS_MapToG1(const component::CurveType curveType, const component::Bignum u, const component::Bignum v, component::Modifier modifier) :
2522
            Operation(std::move(modifier)),
2523
            curveType(curveType),
2524
            u(u),
2525
            v(v)
2526
0
        { }
2527
        BLS_MapToG1(nlohmann::json json) :
2528
            Operation(json["modifier"]),
2529
            curveType(json["curveType"]),
2530
            u(json["u"]),
2531
            v(json["v"])
2532
0
        { }
2533
2534
65
        static size_t MaxOperations(void) { return 5; }
2535
        std::string Name(void) const override;
2536
        std::string ToString(void) const override;
2537
        nlohmann::json ToJSON(void) const override;
2538
0
        inline bool operator==(const BLS_MapToG1& rhs) const {
2539
0
            return
2540
0
                (curveType == rhs.curveType) &&
2541
0
                (u == rhs.u) &&
2542
0
                (v == rhs.v) &&
2543
0
                (modifier == rhs.modifier);
2544
0
        }
2545
0
        void Serialize(Datasource& ds) const {
2546
0
            curveType.Serialize(ds);
2547
0
            u.Serialize(ds);
2548
0
            v.Serialize(ds);
2549
0
        }
2550
};
2551
2552
class BLS_MapToG2 : public Operation {
2553
    public:
2554
        const component::CurveType curveType;
2555
        const component::Fp2 u;
2556
        const component::Fp2 v;
2557
2558
        BLS_MapToG2(Datasource& ds, component::Modifier modifier) :
2559
            Operation(std::move(modifier)),
2560
            curveType(ds),
2561
            u(ds),
2562
            v(ds)
2563
59
        { }
2564
        BLS_MapToG2(const component::CurveType curveType, const component::Fp2 u, const component::Fp2 v, component::Modifier modifier) :
2565
            Operation(std::move(modifier)),
2566
            curveType(curveType),
2567
            u(u),
2568
            v(v)
2569
0
        { }
2570
        BLS_MapToG2(nlohmann::json json) :
2571
            Operation(json["modifier"]),
2572
            curveType(json["curveType"]),
2573
            u(json["u"]),
2574
            v(json["v"])
2575
0
        { }
2576
2577
51
        static size_t MaxOperations(void) { return 5; }
2578
        std::string Name(void) const override;
2579
        std::string ToString(void) const override;
2580
        nlohmann::json ToJSON(void) const override;
2581
0
        inline bool operator==(const BLS_MapToG2& rhs) const {
2582
0
            return
2583
0
                (curveType == rhs.curveType) &&
2584
0
                (u == rhs.u) &&
2585
0
                (v == rhs.v) &&
2586
0
                (modifier == rhs.modifier);
2587
0
        }
2588
0
        void Serialize(Datasource& ds) const {
2589
0
            curveType.Serialize(ds);
2590
0
            u.Serialize(ds);
2591
0
            v.Serialize(ds);
2592
0
        }
2593
};
2594
2595
class BLS_IsG1OnCurve : public Operation {
2596
    public:
2597
        const component::CurveType curveType;
2598
        const component::G1 g1;
2599
2600
        BLS_IsG1OnCurve(Datasource& ds, component::Modifier modifier) :
2601
            Operation(std::move(modifier)),
2602
            curveType(ds),
2603
            g1(ds)
2604
80
        { }
2605
        BLS_IsG1OnCurve(nlohmann::json json) :
2606
            Operation(json["modifier"]),
2607
            curveType(json["curveType"]),
2608
            g1(json["g1_x"], json["g1_y"])
2609
0
        { }
2610
2611
75
        static size_t MaxOperations(void) { return 5; }
2612
        std::string Name(void) const override;
2613
        std::string ToString(void) const override;
2614
        nlohmann::json ToJSON(void) const override;
2615
0
        inline bool operator==(const BLS_IsG1OnCurve& rhs) const {
2616
0
            return
2617
0
                (curveType == rhs.curveType) &&
2618
0
                (g1 == rhs.g1) &&
2619
0
                (modifier == rhs.modifier);
2620
0
        }
2621
0
        void Serialize(Datasource& ds) const {
2622
0
            curveType.Serialize(ds);
2623
0
            g1.Serialize(ds);
2624
0
        }
2625
};
2626
2627
class BLS_IsG2OnCurve : public Operation {
2628
    public:
2629
        const component::CurveType curveType;
2630
        const component::G2 g2;
2631
2632
        BLS_IsG2OnCurve(Datasource& ds, component::Modifier modifier) :
2633
            Operation(std::move(modifier)),
2634
            curveType(ds),
2635
            g2(ds)
2636
120
        { }
2637
        BLS_IsG2OnCurve(nlohmann::json json) :
2638
            Operation(json["modifier"]),
2639
            curveType(json["curveType"]),
2640
            g2(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
2641
0
        { }
2642
2643
112
        static size_t MaxOperations(void) { return 5; }
2644
        std::string Name(void) const override;
2645
        std::string ToString(void) const override;
2646
        nlohmann::json ToJSON(void) const override;
2647
0
        inline bool operator==(const BLS_IsG2OnCurve& rhs) const {
2648
0
            return
2649
0
                (curveType == rhs.curveType) &&
2650
0
                (g2 == rhs.g2) &&
2651
0
                (modifier == rhs.modifier);
2652
0
        }
2653
0
        void Serialize(Datasource& ds) const {
2654
0
            curveType.Serialize(ds);
2655
0
            g2.Serialize(ds);
2656
0
        }
2657
};
2658
2659
class BLS_GenerateKeyPair : public Operation {
2660
    public:
2661
        const component::CurveType curveType;
2662
        const component::Cleartext ikm;
2663
        const component::Cleartext info;
2664
2665
        BLS_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
2666
            Operation(std::move(modifier)),
2667
            curveType(ds),
2668
            ikm(ds),
2669
            info(ds)
2670
62
        { }
2671
2672
        BLS_GenerateKeyPair(nlohmann::json json) :
2673
            Operation(json["modifier"]),
2674
            curveType(json["curveType"]),
2675
            ikm(json["ikm"]),
2676
            info(json["info"])
2677
0
        { }
2678
2679
53
        static size_t MaxOperations(void) { return 5; }
2680
        std::string Name(void) const override;
2681
        std::string ToString(void) const override;
2682
        nlohmann::json ToJSON(void) const override;
2683
0
        inline bool operator==(const BLS_GenerateKeyPair& rhs) const {
2684
0
            return
2685
0
                (curveType == rhs.curveType) &&
2686
0
                (ikm == rhs.ikm) &&
2687
0
                (info == rhs.info) &&
2688
0
                (modifier == rhs.modifier);
2689
0
        }
2690
0
        void Serialize(Datasource& ds) const {
2691
0
            curveType.Serialize(ds);
2692
0
            ikm.Serialize(ds);
2693
0
            info.Serialize(ds);
2694
0
        }
2695
};
2696
2697
class BLS_Decompress_G1 : public Operation {
2698
    public:
2699
        const component::CurveType curveType;
2700
        const component::Bignum compressed;
2701
2702
        BLS_Decompress_G1(Datasource& ds, component::Modifier modifier) :
2703
            Operation(std::move(modifier)),
2704
            curveType(ds),
2705
            compressed(ds)
2706
70
        { }
2707
        BLS_Decompress_G1(nlohmann::json json) :
2708
            Operation(json["modifier"]),
2709
            curveType(json["curveType"]),
2710
            compressed(json["compressed"])
2711
0
        { }
2712
2713
59
        static size_t MaxOperations(void) { return 5; }
2714
        std::string Name(void) const override;
2715
        std::string ToString(void) const override;
2716
        nlohmann::json ToJSON(void) const override;
2717
0
        inline bool operator==(const BLS_Decompress_G1& rhs) const {
2718
0
            return
2719
0
                (curveType == rhs.curveType) &&
2720
0
                (compressed == rhs.compressed) &&
2721
0
                (modifier == rhs.modifier);
2722
0
        }
2723
0
        void Serialize(Datasource& ds) const {
2724
0
            curveType.Serialize(ds);
2725
0
            compressed.Serialize(ds);
2726
0
        }
2727
};
2728
2729
class BLS_Compress_G1 : public Operation {
2730
    public:
2731
        const component::CurveType curveType;
2732
        const component::G1 uncompressed;
2733
2734
        BLS_Compress_G1(Datasource& ds, component::Modifier modifier) :
2735
            Operation(std::move(modifier)),
2736
            curveType(ds),
2737
            uncompressed(ds)
2738
91
        { }
2739
        BLS_Compress_G1(nlohmann::json json) :
2740
            Operation(json["modifier"]),
2741
            curveType(json["curveType"]),
2742
            uncompressed(json["g1_x"], json["g1_y"])
2743
0
        { }
2744
2745
79
        static size_t MaxOperations(void) { return 5; }
2746
        std::string Name(void) const override;
2747
        std::string ToString(void) const override;
2748
        nlohmann::json ToJSON(void) const override;
2749
0
        inline bool operator==(const BLS_Compress_G1& rhs) const {
2750
0
            return
2751
0
                (curveType == rhs.curveType) &&
2752
0
                (uncompressed == rhs.uncompressed) &&
2753
0
                (modifier == rhs.modifier);
2754
0
        }
2755
0
        void Serialize(Datasource& ds) const {
2756
0
            curveType.Serialize(ds);
2757
0
            uncompressed.Serialize(ds);
2758
0
        }
2759
};
2760
2761
class BLS_Decompress_G2 : public Operation {
2762
    public:
2763
        const component::CurveType curveType;
2764
        const component::G1 compressed;
2765
2766
        BLS_Decompress_G2(Datasource& ds, component::Modifier modifier) :
2767
            Operation(std::move(modifier)),
2768
            curveType(ds),
2769
            compressed(ds)
2770
80
        { }
2771
        BLS_Decompress_G2(nlohmann::json json) :
2772
            Operation(json["modifier"]),
2773
            curveType(json["curveType"]),
2774
            compressed(json["g1_x"], json["g1_y"])
2775
0
        { }
2776
2777
72
        static size_t MaxOperations(void) { return 5; }
2778
        std::string Name(void) const override;
2779
        std::string ToString(void) const override;
2780
        nlohmann::json ToJSON(void) const override;
2781
0
        inline bool operator==(const BLS_Decompress_G2& rhs) const {
2782
0
            return
2783
0
                (curveType == rhs.curveType) &&
2784
0
                (compressed == rhs.compressed) &&
2785
0
                (modifier == rhs.modifier);
2786
0
        }
2787
0
        void Serialize(Datasource& ds) const {
2788
0
            curveType.Serialize(ds);
2789
0
            compressed.Serialize(ds);
2790
0
        }
2791
};
2792
2793
class BLS_Compress_G2 : public Operation {
2794
    public:
2795
        const component::CurveType curveType;
2796
        const component::G2 uncompressed;
2797
2798
        BLS_Compress_G2(Datasource& ds, component::Modifier modifier) :
2799
            Operation(std::move(modifier)),
2800
            curveType(ds),
2801
            uncompressed(ds)
2802
52
        { }
2803
        BLS_Compress_G2(nlohmann::json json) :
2804
            Operation(json["modifier"]),
2805
            curveType(json["curveType"]),
2806
            uncompressed(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
2807
0
        { }
2808
2809
47
        static size_t MaxOperations(void) { return 5; }
2810
        std::string Name(void) const override;
2811
        std::string ToString(void) const override;
2812
        nlohmann::json ToJSON(void) const override;
2813
0
        inline bool operator==(const BLS_Compress_G2& rhs) const {
2814
0
            return
2815
0
                (curveType == rhs.curveType) &&
2816
0
                (uncompressed == rhs.uncompressed) &&
2817
0
                (modifier == rhs.modifier);
2818
0
        }
2819
0
        void Serialize(Datasource& ds) const {
2820
0
            curveType.Serialize(ds);
2821
0
            uncompressed.Serialize(ds);
2822
0
        }
2823
};
2824
2825
class BLS_G1_Add : public Operation {
2826
    public:
2827
        const component::CurveType curveType;
2828
        const component::G1 a, b;
2829
2830
        BLS_G1_Add(Datasource& ds, component::Modifier modifier) :
2831
            Operation(std::move(modifier)),
2832
            curveType(ds),
2833
            a(ds),
2834
            b(ds)
2835
106
        { }
2836
        BLS_G1_Add(nlohmann::json json) :
2837
            Operation(json["modifier"]),
2838
            curveType(json["curveType"]),
2839
            a(json["a_x"], json["a_y"]),
2840
            b(json["b_x"], json["b_y"])
2841
0
        { }
2842
2843
99
        static size_t MaxOperations(void) { return 5; }
2844
        std::string Name(void) const override;
2845
        std::string ToString(void) const override;
2846
        nlohmann::json ToJSON(void) const override;
2847
0
        inline bool operator==(const BLS_G1_Add& rhs) const {
2848
0
            return
2849
0
                (curveType == rhs.curveType) &&
2850
0
                (a == rhs.a) &&
2851
0
                (b == rhs.b) &&
2852
0
                (modifier == rhs.modifier);
2853
0
        }
2854
0
        void Serialize(Datasource& ds) const {
2855
0
            curveType.Serialize(ds);
2856
0
            a.Serialize(ds);
2857
0
            b.Serialize(ds);
2858
0
        }
2859
};
2860
2861
class BLS_G1_IsEq : public Operation {
2862
    public:
2863
        const component::CurveType curveType;
2864
        const component::G1 a, b;
2865
2866
        BLS_G1_IsEq(Datasource& ds, component::Modifier modifier) :
2867
            Operation(std::move(modifier)),
2868
            curveType(ds),
2869
            a(ds),
2870
            b(ds)
2871
124
        { }
2872
        BLS_G1_IsEq(nlohmann::json json) :
2873
            Operation(json["modifier"]),
2874
            curveType(json["curveType"]),
2875
            a(json["a_x"], json["a_y"]),
2876
            b(json["b_x"], json["b_y"])
2877
0
        { }
2878
2879
116
        static size_t MaxOperations(void) { return 5; }
2880
        std::string Name(void) const override;
2881
        std::string ToString(void) const override;
2882
        nlohmann::json ToJSON(void) const override;
2883
0
        inline bool operator==(const BLS_G1_IsEq& rhs) const {
2884
0
            return
2885
0
                (curveType == rhs.curveType) &&
2886
0
                (a == rhs.a) &&
2887
0
                (b == rhs.b) &&
2888
0
                (modifier == rhs.modifier);
2889
0
        }
2890
0
        void Serialize(Datasource& ds) const {
2891
0
            curveType.Serialize(ds);
2892
0
            a.Serialize(ds);
2893
0
            b.Serialize(ds);
2894
0
        }
2895
};
2896
2897
class BLS_G1_Mul : public Operation {
2898
    public:
2899
        const component::CurveType curveType;
2900
        const component::G1 a;
2901
        const component::Bignum b;
2902
2903
        BLS_G1_Mul(Datasource& ds, component::Modifier modifier) :
2904
            Operation(std::move(modifier)),
2905
            curveType(ds),
2906
            a(ds),
2907
            b(ds)
2908
94
        { }
2909
        BLS_G1_Mul(nlohmann::json json) :
2910
            Operation(json["modifier"]),
2911
            curveType(json["curveType"]),
2912
            a(json["a_x"], json["a_y"]),
2913
            b(json["b"])
2914
0
        { }
2915
2916
88
        static size_t MaxOperations(void) { return 5; }
2917
        std::string Name(void) const override;
2918
        std::string ToString(void) const override;
2919
        nlohmann::json ToJSON(void) const override;
2920
0
        inline bool operator==(const BLS_G1_Mul& rhs) const {
2921
0
            return
2922
0
                (curveType == rhs.curveType) &&
2923
0
                (a == rhs.a) &&
2924
0
                (b == rhs.b) &&
2925
0
                (modifier == rhs.modifier);
2926
0
        }
2927
0
        void Serialize(Datasource& ds) const {
2928
0
            curveType.Serialize(ds);
2929
0
            a.Serialize(ds);
2930
0
            b.Serialize(ds);
2931
0
        }
2932
};
2933
2934
class BLS_G1_Neg : public Operation {
2935
    public:
2936
        const component::CurveType curveType;
2937
        const component::G1 a;
2938
2939
        BLS_G1_Neg(Datasource& ds, component::Modifier modifier) :
2940
            Operation(std::move(modifier)),
2941
            curveType(ds),
2942
            a(ds)
2943
93
        { }
2944
        BLS_G1_Neg(nlohmann::json json) :
2945
            Operation(json["modifier"]),
2946
            curveType(json["curveType"]),
2947
            a(json["a_x"], json["a_y"])
2948
0
        { }
2949
2950
85
        static size_t MaxOperations(void) { return 5; }
2951
        std::string Name(void) const override;
2952
        std::string ToString(void) const override;
2953
        nlohmann::json ToJSON(void) const override;
2954
0
        inline bool operator==(const BLS_G1_Neg& rhs) const {
2955
0
            return
2956
0
                (curveType == rhs.curveType) &&
2957
0
                (a == rhs.a) &&
2958
0
                (modifier == rhs.modifier);
2959
0
        }
2960
0
        void Serialize(Datasource& ds) const {
2961
0
            curveType.Serialize(ds);
2962
0
            a.Serialize(ds);
2963
0
        }
2964
};
2965
2966
class BLS_G2_Add : public Operation {
2967
    public:
2968
        const component::CurveType curveType;
2969
        const component::G2 a, b;
2970
2971
        BLS_G2_Add(Datasource& ds, component::Modifier modifier) :
2972
            Operation(std::move(modifier)),
2973
            curveType(ds),
2974
            a(ds),
2975
            b(ds)
2976
131
        { }
2977
        BLS_G2_Add(nlohmann::json json) :
2978
            Operation(json["modifier"]),
2979
            curveType(json["curveType"]),
2980
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"]),
2981
            b(json["b_v"], json["b_w"], json["b_x"], json["b_y"])
2982
0
        { }
2983
2984
119
        static size_t MaxOperations(void) { return 5; }
2985
        std::string Name(void) const override;
2986
        std::string ToString(void) const override;
2987
        nlohmann::json ToJSON(void) const override;
2988
0
        inline bool operator==(const BLS_G2_Add& rhs) const {
2989
0
            return
2990
0
                (curveType == rhs.curveType) &&
2991
0
                (a == rhs.a) &&
2992
0
                (b == rhs.b) &&
2993
0
                (modifier == rhs.modifier);
2994
0
        }
2995
0
        void Serialize(Datasource& ds) const {
2996
0
            curveType.Serialize(ds);
2997
0
            a.Serialize(ds);
2998
0
            b.Serialize(ds);
2999
0
        }
3000
};
3001
3002
class BLS_G2_IsEq : public Operation {
3003
    public:
3004
        const component::CurveType curveType;
3005
        const component::G2 a, b;
3006
3007
        BLS_G2_IsEq(Datasource& ds, component::Modifier modifier) :
3008
            Operation(std::move(modifier)),
3009
            curveType(ds),
3010
            a(ds),
3011
            b(ds)
3012
119
        { }
3013
        BLS_G2_IsEq(nlohmann::json json) :
3014
            Operation(json["modifier"]),
3015
            curveType(json["curveType"]),
3016
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"]),
3017
            b(json["b_v"], json["b_w"], json["b_x"], json["b_y"])
3018
0
        { }
3019
3020
107
        static size_t MaxOperations(void) { return 5; }
3021
        std::string Name(void) const override;
3022
        std::string ToString(void) const override;
3023
        nlohmann::json ToJSON(void) const override;
3024
0
        inline bool operator==(const BLS_G2_IsEq& rhs) const {
3025
0
            return
3026
0
                (curveType == rhs.curveType) &&
3027
0
                (a == rhs.a) &&
3028
0
                (b == rhs.b) &&
3029
0
                (modifier == rhs.modifier);
3030
0
        }
3031
0
        void Serialize(Datasource& ds) const {
3032
0
            curveType.Serialize(ds);
3033
0
            a.Serialize(ds);
3034
0
            b.Serialize(ds);
3035
0
        }
3036
};
3037
3038
class BLS_G2_Mul : public Operation {
3039
    public:
3040
        const component::CurveType curveType;
3041
        const component::G2 a;
3042
        const component::Bignum b;
3043
3044
        BLS_G2_Mul(Datasource& ds, component::Modifier modifier) :
3045
            Operation(std::move(modifier)),
3046
            curveType(ds),
3047
            a(ds),
3048
            b(ds)
3049
91
        { }
3050
        BLS_G2_Mul(nlohmann::json json) :
3051
            Operation(json["modifier"]),
3052
            curveType(json["curveType"]),
3053
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"]),
3054
            b(json["b"])
3055
0
        { }
3056
3057
85
        static size_t MaxOperations(void) { return 5; }
3058
        std::string Name(void) const override;
3059
        std::string ToString(void) const override;
3060
        nlohmann::json ToJSON(void) const override;
3061
0
        inline bool operator==(const BLS_G2_Mul& rhs) const {
3062
0
            return
3063
0
                (curveType == rhs.curveType) &&
3064
0
                (a == rhs.a) &&
3065
0
                (b == rhs.b) &&
3066
0
                (modifier == rhs.modifier);
3067
0
        }
3068
0
        void Serialize(Datasource& ds) const {
3069
0
            curveType.Serialize(ds);
3070
0
            a.Serialize(ds);
3071
0
            b.Serialize(ds);
3072
0
        }
3073
};
3074
3075
class BLS_G2_Neg : public Operation {
3076
    public:
3077
        const component::CurveType curveType;
3078
        const component::G2 a;
3079
3080
        BLS_G2_Neg(Datasource& ds, component::Modifier modifier) :
3081
            Operation(std::move(modifier)),
3082
            curveType(ds),
3083
            a(ds)
3084
107
        { }
3085
        BLS_G2_Neg(nlohmann::json json) :
3086
            Operation(json["modifier"]),
3087
            curveType(json["curveType"]),
3088
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"])
3089
0
        { }
3090
3091
98
        static size_t MaxOperations(void) { return 5; }
3092
        std::string Name(void) const override;
3093
        std::string ToString(void) const override;
3094
        nlohmann::json ToJSON(void) const override;
3095
0
        inline bool operator==(const BLS_G2_Neg& rhs) const {
3096
0
            return
3097
0
                (curveType == rhs.curveType) &&
3098
0
                (a == rhs.a) &&
3099
0
                (modifier == rhs.modifier);
3100
0
        }
3101
0
        void Serialize(Datasource& ds) const {
3102
0
            curveType.Serialize(ds);
3103
0
            a.Serialize(ds);
3104
0
        }
3105
};
3106
3107
class Misc : public Operation {
3108
    public:
3109
        const Type operation;
3110
3111
        Misc(Datasource& ds, component::Modifier modifier) :
3112
            Operation(std::move(modifier)),
3113
            operation(ds)
3114
64
        { }
3115
3116
        Misc(nlohmann::json json) :
3117
            Operation(json["modifier"]),
3118
            operation(json["operation"])
3119
0
        { }
3120
3121
60
        static size_t MaxOperations(void) { return 5; }
3122
        std::string Name(void) const override;
3123
        std::string ToString(void) const override;
3124
        nlohmann::json ToJSON(void) const override;
3125
0
        inline bool operator==(const Misc& rhs) const {
3126
0
            return
3127
0
                (operation == rhs.operation) &&
3128
0
                (modifier == rhs.modifier);
3129
0
        }
3130
0
        void Serialize(Datasource& ds) const {
3131
0
            operation.Serialize(ds);
3132
0
        }
3133
};
3134
3135
class SR25519_Verify : public Operation {
3136
    public:
3137
        const component::Cleartext cleartext;
3138
        const component::SR25519_Signature signature;
3139
3140
        SR25519_Verify(Datasource& ds, component::Modifier modifier) :
3141
            Operation(std::move(modifier)),
3142
            cleartext(ds),
3143
            signature(ds)
3144
110
        { }
3145
        SR25519_Verify(nlohmann::json json) :
3146
            Operation(json["modifier"]),
3147
            cleartext(json["cleartext"]),
3148
            signature(json["signature"])
3149
0
        { }
3150
3151
88
        static size_t MaxOperations(void) { return 5; }
3152
        std::string Name(void) const override;
3153
        std::string ToString(void) const override;
3154
        nlohmann::json ToJSON(void) const override;
3155
0
        inline bool operator==(const SR25519_Verify& rhs) const {
3156
0
            return
3157
0
                (cleartext == rhs.cleartext) &&
3158
0
                (signature == rhs.signature) &&
3159
0
                (modifier == rhs.modifier);
3160
0
        }
3161
0
        void Serialize(Datasource& ds) const {
3162
0
            cleartext.Serialize(ds);
3163
0
            signature.Serialize(ds);
3164
0
        }
3165
};
3166
3167
} /* namespace operation */
3168
} /* namespace cryptofuzz */