File: bigintunittest.cpp

package info (click to toggle)
qca2 2.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,672 kB
  • sloc: cpp: 58,980; ansic: 832; perl: 133; sh: 79; makefile: 22
file content (1138 lines) | stat: -rw-r--r-- 71,669 bytes parent folder | download
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
/**
 * Copyright (C)  2004-2006  Brad Hards <bradh@frogmouth.net>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <QtCrypto>
#include <QtTest/QtTest>

#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif

class BigIntUnitTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void initTestCase();
    void cleanupTestCase();
    void allTests();

private:
    QCA::Initializer *m_init;
};

void BigIntUnitTest::initTestCase()
{
    m_init = new QCA::Initializer;
}

void BigIntUnitTest::cleanupTestCase()
{
    delete m_init;
}

void BigIntUnitTest::allTests()
{
    QCA::BigInteger result;

    // Some string conversion tests
    QCOMPARE(QCA::BigInteger("255").toString(), QCA::BigInteger(255).toString());
    QCOMPARE(QCA::BigInteger("-255").toString(), QCA::BigInteger(-255).toString());
    QCOMPARE(QCA::BigInteger("255").toString(), QStringLiteral("255"));
    QCOMPARE(QCA::BigInteger("-255").toString(), QStringLiteral("-255"));
    QCOMPARE(QCA::BigInteger("255"), QCA::BigInteger(QCA::BigInteger(255).toArray()));
    QCOMPARE(QCA::BigInteger("-255"), QCA::BigInteger(QCA::BigInteger(-255).toArray()));

    // Some operator tests
    QCOMPARE(QCA::BigInteger("255") == QCA::BigInteger(255), true);
    QCOMPARE(QCA::BigInteger("-255") == QCA::BigInteger(-255), true);
    QCOMPARE(QCA::BigInteger("256") != QCA::BigInteger(255), true);
    QCOMPARE(QCA::BigInteger("-256") != QCA::BigInteger(-255), true);

    // Some comparison tests
    QCA::BigInteger a("4000000000000");
    QCA::BigInteger b("-4000000000000");
    QCA::BigInteger c("2000000000000");
    QCOMPARE(a < b, false);
    QCOMPARE(a <= b, false);
    QCOMPARE(a.compare(b), 1);
    QCOMPARE(a > b, true);
    QCOMPARE(a >= b, true);
    QCOMPARE(a > c, true);
    QCOMPARE(c.compare(b), 1);
    QCOMPARE(c.compare(a), -1);

    // Check if the stream operator is any good
    QString     testString;
    QTextStream ts(&testString, QIODevice::WriteOnly);
    ts << a << b << c << endl;
    QCOMPARE(testString, QStringLiteral("4000000000000-40000000000002000000000000\n"));

    // Botan's addition tests
    QCOMPARE(QCA::BigInteger(255) += QCA::BigInteger(1), QCA::BigInteger(256));
    result = QCA::BigInteger(255) += QCA::BigInteger(1);
    QCOMPARE(result.toString(), QCA::BigInteger(256).toString());

    result = QCA::BigInteger("65535") += QCA::BigInteger("1");
    QCOMPARE(result.toString(), QStringLiteral("65536"));
    QCOMPARE(result, QCA::BigInteger("65536"));

    result = QCA::BigInteger("4294967295") += QCA::BigInteger(1);
    QCOMPARE(result.toString(), QStringLiteral("4294967296"));
    QCOMPARE(result, QCA::BigInteger("4294967296"));

    result = QCA::BigInteger("18446744073709551615") += QCA::BigInteger(1);
    QCOMPARE(result.toString(), QStringLiteral("18446744073709551616"));
    QCOMPARE(result, QCA::BigInteger("18446744073709551616"));

    result = QCA::BigInteger("124536363637272472") += QCA::BigInteger("124536363637272472");
    QCOMPARE(result.toString(), QStringLiteral("249072727274544944"));
    QCOMPARE(result, QCA::BigInteger("249072727274544944"));

    result = QCA::BigInteger("9223372036854775807") += QCA::BigInteger("281474976710655");
    QCOMPARE(result.toString(), QStringLiteral("9223653511831486462"));
    QCOMPARE(result, QCA::BigInteger("9223653511831486462"));

    result = QCA::BigInteger("9223372036854775807") += QCA::BigInteger("137438953471");
    QCOMPARE(result.toString(), QStringLiteral("9223372174293729278"));
    QCOMPARE(result, QCA::BigInteger("9223372174293729278"));

    // Botan's carry tests
    result = QCA::BigInteger("340282366920938463463374607431768211455") +=
        QCA::BigInteger("340282366920938463463374607431768211455");
    QCOMPARE(result.toString(), QStringLiteral("680564733841876926926749214863536422910"));
    QCOMPARE(result, QCA::BigInteger("680564733841876926926749214863536422910"));

    result = QCA::BigInteger("340282366920938463463374607431768211455") +=
        QCA::BigInteger("340282366920938463463374607431768211450");
    QCOMPARE(result.toString(), QStringLiteral("680564733841876926926749214863536422905"));
    QCOMPARE(result, QCA::BigInteger("680564733841876926926749214863536422905"));

    result = QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935") +=
        QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
    QCOMPARE(result.toString(),
             QStringLiteral("231584178474632390847141970017375815706539969331281128078915168015826259279870"));
    QCOMPARE(result, QCA::BigInteger("231584178474632390847141970017375815706539969331281128078915168015826259279870"));

    result = QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935") +=
        QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639919");
    QCOMPARE(result.toString(),
             QStringLiteral("231584178474632390847141970017375815706539969331281128078915168015826259279854"));
    QCOMPARE(result, QCA::BigInteger("231584178474632390847141970017375815706539969331281128078915168015826259279854"));

    result = QCA::BigInteger(
        "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858"
        "186486050853753882811946569946433649006084095") += QCA::BigInteger("18446744073709551616");
    QCOMPARE(result.toString(),
             QStringLiteral("134078079299425970995740249982058461274793658205923933777235614437217640300735469768018742"
                            "98166903427690031858186486050853753882811946588393177722715635711"));
    QCOMPARE(result,
             QCA::BigInteger("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874"
                             "298166903427690031858186486050853753882811946588393177722715635711"));

    result = QCA::BigInteger(
        "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858"
        "186486050853753882811946569946433649006084095") += QCA::BigInteger("1");
    QCOMPARE(result.toString(),
             QStringLiteral("134078079299425970995740249982058461274793658205923933777235614437217640300735469768018742"
                            "98166903427690031858186486050853753882811946569946433649006084096"));
    QCOMPARE(result,
             QCA::BigInteger("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874"
                             "298166903427690031858186486050853753882811946569946433649006084096"));

    result = QCA::BigInteger(
        "-3979427001391940661083482696042714676976618976483847341650296529192053560111268857919862747528477749805933030"
        "6128763345008528325994574657552726381901") += QCA::BigInteger("-342238655038");
    QCOMPARE(result.toString(),
             QStringLiteral("-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627"
                            "475284777498059330306128763345008528325994574657894965036939"));
    QCOMPARE(result,
             QCA::BigInteger("-3979427001391940661083482696042714676976618976483847341650296529192053560111268857919862"
                             "7475284777498059330306128763345008528325994574657894965036939"));

    result = QCA::BigInteger(
        "25110291853498940831251897922987678157346336093292373576945426289097725034326735312448621015537884914") +=
        QCA::BigInteger("-36551081154398645734533965739979697527373251608055056627686956281114038842935173436543461");
    QCOMPARE(
        result.toString(),
        QStringLiteral(
            "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453"));
    QCOMPARE(
        result,
        QCA::BigInteger(
            "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453"));

    result = QCA::BigInteger("27802650352") += QCA::BigInteger("660736146705288303126411072388564329913778942");
    QCOMPARE(result.toString(), QStringLiteral("660736146705288303126411072388564357716429294"));
    QCOMPARE(result, QCA::BigInteger("660736146705288303126411072388564357716429294"));

    result = QCA::BigInteger(
        "-1348245899955041864800954463709881466231496038216683608715424566397833766910915722793041224478985289") +=
        QCA::BigInteger(
            "1151714952286618235856515264359526625702022859705853911311473221800833298790436145729926116122727676438617"
            "3666571334749062651694592291882972");
    QCOMPARE(result.toString(),
             QStringLiteral("115171495228661823585651526435952662570188803511585840712499312635446231064381299612610444"
                            "77618561339819775832804423833339858653367812897683"));
    QCOMPARE(result,
             QCA::BigInteger("11517149522866182358565152643595266257018880351158584071249931263544623106438129961261044"
                             "477618561339819775832804423833339858653367812897683"));

    result = QCA::BigInteger(
        "-17540530441681616962868251635133601915039026254996886583618243914226325157426408929602625346567256761818") +=
        QCA::BigInteger("865200427983527245206901810160356641402419461642082623179544681519016990");
    QCOMPARE(result.toString(),
             QStringLiteral("-17540530441681616962868251635132736714611042727751679681808083557584922737964766846979445"
                            "801885737744828"));
    QCOMPARE(result,
             QCA::BigInteger("-1754053044168161696286825163513273671461104272775167968180808355758492273796476684697944"
                             "5801885737744828"));

    result = QCA::BigInteger("128844776074298261556398714096948603458177018275051329218555498374") += QCA::BigInteger(
        "44381631382915087636205223513461060322054892810769796122995361187369527639191715091334647906024675972047519364"
        "8");
    QCOMPARE(result.toString(),
             QStringLiteral("443816313829150876362052235134610603220548928236542737304251873430093990488865754371523497"
                            "335298088939030692022"));
    QCOMPARE(result,
             QCA::BigInteger("44381631382915087636205223513461060322054892823654273730425187343009399048886575437152349"
                             "7335298088939030692022"));

    result = QCA::BigInteger("1709484189262457846620911889502097055085989595277300243221975568275935717696463") +=
        QCA::BigInteger("-1646592344139809206374540620411514484579951199941360");
    QCOMPARE(result.toString(),
             QStringLiteral("1709484189262457846620911887855504710946180388902759622810461083695984517755103"));
    QCOMPARE(result,
             QCA::BigInteger("1709484189262457846620911887855504710946180388902759622810461083695984517755103"));

    result = QCA::BigInteger(
        "32017586542963717616570934157618710254018062780641801520492877117023353895132395250905592913967322327352806288"
        "3083030595199153877335714942842") +=
        QCA::BigInteger(
            "-2828241696960736089879965882386687935938570856545481227619497640844399275054327390050478930503975773972");
    QCOMPARE(result.toString(),
             QStringLiteral("320175865429637176165709341576187102537352386109457279115048805287846851015385381652510447"
                            "912053725632683663608028703205148674946831739168870"));
    QCOMPARE(result,
             QCA::BigInteger("32017586542963717616570934157618710253735238610945727911504880528784685101538538165251044"
                             "7912053725632683663608028703205148674946831739168870"));

    result = QCA::BigInteger(
        "-4035398360542181725908295312107496142105415014744259439963377204111754181625695349185753326709217") +=
        QCA::BigInteger("85450213703789913646546187382091037800");
    QCOMPARE(result.toString(),
             QStringLiteral(
                 "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417"));
    QCOMPARE(result,
             QCA::BigInteger(
                 "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417"));

    result = QCA::BigInteger(
        "-1292166446073479876801522363382357887431657639184151284775525387363973852756087726243671676713861533673009088"
        "319851") +=
        QCA::BigInteger(
            "8045388958745181755374994252823750582362455317985903504033438417669555720706432671419456956248951093302427"
            "49935754739434394691714971");
    QCOMPARE(result.toString(),
             QStringLiteral("804538895874518174245332979208895181434723168416232462971686202582804287295117879777971842"
                            "868807383086571073221893205761385603395120"));
    QCOMPARE(result,
             QCA::BigInteger("80453889587451817424533297920889518143472316841623246297168620258280428729511787977797184"
                             "2868807383086571073221893205761385603395120"));

    result = QCA::BigInteger(
        "-4519865887009263094594517568520056973794810149560079685292342518849465226829012150220864325970243240622408355"
        "64200177389") += QCA::BigInteger("15762983479");
    QCOMPARE(result.toString(),
             QStringLiteral("-45198658870092630945945175685200569737948101495600796852923425188494652268290121502208643"
                            "2597024324062240835548437193910"));
    QCOMPARE(result,
             QCA::BigInteger("-4519865887009263094594517568520056973794810149560079685292342518849465226829012150220864"
                             "32597024324062240835548437193910"));

    result = QCA::BigInteger(
        "-3907475412115728816974567022055278374116794025624287474334038831885743634200801846649105209920908153587891040"
        "882946582394429615396962188674594744360388466") +=
        QCA::BigInteger("193893611236537854694879677478106237157079207398283117392998175454362643521031390");
    QCOMPARE(result.toString(),
             QStringLiteral("-39074754121157288169745670220552783741167940256242874743340388318857436340069082354125673"
                            "55226028476109784803725867374996146498003964013220232100839357076"));
    QCOMPARE(result,
             QCA::BigInteger("-3907475412115728816974567022055278374116794025624287474334038831885743634006908235412567"
                             "355226028476109784803725867374996146498003964013220232100839357076"));

    result = QCA::BigInteger("-72603710637966201224690926289") +=
        QCA::BigInteger("-13618442642298533261581255034923612640512507150728017106768861506299813289801666559564532");
    QCOMPARE(
        result.toString(),
        QStringLiteral("-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821"));
    QCOMPARE(
        result,
        QCA::BigInteger("-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821"));

    result = QCA::BigInteger(
        "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111823994257399379783658853"
        "302692762256851623103019589392739") +=
        QCA::BigInteger("-427057313888431079237360487703561848638868677065083968842");
    QCOMPARE(result.toString(),
             QStringLiteral("560779608357130568314029484067907471078894467693575097594722076034839681076939970281113969"
                            "36943510948704421492814989200408212754425954505423897"));
    QCOMPARE(result,
             QCA::BigInteger("56077960835713056831402948406790747107889446769357509759472207603483968107693997028111396"
                             "936943510948704421492814989200408212754425954505423897"));

    result = QCA::BigInteger("-2209800838508504443494783762534800337712101405156784708782197580824527899758308") +=
        QCA::BigInteger(
            "4284407650303949586450021392583759850781770841835415277411207859644308960659857039623581632798746339397171"
            "0495985285591895096794994387176281079");
    QCOMPARE(result.toString(),
             QStringLiteral("428440765030394958645002139258375985078177084183541527741120785942332887680900659527410325"
                            "65452663056259609090828500883112899214169859276522771"));
    QCOMPARE(result,
             QCA::BigInteger("42844076503039495864500213925837598507817708418354152774112078594233288768090065952741032"
                             "565452663056259609090828500883112899214169859276522771"));

    result = QCA::BigInteger(
        "33887767308809826842417841176152232321272231788338404526859019370507113927387984766381329515371768224976188337"
        "692") += QCA::BigInteger("349484339542971517481628970179002500341");
    QCOMPARE(result.toString(),
             QStringLiteral("338877673088098268424178411761522323212722317883384045268590193705071139277374691059243010"
                            "32853397195155190838033"));
    QCOMPARE(result,
             QCA::BigInteger("33887767308809826842417841176152232321272231788338404526859019370507113927737469105924301"
                             "032853397195155190838033"));

    result = QCA::BigInteger(
        "85748089639858660722587321621536298082690707526412426951630101551228144063151688592419555048867068162") +=
        QCA::BigInteger("-383634567691961960211191292397062452265352651123492760493087381707279");
    QCOMPARE(
        result.toString(),
        QStringLiteral(
            "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883"));
    QCOMPARE(
        result,
        QCA::BigInteger(
            "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883"));

    result = QCA::BigInteger("23889807888563742283608049816129153552608399262924421832404872043475") +=
        QCA::BigInteger("995");
    QCOMPARE(result.toString(), QStringLiteral("23889807888563742283608049816129153552608399262924421832404872044470"));
    QCOMPARE(result, QCA::BigInteger("23889807888563742283608049816129153552608399262924421832404872044470"));

    result = QCA::BigInteger(
        "-6547869258334748646692309625826942226114726807018592624664656062396549960483067839575496977812718292577743295"
        "38985") += QCA::BigInteger("-276137507159648540503039013089014674747");
    QCOMPARE(result.toString(),
             QStringLiteral("-65478692583347486466923096258269422261147268070185926246646560623965499604858292146470934"
                            "6321774868270863344213732"));
    QCOMPARE(result,
             QCA::BigInteger("-6547869258334748646692309625826942226114726807018592624664656062396549960485829214647093"
                             "46321774868270863344213732"));

    result = QCA::BigInteger("50463316268089933") += QCA::BigInteger(
        "-1405915834634318069210003494981352875890054233189278509478942429953101385694731575213124136524392343244191305"
        "27702899917161307657443381774866237429");
    QCOMPARE(result.toString(),
             QStringLiteral("-14059158346343180692100034949813528758900542331892785094789424299531013856947315752131241"
                            "3652439234324419130527702899917161307657392918458598147496"));
    QCOMPARE(result,
             QCA::BigInteger("-1405915834634318069210003494981352875890054233189278509478942429953101385694731575213124"
                             "13652439234324419130527702899917161307657392918458598147496"));

    result = QCA::BigInteger(
        "1339015021665554488163337105187026760232395594198925052890859936\
418304234254229440059229155546157793544192") +=
        QCA::BigInteger(
            "6294037420283433712414743361937677483761554699961644450461297486224793278823004487175687771163597590566132"
            "592591599249970281125781761944353272");
    QCOMPARE(result.toString(),
             QStringLiteral("629403742028343371241474336193767748510056972162719893862463459141182003905540008137461282"
                            "4054457526984436826845828690029510281327919737897464"));
    QCOMPARE(result,
             QCA::BigInteger("62940374202834337124147433619376774851005697216271989386246345914118200390554000813746128"
                             "24054457526984436826845828690029510281327919737897464"));

    result = QCA::BigInteger("-241446683") += QCA::BigInteger(
        "-282671163032866994488211995758272717472259277760825940523445628\
442206062910449311538519756165635175664610569214430918184214");
    QCOMPARE(result.toString(),
             QStringLiteral("-28267116303286699448821199575827271747225927776082594052344562844220606291044931153851975"
                            "6165635175664610569214431159630897"));
    QCOMPARE(result,
             QCA::BigInteger("-2826711630328669944882119957582727174722592777608259405234456284422060629104493115385197"
                             "56165635175664610569214431159630897"));

    result = QCA::BigInteger(
        "23586055033034526379960814219020565159517446117183831284424451195057397075503263789123424483550462390668969955"
        "63581") +=
        QCA::BigInteger("-3830437229145325165273364525551261440648845791949681661260946956860463720730123941973615");
    QCOMPARE(result.toString(),
             QStringLiteral("235860550330345263799608141807161928680641944644501860289118367885689391560064471765139549"
                            "1494582518336773053589966"));
    QCOMPARE(result,
             QCA::BigInteger("23586055033034526379960814180716192868064194464450186028911836788568939156006447176513954"
                             "91494582518336773053589966"));

    result = QCA::BigInteger("1860794367587960058388097846258490") +=
        QCA::BigInteger("-237344494507203983863096991896035366478949095337787603280");
    QCOMPARE(result.toString(), QStringLiteral("-237344494507203983863095131101667778518890707239941344790"));
    QCOMPARE(result, QCA::BigInteger("-237344494507203983863095131101667778518890707239941344790"));

    result = QCA::BigInteger("-286399096802321907543674770412181810379003627366516307780436082546") +=
        QCA::BigInteger("6433131620680089024037442172197761714707480582555136398379812339597187475099646442833150194");
    QCOMPARE(
        result.toString(),
        QStringLiteral("6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648"));
    QCOMPARE(
        result,
        QCA::BigInteger("6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648"));

    result = QCA::BigInteger(
        "18118033907710236955953781758362789478332280418185972957475244257214680056902377349016498752054120312533829578"
        "5763244283224569259250011493") +=
        QCA::BigInteger(
            "-119912766577350317025030707802803587547945939765717835695952624506754949712992302334818793328075301820498"
            "3010837846725666878521137637491");
    QCOMPARE(result.toString(),
             QStringLiteral("179981211411328866389287510505599858907843344784202551217792916327079251071893850466816799"
                            "587260450107133312774925397557557690738112374002"));
    QCOMPARE(result,
             QCA::BigInteger("17998121141132886638928751050559985890784334478420255121779291632707925107189385046681679"
                             "9587260450107133312774925397557557690738112374002"));

    result = QCA::BigInteger(
        "-6414020139555553381140864289162018465205127581107592617628203214491558550345077676836677565241902214951203461"
        "1311149858695307750874152") += QCA::BigInteger("174441039");
    QCOMPARE(result.toString(),
             QStringLiteral("-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775"
                            "652419022149512034611311149858695307576433113"));
    QCOMPARE(result,
             QCA::BigInteger("-6414020139555553381140864289162018465205127581107592617628203214491558550345077676836677"
                             "5652419022149512034611311149858695307576433113"));

    result = QCA::BigInteger(
        "12727579443088358572080378780185073375305574454222304955616346165037244198775127175123602392596401935136013522"
        "02821462208896049331599624285621") +=
        QCA::BigInteger(
            "7326562354017884140300121264633612334070903165496641915889499701\
38457507491850467631029977010");
    QCOMPARE(result.toString(),
             QStringLiteral("127275794430883585720803787801850733753055744542296315179703640491775443200397607874576732"
                            "9576189857705190302172959919716387899799230654262631"));
    QCOMPARE(result,
             QCA::BigInteger("12727579443088358572080378780185073375305574454229631517970364049177544320039760787457673"
                             "29576189857705190302172959919716387899799230654262631"));

    result = QCA::BigInteger("-296171972628230") += QCA::BigInteger(
        "-8295766099121843219000823699362222865173820102569731517716391727126741710202086962877467940292139");
    QCOMPARE(result.toString(),
             QStringLiteral(
                 "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369"));
    QCOMPARE(result,
             QCA::BigInteger(
                 "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369"));

    result = QCA::BigInteger("746985914068199510024843682108839444828414222769191520615967632362127522466922882591") +=
        QCA::BigInteger("-20487191102299831461877807785745372724903547246374023");
    QCOMPARE(result.toString(),
             QStringLiteral("746985914068199510024843682108818957637311922937729642808181886989402618919676508568"));
    QCOMPARE(result,
             QCA::BigInteger("746985914068199510024843682108818957637311922937729642808181886989402618919676508568"));

    result = QCA::BigInteger("-4") +=
        QCA::BigInteger("-2344390090753264806043234960981151613122271366762590006930318876906455201397017135");
    QCOMPARE(result.toString(),
             QStringLiteral("-2344390090753264806043234960981151613122271366762590006930318876906455201397017139"));
    QCOMPARE(result,
             QCA::BigInteger("-2344390090753264806043234960981151613122271366762590006930318876906455201397017139"));

    result = QCA::BigInteger("-44876180273995737337769331875058141129678736711749946388832275767882143882764") +=
        QCA::BigInteger("20982187786");
    QCOMPARE(result.toString(),
             QStringLiteral("-44876180273995737337769331875058141129678736711749946388832275767861161694978"));
    QCOMPARE(result, QCA::BigInteger("-44876180273995737337769331875058141129678736711749946388832275767861161694978"));

    result = QCA::BigInteger(
        "-601944008264824351134005823298148744369561537910415436895793990789678217920719566630222862549689727198849"
        "4") +=
        QCA::BigInteger(
            "532566302499155416003316607801593784583652720754079760364736422291735917382015688217276924340984564880");
    QCOMPARE(result.toString(),
             QStringLiteral("-60189075163457443559240549163736858499110317263834002891975751714744904432898136506140113"
                            "48572556287423614"));
    QCOMPARE(result,
             QCA::BigInteger("-6018907516345744355924054916373685849911031726383400289197575171474490443289813650614011"
                             "348572556287423614"));

    result = QCA::BigInteger(
        "-7375547156361602684772634935716753083385095966292105905292822923781472871944886871927821129478599825311797681"
        "2683153264088230182865250970217610487") +=
        QCA::BigInteger("-30100016097092378349958946184353117306134810372681");
    QCOMPARE(result.toString(),
             QStringLiteral("-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211"
                            "294786028353134073905061503223034414535982557105027983168"));
    QCOMPARE(result,
             QCA::BigInteger("-7375547156361602684772634935716753083385095966292105905292822923781472871944886871927821"
                             "1294786028353134073905061503223034414535982557105027983168"));

    result = QCA::BigInteger(
        "-2211177066689704345686852756638946306674958952044447080285364283965878599873864667094550865713828159912") +=
        QCA::BigInteger(
            "-536556043937245689200756579876160678199726920153847573681478030051738396345585808165230823703346036004092"
            "1820049494698892905680307378540208");
    QCOMPARE(result.toString(),
             QStringLiteral("-53655604393724568920075657987616067842084462682281800825016330571563302701308170336967553"
                            "17318824644006800419923359365987456546021206700120"));
    QCOMPARE(result,
             QCA::BigInteger("-5365560439372456892007565798761606784208446268228180082501633057156330270130817033696755"
                             "317318824644006800419923359365987456546021206700120"));

    result = QCA::BigInteger(
        "60741225123371088419685216490350768416336915742544171041442859708190687151580370231498672521465704184848502349"
        "79838064249373816163440") += QCA::BigInteger("301843614094506325875637699");
    QCOMPARE(result.toString(),
             QStringLiteral("607412251233710884196852164903507684163369157425441710414428597081906871515803702314986725"
                            "2146570418484850536823452158755699691801139"));
    QCOMPARE(result,
             QCA::BigInteger("60741225123371088419685216490350768416336915742544171041442859708190687151580370231498672"
                             "52146570418484850536823452158755699691801139"));

    result = QCA::BigInteger(
        "-5182147769311581499087713405643489820105439851080650534792191527346598920424997741288096547136515478330872068"
        "93256740737426200715673766732196603988") +=
        QCA::BigInteger(
            "-2983517255774769372611552588738613700467454531142255734565888403876035392822615770224917521828071895197"
            "9");
    QCOMPARE(result.toString(),
             QStringLiteral("-51821477693115814990877134056434898201054401494323761122691287885018577942863677880335496"
                            "6136208893491971245653610668963583902964848985012915555967"));
    QCOMPARE(result,
             QCA::BigInteger("-5182147769311581499087713405643489820105440149432376112269128788501857794286367788033549"
                             "66136208893491971245653610668963583902964848985012915555967"));

    result = QCA::BigInteger("15937412249227240968245047444122") += QCA::BigInteger(
        "186214680376169426108822450700978827886569053440254258585576645530381613666540347032550716844628275956253");
    QCOMPARE(result.toString(),
             QStringLiteral("186214680376169426108822450700978827886569053440254258585576645530381613682477759281777957"
                            "812873323400375"));
    QCOMPARE(result,
             QCA::BigInteger("18621468037616942610882245070097882788656905344025425858557664553038161368247775928177795"
                             "7812873323400375"));

    result = QCA::BigInteger(
        "-1252801011625868585504750425292810762392310545870176170791196952700385571348584614055110796749581358409708177"
        "7160") +=
        QCA::BigInteger(
            "-539986280927242338236008809854961759996986302156061552378097160849129372827386927545686899193598721998757"
            "419572890");
    QCOMPARE(result.toString(),
             QStringLiteral("-55251429104350102409105631410788986762090940761476331408600913037613322854087277368623800"
                            "7161094535582854501350050"));
    QCOMPARE(result,
             QCA::BigInteger("-5525142910435010240910563141078898676209094076147633140860091303761332285408727736862380"
                             "07161094535582854501350050"));

    result = QCA::BigInteger("-2454746908") += QCA::BigInteger(
        "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626"
        "913419699098985245833920954444218");
    QCOMPARE(result.toString(),
             QStringLiteral("-38229571278893947800552421563603701870755920786555523760506046799344150145738795138700302"
                            "11860839641756441626913419699098985245833923409191126"));
    QCOMPARE(result,
             QCA::BigInteger("-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030"
                             "211860839641756441626913419699098985245833923409191126"));

    result = QCA::BigInteger("-54288706131860071583318409080596095357980447323635") += QCA::BigInteger(
        "-4253394105560156310989737429933273230514384568190270696062942611579402976432972405594521244327792021815897638"
        "74");
    QCOMPARE(result.toString(),
             QStringLiteral("-42533941055601563109897374299332732305143845681902706960629431544664642950336882387786120"
                            "5028874560162037087509"));
    QCOMPARE(result,
             QCA::BigInteger("-4253394105560156310989737429933273230514384568190270696062943154466464295033688238778612"
                             "05028874560162037087509"));

    result = QCA::BigInteger(
        "1418766894051319870818496026367686195459604395660119754151922014257535705077512233275240217434104") +=
        QCA::BigInteger("-111987390206074845527");
    QCOMPARE(result.toString(),
             QStringLiteral(
                 "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577"));
    QCOMPARE(result,
             QCA::BigInteger(
                 "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577"));

    result = QCA::BigInteger(
        "-6904101318604104774561038575945435154096774792428336186348093024529626004763532868225501682312348541164651530"
        "78845744722987447719420052500874721214723") +=
        QCA::BigInteger(
            "-258469037743394674731135699243278836145549479106673938483740960989738710973653960062315588091814633168127"
            "2708396146283818299");
    QCOMPARE(result.toString(),
             QStringLiteral("-69041013186041047745610386017923389284362422655419061106759766390845739154309267165995977"
                            "8128621963853004753702001625641133779400692760897021005033022"));
    QCOMPARE(result,
             QCA::BigInteger("-6904101318604104774561038601792338928436242265541906110675976639084573915430926716599597"
                             "78128621963853004753702001625641133779400692760897021005033022"));

    result = QCA::BigInteger("-2326153002179462643778624079324592172489363679671158") +=
        QCA::BigInteger("-109819757548464054181938329012610459679");
    QCOMPARE(result.toString(), QStringLiteral("-2326153002179572463536172543378774110818376290130837"));
    QCOMPARE(result, QCA::BigInteger("-2326153002179572463536172543378774110818376290130837"));

    result = QCA::BigInteger(
        "-4428752250566525488353857709194941742993785578807911414016959206453045495320705299466107784149485981354180907"
        "411034982168391") +=
        QCA::BigInteger(
            "-39247778259374215325521768005388007526581235832446540589720560855741992694947322437679214611686905696");
    QCOMPARE(result.toString(),
             QStringLiteral("-44287522505665254883538969569732011172091111005759168020244857876888779418612950200269635"
                            "26142180928676618586625646669074087"));
    QCOMPARE(result,
             QCA::BigInteger("-4428752250566525488353896956973201117209111100575916802024485787688877941861295020026963"
                             "526142180928676618586625646669074087"));

    result = QCA::BigInteger("3047") += QCA::BigInteger(
        "-7356458785031315352377693216371961073343377689039020461804017379719600010085607082927794304834315616579528230"
        "7508135277641315214");
    QCOMPARE(result.toString(),
             QStringLiteral("-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943"
                            "048343156165795282307508135277641312167"));
    QCOMPARE(result,
             QCA::BigInteger("-7356458785031315352377693216371961073343377689039020461804017379719600010085607082927794"
                             "3048343156165795282307508135277641312167"));

    result = QCA::BigInteger(
        "71397189765381049110362731262243394989390499523719445987286843598407339615555456955143712741779487184644001767"
        "776382991377987516772847242986") +=
        QCA::BigInteger("-5821969555717973232123574849275726788359152255219972775831");
    QCOMPARE(result.toString(),
             QStringLiteral("713971897653810491103627312622433949893904995237194459872868435984073396155554569493217431"
                            "86061513952520426918500656203018835261552874467155"));
    QCOMPARE(result,
             QCA::BigInteger("71397189765381049110362731262243394989390499523719445987286843598407339615555456949321743"
                             "186061513952520426918500656203018835261552874467155"));

    result = QCA::BigInteger(
        "-1814097526566131387779640926359093790218263603909606471867269911652274001767668314665411600499352055079190702"
        "33410228328274") +=
        QCA::BigInteger(
            "-523301382154855044703947051892202646490840761177533623732372519689918420769842424772676407501350528096714"
            "904915297347684247802773107355881667545916901");
    QCOMPARE(result.toString(),
             QStringLiteral("-52330138215485504470394705207361239914745389995549771636828189871174478116080307195940339"
                            "8666577928273481736381838507734183008281026426115077774245175"));
    QCOMPARE(result,
             QCA::BigInteger("-5233013821548550447039470520736123991474538999554977163682818987117447811608030719594033"
                             "98666577928273481736381838507734183008281026426115077774245175"));

    result = QCA::BigInteger("6858961373707073067") += QCA::BigInteger(
        "-3340515089338930614338442797642711071819749062833649913099030776499716064369180713270728698264719460945945941"
        "15614990907");
    QCOMPARE(result.toString(),
             QStringLiteral("-33405150893389306143384427976427110718197490628336499130990307764997160643691807132707286"
                            "9826471946087735632741907917840"));
    QCOMPARE(result,
             QCA::BigInteger("-3340515089338930614338442797642711071819749062833649913099030776499716064369180713270728"
                             "69826471946087735632741907917840"));

    result = QCA::BigInteger(
        "-23635098930374569407171906960429616870908424281519944658490940109956689534874971218650241680916564611") +=
        QCA::BigInteger(
            "-189589178757795228335995891331428279524485393011427187469792714438466702359827437934396866267364281985416"
            "47202983677887505430060922528525205");
    QCOMPARE(result.toString(),
             QStringLiteral("-18958917875779522833599589133142827952472174400073093316386443350807099852853652217721206"
                            "571394919138651603892518552858724080302603445089816"));
    QCOMPARE(result,
             QCA::BigInteger("-1895891787577952283359958913314282795247217440007309331638644335080709985285365221772120"
                             "6571394919138651603892518552858724080302603445089816"));

    // Botan's subtraction tests
    result = QCA::BigInteger("0") -= QCA::BigInteger("0");
    QCOMPARE(result.toString(), QStringLiteral("0"));
    QCOMPARE(result, QCA::BigInteger("0"));

    result = QCA::BigInteger("0") -= QCA::BigInteger("1");
    QCOMPARE(result.toString(), QStringLiteral("-1"));
    QCOMPARE(result, QCA::BigInteger("-1"));

    result = QCA::BigInteger("0") -= QCA::BigInteger("4294967296");
    QCOMPARE(result.toString(), QStringLiteral("-4294967296"));
    QCOMPARE(result, QCA::BigInteger("-4294967296"));

    // Next test is labelled # 2^512 - 1
    result = QCA::BigInteger(
        "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858"
        "186486050853753882811946569946433649006084095") -= QCA::BigInteger("1");
    QCOMPARE(result.toString(),
             QStringLiteral("134078079299425970995740249982058461274793658205923933777235614437217640300735469768018742"
                            "98166903427690031858186486050853753882811946569946433649006084094"));
    QCOMPARE(result,
             QCA::BigInteger("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874"
                             "298166903427690031858186486050853753882811946569946433649006084094"));

    result = QCA::BigInteger("89094716573076464980713547115099137014719483620102078148320806773871083148864") -=
        QCA::BigInteger("49505213825110728957828173754776257356620450607893971553289366249708672306581");
    QCOMPARE(result.toString(),
             QStringLiteral("39589502747965736022885373360322879658099033012208106595031440524162410842283"));
    QCOMPARE(result, QCA::BigInteger("39589502747965736022885373360322879658099033012208106595031440524162410842283"));

    result = QCA::BigInteger("65894747009896006767807716946835412110318548717263922395390971078905789585431") -=
        QCA::BigInteger("3884269741925508225990715416862047284194603799902650748631039608684367281358");
    QCOMPARE(result.toString(),
             QStringLiteral("62010477267970498541817001529973364826123944917361271646759931470221422304073"));
    QCOMPARE(result, QCA::BigInteger("62010477267970498541817001529973364826123944917361271646759931470221422304073"));

    result = QCA::BigInteger(
        "59501963964519775669021213017070542183647171968931013600114917777619522537369647091659626133477106071641786829"
        "87783755894811024288429224592316636383") -=
        QCA::BigInteger(
            "8750653273562160761286422180115618621879821429145276197424652349306577311499807887070429373153777028581165"
            "316131683348567");
    QCOMPARE(result.toString(),
             QStringLiteral("595019639645197756690212129295640094480255643560667917989587315588213082459168851174131026"
                            "4041133295664370795917354382741033995707263908460633287816"));
    QCOMPARE(result,
             QCA::BigInteger("59501963964519775669021212929564009448025564356066791798958731558821308245916885117413102"
                             "64041133295664370795917354382741033995707263908460633287816"));

    result = QCA::BigInteger("9815262808265519920770782360080149146267723690") -= QCA::BigInteger(
        "14067005768891609281364919358115291341352189918255780397560060748765650205261663193732434161580120817");
    QCOMPARE(
        result.toString(),
        QStringLiteral(
            "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127"));
    QCOMPARE(
        result,
        QCA::BigInteger(
            "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127"));

    result = QCA::BigInteger(
        "-3901491029419486215684797223469406667043760137344853438401542216058534125031549938788864908670209347775308945"
        "93416337175399865065870417717658815158195790") -=
        QCA::BigInteger("1456031684988128870809574635750149625240648487837308");
    QCOMPARE(result.toString(),
             QStringLiteral("-39014910294194862156847972234694066670437601373448534384015422160585341250315499387888649"
                            "0867020934778986926278404466046209439701620567342899463646033098"));
    QCOMPARE(result,
             QCA::BigInteger("-3901491029419486215684797223469406667043760137344853438401542216058534125031549938788864"
                             "90867020934778986926278404466046209439701620567342899463646033098"));

    result = QCA::BigInteger("7473774301764883450943") -=
        QCA::BigInteger("-26256369859367890755157372820052387483402723790185562908491933812453");
    QCOMPARE(result.toString(), QStringLiteral("26256369859367890755157372820052387483402723797659337210256817263396"));
    QCOMPARE(result, QCA::BigInteger("26256369859367890755157372820052387483402723797659337210256817263396"));

    result = QCA::BigInteger(
        "36246343251214922024139186757009148849295485593397952003237349660142296147421019916619944353877490544706223768"
        "684758263065399016597969") -=
        QCA::BigInteger(
            "2574427901445527995149185461475228850098549655325125750771680756403104624569522792792597223218143154924988"
            "199562355517064962665954307425375180");
    QCOMPARE(result.toString(),
             QStringLiteral("-25744278651991847439342634373360420930894008060296401573737287531657549644272266453715773"
                            "06598198801047497654856131748380204402888908408777211"));
    QCOMPARE(result,
             QCA::BigInteger("-2574427865199184743934263437336042093089400806029640157373728753165754964427226645371577"
                             "306598198801047497654856131748380204402888908408777211"));

    result = QCA::BigInteger("30129746266682790628283889040897642317014108334116727") -=
        QCA::BigInteger("-1580480523895398762563721715474380903630073871362143915864398724834897608423");
    QCOMPARE(result.toString(),
             QStringLiteral("1580480523895398762563751845220647586420702155251184813506715738943231725150"));
    QCOMPARE(result, QCA::BigInteger("1580480523895398762563751845220647586420702155251184813506715738943231725150"));

    result = QCA::BigInteger("-4614735863800137951667138933166372061") -=
        QCA::BigInteger("87175694379075561307234146162193190462135078700346746992273");
    QCOMPARE(result.toString(), QStringLiteral("-87175694379075561307238760898056990600086745839279913364334"));
    QCOMPARE(result, QCA::BigInteger("-87175694379075561307238760898056990600086745839279913364334"));

    result = QCA::BigInteger("-3753904") -= QCA::BigInteger("-11269137783745339515071988205310702154422777729974");
    QCOMPARE(result.toString(), QStringLiteral("11269137783745339515071988205310702154422773976070"));
    QCOMPARE(result, QCA::BigInteger("11269137783745339515071988205310702154422773976070"));

    result = QCA::BigInteger(
        "59252394849537944008202127973817008840291885845547005014065278717183005886493293990079450595543785692690297587"
        "0288") -= QCA::BigInteger("-205854658295495452479104108497931263758143158076949293929661651111");
    QCOMPARE(result.toString(),
             QStringLiteral("592523948495379440082021279738170088402918858455675904798948282624309162973430871164552649"
                            "113514806220832637521399"));
    QCOMPARE(result,
             QCA::BigInteger("59252394849537944008202127973817008840291885845567590479894828262430916297343087116455264"
                             "9113514806220832637521399"));

    result = QCA::BigInteger("-33993701617495591491176844355") -= QCA::BigInteger(
        "3438065097398894672826284379125235190693300918673662774192379185002391232383325160416036963599856704698280");
    QCOMPARE(result.toString(),
             QStringLiteral("-34380650973988946728262843791252351906933009186736627741923791850023912323833591541176544"
                            "59191347881542635"));
    QCOMPARE(result,
             QCA::BigInteger("-3438065097398894672826284379125235190693300918673662774192379185002391232383359154117654"
                             "459191347881542635"));

    result = QCA::BigInteger("26876428790838270949718735111909136008255051776703") -= QCA::BigInteger(
        "-1781128112966810373286192008831149275546995635268767241859967609117529616872536681035700534316457543887601645"
        "022");
    QCOMPARE(result.toString(),
             QStringLiteral("178112811296681037328619200883114927554699563526876724185996763599395840771080763075443564"
                            "6225593552142653421725"));
    QCOMPARE(result,
             QCA::BigInteger("17811281129668103732861920088311492755469956352687672418599676359939584077108076307544356"
                             "46225593552142653421725"));

    result = QCA::BigInteger(
        "2059771092932179758019770618974659367350250375647433386639519387\
69317693429941871882153770641334267205446421916220398066553188") -=
        QCA::BigInteger("3342500267594994347156312297990633112620923791590960237694328174171473763026");
    QCOMPARE(result.toString(),
             QStringLiteral("205977109293217975801977061897465936735025037564739996163684343774970537117643881249041149"
                            "717542676245208727588046226592790162"));
    QCOMPARE(result,
             QCA::BigInteger("20597710929321797580197706189746593673502503756473999616368434377497053711764388124904114"
                             "9717542676245208727588046226592790162"));

    result = QCA::BigInteger("5545520403000578843599072515870982842927227412121917598877293331575380404618111609") -=
        QCA::BigInteger("5991287327241003718821424770352575362437680738923552868139860461945460339860477495902");
    QCOMPARE(result.toString(),
             QStringLiteral("-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293"));
    QCOMPARE(result,
             QCA::BigInteger("-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293"));

    result = QCA::BigInteger("248039029608125071340") -= QCA::BigInteger("3664608673");
    QCOMPARE(result.toString(), QStringLiteral("248039029604460462667"));
    QCOMPARE(result, QCA::BigInteger("248039029604460462667"));

    result = QCA::BigInteger("15425705711415937103627") -= QCA::BigInteger(
        "-1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229738262235546179"
        "779885824");
    QCOMPARE(result.toString(),
             QStringLiteral("143550406551774570344004527686898291075408140547412300376755421113283742784696343562152381"
                            "0229753687941257595716989451"));
    QCOMPARE(result,
             QCA::BigInteger("14355040655177457034400452768689829107540814054741230037675542111328374278469634356215238"
                             "10229753687941257595716989451"));

    result = QCA::BigInteger("50882847205108645607281568922683652688671738236030732914347600821086") -=
        QCA::BigInteger("12176160963158");
    QCOMPARE(result.toString(), QStringLiteral("50882847205108645607281568922683652688671738236030732902171439857928"));
    QCOMPARE(result, QCA::BigInteger("50882847205108645607281568922683652688671738236030732902171439857928"));

    result = QCA::BigInteger(
        "-3542651856598581894767004787703302288554217246197356622850977105341631254320181588119095376220762923216041205"
        "8300173038824256783171761132") -=
        QCA::BigInteger("-4864862607366468843184694353123830534588538011093812418208808135799");
    QCOMPARE(result.toString(),
             QStringLiteral("-35426518565985818947670047877033022885542172461973566228509771053416307678339208514722110"
                            "577513276108329877469762161945011838574363625333"));
    QCOMPARE(result,
             QCA::BigInteger("-3542651856598581894767004787703302288554217246197356622850977105341630767833920851472211"
                             "0577513276108329877469762161945011838574363625333"));

    result = QCA::BigInteger(
        "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599921571184") -=
        QCA::BigInteger("-4054101");
    QCOMPARE(result.toString(),
             QStringLiteral(
                 "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083"));
    QCOMPARE(result,
             QCA::BigInteger(
                 "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083"));

    result = QCA::BigInteger("-200931") -= QCA::BigInteger(
        "-4455880246013049575948283291316071779115178672557051947544960765970517168228311149083493083504573514296684748"
        "3009157514950177565952218520297258834187372");
    QCOMPARE(result.toString(),
             QStringLiteral("445588024601304957594828329131607177911517867255705194754496076597051716822831114908349308"
                            "35045735142966847483009157514950177565952218520297258833986441"));
    QCOMPARE(result,
             QCA::BigInteger("44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930"
                             "835045735142966847483009157514950177565952218520297258833986441"));

    result = QCA::BigInteger("105704314890799915321259") -= QCA::BigInteger(
        "82792354594507641557491243849916981441456306687749410083165776119049069747385436947778487411878749535140554980"
        "3329615347120938123226038208");
    QCOMPARE(result.toString(),
             QStringLiteral("-82792354594507641557491243849916981441456306687749410083165776119049069747385436947778487"
                            "4118787495351405549803329509642806047323310716949"));
    QCOMPARE(result,
             QCA::BigInteger("-8279235459450764155749124384991698144145630668774941008316577611904906974738543694777848"
                             "74118787495351405549803329509642806047323310716949"));

    result = QCA::BigInteger("1448979433940064018828919290452280235308901982649341") -=
        QCA::BigInteger("303926827425887072291878308433008512899006711759770318009");
    QCOMPARE(result.toString(), QStringLiteral("-303925378446453132227859479513718060618771402857787668668"));
    QCOMPARE(result, QCA::BigInteger("-303925378446453132227859479513718060618771402857787668668"));

    result = QCA::BigInteger("-243237595290235750457450892290434789864") -= QCA::BigInteger(
        "19817702076334276402981273067417321098467533300947463865383702005126562800253466403934608765512316565811954342"
        "319565128573969");
    QCOMPARE(result.toString(),
             QStringLiteral("-19817702076334276402981273067417321098467533300947463865383702005126562800253466403934852"
                            "003107606801562411793211855563363833"));
    QCOMPARE(result,
             QCA::BigInteger("-1981770207633427640298127306741732109846753330094746386538370200512656280025346640393485"
                             "2003107606801562411793211855563363833"));

    result = QCA::BigInteger("294037338365659932242802023634") -=
        QCA::BigInteger("4401245995535867764294876849802142926077599828776505639975554254356763769548465");
    QCOMPARE(result.toString(),
             QStringLiteral("-4401245995535867764294876849802142926077599828776211602637188594424520967524831"));
    QCOMPARE(result,
             QCA::BigInteger("-4401245995535867764294876849802142926077599828776211602637188594424520967524831"));

    result = QCA::BigInteger("7303853946195223307036710881687367004566538357189824031021831088365362") -=
        QCA::BigInteger("119286025999378935715794641163321741");
    QCOMPARE(result.toString(),
             QStringLiteral("7303853946195223307036710881687366885280512357810888315227189925043621"));
    QCOMPARE(result, QCA::BigInteger("7303853946195223307036710881687366885280512357810888315227189925043621"));

    result =
        QCA::BigInteger("571167355343287235687602610714110416067426289363505412908804940696550592413192300554016875") -=
        QCA::BigInteger("15872188842802631759540597");
    QCOMPARE(
        result.toString(),
        QStringLiteral("571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278"));
    QCOMPARE(
        result,
        QCA::BigInteger("571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278"));

    result = QCA::BigInteger("1002240129784524388754179399598974973256811336031329881209395070412702275169416754240") -=
        QCA::BigInteger(
            "5942948247886059134314539354042003351647830595287234900671578947794647475365720680007051520796770907993342"
            "0746952");
    QCOMPARE(result.toString(),
             QStringLiteral("-59429482478860591343145393539417793386693781564118169607116814504689663417625876918861120"
                            "137555006804764003992712"));
    QCOMPARE(result,
             QCA::BigInteger("-5942948247886059134314539353941779338669378156411816960711681450468966341762587691886112"
                             "0137555006804764003992712"));

    result = QCA::BigInteger(
        "1370431648825444838359719050380239722263203134555431526491525074601463042144798545817957389") -=
        QCA::BigInteger("3473869878");
    QCOMPARE(
        result.toString(),
        QStringLiteral("1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511"));
    QCOMPARE(
        result,
        QCA::BigInteger("1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511"));

    result = QCA::BigInteger("8548280229254726209") -=
        QCA::BigInteger("33066125035269904981849320434016892734943145935582141989968280846973981913056248918");
    QCOMPARE(result.toString(),
             QStringLiteral("-33066125035269904981849320434016892734943145935582141989968280838425701683801522709"));
    QCOMPARE(result,
             QCA::BigInteger("-33066125035269904981849320434016892734943145935582141989968280838425701683801522709"));

    result = QCA::BigInteger(
        "-1902355883268750648950815079596633217599012996302992895858417011175963029327693964733408210016910253836443785"
        "9846398095065171936899503") -=
        QCA::BigInteger(
            "2489927112752354534228346876280965340763863196622012469575197689419310377944305084304077119122752284308807"
            "9031762445684377195650493065096847292797");
    QCOMPARE(result.toString(),
             QStringLiteral("-24899271127542568901116156269299161558434598298396114825715006823151687949554810473334048"
                            "130874856925188248134300810122237042048588130268784192300"));
    QCOMPARE(result,
             QCA::BigInteger("-2489927112754256890111615626929916155843459829839611482571500682315168794955481047333404"
                             "8130874856925188248134300810122237042048588130268784192300"));

    result = QCA::BigInteger(
        "-1800353575522706389288305623797196690530870204356722928042061228497437075035917720399302198953687023") -=
        QCA::BigInteger(
            "-118756682615304660537085387309407764121711064830726245327571774713841280164583325446427884047654699244961"
            "27460164");
    QCOMPARE(result.toString(),
             QStringLiteral("118756682615286657001330160245514881065473092863820936625528207484560859552298351075677524"
                            "87045070622297173773141"));
    QCOMPARE(result,
             QCA::BigInteger("11875668261528665700133016024551488106547309286382093662552820748456085955229835107567752"
                             "487045070622297173773141"));

    result = QCA::BigInteger("-29861551039945217879") -= QCA::BigInteger(
        "11134730259168556423534561466475429305816690823484096396972829608778892265003199963808382325823762328728689476"
        "24793789212829885934");
    QCOMPARE(result.toString(),
             QStringLiteral("-11134730259168556423534561466475429305816690823484096396972829608778892265003199963808382"
                            "32582376232872868947654655340252775103813"));
    QCOMPARE(result,
             QCA::BigInteger("-1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838"
                             "232582376232872868947654655340252775103813"));

    result = QCA::BigInteger(
        "56553296365676115383821827756495791765870729764975792067630330165532810366551228779710851013983764350649164198"
        "7188791892506290") -= QCA::BigInteger("-2188105671531473889939411772533707");
    QCOMPARE(result.toString(),
             QStringLiteral("565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510"
                            "142025749178023115877128203665039997"));
    QCOMPARE(result,
             QCA::BigInteger("56553296365676115383821827756495791765870729764975792067630330165532810366551228779710851"
                             "0142025749178023115877128203665039997"));

    result = QCA::BigInteger("-349535960680522202843083381184496349093812380954435872337802226") -=
        QCA::BigInteger("-1829600726218222026679938");
    QCOMPARE(result.toString(), QStringLiteral("-349535960680522202843083381184496349091982780228217650311122288"));
    QCOMPARE(result, QCA::BigInteger("-349535960680522202843083381184496349091982780228217650311122288"));

    result = QCA::BigInteger("-1") -= QCA::BigInteger("-6726974989587128275");
    QCOMPARE(result.toString(), QStringLiteral("6726974989587128274"));
    QCOMPARE(result, QCA::BigInteger("6726974989587128274"));

    result = QCA::BigInteger("-107142709838121196902389095205618516687047338619382145236348309762148611647954748824") -=
        QCA::BigInteger("42484103615491");
    QCOMPARE(result.toString(),
             QStringLiteral("-107142709838121196902389095205618516687047338619382145236348309762148654132058364315"));
    QCOMPARE(result,
             QCA::BigInteger("-107142709838121196902389095205618516687047338619382145236348309762148654132058364315"));

    result =
        QCA::BigInteger("-90546630430085769764839607528116121381848878494574360812027599640018921358040178215575723") -=
        QCA::BigInteger(
            "-118922408531468986902800063237122125617455464103913195171141030774109638861272017660698580914239435114280"
            "434761425243");
    QCOMPARE(result.toString(),
             QStringLiteral("118922408531468986902800063146575495187369694339073587643024909392260760366697656848670981"
                            "274220513756240256545849520"));
    QCOMPARE(result,
             QCA::BigInteger("11892240853146898690280006314657549518736969433907358764302490939226076036669765684867098"
                             "1274220513756240256545849520"));

    result = QCA::BigInteger(
        "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360432363387"
        "213743735507218270373633222520429") -= QCA::BigInteger("-151423255459028627628896755237194376177115");
    QCOMPARE(result.toString(),
             QStringLiteral("-55450446670824271288017264167276573600015884301135781828506575730632419398825703245730862"
                            "67287272360280940131754715107878321515136438846343314"));
    QCOMPARE(result,
             QCA::BigInteger("-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086"
                             "267287272360280940131754715107878321515136438846343314"));

    result = QCA::BigInteger("-5247636471953421659649611318164848102069") -=
        QCA::BigInteger("-4024324110573096565232590473170599175885004");
    QCOMPARE(result.toString(), QStringLiteral("4019076474101143143572940861852434327782935"));
    QCOMPARE(result, QCA::BigInteger("4019076474101143143572940861852434327782935"));

    result = QCA::BigInteger("39412892606015043322484854253879371723186457838590224795040178472832") -=
        QCA::BigInteger("-5038321321957452145034687815432890684825466579123474921848465393400312");
    QCOMPARE(result.toString(),
             QStringLiteral("5077734214563467188357172669686770056548653036962065146643505571873144"));
    QCOMPARE(result, QCA::BigInteger("5077734214563467188357172669686770056548653036962065146643505571873144"));

    result = QCA::BigInteger(
        "-5597941458800922703568362450520876675318746972779964027720427420784331758329273633391278382952827027264258300"
        "4969175230274821") -=
        QCA::BigInteger(
            "-109633110576212669339535976775635762395927171313557427036242111476016398579345366908401334025571265714128"
            "108308032073779442181369365924213118258269679");
    QCOMPARE(result.toString(),
             QStringLiteral("109633110576212669339535920796221174386700135629932921827475358288546670779705089704127126"
                            "182253682421391774395248244251171908726782919243943027994858"));
    QCOMPARE(result,
             QCA::BigInteger("10963311057621266933953592079622117438670013562993292182747535828854667077970508970412712"
                             "6182253682421391774395248244251171908726782919243943027994858"));

    result =
        QCA::BigInteger("-38752353898173389347479216285772999906325286421302866854350737050533204094183249691110") -=
        QCA::BigInteger(
            "2428819407377764342156426895396654728835493564788997075896393065230009911546390816091652653701035085361");
    QCOMPARE(result.toString(),
             QStringLiteral("-24288194073777643809087807935700440763147098505619969822216794865328767658971278666248567"
                            "47884284776471"));
    QCOMPARE(result,
             QCA::BigInteger("-2428819407377764380908780793570044076314709850561996982221679486532876765897127866624856"
                             "747884284776471"));

    result = QCA::BigInteger("-2784579005241382005249492720344") -=
        QCA::BigInteger("-164204542616919252351131740123094674");
    QCOMPARE(result.toString(), QStringLiteral("164201758037914010969126490630374330"));
    QCOMPARE(result, QCA::BigInteger("164201758037914010969126490630374330"));

    result = QCA::BigInteger("200948857420871544747808060972375039052401280822505804851732868100") -=
        QCA::BigInteger("-795957177479360455258269298038670876462147576765875895105714");
    QCOMPARE(result.toString(), QStringLiteral("200949653378049024108263319241673077723277742970082570727627973814"));
    QCOMPARE(result, QCA::BigInteger("200949653378049024108263319241673077723277742970082570727627973814"));

    result = QCA::BigInteger("217570540819") -= QCA::BigInteger(
        "121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200696970170700");
    QCOMPARE(result.toString(),
             QStringLiteral("-12195508359772042098338428216669330739418553043136847683498074830215871840606350076343456"
                            "1937200479399629881"));
    QCOMPARE(result,
             QCA::BigInteger(QStringLiteral("-1219550835977204209833842821666933073941855304313684768349807483021587184"
                                            "06063500763434561937200479399629881")));

    result = QCA::BigInteger(QStringLiteral("2335319252198456765380587281374076367944")) -=
        QCA::BigInteger(QStringLiteral("-4500271"));
    QCOMPARE(result, QCA::BigInteger(QStringLiteral("2335319252198456765380587281374080868215")));

    result = QCA::BigInteger(
        QStringLiteral("-393694614027544181700073367147249369966344727230221941008713805434207925307052598")) -=
        QCA::BigInteger(QStringLiteral("-153972676737062409261153899615588515236137907791841623991260363840680295565313"
                                       "157972489168132345521780658007459602823125797806770"));
    QCOMPARE(result.toString(),
             QStringLiteral("153972676737062409261153899615588515236137907791447929377232819658980222198165908602522823"
                            "405115299839649293654168615200490754172"));
    QCOMPARE(result,
             QCA::BigInteger(QStringLiteral("15397267673706240926115389961558851523613790779144792937723281965898022219"
                                            "8165908602522823405115299839649293654168615200490754172")));

    result = QCA::BigInteger(QStringLiteral("114832549702862263167")) -=
        QCA::BigInteger(QStringLiteral("1292186490722995955874527641883028787538667360089228102228659716577356947303995"
                                       "3984775959232814911435097412913078625"));
    QCOMPARE(result.toString(),
             QStringLiteral("-12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959"
                            "232814796602547710050815458"));
    QCOMPARE(result,
             QCA::BigInteger(QStringLiteral("-1292186490722995955874527641883028787538667360089228102228659716577356947"
                                            "3039953984775959232814796602547710050815458")));

    result =
        QCA::BigInteger(QStringLiteral("6489502346837936889305337487724547956628371915228387374094443896266362105931065"
                                       "153072983425911767580294076594078932835008494777866083")) -=
        QCA::BigInteger(QStringLiteral("1099205476533612407829257935144627350486541654788267826664706620630745291371323"
                                       "154513322608446957760026881954001581"));
    QCOMPARE(result.toString(),
             QStringLiteral("648950234683793688820613201119093554879911398008376002360790224147809427926635853244223813"
                            "4540444425780753985631975074981612823864502"));
    QCOMPARE(result,
             QCA::BigInteger(QStringLiteral("64895023468379368882061320111909355487991139800837600236079022414780942792"
                                            "66358532442238134540444425780753985631975074981612823864502")));

    result =
        QCA::BigInteger(QStringLiteral("1699911441239587542538013131736629773378508702733583789516405216010771529944743"
                                       "40806917796870911557233689087716056557")) -=
        QCA::BigInteger(QStringLiteral("-15409167"));
    QCOMPARE(result.toString(),
             QStringLiteral("169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796"
                            "870911557233689087731465724"));
    QCOMPARE(result,
             QCA::BigInteger(QStringLiteral("16999114412395875425380131317366297733785087027335837895164052160107715299"
                                            "4474340806917796870911557233689087731465724")));
}

QTEST_MAIN(BigIntUnitTest)

#include "bigintunittest.moc"