def testGetStr(self): P = G1() P.clear() self.assertEqual(P.getStr(), "0") self.assertEqual( G1.BLS12_381_G1_generator().getStr(), "1 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569" )
def testNeq(self): g1 = G1() g1.setStr(test_data.G1_STR) random_fr = Fr() random_fr.setByCSPRNG() random_fr2 = Fr() random_fr2.setByCSPRNG() self.assertNotEqual(g1 * random_fr, g1 * random_fr2)
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 testNeq(self): gen = G1.BLS12_381_G1_generator() self.assertTrue(gen != gen.double()) self.assertFalse(gen != gen)
def testIsZero(self): gen = G1.BLS12_381_G1_generator() P = G1() P.clear() self.assertTrue(P.is_zero()) self.assertFalse(gen.is_zero())
def testMul(self): gen = G1.BLS12_381_G1_generator() self.assertEqual(gen * Fr(2), gen.double())
def testSub(self): gen = G1.BLS12_381_G1_generator() self.assertEqual(gen.double() - gen, gen)
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 return (r_list, s) if __name__ == "__main__": msg = "Master Thesis" g = G1.hashAndMapToG1("DVS") sk_p, pk_p, sk_v, pk_v = keygen(g) # print(sk_p, pk_p, sk_v, pk_v ) sk_t, pk_t, sk_z, pk_z = keygen(g) # print(sk_t, pk_t, sk_z, pk_z) # R, s = sign(g, msg, [pk_p, pk_v], sk_p, 0, 1) R, s = sim(g, msg, [pk_p, pk_v], sk_v, 0, 1) verify(g, msg, [pk_p, pk_v], sk_v, 0, 1, R, s)
def testSetGetStr(self): g1 = G1() g1.setStr(test_data.G1_STR) s = g1.getStr() self.assertEqual(test_data.G1_STR, s)
def testHashAndMapTo(self): g1 = G1.hashAndMapTo(b"test")
def testNeg(self): not G1()
def testMul(self): G1() * Fr()
def testSub(self): G1() - G1()
def testAdd(self): G1() + G1()
def testEqual(self): e1 = G1() e1.setStr(test_data.G1_STR) e2 = G1() e2.setStr(test_data.G1_STR) self.assertTrue(e1 == e2)
def testHashAndMapToG1(self): self.assertEqual( G1.hashAndMapToG1("test").getStr(), "1 1664126500441530256482751269291290703962889676827426721113973279626206305626152966034740921719739598015047469980014 2770511850529075397457134371943688177934498111089053025052575225110555843257818577745559532770169098874656481355098" )
def testAdd(self): gen = G1.BLS12_381_G1_generator() self.assertEqual(gen + gen, gen.double())
def testInitG1(self): self.assertIsNotNone(G1())