### core.ChaChaBlock{,Test}: merge w/ ChaChaInnerBlock

`A redesign is also performed.`
parent 052643e4
 ... @@ -5,20 +5,25 @@ package uk.ac.soton.ecs.can.core ... @@ -5,20 +5,25 @@ package uk.ac.soton.ecs.can.core import chisel3._ import chisel3._ class ChaChaBlock extends MultiIOModule { class ChaChaBlock(val regBetweenRounds: Boolean = true) extends MultiIOModule { val muxIn = IO(Input(Bool())) val roundLoop = IO(Input(Bool())) val initialState = IO(Input(Vec(16, UInt(32.W)))) 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)))) val initialState = Reg(Vec(16, UInt(32.W))) private val columnRound = Module(new ColumnRound) val doubleRound = Module(new ChaChaInnerBlock(regBetweenRounds = true)) private val diagonalRound = Module(new DiagonalRound) val doubleRoundState = Reg(Vec(16, UInt(32.W))) 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))) initialState := in private val muxRoundLoop = Mux(roundLoop, afterRounds, in) doubleRound.in := Mux(muxIn, initialState, doubleRoundState) private val sumInRound = in.zip(afterRounds).map { case (i, r) => i + r } doubleRoundState := doubleRound.out val addedState = doubleRoundState.zip(initialState).map(t => t._1 + t._2) columnRound.in := muxRoundLoop betweenRounds := columnRound.out out := addedState diagonalRound.in := betweenRounds afterRounds := diagonalRound.out out := sumInRound } }
 // SPDX-FileCopyrightText: 2021 Minyong Li // SPDX-License-Identifier: CERN-OHL-W-2.0 package uk.ac.soton.ecs.can.core import chisel3._ class ChaChaInnerBlock(regBetweenRounds: Boolean) extends MultiIOModule { val in = IO(Input(Vec(16, UInt(32.W)))) val out = IO(Output(Vec(16, UInt(32.W)))) val betweenRounds = if (regBetweenRounds) Reg(Vec(16, UInt(32.W))) else Wire(Vec(16, UInt(32.W))) val columnRound = Module(new ColumnRound) val diagonalRound = Module(new DiagonalRound) columnRound.in := in betweenRounds := columnRound.out diagonalRound.in := betweenRounds out := diagonalRound.out }
 ... @@ -64,40 +64,43 @@ class ChaChaBlockTest extends FlatSpec with ChiselScalatestTester { ... @@ -64,40 +64,43 @@ class ChaChaBlockTest extends FlatSpec with ChiselScalatestTester { ) ) private def doTest(c: ChaChaBlock, testVector: Seq[(UInt, UInt)]) { private def doTest(c: ChaChaBlock, testVector: Seq[(UInt, UInt)]) { c.in.zip(testVector).foreach { t => c.in.zip(testVector).foreach { case (blockIn, (vectorIn, _)) => t._1.poke(t._2._1) blockIn.poke(vectorIn) } } // Shift inputs into the initial state register // Select the input port as the input to the rounds c.clock.step() c.roundLoop.poke(false.B) // Select the initial state register as the input to the 2-round circuit // Shift the state through the rounds c.muxIn.poke(true.B) c.clock.step(if (c.regBetweenRounds) 2 else 1) // Shift the 2-rounded state to the round register // Select the round register as the input to the rounds c.clock.step(2) c.roundLoop.poke(true.B) // Select the round register as the input to the 2-round circuit c.muxIn.poke(false.B) // Depending on the ChaCha variant and the pipeline configuration, wait // Depending on the ChaCha variant and the pipeline configuration, wait // for the correct time for the correct result. Note that one 2-round has // for the correct time for the correct result. Note that one 2-round has // been processed in the above steps. // been processed in the above steps. c.clock.step(19) c.clock.step(if (c.regBetweenRounds) 19 else 9) c.out.zip(testVector).foreach { t => c.out.zip(testVector).foreach { case (blockOut, (_, vectorOut)) => t._1.expect(t._2._2) blockOut.expect(vectorOut) } } } } behavior of "The ChaCha Block Function" behavior of "The ChaCha Block Function" it should "compute RFC8439 2.3.2 test vector correctly" in it should "compute RFC8439 2.3.2 test vector correctly" in { test(new ChaChaBlock)(doTest(_, rfc8439232TestVector)) test(new ChaChaBlock(true))(doTest(_, rfc8439232TestVector)) test(new ChaChaBlock(false))(doTest(_, rfc8439232TestVector)) } it should "compute RFC8439 2.4.2 test vector (first block) correctly" in it should "compute RFC8439 2.4.2 test vector (first block) correctly" in { test(new ChaChaBlock)(doTest(_, rfc8439242B1TestVector)) test(new ChaChaBlock(true))(doTest(_, rfc8439242B1TestVector)) test(new ChaChaBlock(false))(doTest(_, rfc8439242B1TestVector)) } it should "compute RFC8439 2.4.2 test vector (second block) correctly" in it should "compute RFC8439 2.4.2 test vector (second block) correctly" in { test(new ChaChaBlock)(doTest(_, rfc8439242B2TestVector)) test(new ChaChaBlock(true))(doTest(_, rfc8439242B2TestVector)) test(new ChaChaBlock(false))(doTest(_, rfc8439242B2TestVector)) } } }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
{"ft_lang_label":"__label__en","ft_lang_prob":0.5615233,"math_prob":0.9807259,"size":5443,"snap":"2022-27-2022-33","text_gpt3_token_len":1602,"char_repetition_ratio":0.13642214,"word_repetition_ratio":0.2828439,"special_character_ratio":0.3092045,"punctuation_ratio":0.2032032,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98215884,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-03T03:22:18Z\",\"WARC-Record-ID\":\"<urn:uuid:7de844b5-3943-4fbe-82f5-7b996bbe2009>\",\"Content-Length\":\"349156\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c9b9db09-d436-4b90-8a45-8877212101ba>\",\"WARC-Concurrent-To\":\"<urn:uuid:bdc1c488-54c5-45d5-a4c4-adc9967ad37c>\",\"WARC-IP-Address\":\"152.78.118.179\",\"WARC-Target-URI\":\"https://git.soton.ac.uk/ml10g20/can/-/commit/e2b4b3249c887a8a9687fa45d4225e95b53db19b?view=parallel\",\"WARC-Payload-Digest\":\"sha1:RU7VX6ONCH3SBQZHSIC6ZU6N66YVCNU7\",\"WARC-Block-Digest\":\"sha1:XRSNSHD5TQ5YQG4NHV7PBPKOSV2FVSZB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104209449.64_warc_CC-MAIN-20220703013155-20220703043155-00318.warc.gz\"}"}