From b366d17a94e5b16710fd915ef4cf04aaf911b455 Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Mon, 21 Nov 2022 15:56:19 +0000 Subject: [PATCH] 8294073: Performance improvement for message digest implementations Reviewed-by: jjiang --- src/java.base/share/classes/sun/security/provider/SHA2.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/sun/security/provider/SHA2.java b/src/java.base/share/classes/sun/security/provider/SHA2.java index 05678746b20..fd161ad694a 100644 --- a/src/java.base/share/classes/sun/security/provider/SHA2.java +++ b/src/java.base/share/classes/sun/security/provider/SHA2.java @@ -195,10 +195,12 @@ abstract class SHA2 extends DigestBase { Integer.rotateRight(e, 25); // ch(x,y,z) = (x and y) xor ((complement x) and z) - int ch_efg = (e & f) ^ ((~e) & g); + // = z xor (x and (y xor z)); + int ch_efg = g ^ (e & (f ^ g)); // maj(x,y,z) = (x and y) xor (x and z) xor (y and z) - int maj_abc = (a & b) ^ (a & c) ^ (b & c); + // = (x and y) xor ((x xor y) and z) + int maj_abc = (a & b) ^ ((a ^ b) & c); int T1 = h + sigma1_e + ch_efg + ROUND_CONSTS[i] + W[i]; int T2 = sigma0_a + maj_abc;