aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/mcl/src/she_c_impl.hpp
blob: 073bc2b346b8751c6892c376170c05bf0b450c99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <iosfwd>
#include <stdint.h>
#include <memory.h>
#include "mcl/impl/bn_c_impl.hpp"
#define MCLSHE_DLL_EXPORT

#include <mcl/she.h>
#include <mcl/she.hpp>

using namespace mcl::she;
using namespace mcl::bn;

static SecretKey *cast(sheSecretKey *p) { return reinterpret_cast<SecretKey*>(p); }
static const SecretKey *cast(const sheSecretKey *p) { return reinterpret_cast<const SecretKey*>(p); }

static PublicKey *cast(shePublicKey *p) { return reinterpret_cast<PublicKey*>(p); }
static const PublicKey *cast(const shePublicKey *p) { return reinterpret_cast<const PublicKey*>(p); }

static PrecomputedPublicKey *cast(shePrecomputedPublicKey *p) { return reinterpret_cast<PrecomputedPublicKey*>(p); }
static const PrecomputedPublicKey *cast(const shePrecomputedPublicKey *p) { return reinterpret_cast<const PrecomputedPublicKey*>(p); }

static CipherTextG1 *cast(sheCipherTextG1 *p) { return reinterpret_cast<CipherTextG1*>(p); }
static const CipherTextG1 *cast(const sheCipherTextG1 *p) { return reinterpret_cast<const CipherTextG1*>(p); }

static CipherTextG2 *cast(sheCipherTextG2 *p) { return reinterpret_cast<CipherTextG2*>(p); }
static const CipherTextG2 *cast(const sheCipherTextG2 *p) { return reinterpret_cast<const CipherTextG2*>(p); }

static CipherTextGT *cast(sheCipherTextGT *p) { return reinterpret_cast<CipherTextGT*>(p); }
static const CipherTextGT *cast(const sheCipherTextGT *p) { return reinterpret_cast<const CipherTextGT*>(p); }

static ZkpBin *cast(sheZkpBin *p) { return reinterpret_cast<ZkpBin*>(p); }
static const ZkpBin *cast(const sheZkpBin *p) { return reinterpret_cast<const ZkpBin*>(p); }

static ZkpEq *cast(sheZkpEq *p) { return reinterpret_cast<ZkpEq*>(p); }
static const ZkpEq *cast(const sheZkpEq *p) { return reinterpret_cast<const ZkpEq*>(p); }

static ZkpBinEq *cast(sheZkpBinEq *p) { return reinterpret_cast<ZkpBinEq*>(p); }
static const ZkpBinEq *cast(const sheZkpBinEq *p) { return reinterpret_cast<const ZkpBinEq*>(p); }

int sheInit(int curve, int compiledTimeVar)
    try
{
    if (compiledTimeVar != MCLBN_COMPILED_TIME_VAR) {
        return -2;
    }
    mcl::CurveParam cp;
    switch (curve) {
    case MCL_BN254:
        cp = mcl::BN254;
        break;
    case MCL_BN381_1:
        cp = mcl::BN381_1;
        break;
    case MCL_BN381_2:
        cp = mcl::BN381_2;
        break;
    case MCL_BN462:
        cp = mcl::BN462;
        break;
    case MCL_BN_SNARK1:
        cp = mcl::BN_SNARK1;
        break;
    case MCL_BLS12_381:
        cp = mcl::BLS12_381;
        break;
    default:
        return -1;
    }
    SHE::init(cp);
    return 0;
} catch (std::exception&) {
    return -1;
}

mclSize sheSecretKeySerialize(void *buf, mclSize maxBufSize, const sheSecretKey *sec)
{
    return (mclSize)cast(sec)->serialize(buf, maxBufSize);
}

mclSize shePublicKeySerialize(void *buf, mclSize maxBufSize, const shePublicKey *pub)
{
    return (mclSize)cast(pub)->serialize(buf, maxBufSize);
}

mclSize sheCipherTextG1Serialize(void *buf, mclSize maxBufSize, const sheCipherTextG1 *c)
{
    return (mclSize)cast(c)->serialize(buf, maxBufSize);
}

mclSize sheCipherTextG2Serialize(void *buf, mclSize maxBufSize, const sheCipherTextG2 *c)
{
    return (mclSize)cast(c)->serialize(buf, maxBufSize);
}

mclSize sheCipherTextGTSerialize(void *buf, mclSize maxBufSize, const sheCipherTextGT *c)
{
    return (mclSize)cast(c)->serialize(buf, maxBufSize);
}

