Package: pymife
PyMIFEMulti input functional encryption library for pythonInstallationpipinstallpymifeSchemesSingle input inner product(Selective Secure) DDH based scheme fromhttps://eprint.iacr.org/2015/017.pdf(Selective Secure) LWE based scheme fromhttps://eprint.iacr.org/2015/017.pdf(Adaptive Secure) Damgard based scheme fromhttps://eprint.iacr.org/2015/608.pdf(Adaptive Secure) LWE based scheme fromhttps://eprint.iacr.org/2015/608.pdfMulti input inner product(Adaptive Secure) Damgard based scheme fromhttps://eprint.iacr.org/2017/972.pdfMulti client inner product(Adaptive Secure with Random Oracle) DDH based scheme fromhttps://eprint.iacr.org/2017/989.pdf(Adaptive Secure) Damgard based scheme fromhttps://eprint.iacr.org/2019/487.pdf, using Damgard single inputNoteThe implementation of these schemes are not fully optimized and not peer-reviewed, recommended to only use for research / testing purpose.More schemes will be added in the futureUsageSingle input inner productDDH based schemefrommife.single.selective.ddhimportFeDDHn=10x=[iforiinrange(n)]y=[i+10foriinrange(n)]key=FeDDH.generate(n)c=FeDDH.encrypt(x,key)sk=FeDDH.keygen(y,key)m=FeDDH.decrypt(c,key.get_public_key(),sk,(0,1000))LWE based schemefrommife.single.selective.lweimportFeLWEn=10x=[i-10foriinrange(n)]y=[iforiinrange(n)]key=FeLWE.generate(n,4,4)c=FeLWE.encrypt(x,key)sk=FeLWE.keygen(y,key)m=FeLWE.decrypt(c,key.get_public_key(),sk)%key.p(Adaptive Secure) Damgard based schemefrommife.single.damgardimportFeDamgardn=10x=[iforiinrange(n)]y=[i+10foriinrange(n)]key=FeDamgard.generate(n)c=FeDamgard.encrypt(x,key)sk=FeDamgard.keygen(y,key)m=FeDamgard.decrypt(c,key.get_public_key(),sk,(0,1000))(Adaptive Secure) LWE based schemefrommife.single.lweimportFeLWEn=10x=[i-10foriinrange(n)]y=[iforiinrange(n)]key=FeLWE.generate(n,4,4)c=FeLWE.encrypt(x,key)sk=FeLWE.keygen(y,key)m=FeLWE.decrypt(c,key.get_public_key(),sk)Multi input inner productDamgard based schemefrommife.multi.damgardimportFeDamgardMultin=3m=5x=[[i+jforjinrange(m)]foriinrange(n)]y=[[i-j+10forjinrange(m)]foriinrange(n)]key=FeDamgardMulti.generate(n,m)cs=[FeDamgardMulti.encrypt(x[i],key.get_enc_key(i))foriinrange(n)]sk=FeDamgardMulti.keygen(y,key)m=FeDamgardMulti.decrypt(cs,key.get_public_key(),sk,(0,2000))Using Curve25519frommife.multi.damgardimportFeDamgardMultifrommife.data.curve25519importCurve25519n=25m=25x=[[i*10+jforjinrange(m)]foriinrange(n)]y=[[i-j-5forjinrange(m)]foriinrange(n)]key=FeDamgardMulti.generate(n,m,Curve25519)cs=[FeDamgardMulti.encrypt(x[i],key.get_enc_key(i))foriinrange(n)]sk=FeDamgardMulti.keygen(y,key)res=FeDamgardMulti.decrypt(cs,key.get_public_key(),sk,(-10000000,10000000))Using P256 from fastecdsafrommife.multi.damgardimportFeDamgardMultifrommife.data.fastecdsa_wrapperimportWrapCurvefromfastecdsa.curveimportP256n=25m=25x=[[i*10+jforjinrange(m)]foriinrange(n)]y=[[i-j-5forjinrange(m)]foriinrange(n)]key=FeDamgardMulti.generate(n,m,WrapCurve(P256))cs=[FeDamgardMulti.encrypt(x[i],key.get_enc_key(i))foriinrange(n)]sk=FeDamgardMulti.keygen(y,key)res=FeDamgardMulti.decrypt(cs,key.get_public_key(),sk,(-10000000,10000000))Multi client inner product(Random Oracle) DDH based schemefrommife.multiclient.rom.ddhimportFeDDHMultiClientn=3m=5x=[[i+jforjinrange(m)]foriinrange(n)]y=[[i-j+10forjinrange(m)]foriinrange(n)]tag=b"testingtag123"key=FeDDHMultiClient.generate(n,m)cs=[FeDDHMultiClient.encrypt(x[i],tag,key.get_enc_key(i))foriinrange(n)]sk=FeDDHMultiClient.keygen(y,key)m=FeDDHMultiClient.decrypt(cs,tag,key.get_public_key(),sk,(0,2000))Damgard based schemefrommife.multiclient.damgardimportFeDamgardMultiClientn=3m=5x=[[i+jforjinrange(m)]foriinrange(n)]y=[[i-j+10forjinrange(m)]foriinrange(n)]tag=b"testingtag123"key=FeDamgardMultiClient.generate(n,m)cs=[FeDamgardMultiClient.encrypt(x[i],tag,key.get_enc_key(i),key.get_public_key())foriinrange(n)]sk=FeDamgardMultiClient.keygen(y,key)m=FeDamgardMultiClient.decrypt(cs,key.get_public_key(),sk,(0,2000))Export Keysfrommife.multiclient.rom.ddhimportFeDDHMultiClientimportjsonn=3m=5x=[[i+jforjinrange(m)]foriinrange(n)]y=[[i-j+10forjinrange(m)]foriinrange(n)]tag=b"testingtag123"key=FeDDHMultiClient.generate(n,m)cs=[FeDDHMultiClient.encrypt(x[i],tag,key.get_enc_key(i))foriinrange(n)]sk=FeDDHMultiClient.keygen(y,key)print(f"enc_key ={json.dumps([key.get_enc_key(i).export()foriinrange(n)])}")print(f"msk ={json.dumps(key.export())}")print(f"ct ={[json.dumps(cs[i].export())foriinrange(n)]}")print(f"secret_key ={json.dumps(sk.export())}")print(f"pub_key ={json.dumps(key.get_public_key().export())}")CustomizeAll of the DDH and Damgard schemes support custom group. You can implement your own group class by extending/src/mife/data/group.pyas base class.To use custom group, simply pass the group class to thegeneratefunction.This library has implemented prime order group and curve25519 group.For MCFE-DDH scheme, you can also supply your own hash function by using the same signature as the default hash function found in/src/mife/multiclient/ddh.py.Referenceshttps://eprint.iacr.org/2015/017.pdfhttps://eprint.iacr.org/2015/608.pdfhttps://eprint.iacr.org/2017/972.pdfhttps://eprint.iacr.org/2017/989.pdfhttps://eprint.iacr.org/2019/487.pdfhttps://github.com/fentec-project/CiFEr/blob/master/src/innerprod/simple/lwe.cr2html