infendro-patch-1 #6

Merged
Infendro merged 3 commits from infendro-patch-1 into develop 2026-04-16 16:09:30 +00:00
6 changed files with 17 additions and 11 deletions
Showing only changes of commit d9454fcdb2 - Show all commits

View File

@@ -4,8 +4,8 @@
Supported [PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) algorithms: Supported [PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) algorithms:
- LCG - LCG
- Xoshiro256++ - xoshiro256++
- Xoshiro256** - xoshiro256**
Supported [CSPRNG](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) algorithms: Supported [CSPRNG](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) algorithms:
- HMAC-DRBG - HMAC-DRBG
@@ -20,7 +20,7 @@ repositories {
} }
dependencies { dependencies {
implementation("com.infendro:prng:1.3.0") implementation("com.infendro:prng:1.3.1")
} }
``` ```
@@ -29,7 +29,7 @@ dependencies {
```kotlin ```kotlin
fun main() { fun main() {
// create PRNG instance // create PRNG instance
val rng = CSPRNG.HMAC(`SHA-256`) val rng = CSPRNG.HMAC(`SHA-256`())
// seed PRNG to receive deterministic numbers // seed PRNG to receive deterministic numbers
rng.seed(/* seed */) rng.seed(/* seed */)

View File

@@ -5,7 +5,7 @@ import com.infendro.plugin.token
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
group = "com.infendro" group = "com.infendro"
version = "1.3.0" version = "1.3.1"
plugins { plugins {
alias(libs.plugins.infendro) alias(libs.plugins.infendro)

View File

@@ -1,9 +1,9 @@
[versions] [versions]
infendro = "1.1.0" infendro = "1.1.0"
kotlin = "2.3.0" kotlin = "2.3.0"
bytes = "1.4.0" bytes = "1.4.2"
hash = "1.6.0" hash = "1.7.0"
mac = "1.4.0" mac = "1.5.0"
[plugins] [plugins]
infendro = { id = "com.infendro.plugin", version.ref = "infendro" } infendro = { id = "com.infendro.plugin", version.ref = "infendro" }

View File

@@ -6,6 +6,8 @@ import com.infendro.random.PRNG
import kotlin.properties.Delegates.notNull import kotlin.properties.Delegates.notNull
class LCG : PRNG() { class LCG : PRNG() {
private val function = `SHA-256`()
private val a: Long = 25214903917L private val a: Long = 25214903917L
private val c: Long = 11L private val c: Long = 11L
private val mask: Long = (1L shl 48) - 1 private val mask: Long = (1L shl 48) - 1
@@ -13,7 +15,7 @@ class LCG : PRNG() {
private var x: Long by notNull() private var x: Long by notNull()
override fun seed(seed: ByteArray) { override fun seed(seed: ByteArray) {
x = `SHA-256`.hash(seed).toLong() and mask x = function.hash(seed).toLong() and mask
} }
override fun generate(): Int { override fun generate(): Int {

View File

@@ -6,10 +6,12 @@ import com.infendro.random.PRNG
import kotlin.properties.Delegates.notNull import kotlin.properties.Delegates.notNull
class Xoshiro256pp : PRNG() { class Xoshiro256pp : PRNG() {
private val function = `SHA-256`()
private var s: LongArray by notNull() private var s: LongArray by notNull()
override fun seed(seed: ByteArray) { override fun seed(seed: ByteArray) {
s = `SHA-256`.hash(seed).toLongArray() s = function.hash(seed).toLongArray()
} }
override fun generate(): Int { override fun generate(): Int {

View File

@@ -6,10 +6,12 @@ import com.infendro.random.PRNG
import kotlin.properties.Delegates.notNull import kotlin.properties.Delegates.notNull
class Xoshiro256ss : PRNG() { class Xoshiro256ss : PRNG() {
private val function = `SHA-256`()
private var s: LongArray by notNull() private var s: LongArray by notNull()
override fun seed(seed: ByteArray) { override fun seed(seed: ByteArray) {
s = `SHA-256`.hash(seed).toLongArray() s = function.hash(seed).toLongArray()
} }
override fun generate(): Int { override fun generate(): Int {