def test_getkey(context): sexp = SExpression( b'(public-key (ecc (curve "NIST P-256")(q #0442B927242237639A36CE9221B340DB1A9AB76DF2FE3E171277F6A4023DED146EE86525E38CCECFF3FB8D152CC6334F70D23A525175C1BCBDDE6E023B2228770E#)))' ) ec = ECurve(keyparam=sexp) with pytest.raises(errors.GcryptException): priv = ec.key(mode=u'SECKEY') pub = ec.key(mode=u'PUBKEY') assert pub.type == u'public'
def test_affine(context): ec = ECurve(curve='secp192r1') point = Point(ec.curve) x = context.mpi(5) y = context.mpi(5) assert point.affine(x, y) == (5, 5)
def test_get(context): ec = ECurve(curve='secp192r1') point = Point(ec.curve) x = context.mpi(0) assert point.x == x assert point.y == x assert point.z == x
def test_double(context): ec = ECurve(curve='secp192r1') point = Point(ec.curve) x = context.mpi(1) y = context.mpi(1) z = context.mpi(1) (point.x, point.y, point.z) = (x, y, z) point.double() assert (point.x.value, point.y.value, point.z.value) == ( 6277101735386680763835789423207666416083908700390324961271, 6277101735386680763835789423207666416083908700390324961271, 2)
def test_set(context): ec = ECurve(curve='secp192r1') point = Point(ec.curve) x = context.mpi(1) y = context.mpi(1) z = context.mpi(1) point.x = x point.y = y point.z = z assert point.x == x assert point.y == y assert point.z == z
def test_add(context): ec = ECurve(curve='secp192r1') point_a = Point(ec.curve) point_b = Point(ec.curve) x = context.mpi(1) y = context.mpi(1) z = context.mpi(1) (point_a.x, point_a.y, point_a.z) = (x, y, z) (point_b.x, point_b.y, point_b.z) = (x, y, z) assert ((point_a + point_b).x.value, (point_a + point_b).y.value, (point_a + point_b).z.value) == ( 6277101735386680763835789423207666416083908700390324961271, 6277101735386680763835789423207666416083908700390324961271, 2) point_a += point_b assert (point_a.x.value, point_a.y.value, point_a.z.value) == ( 6277101735386680763835789423207666416083908700390324961271, 6277101735386680763835789423207666416083908700390324961271, 2)
def test_set(context): ec = ECurve(curve='secp192r1') a = ec['a'] * 2 ec['a'] = a assert ec['a'] == a
def test_get(context): ec = ECurve(curve='secp192r1') assert isinstance(ec['a'], MPIint)
def test_oncurve(context): ec = ECurve(curve='secp192r1') point = Point(ec.curve) assert point.isoncurve() == False assert ec['g'].isoncurve() == True