What is AES? AES is abbreviation of "Advanced Encryption Standard", it was chosen to replace it's predecessor DES (Data Encryption Standard) by NIST ( National Institute of Standards and Technology) and has been adapted by the US government and most developers world wide. AES is considered the most secure encryption algorithm today, while it also being very lightweight and efficient.
AES has block size of 128bits, meaning that if more data is wanted to be encrypted, it must be encrypted block by block.
AES has 3 possible key sizes: 128, 192 and 256 bits.
It would take 1
BILLION BILLION years for a supercomputer to bruteforce an AES 128 encryption.
Even if a quantum computer that could make 72 000 000 000 000 000 key combinations per second (crazy much)
it would still take 149
TRILLION years to break it!
To put this in perspective, the
UNIVERSE is only 13.8 billion years old.
So AES is in practice unbreakable by the bruteforce method (and other known attacks).
This is my implementation of the algorithm:
(this code snippet demonstrates the CTR block cipher mode)
¨
Code:
#include "VirtualAES.h"
#include <iostream>
#include <windows.h>
#include <time.h>
using namespace std;
int main(int argc, char *argv[])
{
/* All char arrays are null terminated here...*/
char cipherhex[256];
char decryptedhex[128];
uchar dechex[128];
uchar szkey[KEY_128] = "very strong key";
uchar szCiphertext[128];
uchar szDecryptedtext[128];
uchar szPlaintext[128] =
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem"
"accusantium doloremque laudantium, totam rem aperiam eaque ipsa.";
aes_ctx_t *ctx;
u64 nonce;
virtualAES::initialize();
ctx = virtualAES::allocatectx(szkey, sizeof(szkey));
virtualAES::rand_nonce(&nonce);
/*encrypt*/
virtualAES::encrypt_ctr(ctx, szPlaintext, szCiphertext, sizeof(szPlaintext), nonce);
cout << "cipherdata in ansi:\n" << szCiphertext << "\n\n";
virtualAES::strtohex(szCiphertext, cipherhex, 128);
cout << "cipherdata in hex:\n" << cipherhex << "\n\n";
/*previously encrypted hex to string for decrypting...*/
virtualAES::hextostr(
"340A0A94EA7BAA70A3672E5D47C2529AA0D7835CD1A5FDF45C FD3D0945F705AC7FBEC8EF4FBB782B"
"710C4BE4C3EF8E4F418A3D213D81344192E4DE32907DB2FFCF 7D816764F8C84511AE3EB636C4BB23"
"D51820801A288360AD7B2A949D35C9B7631C4986333F6CE573 44B9EC909170BBA28CB10E41A7E722"
"5F241E54C5FACAE8", dechex, 128);
/*decrypt*/
virtualAES::decrypt_ctr(ctx, dechex, szDecryptedtext, sizeof(dechex), nonce);
cout << "decrypted data in ansi:\n" << szDecryptedtext << "\n\n";
virtualAES::strtohex(szDecryptedtext, decryptedhex, 128);
cout << "decrypted data in hex:\n" << decryptedhex << endl;
getchar();
return EXIT_SUCCESS;
}
video tutorial (no CTR mode):
- - - Updated - - -
Sources:
How long it will take to break AES?: http://www.eetimes.com/document.asp?doc_id=1279619
general: https://en.wikipedia.org/wiki/Advanced_Encryption_Standard