def Sign(**kwargs):
'''
i/p:
msg: string, which the sender wants to brodcast
A : numpy array, Verification Key dimension nxm
S : numpy array, Signing key dimension mxk
o/p:
(z,c) : signature
'''
msg, A, S, q, n, m, k, d, sd, M = kwargs['msg'],kwargs['A'],kwargs['S'],kwargs['q'],kwargs['n'],kwargs['m'],kwargs['k'],kwargs['d'],kwargs['sd'],kwargs['M']
D = DiscreteGaussianDistributionLatticeSampler(ZZ**m, sd)
count = 0
while(True):
y = np.array(D()) # discrete point in Zq^m
c = util.hash_to_baseb(util.vector_to_Zq(np.matmul(A,y), q), msg, 3, k) # 3 because we want b/w 0,1,2 small coefficients in Zq
Sc = np.matmul(S,c)
z = Sc + y #notice we didnt reduce (mod q)
try:
pxe = float(-2*z.dot(Sc) + Sc.dot(Sc))
val = exp(pxe / (2*sd**2)) / M
except OverflowError:
print "OF"
continue
if(random.random() < min(val, 1.0)):
break
if(count > 4): # beyond 4 rejection sampling iterations are not expected in general
raise ValueError("The number of rejection sampling iterations are more than expected")
count += 1
return z, c
评论列表
文章目录