I am working on converting this C++ code into C so that I can optimize it with the CUDA architecture. Long story short I am running into problems with strings.
The PBKDF2 spec section I am having trouble with is below
Code:
where
U_1 = PRF (P, S || INT (i)) ,
U_2 = PRF (P, U_1) ,
...
U_c = PRF (P, U_{c-1}) .
Here, INT (i) is a four-octet encoding of the integer i, mostsignificant octet first.
So in the first round given a salt of "mysalt" the resulting 'key' passed to the HMAC function should be "mysalt0001" except the numbers 0001 are characters (and the char 0 is the same thing as'\0') which cases the end of the string prematurly. This worked fine with the C++ implementation using strings that accepted the '\0' and did not truncate the string. In my C implementation the char array is passed to HMAC and the trailing char's are lost.
I tried using other values, like '0' which didnt work because its value was not actually 0. Thank you for any help.
Some of the code.
Code:
char U[14+5]; // my test salt is 14 characters
char appended[] = {(char)0, (char)0, (char)0, (char)i, '\0'};
strcpy(U,S);
for (j=0;j<5;++j)
{
U[14+j] = appended[j];
}
Then later HMAC is called...
HMAC's header...
Code:
void HMAC(char* text, char* key)
I have verified and tested my versions of HMAC and SHA1
hmac_sha1.c