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.math.BigInteger
import java.security.* 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. */ /** A wrapper around a digital signature. */
@CordaSerializable @CordaSerializable
open class DigitalSignature(bits: ByteArray) : OpaqueBytes(bits) { 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) @Throws(NoSuchAlgorithmException::class)
fun safeRandomBytes(numOfBytes: Int): ByteArray { 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. * which should never happen and suggests an unusual JVM or non-standard Java library.
*/ */
@Throws(NoSuchAlgorithmException::class) @Throws(NoSuchAlgorithmException::class)
fun safeRandom(): SecureRandom { fun newSecureRandom(): SecureRandom {
if (System.getProperty("os.name") == "Linux") { if (System.getProperty("os.name") == "Linux") {
return SecureRandom.getInstance("NativePRNGNonBlocking") return SecureRandom.getInstance("NativePRNGNonBlocking")
} else { } else {

View File

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