Created
August 6, 2013 10:22
-
-
Save MarkJr94/6163389 to your computer and use it in GitHub Desktop.
Keccak test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STATUS_CODES | |
genShortMsg(int hashbitlen) | |
{ | |
char fn[32], line[SUBMITTER_INFO_LEN]; | |
int msglen, msgbytelen, done; | |
BitSequence Msg[256], MD[64]; | |
FILE *fp_in, *fp_out; | |
if ( (fp_in = fopen("ShortMsgKAT.txt", "r")) == NULL ) { | |
printf("Couldn't open <ShortMsgKAT.txt> for read\n"); | |
return KAT_FILE_OPEN_ERROR; | |
} | |
sprintf(fn, "ShortMsgKAT_%d.txt", hashbitlen); | |
if ( (fp_out = fopen(fn, "w")) == NULL ) { | |
printf("Couldn't open <%s> for write\n", fn); | |
return KAT_FILE_OPEN_ERROR; | |
} | |
fprintf(fp_out, "# %s\n", fn); | |
if ( FindMarker(fp_in, "# Algorithm Name:") ) { | |
fscanf(fp_in, "%[^\n]\n", line); | |
fprintf(fp_out, "# Algorithm Name:%s\n", line); | |
} | |
else { | |
printf("genShortMsg: Couldn't read Algorithm Name\n"); | |
return KAT_HEADER_ERROR; | |
} | |
if ( FindMarker(fp_in, "# Principal Submitter:") ) { | |
fscanf(fp_in, "%[^\n]\n", line); | |
fprintf(fp_out, "# Principal Submitter:%s\n", line); | |
} | |
else { | |
printf("genShortMsg: Couldn't read Principal Submitter\n"); | |
return KAT_HEADER_ERROR; | |
} | |
done = 0; | |
do { | |
if ( FindMarker(fp_in, "Len = ") ) | |
fscanf(fp_in, "%d", &msglen); | |
else { | |
done = 1; | |
break; | |
} | |
msgbytelen = (msglen+7)/8; | |
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) { | |
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n"); | |
return KAT_DATA_ERROR; | |
} | |
Hash(hashbitlen, Msg, msglen, MD); | |
fprintf(fp_out, "\nLen = %d\n", msglen); | |
fprintBstr(fp_out, "Msg = ", Msg, msgbytelen); | |
fprintBstr(fp_out, "MD = ", MD, hashbitlen/8); | |
} while ( !done ); | |
printf("finished ShortMsgKAT for <%d>\n", hashbitlen); | |
fclose(fp_in); | |
fclose(fp_out); | |
return KAT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment