-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhash_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));
assert(is_equal(h->c, expected_c3, 55));
assert(h->reseed_counter==2);
uint8_t* hash2 = hashdrbg_next(h, 1024, 0, 0);
uint8_t expected_v4[55]={0x6c,0x0f,0x82,0x66,0xc2,0xc3,0xaf,0x14,0xd9,0xb2,0x5d,0x94,0x9e,0x05,0x43,0x5d,0x8b,0x75,0x99,0x21,0x37,0x82,0xb6,0xea,0xc6,0xcd,0x90,0xa1,0x0d,0x48,0xe1,0xc9,0x60,0x88,0xf5,0xdb,0xa2,0x02,0x41,0xb6,0x8c,0xb6,0x4b,0xb0,0x50,0x28,0xc3,0x5e,0x55,0x58,0xef,0x8a,0x6e,0xdc,0xa6};
uint8_t expected_c4[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};
uint8_t expected_num[128] ={0x04,0xee,0xc6,0x3b,0xb2,0x31,0xdf,0x2c,0x63,0x0a,0x1a,0xfb,0xe7,0x24,0x94,0x9d,0x00,0x5a,0x58,0x78,0x51,0xe1,0xaa,0x79,0x5e,0x47,0x73,0x47,0xc8,0xb0,0x56,0x62,0x1c,0x18,0xbd,0xdc,0xdd,0x8d,0x99,0xfc,0x5f,0xc2,0xb9,0x20,0x53,0xd8,0xcf,0xac,0xfb,0x0b,0xb8,0x83,0x12,0x05,0xfa,0xd1,0xdd,0xd6,0xc0,0x71,0x31,0x8a,0x60,0x18,0xf0,0x3b,0x73,0xf5,0xed,0xe4,0xd4,0xd0,0x71,0xf9,0xde,0x03,0xfd,0x7a,0xea,0x10,0x5d,0x92,0x99,0xb8,0xaf,0x99,0xaa,0x07,0x5b,0xdb,0x4d,0xb9,0xaa,0x28,0xc1,0x8d,0x17,0x4b,0x56,0xee,0x2a,0x01,0x4d,0x09,0x88,0x96,0xff,0x22,0x82,0xc9,0x55,0xa8,0x19,0x69,0xe0,0x69,0xfa,0x8c,0xe0,0x07,0xa1,0x80,0x18,0x3a,0x07,0xdf,0xae,0x17};
assert(is_equal(h->v, expected_v4, 55));
assert(is_equal(h->c, expected_c4, 55));
assert(is_equal(hash2, expected_num, 128));
assert(h->reseed_counter==3);
/*
uint8_t ei3[32] = {0x09,0x96,0xa3,0x82,0x5a,0x45,0x6d,0xb3,0xc5,0xae,0x7c,0x00,0x58,0xe6,0xf9,0xb5,0xf4,0x38,0x40,0x74,0xdd,0xfe,0x37,0xb4,0xac,0x68,0xe2,0xc9,0x8b,0xdb,0x54,0xc5};
uint8_t n2[16] = {0x31,0x84,0x43,0xaa,0xf8,0xc6,0x6f,0x2b,0x81,0xe4,0x14,0xde,0xe9,0x55,0x3f,0x7c};
struct hashdrbg * h2 = hashdrbg_init(ei3, 32, n2 ,16);
uint8_t expected_v5[55]={0x9d,0x31,0x1d,0x26,0xc0,0x96,0x30,0xb0,0xd0,0x3c,0xcd,0xc1,0x26,0xfc,0x2a,0x6e,0xad,0x67,0xeb,0x8b,0x3c,0x36,0x9c,0xd5,0x51,0x32,0x2e,0xfb,0x60,0xc4,0x0b,0xf5,0x06,0x00,0x56,0x92,0x87,0x2e,0xaa,0xf4,0xe0,0x08,0xed,0x93,0x30,0x5a,0xc3,0x44,0xf2,0x95,0x42,0xc0,0xae,0xcd,0x94};
uint8_t expected_c5[55]={0x4a,0x58,0xd9,0x67,0x53,0xef,0xde,0xdd,0x7d,0x18,0xf6,0x44,0xe6,0x43,0xb5,0xf7,0x2b,0xde,0x48,0x18,0xc7,0x06,0xcd,0xcf,0x61,0x42,0x94,0x64,0x85,0xf6,0x61,0x2f,0x6b,0xdd,0xb6,0x7e,0x64,0x30,0xc9,0xdb,0x3c,0x1d,0xd5,0xf3,0x4c,0x62,0xfc,0xda,0x91,0x4a,0xe9,0x38,0xcd,0x98,0xe2};
assert(is_equal(h2->v, expected_v5, 55));
assert(is_equal(h2->c, expected_c5, 55));
assert(h2->reseed_counter==1);
uint8_t ei4[32] = {0xf7,0xd2,0x84,0x58,0x3d,0xc3,0x0f,0x5e,0xc4,0xb1,0x6f,0x7b,0x91,0x6a,0x7a,0x89,0xbc,0xed,0x38,0xbb,0xc7,0xd4,0x03,0xad,0x35,0x8e,0xc9,0x19,0x69,0x13,0xfe,0x6d};
hashdrbg_reseed(h2,ei4,32,0,0);
uint8_t expected_v6[55]={0xbd,0xdd,0x40,0xd9,0xf6,0xd6,0x73,0xa5, 0xe8,0xf0,0xd2,0x4b,0x56,0xa3,0x57,0x3f, 0xc7,0x1a,0x0d,0x2c,0x23,0x0c,0xb6,0xe1, 0xf1,0x01,0xfe,0x9e,0xdb,0x68,0xfb,0x65, 0xdb,0x31,0xeb,0x5c,0x01,0xd8,0xd7,0x19, 0x16,0x00,0xf0,0x42,0xc0,0x30,0xe7,0x48, 0xce,0x00,0x4e,0x0e,0xbe,0x9a,0x77,};
uint8_t expected_c6[55]={0xc8,0xe4,0x33,0xa7,0x36,0xde,0x7c,0xbd, 0x7e,0x86,0xc6,0x49,0x74,0xd9,0x67,0x73,0xb5, 0x70,0xda,0x8c,0x3e,0x7a,0x2a,0x34,0x17,0xd2, 0x64,0x7f,0xe1,0x22,0x6e,0x3c,0x9f,0x8e,0x69, 0x61,0x91,0xbb,0xd9,0x7c,0x52,0xc0,0xde,0x4d, 0x3f,0xab,0x63,0xf9,0x3c,0xfb,0x5c,0x69,0xe5, 0x75,0x8d};
assert(is_equal(h2->v, expected_v6, 55));
assert(is_equal(h2->c, expected_c6, 55));
assert(h2->reseed_counter==1);
uint8_t expected_v7[55]={0x86,0xc1,0x74,0x81,0x2d,0xb4,0xf0,0x63,0x67,0x77,0x98,0x94,0xcb,0x7c,0xbe,0xb3,0x7c,0x8a,0xe7,0xb8,0x61,0x86,0xe1,0xa0,0x12,0x72,0xcb,0xaf,0x43,0x57,0xaa,0x96,0x38,0x55,0xf3,0x86,0x31,0x96,0xf8,0xa9,0x79,0x6b,0x23,0x4d,0x3e,0x47,0xd7,0xc5,0x1b,0x41,0xaf,0xb1,0x48,0xe5,0x18};
uint8_t expected_c7[55]={0xc8,0xe4,0x33,0xa7,0x36,0xde,0x7c,0xbd,0x7e,0x86,0xc6,0x49,0x74,0xd9,0x67,0x73,0xb5,0x70,0xda,0x8c,0x3e,0x7a,0x2a,0x34,0x17,0xd2,0x64,0x7f,0xe1,0x22,0x6e,0x3c,0x9f,0x8e,0x69,0x61,0x91,0xbb,0xd9,0x7c,0x52,0xc0,0xde,0x4d,0x3f,0xab,0x63,0xf9,0x3c,0xfb,0x5c,0x69,0xe5,0x75,0x8d};
uint8_t* hash3 = hashdrbg_next(h2, 1024, 0, 0);
assert(is_equal(h2->v, expected_v7, 55));
assert(is_equal(h2->c, expected_c7, 55));
assert(h2->reseed_counter==2);
uint8_t expected_v8[55]={0x4f,0xa5,0xa8,0x28,0x64,0x93,0x6d,0x20,0xe5,0xfe,0x5e,0xde,0x40,0x56,0x26,0x27,0x31,0xfb,0xc2,0x44,0xa0,0x01,0x0c,0x26,0xe5,0x64,0x02,0x8e,0x74,0xe5,0x0a,0x29,0xf2,0xba,0xe9,0xeb,0xaf,0xf4,0xa7,0x94,0x28,0xee,0x2e,0x00,0xed,0xcc,0x00,0xbd,0xb7,0xc7,0xa5,0x9e,0xc4,0xe9,0x88};
uint8_t expected_c8[55]={0xc8,0xe4,0x33,0xa7,0x36,0xde,0x7c,0xbd,0x7e,0x86,0xc6,0x49,0x74,0xd9,0x67,0x73,0xb5,0x70,0xda,0x8c,0x3e,0x7a,0x2a,0x34,0x17,0xd2,0x64,0x7f,0xe1,0x22,0x6e,0x3c,0x9f,0x8e,0x69,0x61,0x91,0xbb,0xd9,0x7c,0x52,0xc0,0xde,0x4d,0x3f,0xab,0x63,0xf9,0x3c,0xfb,0x5c,0x69,0xe5,0x75,0x8d};
uint8_t expected_num2[128] ={0x41,0x92,0xe5,0x69,0xbe,0x8f,0x66,0x82,0x0d,0x20,0x37,0x4e,0xfb,0x53,0xd2,0x65,0x4f,0x31,0x6c,0x1f,0x09,0xc8,0xe4,0xb2,0xa2,0xfb,0x78,0x3b,0x0f,0xf8,0xa8,0x2c,0x88,0xb2,0x47,0x91,0x41,0x4b,0x1a,0x1f,0x54,0xbd,0x00,0xc9,0xce,0x6a,0x98,0x1d,0x8d,0x1d,0x44,0x5a,0xa5,0x5d,0xbc,0x83,0x72,0xe6,0x7e,0x44,0x0b,0x4d,0x6f,0x96,0xb2,0xe6,0xac,0x4e,0xe9,0x65,0x76,0x72,0xaa,0xda,0xb5,0x62,0x29,0x7f,0xea,0x4c,0x6d,0x0b,0x1b,0xa0,0x66,0x36,0x2e,0xeb,0x07,0x5a,0x9f,0x04,0xda,0x40,0xc3,0x1d,0x0d,0xc6,0xd3,0x0e,0x3a,0x23,0x6b,0xf2,0xc3,0x4d,0xcc,0xd2,0x91,0xea,0xff,0xd1,0x6e,0xae,0x6c,0x1c,0xdb,0x88,0x71,0x2a,0x91,0x3f,0xc6,0x5f,0x97,0x9d,0xc7,0x42,};
uint8_t* hash4 = hashdrbg_next(h2, 1024, 0, 0);
assert(is_equal(h2->v, expected_v8, 55));
assert(is_equal(h2->c, expected_c8, 55));
assert(is_equal(hash4, expected_num2, 128));
assert(h2->reseed_counter==3);*/
}
int main(){
hash_drbg_test();
}