EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
CryptModule Class Reference

EnigmaIoT Crypto module. Wraps Arduino CryptoLib classes and methods. More...

#include <cryptModule.h>

Public Member Functions

void getDH1 ()
 Starts first stage of Diffie Hellman key agreement algorithm. More...
 
bool getDH2 (const uint8_t *remotePubKey)
 Starts second stage of Diffie Hellman key agreement algorithm and calculate shares key. More...
 
uint8_t * getPrivDHKey ()
 Gets own private key used on Diffie Hellman algorithm. More...
 
uint8_t * getPubDHKey ()
 Gets own public key used on Diffie Hellman algorithm. More...
 

Static Public Member Functions

static uint32_t random ()
 Gets a random number. More...
 
static uint32_t random (uint32_t max, uint32_t min=0)
 
static uint8_t * random (const uint8_t *buf, size_t len)
 Fills a buffer with random values. More...
 
static bool decryptBuffer (const uint8_t *data, size_t length, const uint8_t *iv, uint8_t ivlen, const uint8_t *key, uint8_t keylen, const uint8_t *aad, uint8_t aadLen, const uint8_t *tag, uint8_t tagLen)
 Decrypts a buffer using a shared key. More...
 
static uint8_t * getSHA256 (uint8_t *buffer, uint8_t length)
 Generates a SHA256 hash from input. More...
 
static bool encryptBuffer (const uint8_t *data, size_t length, const uint8_t *iv, uint8_t ivlen, const uint8_t *key, uint8_t keylen, const uint8_t *aad, uint8_t aadLen, const uint8_t *tag, uint8_t tagLen)
 Decrypts a buffer using a shared key. More...
 

Protected Attributes

uint8_t privateDHKey [KEY_LENGTH]
 Temporary private key store used during key agreement. More...
 
uint8_t publicDHKey [KEY_LENGTH]
 Temporary public key store used during key agreement. More...
 

Detailed Description

EnigmaIoT Crypto module. Wraps Arduino CryptoLib classes and methods.

Uses Arduino CryptoLib library

Definition at line 35 of file cryptModule.h.

Member Function Documentation

◆ decryptBuffer()

bool CryptModule::decryptBuffer ( const uint8_t *  data,
size_t  length,
const uint8_t *  iv,
uint8_t  ivlen,
const uint8_t *  key,
uint8_t  keylen,
const uint8_t *  aad,
uint8_t  aadLen,
const uint8_t *  tag,
uint8_t  tagLen 
)
static

Decrypts a buffer using a shared key.

Parameters
dataBuffer to decrypt. It will be used as input and output
lengthBuffer length in number of bytes
ivInitialization Vector used to encrypt this data
ivlenIV length
keyShared key used to encrypt data
keylenKey length
aadAdditional Authentication Data for Poly1305
aadLenAdditional Authentication Data length
tagBuffer to store authentication tag calculated by Poly1305
tagLenAdditional Authentication Tag length
Returns
True if decryption and tag checking was correct

Definition at line 52 of file cryptModule.cpp.

◆ encryptBuffer()

bool CryptModule::encryptBuffer ( const uint8_t *  data,
size_t  length,
const uint8_t *  iv,
uint8_t  ivlen,
const uint8_t *  key,
uint8_t  keylen,
const uint8_t *  aad,
uint8_t  aadLen,
const uint8_t *  tag,
uint8_t  tagLen 
)
static

Decrypts a buffer using a shared key.

Parameters
dataBuffer to decrypt. It will be used as input and output
lengthBuffer length in number of bytes
ivInitialization Vector used to encrypt this data
ivlenIV length
keyShared key used to encrypt data
keylenKey length
aadAdditional Authentication Data for Poly1305
aadLenAdditional Authentication Data length
tagBuffer to store authentication tag calculated by Poly1305
tagLenAdditional Authentication Tag length
Returns
True if encryption and tag generation was correct

Definition at line 86 of file cryptModule.cpp.

◆ getDH1()

void CryptModule::getDH1 ( )

Starts first stage of Diffie Hellman key agreement algorithm.

Definition at line 141 of file cryptModule.cpp.

◆ getDH2()

bool CryptModule::getDH2 ( const uint8_t *  remotePubKey)

Starts second stage of Diffie Hellman key agreement algorithm and calculate shares key.

Parameters
remotePubKeyPublic key got from the other peer
Returns
true if calculation worked normally, false otherwise.

Definition at line 148 of file cryptModule.cpp.

◆ getPrivDHKey()

uint8_t* CryptModule::getPrivDHKey ( )
inline

Gets own private key used on Diffie Hellman algorithm.

Returns
Pointer to private key

Definition at line 128 of file cryptModule.h.

◆ getPubDHKey()

uint8_t* CryptModule::getPubDHKey ( )
inline

Gets own public key used on Diffie Hellman algorithm.

Returns
Pointer to public key

Definition at line 136 of file cryptModule.h.

◆ getSHA256()

uint8_t * CryptModule::getSHA256 ( uint8_t *  buffer,
uint8_t  length 
)
static

Generates a SHA256 hash from input.

Parameters
bufferBuffer with data to hash. Hash will be stored here
lengthBuffer length in number of bytes. It should be 32 at least
Returns
Returns buffer pointer

Definition at line 20 of file cryptModule.cpp.

◆ random() [1/3]

uint32_t CryptModule::random ( )
static

Gets a random number.

Returns
Returns a random number

Definition at line 119 of file cryptModule.cpp.

◆ random() [2/3]

uint8_t * CryptModule::random ( const uint8_t *  buf,
size_t  len 
)
static

Fills a buffer with random values.

Parameters
bufPointer to the buffer to fill
lenBuffer length in number of bytes
Returns
Returns the same buffer used as input, filled with random data

Definition at line 127 of file cryptModule.cpp.

◆ random() [3/3]

static uint32_t CryptModule::random ( uint32_t  max,
uint32_t  min = 0 
)
inlinestatic

Definition at line 43 of file cryptModule.h.

Member Data Documentation

◆ privateDHKey

uint8_t CryptModule::privateDHKey[KEY_LENGTH]
protected

Temporary private key store used during key agreement.

Definition at line 141 of file cryptModule.h.

◆ publicDHKey

uint8_t CryptModule::publicDHKey[KEY_LENGTH]
protected

Temporary public key store used during key agreement.

Definition at line 142 of file cryptModule.h.


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