| 1 | /* |
| 2 | * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
| 3 | * Use is subject to license terms. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public License |
| 16 | * along with this library; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | */ |
| 23 | |
| 24 | /* ********************************************************************* |
| 25 | * |
| 26 | * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library. |
| 27 | * |
| 28 | * The Initial Developer of the Original Code is |
| 29 | * Sun Microsystems, Inc. |
| 30 | * Portions created by the Initial Developer are Copyright (C) 2003 |
| 31 | * the Initial Developer. All Rights Reserved. |
| 32 | * |
| 33 | * Contributor(s): |
| 34 | * Sheueling Chang Shantz <sheueling.chang@sun.com> and |
| 35 | * Douglas Stebila <douglas@stebila.ca> of Sun Laboratories. |
| 36 | * |
| 37 | *********************************************************************** */ |
| 38 | |
| 39 | #ifndef _MP_GF2M_PRIV_H_ |
| 40 | #define _MP_GF2M_PRIV_H_ |
| 41 | |
| 42 | #include "mpi-priv.h" |
| 43 | |
| 44 | extern const mp_digit mp_gf2m_sqr_tb[16]; |
| 45 | |
| 46 | #if defined(MP_USE_UINT_DIGIT) |
| 47 | #define MP_DIGIT_BITS 32 |
| 48 | #else |
| 49 | #define MP_DIGIT_BITS 64 |
| 50 | #endif |
| 51 | |
| 52 | /* Platform-specific macros for fast binary polynomial squaring. */ |
| 53 | #if MP_DIGIT_BITS == 32 |
| 54 | #define gf2m_SQR1(w) \ |
| 55 | mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 16 | \ |
| 56 | mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] |
| 57 | #define gf2m_SQR0(w) \ |
| 58 | mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 8 & 0xF] << 16 | \ |
| 59 | mp_gf2m_sqr_tb[(w) >> 4 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) & 0xF] |
| 60 | #else |
| 61 | #define gf2m_SQR1(w) \ |
| 62 | mp_gf2m_sqr_tb[(w) >> 60 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 56 & 0xF] << 48 | \ |
| 63 | mp_gf2m_sqr_tb[(w) >> 52 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 48 & 0xF] << 32 | \ |
| 64 | mp_gf2m_sqr_tb[(w) >> 44 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 40 & 0xF] << 16 | \ |
| 65 | mp_gf2m_sqr_tb[(w) >> 36 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) >> 32 & 0xF] |
| 66 | #define gf2m_SQR0(w) \ |
| 67 | mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 48 | \ |
| 68 | mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] << 32 | \ |
| 69 | mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 8 & 0xF] << 16 | \ |
| 70 | mp_gf2m_sqr_tb[(w) >> 4 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) & 0xF] |
| 71 | #endif |
| 72 | |
| 73 | /* Multiply two binary polynomials mp_digits a, b. |
| 74 | * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1. |
| 75 | * Output in two mp_digits rh, rl. |
| 76 | */ |
| 77 | void s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b); |
| 78 | |
| 79 | /* Compute xor-multiply of two binary polynomials (a1, a0) x (b1, b0) |
| 80 | * result is a binary polynomial in 4 mp_digits r[4]. |
| 81 | * The caller MUST ensure that r has the right amount of space allocated. |
| 82 | */ |
| 83 | void s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1, |
| 84 | const mp_digit b0); |
| 85 | |
| 86 | /* Compute xor-multiply of two binary polynomials (a2, a1, a0) x (b2, b1, b0) |
| 87 | * result is a binary polynomial in 6 mp_digits r[6]. |
| 88 | * The caller MUST ensure that r has the right amount of space allocated. |
| 89 | */ |
| 90 | void s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0, |
| 91 | const mp_digit b2, const mp_digit b1, const mp_digit b0); |
| 92 | |
| 93 | /* Compute xor-multiply of two binary polynomials (a3, a2, a1, a0) x (b3, b2, b1, b0) |
| 94 | * result is a binary polynomial in 8 mp_digits r[8]. |
| 95 | * The caller MUST ensure that r has the right amount of space allocated. |
| 96 | */ |
| 97 | void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1, |
| 98 | const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1, |
| 99 | const mp_digit b0); |
| 100 | |
| 101 | #endif /* _MP_GF2M_PRIV_H_ */ |
| 102 | |