diff options
Diffstat (limited to 'argon-test.c')
| -rw-r--r-- | argon-test.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/argon-test.c b/argon-test.c new file mode 100644 index 0000000..cd2dcff --- /dev/null +++ b/argon-test.c | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | // Standard C | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | |||
| 7 | // PW-Hashing | ||
| 8 | #include <argon2.h> | ||
| 9 | |||
| 10 | int | ||
| 11 | main(void) | ||
| 12 | { | ||
| 13 | const char pwd[] = "Hallo Welt"; | ||
| 14 | char salt[24]; | ||
| 15 | uint32_t t_cost = 20; | ||
| 16 | uint32_t m_cost = 1600; | ||
| 17 | uint32_t parallelism = 4; | ||
| 18 | uint32_t hashlength = 24; | ||
| 19 | char encoded[256] = { 0 }; | ||
| 20 | |||
| 21 | arc4random_buf(salt, sizeof salt); | ||
| 22 | int res = argon2id_hash_encoded(t_cost, m_cost, parallelism, pwd, strlen(pwd), salt, sizeof salt, hashlength, encoded, sizeof encoded); | ||
| 23 | if ( res == ARGON2_OK ) { | ||
| 24 | printf("hash: %s\n", encoded); | ||
| 25 | |||
| 26 | res = argon2id_verify(encoded, "Hallo Welt", 10); | ||
| 27 | if ( res == ARGON2_OK ) { | ||
| 28 | puts("Alles OK!"); | ||
| 29 | } | ||
| 30 | else { | ||
| 31 | fprintf(stderr, "Error: %s\n", argon2_error_message(res)); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | else { | ||
| 35 | fprintf(stderr, "Error: %s\n", argon2_error_message(res)); | ||
| 36 | } | ||
| 37 | |||
| 38 | return EXIT_SUCCESS; | ||
| 39 | } | ||
