From 633b8c74cce4c1282e1e6d456191d82d7a0627ca Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Tue, 15 Mar 2022 01:41:15 -0700 Subject: [PATCH] translate clmul* to python for easier testing --- __init__.py | 0 clmul.py | 8 ++++++++ clmulh.py | 5 +++++ clmulr.py | 5 +++++ 4 files changed, 18 insertions(+) create mode 100644 __init__.py create mode 100644 clmul.py create mode 100644 clmulh.py create mode 100644 clmulr.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clmul.py b/clmul.py new file mode 100644 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 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 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) -- 2.30.2