Back to index

lightning-sunbird  0.9+nobinonly
mp_gf2m-priv.h
Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Sun Microsystems, Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Sheueling Chang Shantz <sheueling.chang@sun.com> and
00024  *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef _MP_GF2M_PRIV_H_
00041 #define _MP_GF2M_PRIV_H_
00042 
00043 #include "mpi-priv.h"
00044 
00045 extern const mp_digit mp_gf2m_sqr_tb[16];
00046 
00047 #if defined(MP_USE_UINT_DIGIT)
00048 #define MP_DIGIT_BITS 32
00049 #else
00050 #define MP_DIGIT_BITS 64
00051 #endif
00052 
00053 /* Platform-specific macros for fast binary polynomial squaring. */
00054 #if MP_DIGIT_BITS == 32
00055 #define gf2m_SQR1(w) \
00056     mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 16 | \
00057     mp_gf2m_sqr_tb[(w) >> 20 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF]
00058 #define gf2m_SQR0(w) \
00059     mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >>  8 & 0xF] << 16 | \
00060     mp_gf2m_sqr_tb[(w) >>  4 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w)       & 0xF]
00061 #else
00062 #define gf2m_SQR1(w) \
00063     mp_gf2m_sqr_tb[(w) >> 60 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 56 & 0xF] << 48 | \
00064     mp_gf2m_sqr_tb[(w) >> 52 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 48 & 0xF] << 32 | \
00065     mp_gf2m_sqr_tb[(w) >> 44 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 40 & 0xF] << 16 | \
00066     mp_gf2m_sqr_tb[(w) >> 36 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w) >> 32 & 0xF]
00067 #define gf2m_SQR0(w) \
00068     mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 48 | \
00069     mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] << 32 | \
00070     mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >>  8 & 0xF] << 16 | \
00071     mp_gf2m_sqr_tb[(w) >>  4 & 0xF] <<  8 | mp_gf2m_sqr_tb[(w)       & 0xF]
00072 #endif
00073 
00074 /* Multiply two binary polynomials mp_digits a, b.
00075  * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1.
00076  * Output in two mp_digits rh, rl.
00077  */
00078 void s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b);
00079 
00080 /* Compute xor-multiply of two binary polynomials  (a1, a0) x (b1, b0)  
00081  * result is a binary polynomial in 4 mp_digits r[4].
00082  * The caller MUST ensure that r has the right amount of space allocated.
00083  */
00084 void s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1,
00085        const mp_digit b0);
00086 
00087 /* Compute xor-multiply of two binary polynomials  (a2, a1, a0) x (b2, b1, b0)  
00088  * result is a binary polynomial in 6 mp_digits r[6].
00089  * The caller MUST ensure that r has the right amount of space allocated.
00090  */
00091 void s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0, 
00092        const mp_digit b2, const mp_digit b1, const mp_digit b0);
00093 
00094 /* Compute xor-multiply of two binary polynomials  (a3, a2, a1, a0) x (b3, b2, b1, b0)  
00095  * result is a binary polynomial in 8 mp_digits r[8].
00096  * The caller MUST ensure that r has the right amount of space allocated.
00097  */
00098 void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1, 
00099        const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1, 
00100        const mp_digit b0);
00101 
00102 #endif /* _MP_GF2M_PRIV_H_ */