ChaChaBlock.scala 749 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
class ChaChaBlock extends Module {
9
10
11
12
13
14
15
  val io = IO(new Bundle {
    val muxIn = Input(Bool())
    val in = Input(Vec(16, UInt(32.W)))
    val out = Output(Vec(16, UInt(32.W)))
  })

  val initialState = Reg(Vec(16, UInt(32.W)))
16
  val doubleRound = Module(new ChaChaInnerBlock(regBetweenRounds = true))
17
18
19
20
21
22
23
24
25
26
  val doubleRoundState = Reg(Vec(16, UInt(32.W)))

  initialState := io.in
  doubleRound.io.in := Mux(io.muxIn, initialState, doubleRoundState)
  doubleRoundState := doubleRound.io.out

  val addedState = doubleRoundState.zip(initialState).map(t => t._1 + t._2)

  io.out := addedState
}