diff --git a/core/src/main/kotlin/com/r3corda/core/Utils.kt b/core/src/main/kotlin/com/r3corda/core/Utils.kt index feaa452380..e453006ec3 100644 --- a/core/src/main/kotlin/com/r3corda/core/Utils.kt +++ b/core/src/main/kotlin/com/r3corda/core/Utils.kt @@ -4,6 +4,7 @@ import com.google.common.io.ByteStreams import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.MoreExecutors import com.google.common.util.concurrent.SettableFuture +import com.r3corda.core.crypto.newSecureRandom import org.slf4j.Logger import java.io.BufferedInputStream import java.io.InputStream @@ -36,7 +37,7 @@ fun String.abbreviate(maxWidth: Int): String = if (length <= maxWidth) this else * Returns a random positive long generated using a secure RNG. This function sacrifies a bit of entropy in order to * avoid potential bugs where the value is used in a context where negative numbers are not expected. */ -fun random63BitValue(): Long = Math.abs(SecureRandom.getInstanceStrong().nextLong()) +fun random63BitValue(): Long = Math.abs(newSecureRandom().nextLong()) // Some utilities for working with Guava listenable futures. fun ListenableFuture.then(executor: Executor, body: () -> Unit) = addListener(Runnable(body), executor) @@ -200,4 +201,4 @@ fun extractZipFile(zipPath: Path, toPath: Path) { } } -// TODO: Generic csv printing utility for clases. \ No newline at end of file +// TODO: Generic csv printing utility for clases. diff --git a/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt b/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt index a3a7134330..707642edce 100644 --- a/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt +++ b/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt @@ -42,7 +42,7 @@ sealed class SecureHash private constructor(bits: ByteArray) : OpaqueBytes(bits) @JvmStatic fun sha256Twice(bits: ByteArray) = sha256(sha256(bits).bits) @JvmStatic fun sha256(str: String) = sha256(str.toByteArray()) - @JvmStatic fun randomSHA256() = sha256(SecureRandom.getInstanceStrong().generateSeed(32)) + @JvmStatic fun randomSHA256() = sha256(newSecureRandom().generateSeed(32)) } abstract val signatureAlgorithmName: String @@ -165,4 +165,4 @@ operator fun KeyPair.component1() = this.private operator fun KeyPair.component2() = this.public /** A simple wrapper that will make it easier to swap out the EC algorithm we use in future */ -fun generateKeyPair() = EddsaKeyPairGenerator().generateKeyPair() \ No newline at end of file +fun generateKeyPair() = EddsaKeyPairGenerator().generateKeyPair() diff --git a/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt b/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt index 247e5e05c8..be5bc771b0 100644 --- a/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt +++ b/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGraphSearchTests.kt @@ -1,5 +1,6 @@ package com.r3corda.core.contracts +import com.r3corda.core.crypto.newSecureRandom import com.r3corda.core.node.services.testing.MockTransactionStorage import com.r3corda.core.testing.DUMMY_NOTARY import com.r3corda.core.testing.MEGA_CORP_KEY @@ -16,7 +17,7 @@ class TransactionGraphSearchTests { } } - fun random31BitValue(): Int = Math.abs(SecureRandom.getInstanceStrong().nextInt()) + fun random31BitValue(): Int = Math.abs(newSecureRandom().nextInt()) /** * Build a pair of transactions. The first issues a dummy output state, and has a command applied, the second then @@ -70,4 +71,4 @@ class TransactionGraphSearchTests { assertEquals(expected, actual) } -} \ No newline at end of file +} diff --git a/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGroupTests.kt b/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGroupTests.kt index c2e60ed365..520188611c 100644 --- a/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGroupTests.kt +++ b/core/src/test/kotlin/com/r3corda/core/contracts/TransactionGroupTests.kt @@ -2,6 +2,7 @@ package com.r3corda.core.contracts import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.SecureHash +import com.r3corda.core.crypto.newSecureRandom import com.r3corda.core.node.services.testing.MockStorageService import com.r3corda.core.testing.* import org.junit.Test @@ -33,7 +34,7 @@ class TransactionGroupTests { } interface Commands : CommandData { class Move() : TypeOnlyCommandData(), Commands - data class Issue(val nonce: Long = SecureRandom.getInstanceStrong().nextLong()) : Commands + data class Issue(val nonce: Long = newSecureRandom().nextLong()) : Commands data class Exit(val amount: Amount) : Commands } } @@ -178,4 +179,4 @@ class TransactionGroupTests { }.toSet() TransactionGroup(ltxns, emptySet()).verify() } -} \ No newline at end of file +} diff --git a/core/src/test/kotlin/com/r3corda/core/serialization/TransactionSerializationTests.kt b/core/src/test/kotlin/com/r3corda/core/serialization/TransactionSerializationTests.kt index 1ab212e742..26cfd74992 100644 --- a/core/src/test/kotlin/com/r3corda/core/serialization/TransactionSerializationTests.kt +++ b/core/src/test/kotlin/com/r3corda/core/serialization/TransactionSerializationTests.kt @@ -3,6 +3,7 @@ package com.r3corda.core.serialization import com.r3corda.core.contracts.* import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.SecureHash +import com.r3corda.core.crypto.newSecureRandom import com.r3corda.core.node.services.testing.MockStorageService import com.r3corda.core.seconds import com.r3corda.core.testing.* @@ -34,7 +35,7 @@ class TransactionSerializationTests { } interface Commands : CommandData { class Move() : TypeOnlyCommandData(), Commands - data class Issue(val nonce: Long = SecureRandom.getInstanceStrong().nextLong()) : Commands + data class Issue(val nonce: Long = newSecureRandom().nextLong()) : Commands data class Exit(val amount: Amount) : Commands } } @@ -107,4 +108,4 @@ class TransactionSerializationTests { assertEquals(tx.outputStates(), ltx.outputs) assertEquals(TEST_TX_TIME, ltx.commands.getTimestampBy(DUMMY_NOTARY)!!.midpoint) } -} \ No newline at end of file +}