aboutsummaryrefslogtreecommitdiff
path: root/gf28.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-07 20:33:18 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-07 20:33:18 +0200
commit241518f369efce64046be36a15fcb722b00e9477 (patch)
tree1aaa6e56e027df35503c497b3c1ef5fa6e8e7916 /gf28.h
parent8ee3380a6b116778ccd1a895802465884f58a9b9 (diff)
Working AES encrypt and decrypt!
Diffstat (limited to 'gf28.h')
-rw-r--r--gf28.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/gf28.h b/gf28.h
new file mode 100644
index 0000000..194cd57
--- /dev/null
+++ b/gf28.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <iostream>
+#include <cstdint>
+
+//The GF(2^8) field used in AES
+
+class GF28{
+ int value;
+
+ static int reduce(int v,int m);
+
+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);