コード例 #1
0
ファイル: edwards.py プロジェクト: linii/edcrypto
        """
        P = self.c.p
        xx, yy, num, denom, x = ModInt(P), ModInt(P), ModInt(P), ModInt(P), ModInt(P)
        yy.mul(y, y)
        num.sub(yy, self.c.one)
        denom.add(denom.mul(yy, self.c.d), self.c.one)
        xx.div(num, denom)
        if self.x.jacobi(xx) == 1:
            x.sqrt(xx)
            newpt = EdwardsPoint(self.c, x, y)
            if not newpt._on_curve():
                x.sub(P, self.x)
            return self.from_ep(newpt)

    def decode(self, pt):
        """
        Returns the actual data encoded in the point. Checks that the
        data is well-formed.

        Issues: zero padding doesn't work sometimes?
        """
        data = l2b((pt.to_ep(pt).y.v - 1) // k)
        return data[1:-2]

Group.register(EdwardsCurve)
Point.register(EdwardsPoint)

Group.__subclasscheck__(EdwardsCurve)
Point.__subclasscheck__(EdwardsPoint)
Group.__instancecheck__(EdwardsCurve)
Point.__instancecheck__(EdwardsPoint)
コード例 #2
0
ファイル: inv.py プロジェクト: linii/edcrypto
        zero = self.c.zero
        negone = self.c.negone
        ed = self.c.c.point()
        if a._special_pt(a):
            if a.equal(self.c.s1):
                ed.x.set(zero)
                ed.y.set(one)
            elif a.equal(self.c.s2):
                ed.x.set(zero)
                ed.y.set(negone)
            elif a.equal(self.c.s4):
                ed.x.set(negone)
                ed.y.set(zero)
            else:
                ed.x.set(one)
                ed.y.set(zero)
        else:
            x, y = ModInt(self.c.p), ModInt(self.c.p)
            x.div(a.z, a.x)
            y.div(a.z, a.y)
            ed.x.set(x)
            ed.y.set(y)
        return ed

Group.register(invEdwardsCurve)
Point.register(invEdwardsPoint)

Group.__subclasscheck__(invEdwardsCurve)
Point.__subclasscheck__(invEdwardsPoint)
Group.__instancecheck__(invEdwardsCurve)
Point.__instancecheck__(invEdwardsPoint)