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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
//======================================================================
//
// test-sha256.c
// -------------
// test program for Cryptech Novena framwwork with EIM interface
// using the sha256 core.
//
//======================================================================
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "novena-eim.h"
//------------------------------------------------------------------------------
// Defines
//
// Symbolic names for the SHA256 core API.
//------------------------------------------------------------------------------
#define SHA256_PREFIX (0x0000)
#define SHA256_BASE (EIM_BASE_ADDR + SHA256_PREFIX)
#define ADDR_NAME0 (SHA256_BASE + (0x00 << 2))
#define ADDR_NAME1 (SHA256_BASE + (0x01 << 2))
#define ADDR_VERSION (SHA256_BASE + (0x02 << 2))
#define ADDR_CTRL (SHA256_BASE + (0x08 << 2))
#define CTRL_INIT_BIT 0
#define CTRL_NEXT_BIT 1
#define ADDR_STATUS (SHA256_BASE + (0x09 << 2))
#define STATUS_READY_BIT 0
#define STATUS_VALID_BIT 1
#define ADDR_BLOCK0 (SHA256_BASE + (0x10 << 2))
#define ADDR_BLOCK1 (SHA256_BASE + (0x11 << 2))
#define ADDR_BLOCK2 (SHA256_BASE + (0x12 << 2))
#define ADDR_BLOCK3 (SHA256_BASE + (0x13 << 2))
#define ADDR_BLOCK4 (SHA256_BASE + (0x14 << 2))
#define ADDR_BLOCK5 (SHA256_BASE + (0x15 << 2))
#define ADDR_BLOCK6 (SHA256_BASE + (0x16 << 2))
#define ADDR_BLOCK7 (SHA256_BASE + (0x17 << 2))
#define ADDR_BLOCK8 (SHA256_BASE + (0x18 << 2))
#define ADDR_BLOCK9 (SHA256_BASE + (0x19 << 2))
#define ADDR_BLOCK10 (SHA256_BASE + (0x1a << 2))
#define ADDR_BLOCK11 (SHA256_BASE + (0x1b << 2))
#define ADDR_BLOCK12 (SHA256_BASE + (0x1c << 2))
#define ADDR_BLOCK13 (SHA256_BASE + (0x1d << 2))
#define ADDR_BLOCK14 (SHA256_BASE + (0x1e << 2))
#define ADDR_BLOCK15 (SHA256_BASE + (0x1f << 2))
#define ADDR_DIGEST0 (SHA256_BASE + (0x20 << 2))
#define ADDR_DIGEST1 (SHA256_BASE + (0x21 << 2))
#define ADDR_DIGEST2 (SHA256_BASE + (0x22 << 2))
#define ADDR_DIGEST3 (SHA256_BASE + (0x23 << 2))
#define ADDR_DIGEST4 (SHA256_BASE + (0x24 << 2))
#define ADDR_DIGEST5 (SHA256_BASE + (0x25 << 2))
#define ADDR_DIGEST6 (SHA256_BASE + (0x26 << 2))
#define ADDR_DIGEST7 (SHA256_BASE + (0x27 << 2))
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
uint32_t get_w32(uint32_t addr)
{
unsigned int read_data;
eim_read_32(addr, &read_data);
return read_data;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_single_block()
{
uint32_t write_data;
write_data = 0x61626380;
eim_write_32(ADDR_BLOCK0, &write_data);
write_data = 0x00000000;
eim_write_32(ADDR_BLOCK1, &write_data);
eim_write_32(ADDR_BLOCK2, &write_data);
eim_write_32(ADDR_BLOCK3, &write_data);
eim_write_32(ADDR_BLOCK4, &write_data);
eim_write_32(ADDR_BLOCK5, &write_data);
eim_write_32(ADDR_BLOCK6, &write_data);
eim_write_32(ADDR_BLOCK7, &write_data);
eim_write_32(ADDR_BLOCK8, &write_data);
eim_write_32(ADDR_BLOCK9, &write_data);
eim_write_32(ADDR_BLOCK10, &write_data);
eim_write_32(ADDR_BLOCK11, &write_data);
eim_write_32(ADDR_BLOCK12, &write_data);
eim_write_32(ADDR_BLOCK13, &write_data);
eim_write_32(ADDR_BLOCK14, &write_data);
write_data = 0x00000018;
eim_write_32(ADDR_BLOCK15, &write_data);
write_data = 0x00000001;
eim_write_32(ADDR_CTRL, &write_data);
printf("digest0 = 0x%08x\n", get_w32(ADDR_DIGEST0));
printf("digest1 = 0x%08x\n", get_w32(ADDR_DIGEST1));
printf("digest2 = 0x%08x\n", get_w32(ADDR_DIGEST2));
printf("digest3 = 0x%08x\n", get_w32(ADDR_DIGEST3));
printf("digest4 = 0x%08x\n", get_w32(ADDR_DIGEST4));
printf("digest5 = 0x%08x\n", get_w32(ADDR_DIGEST5));
printf("digest6 = 0x%08x\n", get_w32(ADDR_DIGEST6));
printf("digest7 = 0x%08x\n", get_w32(ADDR_DIGEST7));
// What we want to see:
// res0 = 256'hBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_dual_block()
{
// Dual block test vectors as specified by NIST.
// tc1_0 = 512'h6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F70718000000000000000;
// res1_0 = 256'h85E655D6417A17953363376A624CDE5C76E09589CAC5F811CC4B32C1F20E533A;
// tc1_1 = 512'h000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001C0;
// res1_1 = 256'h248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void test_sha256()
{
test_single_block();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int config_eim()
{
int ok;
// try to setup eim (return value should be 1)
printf("Configuring EIM .. ");
ok = eim_setup();
if (ok < 1) {
printf("ERROR\n");
return EXIT_FAILURE;
}
else {
printf("EIM Setup ok.\n");
}
return EXIT_SUCCESS;
}
//------------------------------------------------------------------------------
// main()
//------------------------------------------------------------------------------
int main()
{
config_eim();
test_sha256();
return 0;
}
//======================================================================
// EOF test-sha256.c
//======================================================================
|