This file is indexed.

/usr/include/NTL/GF2EX.h is in libntl-dev 9.9.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
#ifndef NTL_GF2EX__H
#define NTL_GF2EX__H

#include <NTL/vector.h>
#include <NTL/GF2E.h>
#include <NTL/vec_GF2E.h>
#include <NTL/vec_long.h>
#include <NTL/GF2XVec.h>
#include <NTL/Lazy.h>


NTL_OPEN_NNS

class GF2EXModulus; // forward declaration

class GF2EX {
public:
typedef GF2E coeff_type;
typedef GF2EXModulus modulus_type;


vec_GF2E rep;


/***************************************************************

          Constructors, Destructors, and Assignment

****************************************************************/


GF2EX() { }

explicit GF2EX(long a) { *this = a; }
explicit GF2EX(GF2 a) { *this = a; }
explicit GF2EX(const GF2& a) { *this = a; }


GF2EX(INIT_SIZE_TYPE, long n) { rep.SetMaxLength(n); }

GF2EX(const GF2EX& a) : rep(a.rep) { }


GF2EX& operator=(const GF2EX& a) 
   { rep = a.rep; return *this; }

~GF2EX() { }

void normalize();
// strip leading zeros

void SetMaxLength(long n) 
// pre-allocate space for n coefficients.
// Value is unchanged

   { rep.SetMaxLength(n); }


void kill() 
// free space held by this polynomial.  Value becomes 0.

   { rep.kill(); }



void SetLength(long n) { rep.SetLength(n); }
GF2E& operator[](long i) { return rep[i]; }
const GF2E& operator[](long i) const { return rep[i]; }




static const GF2EX& zero();



inline GF2EX& operator=(long a);
inline GF2EX& operator=(GF2 a);
inline GF2EX& operator=(const GF2E& a);

inline GF2EX(long i, long a);
inline GF2EX(long i, GF2 a);
inline GF2EX(long i, const GF2E& a);


inline GF2EX(INIT_MONO_TYPE, long i, long a);
inline GF2EX(INIT_MONO_TYPE, long i, GF2 a);
inline GF2EX(INIT_MONO_TYPE, long i, const GF2E& a);
inline GF2EX(INIT_MONO_TYPE, long i);


GF2EX(GF2EX& x, INIT_TRANS_TYPE) : rep(x.rep, INIT_TRANS) { }

void swap(GF2EX& x) { rep.swap(x.rep); }


};




/********************************************************************

                           input and output

*********************************************************************/


NTL_SNS istream& operator>>(NTL_SNS istream& s, GF2EX& x);
NTL_SNS ostream& operator<<(NTL_SNS ostream& s, const GF2EX& a);




/**********************************************************

                   Some utility routines

***********************************************************/


inline long deg(const GF2EX& a) { return a.rep.length() - 1; }

const GF2E& coeff(const GF2EX& a, long i);
// zero if i not in range

void GetCoeff(GF2E& x, const GF2EX& a, long i);
// x = a[i], or zero if i not in range

const GF2E& LeadCoeff(const GF2EX& a);
// zero if a == 0

const GF2E& ConstTerm(const GF2EX& a);
// zero if a == 0

void SetCoeff(GF2EX& x, long i, const GF2E& a);
void SetCoeff(GF2EX& x, long i, GF2 a);
void SetCoeff(GF2EX& x, long i, long a);
// x[i] = a, error is raised if i < 0

void SetCoeff(GF2EX& x, long i);
// x[i] = 1, error is raised if i < 0

inline GF2EX::GF2EX(long i, const GF2E& a) { SetCoeff(*this, i, a); }
inline GF2EX::GF2EX(long i, GF2 a) { SetCoeff(*this, i, a); }
inline GF2EX::GF2EX(long i, long a) { SetCoeff(*this, i, a); }


inline GF2EX::GF2EX(INIT_MONO_TYPE, long i, const GF2E& a) { SetCoeff(*this, i, a); }
inline GF2EX::GF2EX(INIT_MONO_TYPE, long i, GF2 a) { SetCoeff(*this, i, a); }
inline GF2EX::GF2EX(INIT_MONO_TYPE, long i, long a) { SetCoeff(*this, i, a); }
inline GF2EX::GF2EX(INIT_MONO_TYPE, long i) { SetCoeff(*this, i); }


void SetX(GF2EX& x);
// x is set to the monomial X

long IsX(const GF2EX& a);
// test if x = X

inline void clear(GF2EX& x) 
// x = 0

   { x.rep.SetLength(0); }

