implement seed
This commit is contained in:
@@ -4,20 +4,24 @@ import com.infendro.bytearray.addAll
|
||||
import com.infendro.hash.HashFunction
|
||||
|
||||
class HMAC internal constructor(
|
||||
function: HashFunction,
|
||||
private val function: HashFunction,
|
||||
) : PRNG() {
|
||||
private val random = Default
|
||||
private val hmac = com.infendro.mac.HMAC(function)
|
||||
private var K: ByteArray
|
||||
private var V: ByteArray
|
||||
private lateinit var K: ByteArray
|
||||
private lateinit var V: ByteArray
|
||||
|
||||
init {
|
||||
K = ByteArray(function.bytes).also {
|
||||
random.nextBytes(it)
|
||||
}
|
||||
V = ByteArray(function.bytes).also {
|
||||
random.nextBytes(it)
|
||||
}
|
||||
val bytes = random.nextBytes(function.bytes)
|
||||
seed(bytes)
|
||||
}
|
||||
|
||||
override fun seed(
|
||||
seed: ByteArray,
|
||||
) {
|
||||
K = ByteArray(function.bytes) { 0x00 }
|
||||
V = ByteArray(function.bytes) { 0x01 }
|
||||
reseed(seed)
|
||||
}
|
||||
|
||||
override fun reseed(
|
||||
|
||||
@@ -5,6 +5,10 @@ import com.infendro.hash.HashFunction
|
||||
import kotlin.random.Random
|
||||
|
||||
abstract class PRNG : Random() {
|
||||
abstract fun seed(
|
||||
seed: ByteArray,
|
||||
)
|
||||
|
||||
abstract fun reseed(
|
||||
entropy: ByteArray,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user