Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/shamir_secret_sharing/share_forgery.py
2589 views
1
def attack(p, s, s_, x, y, xs):
2
"""
3
Forges a share to recombine into a new shared secret, s', if a single share and the x coordinates of the other participants are given.
4
:param p: the prime used for Shamir's secret sharing
5
:param s: the original shared secret
6
:param s_: the target shared secret, s'
7
:param x: the x coordinate of the given share
8
:param y: the y coordinate of the given share
9
:param xs: the x coordinates of the other participants (excluding the x coordinate of the given share)
10
:return: the forged share
11
"""
12
const = 1
13
for i in xs:
14
const *= i * pow(i - x, -1, p)
15
16
return ((s_ - s) * pow(const, -1, p) + y) % p
17
18