1// gf256.cpp - written and placed in the public domain by Wei Dai 2 3#include "pch.h" 4#include "gf256.h" 5 6NAMESPACE_BEGIN(CryptoPP) 7 8GF256::Element GF256::Multiply(Element a, Element b) const 9{ 10 word result = 0, t = b; 11 12 for (unsigned int i=0; i<8; i++) 13 { 14 result <<= 1; 15 if (result & 0x100) 16 result ^= m_modulus; 17 18 t <<= 1; 19 if (t & 0x100) 20 result ^= a; 21 } 22 23 return (GF256::Element) result; 24} 25 26GF256::Element GF256::MultiplicativeInverse(Element a) const 27{ 28 Element result = a; 29 for (int i=1; i<7; i++) 30 result = Multiply(Square(result), a); 31 return Square(result); 32} 33 34NAMESPACE_END 35