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