-
Notifications
You must be signed in to change notification settings - Fork 1
/
aesencrypt.h
78 lines (68 loc) · 1.41 KB
/
aesencrypt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Make Watson
// CS 306
// Semester Project
#ifndef AESENCRYPT_H
#define AESENCRYPT_H
#define BLOCK_SIZE 16
#include <string>
#include <bitset>
#include "stdio.h"
class aesEncrypt
{
private:
int Nk, Nb, Nr; // lengths.
std::string textkey;
char* expandedkey;
char* fullkey;
public:
aesEncrypt();
~aesEncrypt();
bool encryptBlock(char*);
bool decryptBlock(char*);
void setTextKey(std::string);
void expandKey();
void subBytes(char *);
void invSubBytes(char *);
void shiftRows(char *);
void invShiftRows(char *);
void mixColumns(char *);
void invMixColumns(char *);
void xorRoundKey(char *, char *);
unsigned char sboxify(unsigned char val);
unsigned char invsboxify(unsigned char val);
unsigned char roundify(unsigned char index);
unsigned char ffmul(unsigned char, unsigned char);
// assumes a word
void rotate_left(unsigned char * tmp) {
unsigned char trimmings;
trimmings = tmp[0];
tmp[0] = tmp[1];
tmp[1] = tmp[2];
tmp[2] = tmp[3];
tmp[3] = trimmings;
}
void rotate_right(unsigned char * tmp) {
unsigned char trimmings;
trimmings = tmp[3];
tmp[3] = tmp[2];
tmp[2] = tmp[1];
tmp[1] = tmp[0];
tmp[0] = trimmings;
}
unsigned char rcon(unsigned char in) {
unsigned char c=1;
if(in == 0)
return 0;
while(in != 1) {
unsigned char b;
b = c & 0x80;
c <<= 1;
if(b == 0x80) {
c ^= 0x1b;
}
in--;
}
return c;
}
};
#endif // AESENCRYPT_H