Note: the returned integer is `XLEN + 1` bits wide.
"""
v = ST.GFBREDPOLY & ((1 << ST.XLEN) - 1) # mask to XLEN bits
- if v == 0 or v == 2: # GF(2)
+ if v == 0: # GF(2)
return 0b10 # degree = 1, poly = x
if (v & 1) == 0:
# all reducing polynomials of degree > 1 must have the LSB set,
from nmigen_gf.reference.gfpmsub import gfpmsub
from nmigen_gf.reference.gfpmsubr import gfpmsubr
from nmigen_gf.reference.pack_poly import pack_poly, unpack_poly
+from nmigen_gf.reference.decode_reducing_polynomial import \
+ decode_reducing_polynomial
+from nmigen_gf.reference.is_irreducible import is_irreducible
import unittest
ST.reinit(XLEN=XLEN, GFBREDPOLY=REDPOLY)
return red_poly
+ def test_all_red_polys_covered(self):
+ for XLEN in 2, 4, 8, 16:
+ for rpoly in range(2 ** (XLEN + 1)):
+ if not is_irreducible(rpoly):
+ continue
+ REDPOLY = rpoly
+ if rpoly == 2:
+ REDPOLY = 0
+ elif rpoly >> XLEN:
+ REDPOLY %= 2 ** XLEN
+ REDPOLY &= ~1
+ with self.subTest(XLEN=XLEN, rpoly=hex(rpoly),
+ REDPOLY=hex(REDPOLY)):
+ ST.reinit(XLEN=XLEN, GFBREDPOLY=REDPOLY)
+ output = decode_reducing_polynomial()
+ with self.subTest(output=hex(output)):
+ self.assertEqual(rpoly, output)
+
def test_gfbmul(self):
# AES's finite field reducing polynomial
red_poly = self.init_aes_red_poly()
def elaborate(self, platform):
m = Module()
v = self.REDPOLY
- with m.If((v == 0) | (v == 0b10)): # GF(2)
+ with m.If(v == 0): # GF(2)
# degree = 1, poly = x
m.d.comb += self.reducing_polynomial.eq(0b10)
with m.Elif(v[0] == 0):