AES-128

by Cody123100
Implementation of AES-128 encryption [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Cody123100.AES128##version=4

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Cody123100.AES128##version=4

69 downloads
Version 1.0
Date added: Feb 11 2013
Last updated: Mar 28 2013
4 fans
This library implements the AES-128 encryption/decryption algorithm to encrypt and decrypt 128 bit long blocks of text. To encrypt and decrypt larger blocks of text it utilizes AES-128 in conjunction with cipher block chaining.

This is the initial implementation and as such may be prone to bugs. Ensure you can encrypt AND decrypt your data before you get rid of the unencrypted data.

AES stands for Advanced Encryption Standard and it is the standard by which the US government encrypts and decrypts their data. This flavor of AES utilizes 128 bit long keys (16 characters). AES's primary features are its speed and security. While this version is neither optimized nor as fast as non-DM implementations, this library is a suitable alternative to offloading encryption to a dll.

Changelog:
V0.2 - Added error reporting feature. Read the error reporting section of readme file for more details. Currently error reporting only reports if the user entered a key or initialization vector that was too short.

V1.0 - Added a hexadecimal mode. The default mode is still for ASCII characters. Read the input modes section of the readme file for more details. Added a test vectors function to the demo under hexadecimal mode to validate encryption correctness.

Comments

Cody123100: (Mar 28 2013, 10:31 am)
Koil wrote:
Your library fails to properly encrypt every AES-128 test vector I've tried. Did you actually test it before you released it?

http://www.inconteam.com/software-development/41-encryption/ 55-aes-test-vectors

http://www.ietf.org/rfc/rfc3602.txt

I added a hexadecimal mode to the library and in that mode I added a Test Vectors function to the demo that executes all of the CBC test vectors from iconteam.com. It all checked out. Note that the default mode is still the ASCII characters mode so to get the test vectors function you need to change the input mode.
Cody123100: (Mar 27 2013, 7:12 pm)
I didn't test it against those test vectors, no. The library takes in ASCII characters for the key, plain-text, and IV not hexadecimal values so I'm curious how you tested them. Because DM doesn't play nice with all ASCII characters it wouldn't be easy to test with test vectors containing characters like null, which DM doesn't store in variables at all as far as I recall.

What I did instead was a few test cases against this online AES encryption oracle which passes with the test vectors for ECB mode to verify that individual blocks are encrypted correctly using a snippet like this:

mob
var/AES/aes = new()
var/cipher_text
verb
Encrypt_Test()
var/data = "ThisIsThePlainTe"
var/key = "ThisIsTheKeyTest"
data = aes.text2mat(data)
key = aes.text2int(key)
world << "Encrypting"
data = aes.EncBlock(data, key)
world << "Encryption Complete"
var/out = ""
for(var/i = 1 to length(data))
for(var/j = 1; j <= 4; j++)
out += "[data[i][j]] "
out += "\n"
world << "Cipher-text:\n[out]"
cipher_text = data
world << "Decrypting"
data = aes.DecBlock(cipher_text,key)
world << "Decryption Complete"
world << "Plain-text: [aes.mat2text(data)]"

Note the cipher-text is treated as a 4x4 matrix of integers because of the aforementioned ASCII problem so I had to convert the integers into hex to verify against the online calculator.

This gave me confidence that my encryption of individual blocks was adequate because it produced the same results as an oracle that does satisfy those test vectors. I was mainly concerned with verifying that individual blocks are encrypted correctly so I did indeed skimp on the testing of CBC mode. I'm considering an update that's hexadecimal friendly which would make it possible to test against those test-vectors directly. Your complaint is extremely valid though, and I'll add a disclaimer to the hub and make it invisible until I do validate against those test vectors.
Koil: (Mar 22 2013, 3:17 am)
Your library fails to properly encrypt every AES-128 test vector I've tried. Did you actually test it before you released it?

http://www.inconteam.com/software-development/41-encryption/ 55-aes-test-vectors

http://www.ietf.org/rfc/rfc3602.txt