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

Updating README.md with provided example for encoded hash for the ease of storing in database #370

Open
th3r0b0t opened this issue Feb 7, 2024 · 0 comments

Comments

@th3r0b0t
Copy link

th3r0b0t commented Feb 7, 2024

Hello!
First of all, I wanna show my appreciation and respects for the nice work you folks have done;
Secondly, to cut things short, I had to go through the run() func in run.c file to see how the command line utility used argon2i_hash_encoded() function, since the encodedlen parameter was a little tricky and hasn't been documented in the comments above argon2i_hash_encoded()!
I think it would be nice to provide an example in readme file for encoded function too!
Here is an example of creating Argon2_i encoded hash:

#include "argon2.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define HASHLEN 128
#define SALTLEN 32
#define PWD "Good strong password"

int main(void)
{
    uint8_t salt[SALTLEN];
    memset( salt, 0x00, SALTLEN );

    uint8_t *pwd = (uint8_t *)strdup(PWD);
    uint32_t pwdlen = strlen((char *)pwd);

    uint32_t t_cost = 16;            // 16-pass computation (1 second or so)
    uint32_t m_cost = (1<<17);      // 128 mebibytes memory usage
    uint32_t parallelism = 4;       // number of threads and lanes

    char * encoded = NULL;
    size_t encodedlen = argon2_encodedlen(t_cost, m_cost, parallelism, SALTLEN, HASHLEN, Argon2_i);    // Argon2_i == 1
    encoded = malloc(encodedlen + 1);

    // high-level API
    argon2i_hash_encoded(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN, HASHLEN, encoded, encodedlen);
    free(pwd);

    printf( "%.*s\n", (int)encodedlen, encoded );
    
    return 0;
}
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

1 participant