|
1 /* ********************************************************************* |
|
2 * |
|
3 * Sun elects to have this file available under and governed by the |
|
4 * Mozilla Public License Version 1.1 ("MPL") (see |
|
5 * http://www.mozilla.org/MPL/ for full license text). For the avoidance |
|
6 * of doubt and subject to the following, Sun also elects to allow |
|
7 * licensees to use this file under the MPL, the GNU General Public |
|
8 * License version 2 only or the Lesser General Public License version |
|
9 * 2.1 only. Any references to the "GNU General Public License version 2 |
|
10 * or later" or "GPL" in the following shall be construed to mean the |
|
11 * GNU General Public License version 2 only. Any references to the "GNU |
|
12 * Lesser General Public License version 2.1 or later" or "LGPL" in the |
|
13 * following shall be construed to mean the GNU Lesser General Public |
|
14 * License version 2.1 only. However, the following notice accompanied |
|
15 * the original version of this file: |
|
16 * |
|
17 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
|
18 * |
|
19 * The contents of this file are subject to the Mozilla Public License Version |
|
20 * 1.1 (the "License"); you may not use this file except in compliance with |
|
21 * the License. You may obtain a copy of the License at |
|
22 * http://www.mozilla.org/MPL/ |
|
23 * |
|
24 * Software distributed under the License is distributed on an "AS IS" basis, |
|
25 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
|
26 * for the specific language governing rights and limitations under the |
|
27 * License. |
|
28 * |
|
29 * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library. |
|
30 * |
|
31 * The Initial Developer of the Original Code is |
|
32 * Sun Microsystems, Inc. |
|
33 * Portions created by the Initial Developer are Copyright (C) 2003 |
|
34 * the Initial Developer. All Rights Reserved. |
|
35 * |
|
36 * Contributor(s): |
|
37 * Sheueling Chang Shantz <sheueling.chang@sun.com> and |
|
38 * Douglas Stebila <douglas@stebila.ca> of Sun Laboratories. |
|
39 * |
|
40 * Alternatively, the contents of this file may be used under the terms of |
|
41 * either the GNU General Public License Version 2 or later (the "GPL"), or |
|
42 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
|
43 * in which case the provisions of the GPL or the LGPL are applicable instead |
|
44 * of those above. If you wish to allow use of your version of this file only |
|
45 * under the terms of either the GPL or the LGPL, and not to allow others to |
|
46 * use your version of this file under the terms of the MPL, indicate your |
|
47 * decision by deleting the provisions above and replace them with the notice |
|
48 * and other provisions required by the GPL or the LGPL. If you do not delete |
|
49 * the provisions above, a recipient may use your version of this file under |
|
50 * the terms of any one of the MPL, the GPL or the LGPL. |
|
51 * |
|
52 *********************************************************************** */ |
|
53 /* |
|
54 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
|
55 * Use is subject to license terms. |
|
56 */ |
|
57 |
|
58 #ifndef _MP_GF2M_PRIV_H_ |
|
59 #define _MP_GF2M_PRIV_H_ |
|
60 |
|
61 #pragma ident "%Z%%M% %I% %E% SMI" |
|
62 |
|
63 #include "mpi-priv.h" |
|
64 |
|
65 extern const mp_digit mp_gf2m_sqr_tb[16]; |
|
66 |
|
67 #if defined(MP_USE_UINT_DIGIT) |
|
68 #define MP_DIGIT_BITS 32 |
|
69 #else |
|
70 #define MP_DIGIT_BITS 64 |
|
71 #endif |
|
72 |
|
73 /* Platform-specific macros for fast binary polynomial squaring. */ |
|
74 #if MP_DIGIT_BITS == 32 |
|
75 #define gf2m_SQR1(w) \ |
|
76 mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 16 | \ |
|
77 mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] |
|
78 #define gf2m_SQR0(w) \ |
|
79 mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 8 & 0xF] << 16 | \ |
|
80 mp_gf2m_sqr_tb[(w) >> 4 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) & 0xF] |
|
81 #else |
|
82 #define gf2m_SQR1(w) \ |
|
83 mp_gf2m_sqr_tb[(w) >> 60 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 56 & 0xF] << 48 | \ |
|
84 mp_gf2m_sqr_tb[(w) >> 52 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 48 & 0xF] << 32 | \ |
|
85 mp_gf2m_sqr_tb[(w) >> 44 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 40 & 0xF] << 16 | \ |
|
86 mp_gf2m_sqr_tb[(w) >> 36 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) >> 32 & 0xF] |
|
87 #define gf2m_SQR0(w) \ |
|
88 mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 48 | \ |
|
89 mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] << 32 | \ |
|
90 mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 8 & 0xF] << 16 | \ |
|
91 mp_gf2m_sqr_tb[(w) >> 4 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) & 0xF] |
|
92 #endif |
|
93 |
|
94 /* Multiply two binary polynomials mp_digits a, b. |
|
95 * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1. |
|
96 * Output in two mp_digits rh, rl. |
|
97 */ |
|
98 void s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b); |
|
99 |
|
100 /* Compute xor-multiply of two binary polynomials (a1, a0) x (b1, b0) |
|
101 * result is a binary polynomial in 4 mp_digits r[4]. |
|
102 * The caller MUST ensure that r has the right amount of space allocated. |
|
103 */ |
|
104 void s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1, |
|
105 const mp_digit b0); |
|
106 |
|
107 /* Compute xor-multiply of two binary polynomials (a2, a1, a0) x (b2, b1, b0) |
|
108 * result is a binary polynomial in 6 mp_digits r[6]. |
|
109 * The caller MUST ensure that r has the right amount of space allocated. |
|
110 */ |
|
111 void s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0, |
|
112 const mp_digit b2, const mp_digit b1, const mp_digit b0); |
|
113 |
|
114 /* Compute xor-multiply of two binary polynomials (a3, a2, a1, a0) x (b3, b2, b1, b0) |
|
115 * result is a binary polynomial in 8 mp_digits r[8]. |
|
116 * The caller MUST ensure that r has the right amount of space allocated. |
|
117 */ |
|
118 void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1, |
|
119 const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1, |
|
120 const mp_digit b0); |
|
121 |
|
122 #endif /* _MP_GF2M_PRIV_H_ */ |