From 8ee3380a6b116778ccd1a895802465884f58a9b9 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 6 Oct 2016 22:21:36 +0200 Subject: Start AES --- aes.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ aes.h | 16 +++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 aes.cpp create mode 100644 aes.h diff --git a/aes.cpp b/aes.cpp new file mode 100644 index 0000000..13659e6 --- /dev/null +++ b/aes.cpp @@ -0,0 +1,79 @@ +#include +#include +#include "aes.h" + +using namespace std; + +namespace AES{ + + //http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf + + void subWord(uint8_t *word); + + void keyExpand(uint8_t *keysched,const uint8_t *key,int keylen,int numrounds); + + void addRoundKey(uint8_t *state,const uint8_t *roundkey); + + void subBytes(uint8_t *state){ + subWord(state); + subWord(state+4); + subWord(state+8); + subWord(state+12); + } + + void shiftRows(uint8_t *state); + + void mixColumns(uint8_t *state); + + + void encryptBlock(uint8_t *state,const uint8_t *key,const uint8_t *data,int keylen,int numrounds){ + uint8_t keysched[16*(numrounds+1)]; + keyExpand(keysched,key,keylen,numrounds); + memcpy(state,data,16); + + addRoundKey(state,keysched); + for(int round=0;round + +namespace AES{ + + enum Algorithm{ + AES_128, + AES_192, + AES_256, + }; + + std::string encrypt(const std::string &key,const std::string &data,Algorithm algo); + std::string decrypt(const std::string &key,const std::string &data,Algorithm algo); + +} -- cgit v1.2.3-70-g09d2