mclSize sheZkpBinSerialize(void *buf, mclSize maxBufSize, const sheZkpBin *zkp)
{
    return (mclSize)cast(zkp)->serialize(buf, maxBufSize);
}

mclSize sheZkpEqSerialize(void *buf, mclSize maxBufSize, const sheZkpEq *zkp)
{
    return (mclSize)cast(zkp)->serialize(buf, maxBufSize);
}

mclSize sheZkpBinEqSerialize(void *buf, mclSize maxBufSize, const sheZkpBinEq *zkp)
{
    return (mclSize)cast(zkp)->serialize(buf, maxBufSize);
}

mclSize sheSecretKeyDeserialize(sheSecretKey* sec, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(sec)->deserialize(buf, bufSize);
}

mclSize shePublicKeyDeserialize(shePublicKey* pub, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(pub)->deserialize(buf, bufSize);
}

mclSize sheCipherTextG1Deserialize(sheCipherTextG1* c, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(c)->deserialize(buf, bufSize);
}

mclSize sheCipherTextG2Deserialize(sheCipherTextG2* c, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(c)->deserialize(buf, bufSize);
}

mclSize sheCipherTextGTDeserialize(sheCipherTextGT* c, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(c)->deserialize(buf, bufSize);
}

mclSize sheZkpBinDeserialize(sheZkpBin* zkp, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(zkp)->deserialize(buf, bufSize);
}

mclSize sheZkpEqDeserialize(sheZkpEq* zkp, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(zkp)->deserialize(buf, bufSize);
}

mclSize sheZkpBinEqDeserialize(sheZkpBinEq* zkp, const void *buf, mclSize bufSize)
{
    return (mclSize)cast(zkp)->deserialize(buf, bufSize);
}

int sheSecretKeySetByCSPRNG(sheSecretKey *sec)
{
    cast(sec)->setByCSPRNG();
    return 0;
}

void sheGetPublicKey(shePublicKey *pub, const sheSecretKey *sec)
{
    cast(sec)->getPublicKey(*cast(pub));
}

