1 // This file is part of the FXT library.
2 // Copyright (C) 2010, 2011, 2012 Joerg Arndt
3 // License: GNU General Public License version 3 or later,
4 // see the file COPYING.txt in the main directory.
5
6 #include "bits/bitrotate.h"
7 #include "bits/parity.h"
8
9 #include "bmat/bitmat-inline.h"
10
11 #include "fxttypes.h" // ulong
12 //#include "bits/print-bin.h"
13 //#include "fxtio.h"
14
15
16 ulong
normal_mult(ulong a,ulong b,const ulong * M,ulong n)17 normal_mult(ulong a, ulong b, const ulong *M, ulong n)
18 // Multiply two elements (a and b in GF(2^n)) in normal basis representation.
19 // The multiplication matrix has to be supplied in M.
20 {
21 ulong p = 0;
22 for (ulong k=0; k<n; ++k)
23 {
24 #if 0
25 ulong v = bitmat_mult_Mv(M, n, b); // M*b
26 v = parity( v & a ); // a*M*b (dot product)
27 p ^= ( v << k );
28 a = bit_rotate_right(a, 1, n);
29 b = bit_rotate_right(b, 1, n);
30
31 #else // more efficient:
32
33 ulong v = bitmat_mult_vM(M, n, a); // a*M
34 v = parity( v & b ); // a*M*b (dot product)
35 p ^= ( v << k );
36 a = bit_rotate_right(a, 1, n);
37 b = bit_rotate_right(b, 1, n);
38 #endif
39 }
40 return p;
41 }
42 // -------------------------
43