Exemple #1
0
 def __init__(self, p, a, b, q, g_y, l):
     self.g_point = ECPoint(0, g_y, a, b, p)
     self.q = q
     self.a = a
     self.b = b
     self.p = p
     self.l = l
 def verify(self, message, sign, public_key):
     e = message % self.q
     if e == 0:
         e = 1
     nu = ECPoint._mod_inverse(e, self.q)
     z1 = (sign[1] * nu) % self.q
     z2 = (-sign[0] * nu) % self.q
     c_point = z1 * self.p_point + z2 * public_key
     r = c_point.x % self.q
     if r == sign[0]:
         return True
     return False
Exemple #3
0
 def verify(self, message, sign, public_key):
     e = message % self.q
     if e == 0:
         e = 1
     nu = ECPoint._mod_inverse(e, self.q)
     z1 = (sign[1] * nu) % self.q
     z2 = (-sign[0] * nu) % self.q
     c_point = z1 * self.p_point + z2 * public_key
     r = c_point.x % self.q
     if r == sign[0]:
         return True
     return False
Exemple #4
0
 def test_gost_verify(self):
     p = 57896044618658097711785492504343953926634992332820282019728792003956564821041
     a = 7
     b = 43308876546767276905765904595650931995942111794451039583252968842033849580414
     x = 2
     y = 4018974056539037503335449422937059775635739389905545080690979365213431566280
     q = 57896044618658097711785492504343953927082934583725450622380973592137631069619
     gost = DSGOST(p, a, b, q, x, y)
     message = 20798893674476452017134061561508270130637142515379653289952617252661468872421
     sign = (29700980915817952874371204983938256990422752107994319651632687982059210933395,
                 574973400270084654178925310019147038455227042649098563933718999175515839552)
     q_x = 57520216126176808443631405023338071176630104906313632182896741342206604859403
     q_y = 17614944419213781543809391949654080031942662045363639260709847859438286763994
     public_key = ECPoint(q_x, q_y, a, b, p)
     self.assertEqual(gost.verify(message, sign, public_key), True)
Exemple #5
0
 def verify(self, message, pub_key, sign):
     if sign[1] > self.q:
         return False
     public_key = ECPoint(pub_key[0], pub_key[1], self.a, self.b, self.p)
     sign_tmp = reverse(sign[0]), reverse(sign[1])
     oid = 0x06092A7000020022651F51
     hash_value = self.belt_hash(message)
     r_point = ((sign_tmp[1] + reverse(hash_value)) % self.q) * self.g_point + \
               (sign_tmp[0] + 2 ** self.l) * public_key
     if r_point == float('inf'):
         return False
     value_to_hash = int2list(oid) + int2list(reverse(
         r_point.x)) + int2list(hash_value)
     t = self.belt_hash(list2int(value_to_hash))
     t = int2list(t)[:16]
     if list2int(t) != sign[0]:
         return False
     return True
 def __init__(self, p, a, b, q, p_x, p_y):
     self.p_point = ECPoint(p_x, p_y, a, b, p)
     self.q = q
     self.a = a
     self.b = b
     self.p = p
Exemple #7
0
 def __init__(self, p, a, b, p_x, p_y, n):
     self.p_point = ECPoint(p_x, p_y, a, b, p, True)
     self.a = a
     self.b = b
     self.p = p
     self.n = n