Crypto++ 8.7
Free C++ class library of cryptographic schemes
gf256.cpp
1// gf256.cpp - originally 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
Square block cipher.
Definition: square.h:25
word64 word
Full word used for multiprecision integer arithmetic.
Definition: config_int.h:182
Classes and functions for schemes over GF(256)
Crypto++ library namespace.
Precompiled header file.