Changeset 444 for trunk/src/sh_tiger0.c
- Timestamp:
- Oct 31, 2013, 11:31:47 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.