Skip to content

A demo of my extension to the Adafruit_nRFCrypto, adding AES

License

Notifications You must be signed in to change notification settings

Kongduino/RAK4631_AES

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

RAK4631_AES

This is a demo for my extension to the Adafruit_nRFCrypto, which adds AES encryption to the Wisblock RAK4631. It adds a class, nRFCrypto_AES:

class nRFCrypto_AES {
  public:
    nRFCrypto_AES(void);
    bool begin(void);
    void end(void);
    int Process(char *msg, uint8_t msgLen, uint8_t *IV, uint8_t *pKey, uint8_t pKeyLen,
                   char *retBuf, SaSiAesEncryptMode_t modeFlag, SaSiAesOperationMode_t opMode);
    SaSiAesEncryptMode_t encryptFlag = (SaSiAesEncryptMode_t) 0; // SASI_AES_ENCRYPT
    SaSiAesEncryptMode_t decryptFlag = (SaSiAesEncryptMode_t) 1; // SASI_AES_DECRYPT
    SaSiAesOperationMode_t ecbMode = (SaSiAesOperationMode_t) 0; // SASI_AES_MODE_ECB
    SaSiAesOperationMode_t cbcMode = (SaSiAesOperationMode_t) 1; // SASI_AES_MODE_CBC
    SaSiAesOperationMode_t ctrMode = (SaSiAesOperationMode_t) 3; // SASI_AES_MODE_CTR
  private:
    bool _begun;
    SaSiAesPaddingType_t _paddingType = (SaSiAesPaddingType_t) 0; // SASI_AES_PADDING_NONE
    SaSiAesKeyType_t _userKey = (SaSiAesKeyType_t) 0; // SASI_AES_USER_KEY
};

The Process function does everything for you: ECB/CBC/CTR, and encrypt/decrypt.

DHKE

Since the ECC submodule of the nrf_crypto library seems to be giving a hard fault, I have switched to a software-based implementation of Diffie-Hellman Key Exchange. This is now part of a separate library, but uses the nRFCrypto library for encryption and random numbers.

Installation & Usage

Remove (and possibly save somewhere) the original version of the Adafruit library, and install mine. Since the only thing it does is add things, without removing anything, it is safe to use as a replacement. After that you use the usual #include "Adafruit_nRFCrypto.h" statement, and create an nRFCrypto_AES object. The sample code shows how to do all 6 operations, plus DHKE. The IV and encryption key are generated by the nRFCrypto.Random class.

About

A demo of my extension to the Adafruit_nRFCrypto, adding AES

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages