Skip to content
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

Updated write() objects to return size_t for Arduino 1.0 #6

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e81d54c
Updated write() objects to return size_t for Arduino 1.0
bakercp Apr 21, 2012
cf93870
Galileo Support Added
spaniakos Nov 28, 2014
0424cf3
Raspberry pi support addded
spaniakos Dec 3, 2014
5b788ef
updated README
spaniakos Dec 3, 2014
8c2b79b
new README update
spaniakos Dec 3, 2014
8314e4a
README update
spaniakos Dec 3, 2014
a805eb0
clean up code
spaniakos Dec 15, 2014
26ee0bc
added time measurement
spaniakos Jan 12, 2015
0f5194f
Rpi fixes
spaniakos Jan 12, 2015
21cc957
Key 2 example as string
spaniakos Jan 22, 2015
404cc43
Makefile update
spaniakos Jan 22, 2015
d09fa7f
new docs
spaniakos Jan 25, 2015
3e176ff
new docs
spaniakos Jan 25, 2015
678a2d3
opt
spaniakos Jan 25, 2015
5c0333e
Update README.md
spaniakos Jan 26, 2015
b484a91
fixes
spaniakos Jan 26, 2015
dd2db77
buffers in class
spaniakos Feb 12, 2015
f4aa83a
Merge pull request #1 from spaniakos/master
bakercp Nov 29, 2015
e54ffc7
Update README.md
Avamander Feb 20, 2016
c0f6229
write should return the number of successful bytes written
sterling Mar 8, 2016
1255b5f
Merge pull request #9 from sterling/master
spaniakos Sep 2, 2016
b26dc43
Added ESP8266 compatibility check for includes
TyIsI Apr 8, 2017
184ae15
Correct capitalization of Arduino.h include filename
per1234 Aug 11, 2017
e8fea84
Merge pull request #3 from per1234/fix-_filename
bakercp Aug 11, 2017
907a341
Merge pull request #2 from Avamander/patch-1
bakercp Aug 11, 2017
f4249f2
Merge pull request #11 from TyIsI/master
spaniakos Sep 25, 2017
c2a3755
Merge pull request #4 from spaniakos/master
bakercp Nov 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,372 changes: 2,372 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions README

This file was deleted.

100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Please see the full documentation at http://spaniakos.github.io/Cryptosuite

Cryptosuite is a cryptographic library for Arduino (including SHA and HMAC-SHA)

It currently supports secure hashing and hashed message authentication using SHA-1, SHA-256, HMAC-SHA-1 and HMAC-SHA-256.

Installation:
Make a 'libraries' directory with your Arduino sketches folder if you do not already have one.
Copy the 'Sha' directory into that directory.
Restart Arduino to rescan for new libraries.

Using SHA-1:

#include "sha1.h"
...
uint8_t *hash;
Sha1.init();
Sha1.print("This is a message to hash");
hash = Sha1.result();

The hash result is then stored in hash[0], hash[1] .. hash[19].

Using HMAC-SHA-1:

#include "sha1.h"
...
uint8_t *hash;
Sha1.initHmac("hash key",8); // key, and length of key in bytes
Sha1.print("This is a message to hash");
hash = Sha1.resultHmac();

The hash result is then stored in hash[0], hash[1] .. hash[19].

Using SHA-256:

#include "sha256.h"
...
uint8_t *hash;
Sha256.init();
Sha256.print("This is a message to hash");
hash = Sha256.result();

The hash result is then stored in hash[0], hash[1] .. hash[31].

Using HMAC-SHA-256:

#include "sha256.h"
...
uint8_t *hash;
Sha256.initHmac("hash key",8); // key, and length of key in bytes
Sha256.print("This is a message to hash");
hash = Sha256.resultHmac();

The hash result is then stored in hash[0], hash[1] .. hash[31].


Verification:
The provided example code tests against published test vectors.
SHA-1: FIPS 180-2, RFC3174 compliant
HMAC-SHA-1: FIPS 198a compliant
SHA-256: FIPS 180-2, RFC4231 compliant
HMAC-SHA-256: RFC4231 compliant

*UPDATE** Added Intel Galileo Support
Added printf.h so galileo can redirect to serial all the printf requests.

*UPDATE** Raspberry pi support added
### Raspberry pi
install
```
sudo make install
cd examples_Rpi
make
```

What to do after changes to the library
```
sudo make clean
sudo make install
cd examples_Rpi
make clean
make
```

What to do after changes to a sketch
```
cd examples_Rpi
make <sketch>

or
make clean
make
```

How to start a sketch
```
cd examples_Rpi
sudo ./<sketch>
```

78 changes: 78 additions & 0 deletions Sha/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#############################################################################
#
# Makefile for SHA on Raspberry Pi
#
# License: GPL (General Public License)
# Author: Charles-Henri Hallard
# Date: 2013/03/13
#
# Description:
# ------------
# use make all and mak install to install the library
# You can change the install directory by editing the LIBDIR line
#
PREFIX=/usr/local