inline void set(GF2EX& x)
// x = 1

   { x.rep.SetLength(1); set(x.rep[0]); }

inline void swap(GF2EX& x, GF2EX& y)
// swap x & y (only pointers are swapped)

   { x.swap(y); }

void random(GF2EX& x, long n);
inline GF2EX random_GF2EX(long n)
   { GF2EX x; random(x, n); NTL_OPT_RETURN(GF2EX, x); }
// generate a random polynomial of degree < n 

void trunc(GF2EX& x, const GF2EX& a, long m);
inline GF2EX trunc(const GF2EX& a, long m)
   { GF2EX x; trunc(x, a, m); NTL_OPT_RETURN(GF2EX, x); }
// x = a % X^m

void RightShift(GF2EX& x, const GF2EX& a, long n);
inline GF2EX RightShift(const GF2EX& a, long n)
   { GF2EX x; RightShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
// x = a/X^n

void LeftShift(GF2EX& x, const GF2EX& a, long n);
inline GF2EX LeftShift(const GF2EX& a, long n)
   { GF2EX x; LeftShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
// x = a*X^n

#ifndef NTL_TRANSITION

inline GF2EX operator>>(const GF2EX& a, long n)
   { GF2EX x; RightShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator<<(const GF2EX& a, long n)
   { GF2EX x; LeftShift(x, a, n); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator<<=(GF2EX& x, long n)
   { LeftShift(x, x, n); return x; }

inline GF2EX& operator>>=(GF2EX& x, long n)
   { RightShift(x, x, n); return x; }

#endif



void diff(GF2EX& x, const GF2EX& a);
inline GF2EX diff(const GF2EX& a)
   { GF2EX x; diff(x, a); NTL_OPT_RETURN(GF2EX, x); }
// x = derivative of a



void MakeMonic(GF2EX& x);

void reverse(GF2EX& c, const GF2EX& a, long hi);

inline GF2EX reverse(const GF2EX& a, long hi)
   { GF2EX x; reverse(x, a, hi); NTL_OPT_RETURN(GF2EX, x); }

inline void reverse(GF2EX& c, const GF2EX& a)
{  reverse(c, a, deg(a)); }

inline GF2EX reverse(const GF2EX& a)
   { GF2EX x; reverse(x, a); NTL_OPT_RETURN(GF2EX, x); }

inline void VectorCopy(vec_GF2E& x, const GF2EX& a, long n)
   { VectorCopy(x, a.rep, n); }

inline vec_GF2E VectorCopy(const GF2EX& a, long n)
   { return VectorCopy(a.rep, n); }




/*******************************************************************

                        conversion routines

********************************************************************/



void conv(GF2EX& x, long a);
void conv(GF2EX& x, GF2 a);
void conv(GF2EX& x, const GF2E& a);
void conv(GF2EX& x, const ZZ& a);

#ifndef NTL_TRANSITION
void conv(GF2EX& x, const GF2X& a);
#endif

void conv(GF2EX& x, const vec_GF2E& a);

inline GF2EX to_GF2EX(long a)
   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX to_GF2EX(GF2 a)
   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX to_GF2EX(const GF2E& a)
   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX to_GF2EX(const ZZ& a)
   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }

#ifndef NTL_TRANSITION
inline GF2EX to_GF2EX(const GF2X& a)
   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }
#endif

inline GF2EX to_GF2EX(const vec_GF2E& a)
   { GF2EX x; conv(x, a); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& GF2EX::operator=(const GF2E& a) { conv(*this, a); return *this; }
inline GF2EX& GF2EX::operator=(GF2 a) { conv(*this, a); return *this; }
inline GF2EX& GF2EX::operator=(long a) { conv(*this, a); return *this; }




/* additional legacy conversions for v6 conversion regime */

inline void conv(GF2EX& x, const GF2EX& a)
   { x = a; }

inline void conv(vec_GF2E& x, const GF2EX& a)
   { x = a.rep; }

class ZZX;
void conv(GF2EX& x, const ZZX& a);


/* ------------------------------------- */





/*************************************************************

                        Comparison

**************************************************************/

long IsZero(const GF2EX& a); 

long IsOne(const GF2EX& a);

inline long operator==(const GF2EX& a, const GF2EX& b)
   { return a.rep == b.rep; }

long operator==(const GF2EX& a, const GF2E& b);
long operator==(const GF2EX& a, GF2 b);
long operator==(const GF2EX& a, long b);

inline long operator==(const GF2E& a, const GF2EX& b) { return b == a; }
inline long operator==(GF2 a, const GF2EX& b) { return b == a; }
inline long operator==(long a, const GF2EX& b) { return b == a; }

inline long operator!=(const GF2EX& a, const GF2EX& b) { return !(a == b); }

inline long operator!=(const GF2EX& a, const GF2E& b) { return !(a == b); }
inline long operator!=(const GF2EX& a, GF2 b) { return !(a == b); }
inline long operator!=(const GF2EX& a, long b) { return !(a == b); }

inline long operator!=(const GF2E& a, const GF2EX& b) { return !(a == b); }
inline long operator!=(GF2 a, const GF2EX& b) { return !(a == b); }
inline long operator!=(long a, const GF2EX& b) { return !(a == b); }


/***************************************************************

                         Addition

****************************************************************/

void add(GF2EX& x, const GF2EX& a, const GF2EX& b);
// x = a + b

void add(GF2EX& x, const GF2EX& a, const GF2E& b);
void add(GF2EX& x, const GF2EX& a, GF2 b);
void add(GF2EX& x, const GF2EX& a, long);

inline void add(GF2EX& x, const GF2E& a, const GF2EX& b) { add(x, b, a); }
inline void add(GF2EX& x, GF2 a, const GF2EX& b) { add(x, b, a); }
inline void add(GF2EX& x, long a, const GF2EX& b) { add(x, b, a); }

inline void sub(GF2EX& x, const GF2EX& a, const GF2EX& b) { add(x, a, b); }

inline void sub(GF2EX& x, const GF2EX& a, const GF2E& b) { add(x, a, b); }
inline void sub(GF2EX& x, const GF2EX& a, GF2 b) { add(x, a, b); }
inline void sub(GF2EX& x, const GF2EX& a, long b) { add(x, a, b); }

inline void sub(GF2EX& x, const GF2E& a, const GF2EX& b) { add(x, a, b); }
inline void sub(GF2EX& x, GF2 a, const GF2EX& b) { add(x, a, b); }
inline void sub(GF2EX& x, long a, const GF2EX& b) { add(x, a, b); }

inline void negate(GF2EX& x, const GF2EX& a) { x = a; }




inline GF2EX operator+(const GF2EX& a, const GF2EX& b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator+(const GF2EX& a, const GF2E& b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator+(const GF2EX& a, GF2 b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator+(const GF2EX& a, long b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator+(const GF2E& a, const GF2EX& b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator+(GF2 a, const GF2EX& b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator+(long a, const GF2EX& b)
   { GF2EX x; add(x, a, b); NTL_OPT_RETURN(GF2EX, x); }


inline GF2EX operator-(const GF2EX& a, const GF2EX& b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator-(const GF2EX& a, const GF2E& b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator-(const GF2EX& a, GF2 b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator-(const GF2EX& a, long b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator-(const GF2E& a, const GF2EX& b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator-(GF2 a, const GF2EX& b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator-(long a, const GF2EX& b)
   { GF2EX x; sub(x, a, b); NTL_OPT_RETURN(GF2EX, x); }


inline GF2EX& operator+=(GF2EX& x, const GF2EX& b)
   { add(x, x, b); return x; }

inline GF2EX& operator+=(GF2EX& x, const GF2E& b)
   { add(x, x, b); return x; }

inline GF2EX& operator+=(GF2EX& x, GF2 b)
   { add(x, x, b); return x; }

inline GF2EX& operator+=(GF2EX& x, long b)
   { add(x, x, b); return x; }

inline GF2EX& operator-=(GF2EX& x, const GF2EX& b)
   { sub(x, x, b); return x; }

inline GF2EX& operator-=(GF2EX& x, const GF2E& b)
   { sub(x, x, b); return x; }

inline GF2EX& operator-=(GF2EX& x, GF2 b)
   { sub(x, x, b); return x; }

inline GF2EX& operator-=(GF2EX& x, long b)
   { sub(x, x, b); return x; }


inline GF2EX operator-(const GF2EX& a) 
   { GF2EX x; negate(x, a); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator++(GF2EX& x) { add(x, x, 1); return x; }
inline void operator++(GF2EX& x, int) { add(x, x, 1); }
inline GF2EX& operator--(GF2EX& x) { sub(x, x, 1); return x; }
inline void operator--(GF2EX& x, int) { sub(x, x, 1); }


/*****************************************************************

                        Multiplication

******************************************************************/


void mul(GF2EX& x, const GF2EX& a, const GF2EX& b);
// x = a * b

void sqr(GF2EX& x, const GF2EX& a);
inline GF2EX sqr(const GF2EX& a)
   { GF2EX x; sqr(x, a); NTL_OPT_RETURN(GF2EX, x); }
// x = a^2

void mul(GF2EX & x, const GF2EX& a, const GF2E& b);
void mul(GF2EX & x, const GF2EX& a, GF2 b);
void mul(GF2EX & x, const GF2EX& a, long b);

inline void mul(GF2EX& x, const GF2E& a, const GF2EX& b) { mul(x, b, a); }
inline void mul(GF2EX& x, GF2 a, const GF2EX& b) { mul(x, b, a); }
inline void mul(GF2EX& x, long a, const GF2EX& b) { mul(x, b, a); }

void MulTrunc(GF2EX& x, const GF2EX& a, const GF2EX& b, long n);
inline GF2EX MulTrunc(const GF2EX& a, const GF2EX& b, long n)
   { GF2EX x; MulTrunc(x, a, b, n); NTL_OPT_RETURN(GF2EX, x); }
// x = a * b % X^n

void SqrTrunc(GF2EX& x, const GF2EX& a, long n);
inline GF2EX SqrTrunc(const GF2EX& a, long n)
   { GF2EX x; SqrTrunc(x, a, n); NTL_OPT_RETURN(GF2EX, x); }
// x = a*a % X^n


inline GF2EX operator*(const GF2EX& a, const GF2EX& b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator*(const GF2EX& a, const GF2E& b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator*(const GF2EX& a, GF2 b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator*(const GF2EX& a, long b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator*(const GF2E& a, const GF2EX& b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator*(GF2 a, const GF2EX& b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator*(long a, const GF2EX& b)
   { GF2EX x; mul(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator*=(GF2EX& x, const GF2EX& b)
   { mul(x, x, b); return x; }

inline GF2EX& operator*=(GF2EX& x, const GF2E& b)
   { mul(x, x, b); return x; }

inline GF2EX& operator*=(GF2EX& x, GF2 b)
   { mul(x, x, b); return x; }

inline GF2EX& operator*=(GF2EX& x, long b)
   { mul(x, x, b); return x; }


void power(GF2EX& x, const GF2EX& a, long e);
inline GF2EX power(const GF2EX& a, long e)
   { GF2EX x; power(x, a, e); NTL_OPT_RETURN(GF2EX, x); }




/*************************************************************

                      Division

**************************************************************/

void DivRem(GF2EX& q, GF2EX& r, const GF2EX& a, const GF2EX& b);
// q = a/b, r = a%b

void div(GF2EX& q, const GF2EX& a, const GF2EX& b);
void div(GF2EX& q, const GF2EX& a, const GF2E& b);
void div(GF2EX& q, const GF2EX& a, GF2 b);
void div(GF2EX& q, const GF2EX& a, long b);
// q = a/b

void rem(GF2EX& r, const GF2EX& a, const GF2EX& b);
// r = a%b

long divide(GF2EX& q, const GF2EX& a, const GF2EX& b);
// if b | a, sets q = a/b and returns 1; otherwise returns 0

long divide(const GF2EX& a, const GF2EX& b);
// if b | a, sets q = a/b and returns 1; otherwise returns 0

void InvTrunc(GF2EX& x, const GF2EX& a, long m);
inline GF2EX InvTrunc(const GF2EX& a, long m)
   { GF2EX x; InvTrunc(x, a, m); NTL_OPT_RETURN(GF2EX, x); }

// computes x = a^{-1} % X^m 
// constant term must be non-zero



inline GF2EX operator/(const GF2EX& a, const GF2EX& b)
   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator/(const GF2EX& a, const GF2E& b)
   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator/(const GF2EX& a, GF2 b)
   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator/(const GF2EX& a, long b)
   { GF2EX x; div(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator/=(GF2EX& x, const GF2EX& b)
   { div(x, x, b); return x; }

inline GF2EX& operator/=(GF2EX& x, const GF2E& b)
   { div(x, x, b); return x; }

inline GF2EX& operator/=(GF2EX& x, GF2 b)
   { div(x, x, b); return x; }

inline GF2EX& operator/=(GF2EX& x, long b)
   { div(x, x, b); return x; }


inline GF2EX operator%(const GF2EX& a, const GF2EX& b)
   { GF2EX x; rem(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator%=(GF2EX& x, const GF2EX& b)
   { rem(x, x, b); return x; }




/***********************************************************

                         GCD's

************************************************************/


void GCD(GF2EX& x, const GF2EX& a, const GF2EX& b);
inline GF2EX GCD(const GF2EX& a, const GF2EX& b)
   { GF2EX x; GCD(x, a, b); NTL_OPT_RETURN(GF2EX, x); }

// x = GCD(a, b),  x is always monic (or zero if a==b==0).

void XGCD(GF2EX& d, GF2EX& s, GF2EX& t, const GF2EX& a, const GF2EX& b);
// d = gcd(a,b), a s + b t = d 


/*************************************************************

             Modular Arithmetic without pre-conditioning

**************************************************************/

// arithmetic mod f.
// all inputs and outputs are polynomials of degree less than deg(f).
// ASSUMPTION: f is assumed monic, and deg(f) > 0.
// NOTE: if you want to do many computations with a fixed f,
//       use the GF2EXModulus data structure and associated routines below.



void MulMod(GF2EX& x, const GF2EX& a, const GF2EX& b, const GF2EX& f);
inline GF2EX MulMod(const GF2EX& a, const GF2EX& b, const GF2EX& f)
   { GF2EX x; MulMod(x, a, b, f); NTL_OPT_RETURN(GF2EX, x); }
// x = (a * b) % f

void SqrMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
inline GF2EX SqrMod(const GF2EX& a, const GF2EX& f)
   { GF2EX x; SqrMod(x, a, f); NTL_OPT_RETURN(GF2EX, x); }
// x = a^2 % f

void MulByXMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
inline GF2EX MulByXMod(const GF2EX& a, const GF2EX& f)
   { GF2EX x; MulByXMod(x, a, f); NTL_OPT_RETURN(GF2EX, x); }
// x = (a * X) mod f

void InvMod(GF2EX& x, const GF2EX& a, const GF2EX& f);
inline GF2EX InvMod(const GF2EX& a, const GF2EX& f)
   { GF2EX x; InvMod(x, a, f); NTL_OPT_RETURN(GF2EX, x); }
// x = a^{-1} % f, error is a is not invertible

long InvModStatus(GF2EX& x, const GF2EX& a, const GF2EX& f);
// if (a, f) = 1, returns 0 and sets x = a^{-1} % f
// otherwise, returns 1 and sets x = (a, f)





/******************************************************************

        Modular Arithmetic with Pre-conditioning

*******************************************************************/


// If you need to do a lot of arithmetic modulo a fixed f,
// build GF2EXModulus F for f.  This pre-computes information about f
// that speeds up the computation a great deal.

class GF2EXModulus {
public:
   GF2EXModulus();
   ~GF2EXModulus() { }

   GF2EXModulus(const GF2EX& ff);

   GF2EX f;   // the modulus

   operator const GF2EX& () const { return f; }
   const GF2EX& val() const { return f; }

   long n; //  deg(f)

   long method; // GF2EX_MOD_PLAIN or GF2EX_MOD_MUL 

   GF2EX h0;
   GF2E hlc;
   GF2EX f0;

   OptionalVal< Lazy<vec_GF2E> > tracevec;
   // extra level of indirection to ensure class is relocatable

}; 


inline long deg(const GF2EXModulus& F) { return F.n; }

void build(GF2EXModulus& F, const GF2EX& f);



void rem(GF2EX& r, const GF2EX& a, const GF2EXModulus& F);
   
void DivRem(GF2EX& q, GF2EX& r, const GF2EX& a, const GF2EXModulus& F);

void div(GF2EX& q, const GF2EX& a, const GF2EXModulus& F);

void MulMod(GF2EX& c, const GF2EX& a, const GF2EX& b, const GF2EXModulus& F);
inline GF2EX MulMod(const GF2EX& a, const GF2EX& b, const GF2EXModulus& F)
   { GF2EX x; MulMod(x, a, b, F); NTL_OPT_RETURN(GF2EX, x); }

void SqrMod(GF2EX& c, const GF2EX& a, const GF2EXModulus& F);
inline GF2EX SqrMod(const GF2EX& a, const GF2EXModulus& F)
   { GF2EX x; SqrMod(x, a, F); NTL_OPT_RETURN(GF2EX, x); }


void PowerMod(GF2EX& h, const GF2EX& g, const ZZ& e, const GF2EXModulus& F);

inline void PowerMod(GF2EX& h, const GF2EX& g, long e, const GF2EXModulus& F)
   { PowerMod(h, g, ZZ_expo(e), F); }

inline GF2EX PowerMod(const GF2EX& g, const ZZ& e, const GF2EXModulus& F)
   { GF2EX x; PowerMod(x, g, e, F);  NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX PowerMod(const GF2EX& g, long e, const GF2EXModulus& F)
   { GF2EX x; PowerMod(x, g, e, F);  NTL_OPT_RETURN(GF2EX, x); }

void PowerXMod(GF2EX& hh, const ZZ& e, const GF2EXModulus& F);

inline void PowerXMod(GF2EX& h, long e, const GF2EXModulus& F)
   { PowerXMod(h, ZZ_expo(e), F); }


inline GF2EX PowerXMod(const ZZ& e, const GF2EXModulus& F)
   { GF2EX x; PowerXMod(x, e, F);  NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX PowerXMod(long e, const GF2EXModulus& F)
   { GF2EX x; PowerXMod(x, e, F);  NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX operator%(const GF2EX& a, const GF2EXModulus& F)
   { GF2EX x; rem(x, a, F); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator%=(GF2EX& x, const GF2EXModulus& F)
   { rem(x, x, F); return x; }

inline GF2EX operator/(const GF2EX& a, const GF2EXModulus& F)
   { GF2EX x; div(x, a, F); NTL_OPT_RETURN(GF2EX, x); }

inline GF2EX& operator/=(GF2EX& x, const GF2EXModulus& F)
   { div(x, x, F); return x; }



/*****************************************************************

                       vectors of GF2EX's

*****************************************************************/



typedef Vec<GF2EX> vec_GF2EX;



/*******************************************************

              Evaluation and related problems

********************************************************/


void BuildFromRoots(GF2EX& x, const vec_GF2E& a);
inline GF2EX BuildFromRoots(const vec_GF2E& a)
   { GF2EX x; BuildFromRoots(x, a); NTL_OPT_RETURN(GF2EX, x); }
// computes the polynomial (X-a[0]) ... (X-a[n-1]), where n = a.length()


void eval(GF2E& b, const GF2EX& f, const GF2E& a);
inline GF2E eval(const GF2EX& f, const GF2E& a)
   { GF2E x; eval(x, f, a); NTL_OPT_RETURN(GF2E, x); }
// b = f(a)

void eval(vec_GF2E& b, const GF2EX& f, const vec_GF2E& a);
inline vec_GF2E eval(const GF2EX& f, const vec_GF2E& a)
   { vec_GF2E x; eval(x, f, a); NTL_OPT_RETURN(vec_GF2E, x); }
//  b[i] = f(a[i])

inline void eval(GF2E& b, const GF2X& f, const GF2E& a)
   { conv(b, CompMod(f, rep(a), GF2E::modulus())); }
   
inline GF2E eval(const GF2X& f, const GF2E& a)
   { GF2E x; eval(x, f, a); NTL_OPT_RETURN(GF2E, x); }
// b = f(a)


void interpolate(GF2EX& f, const vec_GF2E& a, const vec_GF2E& b);
inline GF2EX interpolate(const vec_GF2E& a, const vec_GF2E& b)
   { GF2EX x; interpolate(x, a, b); NTL_OPT_RETURN(GF2EX, x); }
// computes f such that f(a[i]) = b[i]




/**********************************************************

         Modular Composition and Minimal Polynomials

***********************************************************/


// algorithms for computing g(h) mod f




void CompMod(GF2EX& x, const GF2EX& g, const GF2EX& h, const GF2EXModulus& F);
inline GF2EX 
CompMod(const GF2EX& g, const GF2EX& h, const GF2EXModulus& F)
   { GF2EX x; CompMod(x, g, h, F); NTL_OPT_RETURN(GF2EX, x); }
// x = g(h) mod f

void Comp2Mod(GF2EX& x1, GF2EX& x2, const GF2EX& g1, const GF2EX& g2,
              const GF2EX& h, const GF2EXModulus& F);
// xi = gi(h) mod f (i=1,2)

void Comp3Mod(GF2EX& x1, GF2EX& x2, GF2EX& x3, 
              const GF2EX& g1, const GF2EX& g2, const GF2EX& g3,
              const GF2EX& h, const GF2EXModulus& F);
// xi = gi(h) mod f (i=1..3)



// The routine build (see below) which is implicitly called
// by the various compose and UpdateMap routines builds a table
// of polynomials.  
// If GF2EXArgBound > 0, then the table is limited in
// size to approximamtely that many KB.
// If GF2EXArgBound <= 0, then it is ignored, and space is allocated
// so as to maximize speed.
// Initially, GF2EXArgBound = 0.


// If a single h is going to be used with many g's
// then you should build a GF2EXArgument for h,
// and then use the compose routine below.
// build computes and stores h, h^2, ..., h^m mod f.
// After this pre-computation, composing a polynomial of degree 
// roughly n with h takes n/m multiplies mod f, plus n^2
// scalar multiplies.
// Thus, increasing m increases the space requirement and the pre-computation
// time, but reduces the composition time.
// If GF2EXArgBound > 0, a table of size less than m may be built.

struct GF2EXArgument {
   vec_GF2EX H;
};

extern 
NTL_CHEAP_THREAD_LOCAL
long GF2EXArgBound;


void build(GF2EXArgument& H, const GF2EX& h, const GF2EXModulus& F, long m);

// m must be > 0, otherwise an error is raised

void CompMod(GF2EX& x, const GF2EX& g, const GF2EXArgument& H, 
             const GF2EXModulus& F);

inline GF2EX 
CompMod(const GF2EX& g, const GF2EXArgument& H, const GF2EXModulus& F)
   { GF2EX x; CompMod(x, g, H, F); NTL_OPT_RETURN(GF2EX, x); }
   



void MinPolySeq(GF2EX& h, const vec_GF2E& a, long m);
inline GF2EX MinPolySeq(const vec_GF2E& a, long m)
   { GF2EX x; MinPolySeq(x, a, m); NTL_OPT_RETURN(GF2EX, x); }


void MinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F);
inline GF2EX MinPolyMod(const GF2EX& g, const GF2EXModulus& F)
   { GF2EX x; MinPolyMod(x, g, F); NTL_OPT_RETURN(GF2EX, x); }


void MinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F, long m);
inline GF2EX MinPolyMod(const GF2EX& g, const GF2EXModulus& F, long m)
   { GF2EX x; MinPolyMod(x, g, F, m); NTL_OPT_RETURN(GF2EX, x); }

void ProbMinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F);
inline GF2EX ProbMinPolyMod(const GF2EX& g, const GF2EXModulus& F)
   { GF2EX x; ProbMinPolyMod(x, g, F); NTL_OPT_RETURN(GF2EX, x); }

void ProbMinPolyMod(GF2EX& hh, const GF2EX& g, const GF2EXModulus& F, long m);
inline GF2EX ProbMinPolyMod(const GF2EX& g, const GF2EXModulus& F, long m)
   { GF2EX x; ProbMinPolyMod(x, g, F, m); NTL_OPT_RETURN(GF2EX, x); }

void IrredPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F);
inline GF2EX IrredPolyMod(const GF2EX& g, const GF2EXModulus& F)
   { GF2EX x; IrredPolyMod(x, g, F); NTL_OPT_RETURN(GF2EX, x); }

void IrredPolyMod(GF2EX& h, const GF2EX& g, const GF2EXModulus& F, long m);
inline GF2EX IrredPolyMod(const GF2EX& g, const GF2EXModulus& F, long m)
   { GF2EX x; IrredPolyMod(x, g, F, m); NTL_OPT_RETURN(GF2EX, x); }


struct GF2EXTransMultiplier {
   GF2EX f0, fbi, b;
   long shamt, shamt_fbi, shamt_b;
};

void build(GF2EXTransMultiplier& B, const GF2EX& b, const GF2EXModulus& F);

void TransMulMod(GF2EX& x, const GF2EX& a, const GF2EXTransMultiplier& B,
               const GF2EXModulus& F);

void UpdateMap(vec_GF2E& x, const vec_GF2E& a, 
         const GF2EXTransMultiplier& B, const GF2EXModulus& F);

inline vec_GF2E UpdateMap(const vec_GF2E& a,
         const GF2EXTransMultiplier& B, const GF2EXModulus& F)
   { vec_GF2E x; UpdateMap(x, a, B, F); NTL_OPT_RETURN(vec_GF2E, x); }

void ProjectPowers(vec_GF2E& x, const vec_GF2E& a, long k, 
                   const GF2EXArgument& H, const GF2EXModulus& F);
inline vec_GF2E ProjectPowers(const vec_GF2E& a, long k, 
                   const GF2EXArgument& H, const GF2EXModulus& F)
   { vec_GF2E x; ProjectPowers(x, a, k, H, F); NTL_OPT_RETURN(vec_GF2E, x); }

void ProjectPowers(vec_GF2E& x, const vec_GF2E& a, long k, const GF2EX& h, 
                   const GF2EXModulus& F);
inline vec_GF2E ProjectPowers(const vec_GF2E& a, long k, 
                   const GF2EX& H, const GF2EXModulus& F)
   { vec_GF2E x; ProjectPowers(x, a, k, H, F); NTL_OPT_RETURN(vec_GF2E, x); }

inline void project(GF2E& x, const vec_GF2E& a, const GF2EX& b)
   { InnerProduct(x, a, b.rep); }

inline GF2E project(const vec_GF2E& a, const GF2EX& b)
   { GF2E x; InnerProduct(x, a, b.rep); NTL_OPT_RETURN(GF2E, x); }

/**********************************************************

         Modular Composition and Minimal Polynomials
                         in towers

***********************************************************/

// composition

void CompTower(GF2EX& x, const GF2X& g, const GF2EXArgument& A,
             const GF2EXModulus& F);

inline GF2EX CompTower(const GF2X& g, const GF2EXArgument& A,
             const GF2EXModulus& F)
   { GF2EX x; CompTower(x, g, A, F); NTL_OPT_RETURN(GF2EX, x); }

void CompTower(GF2EX& x, const GF2X& g, const GF2EX& h,
             const GF2EXModulus& F);

inline GF2EX CompTower(const GF2X& g, const GF2EX& h,
             const GF2EXModulus& F)
   { GF2EX x; CompTower(x, g, h, F); NTL_OPT_RETURN(GF2EX, x); }

// prob min poly

void ProbMinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
                      long m);

inline GF2X ProbMinPolyTower(const GF2EX& g, const GF2EXModulus& F,
                      long m)
   { GF2X x; ProbMinPolyTower(x, g, F, m); NTL_OPT_RETURN(GF2X, x); }

inline void ProbMinPolyTower(GF2X& h, const GF2EX& g, 
                             const GF2EXModulus& F)
   { ProbMinPolyTower(h, g, F, deg(F)*GF2E::degree()); }

inline GF2X ProbMinPolyTower(const GF2EX& g, const GF2EXModulus& F)
   { GF2X x; ProbMinPolyTower(x, g, F); NTL_OPT_RETURN(GF2X, x); }


// min poly


void MinPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
                      long m);

inline GF2X MinPolyTower(const GF2EX& g, const GF2EXModulus& F,
                      long m)
   { GF2X x; MinPolyTower(x, g, F, m); NTL_OPT_RETURN(GF2X, x); }

inline void MinPolyTower(GF2X& h, const GF2EX& g, 
                             const GF2EXModulus& F)
   { MinPolyTower(h, g, F, deg(F)*GF2E::degree()); }

inline GF2X MinPolyTower(const GF2EX& g, const GF2EXModulus& F)
   { GF2X x; MinPolyTower(x, g, F); NTL_OPT_RETURN(GF2X, x); }

// irred poly


void IrredPolyTower(GF2X& h, const GF2EX& g, const GF2EXModulus& F,
                      long m);

inline GF2X IrredPolyTower(const GF2EX& g, const GF2EXModulus& F,
                      long m)
   { GF2X x; IrredPolyTower(x, g, F, m); NTL_OPT_RETURN(GF2X, x); }

inline void IrredPolyTower(GF2X& h, const GF2EX& g, 
                             const GF2EXModulus& F)
   { IrredPolyTower(h, g, F, deg(F)*GF2E::degree()); }

inline GF2X IrredPolyTower(const GF2EX& g, const GF2EXModulus& F)
   { GF2X x; IrredPolyTower(x, g, F); NTL_OPT_RETURN(GF2X, x); }



/*****************************************************************

                   Traces, norms, resultants

******************************************************************/

void TraceVec(vec_GF2E& S, const GF2EX& f);

inline vec_GF2E TraceVec(const GF2EX& f)
   { vec_GF2E x; TraceVec(x, f); NTL_OPT_RETURN(vec_GF2E, x); }


void TraceMod(GF2E& x, const GF2EX& a, const GF2EXModulus& F);

inline GF2E TraceMod(const GF2EX& a, const GF2EXModulus& F)
   { GF2E x; TraceMod(x, a, F); NTL_OPT_RETURN(GF2E, x); }

void TraceMod(GF2E& x, const GF2EX& a, const GF2EX& f);

inline GF2E TraceMod(const GF2EX& a, const GF2EX& f)
   { GF2E x; TraceMod(x, a, f); NTL_OPT_RETURN(GF2E, x); }





void NormMod(GF2E& x, const GF2EX& a, const GF2EX& f);

inline GF2E NormMod(const GF2EX& a, const GF2EX& f)
   { GF2E x; NormMod(x, a, f); NTL_OPT_RETURN(GF2E, x); }

void resultant(GF2E& rres, const GF2EX& a, const GF2EX& b);

inline GF2E resultant(const GF2EX& a, const GF2EX& b)
   { GF2E x; resultant(x, a, b); NTL_OPT_RETURN(GF2E, x); }


NTL_CLOSE_NNS 

#endif