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 import com.infendro.hash.HashFunction
class HMAC internal constructor( class HMAC internal constructor(
function: HashFunction, private val function: HashFunction,
) : PRNG() { ) : PRNG() {
private val random = Default private val random = Default
private val hmac = com.infendro.mac.HMAC(function) private val hmac = com.infendro.mac.HMAC(function)
private var K: ByteArray private lateinit var K: ByteArray
private var V: ByteArray private lateinit var V: ByteArray
init { init {
K = ByteArray(function.bytes).also { val bytes = random.nextBytes(function.bytes)
random.nextBytes(it) seed(bytes)
} }
V = ByteArray(function.bytes).also {
random.nextBytes(it) override fun seed(
} seed: ByteArray,
) {
K = ByteArray(function.bytes) { 0x00 }
V = ByteArray(function.bytes) { 0x01 }
reseed(seed)
} }
override fun reseed( override fun reseed(

View File

@@ -5,6 +5,10 @@ import com.infendro.hash.HashFunction
import kotlin.random.Random import kotlin.random.Random
abstract class PRNG : Random() { abstract class PRNG : Random() {
abstract fun seed(
seed: ByteArray,
)
abstract fun reseed( abstract fun reseed(
entropy: ByteArray, entropy: ByteArray,
) )