コード例 #1
0
ファイル: dc.py プロジェクト: ognevlive/TSBOL
    def gen_threshold_sign(self, h, m, s, shares):
        shaTSS = Shamir(self.t, self.n)
        k = shaTSS.SC(self.p, shares).list()[_sage_const_0]
        kk = bin(int(str(k)))[_sage_const_2:]
        R = m.parent()
        f_len = int(kk[:_sage_const_8], _sage_const_2)
        fs_len = int(kk[_sage_const_8:_sage_const_16], _sage_const_2)

        R = m.parent()
        f = R([
            -_sage_const_1 * int(x)
            for x in kk[_sage_const_16:_sage_const_16 + f_len]
        ])
        fs = R([
            -_sage_const_1 * int(x)
            for x in kk[_sage_const_16 + f_len:_sage_const_16 + f_len + fs_len]
        ])

        x = auxmath.normilize_coeffs(-(_sage_const_1 / self.q) * m * fs)
        y = auxmath.normilize_coeffs(-(_sage_const_1 / self.q) * m * f)
        s0 = x * f + y * fs
        s_res = R(s + s0)

        b = s_res * auxmath.normilize_coeffs2(s_res * self.h0 - m, self.q)

        print(b)
        print(b.norm(_sage_const_2))
コード例 #2
0
ファイル: dc.py プロジェクト: ognevlive/TSBOL
    def gen_threshold_sign(self, h, m, s, i, shares):
        self.get_info()
        shaTSS = Shamir(self.t, self.n)

        if i == _sage_const_0:
            print('UPDATE')
            print('UPDATE')
            print('UPDATE')
            print('UPDATE')
            self.fs = None
            self.f = None
            print(shares)

        # if self.t_new == None:
        # 	k = shaTSS.SC(self.p, shares).list()[0]
        # else:
        # 	M = []
        # 	for i in range(self.t+self.t_new):
        # 		row = [0] * (self.t+self.t_new)
        # 		if i < self.t_new:
        # 			row[i] = self.p
        # 		else:
        # 			row[i] = self.H / self.p
        # 			for j in range(self.t_new):
        # 				row[j] = shares[j][0] ** (i-self.t_new+1)
        # 		M.append(row)

        # 	M = matrix(QQ, M)
        # 	target = [x[1] for x in shares[:self.t_new]] + [0]*self.t
        # 	c = Babai_CVP(M, target)
        # 	R = Integers(self.p)
        # 	k = R((self.p/self.H)*c[self.t_new])

        R1 = PolynomialRing(ZZ, names=('x', ))
        (x, ) = R1._first_ngens(1)
        phi = x**self.N - _sage_const_1
        Rx = R1.quotient_by_principal_ideal(phi)

        if self.f == None or self.fs == None:
            k = shaTSS.SC(self.p, shares).list()[_sage_const_0]
            kk = bin(int(str(k)))[_sage_const_2:]
            f_len = int(kk[:_sage_const_8], _sage_const_2)
            fs_len = int(kk[_sage_const_8:_sage_const_16], _sage_const_2)
            print(k)
            self.f = Rx([
                -_sage_const_1 * int(x)
                for x in kk[_sage_const_16:_sage_const_16 + f_len]
            ])._polynomial
            self.fs = Rx([
                -_sage_const_1 * int(x)
                for x in kk[_sage_const_16 + f_len:_sage_const_16 + f_len +
                            fs_len]
            ])._polynomial
            T = int(kk[_sage_const_16 + f_len + fs_len:], _sage_const_2)
            print(T)
            if T != self.T:
                return -_sage_const_1

        x = Rx(normilize_coeffs(
            -_sage_const_1 / self.q * m * self.fs))._polynomial % self.q
        y = Rx(normilize_coeffs(
            _sage_const_1 / self.q * m * self.f))._polynomial % self.q

        s0 = (Rx(x * self.f)._polynomial % self.q +
              Rx(y * self.fs)._polynomial % self.q) % self.q
        s = s + s0
        return s