static int setRangeForDLP(void (*f)(mclSize), mclSize hashSize)
    try
{
    f(hashSize);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheSetRangeForDLP(mclSize hashSize)
{
    return setRangeForDLP(SHE::setRangeForDLP, hashSize);
}
int sheSetRangeForG1DLP(mclSize hashSize)
{
    return setRangeForDLP(SHE::setRangeForG1DLP, hashSize);
}
int sheSetRangeForG2DLP(mclSize hashSize)
{
    return setRangeForDLP(SHE::setRangeForG2DLP, hashSize);
}
int sheSetRangeForGTDLP(mclSize hashSize)
{
    return setRangeForDLP(SHE::setRangeForGTDLP, hashSize);
}

void sheSetTryNum(mclSize tryNum)
{
    SHE::setTryNum(tryNum);
}
void sheUseDecG1ViaGT(int use)
{
    SHE::useDecG1ViaGT(use != 0);
}
void sheUseDecG2ViaGT(int use)
{
    SHE::useDecG2ViaGT(use != 0);
}

template<class HashTable>
mclSize loadTable(HashTable& table, const void *buf, mclSize bufSize)
    try
{
    return table.load(buf, bufSize);
} catch (std::exception&) {
    return 0;
}

mclSize sheLoadTableForG1DLP(const void *buf, mclSize bufSize)
{
    return loadTable(getHashTableG1(), buf, bufSize);
}
mclSize sheLoadTableForG2DLP(const void *buf, mclSize bufSize)
{
    return loadTable(getHashTableG2(), buf, bufSize);
}
mclSize sheLoadTableForGTDLP(const void *buf, mclSize bufSize)
{
    return loadTable(getHashTableGT(), buf, bufSize);
}

template<class HashTable>
mclSize saveTable(void *buf, mclSize maxBufSize, const HashTable& table)
    try
{
    return table.save(buf, maxBufSize);
} catch (std::exception&) {
    return 0;
}
mclSize sheSaveTableForG1DLP(void *buf, mclSize maxBufSize)
{
    return saveTable(buf, maxBufSize, SHE::PhashTbl_);
}
mclSize sheSaveTableForG2DLP(void *buf, mclSize maxBufSize)
{
    return saveTable(buf, maxBufSize, SHE::QhashTbl_);
}
mclSize sheSaveTableForGTDLP(void *buf, mclSize maxBufSize)
{
    return saveTable(buf, maxBufSize, SHE::ePQhashTbl_);
}

template<class CT>
int encT(CT *c, const shePublicKey *pub, mclInt m)
    try
{
    cast(pub)->enc(*cast(c), m);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheEncG1(sheCipherTextG1 *c, const shePublicKey *pub, mclInt m)
{
    return encT(c, pub, m);
}

int sheEncG2(sheCipherTextG2 *c, const shePublicKey *pub, mclInt m)
{
    return encT(c, pub, m);
}

int sheEncGT(sheCipherTextGT *c, const shePublicKey *pub, mclInt m)
{
    return encT(c, pub, m);
}

template<class CT, class PK>
int encWithZkpBinT(CT *c, sheZkpBin *zkp, const PK *pub, int m)
    try
{
    cast(pub)->encWithZkpBin(*cast(c), *cast(zkp), m);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheEncWithZkpBinG1(sheCipherTextG1 *c, sheZkpBin *zkp, const shePublicKey *pub, int m)
{
    return encWithZkpBinT(c, zkp, pub, m);
}

int sheEncWithZkpBinG2(sheCipherTextG2 *c, sheZkpBin *zkp, const shePublicKey *pub, int m)
{
    return encWithZkpBinT(c, zkp, pub, m);
}

int shePrecomputedPublicKeyEncWithZkpBinG1(sheCipherTextG1 *c, sheZkpBin *zkp, const shePrecomputedPublicKey *pub, int m)
{
    return encWithZkpBinT(c, zkp, pub, m);
}

int shePrecomputedPublicKeyEncWithZkpBinG2(sheCipherTextG2 *c, sheZkpBin *zkp, const shePrecomputedPublicKey *pub, int m)
{
    return encWithZkpBinT(c, zkp, pub, m);
}

template<class PK>
int encWithZkpEqT(sheCipherTextG1 *c1, sheCipherTextG2 *c2, sheZkpEq *zkp, const PK *pub, mclInt m)
    try
{
    cast(pub)->encWithZkpEq(*cast(c1), *cast(c2), *cast(zkp), m);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheEncWithZkpEq(sheCipherTextG1 *c1, sheCipherTextG2 *c2, sheZkpEq *zkp, const shePublicKey *pub, mclInt m)
{
    return encWithZkpEqT(c1, c2, zkp, pub, m);
}

int shePrecomputedPublicKeyEncWithZkpEq(sheCipherTextG1 *c1, sheCipherTextG2 *c2, sheZkpEq *zkp, const shePrecomputedPublicKey *ppub, mclInt m)
{
    return encWithZkpEqT(c1, c2, zkp, ppub, m);
}

template<class PK>
int encWithZkpBinEqT(sheCipherTextG1 *c1, sheCipherTextG2 *c2, sheZkpBinEq *zkp, const PK *pub, int m)
    try
{
    cast(pub)->encWithZkpBinEq(*cast(c1), *cast(c2), *cast(zkp), m);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheEncWithZkpBinEq(sheCipherTextG1 *c1, sheCipherTextG2 *c2, sheZkpBinEq *zkp, const shePublicKey *pub, int m)
{
    return encWithZkpBinEqT(c1, c2, zkp, pub, m);
}

int shePrecomputedPublicKeyEncWithZkpBinEq(sheCipherTextG1 *c1, sheCipherTextG2 *c2, sheZkpBinEq *zkp, const shePrecomputedPublicKey *ppub, int m)
{
    return encWithZkpBinEqT(c1, c2, zkp, ppub, m);
}

template<class CT>
int decT(mclInt *m, const sheSecretKey *sec, const CT *c)
    try
{
    *m = (cast(sec)->dec)(*cast(c));
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheDecG1(mclInt *m, const sheSecretKey *sec, const sheCipherTextG1 *c)
{
    return decT(m, sec, c);
}

int sheDecG2(mclInt *m, const sheSecretKey *sec, const sheCipherTextG2 *c)
{
    return decT(m, sec, c);
}

int sheDecGT(mclInt *m, const sheSecretKey *sec, const sheCipherTextGT *c)
{
    return decT(m, sec, c);
}

template<class CT>
int decViaGTT(mclInt *m, const sheSecretKey *sec, const CT *c)
    try
{
    *m = (cast(sec)->decViaGT)(*cast(c));
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheDecG1ViaGT(mclInt *m, const sheSecretKey *sec, const sheCipherTextG1 *c)
{
    return decViaGTT(m, sec, c);
}

int sheDecG2ViaGT(mclInt *m, const sheSecretKey *sec, const sheCipherTextG2 *c)
{
    return decViaGTT(m, sec, c);
}


template<class CT>
int isZeroT(const sheSecretKey *sec, const CT *c)
    try
{
    return cast(sec)->isZero(*cast(c));
} catch (std::exception&) {
    return 0;
}

int sheIsZeroG1(const sheSecretKey *sec, const sheCipherTextG1 *c)
{
    return isZeroT(sec, c);
}
int sheIsZeroG2(const sheSecretKey *sec, const sheCipherTextG2 *c)
{
    return isZeroT(sec, c);
}
int sheIsZeroGT(const sheSecretKey *sec, const sheCipherTextGT *c)
{
    return isZeroT(sec, c);
}

template<class CT>
int negT(CT& y, const CT& x)
    try
{
    CT::neg(y, x);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheNegG1(sheCipherTextG1 *y, const sheCipherTextG1 *x)
{
    return negT(*cast(y), *cast(x));
}

int sheNegG2(sheCipherTextG2 *y, const sheCipherTextG2 *x)
{
    return negT(*cast(y), *cast(x));
}

int sheNegGT(sheCipherTextGT *y, const sheCipherTextGT *x)
{
    return negT(*cast(y), *cast(x));
}

template<class CT>
int addT(CT& z, const CT& x, const CT& y)
    try
{
    CT::add(z, x, y);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheAddG1(sheCipherTextG1 *z, const sheCipherTextG1 *x, const sheCipherTextG1 *y)
{
    return addT(*cast(z), *cast(x), *cast(y));
}

int sheAddG2(sheCipherTextG2 *z, const sheCipherTextG2 *x, const sheCipherTextG2 *y)
{
    return addT(*cast(z), *cast(x), *cast(y));
}

int sheAddGT(sheCipherTextGT *z, const sheCipherTextGT *x, const sheCipherTextGT *y)
{
    return addT(*cast(z), *cast(x), *cast(y));
}

template<class CT>
int subT(CT& z, const CT& x, const CT& y)
    try
{
    CT::sub(z, x, y);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheSubG1(sheCipherTextG1 *z, const sheCipherTextG1 *x, const sheCipherTextG1 *y)
{
    return subT(*cast(z), *cast(x), *cast(y));
}

int sheSubG2(sheCipherTextG2 *z, const sheCipherTextG2 *x, const sheCipherTextG2 *y)
{
    return subT(*cast(z), *cast(x), *cast(y));
}

int sheSubGT(sheCipherTextGT *z, const sheCipherTextGT *x, const sheCipherTextGT *y)
{
    return subT(*cast(z), *cast(x), *cast(y));
}

template<class CT1, class CT2, class CT3>
int mulT(CT1& z, const CT2& x, const CT3& y)
    try
{
    CT1::mul(z, x, y);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheMulG1(sheCipherTextG1 *z, const sheCipherTextG1 *x, mclInt y)
{
    return mulT(*cast(z), *cast(x), y);
}

int sheMulG2(sheCipherTextG2 *z, const sheCipherTextG2 *x, mclInt y)
{
    return mulT(*cast(z), *cast(x), y);
}

int sheMulGT(sheCipherTextGT *z, const sheCipherTextGT *x, mclInt y)
{
    return mulT(*cast(z), *cast(x), y);
}

int sheMul(sheCipherTextGT *z, const sheCipherTextG1 *x, const sheCipherTextG2 *y)
{
    return mulT(*cast(z), *cast(x), *cast(y));
}

int sheMulML(sheCipherTextGT *z, const sheCipherTextG1 *x, const sheCipherTextG2 *y)
    try
{
    CipherTextGT::mulML(*cast(z), *cast(x), *cast(y));
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheFinalExpGT(sheCipherTextGT *y, const sheCipherTextGT *x)
    try
{
    CipherTextGT::finalExp(*cast(y), *cast(x));
    return 0;
} catch (std::exception&) {
    return -1;
}

template<class CT>
int reRandT(CT& c, const shePublicKey *pub)
    try
{
    cast(pub)->reRand(c);
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheReRandG1(sheCipherTextG1 *c, const shePublicKey *pub)
{
    return reRandT(*cast(c), pub);
}

int sheReRandG2(sheCipherTextG2 *c, const shePublicKey *pub)
{
    return reRandT(*cast(c), pub);
}

int sheReRandGT(sheCipherTextGT *c, const shePublicKey *pub)
{
    return reRandT(*cast(c), pub);
}

template<class CT>
int convert(sheCipherTextGT *y, const shePublicKey *pub, const CT *x)
    try
{
    cast(pub)->convert(*cast(y), *cast(x));
    return 0;
} catch (std::exception&) {
    return -1;
}

int sheConvertG1(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG1 *x)
{
    return convert(y, pub, x);
}

int sheConvertG2(sheCipherTextGT *y, const shePublicKey *pub, const sheCipherTextG2 *x)
{
    return convert(y, pub, x);
}

shePrecomputedPublicKey *shePrecomputedPublicKeyCreate()
    try
{
    return reinterpret_cast<shePrecomputedPublicKey*>(new PrecomputedPublicKey());
} catch (...) {
    return 0;
}

void shePrecomputedPublicKeyDestroy(shePrecomputedPublicKey *ppub)
{
    delete cast(ppub);
}

int shePrecomputedPublicKeyInit(shePrecomputedPublicKey *ppub, const shePublicKey *pub)
    try
{
    cast(ppub)->init(*cast(pub));
    return 0;
} catch (...) {
    return 1;
}

template<class CT>
int pEncT(CT *c, const shePrecomputedPublicKey *pub, mclInt m)
    try
{
    cast(pub)->enc(*cast(c), m);
    return 0;
} catch (std::exception&) {
    return -1;
}

int shePrecomputedPublicKeyEncG1(sheCipherTextG1 *c, const shePrecomputedPublicKey *pub, mclInt m)
{
    return pEncT(c, pub, m);
}

int shePrecomputedPublicKeyEncG2(sheCipherTextG2 *c, const shePrecomputedPublicKey *pub, mclInt m)
{
    return pEncT(c, pub, m);
}

int shePrecomputedPublicKeyEncGT(sheCipherTextGT *c, const shePrecomputedPublicKey *pub, mclInt m)
{
    return pEncT(c, pub, m);
}

template<class PK, class CT>
int verifyT(const PK& pub, const CT& c, const ZkpBin& zkp)
    try
{
    return pub.verify(c, zkp);
} catch (std::exception&) {
    return 0;
}

int sheVerifyZkpBinG1(const shePublicKey *pub, const sheCipherTextG1 *c, const sheZkpBin *zkp)
{
    return verifyT(*cast(pub), *cast(c), *cast(zkp));
}
int sheVerifyZkpBinG2(const shePublicKey *pub, const sheCipherTextG2 *c, const sheZkpBin *zkp)
{
    return verifyT(*cast(pub), *cast(c), *cast(zkp));
}
int shePrecomputedPublicKeyVerifyZkpBinG1(const shePrecomputedPublicKey *pub, const sheCipherTextG1 *c, const sheZkpBin *zkp)
{
    return verifyT(*cast(pub), *cast(c), *cast(zkp));
}
int shePrecomputedPublicKeyVerifyZkpBinG2(const shePrecomputedPublicKey *pub, const sheCipherTextG2 *c, const sheZkpBin *zkp)
{
    return verifyT(*cast(pub), *cast(c), *cast(zkp));
}

template<class PK, class Zkp>
int verifyT(const PK& pub, const CipherTextG1& c1, const CipherTextG2& c2, const Zkp& zkp)
    try
{
    return pub.verify(c1, c2, zkp);
} catch (std::exception&) {
    return 0;
}

int sheVerifyZkpEq(const shePublicKey *pub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpEq *zkp)
{
    return verifyT(*cast(pub), *cast(c1), *cast(c2), *cast(zkp));
}
int sheVerifyZkpBinEq(const shePublicKey *pub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpBinEq *zkp)
{
    return verifyT(*cast(pub), *cast(c1), *cast(c2), *cast(zkp));
}
int shePrecomputedPublicKeyVerifyZkpEq(const shePrecomputedPublicKey *ppub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpEq *zkp)
{
    return verifyT(*cast(ppub), *cast(c1), *cast(c2), *cast(zkp));
}
int shePrecomputedPublicKeyVerifyZkpBinEq(const shePrecomputedPublicKey *ppub, const sheCipherTextG1 *c1, const sheCipherTextG2 *c2, const sheZkpBinEq *zkp)
{
    return verifyT(*cast(ppub), *cast(c1), *cast(c2), *cast(zkp));
}