mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8209129: Further improvements to cipher buffer management
Reviewed-by: weijun, igerasim
This commit is contained in:
parent
58e2f2d41c
commit
50ec35819d
15 changed files with 388 additions and 316 deletions
|
@ -28,6 +28,7 @@ package sun.security.provider;
|
|||
import java.security.MessageDigestSpi;
|
||||
import java.security.DigestException;
|
||||
import java.security.ProviderException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.HotSpotIntrinsicCandidate;
|
||||
|
@ -178,6 +179,7 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable {
|
|||
implReset();
|
||||
bufOfs = 0;
|
||||
bytesProcessed = 0;
|
||||
Arrays.fill(buffer, (byte) 0x00);
|
||||
}
|
||||
|
||||
// return the digest. See JCA doc.
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
package sun.security.provider;
|
||||
|
||||
import java.security.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
import static sun.security.util.SecurityConstants.PROVIDER_VER;
|
||||
|
@ -92,7 +93,7 @@ public final class MD4 extends DigestBase {
|
|||
super("MD4", 16, 64);
|
||||
state = new int[4];
|
||||
x = new int[16];
|
||||
implReset();
|
||||
resetHashes();
|
||||
}
|
||||
|
||||
// clone this object
|
||||
|
@ -108,6 +109,12 @@ public final class MD4 extends DigestBase {
|
|||
*/
|
||||
void implReset() {
|
||||
// Load magic initialization constants.
|
||||
resetHashes();
|
||||
// clear out old data
|
||||
Arrays.fill(x, 0);
|
||||
}
|
||||
|
||||
private void resetHashes() {
|
||||
state[0] = 0x67452301;
|
||||
state[1] = 0xefcdab89;
|
||||
state[2] = 0x98badcfe;
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
package sun.security.provider;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +68,7 @@ public final class MD5 extends DigestBase {
|
|||
super("MD5", 16, 64);
|
||||
state = new int[4];
|
||||
x = new int[16];
|
||||
implReset();
|
||||
resetHashes();
|
||||
}
|
||||
|
||||
// clone this object
|
||||
|
@ -82,6 +84,12 @@ public final class MD5 extends DigestBase {
|
|||
*/
|
||||
void implReset() {
|
||||
// Load magic initialization constants.
|
||||
resetHashes();
|
||||
// clear out old data
|
||||
Arrays.fill(x, 0);
|
||||
}
|
||||
|
||||
private void resetHashes() {
|
||||
state[0] = 0x67452301;
|
||||
state[1] = 0xefcdab89;
|
||||
state[2] = 0x98badcfe;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
package sun.security.provider;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
|
@ -62,7 +63,7 @@ public final class SHA extends DigestBase {
|
|||
super("SHA-1", 20, 64);
|
||||
state = new int[5];
|
||||
W = new int[80];
|
||||
implReset();
|
||||
resetHashes();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -79,6 +80,13 @@ public final class SHA extends DigestBase {
|
|||
* Resets the buffers and hash value to start a new hash.
|
||||
*/
|
||||
void implReset() {
|
||||
// Load magic initialization constants.
|
||||
resetHashes();
|
||||
// clear out old data
|
||||
Arrays.fill(W, 0);
|
||||
}
|
||||
|
||||
private void resetHashes() {
|
||||
state[0] = 0x67452301;
|
||||
state[1] = 0xefcdab89;
|
||||
state[2] = 0x98badcfe;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
package sun.security.provider;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.HotSpotIntrinsicCandidate;
|
||||
|
@ -83,13 +84,18 @@ abstract class SHA2 extends DigestBase {
|
|||
this.initialHashes = initialHashes;
|
||||
state = new int[8];
|
||||
W = new int[64];
|
||||
implReset();
|
||||
resetHashes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the buffers and hash value to start a new hash.
|
||||
*/
|
||||
void implReset() {
|
||||
resetHashes();
|
||||
Arrays.fill(W, 0);
|
||||
}
|
||||
|
||||
private void resetHashes() {
|
||||
System.arraycopy(initialHashes, 0, state, 0, state.length);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
package sun.security.provider;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.HotSpotIntrinsicCandidate;
|
||||
|
@ -98,10 +99,15 @@ abstract class SHA5 extends DigestBase {
|
|||
this.initialHashes = initialHashes;
|
||||
state = new long[8];
|
||||
W = new long[80];
|
||||
implReset();
|
||||
resetHashes();
|
||||
}
|
||||
|
||||
final void implReset() {
|
||||
resetHashes();
|
||||
Arrays.fill(W, 0L);
|
||||
}
|
||||
|
||||
private void resetHashes() {
|
||||
System.arraycopy(initialHashes, 0, state, 0, state.length);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue