1 /* This file is part of the gf2x library.
2 
3    Copyright 2010, 2013, 2015
4    Richard Brent, Pierrick Gaudry, Emmanuel Thome', Paul Zimmermann
5 
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of either:
8     - If the archive contains a file named toom-gpl.c (not a trivial
9     placeholder), the GNU General Public License as published by the Free
10     Software Foundation; either version 3 of the License, or (at your
11     option) any later version.
12     - If the archive contains a file named toom-gpl.c which is a trivial
13     placeholder, the GNU Lesser General Public License as published by
14     the Free Software Foundation; either version 2.1 of the License, or
15     (at your option) any later version.
16 
17    This program is distributed in the hope that it will be useful, but WITHOUT
18    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19    FITNESS FOR A PARTICULAR PURPOSE.  See the license text for more details.
20 
21    You should have received a copy of the GNU General Public License as
22    well as the GNU Lesser General Public License along with this program;
23    see the files COPYING and COPYING.LIB.  If not, write to the Free
24    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25    02110-1301, USA.
26 */
27 
28 #ifndef GF2X_MUL5_H_
29 #define GF2X_MUL5_H_
30 
31 #include "gf2x.h"
32 /* All gf2x source files for lowlevel functions must include gf2x-small.h
33  * This is mandatory for the tuning mechanism. */
34 #include "gf2x/gf2x-small.h"
35 
36 GF2X_STORAGE_CLASS_mul5
gf2x_mul5(unsigned long * c,const unsigned long * a,const unsigned long * b)37 void gf2x_mul5 (unsigned long *c, const unsigned long *a, const unsigned long *b)
38 {
39     /* adapted from gf2x_mul6, with a[5]=b[5]=c[10]=c[11]=0 */
40     unsigned long d01[4], d1[4], d12[4], aa[2], bb[2];
41     gf2x_mul2 (c,         a,     b); /* D0 */
42     gf2x_mul2 (d1,    a + 2, b + 2); /* D1 */
43     gf2x_mul1 (c + 8, a[4], b[4]);   /* D2 has only two words */
44     aa[0] = a[0] ^ a[2]; aa[1] = a[1] ^ a[3];
45     bb[0] = b[0] ^ b[2]; bb[1] = b[1] ^ b[3];
46     gf2x_mul2 (d01, aa, bb);         /* D01 */
47     aa[0] = a[0] ^ a[4]; aa[1] = a[1];
48     bb[0] = b[0] ^ b[4]; bb[1] = b[1];
49     gf2x_mul2 (c + 4, aa, bb);       /* D02 */
50     aa[0] = a[2] ^ a[4]; aa[1] = a[3];
51     bb[0] = b[2] ^ b[4]; bb[1] = b[3];
52     gf2x_mul2 (d12, aa, bb);         /* D12 */
53     /* low(D1) + high(D0) is used three times */
54     c[2] ^= d1[0]; c[3] ^= d1[1];   /* low(D1) + high(D0) */
55     c[4] ^= c[2];  c[5] ^= c[3];    /* low(D02) + low(D1) + high(D0) */
56     d12[0] ^= c[2]; d12[1] ^= c[3]; /* low(D12) + low(D1) + high(D0) */
57     /* low(D2) + high(D1) is used three times */
58     c[8] ^= d1[2]; c[9] ^= d1[3];   /* low(D2) + high(D1) */
59     c[6] ^= c[8];  c[7] ^= c[9];    /* high(D02) + low(D2) + high(D1) */
60     d01[2] ^= c[8]; d01[3] ^= c[9]; /* high(D01) + low(D2) + high(D1) */
61     c[2] ^= d01[0] ^ c[0]; c[3] ^= d01[1] ^ c[1]; /* l(D1)+h(D0)+l(D01)+l(D0) */
62     c[4] ^= c[0] ^ d01[2]; c[5] ^= c[1] ^ d01[3];
63     c[6] ^= d12[0]; c[7] ^= d12[1];
64     c[8] ^= d12[2]; c[9] ^= d12[3];
65 }
66 
67 #endif  /* GF2X_MUL5_H_ */
68