P-H-C / phc-winner-argon2

The password hash Argon2, winner of PHC
Other
4.83k stars 411 forks source link

Unsure of how to use libargon2 #324

Open demhademha opened 3 years ago

demhademha commented 3 years ago

I'm struggling to use the libargon2 library. The final printf statement doesn't produce the raw output that I was expecting. Any support with this issue will be appreciated: Here's my code:

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "argon2.h"
int main(void)
{
/*ARGON2_PUBLIC int argon2i_hash_encoded(const uint32_t t_cost,
                                       const uint32_t m_cost,
                                       const uint32_t parallelism,
                                       const void *pwd, const size_t pwdlen,
                                       const void *salt, const size_t saltlen,
                                       const size_t hashlen, char *encoded,
                                       const size_t encodedlen);
*/
    const uint32_t iterations =20; //t_cost
    const uint32_t memory =  488281; //m_cost (500mb)
    const uint32_t parallelism = 4; // parallelism
    puts("Enter your password");
    char password [64];
    scanf("%s", password); //get the password
  const size_t passwordLength=strlen(password); //how long is our password?
puts("Enter your salt"); //the user won't actually get to choose this
char salt [64];
scanf("%s", salt); //get the salt
  const size_t saltLength=strlen(salt); //how long is our salt?
const size_t hashLength = 64; //length of the hash buffer
char encodedBuffer [65]; // + 1 for NULL
const size_t encodedLength = strlen(encodedBuffer);
puts("Generating hash");
int returnCode =argon2i_hash_encoded(iterations,
memory,
parallelism,
password, passwordLength,
salt, saltLength,
hashLength, encodedBuffer,
encodedLength);
printf("Return code: %i (%s) \n", returnCode, argon2_error_message(returnCode));
if ( returnCode != 0 )
{
printf("Return code: %i (%s) \n", returnCode, argon2_error_message(returnCode));
exit(-1);
}
for (size_t spinIndex = 0; spinIndex < encodedLength; spinIndex++ )
printf("%02x", encodedBuffer[spinIndex]); //produces nothing
puts("");
return 0;
}

Any support with this issue would be appreciated. Thank you

LoganDark commented 2 years ago

I can't read that code