aboutsummaryrefslogtreecommitdiff
path: root/pyecsca/ec/mod.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyecsca/ec/mod.py')
-rw-r--r--pyecsca/ec/mod.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py
index 1fa3f9d..ec5dfe6 100644
--- a/pyecsca/ec/mod.py
+++ b/pyecsca/ec/mod.py
@@ -136,6 +136,9 @@ class Mod(object):
q, r = divmod(self.x, divisor.x)
return Mod(q, self.n), Mod(r, self.n)
+ def __bytes__(self):
+ return self.x.to_bytes((self.n.bit_length() + 7) // 8, byteorder="big")
+
@staticmethod
def random(n: int):
with RandomModAction(n):
@@ -224,6 +227,9 @@ class Undefined(Mod):
def __divmod__(self, divisor):
raise NotImplementedError
+ def __bytes__(self):
+ raise NotImplementedError
+
def __int__(self):
raise NotImplementedError