[ESRG-CVS] sfesrg/esrgpcpj/gfsw gfsw.c,1.27,1.28
Brought to you by:
dtashley
|
From: David T. A. <dta...@us...> - 2009-11-28 02:00:17
|
Update of /cvsroot/esrg/sfesrg/esrgpcpj/gfsw In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16234 Modified Files: gfsw.c Log Message: SHA-512 function calls added. Index: gfsw.c =================================================================== RCS file: /cvsroot/esrg/sfesrg/esrgpcpj/gfsw/gfsw.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** gfsw.c 28 Nov 2009 00:09:41 -0000 1.27 --- gfsw.c 28 Nov 2009 02:00:09 -0000 1.28 *************** *** 89,93 **** //is actually dead. ! static char GFSW_szAppName[] = "GFSW"; //The application name. --- 89,93 ---- //is actually dead. ! static char GFSW_szAppName[] = "FileHash"; //The application name. *************** *** 144,156 **** volatile unsigned __int64 file_size; //The number of bytes in the file. ! volatile int crc32_valid; //TRUE if the CRC32 has been assigned, or an attempt was made to assign it. This //means the child has filled in the string. volatile char crc32[100]; //A string representation of the CRC-32, or else an error message from the child. ! volatile int md5_valid; //TRUE if the md5 is valid or an attempt was made. volatile char md5[100]; //A string representation of the MD5 or else an error message from the child. }; --- 144,160 ---- volatile unsigned __int64 file_size; //The number of bytes in the file. ! volatile int crc32_valid; //TRUE if the CRC32 has been assigned, or an attempt was made to assign it. This //means the child has filled in the string. volatile char crc32[100]; //A string representation of the CRC-32, or else an error message from the child. ! volatile int md5_valid; //TRUE if the md5 is valid or an attempt was made. volatile char md5[100]; //A string representation of the MD5 or else an error message from the child. + volatile int sha512_valid; + //TRUE if the SHA512 is valid or an attempt was made. + volatile char sha512[200]; + //A string representation of the SHA512 or else an error message from the child. }; *************** *** 377,381 **** int len; int i; ! char buf[2*MAX_PATH+100]; //Count the number of files queued, and put that in the buffer. --- 381,385 ---- int len; int i; ! char buf[2*MAX_PATH+200]; //Count the number of files queued, and put that in the buffer. *************** *** 490,495 **** } } - } } else --- 494,510 ---- } } + //Now, the SHA512. + if (GFSW_file_info.file_info[i].sha512_valid) + { + sprintf_s(buf, sizeof(buf), "\tSHA-512:\t%s\x0d\x0a", GFSW_file_info.file_info[i].sha512); + len = strlen(buf); + if ((len + dispbufidx + 2) < GFSW_DISPBUFLEN) + { + strcpy_s(GFSW_dispbuf+dispbufidx, sizeof(GFSW_dispbuf)-dispbufidx, buf); + dispbufidx += len; + } + } + } } else *************** *** 912,915 **** --- 927,932 ---- struct ESRG_MD5_Md5StateStruct md5s; struct ESRG_MD5_Md5ResultStruct md5r; + struct ESRG_SHA512_Sha512StateStruct sha512s; + struct ESRG_SHA512_Sha512ResultStruct sha512r; int exit_flag = 0; DWORD bytes_read = 0; *************** *** 1039,1043 **** /********************************************************************************/ /********************************************************************************/ ! /******* F I L E C R C - 3 2 A N D M D - 5 ***************************/ /********************************************************************************/ /********************************************************************************/ --- 1056,1060 ---- /********************************************************************************/ /********************************************************************************/ ! /******* F I L E C R C - 3 2, M D - 5, A N D S H A - 5 1 2 *******/ /********************************************************************************/ /********************************************************************************/ *************** *** 1045,1057 **** { //File handle signals an error condition. We cannot ! //even read the file for CRC-32 and MD5. Just set info //and boogie. ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "INVALID FILE HANDLE"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "INVALID FILE HANDLE"); } else { //This is the meat of the matter where we read the file contents and do ! //the CRC-32 calculations. The assumption made is the the buffer size //will be somewhere in the range of 16K-1M, so that the time to process //that much data is fairly small. This should be enough granularity --- 1062,1075 ---- { //File handle signals an error condition. We cannot ! //even read the file for CRC-32, MD-5, and SHA-512. Just set info //and boogie. ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "INVALID FILE HANDLE"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "INVALID FILE HANDLE"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].sha512, sizeof(GFSW_file_info.file_info[fidx].sha512), "INVALID FILE HANDLE"); } else { //This is the meat of the matter where we read the file contents and do ! //the hash calculations. The assumption made is the the buffer size //will be somewhere in the range of 16K-1M, so that the time to process //that much data is fairly small. This should be enough granularity *************** *** 1062,1067 **** if (rc == 0xFFFFFFFF) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "FILE SEEK ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "FILE SEEK ERROR"); goto file_read_loop_endpoint; } --- 1080,1086 ---- if (rc == 0xFFFFFFFF) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "FILE SEEK ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "FILE SEEK ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].sha512, sizeof(GFSW_file_info.file_info[fidx].sha512), "FILE SEEK ERROR"); goto file_read_loop_endpoint; } *************** *** 1070,1073 **** --- 1089,1093 ---- CRCHASHFUNCS_Crc32StateStructOpen(&crc32s); ESRG_MD5_Md5StateStructOpen(&md5s); + ESRG_SHA512_Sha512StateStructOpen(&sha512s); //Iterate through, reading the file and processing the blocks. In the case *************** *** 1082,1087 **** if (bytes_read) { ! CRCHASHFUNCS_Crc32StateStructAddData(&crc32s, GFSW_file_read_buf, bytes_read); ! ESRG_MD5_Md5StateStructAddData(&md5s, GFSW_file_read_buf, bytes_read); } --- 1102,1108 ---- if (bytes_read) { ! CRCHASHFUNCS_Crc32StateStructAddData(&crc32s, GFSW_file_read_buf, bytes_read); ! ESRG_MD5_Md5StateStructAddData (&md5s, GFSW_file_read_buf, bytes_read); ! ESRG_SHA512_Sha512StateStructAddData(&sha512s, GFSW_file_read_buf, bytes_read); } *************** *** 1089,1094 **** if (!rv) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "FILE READ ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "FILE READ ERROR"); goto file_read_loop_endpoint; } --- 1110,1116 ---- if (!rv) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "FILE READ ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "FILE READ ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].sha512, sizeof(GFSW_file_info.file_info[fidx].sha512), "FILE READ ERROR"); goto file_read_loop_endpoint; } *************** *** 1101,1106 **** else if (GFSW_thread_abort_request) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "OPERATION ABORTED"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "OPERATION ABORTED"); goto file_read_loop_endpoint; } --- 1123,1129 ---- else if (GFSW_thread_abort_request) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "OPERATION ABORTED"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "OPERATION ABORTED"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].sha512, sizeof(GFSW_file_info.file_info[fidx].sha512), "OPERATION ABORTED"); goto file_read_loop_endpoint; } *************** *** 1116,1124 **** ESRG_MD5_Md5StateStructClose(&md5s, &md5r); //Form up a CRC-32 string. sprintf_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "%8.8X", crc32); //Form up an MD-5 string. ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), md5r.md5_chars); //Report progress to parent thread. --- 1139,1153 ---- ESRG_MD5_Md5StateStructClose(&md5s, &md5r); + //Close up the SHA-512 structure. + ESRG_SHA512_Sha512StateStructClose(&sha512s, &sha512r); + //Form up a CRC-32 string. sprintf_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "%8.8X", crc32); //Form up an MD-5 string. ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), md5r.md5_chars); ! ! //Form up an SHA-512 string. ! strcpy_s((char *)GFSW_file_info.file_info[fidx].sha512, sizeof(GFSW_file_info.file_info[fidx].sha512), sha512r.sha512_chars); //Report progress to parent thread. *************** *** 1135,1140 **** //In any case both CRC32 and MD5 info filled in. ! GFSW_file_info.file_info[fidx].crc32_valid = 1; ! GFSW_file_info.file_info[fidx].md5_valid = 1; //If the file handle is valid (i.e. we opened the file) we must --- 1164,1170 ---- //In any case both CRC32 and MD5 info filled in. ! GFSW_file_info.file_info[fidx].crc32_valid = 1; ! GFSW_file_info.file_info[fidx].md5_valid = 1; ! GFSW_file_info.file_info[fidx].sha512_valid = 1; //If the file handle is valid (i.e. we opened the file) we must *************** *** 1148,1153 **** if (!close_result) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "FILE HANDLE CLOSE ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "FILE HANDLE CLOSE ERROR"); } } --- 1178,1184 ---- if (!close_result) { ! strcpy_s((char *)GFSW_file_info.file_info[fidx].crc32, sizeof(GFSW_file_info.file_info[fidx].crc32), "FILE HANDLE CLOSE ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].md5, sizeof(GFSW_file_info.file_info[fidx].md5), "FILE HANDLE CLOSE ERROR"); ! strcpy_s((char *)GFSW_file_info.file_info[fidx].sha512, sizeof(GFSW_file_info.file_info[fidx].sha512), "FILE HANDLE CLOSE ERROR"); } } *************** *** 1251,1254 **** --- 1282,1288 ---- /****************************************************************************** ** $Log$ + ** Revision 1.28 2009/11/28 02:00:09 dtashley + ** SHA-512 function calls added. + ** ** Revision 1.27 2009/11/28 00:09:41 dtashley ** Addition of SHA512 module. |