|
def | __init__ (self, str seed_str, int prime, int num_rounds) |
|
int | encrypt (self, int message, int ek) |
|
bytes | hash (self, bytes left, bytes right) |
|
int | hash_int (self, int x, int y) |
|
int | mimc_round (self, int message, int key, int rc) |
|
Base class of MiMC implementations.
Definition at line 28 of file mimc.py.
◆ __init__()
def zeth.core.mimc.MiMCBase.__init__ |
( |
|
self, |
|
|
str |
seed_str, |
|
|
int |
prime, |
|
|
int |
num_rounds |
|
) |
| |
Definition at line 32 of file mimc.py.
37 self.seed = _keccak_256(_str_to_bytes(seed_str))
39 self.num_rounds = num_rounds
◆ encrypt()
int zeth.core.mimc.MiMCBase.encrypt |
( |
|
self, |
|
|
int |
message, |
|
|
int |
ek |
|
) |
| |
Definition at line 41 of file mimc.py.
45 result = message % self.prime
47 round_constant: int = self.seed
50 result = self.mimc_round(result, key, 0)
52 for _
in range(self.num_rounds - 1):
53 round_constant = _update_round_constant(round_constant)
54 result = self.mimc_round(result, key, round_constant)
57 return (result + key) % self.prime
◆ hash()
bytes zeth.core.mimc.MiMCBase.hash |
( |
|
self, |
|
|
bytes |
left, |
|
|
bytes |
right |
|
) |
| |
Apply Miyaguchi-Preneel to the output of the encrypt function.
Reimplemented from zeth.core.merkle_tree.ITreeHash.
Definition at line 59 of file mimc.py.
59 def hash(self, left: bytes, right: bytes) -> bytes:
61 Apply Miyaguchi-Preneel to the output of the encrypt function.
63 x = int.from_bytes(left, byteorder=
'big') % self.prime
64 y = int.from_bytes(right, byteorder=
'big') % self.prime
65 return self.hash_int(x, y).to_bytes(32, byteorder=
'big')
◆ hash_int()
int zeth.core.mimc.MiMCBase.hash_int |
( |
|
self, |
|
|
int |
x, |
|
|
int |
y |
|
) |
| |
Similar to hash, but use field elements directly.
Definition at line 67 of file mimc.py.
67 def hash_int(self, x: int, y: int) -> int:
69 Similar to hash, but use field elements directly.
73 return (self.encrypt(x, y) + x + y) % self.prime
◆ mimc_round()
int zeth.core.mimc.MiMCBase.mimc_round |
( |
|
self, |
|
|
int |
message, |
|
|
int |
key, |
|
|
int |
rc |
|
) |
| |
◆ num_rounds
zeth.core.mimc.MiMCBase.num_rounds |
◆ prime
zeth.core.mimc.MiMCBase.prime |
◆ seed
zeth.core.mimc.MiMCBase.seed |
The documentation for this class was generated from the following file:
- /home/runner/work/zeth/zeth/client/zeth/core/mimc.py