translate clmul* to python for easier testing
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 15 Mar 2022 08:41:15 +0000 (01:41 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Tue, 15 Mar 2022 08:41:15 +0000 (01:41 -0700)
__init__.py [new file with mode: 0644]
clmul.py [new file with mode: 0644]
clmulh.py [new file with mode: 0644]
clmulr.py [new file with mode: 0644]

diff --git a/__init__.py b/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/clmul.py b/clmul.py
new file mode 100644 (file)
index 0000000..7451c3c
--- /dev/null
+++ b/clmul.py
@@ -0,0 +1,8 @@
+def clmul(a, b):
+    x = 0
+    i = 0
+    while b >> i != 0:
+        if (b >> i) & 1:
+            x ^= a << i
+        i += 1
+    return x
diff --git a/clmulh.py b/clmulh.py
new file mode 100644 (file)
index 0000000..b170aca
--- /dev/null
+++ b/clmulh.py
@@ -0,0 +1,5 @@
+from .clmul import clmul
+
+
+def clmulh(a, b, XLEN):
+    return clmul(a, b) >> XLEN
diff --git a/clmulr.py b/clmulr.py
new file mode 100644 (file)
index 0000000..5b155b5
--- /dev/null
+++ b/clmulr.py
@@ -0,0 +1,5 @@
+from .clmul import clmul
+
+
+def clmulh(a, b, XLEN):
+    return clmul(a, b) >> (XLEN - 1)