Daninet / hash-wasm

Lightning fast hash functions using hand-tuned WebAssembly binaries
https://npmjs.com/package/hash-wasm
Other
894 stars 50 forks source link

Feature Request: Calculate MD5 in parallel #25

Closed miyoosan closed 3 years ago

miyoosan commented 3 years ago

It would be nice if we could get the md5 faster than now.

Is there any algorithm Calculating MD5 in parallel? Such as:

` // worker1 hasher.update(new Uint8Array(buffer)) // worker 2 hasher.update(new Uint8Array(buffer))

// main worker hasher.digest() `

thank you for your great work.

Daninet commented 3 years ago

I don't think it's possible. The MD5 algorithm is not really designed for that. Did you see an implementation which does it?

miyoosan commented 3 years ago

I don't think it's possible. The MD5 algorithm is not really designed for that. Did you see an implementation which does it?

Thanks for your answer. Yeah, I couldn't find any one. It's a pitty. I found the reason bellow.

The key issue with MD5 is that the algorithm is mostly one long dependency chain. Because of this, MD5 is limited in what parallelism it can exploit on modern superscalar processors (so much so that the more complex SHA1 hash often runs faster on modern processors).

And some possible optimisation:

  1. Dependency shortcut in G function;
  2. Dependency shortcut in I function;
  3. Instruction reduction;

Above ideas come from animetosho/md5-optimisation

Wish MD5 can be faster.

Thanks.