-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: crypto hash functions(md5, sha1, sha256 and hmac) #513
Conversation
This commit adds the following changes - Move shared sources to js-native directory to reduce redundant files - See portable-scala/sbt-crossproject#145 - Port hash functions in pure Scala for js and native platform with reference to https://github.com/square/okio (Apache V2 License)
Some providers do support MessageDigest alias such as "SHA256" instead of "SHA-256", but others do not. To Maximize portability, we should use MessageDigest names documented at https://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html
4082cac
to
042bb7c
Compare
Sorry, I shouldn't use aliases such as "SHA256", which some providers support, but are not officially supported. |
In fs2, we decided to delegate to Web Crypto on JS and OpenSSL on Native instead of defining these operations in pure Scala. I'd prefer not to include implementations of crypto primitives but I'm interested in your thoughts, as well as feedback from @armanbilge. |
@mpilquist I think one of the virtues of scodec-bits is its dependency-free-ness. I know there is native crypto binding in fs2. If scodec-bits provided crypto hash functions, it would allow developers to choose two options. If they want to convert bytes with portable, dependency-free hash functions in synchronous API, they can use scodec-bits. If they want to convert bytes with battle-tested(hence supposed to be secure), performant hash functions in purely functional API, they can use fs2.
|
The good news is that Web Crypto is not a dependency on effectively all modern JS runtimes :) it's part of the built-in APIs on browsers, Node.js, Deno, Bun, etc.
JS doesn't provide a synchronous API for hashing because doing compute-intensive operations will block the single-threaded runtime. This is especially problematic in browsers because it can cause a webpage to freeze for users. Further reading: https://javascript.info/event-loop For Native, we will have to take on a dependency for some platforms, although I believe macOS and Windows include crypto routines in their system APIs. Meanwhile, OpenSSL is ubiquitous on all platforms. Many Scala Native applications will need OpenSSL anyway to access cryptographic routines for TLS/https.
I feel the same. We are not cryptography experts and have limited resources to responsibly handle CVEs.
Unfortunately, when you provide options, even experienced developers may inadvertently make the wrong choice. For a real example of this in the Scala.js ecosystem, I encourage you to read scala-js/scala-js#4663 (comment). |
Thank you for the feedback and explanation. I withdraw this PR. I'll read the links. |
This commit adds the following changes
References