#include "sha256.h"
uint8_t hmacKey1[]={
0x65,0x63,0x73,0x74,0x61,0x63,0x79
};
void printHash(uint8_t* hash) {
int i;
for (i=0; i<32; i++) {
Serial.print("0123456789abcdef"[hash[i]>>4]);
Serial.print("0123456789abcdef"[hash[i]&0xf]);
}
Serial.println();
}
void setup() {
uint8_t* hash;
uint32_t a;
Serial.begin(9600);
// HMAC tests
Serial.println("Test: RFC4231 4.2");
Serial.print("Result:");
Sha256.initHmac(hmacKey1,20);
Sha256.print("Hi There");
//My TRIAL ATTEMPT
int i;
for (i=0; i<32; i++) {
hash[i] =Sha256.resultHmac();
Serial.println(hash[i]);
}
}
How do I save the hashed result into a variable? I disregarded the Printhash function above and tried it with my own code but it displays
sketch_feb14a:32: error: invalid conversion from 'uint8_t*' to 'unsigned char'
I don't understand the printhash function above and found little to no documentation on the web. I'm thinking of using AES library but I guess it's more complicated over here. The above code is based on Spaniako's CryptoSuite here
Heading
2 Answers 2
My solution was making a new function that returns a String with the hash
String GetHash256(uint8_t* hash) {
char tmp[16];
String sHash256 = "";
int i;
for (i=0; i<32; i++) {
sprintf(tmp, "%.2X",hash[i]);
sHash256.concat(tmp);
}
return sHash256 ;
}
The hash is a series of binary digits. They are usually represented in hexadecimal form for readibility. You are just printing out the raw bytes, which will give a series of random ASCII characters. Some of these may be control characters which interfere with serial port communication.
printHash
function takes the upper and lower 4 bits of each byte, and uses them as an index to the string of hex digits.