Coverage Report

Created: 2024-06-28 06:19

/src/cryptofuzz/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
17.5k
        { }
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
1.71k
        { }
43
44
        Digest(nlohmann::json json) :
45
            Operation(json["modifier"]),
46
            cleartext(json["cleartext"]),
47
            digestType(json["digestType"])
48
0
        { }
49
50
51
1.70k
        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
1.38k
        { }
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
1.36k
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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
0
        { }
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
0
        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 KDF_SRTP : public Operation {
829
    public:
830
        const component::Cleartext key;
831
        const component::Cleartext salt;
832
        const uint8_t kdr;
833
        const uint64_t index;
834
        const uint64_t key1Size;
835
        const uint64_t key2Size;
836
        const uint64_t key3Size;
837
838
        KDF_SRTP(Datasource& ds, component::Modifier modifier) :
839
            Operation(std::move(modifier)),
840
            key(ds),
841
            salt(ds),
842
            kdr(ds.Get<uint8_t>()),
843
            index(ds.Get<uint64_t>()),
844
            key1Size(ds.Get<uint64_t>() % (1024*1024)),
845
            key2Size(ds.Get<uint64_t>() % (1024*1024)),
846
            key3Size(ds.Get<uint64_t>() % (1024*1024))
847
0
        { }
848
        KDF_SRTP(nlohmann::json json) :
849
            Operation(json["modifier"]),
850
            key(json["key"]),
851
            salt(json["salt"]),
852
            kdr(json["kdr"].get<uint8_t>()),
853
            index(json["index"].get<uint64_t>()),
854
            key1Size(json["key1Size"].get<uint64_t>()),
855
            key2Size(json["key2Size"].get<uint64_t>()),
856
            key3Size(json["key3Size"].get<uint64_t>())
857
0
        { }
858
859
0
        static size_t MaxOperations(void) { return 20; }
860
        std::string Name(void) const override;
861
        std::string ToString(void) const override;
862
        nlohmann::json ToJSON(void) const override;
863
0
        inline bool operator==(const KDF_SRTP& rhs) const {
864
0
            return
865
0
                (key == rhs.key) &&
866
0
                (salt == rhs.salt) &&
867
0
                (kdr == rhs.kdr) &&
868
0
                (index == rhs.index) &&
869
0
                (key1Size == rhs.key1Size) &&
870
0
                (key2Size == rhs.key2Size) &&
871
0
                (key3Size == rhs.key3Size) &&
872
0
                (modifier == rhs.modifier);
873
0
        }
874
0
        void Serialize(Datasource& ds) const {
875
0
            key.Serialize(ds);
876
0
            salt.Serialize(ds);
877
0
            ds.Put<>(kdr);
878
0
            ds.Put<>(key1Size);
879
0
            ds.Put<>(key2Size);
880
0
            ds.Put<>(key3Size);
881
0
        }
882
};
883
884
class KDF_SRTCP : public Operation {
885
    public:
886
        const component::Cleartext key;
887
        const component::Cleartext salt;
888
        const uint8_t kdr;
889
        const uint32_t index;
890
        const uint64_t key1Size;
891
        const uint64_t key2Size;
892
        const uint64_t key3Size;
893
894
        KDF_SRTCP(Datasource& ds, component::Modifier modifier) :
895
            Operation(std::move(modifier)),
896
            key(ds),
897
            salt(ds),
898
            kdr(ds.Get<uint8_t>()),
899
            index(ds.Get<uint32_t>()),
900
            key1Size(ds.Get<uint64_t>() % (1024*1024)),
901
            key2Size(ds.Get<uint64_t>() % (1024*1024)),
902
            key3Size(ds.Get<uint64_t>() % (1024*1024))
903
0
        { }
904
        KDF_SRTCP(nlohmann::json json) :
905
            Operation(json["modifier"]),
906
            key(json["key"]),
907
            salt(json["salt"]),
908
            kdr(json["kdr"].get<uint8_t>()),
909
            index(json["index"].get<uint32_t>()),
910
            key1Size(json["key1Size"].get<uint64_t>()),
911
            key2Size(json["key2Size"].get<uint64_t>()),
912
            key3Size(json["key3Size"].get<uint64_t>())
913
0
        { }
914
915
0
        static size_t MaxOperations(void) { return 20; }
916
        std::string Name(void) const override;
917
        std::string ToString(void) const override;
918
        nlohmann::json ToJSON(void) const override;
919
0
        inline bool operator==(const KDF_SRTCP& rhs) const {
920
0
            return
921
0
                (key == rhs.key) &&
922
0
                (salt == rhs.salt) &&
923
0
                (kdr == rhs.kdr) &&
924
0
                (index == rhs.index) &&
925
0
                (key1Size == rhs.key1Size) &&
926
0
                (key2Size == rhs.key2Size) &&
927
0
                (key3Size == rhs.key3Size) &&
928
0
                (modifier == rhs.modifier);
929
0
        }
930
0
        void Serialize(Datasource& ds) const {
931
0
            key.Serialize(ds);
932
0
            salt.Serialize(ds);
933
0
            ds.Put<>(kdr);
934
0
            ds.Put<>(key1Size);
935
0
            ds.Put<>(key2Size);
936
0
            ds.Put<>(key3Size);
937
0
        }
938
};
939
940
class CMAC : public Operation {
941
    public:
942
        const component::Cleartext cleartext;
943
        const component::SymmetricCipher cipher;
944
945
        CMAC(Datasource& ds, component::Modifier modifier) :
946
            Operation(std::move(modifier)),
947
            cleartext(ds),
948
            cipher(ds)
949
0
        { }
950
        CMAC(nlohmann::json json) :
951
            Operation(json["modifier"]),
952
            cleartext(json["cleartext"]),
953
            cipher(json["cipher"])
954
0
        { }
955
956
0
        static size_t MaxOperations(void) { return 20; }
957
        std::string Name(void) const override;
958
        std::string ToString(void) const override;
959
        nlohmann::json ToJSON(void) const override;
960
0
        inline bool operator==(const CMAC& rhs) const {
961
0
            return
962
0
                (cleartext == rhs.cleartext) &&
963
0
                (cipher == rhs.cipher) &&
964
0
                (modifier == rhs.modifier);
965
0
        }
966
0
        void Serialize(Datasource& ds) const {
967
0
            cleartext.Serialize(ds);
968
0
            cipher.Serialize(ds);
969
0
        }
970
};
971
972
class ECC_PrivateToPublic : public Operation {
973
    public:
974
        const component::CurveType curveType;
975
        const component::ECC_PrivateKey priv;
976
977
        ECC_PrivateToPublic(Datasource& ds, component::Modifier modifier) :
978
            Operation(std::move(modifier)),
979
            curveType(ds),
980
            priv(ds)
981
634
        { }
982
        ECC_PrivateToPublic(nlohmann::json json) :
983
            Operation(json["modifier"]),
984
            curveType(json["curveType"]),
985
            priv(json["priv"])
986
0
        { }
987
988
614
        static size_t MaxOperations(void) { return 5; }
989
        std::string Name(void) const override;
990
        std::string ToString(void) const override;
991
        nlohmann::json ToJSON(void) const override;
992
0
        inline bool operator==(const ECC_PrivateToPublic& rhs) const {
993
0
            return
994
0
                (curveType == rhs.curveType) &&
995
0
                (priv == rhs.priv) &&
996
0
                (modifier == rhs.modifier);
997
0
        }
998
0
        void Serialize(Datasource& ds) const {
999
0
            curveType.Serialize(ds);
1000
0
            priv.Serialize(ds);
1001
0
        }
1002
};
1003
1004
class ECC_ValidatePubkey : public Operation {
1005
    public:
1006
        const component::CurveType curveType;
1007
        const component::ECC_PublicKey pub;
1008
1009
        ECC_ValidatePubkey(Datasource& ds, component::Modifier modifier) :
1010
            Operation(std::move(modifier)),
1011
            curveType(ds),
1012
            pub(ds)
1013
347
        { }
1014
        ECC_ValidatePubkey(
1015
                const component::CurveType curveType,
1016
                const component::ECC_PublicKey& pub,
1017
                component::Modifier& modifier);
1018
        ECC_ValidatePubkey(nlohmann::json json) :
1019
            Operation(json["modifier"]),
1020
            curveType(json["curveType"]),
1021
            pub(json["pub_x"], json["pub_y"])
1022
0
        { }
1023
1024
332
        static size_t MaxOperations(void) { return 5; }
1025
        std::string Name(void) const override;
1026
        std::string ToString(void) const override;
1027
        nlohmann::json ToJSON(void) const override;
1028
0
        inline bool operator==(const ECC_ValidatePubkey& rhs) const {
1029
0
            return
1030
0
                (curveType == rhs.curveType) &&
1031
0
                (pub == rhs.pub) &&
1032
0
                (modifier == rhs.modifier);
1033
0
        }
1034
0
        void Serialize(Datasource& ds) const {
1035
0
            curveType.Serialize(ds);
1036
0
            pub.Serialize(ds);
1037
0
        }
1038
};
1039
1040
class ECC_GenerateKeyPair : public Operation {
1041
    public:
1042
        const component::CurveType curveType;
1043
1044
        ECC_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
1045
            Operation(std::move(modifier)),
1046
            curveType(ds)
1047
0
        { }
1048
1049
        ECC_GenerateKeyPair(nlohmann::json json) :
1050
            Operation(json["modifier"]),
1051
            curveType(json["curveType"])
1052
0
        { }
1053
1054
0
        static size_t MaxOperations(void) { return 5; }
1055
        std::string Name(void) const override;
1056
        std::string ToString(void) const override;
1057
        nlohmann::json ToJSON(void) const override;
1058
0
        inline bool operator==(const ECC_GenerateKeyPair& rhs) const {
1059
0
            return
1060
0
                (curveType == rhs.curveType) &&
1061
0
                (modifier == rhs.modifier);
1062
0
        }
1063
0
        void Serialize(Datasource& ds) const {
1064
0
            curveType.Serialize(ds);
1065
0
        }
1066
};
1067
1068
class ECCSI_Sign : public Operation {
1069
    public:
1070
        const component::CurveType curveType;
1071
        const component::ECC_PrivateKey priv;
1072
        const component::Cleartext cleartext;
1073
        const component::Cleartext id;
1074
        const component::DigestType digestType;
1075
1076
        ECCSI_Sign(Datasource& ds, component::Modifier modifier) :
1077
            Operation(std::move(modifier)),
1078
            curveType(ds),
1079
            priv(ds),
1080
            cleartext(ds),
1081
            id(ds),
1082
            digestType(ds)
1083
0
        { }
1084
        ECCSI_Sign(nlohmann::json json) :
1085
            Operation(json["modifier"]),
1086
            curveType(json["curveType"]),
1087
            priv(json["priv"]),
1088
            cleartext(json["cleartext"]),
1089
            id(json["id"]),
1090
            digestType(json["digestType"])
1091
0
        { }
1092
1093
0
        static size_t MaxOperations(void) { return 5; }
1094
        std::string Name(void) const override;
1095
        std::string ToString(void) const override;
1096
        nlohmann::json ToJSON(void) const override;
1097
0
        inline bool operator==(const ECCSI_Sign& rhs) const {
1098
0
            return
1099
0
                (curveType == rhs.curveType) &&
1100
0
                (priv == rhs.priv) &&
1101
0
                (cleartext == rhs.cleartext) &&
1102
0
                (id == rhs.id) &&
1103
0
                (digestType == rhs.digestType ) &&
1104
0
                (modifier == rhs.modifier);
1105
0
        }
1106
0
        void Serialize(Datasource& ds) const {
1107
0
            curveType.Serialize(ds);
1108
0
            priv.Serialize(ds);
1109
0
            cleartext.Serialize(ds);
1110
0
            id.Serialize(ds);
1111
0
            digestType.Serialize(ds);
1112
0
        }
1113
};
1114
1115
class ECDSA_Sign : public Operation {
1116
    public:
1117
        const component::CurveType curveType;
1118
        const component::ECC_PrivateKey priv;
1119
        const component::Bignum nonce;
1120
        const component::Cleartext cleartext;
1121
        const uint8_t nonceSource;
1122
        const component::DigestType digestType;
1123
1124
        ECDSA_Sign(Datasource& ds, component::Modifier modifier) :
1125
            Operation(std::move(modifier)),
1126
            curveType(ds),
1127
            priv(ds),
1128
            nonce(ds),
1129
            cleartext(ds),
1130
            nonceSource(ds.Get<uint8_t>()),
1131
            digestType(ds)
1132
798
        { }
1133
        ECDSA_Sign(nlohmann::json json) :
1134
            Operation(json["modifier"]),
1135
            curveType(json["curveType"]),
1136
            priv(json["priv"]),
1137
            nonce(json["nonce"]),
1138
            cleartext(json["cleartext"]),
1139
            nonceSource(json["nonceSource"].get<uint8_t>()),
1140
            digestType(json["digestType"])
1141
0
        { }
1142
1143
788
        static size_t MaxOperations(void) { return 5; }
1144
        std::string Name(void) const override;
1145
        std::string ToString(void) const override;
1146
        nlohmann::json ToJSON(void) const override;
1147
0
        inline bool operator==(const ECDSA_Sign& rhs) const {
1148
0
            return
1149
0
                (curveType == rhs.curveType) &&
1150
0
                (priv == rhs.priv) &&
1151
0
                (nonce == rhs.nonce) &&
1152
0
                (cleartext == rhs.cleartext) &&
1153
0
                (nonceSource == rhs.nonceSource ) &&
1154
0
                (digestType == rhs.digestType ) &&
1155
0
                (modifier == rhs.modifier);
1156
0
        }
1157
0
        void Serialize(Datasource& ds) const {
1158
0
            curveType.Serialize(ds);
1159
0
            priv.Serialize(ds);
1160
0
            nonce.Serialize(ds);
1161
0
            cleartext.Serialize(ds);
1162
0
            ds.Put<>(nonceSource);
1163
0
            digestType.Serialize(ds);
1164
0
        }
1165
1.62k
        bool UseRandomNonce(void) const {
1166
1.62k
            return nonceSource == 0;
1167
1.62k
        }
1168
2.10k
        bool UseRFC6979Nonce(void) const {
1169
2.10k
            return nonceSource == 1;
1170
2.10k
        }
1171
2.14k
        bool UseSpecifiedNonce(void) const {
1172
2.14k
            return nonceSource == 2;
1173
2.14k
        }
1174
};
1175
1176
class ECGDSA_Sign : public Operation {
1177
    public:
1178
        const component::CurveType curveType;
1179
        const component::ECC_PrivateKey priv;
1180
        const component::Bignum nonce;
1181
        const component::Cleartext cleartext;
1182
        const uint8_t nonceSource;
1183
        const component::DigestType digestType;
1184
1185
        ECGDSA_Sign(Datasource& ds, component::Modifier modifier) :
1186
            Operation(std::move(modifier)),
1187
            curveType(ds),
1188
            priv(ds),
1189
            nonce(ds),
1190
            cleartext(ds),
1191
            nonceSource(ds.Get<uint8_t>()),
1192
            digestType(ds)
1193
252
        { }
1194
        ECGDSA_Sign(nlohmann::json json) :
1195
            Operation(json["modifier"]),
1196
            curveType(json["curveType"]),
1197
            priv(json["priv"]),
1198
            nonce(json["nonce"]),
1199
            cleartext(json["cleartext"]),
1200
            nonceSource(json["nonceSource"].get<uint8_t>()),
1201
            digestType(json["digestType"])
1202
0
        { }
1203
1204
245
        static size_t MaxOperations(void) { return 5; }
1205
        std::string Name(void) const override;
1206
        std::string ToString(void) const override;
1207
        nlohmann::json ToJSON(void) const override;
1208
0
        inline bool operator==(const ECGDSA_Sign& rhs) const {
1209
0
            return
1210
0
                (curveType == rhs.curveType) &&
1211
0
                (priv == rhs.priv) &&
1212
0
                (nonce == rhs.nonce) &&
1213
0
                (cleartext == rhs.cleartext) &&
1214
0
                (nonceSource == rhs.nonceSource ) &&
1215
0
                (digestType == rhs.digestType ) &&
1216
0
                (modifier == rhs.modifier);
1217
0
        }
1218
0
        void Serialize(Datasource& ds) const {
1219
0
            curveType.Serialize(ds);
1220
0
            priv.Serialize(ds);
1221
0
            nonce.Serialize(ds);
1222
0
            cleartext.Serialize(ds);
1223
0
            ds.Put<>(nonceSource);
1224
0
            digestType.Serialize(ds);
1225
0
        }
1226
405
        bool UseRandomNonce(void) const {
1227
405
            return nonceSource == 0;
1228
405
        }
1229
402
        bool UseRFC6979Nonce(void) const {
1230
402
            return nonceSource == 1;
1231
402
        }
1232
472
        bool UseSpecifiedNonce(void) const {
1233
472
            return nonceSource == 2;
1234
472
        }
1235
};
1236
1237
class ECRDSA_Sign : public Operation {
1238
    public:
1239
        const component::CurveType curveType;
1240
        const component::ECC_PrivateKey priv;
1241
        const component::Bignum nonce;
1242
        const component::Cleartext cleartext;
1243
        const uint8_t nonceSource;
1244
        const component::DigestType digestType;
1245
1246
        ECRDSA_Sign(Datasource& ds, component::Modifier modifier) :
1247
            Operation(std::move(modifier)),
1248
            curveType(ds),
1249
            priv(ds),
1250
            nonce(ds),
1251
            cleartext(ds),
1252
            nonceSource(ds.Get<uint8_t>()),
1253
            digestType(ds)
1254
209
        { }
1255
        ECRDSA_Sign(nlohmann::json json) :
1256
            Operation(json["modifier"]),
1257
            curveType(json["curveType"]),
1258
            priv(json["priv"]),
1259
            nonce(json["nonce"]),
1260
            cleartext(json["cleartext"]),
1261
            nonceSource(json["nonceSource"].get<uint8_t>()),
1262
            digestType(json["digestType"])
1263
0
        { }
1264
1265
199
        static size_t MaxOperations(void) { return 5; }
1266
        std::string Name(void) const override;
1267
        std::string ToString(void) const override;
1268
        nlohmann::json ToJSON(void) const override;
1269
0
        inline bool operator==(const ECRDSA_Sign& rhs) const {
1270
0
            return
1271
0
                (curveType == rhs.curveType) &&
1272
0
                (priv == rhs.priv) &&
1273
0
                (nonce == rhs.nonce) &&
1274
0
                (cleartext == rhs.cleartext) &&
1275
0
                (nonceSource == rhs.nonceSource ) &&
1276
0
                (digestType == rhs.digestType ) &&
1277
0
                (modifier == rhs.modifier);
1278
0
        }
1279
0
        void Serialize(Datasource& ds) const {
1280
0
            curveType.Serialize(ds);
1281
0
            priv.Serialize(ds);
1282
0
            nonce.Serialize(ds);
1283
0
            cleartext.Serialize(ds);
1284
0
            ds.Put<>(nonceSource);
1285
0
            digestType.Serialize(ds);
1286
0
        }
1287
154
        bool UseRandomNonce(void) const {
1288
154
            return nonceSource == 0;
1289
154
        }
1290
287
        bool UseRFC6979Nonce(void) const {
1291
287
            return nonceSource == 1;
1292
287
        }
1293
360
        bool UseSpecifiedNonce(void) const {
1294
360
            return nonceSource == 2;
1295
360
        }
1296
};
1297
1298
class Schnorr_Sign : public Operation {
1299
    public:
1300
        const component::CurveType curveType;
1301
        const component::ECC_PrivateKey priv;
1302
        const component::Bignum nonce;
1303
        const component::Cleartext cleartext;
1304
        const uint8_t nonceSource;
1305
        const component::DigestType digestType;
1306
1307
        Schnorr_Sign(Datasource& ds, component::Modifier modifier) :
1308
            Operation(std::move(modifier)),
1309
            curveType(ds),
1310
            priv(ds),
1311
            nonce(ds),
1312
            cleartext(ds),
1313
            nonceSource(ds.Get<uint8_t>()),
1314
            digestType(ds)
1315
0
        { }
1316
        Schnorr_Sign(nlohmann::json json) :
1317
            Operation(json["modifier"]),
1318
            curveType(json["curveType"]),
1319
            priv(json["priv"]),
1320
            nonce(json["nonce"]),
1321
            cleartext(json["cleartext"]),
1322
            nonceSource(json["nonceSource"].get<uint8_t>()),
1323
            digestType(json["digestType"])
1324
0
        { }
1325
1326
0
        static size_t MaxOperations(void) { return 5; }
1327
        std::string Name(void) const override;
1328
        std::string ToString(void) const override;
1329
        nlohmann::json ToJSON(void) const override;
1330
0
        inline bool operator==(const Schnorr_Sign& rhs) const {
1331
0
            return
1332
0
                (curveType == rhs.curveType) &&
1333
0
                (priv == rhs.priv) &&
1334
0
                (nonce == rhs.nonce) &&
1335
0
                (cleartext == rhs.cleartext) &&
1336
0
                (nonceSource == rhs.nonceSource ) &&
1337
0
                (digestType == rhs.digestType ) &&
1338
0
                (modifier == rhs.modifier);
1339
0
        }
1340
0
        void Serialize(Datasource& ds) const {
1341
0
            curveType.Serialize(ds);
1342
0
            priv.Serialize(ds);
1343
0
            nonce.Serialize(ds);
1344
0
            cleartext.Serialize(ds);
1345
0
            ds.Put<>(nonceSource);
1346
0
            digestType.Serialize(ds);
1347
0
        }
1348
0
        bool UseRandomNonce(void) const {
1349
0
            return nonceSource == 0;
1350
0
        }
1351
0
        bool UseBIP340Nonce(void) const {
1352
0
            return nonceSource == 1;
1353
0
        }
1354
0
        bool UseSpecifiedNonce(void) const {
1355
0
            return nonceSource == 2;
1356
0
        }
1357
};
1358
1359
class ECCSI_Verify : public Operation {
1360
    public:
1361
        const component::CurveType curveType;
1362
        const component::Cleartext cleartext;
1363
        const component::Cleartext id;
1364
        const component::ECCSI_Signature signature;
1365
        const component::DigestType digestType;
1366
1367
        ECCSI_Verify(Datasource& ds, component::Modifier modifier) :
1368
            Operation(std::move(modifier)),
1369
            curveType(ds),
1370
            cleartext(ds),
1371
            id(ds),
1372
            signature(ds),
1373
            digestType(ds)
1374
0
        { }
1375
        ECCSI_Verify(const ECCSI_Sign& opECCSI_Sign, const component::ECCSI_Signature signature, component::Modifier modifier);
1376
        ECCSI_Verify(nlohmann::json json) :
1377
            Operation(json["modifier"]),
1378
            curveType(json["curveType"]),
1379
            cleartext(json["cleartext"]),
1380
            id(json["id"]),
1381
            signature(json["signature"]),
1382
            digestType(json["digestType"])
1383
0
        { }
1384
1385
0
        static size_t MaxOperations(void) { return 5; }
1386
        std::string Name(void) const override;
1387
        std::string ToString(void) const override;
1388
        nlohmann::json ToJSON(void) const override;
1389
0
        inline bool operator==(const ECCSI_Verify& rhs) const {
1390
0
            return
1391
0
                (curveType == rhs.curveType) &&
1392
0
                (cleartext == rhs.cleartext) &&
1393
0
                (id == rhs.id) &&
1394
0
                (signature == rhs.signature) &&
1395
0
                (digestType == rhs.digestType) &&
1396
0
                (modifier == rhs.modifier);
1397
0
        }
1398
0
        void Serialize(Datasource& ds) const {
1399
0
            curveType.Serialize(ds);
1400
0
            cleartext.Serialize(ds);
1401
0
            id.Serialize(ds);
1402
0
            signature.Serialize(ds);
1403
0
            digestType.Serialize(ds);
1404
0
        }
1405
};
1406
1407
class ECDSA_Verify : public Operation {
1408
    public:
1409
        const component::CurveType curveType;
1410
        const component::Cleartext cleartext;
1411
        const component::ECDSA_Signature signature;
1412
        const component::DigestType digestType;
1413
1414
        ECDSA_Verify(Datasource& ds, component::Modifier modifier) :
1415
            Operation(std::move(modifier)),
1416
            curveType(ds),
1417
            cleartext(ds),
1418
            signature(ds),
1419
            digestType(ds)
1420
370
        { }
1421
        ECDSA_Verify(const ECDSA_Sign& opECDSA_Sign, const component::ECDSA_Signature signature, component::Modifier modifier);
1422
        ECDSA_Verify(nlohmann::json json) :
1423
            Operation(json["modifier"]),
1424
            curveType(json["curveType"]),
1425
            cleartext(json["cleartext"]),
1426
            signature(json["signature"]),
1427
            digestType(json["digestType"])
1428
0
        { }
1429
1430
364
        static size_t MaxOperations(void) { return 5; }
1431
        std::string Name(void) const override;
1432
        std::string ToString(void) const override;
1433
        nlohmann::json ToJSON(void) const override;
1434
0
        inline bool operator==(const ECDSA_Verify& rhs) const {
1435
0
            return
1436
0
                (curveType == rhs.curveType) &&
1437
0
                (cleartext == rhs.cleartext) &&
1438
0
                (signature == rhs.signature) &&
1439
0
                (digestType == rhs.digestType) &&
1440
0
                (modifier == rhs.modifier);
1441
0
        }
1442
0
        void Serialize(Datasource& ds) const {
1443
0
            curveType.Serialize(ds);
1444
0
            cleartext.Serialize(ds);
1445
0
            signature.Serialize(ds);
1446
0
            digestType.Serialize(ds);
1447
0
        }
1448
};
1449
1450
class ECGDSA_Verify : public Operation {
1451
    public:
1452
        const component::CurveType curveType;
1453
        const component::Cleartext cleartext;
1454
        const component::ECGDSA_Signature signature;
1455
        const component::DigestType digestType;
1456
1457
        ECGDSA_Verify(Datasource& ds, component::Modifier modifier) :
1458
            Operation(std::move(modifier)),
1459
            curveType(ds),
1460
            cleartext(ds),
1461
            signature(ds),
1462
            digestType(ds)
1463
263
        { }
1464
        ECGDSA_Verify(nlohmann::json json) :
1465
            Operation(json["modifier"]),
1466
            curveType(json["curveType"]),
1467
            cleartext(json["cleartext"]),
1468
            signature(json["signature"]),
1469
            digestType(json["digestType"])
1470
0
        { }
1471
1472
256
        static size_t MaxOperations(void) { return 5; }
1473
        std::string Name(void) const override;
1474
        std::string ToString(void) const override;
1475
        nlohmann::json ToJSON(void) const override;
1476
0
        inline bool operator==(const ECGDSA_Verify& rhs) const {
1477
0
            return
1478
0
                (curveType == rhs.curveType) &&
1479
0
                (cleartext == rhs.cleartext) &&
1480
0
                (signature == rhs.signature) &&
1481
0
                (digestType == rhs.digestType) &&
1482
0
                (modifier == rhs.modifier);
1483
0
        }
1484
0
        void Serialize(Datasource& ds) const {
1485
0
            curveType.Serialize(ds);
1486
0
            cleartext.Serialize(ds);
1487
0
            signature.Serialize(ds);
1488
0
            digestType.Serialize(ds);
1489
0
        }
1490
};
1491
1492
class ECRDSA_Verify : public Operation {
1493
    public:
1494
        const component::CurveType curveType;
1495
        const component::Cleartext cleartext;
1496
        const component::ECRDSA_Signature signature;
1497
        const component::DigestType digestType;
1498
1499
        ECRDSA_Verify(Datasource& ds, component::Modifier modifier) :
1500
            Operation(std::move(modifier)),
1501
            curveType(ds),
1502
            cleartext(ds),
1503
            signature(ds),
1504
            digestType(ds)
1505
201
        { }
1506
        ECRDSA_Verify(nlohmann::json json) :
1507
            Operation(json["modifier"]),
1508
            curveType(json["curveType"]),
1509
            cleartext(json["cleartext"]),
1510
            signature(json["signature"]),
1511
            digestType(json["digestType"])
1512
0
        { }
1513
1514
193
        static size_t MaxOperations(void) { return 5; }
1515
        std::string Name(void) const override;
1516
        std::string ToString(void) const override;
1517
        nlohmann::json ToJSON(void) const override;
1518
0
        inline bool operator==(const ECRDSA_Verify& rhs) const {
1519
0
            return
1520
0
                (curveType == rhs.curveType) &&
1521
0
                (cleartext == rhs.cleartext) &&
1522
0
                (signature == rhs.signature) &&
1523
0
                (digestType == rhs.digestType) &&
1524
0
                (modifier == rhs.modifier);
1525
0
        }
1526
0
        void Serialize(Datasource& ds) const {
1527
0
            curveType.Serialize(ds);
1528
0
            cleartext.Serialize(ds);
1529
0
            signature.Serialize(ds);
1530
0
            digestType.Serialize(ds);
1531
0
        }
1532
};
1533
1534
class ECDSA_Recover : public Operation {
1535
    public:
1536
        const component::CurveType curveType;
1537
        const component::Cleartext cleartext;
1538
        const component::BignumPair signature;
1539
        const component::DigestType digestType;
1540
        const uint8_t id;
1541
1542
        ECDSA_Recover(Datasource& ds, component::Modifier modifier) :
1543
            Operation(std::move(modifier)),
1544
            curveType(ds),
1545
            cleartext(ds),
1546
            signature(ds),
1547
            digestType(ds),
1548
            id(ds.Get<uint8_t>())
1549
0
        { }
1550
        ECDSA_Recover(nlohmann::json json) :
1551
            Operation(json["modifier"]),
1552
            curveType(json["curveType"]),
1553
            cleartext(json["cleartext"]),
1554
            signature(json["signature"]),
1555
            digestType(json["digestType"]),
1556
            id(json["id"].get<uint8_t>())
1557
0
        { }
1558
1559
0
        static size_t MaxOperations(void) { return 5; }
1560
        std::string Name(void) const override;
1561
        std::string ToString(void) const override;
1562
        nlohmann::json ToJSON(void) const override;
1563
0
        inline bool operator==(const ECDSA_Recover& rhs) const {
1564
0
            return
1565
0
                (curveType == rhs.curveType) &&
1566
0
                (cleartext == rhs.cleartext) &&
1567
0
                (signature == rhs.signature) &&
1568
0
                (digestType == rhs.digestType) &&
1569
0
                (id == rhs.id) &&
1570
0
                (modifier == rhs.modifier);
1571
0
        }
1572
0
        void Serialize(Datasource& ds) const {
1573
0
            curveType.Serialize(ds);
1574
0
            cleartext.Serialize(ds);
1575
0
            signature.Serialize(ds);
1576
0
            digestType.Serialize(ds);
1577
0
            ds.Put<>(id);
1578
0
        }
1579
};
1580
1581
class DSA_GenerateParameters : public Operation {
1582
    public:
1583
        DSA_GenerateParameters(Datasource& ds, component::Modifier modifier) :
1584
            Operation(std::move(modifier))
1585
0
        { (void)ds; }
1586
        DSA_GenerateParameters(nlohmann::json json) :
1587
            Operation(json["modifier"])
1588
0
        { }
1589
        DSA_GenerateParameters(component::Modifier modifier) :
1590
            Operation(std::move(modifier))
1591
0
        { }
1592
1593
0
        static size_t MaxOperations(void) { return 5; }
1594
        std::string Name(void) const override;
1595
        std::string ToString(void) const override;
1596
        nlohmann::json ToJSON(void) const override;
1597
0
        inline bool operator==(const DSA_GenerateParameters& rhs) const {
1598
0
            return
1599
0
                (modifier == rhs.modifier);
1600
0
        }
1601
0
        void Serialize(Datasource& ds) const {
1602
0
            (void)ds;
1603
0
        }
1604
};
1605
1606
class DSA_PrivateToPublic : public Operation {
1607
    public:
1608
        const component::Bignum g;
1609
        const component::Bignum p;
1610
        const component::Bignum priv;
1611
1612
        DSA_PrivateToPublic(Datasource& ds, component::Modifier modifier) :
1613
            Operation(std::move(modifier)),
1614
            g(ds),
1615
            p(ds),
1616
            priv(ds)
1617
0
        { }
1618
        DSA_PrivateToPublic(nlohmann::json json) :
1619
            Operation(json["modifier"]),
1620
            g(json["g"]),
1621
            p(json["p"]),
1622
            priv(json["priv"])
1623
0
        { }
1624
        DSA_PrivateToPublic(
1625
                component::Modifier modifier,
1626
                component::Bignum g,
1627
                component::Bignum p,
1628
                component::Bignum priv) :
1629
            Operation(std::move(modifier)),
1630
            g(g),
1631
            p(p),
1632
            priv(priv)
1633
0
        { }
1634
1635
0
        static size_t MaxOperations(void) { return 5; }
1636
        std::string Name(void) const override;
1637
        std::string ToString(void) const override;
1638
        nlohmann::json ToJSON(void) const override;
1639
0
        inline bool operator==(const DSA_PrivateToPublic& rhs) const {
1640
0
            return
1641
0
                (g == rhs.g) &&
1642
0
                (p == rhs.p) &&
1643
0
                (priv == rhs.priv) &&
1644
0
                (modifier == rhs.modifier);
1645
0
        }
1646
0
        void Serialize(Datasource& ds) const {
1647
0
            priv.Serialize(ds);
1648
0
        }
1649
};
1650
1651
class DSA_GenerateKeyPair : public Operation {
1652
    public:
1653
        const component::Bignum p;
1654
        const component::Bignum q;
1655
        const component::Bignum g;
1656
1657
        DSA_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
1658
            Operation(std::move(modifier)),
1659
            p(ds),
1660
            q(ds),
1661
            g(ds)
1662
0
        { }
1663
        DSA_GenerateKeyPair(nlohmann::json json) :
1664
            Operation(json["modifier"]),
1665
            p(json["p"]),
1666
            q(json["q"]),
1667
            g(json["g"])
1668
0
        { }
1669
        DSA_GenerateKeyPair(
1670
                component::Modifier modifier,
1671
                component::Bignum p,
1672
                component::Bignum q,
1673
                component::Bignum g) :
1674
            Operation(std::move(modifier)),
1675
            p(p),
1676
            q(q),
1677
            g(g)
1678
0
        { }
1679
1680
0
        static size_t MaxOperations(void) { return 5; }
1681
        std::string Name(void) const override;
1682
        std::string ToString(void) const override;
1683
        nlohmann::json ToJSON(void) const override;
1684
0
        inline bool operator==(const DSA_GenerateKeyPair& rhs) const {
1685
0
            return
1686
0
                (p == rhs.p) &&
1687
0
                (q == rhs.q) &&
1688
0
                (g == rhs.g) &&
1689
0
                (modifier == rhs.modifier);
1690
0
        }
1691
0
        void Serialize(Datasource& ds) const {
1692
0
            p.Serialize(ds);
1693
0
            q.Serialize(ds);
1694
0
            g.Serialize(ds);
1695
0
        }
1696
};
1697
1698
class DSA_Sign : public Operation {
1699
    public:
1700
        const component::DSA_Parameters parameters;
1701
        const component::Bignum priv;
1702
        const component::Cleartext cleartext;
1703
1704
        DSA_Sign(Datasource& ds, component::Modifier modifier) :
1705
            Operation(std::move(modifier)),
1706
            parameters(ds),
1707
            priv(ds),
1708
            cleartext(ds)
1709
0
        { }
1710
        DSA_Sign(nlohmann::json json) :
1711
            Operation(json["modifier"]),
1712
            parameters(json["parameters"]),
1713
            priv(json["priv"]),
1714
            cleartext(json["cleartext"])
1715
0
        { }
1716
        DSA_Sign(
1717
                component::Modifier modifier,
1718
                component::DSA_Parameters parameters,
1719
                component::Bignum priv,
1720
                component::Cleartext cleartext) :
1721
            Operation(std::move(modifier)),
1722
            parameters(parameters),
1723
            priv(priv),
1724
            cleartext(cleartext)
1725
0
        { }
1726
1727
0
        static size_t MaxOperations(void) { return 5; }
1728
        std::string Name(void) const override;
1729
        std::string ToString(void) const override;
1730
        nlohmann::json ToJSON(void) const override;
1731
0
        inline bool operator==(const DSA_Sign& rhs) const {
1732
0
            return
1733
0
                (parameters == rhs.parameters) &&
1734
0
                (priv == rhs.priv) &&
1735
0
                (cleartext == rhs.cleartext) &&
1736
0
                (modifier == rhs.modifier);
1737
0
        }
1738
0
        void Serialize(Datasource& ds) const {
1739
0
            parameters.Serialize(ds);
1740
0
            priv.Serialize(ds);
1741
0
            cleartext.Serialize(ds);
1742
0
        }
1743
};
1744
1745
class DSA_Verify : public Operation {
1746
    public:
1747
        const component::DSA_Parameters parameters;
1748
        const component::Bignum pub;
1749
        const component::BignumPair signature;
1750
        const component::Cleartext cleartext;
1751
1752
        DSA_Verify(Datasource& ds, component::Modifier modifier) :
1753
            Operation(std::move(modifier)),
1754
            parameters(ds),
1755
            pub(ds),
1756
            signature(ds),
1757
            cleartext(ds)
1758
0
        { }
1759
        DSA_Verify(nlohmann::json json) :
1760
            Operation(json["modifier"]),
1761
            parameters(json["parameters"]),
1762
            pub(json["pub"]),
1763
            signature(json["signature"]),
1764
            cleartext(json["cleartext"])
1765
0
        { }
1766
        DSA_Verify(
1767
                component::Modifier modifier,
1768
                component::DSA_Parameters parameters,
1769
                component::Bignum pub,
1770
                component::BignumPair signature,
1771
                component::Cleartext cleartext) :
1772
            Operation(std::move(modifier)),
1773
            parameters(parameters),
1774
            pub(pub),
1775
            signature(signature),
1776
            cleartext(cleartext)
1777
0
        { }
1778
1779
0
        static size_t MaxOperations(void) { return 5; }
1780
        std::string Name(void) const override;
1781
        std::string ToString(void) const override;
1782
        nlohmann::json ToJSON(void) const override;
1783
0
        inline bool operator==(const DSA_Verify& rhs) const {
1784
0
            return
1785
0
                (parameters == rhs.parameters) &&
1786
0
                (pub == rhs.pub) &&
1787
0
                (signature == rhs.signature) &&
1788
0
                (cleartext == rhs.cleartext) &&
1789
0
                (modifier == rhs.modifier);
1790
0
        }
1791
0
        void Serialize(Datasource& ds) const {
1792
0
            parameters.Serialize(ds);
1793
0
            pub.Serialize(ds);
1794
0
            signature.Serialize(ds);
1795
0
            cleartext.Serialize(ds);
1796
0
        }
1797
};
1798
1799
class Schnorr_Verify : public Operation {
1800
    public:
1801
        const component::CurveType curveType;
1802
        const component::Cleartext cleartext;
1803
        const component::ECDSA_Signature signature;
1804
        const component::DigestType digestType;
1805
1806
        Schnorr_Verify(Datasource& ds, component::Modifier modifier) :
1807
            Operation(std::move(modifier)),
1808
            curveType(ds),
1809
            cleartext(ds),
1810
            signature(ds),
1811
            digestType(ds)
1812
0
        { }
1813
        Schnorr_Verify(nlohmann::json json) :
1814
            Operation(json["modifier"]),
1815
            curveType(json["curveType"]),
1816
            cleartext(json["cleartext"]),
1817
            signature(json["signature"]),
1818
            digestType(json["digestType"])
1819
0
        { }
1820
1821
0
        static size_t MaxOperations(void) { return 5; }
1822
        std::string Name(void) const override;
1823
        std::string ToString(void) const override;
1824
        nlohmann::json ToJSON(void) const override;
1825
0
        inline bool operator==(const Schnorr_Verify& rhs) const {
1826
0
            return
1827
0
                (curveType == rhs.curveType) &&
1828
0
                (cleartext == rhs.cleartext) &&
1829
0
                (signature == rhs.signature) &&
1830
0
                (digestType == rhs.digestType) &&
1831
0
                (modifier == rhs.modifier);
1832
0
        }
1833
0
        void Serialize(Datasource& ds) const {
1834
0
            curveType.Serialize(ds);
1835
0
            cleartext.Serialize(ds);
1836
0
            signature.Serialize(ds);
1837
0
            digestType.Serialize(ds);
1838
0
        }
1839
};
1840
1841
class ECDH_Derive : public Operation {
1842
    public:
1843
        const component::CurveType curveType;
1844
        const component::ECC_PrivateKey priv;
1845
        const component::ECC_PublicKey pub;
1846
1847
        ECDH_Derive(Datasource& ds, component::Modifier modifier) :
1848
            Operation(std::move(modifier)),
1849
            curveType(ds),
1850
            priv(ds),
1851
            pub(ds)
1852
151
        { }
1853
        ECDH_Derive(nlohmann::json json) :
1854
            Operation(json["modifier"]),
1855
            curveType(json["curveType"]),
1856
            priv(json["priv"]),
1857
            pub(json["pub_x"], json["pub_y"])
1858
0
        { }
1859
        ECDH_Derive(
1860
                component::Modifier modifier,
1861
                component::CurveType curveType,
1862
                component::ECC_PrivateKey priv,
1863
                component::ECC_PublicKey pub) :
1864
            Operation(std::move(modifier)),
1865
            curveType(curveType),
1866
            priv(priv),
1867
            pub(pub)
1868
0
        { }
1869
1870
1871
141
        static size_t MaxOperations(void) { return 5; }
1872
        std::string Name(void) const override;
1873
        std::string ToString(void) const override;
1874
        nlohmann::json ToJSON(void) const override;
1875
0
        inline bool operator==(const ECDH_Derive& rhs) const {
1876
0
            return
1877
0
                (curveType == rhs.curveType) &&
1878
0
                (priv == rhs.priv) &&
1879
0
                (pub == rhs.pub) &&
1880
0
                (modifier == rhs.modifier);
1881
0
        }
1882
0
        void Serialize(Datasource& ds) const {
1883
0
            curveType.Serialize(ds);
1884
0
            priv.Serialize(ds);
1885
0
            pub.Serialize(ds);
1886
0
        }
1887
};
1888
1889
class ECIES_Encrypt : public Operation {
1890
    public:
1891
        const component::Cleartext cleartext;
1892
        const component::CurveType curveType;
1893
        const component::ECC_PrivateKey priv;
1894
        const component::ECC_PublicKey pub;
1895
        const component::SymmetricCipherType cipherType;
1896
        const std::optional<component::SymmetricIV> iv;
1897
        /* TODO kdf type */
1898
        /* TODO mac type */
1899
1900
        ECIES_Encrypt(Datasource& ds, component::Modifier modifier) :
1901
            Operation(std::move(modifier)),
1902
            cleartext(ds),
1903
            curveType(ds),
1904
            priv(ds),
1905
            pub(ds),
1906
            cipherType(ds),
1907
            iv(ds.Get<bool>() ? std::nullopt : std::make_optional<component::SymmetricIV>(ds))
1908
0
        { }
1909
        ECIES_Encrypt(nlohmann::json json) :
1910
            Operation(json["modifier"]),
1911
            cleartext(json["cleartext"]),
1912
            curveType(json["curveType"]),
1913
            priv(json["priv"]),
1914
            pub(json["pub_x"], json["pub_y"]),
1915
            cipherType(json["cipherType"]),
1916
            iv(
1917
                    json["iv_enabled"].get<bool>() ?
1918
                        std::optional<component::SymmetricIV>(json["iv"]) :
1919
                        std::optional<component::SymmetricIV>(std::nullopt)
1920
            )
1921
0
        { }
1922
1923
0
        static size_t MaxOperations(void) { return 5; }
1924
        std::string Name(void) const override;
1925
        std::string ToString(void) const override;
1926
        nlohmann::json ToJSON(void) const override;
1927
0
        inline bool operator==(const ECIES_Encrypt& rhs) const {
1928
0
            return
1929
0
                (cleartext == rhs.cleartext) &&
1930
0
                (curveType == rhs.curveType) &&
1931
0
                (priv == rhs.priv) &&
1932
0
                (pub == rhs.pub) &&
1933
0
                (cipherType == rhs.cipherType) &&
1934
0
                (iv == rhs.iv) &&
1935
0
                (modifier == rhs.modifier);
1936
0
        }
1937
0
        void Serialize(Datasource& ds) const {
1938
0
            cleartext.Serialize(ds);
1939
0
            curveType.Serialize(ds);
1940
0
            priv.Serialize(ds);
1941
0
            pub.Serialize(ds);
1942
0
            cipherType.Serialize(ds);
1943
0
            if ( iv == std::nullopt ) {
1944
0
                ds.Put<bool>(true);
1945
0
            } else {
1946
0
                ds.Put<bool>(false);
1947
0
                iv->Serialize(ds);
1948
0
            }
1949
0
        }
1950
};
1951
1952
class ECIES_Decrypt : public Operation {
1953
    public:
1954
        const Buffer ciphertext;
1955
        const component::CurveType curveType;
1956
        const component::ECC_PrivateKey priv;
1957
        const component::ECC_PublicKey pub;
1958
        const component::SymmetricCipherType cipherType;
1959
        const std::optional<component::SymmetricIV> iv;
1960
        /* TODO kdf type */
1961
        /* TODO mac type */
1962
1963
        ECIES_Decrypt(Datasource& ds, component::Modifier modifier) :
1964
            Operation(std::move(modifier)),
1965
            ciphertext(ds),
1966
            curveType(ds),
1967
            priv(ds),
1968
            pub(ds),
1969
            cipherType(ds),
1970
            iv(ds.Get<bool>() ? std::nullopt : std::make_optional<component::SymmetricIV>(ds))
1971
0
        { }
1972
        ECIES_Decrypt(nlohmann::json json) :
1973
            Operation(json["modifier"]),
1974
            ciphertext(json["ciphertext"]),
1975
            curveType(json["curveType"]),
1976
            priv(json["priv"]),
1977
            pub(json["pub_x"], json["pub_y"]),
1978
            cipherType(json["cipherType"]),
1979
            iv(
1980
                    json["iv_enabled"].get<bool>() ?
1981
                        std::optional<component::SymmetricIV>(json["iv"]) :
1982
                        std::optional<component::SymmetricIV>(std::nullopt)
1983
            )
1984
0
        { }
1985
1986
0
        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 ECIES_Decrypt& rhs) const {
1991
0
            return
1992
0
                (ciphertext == rhs.ciphertext) &&
1993
0
                (curveType == rhs.curveType) &&
1994
0
                (priv == rhs.priv) &&
1995
0
                (pub == rhs.pub) &&
1996
0
                (cipherType == rhs.cipherType) &&
1997
0
                (iv == rhs.iv) &&
1998
0
                (modifier == rhs.modifier);
1999
0
        }
