def test_gf2m_modmul__pos(self): """ Positive tests for gf2m_modmul(a, b, f) Sage test calculations:: sage: F.<x> = GF(2)[] sage: FF.<y> = GF(2**4, name='y', modulus=x^4 + x + 1 ) # f = 0b10011 sage: a = y^3 + y^2 + 1 # a = 0b1101 sage: b = y^2 + y # b = 0b110 sage: a*b y^3 # == 0b100 sage: K.<y> = GF(2**8, name='y', modulus=x^8 + x^4 + x^3 + x + 1 ) # f = 0b100011011 sage: a = y^6 + y^4 + y + 1 # a = 0b1010011 sage: b = y^7 + y^6 + y^3 + y # b = 0b11001010 sage: a*b 1 """ self.failUnlessEqual(ar.gf2m_modmul(0b1101, 0b110, 0b10011), 0b1000) self.failUnlessEqual(ar.gf2m_modmul(0b110, 0b1101, 0b10011), 0b1000) self.failUnlessEqual( ar.gf2m_modmul(0b1010011, 0b11001010, 0b100011011), 0b1) self.failUnlessEqual( ar.gf2m_modmul(0b11001010, 0b1010011, 0b100011011), 0b1)
def test_gf2m_modmul__neg(self): """ Negative tests for gf2m_modmul(a,b) """ # Not meant to be called with other values than int or long self.failUnlessRaises(AttributeError, ar.gf2m_modmul, 0.0, 0b110, 0b10011) self.failUnlessRaises(TypeError, ar.gf2m_modmul, "asdf", 0b110, 0b10011) self.failUnlessEqual(ar.gf2m_modmul(-0b1101,0b110,0b10011), 0b1000) self.failUnlessEqual(ar.gf2m_modmul(0b1101,-0b110,0b10011), 0b1000) self.failUnlessEqual(ar.gf2m_modmul(-0b1101,-0b110,0b10011), 0b1000)
def test_gf2m_modmul__pos(self): """ Positive tests for gf2m_modmul(a, b, f) Sage test calculations:: sage: F.<x> = GF(2)[] sage: FF.<y> = GF(2**4, name='y', modulus=x^4 + x + 1 ) # f = 0b10011 sage: a = y^3 + y^2 + 1 # a = 0b1101 sage: b = y^2 + y # b = 0b110 sage: a*b y^3 # == 0b100 sage: K.<y> = GF(2**8, name='y', modulus=x^8 + x^4 + x^3 + x + 1 ) # f = 0b100011011 sage: a = y^6 + y^4 + y + 1 # a = 0b1010011 sage: b = y^7 + y^6 + y^3 + y # b = 0b11001010 sage: a*b 1 """ self.failUnlessEqual(ar.gf2m_modmul(0b1101,0b110,0b10011), 0b1000) self.failUnlessEqual(ar.gf2m_modmul(0b110, 0b1101,0b10011), 0b1000) self.failUnlessEqual(ar.gf2m_modmul(0b1010011, 0b11001010, 0b100011011), 0b1) self.failUnlessEqual(ar.gf2m_modmul(0b11001010, 0b1010011, 0b100011011), 0b1)
def check_point_on_curve(self, P): """ Checks if point is on curve. y^2 + x*y = x^3 + a*x^2 + b """ x = P[0] y = P[1] if ((ar._binpolydeg(x) >= self._m) or (ar._binpolydeg(y) >= self._m)): return 0 left = ar.gf2m_add(ar.gf2m_modmul(y, y, self._fx), ar.gf2m_modmul(x, y, self._fx)) right = ar.gf2m_add( ar.gf2m_add( ar.gf2m_modmul(ar.gf2m_modmul(x, x, self._fx), x, self._fx), ar.gf2m_modmul(self._a, ar.gf2m_modmul(x, x, self._fx), self._fx)), self._b) if (left == right): return 1 return 0
def check_point_on_curve(self, P): """ Checks if point is on curve. y^2 + x*y = x^3 + a*x^2 + b """ x = P[0] y = P[1] if ((ar._binpolydeg(x) >= self._m) or (ar._binpolydeg(y) >= self._m)): return 0 left = ar.gf2m_add(ar.gf2m_modmul(y,y,self._fx), ar.gf2m_modmul(x,y,self._fx)) right = ar.gf2m_add(ar.gf2m_add( ar.gf2m_modmul(ar.gf2m_modmul(x,x,self._fx),x,self._fx), ar.gf2m_modmul(self._a,ar.gf2m_modmul(x,x,self._fx),self._fx)), self._b) if (left == right): return 1 return 0