AES Encryption Library for Arduino and Raspberry Pi
Spaniakos - AES Encryption Library for Arduino and Raspberry Pi
|
#include <AES.h>
Public Member Functions | |
AES () | |
AES constructor. More... | |
byte | set_key (byte key[], int keylen) |
void | clean () |
void | copy_n_bytes (byte *AESt, byte *src, byte n) |
byte | encrypt (byte plain[N_BLOCK], byte cipher[N_BLOCK]) |
byte | cbc_encrypt (byte *plain, byte *cipher, int n_block, byte iv[N_BLOCK]) |
byte | cbc_encrypt (byte *plain, byte *cipher, int n_block) |
byte | decrypt (byte cipher[N_BLOCK], byte plain[N_BLOCK]) |
byte | cbc_decrypt (byte *cipher, byte *plain, int n_block, byte iv[N_BLOCK]) |
byte | cbc_decrypt (byte *cipher, byte *plain, int n_block) |
void | set_IV (unsigned long long int IVCl) |
void | iv_inc () |
int | get_size () |
void | set_size (int sizel) |
void | get_IV (byte *out) |
void | calc_size_n_pad (int p_size) |
void | padPlaintext (void *in, byte *out) |
bool | CheckPad (byte *in, int size) |
void | printArray (byte output[], bool p_pad=true) |
void | printArray (byte output[], int sizel) |
void | do_aes_encrypt (byte *plain, int size_p, byte *cipher, byte *key, int bits, byte ivl[N_BLOCK]) |
void | do_aes_encrypt (byte *plain, int size_p, byte *cipher, byte *key, int bits) |
void | do_aes_decrypt (byte *cipher, int size_c, byte *plain, byte *key, int bits, byte ivl[N_BLOCK]) |
void | do_aes_decrypt (byte *cipher, int size_c, byte *plain, byte *key, int bits) |
double | millis () |
Private Attributes | |
int | round |
byte | key_sched [KEY_SCHEDULE_BYTES] |
unsigned long long int | IVC |
byte | iv [16] |
int | pad |
int | size |
timeval | tv |
byte | arr_pad [15] = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f } |
byte AES::set_key | ( | byte | key[], |
int | keylen | ||
) |
Set the cipher key for the pre-keyed version.
key[] | pointer to the key string. |
keylen | Integer that indicates the length of the key. |
void AES::clean | ( | ) |
clean up subkeys after use.
void AES::copy_n_bytes | ( | byte * | AESt, |
byte * | src, | ||
byte | n | ||
) |
copying and xoring utilities.
*AESt | byte pointer of the AEStination array. |
*src | byte pointer of the source array. |
n | byte, indicating the sizeof the bytes to be copied. |
byte AES::encrypt | ( | byte | plain[N_BLOCK], |
byte | cipher[N_BLOCK] | ||
) |
Encrypt a single block of 16 bytes .
plain[N_BLOCK] | Array of the plaintext. |
cipher[N_BLOCK] | Array of the ciphertext. |
byte AES::cbc_encrypt | ( | byte * | plain, |
byte * | cipher, | ||
int | n_block, | ||
byte | iv[N_BLOCK] | ||
) |
CBC encrypt a number of blocks (input and return an IV).
*plain | Pointer, points to the plaintex. |
*cipher | Pointer, points to the ciphertext that will be created. |
n_block | integer, indicated the number of blocks to be ciphered. |
iv[N_BLOCK] | byte Array that holds the IV (initialization vector). 0 if SUCCESS or -1 if FAILURE |
byte AES::cbc_encrypt | ( | byte * | plain, |
byte * | cipher, | ||
int | n_block | ||
) |
CBC encrypt a number of blocks (input and return an IV).
*plain | Pointer, points to the plaintex. |
*cipher | Pointer, points to the ciphertext that will be created. |
n_block | integer, indicated the number of blocks to be ciphered. 0 if SUCCESS or -1 if FAILURE |
byte AES::decrypt | ( | byte | cipher[N_BLOCK], |
byte | plain[N_BLOCK] | ||
) |
Decrypt a single block of 16 bytes
cipher[N_BLOCK] | Array of the ciphertext. |
plain[N_BLOCK] | Array of the plaintext. |
byte AES::cbc_decrypt | ( | byte * | cipher, |
byte * | plain, | ||
int | n_block, | ||
byte | iv[N_BLOCK] | ||
) |
CBC decrypt a number of blocks (input and return an IV)
*cipher | Pointer, points to the ciphertext that will be created. |
*plain | Pointer, points to the plaintex. |
n_block | integer, indicated the number of blocks to be ciphered. |
iv[N_BLOCK] | byte Array that holds the IV (initialization vector). 0 if SUCCESS or -1 if FAILURE |
byte AES::cbc_decrypt | ( | byte * | cipher, |
byte * | plain, | ||
int | n_block | ||
) |
CBC decrypt a number of blocks (input and return an IV)
*cipher | Pointer, points to the ciphertext that will be created. |
*plain | Pointer, points to the plaintex. |
n_block | integer, indicated the number of blocks to be ciphered. 0 if SUCCESS or -1 if FAILURE |
void AES::set_IV | ( | unsigned long long int | IVCl | ) |
Sets IV (initialization vector) and IVC (IV counter). This function changes the ivc and iv variables needed for AES.
IVCl | int or hex value of iv , ex. 0x0000000000000001 |
void AES::iv_inc | ( | ) |
increase the iv (initialization vector) and IVC (IV counter) by 1
This function increased the VI by one step in order to have a different IV each time
int AES::get_size | ( | ) |
Getter method for size
This function return the size
void AES::set_size | ( | int | sizel | ) |
Setter method for size
This function sets the size of the plaintext+pad
void AES::get_IV | ( | byte * | out | ) |
Getter method for IV
This function return the IV
out | byte pointer that gets the IV. |
void AES::calc_size_n_pad | ( | int | p_size | ) |
Calculates the size of the plaintext and the padding.
Calculates the size of theplaintext with the padding and the size of the padding needed. Moreover it stores them in their class variables.
p_size | the size of the byte array ex sizeof(plaintext) |
void AES::padPlaintext | ( | void * | in, |
byte * | out | ||
) |
Pads the plaintext
This function pads the plaintext and returns an char array with the plaintext and the padding in order for the plaintext to be compatible with 16bit size blocks required by AES
in | the string of the plaintext in a byte array |
out | The string of the out array. |
bool AES::CheckPad | ( | byte * | in, |
int | size | ||
) |
Check the if the padding is correct.
This functions checks the padding of the plaintext.
in | the string of the plaintext in a byte array |
size | the size of the string |
void AES::printArray | ( | byte | output[], |
bool | p_pad = true |
||
) |
Prints the array given.
This function prints the given array and pad, It is mainlly used for debugging purpuses or to output the string.
output[] | the string of the text in a byte array |
p_pad | optional, used to print with out the padding characters |
void AES::printArray | ( | byte | output[], |
int | sizel | ||
) |
Prints the array given.
This function prints the given array in Hexadecimal.
output[] | the string of the text in a byte array |
sizel | the size of the array. |
void AES::do_aes_encrypt | ( | byte * | plain, |
int | size_p, | ||
byte * | cipher, | ||
byte * | key, | ||
int | bits, | ||
byte | ivl[N_BLOCK] | ||
) |
User friendly implementation of AES-CBC encryption.
*plain | pointer to the plaintext |
size_p | size of the plaintext |
*cipher | pointer to the ciphertext |
*key | pointer to the key that will be used. |
bits | bits of the encryption/decrpytion |
ivl[N_BLOCK] | the initialization vector IV that will be used for encryption. |
void AES::do_aes_encrypt | ( | byte * | plain, |
int | size_p, | ||
byte * | cipher, | ||
byte * | key, | ||
int | bits | ||
) |
User friendly implementation of AES-CBC encryption.
*plain | pointer to the plaintext |
size_p | size of the plaintext |
*cipher | pointer to the ciphertext |
*key | pointer to the key that will be used. |
bits | bits of the encryption/decrpytion |
void AES::do_aes_decrypt | ( | byte * | cipher, |
int | size_c, | ||
byte * | plain, | ||
byte * | key, | ||
int | bits, | ||
byte | ivl[N_BLOCK] | ||
) |
User friendly implementation of AES-CBC decryption.
*cipher | pointer to the ciphertext |
size_c | size of the ciphertext |
*plain | pointer to the plaintext |
*key | pointer to the key that will be used. |
bits | bits of the encryption/decrpytion |
ivl[N_BLOCK] | the initialization vector IV that will be used for decryption. |
void AES::do_aes_decrypt | ( | byte * | cipher, |
int | size_c, | ||
byte * | plain, | ||
byte * | key, | ||
int | bits | ||
) |
User friendly implementation of AES-CBC decryption.
*cipher | pointer to the ciphertext |
size_c | size of the ciphertext |
*plain | pointer to the plaintext |
*key | pointer to the key that will be used. |
bits | bits of the encryption/decrpytion |
double AES::millis | ( | ) |
used in linux in order to retrieve the time in milliseconds.
|
private |
holds the number of rounds to be used.
|
private |
holds the pre-computed key for the encryption/decrpytion.
|
private |
holds the initialization vector counter in numerical format.
|
private |
holds the initialization vector that will be used in the cipher.
|
private |
holds the size of the padding.
|
private |
hold the size of the plaintext to be ciphered
|
private |
holds the time value on linux
|
private |
holds the hexadecimal padding values on linux
holds the hexadecimal padding values