diff options
Diffstat (limited to 'gf28.h')
-rw-r--r-- | gf28.h | 37 |
1 files changed, 7 insertions, 30 deletions
@@ -4,36 +4,13 @@ #include <cstdint> //The GF(2^8) field used in AES +//Elements are represented by unsigned 8-bit ints, as is their nature. +//Since addition in GF(2^8) is more simply written as just '^', only +//multiplication and taking inverses is necessary to implement separately. -class GF28{ - int value; +namespace GF28 { - static int reduce(int v,int m); + uint8_t multiply(uint8_t x,uint8_t y); + uint8_t inverse(uint8_t value); -public: - static const int modulus=0x11b; - - static uint8_t multiply(uint8_t x,uint8_t y); //for when the class is overkill - - GF28(); - explicit GF28(int v); - - explicit operator uint8_t() const; - - GF28& operator+=(GF28 o); - GF28& operator-=(GF28 o); - GF28& operator<<=(int n); //multiplication by x^n - - GF28 operator+(GF28 o) const; - GF28 operator-(GF28 o) const; - GF28 operator*(GF28 o) const; - GF28 operator<<(int n) const; //multiplication by x^n - - bool operator==(GF28 o) const; - - GF28 inverse() const; - - friend std::ostream& operator<<(std::ostream&,GF28); -}; - -std::ostream& operator<<(std::ostream &os,GF28 p); +} |