Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define MUL(x,y) aes_GaloisFieldMultiply((x),(y))
#define MUL2(x) (((x) << 1) ^ (0x1B & (((x) >> 7) * 0xFF))) & 0xFF
#define MUL3(x) ((x) ^ MUL2(x))
#define SUB4(x) ((s_box[((x) & 0xFF000000) >> 24] << 24) | (s_box[((x) & 0xFF0000) >> 16] << 16) | (s_box[((x) & 0xFF00) >> 8] << 8) | s_box[((x) & 0xFF)])


// AES Tables

Expand Down Expand Up @@ -65,6 +65,13 @@ void aes_InvMixColumns (uint8_t state[16]);
void aes_AddRoundKey (uint8_t state[16], uint8_t sub_key[16]);

// Maths Operation Definitions
void sub4(uint8_t * t)
{
t[0]=s_box[t[0]];
t[1]=s_box[t[1]];
t[2]=s_box[t[2]];
t[3]=s_box[t[3]];
}

uint8_t aes_GaloisFieldMultiply (uint8_t fixed, uint8_t variable);

Expand All @@ -82,10 +89,10 @@ void aes_init(uint32_t *round_key, counter b, uint32_t *key, counter n)
cycle = 0;

aes_Rotate((uint8_t *) &t);
t = SUB4(t);
sub4((uint8_t *)&t);
((uint8_t *) &t)[0] ^= rcon[i++];
} else if (cycle == 4 && n == 8) {
t = SUB4(t);
sub4((uint8_t *)&t);
}

t ^= round_key[position - n];
Expand Down
17 changes: 10 additions & 7 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ def test_file(file_path, size):

command += " -s " + str(size)

print ("Running command: "+command);
output = subprocess.check_output(command, shell=True).strip()
output = str(output).strip('b').strip("'");


if decrypt:
if output.upper() != plainText.upper():
print 'Failed decrypting {} to {}'.format(cipherText, plainText.upper())
print "Got: {}".format(output.upper())
print "Key: {}".format(key)
print ('Failed decrypting '+ cipherText+ ' to ' + plainText.upper())
print ("Got: ",output.upper())
print ("Key: ",key)
sys.exit(1)
else:
if output.upper() is not cipherText.upper():
print 'Failed encrypting {} to {}'.format(plainText, cipherText.upper())
print "Got: {}".format(output.upper())
print "Key: {}".format(key)
print ('Failed encrypting '+plainText+' to '+cipherText.upper())
print ("Got: ",output.upper())
print ("Key: ",key)
sys.exit(1)

tests = tests + 1
Expand All @@ -73,4 +76,4 @@ def test_file(file_path, size):
test_file(files[2][0], 128)
test_file(files[2][1], 128)
test_file(files[2][2], 128)
print "{} have passed successfully".format(tests)
print (str(tests) + " have passed successfully")