You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there and thank you for this free implementation.
I can not produce the same result using your library's fastpbkdf2_hmac_sha512() with Perl's Digest::SHA::hmac_sha512 and also Python's hashlib.sha512 (Perl's and Python's output do agree).
The problem may well be with me misunderstanding the usage of fastpbkdf2_hmac_sha512(). If this is the case, apologies in advance and please let me know how to use said function with a message and a secret key (no salt - are they the same?) and no repetitions.
Here are 2 programs to reproduce my problem:
test.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fastpbkdf2.h"
// gcc -g test.c libfastpbkdf2.a -lcrypto && a.out
// this is not producing the right result compared to perl
#define SHA512_DIGEST_SIZE (512/8)
// print binary buffer in hex
void printhex(FILE *fh, const char *name, const unsigned char *in, int len){
fprintf(fh, "begin hex for '%s':\n", name);
for(int i=0;i<len;i++){ fprintf(fh, "0x%02x ", in[i]); }
fprintf(fh, "\nend hex of %d bytes.\n", len);
}
int main(void){
char *message = "hello there";
char *key = "secret key";
char result[SHA512_DIGEST_SIZE];
int key_len = strlen(key);
int message_len = strlen(message);
fastpbkdf2_hmac_sha512(
// this is the input and its size
(uint8_t *)message, message_len,
// salt to the hash is our secret key decoded
(uint8_t *)key, key_len,
1, // iterations
// the output goes here
result, SHA512_DIGEST_SIZE
);
printhex(stdout, "result", result, SHA512_DIGEST_SIZE);
}
and here is the Perl script which produces a different result but which agrees with Python and also with another C implementation (by ogay):
mac.pl (run it as perl mac.pl)
#!/usr/bin/env perl
use strict;
use warnings;
use Digest::SHA qw/hmac_sha512/;
my $message = "hello there";
my $secret = "secret key";
my $hmacsha512 = Digest::SHA::hmac_sha512($message, $secret);
print "result hmacsha512:\n".bin2hex($hmacsha512)."\n";
sub bin2hex {
my @byts = split //, $_[0];
join(' ', map {sprintf("0x%x", ord)} @byts) . " (size ".@byts.")";
}
I would really love to use your implementation but I need to solve this issue right now.
As I said, the problem may be with me using your function incorrectly. In this case please advise. My usage is that I have a message and a key. Is your salt the same as my key? and I don't need repetitions (what's the default?), so I set them to 1. Even 0 repetitions produce mismatched result.
@hadjiprocopis The output of fastpbkdf2_hmac_sha512 is correct.
You are comparing the output of hmac-sha512 of perl with the output of pbkdf2-hmac-sha512 of fastpbkdf2, while the latter calls the first one iteratively, parameters will differ.
The first iteration of PRF uses Password as the PRF key and Salt concatenated with i encoded as a big-endian 32-bit integer as the input. (Note that i is a 1-based index.)
So, to get the output of fastpbkdf2 in Perl, you would need to use the message as a key (or salt), and the key concatenated with 1 in big endian as a message.
Hi there and thank you for this free implementation.
I can not produce the same result using your library's
fastpbkdf2_hmac_sha512()
with Perl'sDigest::SHA::hmac_sha512
and also Python'shashlib.sha512
(Perl's and Python's output do agree).The problem may well be with me misunderstanding the usage of
fastpbkdf2_hmac_sha512()
. If this is the case, apologies in advance and please let me know how to use said function with a message and a secret key (no salt - are they the same?) and no repetitions.Here are 2 programs to reproduce my problem:
test.c:
and here is the Perl script which produces a different result but which agrees with Python and also with another C implementation (by ogay):
mac.pl (run it as
perl mac.pl
)I would really love to use your implementation but I need to solve this issue right now.
As I said, the problem may be with me using your function incorrectly. In this case please advise. My usage is that I have a message and a key. Is your
salt
the same as mykey
? and I don't need repetitions (what's the default?), so I set them to 1. Even 0 repetitions produce mismatched result.5minute Edit: here are the 2 outputs:
test.c:
mac.pl:
bw,
Andreas Hadjiprocopis
The text was updated successfully, but these errors were encountered: