mipstest.c 1.37 KB
#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(;;) ;
}