Added sha204 library

Taken from the sha204_library folder in
https://github.com/jimblom/sha204-Breakout
Commit 8e1ac05ef987b1869605ad067db2bdbaec1c109f

ATSHA204 is a crypto cirquit from Atmel that enables
SHA256-based MAC and HMAC calculations as well as
secure key storage and random number generation.

This can be used to sign messages passed between
sensor nodes and prevent both man-in-the-middle and
replay attacking.
This commit is contained in:
Patrick Fallberg
2015-01-10 18:37:43 +01:00
parent 0dd6687488
commit 9fd41b4030
4 changed files with 1280 additions and 0 deletions
@@ -0,0 +1,103 @@
/* ATSHA204 Library Simple Example
by: Jim Lindblom
SparkFun Electronics
date: November 8, 2012
This code shows how to wake up and verify that an SHA204 is
connected and operational. And how to obtain an SHA204's unique serial
number, and send it a MAC challenge.
The ATSHA204's SDA pin can be connected to any of the Arduino's digital pins.
When constructing your atsha204Class, pass the constructor the pin you want to use.
In this example we'll attach SDA to pin 7.
The ATSHA204 can be powered between 3.3V and 5V.
*/
#include <sha204_library.h>
const int sha204Pin = 7;
atsha204Class sha204(sha204Pin);
void setup()
{
Serial.begin(9600);
Serial.println("Sending a Wakup Command. Response should be:\r\n4 11 33 43:");
Serial.println("Response is:");
wakeupExample();
Serial.println();
Serial.println("Asking the SHA204's serial number. Response should be:");
Serial.println("1 23 x x x x x x x EE");
Serial.println("Response is:");
serialNumberExample();
Serial.println();
Serial.println("Sending a MAC Challenge. Response should be:");
Serial.println("23 6 67 0 4F 28 4D 6E 98 62 4 F4 60 A3 E8 75 8A 59 85 A6 79 96 C4 8A 88 46 43 4E B3 DB 58 A4 FB E5 73");
Serial.println("Response is:");
macChallengeExample();
}
void loop()
{
}
byte wakeupExample()
{
uint8_t response[SHA204_RSP_SIZE_MIN];
byte returnValue;
returnValue = sha204.sha204c_wakeup(&response[0]);
for (int i=0; i<SHA204_RSP_SIZE_MIN; i++)
{
Serial.print(response[i], HEX);
Serial.print(" ");
}
Serial.println();
return returnValue;
}
byte serialNumberExample()
{
uint8_t serialNumber[9];
byte returnValue;
returnValue = sha204.getSerialNumber(serialNumber);
for (int i=0; i<9; i++)
{
Serial.print(serialNumber[i], HEX);
Serial.print(" ");
}
Serial.println();
return returnValue;
}
byte macChallengeExample()
{
uint8_t command[MAC_COUNT_LONG];
uint8_t response[MAC_RSP_SIZE];
const uint8_t challenge[MAC_CHALLENGE_SIZE] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
};
uint8_t ret_code = sha204.sha204m_execute(SHA204_MAC, 0, 0, MAC_CHALLENGE_SIZE,
(uint8_t *) challenge, 0, NULL, 0, NULL, sizeof(command), &command[0],
sizeof(response), &response[0]);
for (int i=0; i<SHA204_RSP_SIZE_MAX; i++)
{
Serial.print(response[i], HEX);
Serial.print(' ');
}
Serial.println();
return ret_code;
}