Skip to content

Commit a479d7a

Browse files
committed
support --blake2s and --blake2b options
1 parent f693b9e commit a479d7a

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Mon 04 Jan 2021 Aleksey
2+
* supported --blake2s, --blake2b options for the BLAKE2 hash functions
3+
14
Sun 03 Jan 2021 Aleksey
25
* Bugfix: fix computing of EDON-R 512 by big data chunks
36

dist/rhash.1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rhash \- calculate/check CRC32, MD5, SHA1, GOST, TTH, BTIH or other message dige
1313
computes and verifies various message digests and checksums of files.
1414
Supported hash algorithms include CRC32, CRC32C, MD4, MD5, SHA1,
1515
SHA256, SHA512, SHA3, Tiger, DC++ TTH, BTIH, AICH, ED2K, GOST R 34.11\-*,
16-
RIPEMD\-160, HAS\-160, EDON\-R 256/512, Whirlpool, Snefru\-128/256.
16+
RIPEMD\-160, HAS\-160, BLAKE2s/BLAKE2b, EDON\-R 256/512, Whirlpool, Snefru\-128/256.
1717

1818
The program can create and verify Magnet links
1919
and eDonkey ed2k:// links, see \-\-magnet and \-\-ed2k\-link options.
@@ -111,6 +111,8 @@ HAS\-160: Select HAS\-160 hash function.
111111
SNEFRU: Select SNEFRU\-128/256 hash function.
112112
.IP "\-\-edonr256, \-\-edonr512"
113113
EDON\-R: Select EDON\-R 256/512 hash function.
114+
.IP "\-\-blake2b, \-\-blake2s"
115+
BLAKE2: Select BLAKE2b/BLAKE2s hash function.
114116

115117
.IP "\-a, \-\-all"
116118
Calculate all supported hash functions.
@@ -282,7 +284,8 @@ Whirlpool message digest.
282284
%{gost94}, %{gost94\-cryptopro}, %{gost12\-256}, %{gost12\-512},\
283285
%{sha\-224}, %{sha\-256}, %{sha\-384}, %{sha\-512},\
284286
%{sha3\-224}, %{sha3\-256}, %{sha3\-384}, %{sha3\-512},\
285-
%{edon\-r256}, %{edon\-r512}, %{snefru128}, %{snefru256}"
287+
%{edon\-r256}, %{edon\-r512}, %{blake2s}, %{blake2b},\
288+
%{snefru128}, %{snefru256}"
286289
Print the specified message digest. It is printed in uppercase, if the
287290
hash function name starts with a capital letter, e.g. %{TTH}, %{Sha-512}.
288291
.IP "%x<hash>, %b<hash>, %B<hash>, %@<hash>"
@@ -296,7 +299,8 @@ placing a hardlink/symlink to it with a filename containing strings `crc32',
296299
`sha3\-256', `sha3\-512', `sha3\-224', `sha3\-384', `tiger', `tth',
297300
`btih', `aich', `ed2k', `ed2k\-link', `gost12\-256', `gost12\-512',
298301
`gost94', `gost94\-cryptopro', `rmd160', `has160', `whirlpool',
299-
`edonr256', `edonr512', `snefru128', `snefru256', `sfv' , `bsd' or `magnet'.
302+
`edonr256', `edonr512', `blake2s', `blake2b',
303+
`snefru128', `snefru256', `sfv' , `bsd' or `magnet'.
300304

301305
.SH CONFIG FILE
302306
RHash looks for a config file