2000
0
        void Serialize(Datasource& ds) const {
2001
0
            ciphertext.Serialize(ds);
2002
0
            curveType.Serialize(ds);
2003
0
            priv.Serialize(ds);
2004
0
            pub.Serialize(ds);
2005
0
            cipherType.Serialize(ds);
2006
0
            if ( iv == std::nullopt ) {
2007
0
                ds.Put<bool>(true);
2008
0
            } else {
2009
0
                ds.Put<bool>(false);
2010
0
                iv->Serialize(ds);
2011
0
            }
2012
0
        }
2013
};
2014
2015
class ECC_Point_Add : public Operation {
2016
    public:
2017
        const component::CurveType curveType;
2018
        const component::ECC_Point a, b;
2019
2020
        ECC_Point_Add(Datasource& ds, component::Modifier modifier) :
2021
            Operation(std::move(modifier)),
2022
            curveType(ds),
2023
            a(ds),
2024
            b(ds)
2025
394
        { }
2026
        ECC_Point_Add(nlohmann::json json) :
2027
            Operation(json["modifier"]),
2028
            curveType(json["curveType"]),
2029
            a(json["a_x"], json["a_y"]),
2030
            b(json["b_x"], json["b_y"])
2031
0
        { }
2032
2033
386
        static size_t MaxOperations(void) { return 5; }
2034
        std::string Name(void) const override;
2035
        std::string ToString(void) const override;
2036
        nlohmann::json ToJSON(void) const override;
2037
0
        inline bool operator==(const ECC_Point_Add& rhs) const {
2038
0
            return
2039
0
                (curveType == rhs.curveType) &&
2040
0
                (a == rhs.a) &&
2041
0
                (b == rhs.b) &&
2042
0
                (modifier == rhs.modifier);
2043
0
        }
2044
0
        void Serialize(Datasource& ds) const {
2045
0
            curveType.Serialize(ds);
2046
0
            a.Serialize(ds);
2047
0
            b.Serialize(ds);
2048
0
        }
2049
};
2050
2051
class ECC_Point_Sub : public Operation {
2052
    public:
2053
        const component::CurveType curveType;
2054
        const component::ECC_Point a, b;
2055
2056
        ECC_Point_Sub(Datasource& ds, component::Modifier modifier) :
2057
            Operation(std::move(modifier)),
2058
            curveType(ds),
2059
            a(ds),
2060
            b(ds)
2061
0
        { }
2062
        ECC_Point_Sub(nlohmann::json json) :
2063
            Operation(json["modifier"]),
2064
            curveType(json["curveType"]),
2065
            a(json["a_x"], json["a_y"]),
2066
            b(json["b_x"], json["b_y"])
2067
0
        { }
2068
2069
0
        static size_t MaxOperations(void) { return 5; }
2070
        std::string Name(void) const override;
2071
        std::string ToString(void) const override;
2072
        nlohmann::json ToJSON(void) const override;
2073
0
        inline bool operator==(const ECC_Point_Sub& rhs) const {
2074
0
            return
2075
0
                (curveType == rhs.curveType) &&
2076
0
                (a == rhs.a) &&
2077
0
                (b == rhs.b) &&
2078
0
                (modifier == rhs.modifier);
2079
0
        }
2080
0
        void Serialize(Datasource& ds) const {
2081
0
            curveType.Serialize(ds);
2082
0
            a.Serialize(ds);
2083
0
            b.Serialize(ds);
2084
0
        }
2085
};
2086
2087
class ECC_Point_Mul : public Operation {
2088
    public:
2089
        const component::CurveType curveType;
2090
        const component::ECC_Point a;
2091
        const component::Bignum b;
2092
2093
        ECC_Point_Mul(Datasource& ds, component::Modifier modifier) :
2094
            Operation(std::move(modifier)),
2095
            curveType(ds),
2096
            a(ds),
2097
            b(ds)
2098
633
        { }
2099
        ECC_Point_Mul(nlohmann::json json) :
2100
            Operation(json["modifier"]),
2101
            curveType(json["curveType"]),
2102
            a(json["a_x"], json["a_y"]),
2103
            b(json["b"])
2104
0
        { }
2105
2106
618
        static size_t MaxOperations(void) { return 5; }
2107
        std::string Name(void) const override;
2108
        std::string ToString(void) const override;
2109
        nlohmann::json ToJSON(void) const override;
2110
0
        inline bool operator==(const ECC_Point_Mul& rhs) const {
2111
0
            return
2112
0
                (curveType == rhs.curveType) &&
2113
0
                (a == rhs.a) &&
2114
0
                (b == rhs.b) &&
2115
0
                (modifier == rhs.modifier);
2116
0
        }
2117
0
        void Serialize(Datasource& ds) const {
2118
0
            curveType.Serialize(ds);
2119
0
            a.Serialize(ds);
2120
0
            b.Serialize(ds);
2121
0
        }
2122
};
2123
2124
class ECC_Point_Neg : public Operation {
2125
    public:
2126
        const component::CurveType curveType;
2127
        const component::ECC_Point a;
2128
2129
        ECC_Point_Neg(Datasource& ds, component::Modifier modifier) :
2130
            Operation(std::move(modifier)),
2131
            curveType(ds),
2132
            a(ds)
2133
225
        { }
2134
        ECC_Point_Neg(nlohmann::json json) :
2135
            Operation(json["modifier"]),
2136
            curveType(json["curveType"]),
2137
            a(json["a_x"], json["a_y"])
2138
0
        { }
2139
2140
218
        static size_t MaxOperations(void) { return 5; }
2141
        std::string Name(void) const override;
2142
        std::string ToString(void) const override;
2143
        nlohmann::json ToJSON(void) const override;
2144
0
        inline bool operator==(const ECC_Point_Neg& rhs) const {
2145
0
            return
2146
0
                (curveType == rhs.curveType) &&
2147
0
                (a == rhs.a) &&
2148
0
                (modifier == rhs.modifier);
2149
0
        }
2150
0
        void Serialize(Datasource& ds) const {
2151
0
            curveType.Serialize(ds);
2152
0
            a.Serialize(ds);
2153
0
        }
2154
};
2155
2156
class ECC_Point_Dbl : public Operation {
2157
    public:
2158
        const component::CurveType curveType;
2159
        const component::ECC_Point a;
2160
2161
        ECC_Point_Dbl(Datasource& ds, component::Modifier modifier) :
2162
            Operation(std::move(modifier)),
2163
            curveType(ds),
2164
            a(ds)
2165
433
        { }
2166
        ECC_Point_Dbl(nlohmann::json json) :
2167
            Operation(json["modifier"]),
2168
            curveType(json["curveType"]),
2169
            a(json["a_x"], json["a_y"])
2170
0
        { }
2171
2172
426
        static size_t MaxOperations(void) { return 5; }
2173
        std::string Name(void) const override;
2174
        std::string ToString(void) const override;
2175
        nlohmann::json ToJSON(void) const override;
2176
0
        inline bool operator==(const ECC_Point_Dbl& rhs) const {
2177
0
            return
2178
0
                (curveType == rhs.curveType) &&
2179
0
                (a == rhs.a) &&
2180
0
                (modifier == rhs.modifier);
2181
0
        }
2182
0
        void Serialize(Datasource& ds) const {
2183
0
            curveType.Serialize(ds);
2184
0
            a.Serialize(ds);
2185
0
        }
2186
};
2187
2188
class ECC_Point_Cmp : public Operation {
2189
    public:
2190
        const component::CurveType curveType;
2191
        const component::ECC_Point a, b;
2192
2193
        ECC_Point_Cmp(Datasource& ds, component::Modifier modifier) :
2194
            Operation(std::move(modifier)),
2195
            curveType(ds),
2196
            a(ds),
2197
            b(ds)
2198
0
        { }
2199
        ECC_Point_Cmp(nlohmann::json json) :
2200
            Operation(json["modifier"]),
2201
            curveType(json["curveType"]),
2202
            a(json["a_x"], json["a_y"]),
2203
            b(json["b_x"], json["b_y"])
2204
0
        { }
2205
2206
0
        static size_t MaxOperations(void) { return 5; }
2207
        std::string Name(void) const override;
2208
        std::string ToString(void) const override;
2209
        nlohmann::json ToJSON(void) const override;
2210
0
        inline bool operator==(const ECC_Point_Cmp& rhs) const {
2211
0
            return
2212
0
                (curveType == rhs.curveType) &&
2213
0
                (a == rhs.a) &&
2214
0
                (b == rhs.b) &&
2215
0
                (modifier == rhs.modifier);
2216
0
        }
2217
0
        void Serialize(Datasource& ds) const {
2218
0
            curveType.Serialize(ds);
2219
0
            a.Serialize(ds);
2220
0
            b.Serialize(ds);
2221
0
        }
2222
};
2223
2224
class DH_GenerateKeyPair : public Operation {
2225
    public:
2226
        const component::Bignum prime;
2227
        const component::Bignum base;
2228
2229
        DH_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
2230
            Operation(std::move(modifier)),
2231
            prime(ds),
2232
            base(ds)
2233
0
        { }
2234
        DH_GenerateKeyPair(nlohmann::json json) :
2235
            Operation(json["modifier"]),
2236
            prime(json["prime"]),
2237
            base(json["base"])
2238
0
        { }
2239
        DH_GenerateKeyPair(
2240
                component::Modifier modifier,
2241
                component::Bignum prime,
2242
                component::Bignum base) :
2243
            Operation(std::move(modifier)),
2244
            prime(prime),
2245
            base(base)
2246
0
        { }
2247
2248
0
        static size_t MaxOperations(void) { return 5; }
2249
        std::string Name(void) const override;
2250
        std::string ToString(void) const override;
2251
        nlohmann::json ToJSON(void) const override;
2252
0
        inline bool operator==(const DH_GenerateKeyPair& rhs) const {
2253
0
            return
2254
0
                (prime == rhs.prime) &&
2255
0
                (base  == rhs.base) &&
2256
0
                (modifier == rhs.modifier);
2257
0
        }
2258
0
        void Serialize(Datasource& ds) const {
2259
0
            prime.Serialize(ds);
2260
0
            base.Serialize(ds);
2261
0
        }
2262
};
2263
2264
class DH_Derive : public Operation {
2265
    public:
2266
        const component::Bignum prime;
2267
        const component::Bignum base;
2268
        const component::Bignum pub;
2269
        const component::Bignum priv;
2270
2271
        DH_Derive(Datasource& ds, component::Modifier modifier) :
2272
            Operation(std::move(modifier)),
2273
            prime(ds),
2274
            base(ds),
2275
            pub(ds),
2276
            priv(ds)
2277
0
        { }
2278
        DH_Derive(nlohmann::json json) :
2279
            Operation(json["modifier"]),
2280
            prime(json["prime"]),
2281
            base(json["base"]),
2282
            pub(json["pub"]),
2283
            priv(json["priv"])
2284
0
        { }
2285
        DH_Derive(
2286
                component::Modifier modifier,
2287
                component::Bignum prime,
2288
                component::Bignum base,
2289
                component::Bignum pub,
2290
                component::Bignum priv) :
2291
            Operation(std::move(modifier)),
2292
            prime(prime),
2293
            base(base),
2294
            pub(pub),
2295
            priv(priv)
2296
0
        { }
2297
2298
0
        static size_t MaxOperations(void) { return 5; }
2299
        std::string Name(void) const override;
2300
        std::string ToString(void) const override;
2301
        nlohmann::json ToJSON(void) const override;
2302
0
        inline bool operator==(const DH_Derive& rhs) const {
2303
0
            return
2304
0
                (prime == rhs.prime) &&
2305
0
                (base  == rhs.base) &&
2306
0
                (pub == rhs.pub) &&
2307
0
                (priv == rhs.priv) &&
2308
0
                (modifier == rhs.modifier);
2309
0
        }
2310
0
        void Serialize(Datasource& ds) const {
2311
0
            prime.Serialize(ds);
2312
0
            base.Serialize(ds);
2313
0
            pub.Serialize(ds);
2314
0
            priv.Serialize(ds);
2315
0
        }
2316
};
2317
2318
class BignumCalc : public Operation {
2319
    public:
2320
        const component::CalcOp calcOp;
2321
        const component::Bignum bn0;
2322
        const component::Bignum bn1;
2323
        const component::Bignum bn2;
2324
        const component::Bignum bn3;
2325
        std::optional<component::Bignum> modulo;
2326
2327
        BignumCalc(Datasource& ds, component::Modifier modifier) :
2328
            Operation(std::move(modifier)),
2329
            calcOp(ds),
2330
            bn0(ds),
2331
            bn1(ds),
2332
            bn2(ds),
2333
            bn3(ds)
2334
8.74k
        { }
2335
        BignumCalc(nlohmann::json json) :
2336
            Operation(json["modifier"]),
2337
            calcOp(json["calcOp"]),
2338
            bn0(json["bn1"]),
2339
            bn1(json["bn2"]),
2340
            bn2(json["bn3"]),
2341
            bn3(json["bn4"])
2342
0
        { }
2343
        BignumCalc(
2344
                component::Modifier modifier,
2345
                component::CurveType calcOp,
2346
                component::Bignum bn0,
2347
                component::Bignum bn1,
2348
                component::Bignum bn2,
2349
                component::Bignum bn3) :
2350
            Operation(std::move(modifier)),
2351
            calcOp(calcOp),
2352
            bn0(bn0),
2353
            bn1(bn1),
2354
            bn2(bn2),
2355
            bn3(bn3)
2356
0
        { }
2357
2358
2359
8.73k
        static size_t MaxOperations(void) { return 5; }
2360
        std::string Name(void) const override;
2361
        std::string ToString(void) const override;
2362
        nlohmann::json ToJSON(void) const override;
2363
0
        inline bool operator==(const BignumCalc& rhs) const {
2364
0
            return
2365
0
                (calcOp == rhs.calcOp) &&
2366
0
                (bn0 == rhs.bn0) &&
2367
0
                (bn1 == rhs.bn1) &&
2368
0
                (bn2 == rhs.bn2) &&
2369
0
                (bn3 == rhs.bn3) &&
2370
0
                (modifier == rhs.modifier);
2371
0
        }
2372
0
        void Serialize(Datasource& ds) const {
2373
0
            calcOp.Serialize(ds);
2374
0
            bn0.Serialize(ds);
2375
0
            bn1.Serialize(ds);
2376
0
            bn2.Serialize(ds);
2377
0
            bn3.Serialize(ds);
2378
0
        }
2379
        void SetModulo(component::Bignum& modulo);
2380
};
2381
2382
class BignumCalc_Fp2 : public Operation {
2383
    public:
2384
        const component::CalcOp calcOp;
2385
        const component::Fp2 bn0;
2386
        const component::Fp2 bn1;
2387
        const component::Fp2 bn2;
2388
        const component::Fp2 bn3;
2389
        std::optional<component::Fp2> modulo;
2390
2391
        BignumCalc_Fp2(Datasource& ds, component::Modifier modifier) :
2392
            Operation(std::move(modifier)),
2393
            calcOp(ds),
2394
            bn0(ds),
2395
            bn1(ds),
2396
            bn2(ds),
2397
            bn3(ds)
2398
0
        { }
2399
        BignumCalc_Fp2(nlohmann::json json) :
2400
            Operation(json["modifier"]),
2401
            calcOp(json["calcOp"]),
2402
            bn0(json["bn1"]),
2403
            bn1(json["bn2"]),
2404
            bn2(json["bn3"]),
2405
            bn3(json["bn4"])
2406
0
        { }
2407
        BignumCalc_Fp2(
2408
                component::Modifier modifier,
2409
                component::CurveType calcOp,
2410
                component::Fp2 bn0,
2411
                component::Fp2 bn1,
2412
                component::Fp2 bn2,
2413
                component::Fp2 bn3) :
2414
            Operation(std::move(modifier)),
2415
            calcOp(calcOp),
2416
            bn0(bn0),
2417
            bn1(bn1),
2418
            bn2(bn2),
2419
            bn3(bn3)
2420
0
        { }
2421
2422
2423
0
        static size_t MaxOperations(void) { return 5; }
2424
        std::string Name(void) const override;
2425
        std::string ToString(void) const override;
2426
        nlohmann::json ToJSON(void) const override;
2427
0
        inline bool operator==(const BignumCalc_Fp2& rhs) const {
2428
0
            return
2429
0
                (calcOp == rhs.calcOp) &&
2430
0
                (bn0 == rhs.bn0) &&
2431
0
                (bn1 == rhs.bn1) &&
2432
0
                (bn2 == rhs.bn2) &&
2433
0
                (bn3 == rhs.bn3) &&
2434
0
                (modifier == rhs.modifier);
2435
0
        }
2436
0
        void Serialize(Datasource& ds) const {
2437
0
            calcOp.Serialize(ds);
2438
0
            bn0.Serialize(ds);
2439
0
            bn1.Serialize(ds);
2440
0
            bn2.Serialize(ds);
2441
0
            bn3.Serialize(ds);
2442
0
        }
2443
        void SetModulo(component::Fp2& modulo);
2444
};
2445
2446
class BignumCalc_Fp12 : public Operation {
2447
    public:
2448
        const component::CalcOp calcOp;
2449
        const component::Fp12 bn0;
2450
        const component::Fp12 bn1;
2451
        const component::Fp12 bn2;
2452
        const component::Fp12 bn3;
2453
        std::optional<component::Fp12> modulo;
2454
2455
        BignumCalc_Fp12(Datasource& ds, component::Modifier modifier) :
2456
            Operation(std::move(modifier)),
2457
            calcOp(ds),
2458
            bn0(ds),
2459
            bn1(ds),
2460
            bn2(ds),
2461
            bn3(ds)
2462
0
        { }
2463
        BignumCalc_Fp12(nlohmann::json json) :
2464
            Operation(json["modifier"]),
2465
            calcOp(json["calcOp"]),
2466
            bn0(json["bn1"]),
2467
            bn1(json["bn2"]),
2468
            bn2(json["bn3"]),
2469
            bn3(json["bn4"])
2470
0
        { }
2471
        BignumCalc_Fp12(
2472
                component::Modifier modifier,
2473
                component::CurveType calcOp,
2474
                component::Fp12 bn0,
2475
                component::Fp12 bn1,
2476
                component::Fp12 bn2,
2477
                component::Fp12 bn3) :
2478
            Operation(std::move(modifier)),
2479
            calcOp(calcOp),
2480
            bn0(bn0),
2481
            bn1(bn1),
2482
            bn2(bn2),
2483
            bn3(bn3)
2484
0
        { }
2485
2486
2487
0
        static size_t MaxOperations(void) { return 5; }
2488
        std::string Name(void) const override;
2489
        std::string ToString(void) const override;
2490
        nlohmann::json ToJSON(void) const override;
2491
0
        inline bool operator==(const BignumCalc_Fp12& rhs) const {
2492
0
            return
2493
0
                (calcOp == rhs.calcOp) &&
2494
0
                (bn0 == rhs.bn0) &&
2495
0
                (bn1 == rhs.bn1) &&
2496
0
                (bn2 == rhs.bn2) &&
2497
0
                (bn3 == rhs.bn3) &&
2498
0
                (modifier == rhs.modifier);
2499
0
        }
2500
0
        void Serialize(Datasource& ds) const {
2501
0
            calcOp.Serialize(ds);
2502
0
            bn0.Serialize(ds);
2503
0
            bn1.Serialize(ds);
2504
0
            bn2.Serialize(ds);
2505
0
            bn3.Serialize(ds);
2506
0
        }
2507
        void SetModulo(component::Fp12& modulo);
2508
};
2509
2510
class BLS_PrivateToPublic : public Operation {
2511
    public:
2512
        const component::CurveType curveType;
2513
        const component::BLS_PrivateKey priv;
2514
2515
        BLS_PrivateToPublic(Datasource& ds, component::Modifier modifier) :
2516
            Operation(std::move(modifier)),
2517
            curveType(ds),
2518
            priv(ds)
2519
0
        { }
2520
        BLS_PrivateToPublic(nlohmann::json json) :
2521
            Operation(json["modifier"]),
2522
            curveType(json["curveType"]),
2523
            priv(json["priv"])
2524
0
        { }
2525
2526
0
        static size_t MaxOperations(void) { return 5; }
2527
        std::string Name(void) const override;
2528
        std::string ToString(void) const override;
2529
        nlohmann::json ToJSON(void) const override;
2530
0
        inline bool operator==(const BLS_PrivateToPublic& rhs) const {
2531
0
            return
2532
0
                (curveType == rhs.curveType) &&
2533
0
                (priv == rhs.priv) &&
2534
0
                (modifier == rhs.modifier);
2535
0
        }
2536
0
        void Serialize(Datasource& ds) const {
2537
0
            curveType.Serialize(ds);
2538
0
            priv.Serialize(ds);
2539
0
        }
2540
};
2541
2542
class BLS_PrivateToPublic_G2 : public Operation {
2543
    public:
2544
        const component::CurveType curveType;
2545
        const component::BLS_PrivateKey priv;
2546
2547
        BLS_PrivateToPublic_G2(Datasource& ds, component::Modifier modifier) :
2548
            Operation(std::move(modifier)),
2549
            curveType(ds),
2550
            priv(ds)
2551
0
        { }
2552
        BLS_PrivateToPublic_G2(nlohmann::json json) :
2553
            Operation(json["modifier"]),
2554
            curveType(json["curveType"]),
2555
            priv(json["priv"])
2556
0
        { }
2557
2558
0
        static size_t MaxOperations(void) { return 5; }
2559
        std::string Name(void) const override;
2560
        std::string ToString(void) const override;
2561
        nlohmann::json ToJSON(void) const override;
2562
0
        inline bool operator==(const BLS_PrivateToPublic_G2& rhs) const {
2563
0
            return
2564
0
                (curveType == rhs.curveType) &&
2565
0
                (priv == rhs.priv) &&
2566
0
                (modifier == rhs.modifier);
2567
0
        }
2568
0
        void Serialize(Datasource& ds) const {
2569
0
            curveType.Serialize(ds);
2570
0
            priv.Serialize(ds);
2571
0
        }
2572
};
2573
2574
class BLS_Sign : public Operation {
2575
    public:
2576
        const component::CurveType curveType;
2577
        const component::BLS_PrivateKey priv;
2578
        const bool hashOrPoint;
2579
        const component::G2 point;
2580
        const component::Cleartext cleartext;
2581
        const component::Cleartext dest;
2582
        const component::Cleartext aug;
2583
2584
        BLS_Sign(Datasource& ds, component::Modifier modifier) :
2585
            Operation(std::move(modifier)),
2586
            curveType(ds),
2587
            priv(ds),
2588
            hashOrPoint(ds.Get<bool>()),
2589
            point(ds),
2590
            cleartext(ds),
2591
            dest(ds),
2592
            aug(ds)
2593
0
        { }
2594
        BLS_Sign(nlohmann::json json) :
2595
            Operation(json["modifier"]),
2596
            curveType(json["curveType"]),
2597
            priv(json["priv"]),
2598
            hashOrPoint(json["hashOrPoint"]),
2599
            point(json["point_v"], json["point_w"], json["point_x"], json["point_y"]),
2600
            cleartext(json["cleartext"]),
2601
            dest(json["dest"]),
2602
            aug(json["aug"])
2603
0
        { }
2604
2605
0
        static size_t MaxOperations(void) { return 5; }
2606
        std::string Name(void) const override;
2607
        std::string ToString(void) const override;
2608
        nlohmann::json ToJSON(void) const override;
2609
0
        inline bool operator==(const BLS_Sign& rhs) const {
2610
0
            return
2611
0
                (curveType == rhs.curveType) &&
2612
0
                (priv == rhs.priv) &&
2613
0
                (hashOrPoint == rhs.hashOrPoint) &&
2614
0
                (point == rhs.point) &&
2615
0
                (cleartext == rhs.cleartext) &&
2616
0
                (dest == rhs.dest) &&
2617
0
                (aug == rhs.aug) &&
2618
0
                (modifier == rhs.modifier);
2619
0
        }
2620
0
        void Serialize(Datasource& ds) const {
2621
0
            curveType.Serialize(ds);
2622
0
            priv.Serialize(ds);
2623
0
            ds.Put<bool>(hashOrPoint);
2624
0
            point.Serialize(ds);
2625
0
            cleartext.Serialize(ds);
2626
0
            dest.Serialize(ds);
2627
0
            aug.Serialize(ds);
2628
0
        }
2629
};
2630
2631
class BLS_Verify : public Operation {
2632
    public:
2633
        const component::CurveType curveType;
2634
        const component::BLS_PublicKey pub;
2635
        const bool hashOrPoint;
2636
        const component::G2 point;
2637
        const component::Cleartext cleartext;
2638
        const component::Cleartext dest;
2639
        const component::G2 signature;
2640
2641
        BLS_Verify(Datasource& ds, component::Modifier modifier) :
2642
            Operation(std::move(modifier)),
2643
            curveType(ds),
2644
            pub(ds),
2645
            hashOrPoint(ds.Get<bool>()),
2646
            point(ds),
2647
            cleartext(ds),
2648
            dest(ds),
2649
            signature(ds)
2650
0
        { }
2651
        BLS_Verify(nlohmann::json json) :
2652
            Operation(json["modifier"]),
2653
            curveType(json["curveType"]),
2654
            pub(json["pub_x"], json["pub_y"]),
2655
            hashOrPoint(json["hashOrPoint"]),
2656
            point(json["point_v"], json["point_w"], json["point_x"], json["point_y"]),
2657
            cleartext(json["cleartext"]),
2658
            dest(json["dest"]),
2659
            signature(json["sig_v"], json["sig_w"], json["sig_x"], json["sig_y"])
2660
0
        { }
2661
2662
0
        static size_t MaxOperations(void) { return 5; }
2663
        std::string Name(void) const override;
2664
        std::string ToString(void) const override;
2665
        nlohmann::json ToJSON(void) const override;
2666
0
        inline bool operator==(const BLS_Verify& rhs) const {
2667
0
            return
2668
0
                (curveType == rhs.curveType) &&
2669
0
                (pub == rhs.pub) &&
2670
0
                (hashOrPoint == rhs.hashOrPoint) &&
2671
0
                (point == rhs.point) &&
2672
0
                (cleartext == rhs.cleartext) &&
2673
0
                (dest == rhs.dest) &&
2674
0
                (signature == rhs.signature) &&
2675
0
                (modifier == rhs.modifier);
2676
0
        }
2677
0
        void Serialize(Datasource& ds) const {
2678
0
            curveType.Serialize(ds);
2679
0
            pub.Serialize(ds);
2680
0
            ds.Put<bool>(hashOrPoint);
2681
0
            point.Serialize(ds);
2682
0
            cleartext.Serialize(ds);
2683
0
            dest.Serialize(ds);
2684
0
            signature.Serialize(ds);
2685
0
        }
2686
};
2687
2688
class BLS_BatchSign : public Operation {
2689
    public:
2690
        component::BLS_BatchSign_Vector bf;
2691
2692
        BLS_BatchSign(Datasource& ds, component::Modifier modifier) :
2693
            Operation(std::move(modifier)),
2694
            bf(ds)
2695
0
        { }
2696
        BLS_BatchSign(nlohmann::json json) :
2697
            Operation(json["modifier"]),
2698
            bf(json["bf"])
2699
0
        { }
2700
2701
0
        static size_t MaxOperations(void) { return 5; }
2702
        std::string Name(void) const override;
2703
        std::string ToString(void) const override;
2704
        nlohmann::json ToJSON(void) const override;
2705
0
        inline bool operator==(const BLS_BatchSign& rhs) const {
2706
0
            return
2707
0
                (bf == rhs.bf) &&
2708
0
                (modifier == rhs.modifier);
2709
0
        }
2710
0
        void Serialize(Datasource& ds) const {
2711
0
            bf.Serialize(ds);
2712
0
        }
2713
};
2714
2715
class BLS_BatchVerify : public Operation {
2716
    public:
2717
        component::BLS_BatchVerify_Vector bf;
2718
2719
        BLS_BatchVerify(Datasource& ds, component::Modifier modifier) :
2720
            Operation(std::move(modifier)),
2721
            bf(ds)
2722
0
        { }
2723
        BLS_BatchVerify(nlohmann::json json) :
2724
            Operation(json["modifier"]),
2725
            bf(json["bf"])
2726
0
        { }
2727
2728
0
        static size_t MaxOperations(void) { return 5; }
2729
        std::string Name(void) const override;
2730
        std::string ToString(void) const override;
2731
        nlohmann::json ToJSON(void) const override;
2732
0
        inline bool operator==(const BLS_BatchVerify& rhs) const {
2733
0
            return
2734
0
                (bf == rhs.bf) &&
2735
0
                (modifier == rhs.modifier);
2736
0
        }
2737
0
        void Serialize(Datasource& ds) const {
2738
0
            bf.Serialize(ds);
2739
0
        }
2740
};
2741
2742
class BLS_Aggregate_G1 : public Operation {
2743
    public:
2744
        const component::CurveType curveType;
2745
        component::BLS_G1_Vector points;
2746
2747
        BLS_Aggregate_G1(Datasource& ds, component::Modifier modifier) :
2748
            Operation(std::move(modifier)),
2749
            curveType(ds),
2750
            points(ds)
2751
0
        { }
2752
        BLS_Aggregate_G1(nlohmann::json json) :
2753
            Operation(json["modifier"]),
2754
            curveType(json["curveType"]),
2755
            points(json["points"])
2756
0
        { }
2757
2758
0
        static size_t MaxOperations(void) { return 5; }
2759
        std::string Name(void) const override;
2760
        std::string ToString(void) const override;
2761
        nlohmann::json ToJSON(void) const override;
2762
0
        inline bool operator==(const BLS_Aggregate_G1& rhs) const {
2763
0
            return
2764
0
                (curveType == rhs.curveType) &&
2765
0
                (points == rhs.points) &&
2766
0
                (modifier == rhs.modifier);
2767
0
        }
2768
0
        void Serialize(Datasource& ds) const {
2769
0
            curveType.Serialize(ds);
2770
0
            points.Serialize(ds);
2771
0
        }
2772
};
2773
2774
class BLS_Aggregate_G2 : public Operation {
2775
    public:
2776
        const component::CurveType curveType;
2777
        component::BLS_G2_Vector points;
2778
2779
        BLS_Aggregate_G2(Datasource& ds, component::Modifier modifier) :
2780
            Operation(std::move(modifier)),
2781
            curveType(ds),
2782
            points(ds)
2783
0
        { }
2784
        BLS_Aggregate_G2(nlohmann::json json) :
2785
            Operation(json["modifier"]),
2786
            curveType(json["curveType"]),
2787
            points(json["points"])
2788
0
        { }
2789
2790
0
        static size_t MaxOperations(void) { return 5; }
2791
        std::string Name(void) const override;
2792
        std::string ToString(void) const override;
2793
        nlohmann::json ToJSON(void) const override;
2794
0
        inline bool operator==(const BLS_Aggregate_G2& rhs) const {
2795
0
            return
2796
0
                (curveType == rhs.curveType) &&
2797
0
                (points == rhs.points) &&
2798
0
                (modifier == rhs.modifier);
2799
0
        }
2800
0
        void Serialize(Datasource& ds) const {
2801
0
            curveType.Serialize(ds);
2802
0
            points.Serialize(ds);
2803
0
        }
2804
};
2805
2806
class BLS_Pairing : public Operation {
2807
    public:
2808
        const component::CurveType curveType;
2809
        const component::G1 g1;
2810
        const component::G2 g2;
2811
2812
        BLS_Pairing(Datasource& ds, component::Modifier modifier) :
2813
            Operation(std::move(modifier)),
2814
            curveType(ds),
2815
            g1(ds),
2816
            g2(ds)
2817
0
        { }
2818
        BLS_Pairing(nlohmann::json json) :
2819
            Operation(json["modifier"]),
2820
            curveType(json["curveType"]),
2821
            g1(json["g1_x"], json["g1_y"]),
2822
            g2(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
2823
0
        { }
2824
2825
0
        static size_t MaxOperations(void) { return 5; }
2826
        std::string Name(void) const override;
2827
        std::string ToString(void) const override;
2828
        nlohmann::json ToJSON(void) const override;
2829
0
        inline bool operator==(const BLS_Pairing& rhs) const {
2830
0
            return
2831
0
                (curveType == rhs.curveType) &&
2832
0
                (g1 == rhs.g1) &&
2833
0
                (g2 == rhs.g2) &&
2834
0
                (modifier == rhs.modifier);
2835
0
        }
2836
0
        void Serialize(Datasource& ds) const {
2837
0
            curveType.Serialize(ds);
2838
0
            g1.Serialize(ds);
2839
0
            g2.Serialize(ds);
2840
0
        }
2841
};
2842
2843
class BLS_MillerLoop : public Operation {
2844
    public:
2845
        const component::CurveType curveType;
2846
        const component::G1 g1;
2847
        const component::G2 g2;
2848
2849
        BLS_MillerLoop(Datasource& ds, component::Modifier modifier) :
2850
            Operation(std::move(modifier)),
2851
            curveType(ds),
2852
            g1(ds),
2853
            g2(ds)
2854
0
        { }
2855
        BLS_MillerLoop(nlohmann::json json) :
2856
            Operation(json["modifier"]),
2857
            curveType(json["curveType"]),
2858
            g1(json["g1_x"], json["g1_y"]),
2859
            g2(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
2860
0
        { }
2861
2862
0
        static size_t MaxOperations(void) { return 5; }
2863
        std::string Name(void) const override;
2864
        std::string ToString(void) const override;
2865
        nlohmann::json ToJSON(void) const override;
2866
0
        inline bool operator==(const BLS_MillerLoop& rhs) const {
2867
0
            return
2868
0
                (curveType == rhs.curveType) &&
2869
0
                (g1 == rhs.g1) &&
2870
0
                (g2 == rhs.g2) &&
2871
0
                (modifier == rhs.modifier);
2872
0
        }
2873
0
        void Serialize(Datasource& ds) const {
2874
0
            curveType.Serialize(ds);
2875
0
            g1.Serialize(ds);
2876
0
            g2.Serialize(ds);
2877
0
        }
2878
};
2879
2880
class BLS_FinalExp : public Operation {
2881
    public:
2882
        const component::CurveType curveType;
2883
        const component::Fp12 fp12;
2884
2885
        BLS_FinalExp(Datasource& ds, component::Modifier modifier) :
2886
            Operation(std::move(modifier)),
2887
            curveType(ds),
2888
            fp12(ds)
2889
0
        { }
2890
        BLS_FinalExp(nlohmann::json json) :
2891
            Operation(json["modifier"]),
2892
            curveType(json["curveType"]),
2893
            fp12(json["fp12"])
2894
0
        { }
2895
2896
0
        static size_t MaxOperations(void) { return 5; }
2897
        std::string Name(void) const override;
2898
        std::string ToString(void) const override;
2899
        nlohmann::json ToJSON(void) const override;
2900
0
        inline bool operator==(const BLS_FinalExp& rhs) const {
2901
0
            return
2902
0
                (curveType == rhs.curveType) &&
2903
0
                (fp12 == rhs.fp12) &&
2904
0
                (modifier == rhs.modifier);
2905
0
        }
2906
0
        void Serialize(Datasource& ds) const {
2907
0
            curveType.Serialize(ds);
2908
0
            fp12.Serialize(ds);
2909
0
        }
2910
};
2911
2912
class BLS_HashToG1 : public Operation {
2913
    public:
2914
        const component::CurveType curveType;
2915
        const component::Cleartext cleartext;
2916
        const component::Cleartext dest;
2917
        const component::Cleartext aug;
2918
2919
        BLS_HashToG1(Datasource& ds, component::Modifier modifier) :
2920
            Operation(std::move(modifier)),
2921
            curveType(ds),
2922
            cleartext(ds),
2923
            dest(ds),
2924
            aug(ds)
2925
0
        { }
2926
        BLS_HashToG1(const component::CurveType curveType, const component::Cleartext cleartext, const component::Cleartext dest, const component::Cleartext aug, component::Modifier modifier) :
2927
            Operation(std::move(modifier)),
2928
            curveType(curveType),
2929
            cleartext(cleartext),
2930
            dest(dest),
2931
            aug(aug)
2932
0
        { }
2933
        BLS_HashToG1(nlohmann::json json) :
2934
            Operation(json["modifier"]),
2935
            curveType(json["curveType"]),
2936
            cleartext(json["cleartext"]),
2937
            dest(json["dest"]),
2938
            aug(json["aug"])
2939
0
        { }
2940
2941
0
        static size_t MaxOperations(void) { return 5; }
2942
        std::string Name(void) const override;
2943
        std::string ToString(void) const override;
2944
        nlohmann::json ToJSON(void) const override;
2945
0
        inline bool operator==(const BLS_HashToG1& rhs) const {
2946
0
            return
2947
0
                (curveType == rhs.curveType) &&
2948
0
                (cleartext == rhs.cleartext) &&
2949
0
                (dest == rhs.dest) &&
2950
0
                (aug == rhs.aug) &&
2951
0
                (modifier == rhs.modifier);
2952
0
        }
2953
0
        void Serialize(Datasource& ds) const {
2954
0
            curveType.Serialize(ds);
2955
0
            cleartext.Serialize(ds);
2956
0
            dest.Serialize(ds);
2957
0
            aug.Serialize(ds);
2958
0
        }
2959
};
2960
2961
class BLS_HashToG2 : public Operation {
2962
    public:
2963
        const component::CurveType curveType;
2964
        const component::Cleartext cleartext;
2965
        const component::Cleartext dest;
2966
        const component::Cleartext aug;
2967
2968
        BLS_HashToG2(Datasource& ds, component::Modifier modifier) :
2969
            Operation(std::move(modifier)),
2970
            curveType(ds),
2971
            cleartext(ds),
2972
            dest(ds),
2973
            aug(ds)
2974
0
        { }
2975
        BLS_HashToG2(const component::CurveType curveType, const component::Cleartext cleartext, const component::Cleartext dest, const component::Cleartext aug, component::Modifier modifier) :
2976
            Operation(std::move(modifier)),
2977
            curveType(curveType),
2978
            cleartext(cleartext),
2979
            dest(dest),
2980
            aug(aug)
2981
0
        { }
2982
        BLS_HashToG2(nlohmann::json json) :
2983
            Operation(json["modifier"]),
2984
            curveType(json["curveType"]),
2985
            cleartext(json["cleartext"]),
2986
            dest(json["dest"]),
2987
            aug(json["aug"])
2988
0
        { }
2989
2990
0
        static size_t MaxOperations(void) { return 5; }
2991
        std::string Name(void) const override;
2992
        std::string ToString(void) const override;
2993
        nlohmann::json ToJSON(void) const override;
2994
0
        inline bool operator==(const BLS_HashToG2& rhs) const {
2995
0
            return
2996
0
                (curveType == rhs.curveType) &&
2997
0
                (cleartext == rhs.cleartext) &&
2998
0
                (dest == rhs.dest) &&
2999
0
                (aug == rhs.aug) &&
3000
0
                (modifier == rhs.modifier);
3001
0
        }
3002
0
        void Serialize(Datasource& ds) const {
3003
0
            curveType.Serialize(ds);
3004
0
            cleartext.Serialize(ds);
3005
0
            dest.Serialize(ds);
3006
0
            aug.Serialize(ds);
3007
0
        }
3008
};
3009
3010
class BLS_MapToG1 : public Operation {
3011
    public:
3012
        const component::CurveType curveType;
3013
        const component::Bignum u;
3014
        const component::Bignum v;
3015
3016
        BLS_MapToG1(Datasource& ds, component::Modifier modifier) :
3017
            Operation(std::move(modifier)),
3018
            curveType(ds),
3019
            u(ds),
3020
            v(ds)
3021
0
        { }
3022
        BLS_MapToG1(const component::CurveType curveType, const component::Bignum u, const component::Bignum v, component::Modifier modifier) :
3023
            Operation(std::move(modifier)),
3024
            curveType(curveType),
3025
            u(u),
3026
            v(v)
3027
0
        { }
3028
        BLS_MapToG1(nlohmann::json json) :
3029
            Operation(json["modifier"]),
3030
            curveType(json["curveType"]),
3031
            u(json["u"]),
3032
            v(json["v"])
3033
0
        { }
3034
3035
0
        static size_t MaxOperations(void) { return 5; }
3036
        std::string Name(void) const override;
3037
        std::string ToString(void) const override;
3038
        nlohmann::json ToJSON(void) const override;
3039
0
        inline bool operator==(const BLS_MapToG1& rhs) const {
3040
0
            return
3041
0
                (curveType == rhs.curveType) &&
3042
0
                (u == rhs.u) &&
3043
0
                (v == rhs.v) &&
3044
0
                (modifier == rhs.modifier);
3045
0
        }
3046
0
        void Serialize(Datasource& ds) const {
3047
0
            curveType.Serialize(ds);
3048
0
            u.Serialize(ds);
3049
0
            v.Serialize(ds);
3050
0
        }
3051
};
3052
3053
class BLS_MapToG2 : public Operation {
3054
    public:
3055
        const component::CurveType curveType;
3056
        const component::Fp2 u;
3057
        const component::Fp2 v;
3058
3059
        BLS_MapToG2(Datasource& ds, component::Modifier modifier) :
3060
            Operation(std::move(modifier)),
3061
            curveType(ds),
3062
            u(ds),
3063
            v(ds)
3064
0
        { }
3065
        BLS_MapToG2(const component::CurveType curveType, const component::Fp2 u, const component::Fp2 v, component::Modifier modifier) :
3066
            Operation(std::move(modifier)),
3067
            curveType(curveType),
3068
            u(u),
3069
            v(v)
3070
0
        { }
3071
        BLS_MapToG2(nlohmann::json json) :
3072
            Operation(json["modifier"]),
3073
            curveType(json["curveType"]),
3074
            u(json["u"]),
3075
            v(json["v"])
3076
0
        { }
3077
3078
0
        static size_t MaxOperations(void) { return 5; }
3079
        std::string Name(void) const override;
3080
        std::string ToString(void) const override;
3081
        nlohmann::json ToJSON(void) const override;
3082
0
        inline bool operator==(const BLS_MapToG2& rhs) const {
3083
0
            return
3084
0
                (curveType == rhs.curveType) &&
3085
0
                (u == rhs.u) &&
3086
0
                (v == rhs.v) &&
3087
0
                (modifier == rhs.modifier);
3088
0
        }
3089
0
        void Serialize(Datasource& ds) const {
3090
0
            curveType.Serialize(ds);
3091
0
            u.Serialize(ds);
3092
0
            v.Serialize(ds);
3093
0
        }
3094
};
3095
3096
class BLS_IsG1OnCurve : public Operation {
3097
    public:
3098
        const component::CurveType curveType;
3099
        const component::G1 g1;
3100
3101
        BLS_IsG1OnCurve(Datasource& ds, component::Modifier modifier) :
3102
            Operation(std::move(modifier)),
3103
            curveType(ds),
3104
            g1(ds)
3105
0
        { }
3106
        BLS_IsG1OnCurve(nlohmann::json json) :
3107
            Operation(json["modifier"]),
3108
            curveType(json["curveType"]),
3109
            g1(json["g1_x"], json["g1_y"])
3110
0
        { }
3111
3112
0
        static size_t MaxOperations(void) { return 5; }
3113
        std::string Name(void) const override;
3114
        std::string ToString(void) const override;
3115
        nlohmann::json ToJSON(void) const override;
3116
0
        inline bool operator==(const BLS_IsG1OnCurve& rhs) const {
3117
0
            return
3118
0
                (curveType == rhs.curveType) &&
3119
0
                (g1 == rhs.g1) &&
3120
0
                (modifier == rhs.modifier);
3121
0
        }
3122
0
        void Serialize(Datasource& ds) const {
3123
0
            curveType.Serialize(ds);
3124
0
            g1.Serialize(ds);
3125
0
        }
3126
};
3127
3128
class BLS_IsG2OnCurve : public Operation {
3129
    public:
3130
        const component::CurveType curveType;
3131
        const component::G2 g2;
3132
3133
        BLS_IsG2OnCurve(Datasource& ds, component::Modifier modifier) :
3134
            Operation(std::move(modifier)),
3135
            curveType(ds),
3136
            g2(ds)
3137
0
        { }
3138
        BLS_IsG2OnCurve(nlohmann::json json) :
3139
            Operation(json["modifier"]),
3140
            curveType(json["curveType"]),
3141
            g2(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
3142
0
        { }
3143
3144
0
        static size_t MaxOperations(void) { return 5; }
3145
        std::string Name(void) const override;
3146
        std::string ToString(void) const override;
3147
        nlohmann::json ToJSON(void) const override;
3148
0
        inline bool operator==(const BLS_IsG2OnCurve& rhs) const {
3149
0
            return
3150
0
                (curveType == rhs.curveType) &&
3151
0
                (g2 == rhs.g2) &&
3152
0
                (modifier == rhs.modifier);
3153
0
        }
3154
0
        void Serialize(Datasource& ds) const {
3155
0
            curveType.Serialize(ds);
3156
0
            g2.Serialize(ds);
3157
0
        }
3158
};
3159
3160
class BLS_GenerateKeyPair : public Operation {
3161
    public:
3162
        const component::CurveType curveType;
3163
        const component::Cleartext ikm;
3164
        const component::Cleartext info;
3165
3166
        BLS_GenerateKeyPair(Datasource& ds, component::Modifier modifier) :
3167
            Operation(std::move(modifier)),
3168
            curveType(ds),
3169
            ikm(ds),
3170
            info(ds)
3171
0
        { }
3172
3173
        BLS_GenerateKeyPair(nlohmann::json json) :
3174
            Operation(json["modifier"]),
3175
            curveType(json["curveType"]),
3176
            ikm(json["ikm"]),
3177
            info(json["info"])
3178
0
        { }
3179
3180
0
        static size_t MaxOperations(void) { return 5; }
3181
        std::string Name(void) const override;
3182
        std::string ToString(void) const override;
3183
        nlohmann::json ToJSON(void) const override;
3184
0
        inline bool operator==(const BLS_GenerateKeyPair& rhs) const {
3185
0
            return
3186
0
                (curveType == rhs.curveType) &&
3187
0
                (ikm == rhs.ikm) &&
3188
0
                (info == rhs.info) &&
3189
0
                (modifier == rhs.modifier);
3190
0
        }
3191
0
        void Serialize(Datasource& ds) const {
3192
0
            curveType.Serialize(ds);
3193
0
            ikm.Serialize(ds);
3194
0
            info.Serialize(ds);
3195
0
        }
3196
};
3197
3198
class BLS_Decompress_G1 : public Operation {
3199
    public:
3200
        const component::CurveType curveType;
3201
        const component::Bignum compressed;
3202
3203
        BLS_Decompress_G1(Datasource& ds, component::Modifier modifier) :
3204
            Operation(std::move(modifier)),
3205
            curveType(ds),
3206
            compressed(ds)
3207
0
        { }
3208
        BLS_Decompress_G1(nlohmann::json json) :
3209
            Operation(json["modifier"]),
3210
            curveType(json["curveType"]),
3211
            compressed(json["compressed"])
3212
0
        { }
3213
3214
0
        static size_t MaxOperations(void) { return 5; }
3215
        std::string Name(void) const override;
3216
        std::string ToString(void) const override;
3217
        nlohmann::json ToJSON(void) const override;
3218
0
        inline bool operator==(const BLS_Decompress_G1& rhs) const {
3219
0
            return
3220
0
                (curveType == rhs.curveType) &&
3221
0
                (compressed == rhs.compressed) &&
3222
0
                (modifier == rhs.modifier);
3223
0
        }
3224
0
        void Serialize(Datasource& ds) const {
3225
0
            curveType.Serialize(ds);
3226
0
            compressed.Serialize(ds);
3227
0
        }
3228
};
3229
3230
class BLS_Compress_G1 : public Operation {
3231
    public:
3232
        const component::CurveType curveType;
3233
        const component::G1 uncompressed;
3234
3235
        BLS_Compress_G1(Datasource& ds, component::Modifier modifier) :
3236
            Operation(std::move(modifier)),
3237
            curveType(ds),
3238
            uncompressed(ds)
3239
0
        { }
3240
        BLS_Compress_G1(nlohmann::json json) :
3241
            Operation(json["modifier"]),
3242
            curveType(json["curveType"]),
3243
            uncompressed(json["g1_x"], json["g1_y"])
3244
0
        { }
3245
3246
0
        static size_t MaxOperations(void) { return 5; }
3247
        std::string Name(void) const override;
3248
        std::string ToString(void) const override;
3249
        nlohmann::json ToJSON(void) const override;
3250
0
        inline bool operator==(const BLS_Compress_G1& rhs) const {
3251
0
            return
3252
0
                (curveType == rhs.curveType) &&
3253
0
                (uncompressed == rhs.uncompressed) &&
3254
0
                (modifier == rhs.modifier);
3255
0
        }
3256
0
        void Serialize(Datasource& ds) const {
3257
0
            curveType.Serialize(ds);
3258
0
            uncompressed.Serialize(ds);
3259
0
        }
3260
};
3261
3262
class BLS_Decompress_G2 : public Operation {
3263
    public:
3264
        const component::CurveType curveType;
3265
        const component::G1 compressed;
3266
3267
        BLS_Decompress_G2(Datasource& ds, component::Modifier modifier) :
3268
            Operation(std::move(modifier)),
3269
            curveType(ds),
3270
            compressed(ds)
3271
0
        { }
3272
        BLS_Decompress_G2(nlohmann::json json) :
3273
            Operation(json["modifier"]),
3274
            curveType(json["curveType"]),
3275
            compressed(json["g1_x"], json["g1_y"])
3276
0
        { }
3277
3278
0
        static size_t MaxOperations(void) { return 5; }
3279
        std::string Name(void) const override;
3280
        std::string ToString(void) const override;
3281
        nlohmann::json ToJSON(void) const override;
3282
0
        inline bool operator==(const BLS_Decompress_G2& rhs) const {
3283
0
            return
3284
0
                (curveType == rhs.curveType) &&
3285
0
                (compressed == rhs.compressed) &&
3286
0
                (modifier == rhs.modifier);
3287
0
        }
3288
0
        void Serialize(Datasource& ds) const {
3289
0
            curveType.Serialize(ds);
3290
0
            compressed.Serialize(ds);
3291
0
        }
3292
};
3293
3294
class BLS_Compress_G2 : public Operation {
3295
    public:
3296
        const component::CurveType curveType;
3297
        const component::G2 uncompressed;
3298
3299
        BLS_Compress_G2(Datasource& ds, component::Modifier modifier) :
3300
            Operation(std::move(modifier)),
3301
            curveType(ds),
3302
            uncompressed(ds)
3303
0
        { }
3304
        BLS_Compress_G2(nlohmann::json json) :
3305
            Operation(json["modifier"]),
3306
            curveType(json["curveType"]),
3307
            uncompressed(json["g2_v"], json["g2_w"], json["g2_x"], json["g2_y"])
3308
0
        { }
3309
3310
0
        static size_t MaxOperations(void) { return 5; }
3311
        std::string Name(void) const override;
3312
        std::string ToString(void) const override;
3313
        nlohmann::json ToJSON(void) const override;
3314
0
        inline bool operator==(const BLS_Compress_G2& rhs) const {
3315
0
            return
3316
0
                (curveType == rhs.curveType) &&
3317
0
                (uncompressed == rhs.uncompressed) &&
3318
0
                (modifier == rhs.modifier);
3319
0
        }
3320
0
        void Serialize(Datasource& ds) const {
3321
0
            curveType.Serialize(ds);
3322
0
            uncompressed.Serialize(ds);
3323
0
        }
3324
};
3325
3326
class BLS_G1_Add : public Operation {
3327
    public:
3328
        const component::CurveType curveType;
3329
        const component::G1 a, b;
3330
3331
        BLS_G1_Add(Datasource& ds, component::Modifier modifier) :
3332
            Operation(std::move(modifier)),
3333
            curveType(ds),
3334
            a(ds),
3335
            b(ds)
3336
0
        { }
3337
        BLS_G1_Add(nlohmann::json json) :
3338
            Operation(json["modifier"]),
3339
            curveType(json["curveType"]),
3340
            a(json["a_x"], json["a_y"]),
3341
            b(json["b_x"], json["b_y"])
3342
0
        { }
3343
3344
0
        static size_t MaxOperations(void) { return 5; }
3345
        std::string Name(void) const override;
3346
        std::string ToString(void) const override;
3347
        nlohmann::json ToJSON(void) const override;
3348
0
        inline bool operator==(const BLS_G1_Add& rhs) const {
3349
0
            return
3350
0
                (curveType == rhs.curveType) &&
3351
0
                (a == rhs.a) &&
3352
0
                (b == rhs.b) &&
3353
0
                (modifier == rhs.modifier);
3354
0
        }
3355
0
        void Serialize(Datasource& ds) const {
3356
0
            curveType.Serialize(ds);
3357
0
            a.Serialize(ds);
3358
0
            b.Serialize(ds);
3359
0
        }
3360
};
3361
3362
class BLS_G1_IsEq : public Operation {
3363
    public:
3364
        const component::CurveType curveType;
3365
        const component::G1 a, b;
3366
3367
        BLS_G1_IsEq(Datasource& ds, component::Modifier modifier) :
3368
            Operation(std::move(modifier)),
3369
            curveType(ds),
3370
            a(ds),
3371
            b(ds)
3372
0
        { }
3373
        BLS_G1_IsEq(nlohmann::json json) :
3374
            Operation(json["modifier"]),
3375
            curveType(json["curveType"]),
3376
            a(json["a_x"], json["a_y"]),
3377
            b(json["b_x"], json["b_y"])
3378
0
        { }
3379
3380
0
        static size_t MaxOperations(void) { return 5; }
3381
        std::string Name(void) const override;
3382
        std::string ToString(void) const override;
3383
        nlohmann::json ToJSON(void) const override;
3384
0
        inline bool operator==(const BLS_G1_IsEq& rhs) const {
3385
0
            return
3386
0
                (curveType == rhs.curveType) &&
3387
0
                (a == rhs.a) &&
3388
0
                (b == rhs.b) &&
3389
0
                (modifier == rhs.modifier);
3390
0
        }
3391
0
        void Serialize(Datasource& ds) const {
3392
0
            curveType.Serialize(ds);
3393
0
            a.Serialize(ds);
3394
0
            b.Serialize(ds);
3395
0
        }
3396
};
3397
3398
class BLS_G1_Mul : public Operation {
3399
    public:
3400
        const component::CurveType curveType;
3401
        const component::G1 a;
3402
        const component::Bignum b;
3403
3404
        BLS_G1_Mul(Datasource& ds, component::Modifier modifier) :
3405
            Operation(std::move(modifier)),
3406
            curveType(ds),
3407
            a(ds),
3408
            b(ds)
3409
0
        { }
3410
        BLS_G1_Mul(nlohmann::json json) :
3411
            Operation(json["modifier"]),
3412
            curveType(json["curveType"]),
3413
            a(json["a_x"], json["a_y"]),
3414
            b(json["b"])
3415
0
        { }
3416
3417
0
        static size_t MaxOperations(void) { return 5; }
3418
        std::string Name(void) const override;
3419
        std::string ToString(void) const override;
3420
        nlohmann::json ToJSON(void) const override;
3421
0
        inline bool operator==(const BLS_G1_Mul& rhs) const {
3422
0
            return
3423
0
                (curveType == rhs.curveType) &&
3424
0
                (a == rhs.a) &&
3425
0
                (b == rhs.b) &&
3426
0
                (modifier == rhs.modifier);
3427
0
        }
3428
0
        void Serialize(Datasource& ds) const {
3429
0
            curveType.Serialize(ds);
3430
0
            a.Serialize(ds);
3431
0
            b.Serialize(ds);
3432
0
        }
3433
};
3434
3435
class BLS_G1_Neg : public Operation {
3436
    public:
3437
        const component::CurveType curveType;
3438
        const component::G1 a;
3439
3440
        BLS_G1_Neg(Datasource& ds, component::Modifier modifier) :
3441
            Operation(std::move(modifier)),
3442
            curveType(ds),
3443
            a(ds)
3444
0
        { }
3445
        BLS_G1_Neg(nlohmann::json json) :
3446
            Operation(json["modifier"]),
3447
            curveType(json["curveType"]),
3448
            a(json["a_x"], json["a_y"])
3449
0
        { }
3450
3451
0
        static size_t MaxOperations(void) { return 5; }
3452
        std::string Name(void) const override;
3453
        std::string ToString(void) const override;
3454
        nlohmann::json ToJSON(void) const override;
3455
0
        inline bool operator==(const BLS_G1_Neg& rhs) const {
3456
0
            return
3457
0
                (curveType == rhs.curveType) &&
3458
0
                (a == rhs.a) &&
3459
0
                (modifier == rhs.modifier);
3460
0
        }
3461
0
        void Serialize(Datasource& ds) const {
3462
0
            curveType.Serialize(ds);
3463
0
            a.Serialize(ds);
3464
0
        }
3465
};
3466
3467
class BLS_G2_Add : public Operation {
3468
    public:
3469
        const component::CurveType curveType;
3470
        const component::G2 a, b;
3471
3472
        BLS_G2_Add(Datasource& ds, component::Modifier modifier) :
3473
            Operation(std::move(modifier)),
3474
            curveType(ds),
3475
            a(ds),
3476
            b(ds)
3477
0
        { }
3478
        BLS_G2_Add(nlohmann::json json) :
3479
            Operation(json["modifier"]),
3480
            curveType(json["curveType"]),
3481
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"]),
3482
            b(json["b_v"], json["b_w"], json["b_x"], json["b_y"])
3483
0
        { }
3484
3485
0
        static size_t MaxOperations(void) { return 5; }
3486
        std::string Name(void) const override;
3487
        std::string ToString(void) const override;
3488
        nlohmann::json ToJSON(void) const override;
3489
0
        inline bool operator==(const BLS_G2_Add& rhs) const {
3490
0
            return
3491
0
                (curveType == rhs.curveType) &&
3492
0
                (a == rhs.a) &&
3493
0
                (b == rhs.b) &&
3494
0
                (modifier == rhs.modifier);
3495
0
        }
3496
0
        void Serialize(Datasource& ds) const {
3497
0
            curveType.Serialize(ds);
3498
0
            a.Serialize(ds);
3499
0
            b.Serialize(ds);
3500
0
        }
3501
};
3502
3503
class BLS_G2_IsEq : public Operation {
3504
    public:
3505
        const component::CurveType curveType;
3506
        const component::G2 a, b;
3507
3508
        BLS_G2_IsEq(Datasource& ds, component::Modifier modifier) :
3509
            Operation(std::move(modifier)),
3510
            curveType(ds),
3511
            a(ds),
3512
            b(ds)
3513
0
        { }
3514
        BLS_G2_IsEq(nlohmann::json json) :
3515
            Operation(json["modifier"]),
3516
            curveType(json["curveType"]),
3517
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"]),
3518
            b(json["b_v"], json["b_w"], json["b_x"], json["b_y"])
3519
0
        { }
3520
3521
0
        static size_t MaxOperations(void) { return 5; }
3522
        std::string Name(void) const override;
3523
        std::string ToString(void) const override;
3524
        nlohmann::json ToJSON(void) const override;
3525
0
        inline bool operator==(const BLS_G2_IsEq& rhs) const {
3526
0
            return
3527
0
                (curveType == rhs.curveType) &&
3528
0
                (a == rhs.a) &&
3529
0
                (b == rhs.b) &&
3530
0
                (modifier == rhs.modifier);
3531
0
        }
3532
0
        void Serialize(Datasource& ds) const {
3533
0
            curveType.Serialize(ds);
3534
0
            a.Serialize(ds);
3535
0
            b.Serialize(ds);
3536
0
        }
3537
};
3538
3539
class BLS_G2_Mul : public Operation {
3540
    public:
3541
        const component::CurveType curveType;
3542
        const component::G2 a;
3543
        const component::Bignum b;
3544
3545
        BLS_G2_Mul(Datasource& ds, component::Modifier modifier) :
3546
            Operation(std::move(modifier)),
3547
            curveType(ds),
3548
            a(ds),
3549
            b(ds)
3550
0
        { }
3551
        BLS_G2_Mul(nlohmann::json json) :
3552
            Operation(json["modifier"]),
3553
            curveType(json["curveType"]),
3554
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"]),
3555
            b(json["b"])
3556
0
        { }
3557
3558
0
        static size_t MaxOperations(void) { return 5; }
3559
        std::string Name(void) const override;
3560
        std::string ToString(void) const override;
3561
        nlohmann::json ToJSON(void) const override;
3562
0
        inline bool operator==(const BLS_G2_Mul& rhs) const {
3563
0
            return
3564
0
                (curveType == rhs.curveType) &&
3565
0
                (a == rhs.a) &&
3566
0
                (b == rhs.b) &&
3567
0
                (modifier == rhs.modifier);
3568
0
        }
3569
0
        void Serialize(Datasource& ds) const {
3570
0
            curveType.Serialize(ds);
3571
0
            a.Serialize(ds);
3572
0
            b.Serialize(ds);
3573
0
        }
3574
};
3575
3576
class BLS_G2_Neg : public Operation {
3577
    public:
3578
        const component::CurveType curveType;
3579
        const component::G2 a;
3580
3581
        BLS_G2_Neg(Datasource& ds, component::Modifier modifier) :
3582
            Operation(std::move(modifier)),
3583
            curveType(ds),
3584
            a(ds)
3585
0
        { }
3586
        BLS_G2_Neg(nlohmann::json json) :
3587
            Operation(json["modifier"]),
3588
            curveType(json["curveType"]),
3589
            a(json["a_v"], json["a_w"], json["a_x"], json["a_y"])
3590
0
        { }
3591
3592
0
        static size_t MaxOperations(void) { return 5; }
3593
        std::string Name(void) const override;
3594
        std::string ToString(void) const override;
3595
        nlohmann::json ToJSON(void) const override;
3596
0
        inline bool operator==(const BLS_G2_Neg& rhs) const {
3597
0
            return
3598
0
                (curveType == rhs.curveType) &&
3599
0
                (a == rhs.a) &&
3600
0
                (modifier == rhs.modifier);
3601
0
        }
3602
0
        void Serialize(Datasource& ds) const {
3603
0
            curveType.Serialize(ds);
3604
0
            a.Serialize(ds);
3605
0
        }
3606
};
3607
3608
class BLS_G1_MultiExp : public Operation {
3609
    public:
3610
        const component::CurveType curveType;
3611
        component::BLS_G1_Scalar_Vector points_scalars;
3612
3613
        BLS_G1_MultiExp(Datasource& ds, component::Modifier modifier) :
3614
            Operation(std::move(modifier)),
3615
            curveType(ds),
3616
            points_scalars(ds)
3617
0
        { }
3618
        BLS_G1_MultiExp(nlohmann::json json) :
3619
            Operation(json["modifier"]),
3620
            curveType(json["curveType"]),
3621
            points_scalars(json["points_scalars"])
3622
0
        { }
3623
3624
0
        static size_t MaxOperations(void) { return 5; }
3625
        std::string Name(void) const override;
3626
        std::string ToString(void) const override;
3627
        nlohmann::json ToJSON(void) const override;
3628
0
        inline bool operator==(const BLS_G1_MultiExp& rhs) const {
3629
0
            return
3630
0
                (curveType == rhs.curveType) &&
3631
0
                (points_scalars == rhs.points_scalars) &&
3632
0
                (modifier == rhs.modifier);
3633
0
        }
3634
0
        void Serialize(Datasource& ds) const {
3635
0
            curveType.Serialize(ds);
3636
0
            points_scalars.Serialize(ds);
3637
0
        }
3638
};
3639
3640
class Misc : public Operation {
3641
    public:
3642
        const Type operation;
3643
3644
        Misc(Datasource& ds, component::Modifier modifier) :
3645
            Operation(std::move(modifier)),
3646
            operation(ds)
3647
0
        { }
3648
3649
        Misc(nlohmann::json json) :
3650
            Operation(json["modifier"]),
3651
            operation(json["operation"])
3652
0
        { }
3653
3654
0
        static size_t MaxOperations(void) { return 5; }
3655
        std::string Name(void) const override;
3656
        std::string ToString(void) const override;
3657
        nlohmann::json ToJSON(void) const override;
3658
0
        inline bool operator==(const Misc& rhs) const {
3659
0
            return
3660
0
                (operation == rhs.operation) &&
3661
0
                (modifier == rhs.modifier);
3662
0
        }
3663
0
        void Serialize(Datasource& ds) const {
3664
0
            operation.Serialize(ds);
3665
0
        }
3666
};
3667
3668
class SR25519_Verify : public Operation {
3669
    public:
3670
        const component::Cleartext cleartext;
3671
        const component::SR25519_Signature signature;
3672
3673
        SR25519_Verify(Datasource& ds, component::Modifier modifier) :
3674
            Operation(std::move(modifier)),
3675
            cleartext(ds),
3676
            signature(ds)
3677
0
        { }
3678
        SR25519_Verify(nlohmann::json json) :
3679
            Operation(json["modifier"]),
3680
            cleartext(json["cleartext"]),
3681
            signature(json["signature"])
3682
0
        { }
3683
3684
0
        static size_t MaxOperations(void) { return 5; }
3685
        std::string Name(void) const override;
3686
        std::string ToString(void) const override;
3687
        nlohmann::json ToJSON(void) const override;
3688
0
        inline bool operator==(const SR25519_Verify& rhs) const {
3689
0
            return
3690
0
                (cleartext == rhs.cleartext) &&
3691
0
                (signature == rhs.signature) &&
3692
0
                (modifier == rhs.modifier);
3693
0
        }
3694
0
        void Serialize(Datasource& ds) const {
3695
0
            cleartext.Serialize(ds);
3696
0
            signature.Serialize(ds);
3697
0
        }
3698
};
3699
3700
} /* namespace operation */
3701
} /* namespace cryptofuzz */