-
Notifications
You must be signed in to change notification settings - Fork 724
/
Copy pathbiguint.cpp
777 lines (655 loc) · 19.4 KB
/
biguint.cpp
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// STD
#include <string>
// SEALNet
#include "seal/c/biguint.h"
#include "seal/c/stdafx.h"
#include "seal/c/utilities.h"
// SEAL
#include "seal/biguint.h"
using namespace std;
using namespace seal;
using namespace seal::c;
SEAL_C_FUNC BigUInt_Create1(void **bui)
{
IfNullRet(bui, E_POINTER);
BigUInt *biguint = new BigUInt();
*bui = biguint;
return S_OK;
}
SEAL_C_FUNC BigUInt_Create2(int bitCount, void **bui)
{
IfNullRet(bui, E_POINTER);
try
{
BigUInt *biguint = new BigUInt(bitCount, /* value */ static_cast<uint64_t>(0));
*bui = biguint;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC BigUInt_Create3(int bitCount, char *hex_string, void **bui)
{
IfNullRet(hex_string, E_POINTER);
IfNullRet(bui, E_POINTER);
string hexstring(hex_string);
BigUInt *biguint = nullptr;
try
{
biguint = new BigUInt(bitCount, hexstring);
*bui = biguint;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC BigUInt_Create4(int bitCount, uint64_t value, void **bui)
{
IfNullRet(bui, E_POINTER);
try
{
BigUInt *biguint = new BigUInt(bitCount, value);
*bui = biguint;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC BigUInt_Create5(char *hex_string, void **bui)
{
IfNullRet(hex_string, E_POINTER);
IfNullRet(bui, E_POINTER);
string hexstring(hex_string);
BigUInt *biguint = nullptr;
try
{
biguint = new BigUInt(hexstring);
*bui = biguint;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC BigUInt_Create6(void *copy, void **bui)
{
BigUInt *other = FromVoid<BigUInt>(copy);
IfNullRet(other, E_POINTER);
IfNullRet(bui, E_POINTER);
BigUInt *biguint = new BigUInt(*other);
*bui = biguint;
return S_OK;
}
SEAL_C_FUNC BigUInt_Destroy(void *thisptr)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(thisptr, E_POINTER);
delete biguint;
return S_OK;
}
SEAL_C_FUNC BigUInt_IsAlias(void *thisptr, bool *is_alias)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(is_alias, E_POINTER);
*is_alias = biguint->is_alias();
return S_OK;
}
SEAL_C_FUNC BigUInt_BitCount(void *thisptr, int *bit_count)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(bit_count, E_POINTER);
*bit_count = biguint->bit_count();
return S_OK;
}
SEAL_C_FUNC BigUInt_ByteCount(void *thisptr, uint64_t *byte_count)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(byte_count, E_POINTER);
*byte_count = biguint->byte_count();
return S_OK;
}
SEAL_C_FUNC BigUInt_UInt64Count(void *thisptr, uint64_t *uint64_count)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(uint64_count, E_POINTER);
*uint64_count = biguint->uint64_count();
return S_OK;
}
SEAL_C_FUNC BigUInt_IsZero(void *thisptr, bool *is_zero)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(is_zero, E_POINTER);
*is_zero = biguint->is_zero();
return S_OK;
}
SEAL_C_FUNC BigUInt_Get(void *thisptr, uint64_t index, uint8_t *value)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(value, E_POINTER)
if (index >= biguint->byte_count())
{
return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
}
auto result = (*biguint)[index];
*value = static_cast<uint8_t>(result);
return S_OK;
}
SEAL_C_FUNC BigUInt_GetU64(void *thisptr, uint64_t index, uint64_t *value)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(value, E_POINTER);
if (index >= biguint->uint64_count())
{
return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
}
*value = biguint->data()[index];
return S_OK;
}
SEAL_C_FUNC BigUInt_Set1(void *thisptr, uint64_t index, uint8_t value)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
if (index >= biguint->byte_count())
{
return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
}
(*biguint)[index] = static_cast<SEAL_BYTE>(value);
return S_OK;
}
SEAL_C_FUNC BigUInt_GetSignificantBitCount(void *thisptr, int *significant_bit_count)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(significant_bit_count, E_POINTER);
*significant_bit_count = biguint->significant_bit_count();
return S_OK;
}
SEAL_C_FUNC BigUInt_Set2(void *thisptr, void *assign)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *other = FromVoid<BigUInt>(assign);
IfNullRet(other, E_POINTER);
*biguint = *other;
return S_OK;
}
SEAL_C_FUNC BigUInt_Set3(void *thisptr, uint64_t value)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
try
{
*biguint = value;
return S_OK;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
}
SEAL_C_FUNC BigUInt_Set4(void *thisptr, char *assign)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(assign, E_POINTER);
string assign_str(assign);
try
{
*biguint = assign_str;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
}
SEAL_C_FUNC BigUInt_SetZero(void *thisptr)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
biguint->set_zero();
return S_OK;
}
SEAL_C_FUNC BigUInt_Resize(void *thisptr, int bitCount)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
biguint->resize(bitCount);
return S_OK;
}
SEAL_C_FUNC BigUInt_Equals(void *thisptr, void *compare, bool *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *other = FromVoid<BigUInt>(compare);
IfNullRet(other, E_POINTER);
IfNullRet(result, E_POINTER);
*result = (*biguint) == (*other);
return S_OK;
}
SEAL_C_FUNC BigUInt_CompareTo1(void *thisptr, void *compare, int *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *other = FromVoid<BigUInt>(compare);
IfNullRet(other, E_POINTER);
IfNullRet(result, E_POINTER);
*result = biguint->compareto(*other);
return S_OK;
}
SEAL_C_FUNC BigUInt_CompareTo2(void *thisptr, uint64_t compare, int *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
*result = biguint->compareto(compare);
return S_OK;
}
SEAL_C_FUNC BigUInt_DivideRemainder1(void *thisptr, void *operand2, void *remainder, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operand2bui = FromVoid<BigUInt>(operand2);
IfNullRet(operand2bui, E_POINTER);
BigUInt *remainderbui = FromVoid<BigUInt>(remainder);
IfNullRet(remainderbui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(biguint->divrem(*operand2bui, *remainderbui));
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_DivideRemainder2(void *thisptr, uint64_t operand2, void *remainder, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *remainderbui = FromVoid<BigUInt>(remainder);
IfNullRet(remainderbui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(biguint->divrem(operand2, *remainderbui));
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_ToString(void *thisptr, char *outstr, uint64_t *length)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(length, E_POINTER);
return ToStringHelper(biguint->to_string(), outstr, length);
}
SEAL_C_FUNC BigUInt_ToDecimalString(void *thisptr, char *outstr, uint64_t *length)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(length, E_POINTER);
return ToStringHelper(biguint->to_dec_string(), outstr, length);
}
SEAL_C_FUNC BigUInt_DuplicateTo(void *thisptr, void *destination)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *destbui = FromVoid<BigUInt>(destination);
IfNullRet(destbui, E_POINTER);
biguint->duplicate_to(*destbui);
return S_OK;
}
SEAL_C_FUNC BigUInt_DuplicateFrom(void *thisptr, void *value)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *valuebui = FromVoid<BigUInt>(value);
IfNullRet(valuebui, E_POINTER);
biguint->duplicate_from(*valuebui);
return S_OK;
}
SEAL_C_FUNC BigUInt_ModuloInvert1(void *thisptr, void *modulus, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *modulusui = FromVoid<BigUInt>(modulus);
IfNullRet(modulusui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = nullptr;
try
{
resultbui = new BigUInt(biguint->modinv(*modulusui));
*result = resultbui;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
}
SEAL_C_FUNC BigUInt_ModuloInvert2(void *thisptr, uint64_t modulus, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *resultbui = nullptr;
try
{
resultbui = new BigUInt(biguint->modinv(modulus));
*result = resultbui;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
}
SEAL_C_FUNC BigUInt_TryModuloInvert1(void *thisptr, void *modulus, void *inverse, bool *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *modulusui = FromVoid<BigUInt>(modulus);
IfNullRet(modulusui, E_POINTER);
BigUInt *inverseui = FromVoid<BigUInt>(inverse);
IfNullRet(inverseui, E_POINTER);
IfNullRet(result, E_POINTER);
try
{
*result = biguint->trymodinv(*modulusui, *inverseui);
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC BigUInt_TryModuloInvert2(void *thisptr, uint64_t modulus, void *inverse, bool *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *inverseui = FromVoid<BigUInt>(inverse);
IfNullRet(inverseui, E_POINTER);
IfNullRet(result, E_POINTER);
try
{
*result = biguint->trymodinv(modulus, *inverseui);
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC BigUInt_OperatorNeg(void *thisptr, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(biguint->operator-());
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorTilde(void *thisptr, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(biguint->operator~());
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorPlus1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint + *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorPlus2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint + operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorMinus1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint - *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorMinus2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint - operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorMult1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint * *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorMult2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint * operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorDiv1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint / *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorDiv2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint / operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorXor1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint ^ *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorXor2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint ^ operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorAnd1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint & *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorAnd2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint & operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorOr1(void *thisptr, void *operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
BigUInt *operandui = FromVoid<BigUInt>(operand);
IfNullRet(operandui, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint | *operandui);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorOr2(void *thisptr, uint64_t operand, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint | operand);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorShiftLeft(void *thisptr, int shift, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint << shift);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_OperatorShiftRight(void *thisptr, int shift, void **result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
BigUInt *resultbui = new BigUInt(*biguint >> shift);
*result = resultbui;
return S_OK;
}
SEAL_C_FUNC BigUInt_ToDouble(void *thisptr, double *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
*result = biguint->to_double();
return S_OK;
}
SEAL_C_FUNC BigUInt_SaveSize(void *thisptr, uint8_t compr_mode, int64_t *result)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(result, E_POINTER);
try
{
*result = static_cast<int64_t>(biguint->save_size(static_cast<compr_mode_type>(compr_mode)));
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
}
SEAL_C_FUNC BigUInt_Save(void *thisptr, uint8_t *outptr, uint64_t size, uint8_t compr_mode, int64_t *out_bytes)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(outptr, E_POINTER);
IfNullRet(out_bytes, E_POINTER);
try
{
*out_bytes = util::safe_cast<int64_t>(biguint->save(
reinterpret_cast<SEAL_BYTE *>(outptr), util::safe_cast<size_t>(size),
static_cast<compr_mode_type>(compr_mode)));
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
catch (const runtime_error &)
{
return COR_E_IO;
}
}
SEAL_C_FUNC BigUInt_Load(void *thisptr, uint8_t *inptr, uint64_t size, int64_t *in_bytes)
{
BigUInt *biguint = FromVoid<BigUInt>(thisptr);
IfNullRet(biguint, E_POINTER);
IfNullRet(inptr, E_POINTER);
IfNullRet(in_bytes, E_POINTER);
try
{
*in_bytes = util::safe_cast<int64_t>(
biguint->load(reinterpret_cast<SEAL_BYTE *>(inptr), util::safe_cast<size_t>(size)));
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
catch (const logic_error &)
{
return COR_E_INVALIDOPERATION;
}
catch (const runtime_error &)
{
return COR_E_IO;
}
}