MySensors Library & Examples
2.3.2
|
#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) |
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) |
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. |
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 | byte Array that holds the IV (initialization vector). |
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. |
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 | byte Array that holds the IV (initialization vector). |
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::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::decrypt | ( | byte | cipher[N_BLOCK], |
byte | plain[N_BLOCK] | ||
) |
Decrypt a single block of 16 bytes
cipher | Array of the ciphertext. |
plain | Array of the plaintext. |
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 |
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 | the initialization vector IV that will be used for decryption. |
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_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 | the initialization vector IV that will be used for encryption. |
byte AES::encrypt | ( | byte | plain[N_BLOCK], |
byte | cipher[N_BLOCK] | ||
) |
Encrypt a single block of 16 bytes .
plain | Array of the plaintext. |
cipher | Array of the ciphertext. |
void AES::get_IV | ( | byte * | out | ) |
Getter method for IV
This function return the IV
out | byte pointer that gets the IV. |
int AES::get_size | ( | ) |
Getter method for size
This function return the size
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
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. |
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::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 |
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::set_size | ( | int | sizel | ) |
Setter method for size
This function sets the size of the plaintext+pad