GithubHelp home page GithubHelp logo

shuixi2013 / arduino-aes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bigfighter/arduino-aes

0.0 0.0 0.0 6 KB

minimal AES library for arduino: 256 bit key + counter mode

Makefile 1.90% Python 10.00% C++ 88.10%

arduino-aes's Introduction

Minimal implementation of AES in counter mode with a key length of 256 bit.

Quickstart:

#include <aes.h>
AES aes;
for (char i = 0; i < 32; i++) {
	aes.key[i] = i; // set the key
}
for (char i = 0; i < 15; i++) {
	aes.counter[i] = 0;
}
aes.counter[15] = 1;

char msg[] = "Hello world";
// encrypt msg in place
for (char i = 0; i < 11; i++) {
	aes.process(&msg[i]);
}

The implementation and header file are aes-demo/aes.{cpp,h}. The code uses approximately 3k of program memory.

Demo Arduino sketch:

For a simple demo sketch, plug the arduino into /dev/ttyUSB0 (or change the parameter below), and run these commands:

cd aes-demo
make upload
./aes-demo.py /dev/ttyUSB0

Now you can enter a string. Press enter to send it to the Arduino. The Arduino will encrypt it and send it back. The python script will decrypt it again.

To keep the demo code simple, a restart of the python program requires a restart of the arduino.

For this to work, the arduino-mk package needs to be installed. Otherwise, the Arduino IDE can be used instead. The python script requires python3, Crypto, and serial. This is just for demonstration purposes. The AES library does of course not require python.

How AES in counter mode works:

This is just a vague description. For more details, see https://en.wikipedia.org/wiki/Advanced_Encryption_Standard https://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29

AES uses a 32 byte key to encrypt a block of 16 bytes. For a given key, the same block of plaintext will always be encrypted to the same block of ciphertext.

In counter mode, AES is used to encrypt a 16 byte counter. The result is XOR-ed with a block of plaintext, and the counter is incremented. This basically provides a one-time-pad stream.

The resulting encryption scheme can be used to encrypt 16*(2**(16*8)) bytes.

Note that there is no message authentication or validation. If such a thing is desired it must be provided upstream.

arduino-aes's People

Contributors

bigfighter avatar per1234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.