Files
MySensors/libraries/MySensors/MySigningAtsha204.h
T
Patrick Fallberg 4c4c9a8b39 Added SHA command to ATSHA204 backend driver
The SHA command is available in ATSHA204A variants of the chip
and can be used to calculate SHA256 digests of arbitrary data.

This enables us to strengthen the quality of the signatures by
salting signatures with node-specific data and improving the
quality of random data.
2015-03-16 20:14:22 +01:00

42 lines
1.2 KiB
C++

/*
ATSHA204 signing backend. The Atmel ATSHA204 offers true random number generation and
HMAC-SHA256 authentication with a readout-protected key.
Created by Patrick "Anticimex" Fallberg <patrick@fallberg.net>
*/
#ifndef MySigningAtsha204_h
#define MySigningAtsha204_h
#include "MyConfig.h"
#include "MySigning.h"
#include "utility/ATSHA204.h"
#include <stdint.h>
#define SIGNING_IDENTIFIER (1)
// The ATSHA204 is capable of generating proper random numbers for nonce
// and can calculate HMAC-SHA256 signatures. This is enterprise-
// level of security and ought to implement the signing needs for anybody.
class MySigningAtsha204 : public MySigning
{
public:
MySigningAtsha204(bool requestSignatures=true, uint8_t atshaPin = MY_ATSHA204_PIN);
bool getNonce(MyMessage &msg);
bool checkTimer(void);
bool putNonce(MyMessage &msg);
bool signMsg(MyMessage &msg);
bool verifyMsg(MyMessage &msg);
private:
atsha204Class atsha204;
unsigned long timestamp;
bool verification_ongoing;
uint8_t current_nonce[NONCE_NUMIN_SIZE_PASSTHROUGH];
uint8_t temp_message[SHA_MSG_SIZE];
uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
bool calculateSignature(MyMessage &msg);
uint8_t* sha256(const uint8_t* data, size_t sz);
};
#endif