lyu12vK.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Lattice-Based-Signatures 作者: krishnacharya 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号