def testGetStr(self): P = G2() P.clear() self.assertEqual(P.getStr(), "0") self.assertEqual( G2.BLS12_381_G2_generator().getStr(), "1 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582" )
def sim(g, msg, pks, sk, p_id, v_id): a_list = [] r_list = [] h_list = [] for i in range(len(pks)): if i == v_id: a_list.append(None) r_list.append(None) h_list.append(None) else: a_i = Fr() a_i.set_by_CSPRNG() a_list.append(a_i) r_i = g * a_i r_list.append(r_i) h_i = Fr.set_hash_of(f"{msg}{r_i.getStr()}") h_list.append(h_i) a = Fr() a.set_by_CSPRNG() r = (g * a) + reduce( operator.add, [pks[i] * h_list[i].neg() for i in range(len(pks)) if i != v_id]) h = Fr.set_hash_of(f"{msg}{r.getStr()}") s = reduce( operator.add, [a_list[i] + a + (sk * h) for i in range(len(pks)) if i != v_id]) r_list[v_id] = r * sk g_hat = G2.hashAndMapToG2(f'{msg}{r_list}{pks}') S = g_hat * s return (r_list, S)
def verify(g, msg, pks, sk, p_id, v_id, R, S): g_hat = G2.hashAndMapToG2(f'{msg}{R}{pks}') R[v_id] = R[v_id] * sk.inv() h_list = [] for i in range(len(pks)): h_i = Fr.set_hash_of(f"{msg}{R[i].getStr()}") h_list.append(h_i) prod = R[v_id] + (pks[v_id] * h_list[v_id]) for i in range(len(pks)): if i == v_id: continue else: prod += R[i] + (pks[i] * h_list[i]) assert pairing(g, S) == pairing(prod, g_hat)
def testPairing(self): fr1 = Fr() fr1.setByCSPRNG() g1 = G1() g1.setStr(test_data.G1_STR) g2 = G2() g2.setStr(test_data.G2_STR) fr2 = Fr() fr2.setByCSPRNG() gt = GT.pairing(g1 * fr1, g2 * fr2) self.assertIsNotNone(gt)
def testAdd(self): gen = G2.BLS12_381_G2_generator() self.assertEqual(gen + gen, gen.double())
def testHashAndMapToG2(self): self.assertEqual( G2.hashAndMapToG2("test").getStr(), "1 3035410284670172822278382403907957115899337120663486077801493809533423924318135197683333296400242994086357673794613 1785141689185704244408511370343548582455844354038743678281465122886880406332213470381122199452223171130208308480869 1368740321157085535728641591680992724049630704543547765519682150483834212857623630342844610363547815367196638166789 2757256452659599929159715569400251080685640247308155348704439120375220684577877691557778850755152690283407968072052" )
def testNeq(self): gen = G2.BLS12_381_G2_generator() self.assertTrue(gen != gen.double()) self.assertFalse(gen != gen)
def testIsZero(self): gen = G2.BLS12_381_G2_generator() P = G2() P.clear() self.assertTrue(P.is_zero()) self.assertFalse(gen.is_zero())
def testMul(self): gen = G2.BLS12_381_G2_generator() self.assertEqual(gen * Fr(2), gen.double())
def testAdd(self): G2() + G2()
def testInitG2(self): self.assertIsNotNone(G2())
def testHashAndMapTo(self): g1 = G2.hashAndMapTo(b"test")
def testNeg(self): not G2()
def testMul(self): G2() * Fr()
def testSub(self): G2() - G2()
def testSub(self): gen = G2.BLS12_381_G2_generator() self.assertEqual(gen.double() - gen, gen)
def testSetGetStr(self): g2 = G2() g2.setStr(test_data.G2_STR) s = g2.getStr() self.assertEqual(test_data.G2_STR, s)