RFR: 8294073: Performance improvement for message digest implementations

Xue-Lei Andrew Fan xuelei at openjdk.org
Wed Sep 21 04:18:33 UTC 2022


Hi,

In the message digest implementation, for example SHA256, in JDK, two bitwise operations could be improved with equivalent arithmetic, and then the number bitwise operations could be reduced accordingly.  Specifically
"(x and y) xor ((complement x) and z)" could be replaced with the equivalent "z xor (x and (y xor z))", and "(x and y) xor (x and z) xor (y and z)" could be replaced with the equivalent "(x and y) xor ((x xor y) and z)".  Each replacement reduces one bitwise operation, and thus improve the performance.

Per my testing on my MacOS laptop, the update on SHA256 improves the message digest throughput by 0.5%-0.8%.  The improvement is not significant, but might be worthy of it as the update is pretty simple and trivial, for those platforms that do not support CPU intrinsic for a certain hash algorithm.

This patch update SHA2 implementation only.  Please let me know what do you think.  If you are good  with this little bit performance, I will update more message digest implementations.  If no one interested in these little benefits, I will close this PR later.

Thanks,
Xuelei

-------------

Commit messages:
 - remove tab space
 - 8294073: Performance improvement for message digest implementations

Changes: https://git.openjdk.org/jdk/pull/10365/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10365&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8294073
  Stats: 4 lines in 1 file changed: 2 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/10365.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/10365/head:pull/10365

PR: https://git.openjdk.org/jdk/pull/10365



More information about the security-dev mailing list