示例#1
0
 def testGetStr(self):
     P = G1()
     P.clear()
     self.assertEqual(P.getStr(), "0")
     self.assertEqual(
         G1.BLS12_381_G1_generator().getStr(),
         "1 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"
     )
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
 def testNeq(self):
     gen = G1.BLS12_381_G1_generator()
     self.assertTrue(gen != gen.double())
     self.assertFalse(gen != gen)
示例#5
0
 def testIsZero(self):
     gen = G1.BLS12_381_G1_generator()
     P = G1()
     P.clear()
     self.assertTrue(P.is_zero())
     self.assertFalse(gen.is_zero())
示例#6
0
 def testMul(self):
     gen = G1.BLS12_381_G1_generator()
     self.assertEqual(gen * Fr(2), gen.double())
示例#7
0
 def testSub(self):
     gen = G1.BLS12_381_G1_generator()
     self.assertEqual(gen.double() - gen, gen)
示例#8
0
            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)
示例#9
0
 def testSetGetStr(self):
     g1 = G1()
     g1.setStr(test_data.G1_STR)
     s = g1.getStr()
     self.assertEqual(test_data.G1_STR, s)
示例#10
0
 def testHashAndMapTo(self):
     g1 = G1.hashAndMapTo(b"test")
示例#11
0
 def testNeg(self):
     not G1()
示例#12
0
 def testMul(self):
     G1() * Fr()
示例#13
0
 def testSub(self):
     G1() - G1()
示例#14
0
 def testAdd(self):
     G1() + G1()
示例#15
0
 def testEqual(self):
     e1 = G1()
     e1.setStr(test_data.G1_STR)
     e2 = G1()
     e2.setStr(test_data.G1_STR)
     self.assertTrue(e1 == e2)
示例#16
0
 def testHashAndMapToG1(self):
     self.assertEqual(
         G1.hashAndMapToG1("test").getStr(),
         "1 1664126500441530256482751269291290703962889676827426721113973279626206305626152966034740921719739598015047469980014 2770511850529075397457134371943688177934498111089053025052575225110555843257818577745559532770169098874656481355098"
     )
示例#17
0
 def testAdd(self):
     gen = G1.BLS12_381_G1_generator()
     self.assertEqual(gen + gen, gen.double())
示例#18
0
 def testInitG1(self):
     self.assertIsNotNone(G1())