1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| def sign(self, data, K): E = data.hex() e = int(E, 16) d = int(self.private_key, 16) k = int(K, 16)
P1 = self._kg(k, self.ecc_table['g'])
x = int(P1[0:self.para_len], 16) R = ((e + x) % int(self.ecc_table['n'], base=16)) if R == 0 or R + k == int(self.ecc_table['n'], base=16): return None d_1 = pow(d+1, int(self.ecc_table['n'], base=16) - 2, int(self.ecc_table['n'], base=16)) S = (d_1*(k + R) - R) % int(self.ecc_table['n'], base=16) if S == 0: return None else: return '%064x%064x' % (R,S)
|