mirror of
https://github.com/corda/corda.git
synced 2024-12-23 14:52:29 +00:00
core: use newSecureRandom() instead of SecureRandom.getInstanceStrong()
This commit is contained in:
parent
906c100c29
commit
481d2f7151
@ -4,6 +4,7 @@ import com.google.common.io.ByteStreams
|
|||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
import com.google.common.util.concurrent.MoreExecutors
|
import com.google.common.util.concurrent.MoreExecutors
|
||||||
import com.google.common.util.concurrent.SettableFuture
|
import com.google.common.util.concurrent.SettableFuture
|
||||||
|
import com.r3corda.core.crypto.newSecureRandom
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
import java.io.InputStream
|
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
|
* 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.
|
* 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.
|
// Some utilities for working with Guava listenable futures.
|
||||||
fun <T> ListenableFuture<T>.then(executor: Executor, body: () -> Unit) = addListener(Runnable(body), executor)
|
fun <T> ListenableFuture<T>.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.
|
// TODO: Generic csv printing utility for clases.
|
||||||
|
@ -42,7 +42,7 @@ sealed class SecureHash private constructor(bits: ByteArray) : OpaqueBytes(bits)
|
|||||||
@JvmStatic fun sha256Twice(bits: ByteArray) = sha256(sha256(bits).bits)
|
@JvmStatic fun sha256Twice(bits: ByteArray) = sha256(sha256(bits).bits)
|
||||||
@JvmStatic fun sha256(str: String) = sha256(str.toByteArray())
|
@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
|
abstract val signatureAlgorithmName: String
|
||||||
@ -165,4 +165,4 @@ operator fun KeyPair.component1() = this.private
|
|||||||
operator fun KeyPair.component2() = this.public
|
operator fun KeyPair.component2() = this.public
|
||||||
|
|
||||||
/** A simple wrapper that will make it easier to swap out the EC algorithm we use in future */
|
/** A simple wrapper that will make it easier to swap out the EC algorithm we use in future */
|
||||||
fun generateKeyPair() = EddsaKeyPairGenerator().generateKeyPair()
|
fun generateKeyPair() = EddsaKeyPairGenerator().generateKeyPair()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.r3corda.core.contracts
|
package com.r3corda.core.contracts
|
||||||
|
|
||||||
|
import com.r3corda.core.crypto.newSecureRandom
|
||||||
import com.r3corda.core.node.services.testing.MockTransactionStorage
|
import com.r3corda.core.node.services.testing.MockTransactionStorage
|
||||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||||
import com.r3corda.core.testing.MEGA_CORP_KEY
|
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
|
* 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)
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.r3corda.core.contracts
|
|||||||
|
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.crypto.SecureHash
|
import com.r3corda.core.crypto.SecureHash
|
||||||
|
import com.r3corda.core.crypto.newSecureRandom
|
||||||
import com.r3corda.core.node.services.testing.MockStorageService
|
import com.r3corda.core.node.services.testing.MockStorageService
|
||||||
import com.r3corda.core.testing.*
|
import com.r3corda.core.testing.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -33,7 +34,7 @@ class TransactionGroupTests {
|
|||||||
}
|
}
|
||||||
interface Commands : CommandData {
|
interface Commands : CommandData {
|
||||||
class Move() : TypeOnlyCommandData(), Commands
|
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<Currency>) : Commands
|
data class Exit(val amount: Amount<Currency>) : Commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,4 +179,4 @@ class TransactionGroupTests {
|
|||||||
}.toSet()
|
}.toSet()
|
||||||
TransactionGroup(ltxns, emptySet()).verify()
|
TransactionGroup(ltxns, emptySet()).verify()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.r3corda.core.serialization
|
|||||||
import com.r3corda.core.contracts.*
|
import com.r3corda.core.contracts.*
|
||||||
import com.r3corda.core.crypto.Party
|
import com.r3corda.core.crypto.Party
|
||||||
import com.r3corda.core.crypto.SecureHash
|
import com.r3corda.core.crypto.SecureHash
|
||||||
|
import com.r3corda.core.crypto.newSecureRandom
|
||||||
import com.r3corda.core.node.services.testing.MockStorageService
|
import com.r3corda.core.node.services.testing.MockStorageService
|
||||||
import com.r3corda.core.seconds
|
import com.r3corda.core.seconds
|
||||||
import com.r3corda.core.testing.*
|
import com.r3corda.core.testing.*
|
||||||
@ -34,7 +35,7 @@ class TransactionSerializationTests {
|
|||||||
}
|
}
|
||||||
interface Commands : CommandData {
|
interface Commands : CommandData {
|
||||||
class Move() : TypeOnlyCommandData(), Commands
|
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<Currency>) : Commands
|
data class Exit(val amount: Amount<Currency>) : Commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,4 +108,4 @@ class TransactionSerializationTests {
|
|||||||
assertEquals(tx.outputStates(), ltx.outputs)
|
assertEquals(tx.outputStates(), ltx.outputs)
|
||||||
assertEquals(TEST_TX_TIME, ltx.commands.getTimestampBy(DUMMY_NOTARY)!!.midpoint)
|
assertEquals(TEST_TX_TIME, ltx.commands.getTimestampBy(DUMMY_NOTARY)!!.midpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user