Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Member Functions | Public Attributes | List of all members
zeth.core.mimc.MiMCBase Class Reference
Inheritance diagram for zeth.core.mimc.MiMCBase:
Inheritance graph
[legend]
Collaboration diagram for zeth.core.mimc.MiMCBase:
Collaboration graph
[legend]

Public Member Functions

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)
 

Public Attributes

 seed
 
 prime
 
 num_rounds
 

Detailed Description

Base class of MiMC implementations.

Definition at line 28 of file mimc.py.

Constructor & Destructor Documentation

◆ __init__()

def zeth.core.mimc.MiMCBase.__init__ (   self,
str  seed_str,
int  prime,
int  num_rounds 
)

Definition at line 32 of file mimc.py.

32  def __init__(
33  self,
34  seed_str: str,
35  prime: int,
36  num_rounds: int):
37  self.seed = _keccak_256(_str_to_bytes(seed_str))
38  self.prime = prime
39  self.num_rounds = num_rounds
40 

Member Function Documentation

◆ encrypt()

int zeth.core.mimc.MiMCBase.encrypt (   self,
int  message,
int  ek 
)

Definition at line 41 of file mimc.py.

41  def encrypt(
42  self,
43  message: int,
44  ek: int) -> int:
45  result = message % self.prime
46  key = ek % self.prime
47  round_constant: int = self.seed
48 
49  # The round constant in round 0 is 0 (see [AGRRT16])
50  result = self.mimc_round(result, key, 0)
51 
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)
55 
56  # Add key to the final result (see [AGRRT16])
57  return (result + key) % self.prime
58 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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:
60  """
61  Apply Miyaguchi-Preneel to the output of the encrypt function.
62  """
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')
66 
Here is the call graph for this function:

◆ 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:
68  """
69  Similar to hash, but use field elements directly.
70  """
71  assert x < self.prime
72  assert y < self.prime
73  return (self.encrypt(x, y) + x + y) % self.prime
74 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mimc_round()

int zeth.core.mimc.MiMCBase.mimc_round (   self,
int  message,
int  key,
int  rc 
)

Reimplemented in zeth.core.mimc.MiMC17Base.

Definition at line 76 of file mimc.py.

76  def mimc_round(self, message: int, key: int, rc: int) -> int:
77  pass
78 
79 
Here is the caller graph for this function:

Member Data Documentation

◆ num_rounds

zeth.core.mimc.MiMCBase.num_rounds

Definition at line 35 of file mimc.py.

◆ prime

zeth.core.mimc.MiMCBase.prime

Definition at line 34 of file mimc.py.

◆ seed

zeth.core.mimc.MiMCBase.seed

Definition at line 33 of file mimc.py.


The documentation for this class was generated from the following file:
zeth.core.encryption.encrypt
bytes encrypt(bytes message, EncryptionPublicKey pk_receiver)
Definition: encryption.py:168