MySensors Library & Examples  2.3.2-62-ge298769
Public Member Functions | List of all members
AES Class Reference

Detailed Description

AES class

Definition at line 39 of file AES.h.

#include <AES.h>

+ Collaboration diagram for AES:

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)
 

Constructor & Destructor Documentation

◆ AES()

AES::AES ( )

AES constructor.

This function initialized an instance of AES.

Member Function Documentation

◆ calc_size_n_pad()

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.

Parameters
p_sizethe size of the byte array ex sizeof(plaintext)

◆ cbc_decrypt() [1/2]

byte AES::cbc_decrypt ( byte *  cipher,
byte *  plain,
int  n_block 
)

CBC decrypt a number of blocks (input and return an IV)

Parameters
*cipherPointer, points to the ciphertext that will be created.
*plainPointer, points to the plaintex.
n_blockinteger, indicated the number of blocks to be ciphered.
Returns
0 if SUCCESS or -1 if FAILURE

◆ cbc_decrypt() [2/2]

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)

Parameters
*cipherPointer, points to the ciphertext that will be created.
*plainPointer, points to the plaintex.
n_blockinteger, indicated the number of blocks to be ciphered.
ivbyte Array that holds the IV (initialization vector).
Returns
0 if SUCCESS or -1 if FAILURE

◆ cbc_encrypt() [1/2]

byte AES::cbc_encrypt ( byte *  plain,
byte *  cipher,
int  n_block 
)

CBC encrypt a number of blocks (input and return an IV).

Parameters
*plainPointer, points to the plaintex.
*cipherPointer, points to the ciphertext that will be created.
n_blockinteger, indicated the number of blocks to be ciphered.
Returns
0 if SUCCESS or -1 if FAILURE

◆ cbc_encrypt() [2/2]

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).

Parameters
*plainPointer, points to the plaintex.
*cipherPointer, points to the ciphertext that will be created.
n_blockinteger, indicated the number of blocks to be ciphered.
ivbyte Array that holds the IV (initialization vector).
Returns
0 if SUCCESS or -1 if FAILURE

◆ CheckPad()

bool AES::CheckPad ( byte *  in,
int  size 
)

Check the if the padding is correct.

This functions checks the padding of the plaintext.

Parameters
inthe string of the plaintext in a byte array
sizethe size of the string
Returns
true if correct / false if not

◆ clean()

void AES::clean ( )

clean up subkeys after use.

◆ copy_n_bytes()

void AES::copy_n_bytes ( byte *  AESt,
byte *  src,
byte  n 
)

copying and xoring utilities.

Parameters
*AEStbyte pointer of the AEStination array.
*srcbyte pointer of the source array.
nbyte, indicating the sizeof the bytes to be copied.
Note
this is an alternative for memcpy(void *s1,const void *s2, site_t n), i have not updated the function in the implementation yet, but it is considered a future plan.

◆ decrypt()

byte AES::decrypt ( byte  cipher[N_BLOCK],
byte  plain[N_BLOCK] 
)

Decrypt a single block of 16 bytes

Parameters
cipherArray of the ciphertext.
plainArray of the plaintext.
Note
The N_BLOCK is defined in AES_config.h as,
#define N_ROW 4
#define N_COL 4
#define N_BLOCK (N_ROW * N_COL)
Changed to that will change the Block_size.
Returns
0 if SUCCESS or -1 if FAILURE

◆ do_aes_decrypt() [1/2]

void AES::do_aes_decrypt ( byte *  cipher,
int  size_c,
byte *  plain,
byte *  key,
int  bits 
)

User friendly implementation of AES-CBC decryption.

Parameters
*cipherpointer to the ciphertext
size_csize of the ciphertext
*plainpointer to the plaintext
*keypointer to the key that will be used.
bitsbits of the encryption/decrpytion
Note
The key will be stored in class variable.

◆ do_aes_decrypt() [2/2]

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.

Parameters
*cipherpointer to the ciphertext
size_csize of the ciphertext
*plainpointer to the plaintext
*keypointer to the key that will be used.
bitsbits of the encryption/decrpytion
ivlthe initialization vector IV that will be used for decryption.
Note
The key will be stored in class variable.

◆ do_aes_encrypt() [1/2]

void AES::do_aes_encrypt ( byte *  plain,
int  size_p,
byte *  cipher,
byte *  key,
int  bits 
)

User friendly implementation of AES-CBC encryption.

Parameters
*plainpointer to the plaintext
size_psize of the plaintext
*cipherpointer to the ciphertext
*keypointer to the key that will be used.
bitsbits of the encryption/decrpytion
Note
The key will be stored in class variable.

◆ do_aes_encrypt() [2/2]

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.

Parameters
*plainpointer to the plaintext
size_psize of the plaintext
*cipherpointer to the ciphertext
*keypointer to the key that will be used.
bitsbits of the encryption/decrpytion
ivlthe initialization vector IV that will be used for encryption.
Note
The key will be stored in class variable.

◆ encrypt()

byte AES::encrypt ( byte  plain[N_BLOCK],
byte  cipher[N_BLOCK] 
)

Encrypt a single block of 16 bytes .

Parameters
plainArray of the plaintext.
cipherArray of the ciphertext.
Note
The N_BLOCK is defined in AES_config.h as,
#define N_ROW 4
#define N_COL 4
#define N_BLOCK (N_ROW * N_COL)
Changed to that will change the Block_size.
Returns
0 if SUCCESS or -1 if FAILURE

◆ get_IV()

void AES::get_IV ( byte *  out)

Getter method for IV

This function return the IV

Parameters
outbyte pointer that gets the IV.
Returns
none, the IV is writed to the out pointer.

◆ get_size()

int AES::get_size ( )

Getter method for size

This function return the size

Returns
an integer, that is the size of the of the padded plaintext, thus, the size of the ciphertext.

◆ iv_inc()

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

◆ padPlaintext()

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

Parameters
inthe string of the plaintext in a byte array
outThe string of the out array.
Returns
no return, The padded plaintext is stored in the out pointer.

◆ printArray() [1/2]

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.

Parameters
output[]the string of the text in a byte array
p_padoptional, used to print with out the padding characters

◆ printArray() [2/2]

void AES::printArray ( byte  output[],
int  sizel 
)

Prints the array given.

This function prints the given array in Hexadecimal.

Parameters
output[]the string of the text in a byte array
sizelthe size of the array.

◆ set_IV()

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.

Parameters
IVClint or hex value of iv , ex. 0x0000000000000001
Note
example:
unsigned long long int my_iv = 01234567;

◆ set_key()

byte AES::set_key ( byte  key[],
int  keylen 
)

Set the cipher key for the pre-keyed version.

Parameters
key[]pointer to the key string.
keylenInteger that indicates the length of the key.
Note
NOTE: If the length_type used for the key length is an unsigned 8-bit character, a key length of 256 bits must be entered as a length in bytes (valid inputs are hence 128, 192, 16, 24 and 32).

◆ set_size()

void AES::set_size ( int  sizel)

Setter method for size

This function sets the size of the plaintext+pad


The documentation for this class was generated from the following file: