00001 // Copyright (C) 2001, Compaq Computer Corporation 00002 // 00003 // This file is part of Vesta. 00004 // 00005 // Vesta is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // Vesta is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with Vesta; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 // Last modified on Thu Aug 1 14:30:24 EDT 2002 by kcschalk@shr.intel.com 00020 // modified on Tue Jun 25 19:15:08 EDT 2002 by ken@xorian.net 00021 00022 #include "ByteModTable.H" 00023 00024 // Define the storage for ByteModTable 00025 Poly ByteModTable[8][256]; 00026 00027 // Initialization of ByteModTable constants------------------------------------ 00028 00029 // Force ByteModTable to be initialized early with a static instance 00030 // of a special initializer class. 00031 class ByteModTableInit 00032 { 00033 public: 00034 typedef Poly table_type[8][256]; 00035 ByteModTableInit(table_type &table) throw (); 00036 }; 00037 00038 static ByteModTableInit byte_mod_table_init(ByteModTable); 00039 00040 static void TimesX(Poly& p) throw () 00041 /* Set "p" to the polynomial "p" times "X" mod "POLY_IRRED". */ 00042 { 00043 short x127flag = (p.w[0] & POLY_X63_W); 00044 p.w[0] >>= 1; 00045 if (p.w[1] & POLY_X63_W) p.w[0] |= POLY_ONE_W; 00046 p.w[1] >>= 1; 00047 if (x127flag) PolyInc(p, POLY_IRRED); 00048 } 00049 00050 // This is the fucntion which actually computes ByteModTable. 00051 ByteModTableInit::ByteModTableInit(table_type &table) throw () 00052 { 00053 Poly PowerTable[256], p; 00054 00055 // TimesX above assumes this, as does FP::Send and FP::Recv, as well 00056 // as other code in this package. 00057 assert(PolyVal::WordCnt == 2); 00058 00059 // Compute "PowerTable" 00060 int i; 00061 p = POLY_ONE; 00062 for(i = 0; i < 256; TimesX(p),i++) 00063 { 00064 PowerTable[i] = p; 00065 } 00066 00067 // Compute ByteModTable 00068 int j, k; 00069 const unsigned char X7 = 1; 00070 for(i = 0; i < 8; i++) 00071 { 00072 for(j = 0; j < 256; j++) 00073 { 00074 p = POLY_ZERO; 00075 for(k=0; k < 8; k++) 00076 { 00077 if(j & (X7 << k)) 00078 { 00079 PolyInc(p, PowerTable[191-(i*8)-k]); 00080 } 00081 } 00082 00083 // ByteModTable[i][j] = p; 00084 table[i][j] = p; 00085 } 00086 } 00087 }