Skip to content

Convert secure int to secure field using mpc.convert() #99

Closed Answered by lschoe
abraj asked this question in Q&A
Discussion options

You must be logged in to vote

Right, those things won't work. It's a bit more complicated as we need to use random bits that "live" both as a secint and as a secfld256.

Here's some starter code that does the job. It may be sufficiently efficient for your case?

import secrets
from mpyc.runtime import mpc

secint = mpc.SecInt()
secfld256 = mpc.SecFld(256)

@mpc.coroutine
async def to(x):
    n = len(x)
    await mpc.returnType(secfld256, n)
    
    r = [secrets.randbits(1) for _ in range(n)]
    r_src = [secint.field(1-2*a) for a in r]
    r_src = mpc.input([secint(a) for a in r_src])
    r_src = list(map(list, zip(*r_src)))
    r_src = [mpc.prod(a) for a in r_src]
    r_src = [(1-a)/2 for a in r_src]
    c = mpc.vecto…

Replies: 6 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@abraj
Comment options

@abraj
Comment options

Comment options

You must be logged in to vote
1 reply
@abraj
Comment options

Answer selected by abraj
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@abraj
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants