Add native keccak256 hash function from OpenSSL 3.x #745
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The createHash('KECCAK-256') function was failing with "Unknown hash algorithm" error on iOS, even though getHashes() listed KECCAK-256 as available. This was caused by a mismatch between the legacy OpenSSL API (EVP_get_digestbyname) used in createHash() and the provider-based API that enumerates available algorithms.
Solution
Added a dedicated keccak256() function that uses OpenSSL's modern provider-aware API (EVP_MD_fetch) to properly access KECCAK-256 digests. Also added unit test.
Future work
This could be extended to support all hash functions using the new OpenSSL API, but this satisfied my needs for my project. I might also add a PR to extend keccak256 support to the legacy 0.7.15 package because that is what everyone is using on npm (however as I understand it this would require upgrading the OpenSSL version on that package to 3.x)