Verified Commit 0ed01c1d authored by Minyong Li's avatar Minyong Li 💬
Browse files

core.BlockInitializer{,Test}: remove RNGs

LFSR PRNGs cannot be properly implemented
parent db2f8baa
package uk.ac.soton.ecs.can.core package uk.ac.soton.ecs.can.core
import chisel3._ import chisel3._
import chisel3.util.random.GaloisLFSR
class BlockInitializer extends MultiIOModule { class BlockInitializer extends MultiIOModule {
val fillConstants = IO(Input(Bool())) val fillConstants = IO(Input(Bool()))
val generateKey = IO(Input(Bool()))
val incrementBlockCount = IO(Input(Bool())) val incrementBlockCount = IO(Input(Bool()))
val generateNonce = IO(Input(Bool()))
val in = IO(Input(Vec(16, UInt(32.W)))) val in = IO(Input(Vec(16, UInt(32.W))))
val out = IO(Output(Vec(16, UInt(32.W)))) val out = IO(Output(Vec(16, UInt(32.W))))
...@@ -17,9 +14,7 @@ class BlockInitializer extends MultiIOModule { ...@@ -17,9 +14,7 @@ class BlockInitializer extends MultiIOModule {
"h79622d32".U(32.W), "h79622d32".U(32.W),
"h6b206574".U(32.W) "h6b206574".U(32.W)
) )
private val randomKey = (0 until 16).map(_ => GaloisLFSR.maxPeriod(32))
private val incrementedBlockCount = in(12) + 1.U(32.W) private val incrementedBlockCount = in(12) + 1.U(32.W)
private val randomNonce = (0 until 3).map(_ => GaloisLFSR.maxPeriod(32))
private val io = in.zip(out) private val io = in.zip(out)
...@@ -27,15 +22,11 @@ class BlockInitializer extends MultiIOModule { ...@@ -27,15 +22,11 @@ class BlockInitializer extends MultiIOModule {
o := Mux(fillConstants, c, i) o := Mux(fillConstants, c, i)
} }
io.slice(4, 12).zip(randomKey).foreach { case ((i, o), k) => io.slice(4, 12).foreach { case (i, o) => o := i }
o := Mux(generateKey, k, i)
}
io(12) match { io(12) match {
case (i, o) => o := Mux(incrementBlockCount, incrementedBlockCount, i) case (i, o) => o := Mux(incrementBlockCount, incrementedBlockCount, i)
} }
io.takeRight(3).zip(randomNonce).foreach { case ((i, o), n) => io.takeRight(3).foreach { case (i, o) => o := i }
o := Mux(generateNonce, n, i)
}
} }
...@@ -25,23 +25,6 @@ class BlockInitializerTest extends FlatSpec with ChiselScalatestTester { ...@@ -25,23 +25,6 @@ class BlockInitializerTest extends FlatSpec with ChiselScalatestTester {
} }
} }
it should "randomly generate some keys when requested" in {
test(new BlockInitializer) { c =>
c.in.zip(input).foreach { case (p, n) => p.poke(n) }
c.generateKey.poke(true.B)
(0 until 10).foreach { _ =>
c.out.take(4).foreach(_.expect(0.U(32.W)))
c.out.slice(4, 12).foreach(o => assert(o.peek().litValue() != 0))
c.out.takeRight(4).foreach(_.expect(0.U(32.W)))
c.clock.step()
}
c.generateKey.poke(false.B)
c.out.foreach(_.expect(0.U(32.W)))
}
}
it should "increment the block count when requested" in { it should "increment the block count when requested" in {
test(new BlockInitializer) { c => test(new BlockInitializer) { c =>
c.in.zip(input).foreach { case (p, n) => p.poke(n) } c.in.zip(input).foreach { case (p, n) => p.poke(n) }
...@@ -59,20 +42,4 @@ class BlockInitializerTest extends FlatSpec with ChiselScalatestTester { ...@@ -59,20 +42,4 @@ class BlockInitializerTest extends FlatSpec with ChiselScalatestTester {
} }
} }
it should "randomly generate some nonce when requested" in {
test(new BlockInitializer) { c =>
c.in.zip(input).foreach { case (p, n) => p.poke(n) }
c.generateNonce.poke(true.B)
(0 until 10).foreach { _ =>
c.out.take(9).foreach(_.expect(0.U(32.W)))
c.out.takeRight(3).foreach(o => assert(o.peek().litValue() != 0))
c.clock.step()
}
c.generateNonce.poke(false.B)
c.out.foreach(_.expect(0.U(32.W)))
}
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment