aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca
diff options
context:
space:
mode:
Diffstat (limited to 'pyecsca')
-rw-r--r--pyecsca/ec/mod.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py
index b996d40..9e579b1 100644
--- a/pyecsca/ec/mod.py
+++ b/pyecsca/ec/mod.py
@@ -839,9 +839,17 @@ if has_flint:
return FlintMod(self.x + other.x, self._ctx, ensure=False)
@_flint_check
+ def __radd__(self, other) -> "Mod":
+ return self + other
+
+ @_flint_check
def __sub__(self, other) -> "FlintMod":
return FlintMod(self.x - other.x, self._ctx, ensure=False)
+ @_flint_check
+ def __rsub__(self, other) -> "Mod":
+ return -self + other
+
def __neg__(self) -> "FlintMod":
return FlintMod(-self.x, self._ctx, ensure=False)
@@ -849,6 +857,26 @@ if has_flint:
def __mul__(self, other) -> "FlintMod":
return FlintMod(self.x * other.x, self._ctx, ensure=False)
+ @_flint_check
+ def __rmul__(self, other) -> "Mod":
+ return self * other
+
+ @_flint_check
+ def __truediv__(self, other) -> "Mod":
+ return self * ~other
+
+ @_flint_check
+ def __rtruediv__(self, other) -> "Mod":
+ return ~self * other
+
+ @_flint_check
+ def __floordiv__(self, other) -> "Mod":
+ return self * ~other
+
+ @_flint_check
+ def __rfloordiv__(self, other) -> "Mod":
+ return ~self * other
+
def __bytes__(self):
return int(self.x).to_bytes(
(int(self.n).bit_length() + 7) // 8, byteorder="big"