summaryrefslogtreecommitdiff
path: root/argon-test.c
blob: cd2dcff02fa45238e9462fe810043b72ca7b673d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Standard C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

// PW-Hashing
#include <argon2.h>

int
main(void)
{
	const char pwd[] = "Hallo Welt";
	char salt[24];
	uint32_t t_cost = 20;
	uint32_t m_cost = 1600;
	uint32_t parallelism = 4;
	uint32_t hashlength = 24;
	char encoded[256] = { 0 };

	arc4random_buf(salt, sizeof salt);
	int res = argon2id_hash_encoded(t_cost, m_cost, parallelism, pwd, strlen(pwd), salt, sizeof salt, hashlength, encoded, sizeof encoded);
	if ( res == ARGON2_OK ) {
		printf("hash: %s\n", encoded);

		res = argon2id_verify(encoded, "Hallo Welt", 10);
		if ( res == ARGON2_OK ) {
			puts("Alles OK!");
		}
		else {
			fprintf(stderr, "Error: %s\n", argon2_error_message(res));
		}
	}
	else {
		fprintf(stderr, "Error: %s\n", argon2_error_message(res));
	}

	return EXIT_SUCCESS;
}