def mimc_encrypt(key, ms): """ ms - blocks of plaintext, that is, plaintext -> {m1, m2,...,ml} Each plaintext is a field element. ciphertext <- F_MiMC(counter, key) + plaintext """ return [mimc_plain(idx, key) + m for (idx, m) in enumerate(ms)]
def mimc_encrypt(pub_key, ms, seed=None): """ Encrypts blocks of plaintext data using counter-mode encryption. args: pub_key (Point): public key for encryption ms (list): list of message/plaintext data to encode seed(int): seed to use for random generation in encryption output: ciphertext (list): encoded blocks a_ (Point) auxilliary point sent to caller for decryption """ # Randomly generated variable hold only by the dealer a = Jubjub.Field.random() if seed is None else seed # Auxiliary variable needed for decryption a_ = a * GP # secret key kept by dealer k = (a * pub_key).x # ciphertext sent to user ciphertext = [mimc_plain(idx, k) + m for (idx, m) in enumerate(ms)] return (ciphertext, a_)
async def _prog(context): xs = [context.preproc.get_rand(context) for _ in range(20)] # Compute F_MiMC_mpc, mm - mimc_mpc mm = await mimc_mpc_batch(context, xs, key) mm_open = await context.ShareArray(mm).open() # open x, then compute F_MiMC_plain, mp - mimc_plain xs_open = await context.ShareArray(xs).open() mp = [mimc_plain(x, key) for x in xs_open] # Compare the MPC evaluation to the plain one assert mm_open == mp
async def _prog(context): x = context.preproc.get_zero(context) field = GF(Subgroup.BLS12_381) key = field(15) # Compute F_MiMC_mpc mm = await mimc_mpc(context, x, key) mm_open = await mm.open() # open x, then compute F_MiMC_plain x_open = await x.open() mp = mimc_plain(x_open, key) # Compare the MPC evaluation to the plain one assert mm_open == mp