1 | |
---|
2 | /**************************************************************************\ |
---|
3 | |
---|
4 | MODULE: vec_GF2E |
---|
5 | |
---|
6 | SUMMARY: |
---|
7 | |
---|
8 | Provides vectors over GF2E, along with some related operations. |
---|
9 | |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | #include <NTL/GF2E.h> |
---|
13 | #include <NTL/vector.h> |
---|
14 | |
---|
15 | NTL_vector_decl(GF2E,vec_GF2E) |
---|
16 | |
---|
17 | NTL_io_vector_decl(GF2E,vec_GF2E) |
---|
18 | // I/O operators are defined |
---|
19 | |
---|
20 | NTL_eq_vector_decl(GF2E,vec_GF2E) |
---|
21 | // operators == and != are defined |
---|
22 | |
---|
23 | void mul(vec_GF2E& x, const vec_GF2E& a, const GF2E& b); |
---|
24 | void mul(vec_GF2E& x, const vec_GF2E& a, GF2 b); |
---|
25 | void mul(vec_GF2E& x, const vec_GF2E& a, long b); |
---|
26 | |
---|
27 | void mul(vec_GF2E& x, const GF2E& a, const vec_GF2E& b); |
---|
28 | void mul(vec_GF2E& x, GF2 a, const vec_GF2E& b); |
---|
29 | void mul(vec_GF2E& x, long a, const vec_GF2E& b); |
---|
30 | // x = a * b |
---|
31 | |
---|
32 | void add(vec_GF2E& x, const vec_GF2E& a, const vec_GF2E& b); |
---|
33 | // x = a + b |
---|
34 | |
---|
35 | void sub(vec_GF2E& x, const vec_GF2E& a, const vec_GF2E& b); |
---|
36 | // x = a - b = x + a |
---|
37 | |
---|
38 | void negate(vec_GF2E& x, const vec_GF2E& a); |
---|
39 | // x = - a = a |
---|
40 | |
---|
41 | void clear(vec_GF2E& x); |
---|
42 | // x = 0 (length unchanged) |
---|
43 | |
---|
44 | long IsZero(const vec_GF2E& a); |
---|
45 | // test if a is the zero vector |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | void InnerProduct(GF2E& x, const vec_GF2E& a, const vec_GF2E& b); |
---|
50 | // x = sum_{i=0}^{n-1} a[i]*b[i], where n = min(a.length(), b.length()) |
---|
51 | |
---|
52 | void InnerProduct(GF2E& x, const vec_GF2E& a, const vec_GF2E& b, |
---|
53 | long offset); |
---|
54 | // x = sum_{i=offset}^{n-1} a[i]*b[i-offset], where n = min(a.length(), |
---|
55 | // b.length()+offset) |
---|
56 | |
---|
57 | void VectorCopy(vec_GF2E& x, const vec_GF2E& a, long n); |
---|
58 | vec_GF2E VectorCopy(const vec_GF2E& a, long n); |
---|
59 | // x = a copy of a of length exactly n. |
---|
60 | // The input is truncated or padded with zeroes, as necessary. |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | // operator notation: |
---|
65 | |
---|
66 | vec_GF2E |
---|
67 | operator+(const vec_GF2E& a, const vec_GF2E& b); |
---|
68 | |
---|
69 | vec_GF2E |
---|
70 | operator-(const vec_GF2E& a, const vec_GF2E& b); |
---|
71 | |
---|
72 | vec_GF2E operator-(const vec_GF2E& a); |
---|
73 | |
---|
74 | |
---|
75 | // vector/scalar multiplication: |
---|
76 | |
---|
77 | vec_GF2E operator*(const vec_GF2E& a, const GF2E& b); |
---|
78 | vec_GF2E operator*(const vec_GF2E& a, GF2 b); |
---|
79 | vec_GF2E operator*(const vec_GF2E& a, long b); |
---|
80 | |
---|
81 | vec_GF2E operator*(const GF2E& a, const vec_GF2E& b); |
---|
82 | vec_GF2E operator*(GF2 a, const vec_GF2E& b); |
---|
83 | vec_GF2E operator*(long a, const vec_GF2E& b); |
---|
84 | |
---|
85 | // inner product: |
---|
86 | |
---|
87 | GF2E operator*(const vec_GF2E& a, const vec_GF2E& b); |
---|
88 | |
---|
89 | |
---|
90 | // assignment operator notation: |
---|
91 | |
---|
92 | vec_GF2E& operator+=(vec_GF2E& x, const vec_GF2E& a); |
---|
93 | vec_GF2E& operator-=(vec_GF2E& x, const vec_GF2E& a); |
---|
94 | |
---|
95 | vec_GF2E& operator*=(vec_GF2E& x, const GF2E& a); |
---|
96 | vec_GF2E& operator*=(vec_GF2E& x, GF2 a); |
---|
97 | vec_GF2E& operator*=(vec_GF2E& x, long a); |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | // Implementation note: the BlockConstruct routine has been customized |
---|
102 | // for GF2E so that when a vec_GF2E is grown, space for the needed |
---|
103 | // elements is allocated in one contiguous chunk. This saves on calls to |
---|
104 | // malloc and free, and should also yield better locality of reference. |
---|
105 | // One consequence of this is that swapping an element of a vec_GF2E |
---|
106 | // with another GF2E can not be implemented by pointer swap, and will in |
---|
107 | // this case be done by copy. |
---|