Remove duplicated SecureRandom functions in crypto package.

This commit is contained in:
Katarzyna Streich 2017-03-23 15:51:59 +00:00 committed by kasiastreich
parent eaf9dad7c9
commit c5966a93e5
3 changed files with 4 additions and 12 deletions

View File

@ -14,14 +14,6 @@ import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec
import java.math.BigInteger
import java.security.*
fun newSecureRandom(): SecureRandom {
if (System.getProperty("os.name") == "Linux") {
return SecureRandom.getInstance("NativePRNGNonBlocking")
} else {
return SecureRandom.getInstanceStrong()
}
}
/** A wrapper around a digital signature. */
@CordaSerializable
open class DigitalSignature(bits: ByteArray) : OpaqueBytes(bits) {

View File

@ -86,7 +86,7 @@ fun KeyPair.verify(signatureData: ByteArray, clearData: ByteArray): Boolean = Cr
*/
@Throws(NoSuchAlgorithmException::class)
fun safeRandomBytes(numOfBytes: Int): ByteArray {
return safeRandom().generateSeed(numOfBytes)
return newSecureRandom().generateSeed(numOfBytes)
}
/**
@ -108,7 +108,7 @@ fun safeRandomBytes(numOfBytes: Int): ByteArray {
* which should never happen and suggests an unusual JVM or non-standard Java library.
*/
@Throws(NoSuchAlgorithmException::class)
fun safeRandom(): SecureRandom {
fun newSecureRandom(): SecureRandom {
if (System.getProperty("os.name") == "Linux") {
return SecureRandom.getInstance("NativePRNGNonBlocking")
} else {

View File

@ -35,8 +35,8 @@ data class SignatureScheme(
*/
init {
if (algSpec != null)
keyPairGenerator.initialize(algSpec, safeRandom())
keyPairGenerator.initialize(algSpec, newSecureRandom())
else
keyPairGenerator.initialize(keySize, safeRandom())
keyPairGenerator.initialize(keySize, newSecureRandom())
}
}