Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
AES Class Reference

Class that implements AES encryption. More...

#include <cs_AES.h>

Public Member Functions

void init ()
 Initialize the class, reads from State. More...
 
cs_ret_code_t encryptEcb (cs_data_t key, cs_data_t prefix, cs_data_t input, cs_data_t output, cs_buffer_size_t &writtenSize)
 Encrypt data with given key in ECB mode. More...
 
cs_ret_code_t encryptCtr (cs_data_t key, cs_data_t nonce, cs_data_t prefix, cs_data_t input, cs_data_t output, cs_buffer_size_t &writtenSize, uint8_t blockCtr=0)
 Encrypt data with given key in CTR mode. More...
 
cs_ret_code_t decryptCtr (cs_data_t key, cs_data_t nonce, cs_data_t input, cs_data_t prefix, cs_data_t output, cs_buffer_size_t &writtenSize, uint8_t blockCtr=0)
 Decrypt data with given key in CTR mode. More...
 

Static Public Member Functions

static AESgetInstance ()
 Use static variant of singleton, no dynamic memory allocation. More...
 

Private Member Functions

 AES ()
 
 AES (AES const &)
 
void operator= (AES const &)
 
cs_ret_code_t ctr (cs_data_t key, cs_data_t nonce, cs_data_t inputPrefix, cs_data_t input, cs_data_t outputPrefix, cs_data_t output, cs_buffer_size_t &writtenSize, uint8_t blockCtr=0)
 Encrypt or decrypt data with given key in CTR mode. More...
 

Private Attributes

nrf_ecb_hal_data_t _block
 Struct with key, and single block of encrypted and decypted data. More...
 

Detailed Description

Class that implements AES encryption.

  • Block size is 16 byte.
  • ECB mode has no decrypt method, as that's not hardware accelerated.
  • CTR mode has both encrypt and decrypt methods.

Constructor & Destructor Documentation

◆ AES() [1/2]

AES::AES ( )
private

◆ AES() [2/2]

AES::AES ( AES const &  )
private

Member Function Documentation

◆ ctr()

cs_ret_code_t AES::ctr ( cs_data_t  key,
cs_data_t  nonce,
cs_data_t  inputPrefix,
cs_data_t  input,
cs_data_t  outputPrefix,
cs_data_t  output,
cs_buffer_size_t writtenSize,
uint8_t  blockCtr = 0 
)
private

Encrypt or decrypt data with given key in CTR mode.

Parameters
[in]keyKey to encrypt with.
[in]nonceNonce to use for encryption.
[in]inputPrefixExtra data to put before the input data.
[in]inputInput data to be encrypted.
[in]outputPrefixExtra data to be written to before writing to the output buffer.
[out]outputBuffer to encrypt to. Can be the same as input, as long as: output pointer + output prefix size >= input pointer + input prefix size.
[out]writtenSizeHow many bytes are written to output.
[in]blockCtrOptional initial block counter.
Returns
Return code.

◆ decryptCtr()

cs_ret_code_t AES::decryptCtr ( cs_data_t  key,
cs_data_t  nonce,
cs_data_t  input,
cs_data_t  prefix,
cs_data_t  output,
cs_buffer_size_t writtenSize,
uint8_t  blockCtr = 0 
)

Decrypt data with given key in CTR mode.

The decrypted data is a concatenation of prefix and output.

Parameters
[in]keyKey to encrypt with.
[in]nonceNonce to use for decryption.
[in]inputInput data to be encrypted.
[out]prefixBuffer to encrypt to, before the output buffer. Can be the same as input.
[out]outputBuffer to encrypt to. Can be the same as input, as long as: output pointer <= input pointer + prefix size.
[out]writtenSizeHow many bytes are written to output.
[in]blockCtrOptional initial block counter.
Returns
Return code.

◆ encryptCtr()

cs_ret_code_t AES::encryptCtr ( cs_data_t  key,
cs_data_t  nonce,
cs_data_t  prefix,
cs_data_t  input,
cs_data_t  output,
cs_buffer_size_t writtenSize,
uint8_t  blockCtr = 0 
)

Encrypt data with given key in CTR mode.

The data that's encrypted is a concatenation of prefix and input.

Parameters
[in]keyKey to encrypt with.
[in]nonceNonce to use for encryption.
[in]prefixExtra data to put before the input data.
[in]inputInput data to be encrypted.
[out]outputBuffer to encrypt to. Can be the same as input, as long as: output pointer <= input pointer - prefix size.
[out]writtenSizeHow many bytes are written to output.
[in]blockCtrOptional initial block counter.
Returns
Return code.

◆ encryptEcb()

cs_ret_code_t AES::encryptEcb ( cs_data_t  key,
cs_data_t  prefix,
cs_data_t  input,
cs_data_t  output,
cs_buffer_size_t writtenSize 
)

Encrypt data with given key in ECB mode.

The data that's encrypted is a concatenation of prefix and input.

Parameters
[in]keyKey to encrypt with.
[in]prefixExtra data to put before the input data. Can be skipped by passing a null pointer and data size 0.
[in]inputInput data to be encrypted.
[out]outputBuffer to encrypt to. Can be the same as input, as long as: output pointer >= input pointer + prefix size.
[out]writtenSizeHow many bytes are written to output.
Returns
Return code.

◆ getInstance()

static AES & AES::getInstance ( )
inlinestatic

Use static variant of singleton, no dynamic memory allocation.

◆ init()

void AES::init ( )

Initialize the class, reads from State.

◆ operator=()

void AES::operator= ( AES const &  )
private

Member Data Documentation

◆ _block

nrf_ecb_hal_data_t AES::_block
private

Struct with key, and single block of encrypted and decypted data.


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