Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 1870

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: gf128mul.cc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>gf128mul.cc</h1><a href="gf128mul_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> ---------------------------------------------------------------------------</span>
<a name="l00004"></a>00004 <span class="comment"> Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.</span>
<a name="l00005"></a>00005 <span class="comment"></span>
<a name="l00006"></a>00006 <span class="comment"> LICENSE TERMS</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment"> The free distribution and use of this software in both source and binary</span>
<a name="l00009"></a>00009 <span class="comment"> form is allowed (with or without changes) provided that:</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">   1. distributions of this source code include the above copyright</span>
<a name="l00012"></a>00012 <span class="comment">      notice, this list of conditions and the following disclaimer;</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment">   2. distributions in binary form include the above copyright</span>
<a name="l00015"></a>00015 <span class="comment">      notice, this list of conditions and the following disclaimer</span>
<a name="l00016"></a>00016 <span class="comment">      in the documentation and/or other associated materials;</span>
<a name="l00017"></a>00017 <span class="comment"></span>
<a name="l00018"></a>00018 <span class="comment">   3. the copyright holder's name is not used to endorse products</span>
<a name="l00019"></a>00019 <span class="comment">      built using this software without specific written permission.</span>
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment"> ALTERNATIVELY, provided that this notice is retained in full, this product</span>
<a name="l00022"></a>00022 <span class="comment"> may be distributed under the terms of the GNU General Public License (GPL),</span>
<a name="l00023"></a>00023 <span class="comment"> in which case the provisions of the GPL apply INSTEAD OF those given above.</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00025"></a>00025 <span class="comment"> DISCLAIMER</span>
<a name="l00026"></a>00026 <span class="comment"></span>
<a name="l00027"></a>00027 <span class="comment"> This software is provided 'as is' with no explicit or implied warranties</span>
<a name="l00028"></a>00028 <span class="comment"> in respect of its properties, including, but not limited to, correctness</span>
<a name="l00029"></a>00029 <span class="comment"> and/or fitness for purpose.</span>
<a name="l00030"></a>00030 <span class="comment"> ---------------------------------------------------------------------------</span>
<a name="l00031"></a>00031 <span class="comment"> Issue 31/01/2006</span>
<a name="l00032"></a>00032 <span class="comment"></span>
<a name="l00033"></a>00033 <span class="comment"> This file provides fast multiplication in GF(128) as required by several</span>
<a name="l00034"></a>00034 <span class="comment"> cryptographic authentication modes</span>
<a name="l00035"></a>00035 <span class="comment">*/</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#endif</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="preprocessor">#ifdef BSP_ENABLED</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00043"></a>00043 <span class="preprocessor">#include "<a class="code" href="brg__types_8h.html">brg_types.h</a>"</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include "<a class="code" href="brg__endian_8h.html">brg_endian.h</a>"</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include "<a class="code" href="gf128mul_8h.html">gf128mul.h</a>"</span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="preprocessor">#define gf_dat(q) {\</span>
<a name="l00048"></a>00048 <span class="preprocessor">    q(0x00), q(0x01), q(0x02), q(0x03), q(0x04), q(0x05), q(0x06), q(0x07),\</span>
<a name="l00049"></a>00049 <span class="preprocessor">    q(0x08), q(0x09), q(0x0a), q(0x0b), q(0x0c), q(0x0d), q(0x0e), q(0x0f),\</span>
<a name="l00050"></a>00050 <span class="preprocessor">    q(0x10), q(0x11), q(0x12), q(0x13), q(0x14), q(0x15), q(0x16), q(0x17),\</span>
<a name="l00051"></a>00051 <span class="preprocessor">    q(0x18), q(0x19), q(0x1a), q(0x1b), q(0x1c), q(0x1d), q(0x1e), q(0x1f),\</span>
<a name="l00052"></a>00052 <span class="preprocessor">    q(0x20), q(0x21), q(0x22), q(0x23), q(0x24), q(0x25), q(0x26), q(0x27),\</span>
<a name="l00053"></a>00053 <span class="preprocessor">    q(0x28), q(0x29), q(0x2a), q(0x2b), q(0x2c), q(0x2d), q(0x2e), q(0x2f),\</span>
<a name="l00054"></a>00054 <span class="preprocessor">    q(0x30), q(0x31), q(0x32), q(0x33), q(0x34), q(0x35), q(0x36), q(0x37),\</span>
<a name="l00055"></a>00055 <span class="preprocessor">    q(0x38), q(0x39), q(0x3a), q(0x3b), q(0x3c), q(0x3d), q(0x3e), q(0x3f),\</span>
<a name="l00056"></a>00056 <span class="preprocessor">    q(0x40), q(0x41), q(0x42), q(0x43), q(0x44), q(0x45), q(0x46), q(0x47),\</span>
<a name="l00057"></a>00057 <span class="preprocessor">    q(0x48), q(0x49), q(0x4a), q(0x4b), q(0x4c), q(0x4d), q(0x4e), q(0x4f),\</span>
<a name="l00058"></a>00058 <span class="preprocessor">    q(0x50), q(0x51), q(0x52), q(0x53), q(0x54), q(0x55), q(0x56), q(0x57),\</span>
<a name="l00059"></a>00059 <span class="preprocessor">    q(0x58), q(0x59), q(0x5a), q(0x5b), q(0x5c), q(0x5d), q(0x5e), q(0x5f),\</span>
<a name="l00060"></a>00060 <span class="preprocessor">    q(0x60), q(0x61), q(0x62), q(0x63), q(0x64), q(0x65), q(0x66), q(0x67),\</span>
<a name="l00061"></a>00061 <span class="preprocessor">    q(0x68), q(0x69), q(0x6a), q(0x6b), q(0x6c), q(0x6d), q(0x6e), q(0x6f),\</span>
<a name="l00062"></a>00062 <span class="preprocessor">    q(0x70), q(0x71), q(0x72), q(0x73), q(0x74), q(0x75), q(0x76), q(0x77),\</span>
<a name="l00063"></a>00063 <span class="preprocessor">    q(0x78), q(0x79), q(0x7a), q(0x7b), q(0x7c), q(0x7d), q(0x7e), q(0x7f),\</span>
<a name="l00064"></a>00064 <span class="preprocessor">    q(0x80), q(0x81), q(0x82), q(0x83), q(0x84), q(0x85), q(0x86), q(0x87),\</span>
<a name="l00065"></a>00065 <span class="preprocessor">    q(0x88), q(0x89), q(0x8a), q(0x8b), q(0x8c), q(0x8d), q(0x8e), q(0x8f),\</span>
<a name="l00066"></a>00066 <span class="preprocessor">    q(0x90), q(0x91), q(0x92), q(0x93), q(0x94), q(0x95), q(0x96), q(0x97),\</span>
<a name="l00067"></a>00067 <span class="preprocessor">    q(0x98), q(0x99), q(0x9a), q(0x9b), q(0x9c), q(0x9d), q(0x9e), q(0x9f),\</span>
<a name="l00068"></a>00068 <span class="preprocessor">    q(0xa0), q(0xa1), q(0xa2), q(0xa3), q(0xa4), q(0xa5), q(0xa6), q(0xa7),\</span>
<a name="l00069"></a>00069 <span class="preprocessor">    q(0xa8), q(0xa9), q(0xaa), q(0xab), q(0xac), q(0xad), q(0xae), q(0xaf),\</span>
<a name="l00070"></a>00070 <span class="preprocessor">    q(0xb0), q(0xb1), q(0xb2), q(0xb3), q(0xb4), q(0xb5), q(0xb6), q(0xb7),\</span>
<a name="l00071"></a>00071 <span class="preprocessor">    q(0xb8), q(0xb9), q(0xba), q(0xbb), q(0xbc), q(0xbd), q(0xbe), q(0xbf),\</span>
<a name="l00072"></a>00072 <span class="preprocessor">    q(0xc0), q(0xc1), q(0xc2), q(0xc3), q(0xc4), q(0xc5), q(0xc6), q(0xc7),\</span>
<a name="l00073"></a>00073 <span class="preprocessor">    q(0xc8), q(0xc9), q(0xca), q(0xcb), q(0xcc), q(0xcd), q(0xce), q(0xcf),\</span>
<a name="l00074"></a>00074 <span class="preprocessor">    q(0xd0), q(0xd1), q(0xd2), q(0xd3), q(0xd4), q(0xd5), q(0xd6), q(0xd7),\</span>
<a name="l00075"></a>00075 <span class="preprocessor">    q(0xd8), q(0xd9), q(0xda), q(0xdb), q(0xdc), q(0xdd), q(0xde), q(0xdf),\</span>
<a name="l00076"></a>00076 <span class="preprocessor">    q(0xe0), q(0xe1), q(0xe2), q(0xe3), q(0xe4), q(0xe5), q(0xe6), q(0xe7),\</span>
<a name="l00077"></a>00077 <span class="preprocessor">    q(0xe8), q(0xe9), q(0xea), q(0xeb), q(0xec), q(0xed), q(0xee), q(0xef),\</span>
<a name="l00078"></a>00078 <span class="preprocessor">    q(0xf0), q(0xf1), q(0xf2), q(0xf3), q(0xf4), q(0xf5), q(0xf6), q(0xf7),\</span>
<a name="l00079"></a>00079 <span class="preprocessor">    q(0xf8), q(0xf9), q(0xfa), q(0xfb), q(0xfc), q(0xfd), q(0xfe), q(0xff) }</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span>
<a name="l00081"></a>00081 
<a name="l00082"></a>00082 <span class="comment">/*  Given the value i in 0..255 as the byte overflow when a field element</span>
<a name="l00083"></a>00083 <span class="comment">    in GHASH is multipled by x^8, this function will return the values that</span>
<a name="l00084"></a>00084 <span class="comment">    are generated in the lo 16-bit word of the field value by applying the</span>
<a name="l00085"></a>00085 <span class="comment">    modular polynomial. The values lo_byte and hi_byte are returned via the</span>
<a name="l00086"></a>00086 <span class="comment">    macro xp_fun(lo_byte, hi_byte) so that the values can be assembled into</span>
<a name="l00087"></a>00087 <span class="comment">    memory as required by a suitable definition of this macro operating on</span>
<a name="l00088"></a>00088 <span class="comment">    the table above</span>
<a name="l00089"></a>00089 <span class="comment">*/</span>
<a name="l00090"></a>00090 
<a name="l00091"></a>00091 <span class="preprocessor">#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#  define xx(p,q)   0x##q##p    </span><span class="comment">/* assemble in little endian order */</span>
<a name="l00093"></a>00093 <span class="preprocessor">#else</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor">#  define xx(p,q)   0x##p##q    </span><span class="comment">/* assemble in big endian order    */</span>
<a name="l00095"></a>00095 <span class="preprocessor">#endif</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span>
<a name="l00097"></a>00097 <span class="preprocessor">#define xda(i) (                                              \</span>
<a name="l00098"></a>00098 <span class="preprocessor">    (i &amp; 0x80 ? xx(e1,00) : 0) ^ (i &amp; 0x40 ? xx(70,80) : 0) ^ \</span>
<a name="l00099"></a>00099 <span class="preprocessor">    (i &amp; 0x20 ? xx(38,40) : 0) ^ (i &amp; 0x10 ? xx(1c,20) : 0) ^ \</span>
<a name="l00100"></a>00100 <span class="preprocessor">    (i &amp; 0x08 ? xx(0e,10) : 0) ^ (i &amp; 0x04 ? xx(07,08) : 0) ^ \</span>
<a name="l00101"></a>00101 <span class="preprocessor">    (i &amp; 0x02 ? xx(03,84) : 0) ^ (i &amp; 0x01 ? xx(01,c2) : 0) )</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span>
<a name="l00103"></a>00103 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="gf128mul_8h.html#5ac31cee258e0700bf2ca6273047d31b">gf_tab</a>[256] = gf_dat(xda);
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 <span class="keywordtype">void</span> <a class="code" href="gf128mul_8h.html#4d596dd0da0ecc262a6ad482262f4c8c">gf_mul</a>(<span class="keywordtype">void</span> *a, <span class="keyword">const</span> <span class="keywordtype">void</span>* b)
<a name="l00106"></a>00106 {   uint_32t r[<a class="code" href="gf128mul_8h.html#71e85162c7a6927d581e972a49d0d496">GF_BYTE_LEN</a> &gt;&gt; 2], p[8][<a class="code" href="gf128mul_8h.html#71e85162c7a6927d581e972a49d0d496">GF_BYTE_LEN</a> &gt;&gt; 2];
<a name="l00107"></a>00107     <span class="keywordtype">int</span> i;
<a name="l00108"></a>00108 
<a name="l00109"></a>00109     <a class="code" href="mode__hdr_8h.html#0f54ed87500e2f9378f2f7b350791a7d">move_block_aligned</a>(p[0], b);
<a name="l00110"></a>00110     <span class="keywordflow">for</span>(i = 0; i &lt; 7; ++i)
<a name="l00111"></a>00111         mul_x(p[i + 1], p[i]);
<a name="l00112"></a>00112 
<a name="l00113"></a>00113     memset(r, 0, <a class="code" href="gf128mul_8h.html#71e85162c7a6927d581e972a49d0d496">GF_BYTE_LEN</a>);
<a name="l00114"></a>00114     <span class="keywordflow">for</span>(i = 0; i &lt; 16; ++i)
<a name="l00115"></a>00115     {   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ch = ((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)a)[15 - i];
<a name="l00116"></a>00116         <span class="keywordflow">if</span>(i) mul_x8(r);
<a name="l00117"></a>00117 
<a name="l00118"></a>00118         <span class="keywordflow">if</span>(ch &amp; 0x80)
<a name="l00119"></a>00119             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[0]);
<a name="l00120"></a>00120         <span class="keywordflow">if</span>(ch &amp; 0x40)
<a name="l00121"></a>00121             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[1]);
<a name="l00122"></a>00122         <span class="keywordflow">if</span>(ch &amp; 0x20)
<a name="l00123"></a>00123             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[2]);
<a name="l00124"></a>00124         <span class="keywordflow">if</span>(ch &amp; 0x10)
<a name="l00125"></a>00125             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[3]);
<a name="l00126"></a>00126         <span class="keywordflow">if</span>(ch &amp; 0x08)
<a name="l00127"></a>00127             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[4]);
<a name="l00128"></a>00128         <span class="keywordflow">if</span>(ch &amp; 0x04)
<a name="l00129"></a>00129             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[5]);
<a name="l00130"></a>00130         <span class="keywordflow">if</span>(ch &amp; 0x02)
<a name="l00131"></a>00131             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[6]);
<a name="l00132"></a>00132         <span class="keywordflow">if</span>(ch &amp; 0x01)
<a name="l00133"></a>00133             <a class="code" href="mode__hdr_8h.html#27e5e634e05aa9fa2f09e8c1cabe8100">xor_block_aligned</a>(r, p[7]);
<a name="l00134"></a>00134     }
<a name="l00135"></a>00135     <a class="code" href="mode__hdr_8h.html#0f54ed87500e2f9378f2f7b350791a7d">move_block_aligned</a>(a, r);
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 
<a name="l00138"></a>00138 <span class="preprocessor">#if defined( TABLES_64K )</span>
<a name="l00139"></a>00139 <span class="preprocessor"></span>
<a name="l00140"></a>00140 <span class="keywordtype">void</span> <a class="code" href="gf128mul_8h.html#741bf0a5a9414cba0e449b60aa0de330">init_64k_table</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> g[], <span class="keywordtype">void</span> *t)
<a name="l00141"></a>00141 {   <span class="keywordtype">int</span> i, j, k;
<a name="l00142"></a>00142 
<a name="l00143"></a>00143     memset(t, 0, 16 * 256 * 16);
<a name="l00144"></a>00144     <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="gf128mul_8h.html#71e85162c7a6927d581e972a49d0d496">GF_BYTE_LEN</a>; ++i)
<a name="l00145"></a>00145     {
<a name="l00146"></a>00146         <span class="keywordflow">if</span>(!i)
<a name="l00147"></a>00147         {
<a name="l00148"></a>00148             memcpy(<a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[0][128], g, GF_BYTE_LEN);
<a name="l00149"></a>00149             <span class="keywordflow">for</span>(j = 64; j &gt; 0; j &gt;&gt;= 1)
<a name="l00150"></a>00150                 mul_x(<a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[0][j], <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[0][j + j]);
<a name="l00151"></a>00151         }
<a name="l00152"></a>00152         <span class="keywordflow">else</span>
<a name="l00153"></a>00153             <span class="keywordflow">for</span>(j = 128; j &gt; 0; j &gt;&gt;= 1)
<a name="l00154"></a>00154             {
<a name="l00155"></a>00155                 memcpy(<a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j], <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i - 1][j], GF_BYTE_LEN);
<a name="l00156"></a>00156                 mul_x8(<a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j]);
<a name="l00157"></a>00157             }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159         <span class="keywordflow">for</span>(j = 2; j &lt; 256; j += j)
<a name="l00160"></a>00160             <span class="keywordflow">for</span>(k = 1; k &lt; j; ++k)
<a name="l00161"></a>00161             {
<a name="l00162"></a>00162                 <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j + k][0] = <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j][0] ^ <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][k][0];
<a name="l00163"></a>00163                 <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j + k][1] = <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j][1] ^ <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][k][1];
<a name="l00164"></a>00164                 <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j + k][2] = <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j][2] ^ <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][k][2];
<a name="l00165"></a>00165                 <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j + k][3] = <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][j][3] ^ <a class="code" href="gf128mul_8h.html#2104f6ab0725d0d84b0fc87c83439da6">tab64k</a>(t)[i][k][3];
<a name="l00166"></a>00166             }
<a name="l00167"></a>00167     }
<a name="l00168"></a>00168 }
<a name="l00169"></a>00169 
<a name="l00170"></a>00170 <span class="preprocessor">#endif</span>
<a name="l00171"></a>00171 <span class="preprocessor"></span>
<a name="l00172"></a>00172 <span class="preprocessor">#if defined( TABLES_8K )</span>
<a name="l00173"></a>00173 <span class="preprocessor"></span>
<a name="l00174"></a>00174 <span class="keywordtype">void</span> <a class="code" href="gf128mul_8h.html#ba357f33a03ac6ab2168767c793f2cff">init_8k_table</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> g[], <span class="keywordtype">void</span> *t)
<a name="l00175"></a>00175 {   <span class="keywordtype">int</span> i, j, k;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177     memset(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t), 0, 32 * 16 * 16);
<a name="l00178"></a>00178     <span class="keywordflow">for</span>(i = 0; i &lt; 2 * GF_BYTE_LEN; ++i)
<a name="l00179"></a>00179     {
<a name="l00180"></a>00180         <span class="keywordflow">if</span>(i == 0)
<a name="l00181"></a>00181         {
<a name="l00182"></a>00182             memcpy(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[1][8], g, GF_BYTE_LEN);
<a name="l00183"></a>00183             <span class="keywordflow">for</span>(j = 4; j &gt; 0; j &gt;&gt;= 1)
<a name="l00184"></a>00184                 mul_x(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[1][j], <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[1][j + j]);
<a name="l00185"></a>00185 
<a name="l00186"></a>00186             mul_x(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[0][8], <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[1][1]);
<a name="l00187"></a>00187 
<a name="l00188"></a>00188             <span class="keywordflow">for</span>(j = 4; j &gt; 0; j &gt;&gt;= 1)
<a name="l00189"></a>00189                 mul_x(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[0][j], <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[0][j + j]);
<a name="l00190"></a>00190         }
<a name="l00191"></a>00191         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(i &gt; 1)
<a name="l00192"></a>00192             <span class="keywordflow">for</span>(j = 8; j &gt; 0; j &gt;&gt;= 1)
<a name="l00193"></a>00193             {
<a name="l00194"></a>00194                 memcpy(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j], <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i - 2][j], GF_BYTE_LEN);
<a name="l00195"></a>00195                 mul_x8(<a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j]);
<a name="l00196"></a>00196             }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <span class="keywordflow">for</span>(j = 2; j &lt; 16; j += j)
<a name="l00199"></a>00199             <span class="keywordflow">for</span>(k = 1; k &lt; j; ++k)
<a name="l00200"></a>00200             {
<a name="l00201"></a>00201                 <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j + k][0] = <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j][0] ^ <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][k][0];
<a name="l00202"></a>00202                 <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j + k][1] = <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j][1] ^ <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][k][1];
<a name="l00203"></a>00203                 <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j + k][2] = <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j][2] ^ <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][k][2];
<a name="l00204"></a>00204                 <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j + k][3] = <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][j][3] ^ <a class="code" href="gf128mul_8h.html#75a5b58e6e61f3d890856236af267212">tab8k</a>(t)[i][k][3];
<a name="l00205"></a>00205             }
<a name="l00206"></a>00206     }
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209 <span class="preprocessor">#endif</span>
<a name="l00210"></a>00210 <span class="preprocessor"></span>
<a name="l00211"></a>00211 <span class="preprocessor">#if defined( TABLES_4K )</span>
<a name="l00212"></a>00212 <span class="preprocessor"></span>
<a name="l00213"></a>00213 <span class="keywordtype">void</span> <a class="code" href="gf128mul_8h.html#7e282fa94ff8923ddce24e345feb814c">init_4k_table</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> g[], <span class="keywordtype">void</span> *t)
<a name="l00214"></a>00214 {   <span class="keywordtype">int</span> j, k;
<a name="l00215"></a>00215 
<a name="l00216"></a>00216     memset(<a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t), 0, 256 * 16);
<a name="l00217"></a>00217     memcpy(<a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[128], g, GF_BYTE_LEN);
<a name="l00218"></a>00218     <span class="keywordflow">for</span>(j = 64; j &gt; 0; j &gt;&gt;= 1)
<a name="l00219"></a>00219     {
<a name="l00220"></a>00220         mul_x(<a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j], <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j + j]);
<a name="l00221"></a>00221     }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223     <span class="keywordflow">for</span>(j = 2; j &lt; 256; j += j)
<a name="l00224"></a>00224         <span class="keywordflow">for</span>(k = 1; k &lt; j; ++k)
<a name="l00225"></a>00225         {
<a name="l00226"></a>00226             <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j + k][0] = <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j][0] ^ <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[k][0];
<a name="l00227"></a>00227             <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j + k][1] = <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j][1] ^ <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[k][1];
<a name="l00228"></a>00228             <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j + k][2] = <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j][2] ^ <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[k][2];
<a name="l00229"></a>00229             <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j + k][3] = <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[j][3] ^ <a class="code" href="gf128mul_8h.html#276c261ec324bfa266b70b66bbea0dcb">tab4k</a>(t)[k][3];
<a name="l00230"></a>00230         }
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232 
<a name="l00233"></a>00233 <span class="preprocessor">#endif</span>
<a name="l00234"></a>00234 <span class="preprocessor"></span>
<a name="l00235"></a>00235 <span class="preprocessor">#if defined( TABLES_256 )</span>
<a name="l00236"></a>00236 <span class="preprocessor"></span>
<a name="l00237"></a>00237 <span class="keywordtype">void</span> <a class="code" href="gf128mul_8h.html#6e5c2dbe4a3432e5b667df324c7de42e">init_256_table</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> g[], <span class="keywordtype">void</span> *t)
<a name="l00238"></a>00238 {   <span class="keywordtype">int</span> j, k;
<a name="l00239"></a>00239 
<a name="l00240"></a>00240     memset(<a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t), 0, 16 * 16);
<a name="l00241"></a>00241     memcpy(<a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[8], g, GF_BYTE_LEN);
<a name="l00242"></a>00242     <span class="keywordflow">for</span>(j = 4; j &gt; 0; j &gt;&gt;= 1)
<a name="l00243"></a>00243     {
<a name="l00244"></a>00244         mul_x(<a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j], <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j + j]);
<a name="l00245"></a>00245     }
<a name="l00246"></a>00246 
<a name="l00247"></a>00247     <span class="keywordflow">for</span>(j = 2; j &lt; 16; j += j)
<a name="l00248"></a>00248         <span class="keywordflow">for</span>(k = 1; k &lt; j; ++k)
<a name="l00249"></a>00249         {
<a name="l00250"></a>00250             <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j + k][0] = <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j][0] ^ <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[k][0];
<a name="l00251"></a>00251             <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j + k][1] = <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j][1] ^ <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[k][1];
<a name="l00252"></a>00252             <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j + k][2] = <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j][2] ^ <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[k][2];
<a name="l00253"></a>00253             <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j + k][3] = <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[j][3] ^ <a class="code" href="gf128mul_8h.html#8ee14e91ae5d8d557c51f5ad0aceb4f1">tab256</a>(t)[k][3];
<a name="l00254"></a>00254         }
<a name="l00255"></a>00255 }
<a name="l00256"></a>00256 
<a name="l00257"></a>00257 <span class="preprocessor">#endif</span>
<a name="l00258"></a>00258 <span class="preprocessor"></span>
<a name="l00259"></a>00259 <span class="preprocessor">#endif </span><span class="comment">/* BSP_ENABLED */</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:56 2009 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>