Add rtl for friendly_modulo
This commit is contained in:
@@ -4,4 +4,10 @@ tests:
|
||||
modules:
|
||||
- "poly1305_core"
|
||||
sources: "sources.list"
|
||||
waves: True
|
||||
- name: "friendly_modulo"
|
||||
toplevel: "poly1305_friendly_modulo"
|
||||
modules:
|
||||
- "poly1305_friendly_modulo"
|
||||
sources: sources.list
|
||||
waves: True
|
||||
62
ChaCha20_Poly1305_64/sim/poly1305_friendly_modulo.py
Normal file
62
ChaCha20_Poly1305_64/sim/poly1305_friendly_modulo.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import logging
|
||||
|
||||
|
||||
import cocotb
|
||||
from cocotb.clock import Clock
|
||||
from cocotb.triggers import Timer, RisingEdge, FallingEdge
|
||||
from cocotb.queue import Queue
|
||||
|
||||
from cocotbext.axi import AxiStreamBus, AxiStreamSource
|
||||
|
||||
import random
|
||||
|
||||
PRIME = 2**130-5
|
||||
|
||||
CLK_PERIOD = 4
|
||||
|
||||
|
||||
class TB:
|
||||
def __init__(self, dut):
|
||||
self.dut = dut
|
||||
|
||||
self.log = logging.getLogger("cocotb.tb")
|
||||
self.log.setLevel(logging.INFO)
|
||||
|
||||
cocotb.start_soon(Clock(self.dut.i_clk, CLK_PERIOD, units="ns").start())
|
||||
|
||||
async def cycle_reset(self):
|
||||
await self._cycle_reset(self.dut.i_rst, self.dut.i_clk)
|
||||
|
||||
async def _cycle_reset(self, rst, clk):
|
||||
rst.setimmediatevalue(0)
|
||||
await RisingEdge(clk)
|
||||
await RisingEdge(clk)
|
||||
rst.value = 1
|
||||
await RisingEdge(clk)
|
||||
await RisingEdge(clk)
|
||||
rst.value = 0
|
||||
await RisingEdge(clk)
|
||||
await RisingEdge(clk)
|
||||
|
||||
@cocotb.test
|
||||
async def test_sanity(dut):
|
||||
tb = TB(dut)
|
||||
|
||||
await tb.cycle_reset()
|
||||
|
||||
value_a = random.randint(1,2**(130+16))
|
||||
|
||||
# value_a = PRIME + 1000000
|
||||
tb.dut.i_valid.value = 1
|
||||
tb.dut.i_val.value = value_a
|
||||
await RisingEdge(tb.dut.i_clk)
|
||||
tb.dut.i_valid.value = 0
|
||||
tb.dut.i_val.value = 0
|
||||
|
||||
await RisingEdge(tb.dut.o_valid)
|
||||
value = tb.dut.o_result.value.integer
|
||||
|
||||
print(value_a % PRIME)
|
||||
print(value)
|
||||
|
||||
await Timer(1, "us")
|
||||
Reference in New Issue
Block a user