コード例 #1
0
ファイル: ntrusign.py プロジェクト: 68823613/QS-BlockChain
    def sign(self, message, randPol, b, f_new, g_new, d_new):
        self.f = f_new
        self.g = g_new
        self.d = d_new
        #compute up,vp
        up = self.myhash(message)
        vp = self.myhash(self.h)

        #compute u1
        u1_pre = poly.multPoly([self.p], randPol)
        u1 = poly.addPoly(u1_pre, up)

        #compute v1
        v1 = self.reModulo(poly.multPoly(u1, self.h), self.D, self.q)

        #compute a
        [gcd_g, s_g, t_g] = poly.extEuclidPoly(self.g, self.D)
        self.g_p = poly.modPoly(s_g, self.p)

        a_pre = poly.subPoly(vp, v1)
        a = self.reModulo(poly.multPoly(a_pre, self.g_p), self.D, self.p)

        #compute v
        v_pre = poly.multPoly([int(math.pow(-1, b))], poly.multPoly(a, self.g))
        v = poly.addPoly(v1, v_pre)

        #compute sign
        sign_pre = poly.multPoly([int(math.pow(-1, b))],
                                 poly.multPoly(a, self.f))
        sign = poly.addPoly(randPol, sign_pre)
        return sign
コード例 #2
0
 def genPublicKey(self, f_new, g_new, d_new):
     self.f = f_new
     self.g = g_new
     self.d = d_new
     [gcd_f, s_f, t_f] = poly.extEuclidPoly(self.f, self.D)
     self.f_p = poly.modPoly(s_f, self.p)
     self.f_q = poly.modPoly(s_f, self.q)
     self.h = self.reModulo(poly.multPoly(self.f_q, self.g), self.D, self.q)
     if not self.runTests():
         print("Failed!")
         quit()
コード例 #3
0
 def genPublicKey(self, f_new, g_new, d_new):
     # Using Extended Euclidean Algorithm for Polynomials to get s and t.
     self.f = f_new
     self.g = g_new
     self.d = d_new
     [gcd_f, s_f, t_f] = poly.extEuclidPoly(self.f, self.D)
     self.f_p = poly.modPoly(s_f, self.p)
     self.f_q = poly.modPoly(s_f, self.q)
     self.h = self.reModulo(poly.multPoly(self.f_q, self.g), self.D, self.q)
     if not self.runTests():
         quit()
コード例 #4
0
ファイル: ntrusign.py プロジェクト: 68823613/QS-BlockChain
    def genPublicKey(self, f_new, g_new, d_new):
        # Using Extended Euclidean Algorithm for Polynomials
        # to get s and t. Note that the gcd must be 1
        self.f = f_new
        self.g = g_new
        self.d = d_new

        pf = poly.multPoly([self.p], self.f)
        [gcd_f, s_f, t_f] = poly.extEuclidPoly(self.f, self.D)
        [gcd_pf, s_pf, t_pf] = poly.extEuclidPoly(pf, self.D)
        self.f_p = poly.modPoly(s_f, self.p)
        self.f_q = poly.modPoly(s_f, self.q)

        self.pf_q = poly.modPoly(s_pf, self.q)

        self.h = self.reModulo(poly.multPoly(self.g, self.pf_q), self.D,
                               self.q)

        if not self.runTests():
            print "Failed!"
            quit()
コード例 #5
0
ファイル: ntru.py プロジェクト: Sapphirine/ntru
	def genPublicKey(self,f_new,g_new,d_new):
		# Using Extended Euclidean Algorithm for Polynomials
		# to get s and t. Note that the gcd must be 1
		self.f=f_new
		self.g=g_new
		self.d=d_new
		[gcd_f,s_f,t_f]=poly.extEuclidPoly(self.f,self.D)
		self.f_p=poly.modPoly(s_f,self.p)
		self.f_q=poly.modPoly(s_f,self.q)
		self.h=self.reModulo(poly.multPoly(self.f_q,self.g),self.D,self.q)
		if not self.runTests():
			print "Failed!"
			quit()