hash_check.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ static unsigned char test_hash_string(char** ptr, char* end, int* p_len)
281281
*/
282282
static unsigned bsd_hash_name_to_id(const char* name, unsigned length)
283283
{
284-
#define code2mask_size (18 * 2)
284+
#define code2mask_size (19 * 2)
285285
static unsigned code2mask[code2mask_size] = {
286286
FOURC2U('A', 'I', 'C', 'H'), RHASH_AICH,
287+
FOURC2U('B', 'L', 'A', 'K'), (RHASH_BLAKE2S | RHASH_BLAKE2B),
287288
FOURC2U('B', 'T', 'I', 'H'), RHASH_BTIH,
288289
FOURC2U('C', 'R', 'C', '3'), (RHASH_CRC32 | RHASH_CRC32C),
289290
FOURC2U('E', 'D', '2', 'K'), RHASH_ED2K,

hash_print.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void init_hash_info_table(void)
552552
{
553553
unsigned bit;
554554
const unsigned fullmask = RHASH_ALL_HASHES | OPT_ED2K_LINK;
555-
const unsigned custom_bsd_name = RHASH_RIPEMD160 |
555+
const unsigned custom_bsd_name = RHASH_RIPEMD160 | RHASH_BLAKE2S | RHASH_BLAKE2B |
556556
RHASH_SHA224 | RHASH_SHA256 | RHASH_SHA384 | RHASH_SHA512;
557557
const unsigned short_opt_mask = RHASH_CRC32 | RHASH_MD5 | RHASH_SHA1 | RHASH_TTH | RHASH_ED2K |
558558
RHASH_AICH | RHASH_WHIRLPOOL | RHASH_RIPEMD160 | RHASH_GOST12_256 | OPT_ED2K_LINK;
@@ -616,6 +616,12 @@ void init_hash_info_table(void)
616616
case RHASH_SHA512:
617617
info->bsd_name = "SHA512";
618618
break;
619+
case RHASH_BLAKE2S:
620+
info->bsd_name = "BLAKE2s";
621+
break;
622+
case RHASH_BLAKE2B:
623+
info->bsd_name = "BLAKE2b";
624+
break;
619625
}
620626
} else
621627
info->bsd_name = info->name;

parse_cmdline.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ static void print_help(void)
8888
print_help_line(" --gost94-cryptopro ", digest_format, _("GOST R 34.11-94 CryptoPro"));
8989
print_help_line(" --ripemd160 ", digest_format, "RIPEMD-160");
9090
print_help_line(" --has160 ", digest_format, "HAS-160");
91-
print_help_line(" --edonr256, --edonr512 ", digest_format, "EDON-R 256/512");
92-
print_help_line(" --snefru128, --snefru256 ", digest_format, "SNEFRU-128/256");
91+
print_help_line(" --blake2s, --blake2b ", digest_format, "BLAKE2S/BLAKE2B");
92+
print_help_line(" --edonr256, --edonr512 ", digest_format, "EDON-R 256/512");
93+
print_help_line(" --snefru128, --snefru256 ", digest_format, "SNEFRU-128/256");
9394
print_help_line(" -a, --all ", _("Calculate all supported hash functions.\n"));
9495
print_help_line(" -c, --check ", _("Check hash files specified by command line.\n"));
9596
print_help_line(" -u, --update=<file> ", _("Update the specified hash file.\n"));
@@ -395,6 +396,8 @@ cmdline_opt_t cmdline_opt[] =
395396
{ F_UFLG, 0, 0, "snefru256", &opt.sum_flags, RHASH_SNEFRU256 },
396397
{ F_UFLG, 0, 0, "edonr256", &opt.sum_flags, RHASH_EDONR256 },
397398
{ F_UFLG, 0, 0, "edonr512", &opt.sum_flags, RHASH_EDONR512 },
399+
{ F_UFLG, 0, 0, "blake2s", &opt.sum_flags, RHASH_BLAKE2S },
400+
{ F_UFLG, 0, 0, "blake2b", &opt.sum_flags, RHASH_BLAKE2B },
398401
{ F_UFLG, 'L', 0, "ed2k-link", &opt.sum_flags, OPT_ED2K_LINK },
399402

400403
/* output formats */
@@ -1008,11 +1011,13 @@ static void set_default_sums_flags(const char* progName)
10081011
else if (strstr(buf, "gost94")) res |= RHASH_GOST94;
10091012
if (strstr(buf, "has160")) res |= RHASH_HAS160;
10101013
if (strstr(buf, "ripemd160") || strstr(buf, "rmd160")) res |= RHASH_RIPEMD160;
1011-
if (strstr(buf, "whirlpool")) res |= RHASH_WHIRLPOOL;
1012-
if (strstr(buf, "edonr256")) res |= RHASH_EDONR256;
1013-
if (strstr(buf, "edonr512")) res |= RHASH_EDONR512;
1014-
if (strstr(buf, "snefru256")) res |= RHASH_SNEFRU128;
1015-
if (strstr(buf, "snefru128")) res |= RHASH_SNEFRU256;
1014+
if (strstr(buf, "whirlpool")) res |= RHASH_WHIRLPOOL;
1015+
if (strstr(buf, "edonr256")) res |= RHASH_EDONR256;
1016+
if (strstr(buf, "edonr512")) res |= RHASH_EDONR512;
1017+
if (strstr(buf, "blake2s")) res |= RHASH_BLAKE2S;
1018+
if (strstr(buf, "blake2b")) res |= RHASH_BLAKE2B;
1019+
if (strstr(buf, "snefru256")) res |= RHASH_SNEFRU128;
1020+
if (strstr(buf, "snefru128")) res |= RHASH_SNEFRU256;
10161021
if (strstr(buf, "ed2k-link")) res |= OPT_ED2K_LINK;
10171022
else if (strstr(buf, "ed2k")) res |= RHASH_ED2K;
10181023

0 commit comments

Comments
 (0)