DirHash icon indicating copy to clipboard operation
DirHash copied to clipboard

FEATURE: Use multiple hash algorithms

Open david-bakin opened this issue 2 years ago • 1 comments

(Just started using dirhash when making backups of lots of VHDs, their split archives, their par2 files, etc. and it is invaluable at catching occasional errors writing to external USB drives ... thank you! I like the flexibility - both hash and verify, choice of hash algorithm, etc.)

I'd like to be able to specify multiple hash algorithms, e.g., both BLAKE3 and SHA256. Because it may happen that when I'm comparing hash values against that provided by some source, in some cases they may specify SHA256 or MD5 or something, while for my own purposes (validating backups to external USB drives) I prefer to use something else - e.g., BLAKE3 - consistently.

If implemented as a feature I'd also suggest writing the hash values to the output file in the order specified on the command line.

Reason this might be nice is that the bottleneck is most often device input speeds - especially when talking to external drives (even at USB 3.0 speeds). CPU load is pretty minimal - at least when using -mscrypto: I can run multiple dirhashes on different (SSD but not NVMe) drives with them maxing out on read speed while my CPU load is below 30%, on a 4yr old 4core laptop. So it would be nice to be able to read a terabyte or so off the drive only once even though getting multiple hashes computed.

david-bakin avatar Aug 08 '21 20:08 david-bakin

Thank you for proposing this feature. It is interesting indeed to be able to compute different hashes for the same input in one call.

In order to keep the new syntax compatible with existing one, I'm thinking of making HashAlgo argument accept combination of hash algorithms in the form of ALGO1-ALGO2..-ALGOn. For example, one could specify sha1 or sha256-sha512 or md5+sha256+blake3.

For the output file, there are two cases:

  • if -sum is not specified, then the output file will contains one line for each specified hash algorithm.
  • if -sum is specified, the program will create a number of output file equal to the number of specified hash algorithm, and it will append an extension to the output filename that is equal to the hash algorithm name. For example, if the command is "DirHash.exe C:\Data sha256-sha512 -sum -t C:\sumResult", then DirHash will output 2 files: C:\sumResult.sha256 and C:\sumResult.sha512.

I will update this issue with the progress on this idea.

idrassi avatar Aug 18 '21 21:08 idrassi

Finally I have implemented this feature, see commit: https://github.com/idrassi/DirHash/commit/3c739ee894d7111f7201434cce7b9b963da2a582 I will publish version 1.24 that includes this feature later today.

idrassi avatar Jun 17 '23 11:06 idrassi