diff options
| author | J08nY | 2024-07-12 13:59:32 +0200 |
|---|---|---|
| committer | J08nY | 2024-07-12 13:59:32 +0200 |
| commit | bbef33efb9b37920e268124f443012cb85314a04 (patch) | |
| tree | 3865e2ed624f4bed7939db2fae95a6b15625a4be /pyecsca | |
| parent | 1e41f6e79980fd7c5a3686edefac7d48ed8094dc (diff) | |
| download | pyecsca-bbef33efb9b37920e268124f443012cb85314a04.tar.gz pyecsca-bbef33efb9b37920e268124f443012cb85314a04.tar.zst pyecsca-bbef33efb9b37920e268124f443012cb85314a04.zip | |
Add faster modulus checks for other special methods.
Diffstat (limited to 'pyecsca')
| -rw-r--r-- | pyecsca/ec/mod.py | 28 |
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" |
