提交 f3faa1d9 编写于 作者: R robm

8044659: Java SecureRandom on SPARC T4 much slower than on x86/Linux

Reviewed-by: mullan
Contributed-by: NBradford Wetmore <bradford.wetmore@oracle.com>
上级 224c42c0
/* /*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,6 +29,7 @@ import java.io.IOException; ...@@ -29,6 +29,7 @@ import java.io.IOException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.SecureRandomSpi; import java.security.SecureRandomSpi;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
/** /**
* <p>This class provides a crytpographically strong pseudo-random number * <p>This class provides a crytpographically strong pseudo-random number
...@@ -94,9 +95,19 @@ implements java.io.Serializable { ...@@ -94,9 +95,19 @@ implements java.io.Serializable {
*/ */
private void init(byte[] seed) { private void init(byte[] seed) {
try { try {
digest = MessageDigest.getInstance("SHA"); /*
} catch (NoSuchAlgorithmException e) { * Use the local SUN implementation to avoid native
throw new InternalError("internal error: SHA-1 not available.", e); * performance overhead.
*/
digest = MessageDigest.getInstance("SHA", "SUN");
} catch (NoSuchProviderException | NoSuchAlgorithmException e) {
// Fallback to any available.
try {
digest = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException exc) {
throw new InternalError(
"internal error: SHA-1 not available.", exc);
}
} }
if (seed != null) { if (seed != null) {
...@@ -265,9 +276,19 @@ implements java.io.Serializable { ...@@ -265,9 +276,19 @@ implements java.io.Serializable {
s.defaultReadObject (); s.defaultReadObject ();
try { try {
digest = MessageDigest.getInstance("SHA"); /*
} catch (NoSuchAlgorithmException e) { * Use the local SUN implementation to avoid native
throw new InternalError("internal error: SHA-1 not available.", e); * performance overhead.
*/
digest = MessageDigest.getInstance("SHA", "SUN");
} catch (NoSuchProviderException | NoSuchAlgorithmException e) {
// Fallback to any available.
try {
digest = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException exc) {
throw new InternalError(
"internal error: SHA-1 not available.", exc);
}
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册