- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libsys.h"
|
||||
|
||||
#include "rmd160.h"
|
||||
|
||||
#ifndef RMDsize
|
||||
#define RMDsize 160
|
||||
#endif
|
||||
|
||||
byte *RMD(byte *message)
|
||||
/*
|
||||
* returns RMD(message)
|
||||
* message should be a string terminated by '\0'
|
||||
*/
|
||||
{
|
||||
dword MDbuf[RMDsize/32]; /* contains (A, B, C, D(, E)) */
|
||||
static byte hashcode[RMDsize/8]; /* for final hash-value */
|
||||
dword X[16]; /* current 16-word chunk */
|
||||
unsigned int i; /* counter */
|
||||
dword length; /* length in bytes of message */
|
||||
dword nbytes; /* # of bytes not yet processed */
|
||||
|
||||
/* initialize */
|
||||
MDinit(MDbuf);
|
||||
length = (dword)strlen((char *)message);
|
||||
|
||||
/* process message in 16-word chunks */
|
||||
for (nbytes=length; nbytes > 63; nbytes-=64) {
|
||||
for (i=0; i<16; i++) {
|
||||
X[i] = BYTES_TO_DWORD(message);
|
||||
message += 4;
|
||||
}
|
||||
compress(MDbuf, X);
|
||||
} /* length mod 64 bytes left */
|
||||
|
||||
/* finish: */
|
||||
MDfinish(MDbuf, message, length, 0);
|
||||
|
||||
for (i=0; i<RMDsize/8; i+=4) {
|
||||
hashcode[i] = MDbuf[i>>2]; /* implicit cast to byte */
|
||||
hashcode[i+1] = (MDbuf[i>>2] >> 8); /* extracts the 8 least */
|
||||
hashcode[i+2] = (MDbuf[i>>2] >> 16); /* significant bits. */
|
||||
hashcode[i+3] = (MDbuf[i>>2] >> 24);
|
||||
}
|
||||
|
||||
return (byte *)hashcode;
|
||||
}
|
||||
|
||||
#define MSG_SIZE (1*1024*1024) // Bit
|
||||
#define TIME_STEP 2
|
||||
|
||||
char msg[MSG_SIZE/8+1];
|
||||
byte hashref[] = {0xFC,0x20,0x7B,0x84,0x40,0x1C,0x49,0x0B,0x8D,0x69,0x88,0xD2,0x49,0x20,0x01,0x90,0x41,0x77,0x72,0x59};
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int result, i, j, cnt;
|
||||
byte *hashcode;
|
||||
UINT32 start, stop;
|
||||
|
||||
for (i=0; i < MSG_SIZE/8; i++)
|
||||
msg[i] = 0x55;
|
||||
|
||||
msg[i] = 0;
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
cnt = 0;
|
||||
while(1)
|
||||
{
|
||||
while (start == time(NULL));
|
||||
|
||||
start = time(NULL);
|
||||
stop = start + TIME_STEP;
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
hashcode = RMD((byte *)msg);
|
||||
cnt++;
|
||||
|
||||
if (memcmp(hashcode, hashref, sizeof(hashref)))
|
||||
{
|
||||
printf("Error RipeMD-160!\n");
|
||||
printf("Hash expected: ");
|
||||
for (i=0; i<sizeof(hashref); i++)
|
||||
printf("%2.2X", hashref[i]);
|
||||
|
||||
printf("\n");
|
||||
printf("Hash computed: ");
|
||||
for (i=0; i<sizeof(hashref); i++)
|
||||
printf("%2.2X", hashcode[i]);
|
||||
|
||||
printf("\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (time(NULL) == stop)
|
||||
{
|
||||
for (i=0; i<sizeof(hashref); i++)
|
||||
printf("%2.2X", hashcode[i]);
|
||||
printf("\n%d Hashes/s of %d Mbit message in %2d s => %d Mbit/s\n\n", cnt, MSG_SIZE/(1024*1024), TIME_STEP, cnt*MSG_SIZE/(1024*1024)/TIME_STEP);
|
||||
cnt = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user