mipstest.c
1.37 KB
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
#define DEV_CNSLE_TX_INTR 0x01 /* intr enable / state bits */
#define DEV_CNSLE_RX_INTR 0x02
typedef unsigned int DevRegister;
typedef struct DevConsoleRegisters {
DevRegister intr_status; /* r: intr state / w: intr enable */
DevRegister data; /* r: current char / w: send char */
} DevConsoleRegisters;
#define K1BASE (0xA0000000)
#include "sha1.h"
/*
* Define patterns for testing
*/
#define TEST1 "abc"
char *testarray = TEST1;
const char *break1 = "a";
const char *break2 = "bc";
char *resultarray = "A9 99 3E 36 47 06 81 6A BA 3E 25 71 78 50 C2 6C 9C D0 D8 9D";
uint8_t Message_Digest[20];
int main()
{
volatile DevConsoleRegisters* console =
(DevConsoleRegisters*)(K1BASE+0x01e01000);
SHA1Context sha;
int i, j, err;
//uint8_t Message_Digest[20];
char *pass = "pass\r\n";
char *fail = "fail\r\n";
char *p;
err = SHA1Reset(&sha);
if (err){
}
SHA1Input(&sha,break1,1);
SHA1Input(&sha,break2,2);
SHA1Result(&sha, Message_Digest);
err=0;
for(i=0;i<20;i++){
if(Message_Digest[i]!=resultarray[i]){
err=1;
break;
}
}
if(err){
for(p = fail; *p; p++) {
console->data = *p;
}
}
else{
for(p = pass; *p; p++) {
console->data = *p;
}
}
for(;;) ;
}