# Library parameters
# where to put the lib
LIBDIR=$(PREFIX)/lib
# lib name
LIB=libSHA1
LIB2=libSHA256
# shared library name
LIBNAME=$(LIB).so.1.0
LIBNAME2=$(LIB2).so.1.0

# Where to put the header files
HEADER_DIR=${PREFIX}/include/SHA1
HEADER_DIR2=${PREFIX}/include/SHA256

# The recommended compiler flags for the Raspberry Pi
CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s

# make all
# reinstall the library after each recompilation
all: libSHA1 libSHA256

# Make the library
libSHA1: sha1.o
g++ -shared -Wl,-soname,[email protected] ${CCFLAGS} -o ${LIBNAME} $^

# Library parts
sha1.o: sha1.cpp
g++ -Wall -fPIC ${CCFLAGS} -c $^

# Make the library
libSHA256: sha256.o
g++ -shared -Wl,-soname,[email protected] ${CCFLAGS} -o ${LIBNAME2} $^

# Library parts
sha256.o: sha256.cpp
g++ -Wall -fPIC ${CCFLAGS} -c $^

# clear build files
clean:
rm -rf *.o ${LIB}.* ${LIB2}.*
rm -rf ${LIBDIR}/${LIB}.*
rm -rf ${HEADER_DIR}

install: all install-libs install-headers

# Install the library to LIBPATH
install-libs:
@echo "[Installing Libs]"
@if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
@install -m 0755 ${LIBNAME} ${LIBDIR}
@ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so.1
@ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so
@install -m 0755 ${LIBNAME2} ${LIBDIR}
@ln -sf ${LIBDIR}/${LIBNAME2} ${LIBDIR}/${LIB2}.so.1
@ln -sf ${LIBDIR}/${LIBNAME2} ${LIBDIR}/${LIB2}.so
@ldconfig

install-headers:
@echo "[Installing Headers]"
@if ( test ! -d ${HEADER_DIR} ) ; then mkdir -p ${HEADER_DIR} ; fi
@install -m 0644 *1.h ${HEADER_DIR}
@if ( test ! -d ${HEADER_DIR2} ) ; then mkdir -p ${HEADER_DIR2} ; fi
@install -m 0644 *256.h ${HEADER_DIR2}
35 changes: 33 additions & 2 deletions Sha/examples/hmacsha256test/hmacsha256test.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "sha256.h"
#include <Arduino.h>
#include "./printf.h"

uint8_t hmacKey1[]={
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b
Expand Down Expand Up @@ -33,70 +35,99 @@ void printHash(uint8_t* hash) {
}

void setup() {
printf_begin();
uint8_t* hash;
uint32_t a;

unsigned long ms;
Serial.begin(9600);

// HMAC tests
Serial.println("Test: RFC4231 4.2");
Serial.println("Expect:b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7");
Serial.print("Result:");
ms = micros();
Sha256.initHmac(hmacKey1,20);
Sha256.print("Hi There");
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

Serial.println("Test: RFC4231 4.3");
Serial.println("Expect:5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843");
Serial.print("Result:");
ms = micros();
Sha256.initHmac((uint8_t*)"Jefe",4);
Sha256.print("what do ya want for nothing?");
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

Serial.println("Test: RFC4231 4.4");
Serial.println("Expect:773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe");
Serial.print("Result:");
ms = micros();
Sha256.initHmac(hmacKey3,20);
for (a=0; a<50; a++) Sha256.write(0xdd);
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

Serial.println("Test: RFC4231 4.5");
Serial.println("Expect:82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b");
Serial.print("Result:");
ms = micros();
Sha256.initHmac(hmacKey2,25);
for (a=0; a<50; a++) Sha256.write(0xcd);
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

Serial.println("Test: RFC4231 4.6");
Serial.println("Expect:a3b6167473100ee06e0c796c2955552b-------------------------------");
Serial.print("Result:");
ms = micros();
Sha256.initHmac(hmacKey4,20);
Sha256.print("Test With Truncation");
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

Serial.println("Test: RFC4231 4.7");
Serial.println("Expect:60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54");
Serial.print("Result:");
ms = micros();
Sha256.initHmac(hmacKey5,131);
Sha256.print("Test Using Larger Than Block-Size Key - Hash Key First");
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

Serial.println("Test: RFC4231 4.8");
Serial.println("Expect:9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2");
Serial.print("Result:");
ms = micros();
Sha256.initHmac(hmacKey5,131);
Sha256.print("This is a test using a larger than block-size key and a larger than "
"block-size data. The key needs to be hashed before being used by the HMAC algorithm.");
printHash(Sha256.resultHmac());
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();

}

void loop() {
}
}
Loading