From d32dbc33c55a5473f12ccbeb0f39b6cdea0fe36e Mon Sep 17 00:00:00 2001 From: Konstantinos Chalkias Date: Thu, 8 Mar 2018 15:12:18 +0000 Subject: [PATCH] CORDA-1092 - fix secureRandomBytes (#2766) --- core/src/main/kotlin/net/corda/core/crypto/CryptoUtils.kt | 2 +- core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/crypto/CryptoUtils.kt b/core/src/main/kotlin/net/corda/core/crypto/CryptoUtils.kt index 96f0c85cc2..b586f5e562 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/CryptoUtils.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/CryptoUtils.kt @@ -168,7 +168,7 @@ fun KeyPair.verify(signatureData: ByteArray, clearData: ByteArray): Boolean = Cr * which should never happen and suggests an unusual JVM or non-standard Java library. */ @Throws(NoSuchAlgorithmException::class) -fun secureRandomBytes(numOfBytes: Int): ByteArray = newSecureRandom().generateSeed(numOfBytes) +fun secureRandomBytes(numOfBytes: Int): ByteArray = ByteArray(numOfBytes).apply { newSecureRandom().nextBytes(this) } /** * Get an instance of [SecureRandom] to avoid blocking, due to waiting for additional entropy, when possible. diff --git a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt index 9a2348c48f..cf253903e2 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt @@ -78,7 +78,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) { * Generates a random SHA-256 value. */ @JvmStatic - fun randomSHA256() = sha256(newSecureRandom().generateSeed(32)) + fun randomSHA256() = sha256(secureRandomBytes(32)) /** * A SHA-256 hash value consisting of 32 0x00 bytes.