-
Notifications
You must be signed in to change notification settings - Fork 4
/
hash_drbg_test.c
84 lines (78 loc) · 8.9 KB
/
hash_drbg_test.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
#include "hash_drbg.h"
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
extern void print_hex(uint8_t* a, size_t len);
int is_equal(uint8_t* x, uint8_t* y, size_t len){
for(int i =0; i<len; i++){
if(x[i]!=y[i]){
return 0;
}
}
return 1;
}
void hash_drbg_test(){
uint8_t ei[32] = {0x63,0x36,0x33,0x77,0xe4,0x1e,0x86,0x46, 0x8d,0xeb,0x0a,0xb4,0xa8,0xed,0x68,0x3f, 0x6a,0x13,0x4e,0x47,0xe0,0x14,0xc7,0x00, 0x45,0x4e,0x81,0xe9,0x53,0x58,0xa5,0x69};
uint8_t n[16] = {0x80,0x8a,0xa3,0x8f,0x2a,0x72,0xa6,0x23, 0x59,0x91,0x5a,0x9f,0x8a,0x04,0xca,0x68};
struct hashdrbg * h = hashdrbg_init(ei, 32, n ,16);
uint8_t expected_v[55] ={0x32,0xab,0x60,0x5d,0xdc,0x8d,0x56,0x51, 0x09,0x3b,0x8a,0x59,0xbd,0x9d,0x3a,0xde, 0xa1,0x24,0x9e,0x21,0xa6,0x9e,0x2e,0x4a, 0x39,0x67,0x51,0x5f,0xa0,0x3a,0xd4,0x1c, 0xcf,0x5b,0x12,0x6e,0xb9,0xf3,0xb2,0x68, 0x08,0x0c,0x95,0x2d,0xf8,0x82,0x41,0xfe, 0x4c,0xc2,0x7b,0xbc,0xbb,0xbe,0xd5};
uint8_t expected_c[55] ={0x8e,0xa2,0x69,0x1d,0x19,0x15,0xeb,0xb4, 0x97,0x55,0x93,0xca,0x3f,0xba,0xd0,0xba, 0x13,0x70,0x26,0xd9,0x01,0xa9,0x59,0x50, 0xa2,0x07,0xc4,0x1d,0xc7,0x77,0x3e,0x15, 0xc1,0xe8,0x5f,0x4a,0x5f,0x91,0x00,0x28, 0x66,0x83,0x0b,0xeb,0xe5,0xc4,0xee,0x17, 0x85,0xb8,0x39,0x32,0x3f,0xbb,0x44};
assert(is_equal(h->v, expected_v, 55));
assert(is_equal(h->c, expected_c, 55));
assert(h->reseed_counter==1);
uint8_t ei2[32] = {0xe6,0x2b,0x8a,0x8e,0xe8,0xf1,0x41,0xb6, 0x98,0x05,0x66,0xe3,0xbf,0xe3,0xc0,0x49, 0x03,0xda,0xd4,0xac,0x2c,0xdf,0x9f,0x22, 0x80,0x01,0x0a,0x67,0x39,0xbc,0x83,0xd3};
hashdrbg_reseed(h,ei2,32,0,0);
uint8_t expected_v2[55] = {0x59,0x17,0x7d,0x93,0x84,0x3f,0x05,0x50,0xf3,0x39,0x33,0xa5,0x1e,0xb4,0x88,0x16,0x86,0x99,0xab,0x9c,0x85,0x65,0x15,0x36,0xa6,0x1f,0x7e,0xc7,0x1e,0x8b,0x27,0x4a,0x15,0x1f,0x17,0xe5,0x6b,0xec,0xaf,0x53,0x1d,0xcf,0xc9,0x55,0xf2,0xf1,0xad,0xb6,0x53,0x6d,0x51,0xb2,0x56,0xd5,0x3c};
uint8_t expected_c2[55] = {0x89,0x7c,0x02,0x69,0x9f,0x42,0x54,0xe1,0xf3,0x3c,0x94,0xf7,0xbf,0xa8,0x5d,0xa3,0x82,0x6d,0xf6,0xc2,0x59,0x0e,0xd0,0x81,0x5c,0xbc,0xed,0x36,0xd7,0x7a,0xa3,0x37,0x5a,0x15,0x82,0xff,0xc1,0xc8,0x87,0x41,0x6a,0xfd,0x1b,0xa0,0xf0,0x4b,0x6d,0xdf,0xf8,0x1a,0x2b,0x0e,0x5b,0x84,0x4d};
assert(is_equal(h->v, expected_v2, 55));
assert(is_equal(h->c, expected_c2, 55));
assert(h->reseed_counter==1);
uint8_t* hash = hashdrbg_next(h, 1024, 0, 0);
uint8_t expected_v3[55] = {0xe2,0x93,0x7f,0xfd,0x23,0x81,0x5a,0x32,0xe6,0x75,0xc8,0x9c,0xde,0x5c,0xe5,0xba,0x09,0x07,0xa2,0x5e,0xde,0x73,0xe6,0x1c,0x9e,0xc7,0x6d,0x67,0xda,0x58,0x2c,0x94,0x00,0x1f,0xda,0x32,0xb6,0x0e,0xc4,0x02,0x02,0xa1,0x64,0xc6,0xa4,0xd6,0x64,0x11,0xcc,0x6b,0x99,0xb1,0x28,0x46,0x17};
uint8_t expected_c3[55] = {0x89,0x7c,0x02,0x69,0x9f,0x42,0x54,0xe1,0xf3,0x3c,0x94,0xf7,0xbf,0xa8,0x5d,0xa3,0x82,0x6d,0xf6,0xc2,0x59,0x0e,0xd0,0x81,0x5c,0xbc,0xed,0x36,0xd7,0x7a,0xa3,0x37,0x5a,0x15,0x82,0xff,0xc1,0xc8,0x87,0x41,0x6a,0xfd,0x1b,0xa0,0xf0,0x4b,0x6d,0xdf,0xf8,0x1a,0x2b,0x0e,0x5b,0x84,0x4d};
assert(is_equal(h->v, expected_v3, 55));
<