question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use more lightweight sha256 implementation

See original GitHub issue

Using sh256 via create-hash pulls in a bunch of dependencies we don’t need, like cipher-base, md5.js and ripemd160.

cipher-base is particularly problematic for everyone switching from Webpack 4 to Webpack 5 or using other reasonably modern bundlers because it requires node’s stream: https://github.com/crypto-browserify/cipher-base/blob/v1.0.4/index.js#L7. This causes hard to debug and support problems downstream, like https://github.com/cosmos/cosmjs/issues/925.

I think it would be much nicer to use a dependency that only implements sha256. This could be sha.js or something else, but sha.js is used already anyways.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

5reactions
webmaster128commented, Nov 24, 2021

If I get a 👍 for such a change, I’m happy to create a PR.

2reactions
webmaster128commented, Dec 6, 2021

Here are noble crypro benchmarks from my machine. The 3rd block with 2048 iterations is what matters to this use case. So as long as we are happy with those timings, we can build this lib on @noble/hashes for both sha256 and pbkdf2.

==== PBKDF2-HMAC-SHA512 ====
PBKDF2-HMAC-SHA512 512 node x 3,633 ops/sec @ 275μs/op
PBKDF2-HMAC-SHA512 512 hash-wasm x 859 ops/sec @ 1ms/op
PBKDF2-HMAC-SHA512 512 stablelib x 513 ops/sec @ 1ms/op
PBKDF2-HMAC-SHA512 512 noble x 512 ops/sec @ 1ms/op
PBKDF2-HMAC-SHA512 512 noble (async) x 500 ops/sec @ 1ms/op

PBKDF2-HMAC-SHA512 1024 node x 1,845 ops/sec @ 541μs/op
PBKDF2-HMAC-SHA512 1024 hash-wasm x 480 ops/sec @ 2ms/op
PBKDF2-HMAC-SHA512 1024 stablelib x 258 ops/sec @ 3ms/op
PBKDF2-HMAC-SHA512 1024 noble x 256 ops/sec @ 3ms/op
PBKDF2-HMAC-SHA512 1024 noble (async) x 250 ops/sec @ 3ms/op

PBKDF2-HMAC-SHA512 2048 node x 921 ops/sec @ 1ms/op
PBKDF2-HMAC-SHA512 2048 hash-wasm x 241 ops/sec @ 4ms/op
PBKDF2-HMAC-SHA512 2048 stablelib x 128 ops/sec @ 7ms/op
PBKDF2-HMAC-SHA512 2048 noble x 127 ops/sec @ 7ms/op
PBKDF2-HMAC-SHA512 2048 noble (async) x 122 ops/sec @ 8ms/op

PBKDF2-HMAC-SHA512 16384 node x 112 ops/sec @ 8ms/op
PBKDF2-HMAC-SHA512 16384 hash-wasm x 29 ops/sec @ 34ms/op
PBKDF2-HMAC-SHA512 16384 stablelib x 15 ops/sec @ 63ms/op
PBKDF2-HMAC-SHA512 16384 noble x 16 ops/sec @ 62ms/op
PBKDF2-HMAC-SHA512 16384 noble (async) x 15 ops/sec @ 66ms/op

PBKDF2-HMAC-SHA512 65536 node x 28 ops/sec @ 35ms/op
PBKDF2-HMAC-SHA512 65536 hash-wasm x 6 ops/sec @ 144ms/op
PBKDF2-HMAC-SHA512 65536 stablelib x 4 ops/sec @ 247ms/op
PBKDF2-HMAC-SHA512 65536 noble x 3 ops/sec @ 252ms/op
PBKDF2-HMAC-SHA512 65536 noble (async) x 3 ops/sec @ 265ms/op

PBKDF2-HMAC-SHA512 262144 node x 7 ops/sec @ 141ms/op
PBKDF2-HMAC-SHA512 262144 hash-wasm x 1 ops/sec @ 509ms/op
PBKDF2-HMAC-SHA512 262144 stablelib x 1 ops/sec @ 967ms/op
PBKDF2-HMAC-SHA512 262144 noble x 0 ops/sec @ 1006ms/op
PBKDF2-HMAC-SHA512 262144 noble (async) x 0 ops/sec @ 1028ms/op
Read more comments on GitHub >

github_iconTop Results From Across the Web

hash - Are there any SHA-256 javascript implementations that ...
I'm having trouble figuring out which SHA-256 implementation I can actually trust. I was expecting there to be some kind of authoritative script...
Read more >
crypto-algorithms/sha256.c at master - GitHub
Details: Implementation of the SHA-256 hashing algorithm. SHA-256 is one of the three algorithms in ... This implementation uses little endian byte order....
Read more >
Lightweight and High Performance SHA-256 ... - IEEE Xplore
To the best of our knowledge, our work is the first to employ architectural folding and 4-2 adder compressor in. SHA-256 implementation. A...
Read more >
Lightweight, portable, public domain, endian-proof ... - Reddit
Does anyone know of a good sha256 implementation to use when one only needs that one function? Since I literally only need a...
Read more >
Fast Embedded Software Hashing - Cryptology ePrint Archive
Cryptographic hash functions are one of the most widely used ... Control flow of the core of our SHA-256 implementation is illustrated in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found