Please, post your current code now (especially key writing part). You wrote a textual representation of repeated "0b" pair (exactly 30 62 in ASCII) instead of packed byte '0x0b').
I have a file called mackeystring.dat and its contents is exactly:
0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
NB: the key, as exactly given by the test vector that I am using, using hmac-sha from rfc2202 is:
0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
unsigned char key[20];
fstream myFile ("/home/adam/Documents/cryptopp/mackeystring.dat", ios::binary);
myFile.open("/home/adam/Documents/cryptopp/mackeystring.dat");
if (myFile)
{
myFile.read((char*)key,sizeof key);
}
else printf("error opening file");
myFile.close();
printf("\nFILE CONTENTS: \n");
for (int i=0; i<20; i++)
printf(" %02x ", key[i]);
//full content of key= 30 62 30 62 30 62 30 62 30 62 30 62 30 62 30 62 30 62 30 62
//this is where the 20 byte key is used:
HMAC<SHA1> hmac( key, sizeof(key ) );
...
...
Previously I used: memset (key, 0x0b, 20);
to get my key, and if gave the correct result for my hmac-sha calculation, but have taken this out to retrieve it from the file instead.
So could either have the block of 0x0b stored in the file, and then put that 1 byte unsigned char into the memset, or just have the full key written to the file, which is what I have done now. Because when I try to replace 0x0b in the memset, with a unsigned char variable, it says invalid conversion between unsigned char and int for the memset expected values.
When I put the 0x in my ,dat file, both the 0 and the x are being read as a characters individually (ie 30 78)so took it out.
It works when I use the test vector with the string value of Jefe being used as the key in the file. As each character is one byte. But when I have the 0b pairs in, it does not give the correct output when I use that value for my calculation using the key.
Thanks again.