- Timestamp:
- Oct 31, 2013, 11:31:47 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cutest_sh_tiger0.c
r248 r444 8 8 9 9 #include "sh_tiger.h" 10 #include "sh_checksum.h" 10 11 11 12 #if defined(HAVE_PTHREAD) && defined(SH_STEALTH) … … 135 136 char * expected; 136 137 char hashbuf[KEYBUF_SIZE]; 138 char hexdigest[SHA256_DIGEST_STRING_LENGTH]; 137 139 UINT64 length; 138 140 … … 197 199 actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf)); 198 200 expected = "2FE65D1D995B8F8BC8B13F798C07E7E935A787ED00000000"; 201 CuAssertStrEquals(tc, expected, actual); 202 203 result = sl_close(rval_open); 204 CuAssertTrue(tc, result == 0); 205 206 result = sh_tiger_hashtype("SHA256"); 207 CuAssertTrue(tc, result == 0); 208 209 rval_open = sl_open_fastread (__FILE__, __LINE__, "cutest_foo", SL_YESPRIV); 210 CuAssertTrue(tc, rval_open >= 0); 211 212 /* same result as gpg --print-md SHA256 213 */ 214 length = TIGER_NOLIM; 215 { 216 char * tmp = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf)); 217 actual = SHA256_Base2Hex(tmp, hexdigest); 218 } 219 expected = "235790848f95e96b2c627f1bf58a2b8c05c535ada8c0a3326aac34ce1391ad40"; 199 220 CuAssertStrEquals(tc, expected, actual); 200 221 -
trunk/src/cutest_sh_utils.c
r167 r444 139 139 140 140 ret = sh_util_base64_enc (out, inp0, strlen((char*)inp0)); 141 CuAssertIntEquals(tc, ret, 0);141 CuAssertIntEquals(tc, 0, ret); 142 142 CuAssertStrEquals(tc, "", (char*)out); 143 143 ret = sh_util_base64_dec (ou2, out, strlen((char*)out)); -
trunk/src/sh_error.c
r440 r444 867 867 } 868 868 #endif 869 869 870 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE) 871 #include "sh_checksum.h" 872 static char * sh_error_replace(const char * msg) 873 { 874 char * ret = NULL; 875 876 if (sh_tiger_get_hashtype () == SH_SHA256) 877 { 878 char * store = NULL; 879 880 #ifdef SH_USE_XML 881 char c_end = '"'; 882 char * str = _("chksum_old=\""); 883 char * str2 = _("chksum_new=\""); 884 #else 885 char c_end = '>'; 886 char * str = _("chksum_old=<"); 887 char * str2 = _("chksum_new=<"); 888 #endif 889 890 ret = SHA256_ReplaceBaseByHex(msg, str, c_end); 891 892 if (ret) { 893 store = ret; 894 ret = SHA256_ReplaceBaseByHex(ret, str2, c_end); 895 if (ret) 896 SH_FREE(store); 897 else 898 ret = store; 899 } else { 900 ret = SHA256_ReplaceBaseByHex(msg, str2, c_end); 901 } 902 } 903 return ret; 904 } 905 static void sh_replace_free(char * msg) 906 { 907 if (msg) 908 SH_FREE(msg); 909 return; 910 } 911 #else 912 static char * sh_error_replace(const char * msg) { (void) msg; return NULL; } 913 static void sh_replace_free(char * msg) { (void) msg; return; } 914 #endif 870 915 871 916 /********************************************************** … … 910 955 #endif 911 956 957 char * hexmsg = NULL; 958 912 959 static int own_block = 0; 913 960 … … 1083 1130 own_block = 0; 1084 1131 1132 hexmsg = sh_error_replace(lmsg->msg); 1085 1133 1086 1134 /* Log to stderr. … … 1103 1151 * Reports first error after failure. Always tries. 1104 1152 */ 1105 (void) sh_log_console ( lmsg->msg);1153 (void) sh_log_console (hexmsg ? hexmsg : lmsg->msg); 1106 1154 print_block = 0; 1107 1155 } … … 1131 1179 * Ignores errors. Always tries. 1132 1180 */ 1133 (void) sh_log_syslog (lmsg->severity, lmsg->msg);1181 (void) sh_log_syslog (lmsg->severity, hexmsg ? hexmsg : lmsg->msg); 1134 1182 syslog_block = 0; 1135 1183 } … … 1153 1201 * Reports first error after failure. Always tries. 1154 1202 */ 1155 (void) sh_ext_execute ('l', 'o', 'g', lmsg->msg, 0);1203 (void) sh_ext_execute ('l', 'o', 'g', hexmsg ? hexmsg : lmsg->msg, 0); 1156 1204 external_block = 0; 1157 1205 } … … 1270 1318 BREAKEXIT(sh_nmail_msg); 1271 1319 if ( (severity & SH_ERR_FATAL) == 0) 1272 retval = sh_nmail_pushstack (severity, lmsg->msg, NULL);1320 retval = sh_nmail_pushstack (severity, hexmsg ? hexmsg : lmsg->msg, NULL); 1273 1321 else 1274 retval = sh_nmail_msg (severity, lmsg->msg, NULL);1322 retval = sh_nmail_msg (severity, hexmsg ? hexmsg : lmsg->msg, NULL); 1275 1323 1276 1324 mail_block = 0; … … 1306 1354 #if defined(HAVE_LIBPRELUDE) && defined(SH_WITH_SERVER) 1307 1355 (void) sh_prelude_alert (severity, (int) class, 1308 lmsg->msg, lmsg->status, msg_id,1356 hexmsg ? hexmsg : lmsg->msg, lmsg->status, msg_id, 1309 1357 local_inet_peer_ip); 1310 1358 #else 1311 1359 (void) sh_prelude_alert (severity, (int) class, 1312 lmsg->msg, lmsg->status, msg_id,1360 hexmsg ? hexmsg : lmsg->msg, lmsg->status, msg_id, 1313 1361 NULL); 1314 1362 #endif … … 1351 1399 } 1352 1400 #else 1353 (void) sh_log_file ( lmsg->msg, NULL);1401 (void) sh_log_file (hexmsg ? hexmsg : lmsg->msg, NULL); 1354 1402 #endif 1355 1403 /* sh_log_file (lmsg->msg); */ … … 1366 1414 if (lmsg->msg) 1367 1415 SH_FREE( lmsg->msg ); 1416 sh_replace_free(hexmsg); 1368 1417 1369 1418 memset ( lmsg, (int) '\0', sizeof(struct _log_t) ); -
trunk/src/sh_hash.c
r425 r444 34 34 #include <sys/stat.h> 35 35 #include <unistd.h> 36 #include <ctype.h> 36 37 37 38 #ifdef MAJOR_IN_MKDEV … … 3973 3974 } 3974 3975 3975 3976 int isHexKey(char * s) 3977 { 3978 int i; 3979 3980 for (i = 0; i < KEY_LEN; ++i) 3981 { 3982 if (*s) 3983 { 3984 if ((*s >= '0' && *s <= '9') || 3985 (*s >= 'A' && *s <= 'F') || 3986 (*s >= 'a' && *s <= 'f')) 3987 { 3988 ++s; 3989 continue; 3990 } 3991 } 3992 return S_FALSE; 3993 } 3994 return S_TRUE; 3995 } 3976 3996 3997 #include "sh_checksum.h" 3998 3999 static char * KEYBUFtolower (char * s, char * result) 4000 { 4001 char * r = result; 4002 if (s) 4003 { 4004 for (; *s; ++s) 4005 { 4006 *r = tolower((unsigned char) *s); ++r; 4007 } 4008 *r = '\0'; 4009 } 4010 return result; 4011 } 4012 3977 4013 void sh_hash_list_db_entry_full_detail (sh_file_t * p) 3978 4014 { … … 3980 4016 char * esc; 3981 4017 char str[81]; 4018 char hexdigest[SHA256_DIGEST_STRING_LENGTH]; 4019 char keybuffer[KEYBUF_SIZE]; 3982 4020 3983 4021 if (ListWithDelimiter == S_TRUE) … … 4020 4058 if (ListWithDelimiter == S_TRUE) 4021 4059 putchar(','); 4022 printf( _(" %s"), p->theFile.checksum); 4060 4061 if (isHexKey(p->theFile.checksum)) 4062 printf( _(" %s"), KEYBUFtolower(p->theFile.checksum, keybuffer)); 4063 else 4064 printf( _(" %s"), SHA256_Base2Hex(p->theFile.checksum, hexdigest)); 4023 4065 if (ListWithDelimiter == S_TRUE) 4024 4066 putchar(','); -
trunk/src/sh_tiger0.c
r440 r444 1386 1386 /*@+type@*/ 1387 1387 1388 #include "sh_checksum.h" 1389 1390 #define SH_VAR_SHA1 0 1391 #define SH_VAR_SHA256 1 1392 1388 1393 /* Compute SHA1 message digest for bytes read from STREAM. The 1389 1394 resulting message digest number will be written into the 16 bytes 1390 1395 beginning at RESBLOCK. */ 1391 static int sha1_stream(char * filename, void *resblock,1392 UINT64 * Length, int timeout, SL_TICKET fd)1396 static int SHA_stream(char * filename, void *resblock, 1397 UINT64 * Length, int timeout, SL_TICKET fd, int variant) 1393 1398 { 1394 1399 /* Important: BLOCKSIZE must be a multiple of 64. */ 1395 1400 static const int BLOCKSIZE = 4096; 1396 1401 struct sha_ctx ctx; 1402 SHA256_CTX ctx_sha2; 1397 1403 char * buffer = SH_ALLOC(4168); /* BLOCKSIZE + 72 AIX compiler chokes */ 1398 1404 off_t sum = 0; … … 1410 1416 1411 1417 /* Initialize the computation context. */ 1412 (void) sha_init(&ctx); 1418 if (variant == SH_VAR_SHA256) 1419 (void) SHA256_Init(&ctx_sha2); 1420 else 1421 (void) sha_init(&ctx); 1413 1422 1414 1423 if (SL_ISERROR (fd)) … … 1506 1515 BLOCKSIZE % 64 == 0 1507 1516 */ 1508 sha_update(&ctx, (sha_word8*) buffer, (sha_word32) BLOCKSIZE); 1517 if (variant == SH_VAR_SHA256) 1518 SHA256_Update(&ctx_sha2, (sha2_byte*) buffer, (size_t) BLOCKSIZE); 1519 else 1520 sha_update(&ctx, (sha_word8*) buffer, (sha_word32) BLOCKSIZE); 1509 1521 sh.statistics.bytes_hashed += BLOCKSIZE; 1510 1522 … … 1528 1540 if (sum > 0) 1529 1541 { 1530 sha_update(&ctx, (sha_word8*) buffer, (sha_word32) sum); 1542 if (variant == SH_VAR_SHA256) 1543 SHA256_Update(&ctx_sha2, (sha2_byte*) buffer, (size_t) sum); 1544 else 1545 sha_update(&ctx, (sha_word8*) buffer, (sha_word32) sum); 1531 1546 sh.statistics.bytes_hashed += sum; 1532 1547 } 1533 1548 1534 sha_final (&ctx);1535 1536 1549 /* Construct result in desired memory. */ 1537 sha_digest (&ctx, resblock); 1550 if (variant == SH_VAR_SHA256) 1551 { 1552 SHA256_End(&ctx_sha2, resblock); 1553 } 1554 else 1555 { 1556 sha_final (&ctx); 1557 sha_digest (&ctx, resblock); 1558 } 1559 1538 1560 *Length = bcount; 1539 1561 SH_FREE(buffer); … … 1550 1572 unsigned char sha1buffer[20]; 1551 1573 1552 (void) sha1_stream (filename, sha1buffer, Length, timeout, what);1574 (void) SHA_stream (filename, sha1buffer, Length, timeout, what, SH_VAR_SHA1); 1553 1575 1554 1576 /*@-bufferoverflowhigh -usedef@*/ … … 1565 1587 } 1566 1588 1589 static char * sh_tiger_sha256_hash (char * filename, TigerType what, 1590 UINT64 * Length, int timeout, 1591 char * out, size_t len) 1592 { 1593 char outbuf[KEYBUF_SIZE]; 1594 1595 (void) SHA_stream (filename, outbuf, Length, timeout, what, SH_VAR_SHA256); 1596 1597 sl_strlcpy(out, outbuf, len); 1598 return out; 1599 } 1600 1567 1601 /* ifdef USE_SHA1 */ 1568 1602 #endif 1569 1603 1570 static int hash_type = 0;1604 static int hash_type = SH_TIGER192; 1571 1605 1572 1606 int sh_tiger_get_hashtype () … … 1585 1619 1586 1620 if (0 == strcmp(c, _("TIGER192"))) 1587 hash_type = 0;1621 hash_type = SH_TIGER192; 1588 1622 #ifdef USE_SHA1 1589 1623 else if (0 == strcmp(c, _("SHA1"))) 1590 hash_type = 1;1624 hash_type = SH_SHA1; 1591 1625 #endif 1592 1626 #ifdef USE_MD5 1593 1627 else if (0 == strcmp(c, _("MD5"))) 1594 hash_type = 2; 1628 hash_type = SH_MD5; 1629 #endif 1630 #ifdef USE_SHA1 1631 else if (0 == strcmp(c, _("SHA256"))) 1632 hash_type = SH_SHA256; 1595 1633 #endif 1596 1634 else … … 1618 1656 { 1619 1657 #ifdef USE_SHA1 1620 if (hash_type == 1)1658 if (hash_type == SH_SHA1) 1621 1659 return sh_tiger_sha1_hash (filename, what, Length, timeout, out, len); 1622 1660 #endif 1623 1661 #ifdef USE_MD5 1624 if (hash_type == 2)1662 if (hash_type == SH_MD5) 1625 1663 return sh_tiger_md5_hash (filename, what, Length, timeout, out, len); 1664 #endif 1665 #ifdef USE_SHA1 1666 if (hash_type == SH_SHA256) 1667 return sh_tiger_sha256_hash (filename, what, Length, timeout, out, len); 1626 1668 #endif 1627 1669 return sh_tiger_hash_internal (filename, what, Length, timeout, out, len); -
trunk/src/sh_utils.c
r382 r444 2239 2239 if (bto64[0] != '\0') 2240 2240 { 2241 if (instr && *instr)2241 if (instr /* && *instr *//* need to handle binary data */) 2242 2242 { 2243 2243 if (lin == 0) 2244 2244 lin = strlen((const char *)instr); 2245 2245 2246 do { 2247 ll = 0; 2248 2249 if (len < lin) 2250 { a = *instr; ++instr; ++len; ++ll; } 2251 else 2252 { a = 0; } 2253 if (len < lin) 2254 { b = *instr; ++instr; ++len; ++ll; } 2255 else 2256 { b = 0; } 2257 if (len < lin) 2258 { c = *instr; ++instr; ++len; ++ll; } 2259 else 2260 { c = 0; } 2261 2262 *out = bto64[ a >> 2 ]; 2263 ++j; ++out; 2264 *out = bto64[ ((a & 0x03) << 4) | ((b & 0xf0) >> 4) ]; 2265 ++j; ++out; 2266 *out = (unsigned char) (ll > 1 ? bto64[ ((b & 0x0f) << 2) | ((c & 0xc0) >> 6) ] : '?'); 2267 ++j; ++out; 2268 *out = (unsigned char) (ll > 2 ? bto64[ c & 0x3f ] : '?'); 2269 ++j; ++out; 2270 } while (len < lin); 2246 if (lin > 0) 2247 { 2248 do { 2249 ll = 0; 2250 2251 if (len < lin) 2252 { a = *instr; ++instr; ++len; ++ll; } 2253 else 2254 { a = 0; } 2255 if (len < lin) 2256 { b = *instr; ++instr; ++len; ++ll; } 2257 else 2258 { b = 0; } 2259 if (len < lin) 2260 { c = *instr; ++instr; ++len; ++ll; } 2261 else 2262 { c = 0; } 2263 2264 *out = bto64[ a >> 2 ]; 2265 ++j; ++out; 2266 *out = bto64[ ((a & 0x03) << 4) | ((b & 0xf0) >> 4) ]; 2267 ++j; ++out; 2268 *out = (unsigned char) (ll > 1 ? bto64[ ((b & 0x0f) << 2) | ((c & 0xc0) >> 6) ] : '?'); 2269 ++j; ++out; 2270 *out = (unsigned char) (ll > 2 ? bto64[ c & 0x3f ] : '?'); 2271 ++j; ++out; 2272 } while (len < lin); 2273 } 2271 2274 } 2272 2275 *out = '\0';
Note:
See TracChangeset
for help on using the changeset viewer.