This repository was archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_hmac.c
88 lines (76 loc) · 1.98 KB
/
main_hmac.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "include/drbg_hmac.h"
#include "include/hmac/sha256_hmac.h"
#include "include/test/timer_util.h"
#include "include/random_source.h"
#include <stdio.h>
#define DRBG_LEN 32
#define ENTROPY_LEN 32
int main() {
DRBG_HMAC drbg;
DRBG_HMAC_CONF conf;
uint8_t ent[ENTROPY_LEN];
uint8_t serial[16];
uint8_t res[DRBG_LEN];
print_time(1);
if (!DRBG_HMAC_SHA256_conf(&conf)) {
printf("Conf err");
return 1;
}
print_time(2);
if (!DRBG_HMAC_new(&drbg, &conf)) {
printf("New err");
return 2;
}
print_time(3);
int result = Get_Entropy(ENTROPY_LEN, false, ent);
if (result) {
printf("System call err1 %d", result);
return result;
}
print_time(4);
if (!DRBG_HMAC_instantiate(&drbg, ent, ENTROPY_LEN, NULL, 0, serial, 16)) {
printf("Instantiate err");
return 3;
}
print_time(5);
for (int j = 0; j < 10; ++j) {
if (!DRBG_HMAC_generate(&drbg, serial, 16, res, DRBG_LEN)) {
printf("Gen err");
return 4;
} else {
for (int i = 0; i < DRBG_LEN; ++i) {
printf("%d ", res[i]);
}
printf("\n");
}
}
print_time(6);
result = Get_Entropy(ENTROPY_LEN, false, ent);
if (result) {
printf("System call err2 %d", result);
return result;
}
print_time(7);
if (!DRBG_HMAC_reseed(&drbg, ent, ENTROPY_LEN, serial, 16)) {
printf("Reseed err");
return 5;
}
print_time(8);
for (int j = 0; j < 10; ++j) {
if (!DRBG_HMAC_generate(&drbg, serial, 16, res, DRBG_LEN)) {
printf("Gen err after reseed");
return 6;
} else {
for (int i = 0; i < DRBG_LEN; ++i) {
printf("%d ", res[i]);
}
printf("\n");
}
}
print_time(9);
if (!DRBG_HMAC_uninstantiate(&drbg)) {
printf("Uninstant err");
return 7;
}
return 0;
}