This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
67 lines (50 loc) · 1.56 KB
/
main.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "src/pbkdf2.h"
#include <string.h>
/* CHEATSHEET
Input:
P = password
S = salt
c = 1
Output = 0c60c80f 961f0e71 f3a9b524 af601206 2fe037a6
Input:
P = password
S = salt
c = 2
Output = ea6c014d c72d6f8c cd1ed92a ce1d41f0 d8de8957
Input:
P = password
S = salt
c = 4096
Output = 4b007901 b765489a bead49d9 26f721d0 65a429c1
Input:
P = password
S = salt
c = 16777216
Output = eefe3d61 cd4da4e4 e9945b3d 6ba2158c 2634e984
*/
int main(int argc, char** argv)
{
char salt[MAX_LENGTH] = "salt";
char password[MAX_LENGTH] = "password";
uint32_t strlen_password, strlen_salt;
uint32_t iteration_count = 4096;
pbkdf2_ctx_t ctx;
strlen_password = strlen(password);
strlen_salt = strlen(salt);
ctx.strlen_password = strlen_password;
ctx.strlen_salt = strlen_salt;
ctx.iteration_count = iteration_count;
ctx.bits_in_result_hash = 256;
strncpy((char*) ctx.password, password, ctx.strlen_password);
strncpy((char*) ctx.salt, salt, ctx.strlen_salt);
pbkdf2_ctx_init(&ctx);
hmac_append_str_text(&ctx.hmac_ctx, ctx.salt, ctx.strlen_salt);
hmac_append_str_key(&ctx.hmac_ctx, ctx.password, ctx.strlen_password);
pbkdf2(&ctx);
for(int i = 0; i < ctx.bits_in_result_hash / BITS_IN_WORD; i++)
{
printf("%08x ", ctx.T[i]);
}
printf("\n");
pbkdf2_ctx_dispose(&ctx);
}