Turns an Arduino (I used a RedStick from Sparkfun) in a cryptography token, allowing you to encrypt and decrypt messages with an unknown secret key using the NaCl encryption algorithm.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 58be87c Mar 5, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md Fixed README table Mar 5, 2017
crypto-arduino.sublime-project
crypto.ino
crypto_box.py Removed serial port from list of args to encrypt and decrypt Mar 5, 2017
secrets.cpp Completed encryption/decryption state machine Mar 4, 2017
secrets.h Completed encryption/decryption state machine Mar 4, 2017
state.cpp
state.h
state_buffer.cpp Growing buffer to fit additional encryption overhead of encrypted data Mar 5, 2017
state_buffer.h Completed encryption/decryption state machine Mar 4, 2017
state_decrypt.cpp
state_decrypt.h
state_encrypt.cpp
state_encrypt.h
state_idle.cpp
state_idle.h
state_send_result.cpp
state_send_result.h Completed encryption/decryption state machine Mar 4, 2017
testme.py
tweetnacl.c
tweetnacl.h

README.md

crypto-in-a-box

Turns an Arduino (I used a RedStick from Sparkfun) in a cryptography token, allowing you to encrypt and decrypt messages with an unknown secret key using the NaCl encryption algorithm.

The protocol is as follows:

Byte 0 Byte 1 ... Byte N-1 Byte N
Input len Input ... Input 'E' or 'D'

Sending an 'E' as the last character tells the Arduino to attempt to encrypt the input, and send back the result.

Sending a 'D' as the last character tells the Arduino to attempt to decrypt the input, and send back the result.

This was a cool opportunity to experiment with a few different things:

  • NaCl encryption with the TweetNaCl library written in C
  • State machine design patterns in C

The Arduino running this program effectively becomes a security "token", or in other words, a physical device one needs in order to create/parse encrypted messages. This was a cool concept to explore: secrets embedded in a physical device.

I was also inspired by the book "Patterns in C", which describes a few software design patterns and their implementations in C. This project was a great opportunity to use a state machine, as different actions need to be taken as character inputs come in. You'll notice that despite Arduino supporting C++ (and thus object-oriented design which would make implementing the STATE pattern that much easier) I've stuck to C constructs exclusively, for my own benefit. I use C day to day and want to get better at implementing desing patterns without object-oriented language support.