reference/test_cl_gfb_gfp.py: test reducing polynomial that is XLEN+1 bits
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 15 May 2024 06:32:00 +0000 (23:32 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 15 May 2024 06:36:55 +0000 (23:36 -0700)
gf_reference/test_cl_gfb_gfp.py

index b4db911644655b04124e2ef5b1979b28aaa60211..a831639cbfa7d4edbfdf13abae6d3a78201f3fed 100644 (file)
@@ -540,10 +540,14 @@ class TestCL(unittest.TestCase):
 
 class TestGFBInstructions(unittest.TestCase):
     @staticmethod
-    def init_aes_red_poly():
+    def init_aes_red_poly(XLEN=8):
         # AES's finite field reducing polynomial
         red_poly = GF2Poly([1, 1, 0, 1, 1, 0, 0, 0, 1])
-        ST.reinit(GFBREDPOLY=pack_poly(red_poly.coefficients))
+        REDPOLY = pack_poly(red_poly.coefficients)
+        if REDPOLY >= 2 ** XLEN:
+            REDPOLY %= 2 ** XLEN
+            REDPOLY &= ~1
+        ST.reinit(XLEN=XLEN, GFBREDPOLY=REDPOLY)
         return red_poly
 
     def test_gfbmul(self):
@@ -561,9 +565,9 @@ class TestGFBInstructions(unittest.TestCase):
                     expectedv = pack_poly(expected.value.coefficients)
                     self.assertEqual(product, expectedv)
 
-    def test_gfbmadd(self):
+    def test_gfbmadd(self, XLEN=8):
         # AES's finite field reducing polynomial
-        red_poly = self.init_aes_red_poly()
+        red_poly = self.init_aes_red_poly(XLEN=XLEN)
         a_width = 5
         b_width = 4
         c_width = 4
@@ -582,6 +586,9 @@ class TestGFBInstructions(unittest.TestCase):
                         expectedv = pack_poly(expected.value.coefficients)
                         self.assertEqual(result, expectedv)
 
+    def test_gfbmadd_64(self):
+        self.test_gfbmadd(XLEN=64)
+
     def test_gfbinv(self):
         # AES's finite field reducing polynomial
         red_poly = self.init_aes_red_poly()