cathedrow / cryptosuite Goto Github PK
View Code? Open in Web Editor NEWCryptographic suite for Arduino (SHA, HMAC-SHA)
Cryptographic suite for Arduino (SHA, HMAC-SHA)
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
The compiling error message is shown below:
Arduino: 1.7.4 (Mac OS X), Board: "Arduino Uno"
In file included from /Users/../Documents/Arduino/libraries/Sha/sha256.cpp:3:0:
/Users/../Documents/Arduino/libraries/Sha/sha256.cpp:6:20: error: variable 'sha256K' must be const in order to be put into read-only section by means of 'attribute((progmem))'
uint32_t sha256K[] PROGMEM = {
^
/Users/../Documents/Arduino/libraries/Sha/sha256.cpp:19:27: error: variable 'sha256InitState' must be const in order to be put into read-only section by means of 'attribute((progmem))'
uint8_t sha256InitState[] PROGMEM = {
^
Read-only variables must be const as above suggestion.
Thanks!
I propose the following changes:
sha1.cpp should be changed:
void Sha1Class::write(uint8_t data) {
to:
size_t Sha1Class::write(uint8_t data) {
uint8_t sha1InitState[] PROGMEM = {
to:
const uint8_t sha1InitState[] PROGMEM = {
sha256.cpp should be changed:
uint32_t sha256K[] PROGMEM = {
to:
const uint32_t sha256K[] PROGMEM = {
uint8_t sha256InitState[] PROGMEM = {
to:
const uint8_t sha256InitState[] PROGMEM = {
Both sha1.h and sha256.h should be changed from:
virtual void write(uint8_t);
to:
virtual size_t write(uint8_t);
please consider support for ESP8266 and/or NodeMCU
In file included from ShowerWithFriends.ino:1:
/Users/george/Documents/Arduino/libraries/Sha/sha1.h:26: error: conflicting return type specified for 'virtual void Sha1Class::write(uint8_t)'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
A similar error happens for sha256.h
I'm new to SH256 and HMAC.
In my loop, I have
`
void loop(void) {
uint8_t sk[32] = {0x91,0x2F,0xC9,0xA2,0x46,0x16,0xB7,0x60,0x40,0xCA,0x7A,0x81,0x44,0x22,0xFB,0xB9,0x60,0x6A,0x70,0x20,0x56,0x69,0xF7,0x12,0x19,0x5B,0xA4,0x62,0xC5,0x64,0x52,0x67};
Sha256.initHmac(sk, 32);
Sha256.print("68C63AA0F4AE");
printHash(Sha256.resultHmac());
delay(1000);
}
`
The key and message is the same, but the result is different everytime I reboot the ESP.
I've followed the instructions on how to add this library to the Arduino IDE; and have selected a Sketch from the examples providers, however all examples result in the following :--
In file included from sha256test.pde:1:0:
C:\Users...\Documents\Arduino\libraries\Sha/sha256.h:26:18: error: conflicting return type specified for 'virtual void Sha256Class::write(uint8_t)'
virtual void write(uint8_t);
^
In file included from C:\Users...\Documents\Arduino\libraries\Sha/sha256.h:5:0,
from sha256test.pde:1:
C:\Users...\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1160-gef26c5f\cores\esp8266/Print.h:55:24: error: overriding 'virtual size_t Print::write(uint8_t)'
virtual size_t write(uint8_t) = 0;
^
Error compiling.
Last commit was a long time ago...
Thanks
Thank you for this code! It is much appreciated!
I'd like to know under which license it may be used.
A commented out header describing the license would be ideal.
Best Regards
I am using Arduino with ATMEGA 328 and the IDE is version 16.7 installed on Windows 10.
tried to run the example in the documentation. Just to create a HMAC256. I tried to verify the code in the IDE, I get this error which I do not know how to fix. Can you help.
invalid conversion from 'const char_' to 'const uint8_t_ {aka const unsigned char*}' [-fpermissive]
The Code is:
void setup() {
// put your setup code here, to run once:
uint8_t *hash;
//static const char hash[450]={};
//const char *hash; hash={};
Sha256.initHmac("hash key",8); // key, and length of key in bytes
Sha256.print("This is a message to hash");
hash = Sha256.resultHmac();
//Serial.print(hash,HEX);
}
void loop() {
// put your main code here, to run repeatedly:
}
I suggest a rewrite of this project under the terms of the GNU LGPLv3 (or a similar license) within a project with multiple maintainers.
This would fit the needs of the community (in my opinion) and would make an active development possible.
If I would get some support (about two or three other developers) I would start a rewrite in three or four weeks.
Feel free to join the Telegram group about this topic.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.