implement seed

This commit is contained in:
2025-08-04 13:28:08 +02:00
parent 9480d02021
commit 02eaa9ec59
2 changed files with 17 additions and 9 deletions

View File

@@ -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(

View File

@@ -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,
)