#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*>>4]);*
_ Serial.print("0123456789abcdef"[hash*&0xf]);_
_ }_
_ Serial.println();_
_}_
void setup() {
uint8_t hash;
* uint32_t a;*_ Serial.begin(9600);
* // HMAC tests*
Serial.println("Test: RFC4231 4.2");
Serial.println("Expect:b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7");
Serial.print("Result:");_
* Sha256.initHmac(hmacKey1,20);*
* Sha256.print("Hi There");** //MY TRIAL ATTEMPT*
* int i;*
* for (i=0; i<32; i++) {*
_ hash =Sha256.resultHmac();
Serial.println(hash*);
}
}
void loop() {
}
[/quote]
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
saiyojeff:
I don't understand the printhash function above and found little to no documentation on the web.
Why do you need "documentation on the web" for something that is self-explaining?
The results are coded into a "array of uint8_t" which means nearly the same as 'byte' in Arduino.
When you call the function, a pointer to the array with the results is returned to you:
hash =Sha256.resultHmac();
'hash' is a pointer to an array of 32 byte values.
And with this pointer you can access the resulting bytes with hash[0], hash[1], hash[2], hash[3] etc.
What you are doing/trying here is pure nonsense:
for (i=0; i<32; i++) {
hash =Sha256.resultHmac();
Serial.println(hash);
}
This would mean: Do the hash code calculation 32 times, and each time you calculated the code, print the pointer to the first address in RAM where the result resides.
Most likely not what you want.
Did you see the Arduino example that came with the library?
Are 'pointers' in C something like 'little strangers' to you and you are unable to deal with them and need some different example code?
If so: Please explain more detailed what you want to do with the 32 bytes from the 'hash' result!
If I read the headline I see something like "save result into a variable". There is just one problem: Arduino has no variable type that could take 32 bytes. So you must put the result into an "array" to save it for further usage. Two possibilities: 32 bytes can be saved in an array of 32 bytes length. You always can save it that way and later convert is to somethin that is "human readable".
Or you might want so save the bytes in "human readable" form. This would perhaps be a "string full of hexadecimal values". As a hex-string you'd need two bytes for one plus one zero as a string terminator, so the result where you could save it as a string would be an array like
char resultStr[65];
Can you send me link for the library?
itroublee:
Can you send me link for the library?
Who shall send the link?
Is Google censored by the authorities in your country?
Do you have problems with reading postings in this forum?
Or do you have problems with clicking a link that's contained in a posting in this forum?
Does the link not work if you click on it?
The link to the library is on the word "here" in the initial posting of "saiyojeff". Last word of his initial posting. Links in this forum are "underlined text" in a special link color. For me, the link to the library posted in the initial posting is still working (just tested).
I'm sure itroublee found it. Started another thread if I'm not mistaken