def Sign(**kwargs):
'''
Algorithm 1, Pg 12 of BLISS paper
o/p:
z,c
'''
msg, A, S, m, n, sd, q, M, kappa = kwargs['msg'], kwargs['A'], kwargs['S'], kwargs['m'], kwargs['n'], kwargs['sd'], kwargs['q'], kwargs['M'], kwargs['kappa']
m_bar = m + n
D = DiscreteGaussianDistributionLatticeSampler(ZZ**m_bar, sd)
count = 0
while(True):
y = np.array(D()) # m' x 1
reduced_Ay = util.vector_to_Zq(np.matmul(A, y), 2*q)
c = hash_iterative(np.array_str(reduced_Ay) + msg, n, kappa) # still not the hash but this is test run
b = util.crypt_secure_randint(0, 1)
Sc = np.matmul(S,c)
z = y + ((-1)**b) * Sc
try:
exp_term = exp(float(Sc.dot(Sc)) / (2*sd**2))
cosh_term = np.cosh(float(z.dot(Sc)) / (sd**2))
val = exp_term / (cosh_term * M)
except OverflowError:
print "OF"
continue
if(random.random() < min(val, 1.0)):
break
if(count > 10): # 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
评论列表
文章目录