Skip to content

Adding symmetric encryption #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 23, 2020
Merged

Adding symmetric encryption #34

merged 4 commits into from
Sep 23, 2020

Conversation

luigigubello
Copy link
Contributor

@luigigubello luigigubello commented Sep 22, 2020

I have added user-friendly (I hope) support to symmetric encryption. In particular, you can run DES and AES128 now.

How to use

AES128

runEnc()

Giving the secret key, the initialization vector and the plain text, this method returns the encrypted one.

Syntax

AES128.runEnc(key, keyLength, input, inputLengh, iv);

Parameters

  • key: the secret key used to encrypt the plain text. The variable type is uint8_t;
  • keyLength: the secret key's length. It is always 16. The variable type is size_t;
  • input: the plain text. The variable type is uint8_t;
  • inputLengh: the plain text's length. It must be always a multiple of 16. The variable type is size_t;
  • iv: the initialization vector. It must have always 16 bytes. The variable type is uint8_t;

Example

#include <ArduinoBearSSL.h>
uint8_t key[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02};
uint8_t iv[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01};
uint8_t input[16] = "ArduinoArduino";
void setup() {
  AES128.runEnc(key, 16, input, 16, iv);
}
void loop() {}

runDec()

Giving the secret key, the initialization vector and the encrypted text, this method returns the decrypted one.

Sintax

AES128.runDec(key, keyLength, input, inputLengh, iv);

Parameters

  • key: the secret key used to encrypt the plain text. The variable type is uint8_t;
  • keyLength: the secret key's length. It is always 16. The variable type is size_t;
  • input: the encrypted text. The variable type is uint8_t;
  • inputLengh: the encrypted text's length. It must be always a multiple of 16. The variable type is size_t;
  • iv: the initialization vector. It must have always 16 bytes. The variable type is uint8_t;

Example

#include <ArduinoBearSSL.h>
uint8_t key[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02};
uint8_t iv[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01};
uint8_t input[16] = {0x65,0xD0,0xF7,0x75,0x8B,0x09,0x41,0x14,0xAF,0xA6,0xD3,0x3A,0x5E,0xA0,0x71,0x6A};
void setup() {
  AES128.runDec(key, 16, input, 16, iv);
}
void loop() {}

(similar for DES)

I have tested the examples with Arduino Nano 33 IoT (SAMD21), Arduino Uno WiFi Rev2 (ATmega4809) and Arduino Nano 33 BLE Sense.

Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thank you @luigigubello 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants