Changeset 133 for trunk/src/sh_tiger0.c
- Timestamp:
- Oct 25, 2007, 12:19:05 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_tiger0.c
r131 r133 99 99 * implementation 100 100 */ 101 SL_TICKET tiger_fd = (-1);102 101 103 102 static sh_byte buffer[PRIV_MAX + 72]; … … 106 105 static 107 106 word64 * sh_tiger_hash_val (const char * filename, TigerType what, 108 UINT64 Length, int timeout )107 UINT64 Length, int timeout, word64 * res) 109 108 #else 110 109 static 111 110 sh_word32 * sh_tiger_hash_val (const char * filename, TigerType what, 112 UINT64 Length, int timeout )111 UINT64 Length, int timeout, sh_word32 * res) 113 112 #endif 114 113 { … … 138 137 #if defined(TIGER_64_BIT) 139 138 #define TIGER_CAST (word64*) 140 static word64 res[3];139 /* word64 res[3]; */ 141 140 res[0]= (word64) 0x0123456789ABCDEFLL; 142 141 res[1]= (word64) 0xFEDCBA9876543210LL; … … 144 143 #else 145 144 #define TIGER_CAST (sh_word32*) 146 static sh_word32 res[6];145 /* sh_word32 res[6]; */ 147 146 res[0]= (sh_word32) 0x89ABCDEF; 148 147 res[1]= (sh_word32) 0x01234567; … … 155 154 SL_ENTER(_("sh_tiger_hash_val")); 156 155 157 if (what == TIGER_FD || what == TIGER_FILE)156 if (what >= TIGER_FILE) 158 157 { 159 if (what ==TIGER_FD)158 if (what > TIGER_FD) 160 159 { 161 fd = tiger_fd;162 TPT((0,FIL__, __LINE__, _("msg=<TIGER_FD>, fd=<%ld>\n"), tiger_fd));160 fd = what; 161 TPT((0,FIL__, __LINE__, _("msg=<TIGER_FD>, fd=<%ld>\n"), fd)); 163 162 } 164 163 else … … 171 170 if (SL_ISERROR (fd)) 172 171 { 173 TPT((0, FIL__, __LINE__, _("msg=<SL_ISERROR (%ld)>\n"), tiger_fd));172 TPT((0, FIL__, __LINE__, _("msg=<SL_ISERROR (%ld)>\n"), fd)); 174 173 tmp = sh_util_safe_name (filename); 175 174 (void) sl_get_euid(&euid); … … 179 178 SL_RETURN( NULL, _("sh_tiger_hash_val")); 180 179 } 181 180 181 SH_MUTEX_LOCK(mutex_skey); 182 182 #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK) 183 183 if ((lockflag == SL_FALSE) && (skey->mlock_failed == SL_FALSE)) … … 196 196 } 197 197 #endif 198 SH_MUTEX_UNLOCK(mutex_skey); 198 199 199 200 #ifdef TIGER_DBG … … 254 255 255 256 nblocks += blk; 257 /* MAY_LOCK */ 256 258 sh.statistics.bytes_hashed += tt; 257 259 … … 331 333 bbuf[j++] = (sh_byte) 0; 332 334 tiger_t(TIGER_CAST bbuf, 64, res); 335 /* MAY_LOCK */ 333 336 sh.statistics.bytes_hashed += 64; 334 337 ++nblocks; ncount = 0; … … 361 364 if (what == TIGER_FILE) 362 365 (void) sl_close (fd); 363 else364 tiger_fd = (-1);365 366 366 367 SL_RETURN( res, _("sh_tiger_hash_val")); … … 807 808 beginning at RESBLOCK. */ 808 809 static int md5_stream(char * filename, void *resblock, 809 UINT64 Length, int timeout )810 UINT64 Length, int timeout, SL_TICKET fd) 810 811 { 811 812 /* Important: BLOCKSIZE must be a multiple of 64. */ … … 830 831 (void) md5Reset (&ctx); 831 832 832 fd = tiger_fd;833 834 833 if (SL_ISERROR (fd)) 835 834 { 836 TPT((0, FIL__, __LINE__, _("msg=<SL_ISERROR (%ld)>\n"), tiger_fd));835 TPT((0, FIL__, __LINE__, _("msg=<SL_ISERROR (%ld)>\n"), fd)); 837 836 tmp = sh_util_safe_name (filename); 838 837 (void) sl_get_euid(&euid); … … 932 931 static 933 932 char * sh_tiger_md5_hash (char * filename, TigerType what, 934 UINT64 Length, int timeout )933 UINT64 Length, int timeout, char * out, size_t len) 935 934 { 936 935 int cnt; 937 static char out[KEY_LEN+1];936 char outbuf[KEY_LEN+1]; 938 937 unsigned char md5buffer[16]; 939 938 940 if (what != TIGER_FD) 941 { 942 sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, 0, 943 MSG_E_SUBGEN, _("Not TIGER_FD"), 944 _("sh_tiger_md5_hash")); 945 out[0] = '\0'; 946 return out; 947 } 948 949 (void) md5_stream (filename, md5buffer, Length, timeout); 939 (void) md5_stream (filename, md5buffer, Length, timeout, what); 950 940 951 941 /*@-bufferoverflowhigh -usedef@*/ 952 942 for (cnt = 0; cnt < 16; ++cnt) 953 sprintf (&out [cnt*2], _("%02X"), /* known to fit */943 sprintf (&outbuf[cnt*2], _("%02X"), /* known to fit */ 954 944 (unsigned int) md5buffer[cnt]); 955 945 /*@+bufferoverflowhigh +usedef@*/ 956 946 for (cnt = 32; cnt < KEY_LEN; ++cnt) 957 out[cnt] = '0'; 958 out[KEY_LEN] = '\0'; 959 947 outbuf[cnt] = '0'; 948 outbuf[KEY_LEN] = '\0'; 949 950 sl_strlcpy(out, outbuf, len); 960 951 return out; 961 952 } … … 1328 1319 beginning at RESBLOCK. */ 1329 1320 static int sha1_stream(char * filename, void *resblock, 1330 UINT64 Length, int timeout )1321 UINT64 Length, int timeout, SL_TICKET fd) 1331 1322 { 1332 1323 /* Important: BLOCKSIZE must be a multiple of 64. */ … … 1350 1341 (void) sha_init(&ctx); 1351 1342 1352 fd = tiger_fd;1353 1354 1343 if (SL_ISERROR (fd)) 1355 1344 { 1356 TPT((0, FIL__, __LINE__, _("msg=<SL_ISERROR (%ld)>\n"), tiger_fd));1345 TPT((0, FIL__, __LINE__, _("msg=<SL_ISERROR (%ld)>\n"), fd)); 1357 1346 tmp = sh_util_safe_name (filename); 1358 1347 (void) sl_get_euid(&euid); … … 1457 1446 1458 1447 static char * sh_tiger_sha1_hash (char * filename, TigerType what, 1459 UINT64 Length, int timeout) 1448 UINT64 Length, int timeout, 1449 char * out, size_t len) 1460 1450 { 1461 1451 int cnt = (int) Length; /* fix compiler warning */ 1462 static char out[KEY_LEN+1];1452 char outbuf[KEY_LEN+1]; 1463 1453 unsigned char sha1buffer[20]; 1464 1454 1465 if (what != TIGER_FD) 1466 { 1467 sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, 0, 1468 MSG_E_SUBGEN, _("Not TIGER_FD"), 1469 _("sh_tiger_sha1_hash")); 1470 out[0] = '\0'; 1471 return out; 1472 } 1473 1474 (void) sha1_stream (filename, sha1buffer, Length, timeout); 1455 (void) sha1_stream (filename, sha1buffer, Length, timeout, what); 1475 1456 1476 1457 /*@-bufferoverflowhigh -usedef@*/ 1477 1458 for (cnt = 0; cnt < 20; ++cnt) 1478 sprintf (&out [cnt*2], _("%02X"),/* known to fit */1459 sprintf (&outbuf[cnt*2], _("%02X"), /* known to fit */ 1479 1460 (unsigned int) sha1buffer[cnt]); 1480 1461 /*@+bufferoverflowhigh +usedef@*/ 1481 1462 for (cnt = 40; cnt < KEY_LEN; ++cnt) 1482 out[cnt] = '0'; 1483 out[KEY_LEN] = '\0'; 1484 1463 outbuf[cnt] = '0'; 1464 outbuf[KEY_LEN] = '\0'; 1465 1466 sl_strlcpy(out, outbuf, len); 1485 1467 return out; 1486 1468 } … … 1523 1505 1524 1506 static char * sh_tiger_hash_internal (const char * filename, TigerType what, 1525 UINT64 Length, int timeout); 1507 UINT64 Length, int timeout, 1508 char * out, size_t len); 1526 1509 1527 1510 char * sh_tiger_hash (const char * filename, TigerType what, 1528 UINT64 Length )1529 { 1530 return sh_tiger_hash_internal (filename, what, Length, 0 );1511 UINT64 Length, char * out, size_t len) 1512 { 1513 return sh_tiger_hash_internal (filename, what, Length, 0, out,len); 1531 1514 } 1532 1515 1533 1516 char * sh_tiger_generic_hash (char * filename, TigerType what, 1534 UINT64 Length, int timeout) 1517 UINT64 Length, int timeout, 1518 char * out, size_t len) 1535 1519 { 1536 1520 #ifdef USE_SHA1 1537 1521 if (hash_type == 1) 1538 return sh_tiger_sha1_hash (filename, what, Length, timeout );1522 return sh_tiger_sha1_hash (filename, what, Length, timeout, out, len); 1539 1523 #endif 1540 1524 #ifdef USE_MD5 1541 1525 if (hash_type == 2) 1542 return sh_tiger_md5_hash (filename, what, Length, timeout );1543 #endif 1544 return sh_tiger_hash_internal (filename, what, Length, timeout );1526 return sh_tiger_md5_hash (filename, what, Length, timeout, out, len); 1527 #endif 1528 return sh_tiger_hash_internal (filename, what, Length, timeout, out, len); 1545 1529 } 1546 1530 … … 1549 1533 1550 1534 static char * sh_tiger_hash_internal (const char * filename, TigerType what, 1551 UINT64 Length, int timeout) 1535 UINT64 Length, int timeout, 1536 char * out, size_t len) 1552 1537 { 1553 1538 #if defined(TIGER_64_BIT) 1554 word64 * res;1539 word64 res[3]; 1555 1540 #else 1556 sh_word32 * res; 1557 #endif 1558 static char out[KEY_LEN+1]; 1541 sh_word32 res[6]; 1542 #endif 1559 1543 1560 1544 SL_ENTER( _("sh_tiger_hash_internal")); 1561 1545 1562 res = sh_tiger_hash_val (filename, what, Length, timeout);1563 1564 if ( res != NULL)1546 SH_VALIDATE_GE(len, (KEY_LEN+1)); 1547 1548 if (NULL != sh_tiger_hash_val (filename, what, Length, timeout, res)) 1565 1549 { 1566 1550 #if defined(TIGER_64_BIT) 1567 sl_snprintf(out, 1568 sizeof(out), 1551 sl_snprintf(out, len, 1569 1552 MYFORMAT, 1570 1553 (sh_word32)(res[0]>>32), … … 1575 1558 (sh_word32)(res[2]) ); 1576 1559 #else 1577 sl_snprintf(out, 1578 sizeof(out), 1560 sl_snprintf(out, len, 1579 1561 MYFORMAT, 1580 1562 (sh_word32)(res[1]), … … 1585 1567 (sh_word32)(res[4]) ); 1586 1568 #endif 1587 out[ sizeof(out)-1] = '\0';1569 out[len-1] = '\0'; 1588 1570 SL_RETURN( out, _("sh_tiger_hash_internal")); 1589 1571 … … 1600 1582 char outhash[48+6+1]; 1601 1583 #if defined(TIGER_64_BIT) 1602 word64 * res;1584 word64 res[3]; 1603 1585 #else 1604 sh_word32 * res;1586 sh_word32 res[6]; 1605 1587 #endif 1606 1588 1607 1589 SL_ENTER(_("sh_tiger_hash_gpg")); 1608 1590 1609 res = sh_tiger_hash_val (filename, what, Length, 0); 1610 if (res != NULL) 1591 if (NULL != sh_tiger_hash_val (filename, what, Length, 0, res)) 1611 1592 { 1612 1593 #if defined(TIGER_64_BIT) … … 1663 1644 UINT32 * sh_tiger_hash_uint32 (char * filename, 1664 1645 TigerType what, 1665 UINT64 Length )1646 UINT64 Length, UINT32 * out, size_t len) 1666 1647 { 1667 1648 #if defined(TIGER_64_BIT) 1668 word64 * res;1649 word64 res[3]; 1669 1650 #else 1670 sh_word32 * res; 1671 #endif 1672 1673 static UINT32 out[6]; 1651 sh_word32 res[6]; 1652 #endif 1674 1653 1675 1654 SL_ENTER(_("sh_tiger_hash_uint32")); 1655 1656 SH_VALIDATE_GE(len, 6); 1676 1657 1677 1658 out[0] = 0; out[1] = 0; out[2] = 0; 1678 1659 out[3] = 0; out[4] = 0; out[5] = 0; 1679 1660 1680 res = sh_tiger_hash_val (filename, what, Length, 0); 1681 1682 if (res != NULL) 1661 if (NULL != sh_tiger_hash_val (filename, what, Length, 0, res)) 1683 1662 { 1684 1663 #if defined(TIGER_64_BIT)
Note:
See TracChangeset
for help on using the changeset viewer.