Skip to content

Instantly share code, notes, and snippets.

@kushti
Created January 30, 2021 16:02
Show Gist options
  • Save kushti/75007b05061a7652583ed8e11dffea58 to your computer and use it in GitHub Desktop.
Save kushti/75007b05061a7652583ed8e11dffea58 to your computer and use it in GitHub Desktop.
property("testvectors from WP") {
val msg = Base16.decode("82dbfccc40aa9919d21dd2bad90935ec44db013738592466e5dad1fa051cb4ff").get
val nonce = Base16.decode("E8F2800001A12388").get
val height = 5090
val h = Ints.toByteArray(height)
val pow = new AutolykosPowScheme(32, 26)
val N = pow.calcN(2, height)
val prei8 = BigIntegers.fromUnsignedByteArray(hash(Bytes.concat(msg, nonce)).takeRight(8))
val i = BigIntegers.asUnsignedByteArray(4, prei8.mod(BigInt(N).underlying()))
val f = Blake2b256(Bytes.concat(i, h, pow.M)).drop(1) // .drop(1) is the same as takeRight(31)
val seed = Bytes.concat(f, msg, nonce) // Autolykos v1, Alg. 2, line4:
println("seed: " + Base16.encode(seed))
val indexes = pow.genIndexes(seed, N)
//pk and w not used in v2
val elems = indexes.map(idx => pow.genElement(2, msg, null, null, Ints.toByteArray(idx), h))
val f2 = elems.sum
println("f2 (table elems sum): " + f2)
// sum as byte array is always about 32 bytes
val array: Array[Byte] = BigIntegers.asUnsignedByteArray(32, f2.underlying())
val hf = toBigInt(hash(array))
println("hf: " + hf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment