Skip to content

Commit

Permalink
Merging master HEAD into openj9-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
j9build committed Nov 23, 2020
2 parents 910de1b + b359dbd commit 30a060c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 83 deletions.
2 changes: 1 addition & 1 deletion make/autoconf/jvm-features.m4
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ AC_DEFUN([JVM_FEATURES_PREPARE_VARIANT],
JVM_FEATURES_VARIANT_UNAVAILABLE="cds minimal zero"
elif test "x$variant" = "xzero"; then
JVM_FEATURES_VARIANT_UNAVAILABLE="aot cds compiler1 compiler2 \
g1gc graal jvmci minimal shenandoahgc zgc"
graal jvmci minimal zgc"
else
JVM_FEATURES_VARIANT_UNAVAILABLE="minimal zero"
fi
Expand Down
127 changes: 45 additions & 82 deletions src/java.base/share/classes/sun/security/provider/SHA2.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,84 +113,6 @@ void implDigest(byte[] out, int ofs) {
i2bBig(state, 0, out, ofs, engineGetDigestLength());
}

/**
* logical function ch(x,y,z) as defined in spec:
* @return (x and y) xor ((complement x) and z)
* @param x int
* @param y int
* @param z int
*/
private static int lf_ch(int x, int y, int z) {
return (x & y) ^ ((~x) & z);
}

/**
* logical function maj(x,y,z) as defined in spec:
* @return (x and y) xor (x and z) xor (y and z)
* @param x int
* @param y int
* @param z int
*/
private static int lf_maj(int x, int y, int z) {
return (x & y) ^ (x & z) ^ (y & z);
}

/**
* logical function R(x,s) - right shift
* @return x right shift for s times
* @param x int
* @param s int
*/
private static int lf_R( int x, int s ) {
return (x >>> s);
}

/**
* logical function S(x,s) - right rotation
* @return x circular right shift for s times
* @param x int
* @param s int
*/
private static int lf_S(int x, int s) {
return (x >>> s) | (x << (32 - s));
}

/**
* logical function sigma0(x) - xor of results of right rotations
* @return S(x,2) xor S(x,13) xor S(x,22)
* @param x int
*/
private static int lf_sigma0(int x) {
return lf_S(x, 2) ^ lf_S(x, 13) ^ lf_S(x, 22);
}

/**
* logical function sigma1(x) - xor of results of right rotations
* @return S(x,6) xor S(x,11) xor S(x,25)
* @param x int
*/
private static int lf_sigma1(int x) {
return lf_S( x, 6 ) ^ lf_S( x, 11 ) ^ lf_S( x, 25 );
}

/**
* logical function delta0(x) - xor of results of right shifts/rotations
* @return int
* @param x int
*/
private static int lf_delta0(int x) {
return lf_S(x, 7) ^ lf_S(x, 18) ^ lf_R(x, 3);
}

/**
* logical function delta1(x) - xor of results of right shifts/rotations
* @return int
* @param x int
*/
private static int lf_delta1(int x) {
return lf_S(x, 17) ^ lf_S(x, 19) ^ lf_R(x, 10);
}

/**
* Process the current block to update the state variable state.
*/
Expand Down Expand Up @@ -219,8 +141,27 @@ private void implCompress0(byte[] buf, int ofs) {
// The first 16 ints are from the byte stream, compute the rest of
// the W[]'s
for (int t = 16; t < ITERATION; t++) {
W[t] = lf_delta1(W[t-2]) + W[t-7] + lf_delta0(W[t-15])
+ W[t-16];
int W_t2 = W[t - 2];
int W_t15 = W[t - 15];

// S(x,s) is right rotation of x by s positions:
// S(x,s) = (x >>> s) | (x << (32 - s))
// R(x,s) is right shift of x by s positions:
// R(x,s) = (x >>> s)

// delta0(x) = S(x, 7) ^ S(x, 18) ^ R(x, 3)
int delta0_W_t15 =
((W_t15 >>> 7) | (W_t15 << 25)) ^
((W_t15 >>> 18) | (W_t15 << 14)) ^
(W_t15 >>> 3);

// delta1(x) = S(x, 17) ^ S(x, 19) ^ R(x, 10)
int delta1_W_t2 =
((W_t2 >>> 17) | (W_t2 << 15)) ^
((W_t2 >>> 19) | (W_t2 << 13)) ^
(W_t2 >>> 10);

W[t] = delta0_W_t15 + delta1_W_t2 + W[t-7] + W[t-16];
}

int a = state[0];
Expand All @@ -233,8 +174,29 @@ private void implCompress0(byte[] buf, int ofs) {
int h = state[7];

for (int i = 0; i < ITERATION; i++) {
int T1 = h + lf_sigma1(e) + lf_ch(e,f,g) + ROUND_CONSTS[i] + W[i];
int T2 = lf_sigma0(a) + lf_maj(a,b,c);
// S(x,s) is right rotation of x by s positions:
// S(x,s) = (x >>> s) | (x << (32 - s))

// sigma0(x) = S(x,2) xor S(x,13) xor S(x,22)
int sigma0_a =
((a >>> 2) | (a << 30)) ^
((a >>> 13) | (a << 19)) ^
((a >>> 22) | (a << 10));

// sigma1(x) = S(x,6) xor S(x,11) xor S(x,25)
int sigma1_e =
((e >>> 6) | (e << 26)) ^
((e >>> 11) | (e << 21)) ^
((e >>> 25) | (e << 7));

// ch(x,y,z) = (x and y) xor ((complement x) and z)
int ch_efg = (e & f) ^ ((~e) & 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);

int T1 = h + sigma1_e + ch_efg + ROUND_CONSTS[i] + W[i];
int T2 = sigma0_a + maj_abc;
h = g;
g = f;
f = e;
Expand All @@ -244,6 +206,7 @@ private void implCompress0(byte[] buf, int ofs) {
b = a;
a = T1 + T2;
}

state[0] += a;
state[1] += b;
state[2] += c;
Expand Down

0 comments on commit 30a060c

Please sign in to comment.