ChaChaBlock.scala 1001 Bytes
Newer Older
1
2
3
// SPDX-FileCopyrightText: 2021 Minyong Li <ml10g20@soton.ac.uk>
// SPDX-License-Identifier: CERN-OHL-W-2.0

4
5
6
7
package uk.ac.soton.ecs.can.core

import chisel3._

8
9
10
class ChaChaBlock(val regBetweenRounds: Boolean = true) extends MultiIOModule {
  val roundLoop = IO(Input(Bool()))
  val initialState = IO(Input(Vec(16, UInt(32.W))))
11
12
  val in = IO(Input(Vec(16, UInt(32.W))))
  val out = IO(Output(Vec(16, UInt(32.W))))
13

14
15
  private val columnRound = Module(ChaChaRound.columnar)
  private val diagonalRound = Module(ChaChaRound.diagonal)
16
17
18
19
  private val betweenRounds =
    if (regBetweenRounds) Reg(Vec(16, UInt(32.W)))
    else Wire(Vec(16, UInt(32.W)))
  private val afterRounds = Reg(Vec(16, UInt(32.W)))
20

21
22
  private val muxRoundLoop = Mux(roundLoop, afterRounds, in)
  private val sumInRound = in.zip(afterRounds).map { case (i, r) => i + r }
23

24
25
26
27
28
  columnRound.in := muxRoundLoop
  betweenRounds := columnRound.out
  diagonalRound.in := betweenRounds
  afterRounds := diagonalRound.out
  out := sumInRound
29
}