Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsure of how to use libargon2 #324

Open
demhademha opened this issue Jul 14, 2021 · 1 comment
Open

Unsure of how to use libargon2 #324

demhademha opened this issue Jul 14, 2021 · 1 comment

Comments

@demhademha
Copy link

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
Copy link

I can't read that code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants