[she] add isZero

pull/2/head
MITSUNARI Shigeo 6 years ago
parent 189c2fa0e2
commit 8d54609260
  1. 15
      ffi/python/she.py

@ -186,6 +186,14 @@ class SecretKey(Structure):
if ret != 0: if ret != 0:
raise RuntimeError("dec") raise RuntimeError("dec")
return m.value return m.value
def isZero(self, c):
if isinstance(c, CipherTextG1):
return lib.sheIsZeroG1(byref(self.v), byref(c.v)) == 1
elif isinstance(c, CipherTextG2):
return lib.sheIsZeroG2(byref(self.v), byref(c.v)) == 1
elif isinstance(c, CipherTextGT):
return lib.sheIsZeroGT(byref(self.v), byref(c.v)) == 1
raise RuntimeError("dec")
def neg(c): def neg(c):
ret = -1 ret = -1
@ -307,6 +315,13 @@ if __name__ == '__main__':
# mul G1 and G2 # mul G1 and G2
if sec.dec(mul(c11, c21)) != m11 * m21: print("err8") if sec.dec(mul(c11, c21)) != m11 * m21: print("err8")
if not sec.isZero(pub.encG1(0)): print("err-zero11")
if sec.isZero(pub.encG1(3)): print("err-zero12")
if not sec.isZero(pub.encG2(0)): print("err-zero21")
if sec.isZero(pub.encG2(3)): print("err-zero22")
if not sec.isZero(pub.encGT(0)): print("err-zero31")
if sec.isZero(pub.encGT(3)): print("err-zero32")
# use precomputedPublicKey for performance # use precomputedPublicKey for performance
ppub = pub.createPrecomputedPublicKey() ppub = pub.createPrecomputedPublicKey()
c1 = ppub.encG1(m11) c1 = ppub.encG1(m11)

Loading…
Cancel
Save