本文整理汇总了Python中petlib.ec.EcGroup.parameters方法的典型用法代码示例。如果您正苦于以下问题:Python EcGroup.parameters方法的具体用法?Python EcGroup.parameters怎么用?Python EcGroup.parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类petlib.ec.EcGroup
的用法示例。
在下文中一共展示了EcGroup.parameters方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Point_doubling
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import parameters [as 别名]
def test_Point_doubling():
"""
Test whether the EC point doubling is correct.
"""
from pytest import raises
from petlib.ec import EcGroup, EcPt
G = EcGroup(713) # NIST curve
d = G.parameters()
a, b, p = d["a"], d["b"], d["p"]
g = G.generator()
gx0, gy0 = g.get_affine()
gx2, gy2 = (2*g).get_affine()
from Lab01Code import is_point_on_curve
from Lab01Code import point_double
x2, y2 = point_double(a, b, p, gx0, gy0)
assert is_point_on_curve(a, b, p, x2, y2)
assert x2 == gx2 and y2 == gy2
x2, y2 = point_double(a, b, p, None, None)
assert is_point_on_curve(a, b, p, x2, y2)
assert x2 == None and y2 == None
示例2: test_Point_addition
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import parameters [as 别名]
def test_Point_addition():
"""
Test whether the EC point addition is correct.
"""
from pytest import raises
from petlib.ec import EcGroup, EcPt
G = EcGroup(713) # NIST curve
d = G.parameters()
a, b, p = d["a"], d["b"], d["p"]
g = G.generator()
gx0, gy0 = g.get_affine()
r = G.order().random()
gx1, gy1 = (r*g).get_affine()
from Lab01Code import is_point_on_curve
from Lab01Code import point_add
assert is_point_on_curve(a, b, p, gx0, gy0)
assert is_point_on_curve(a, b, p, gx1, gy1)
## Test a simple addition
h = (r + 1) * g
hx1, hy1 = h.get_affine()
x, y = point_add(a, b, p, gx0, gy0, gx1, gy1)
assert is_point_on_curve(a, b, p, x, y)
assert x == hx1
assert y == hy1
## Ensure commutativity
xp, yp = point_add(a, b, p, gx1, gy1, gx0, gy0)
assert is_point_on_curve(a, b, p, xp, yp)
assert x == xp
assert y == yp
## Ensure addition with neutral returns the element
xp, yp = point_add(a, b, p, gx1, gy1, None, None)
assert is_point_on_curve(a, b, p, xp, yp)
assert xp == gx1
assert yp == gy1
xp, yp = point_add(a, b, p, None, None, gx0, gy0)
assert is_point_on_curve(a, b, p, xp, yp)
assert gx0 == xp
assert gy0 == yp
## An error is raised in case the points are equal
with raises(Exception) as excinfo:
point_add(a, b, p, gx0, gy0, gx0, gy0)
assert 'EC Points must not be equal' in str(excinfo.value)
示例3: test_on_curve
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import parameters [as 别名]
def test_on_curve():
"""
Test the procedues that tests whether a point is on a curve.
"""
## Example on how to define a curve
from petlib.ec import EcGroup, EcPt
G = EcGroup(713) # NIST curve
d = G.parameters()
a, b, p = d["a"], d["b"], d["p"]
g = G.generator()
gx, gy = g.get_affine()
from Lab01Code import is_point_on_curve
assert is_point_on_curve(a, b, p, gx, gy)
assert is_point_on_curve(a, b, p, None, None)
示例4: test_Point_addition_check_inf_result
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import parameters [as 别名]
def test_Point_addition_check_inf_result():
"""
Test whether the EC point addition is correct for pt - pt = inf
"""
from pytest import raises
from petlib.ec import EcGroup, EcPt
G = EcGroup(713) # NIST curve
d = G.parameters()
a, b, p = d["a"], d["b"], d["p"]
g = G.generator()
gx0, gy0 = g.get_affine()
gx1, gy1 = gx0, p - gy0
assert is_point_on_curve(a, b, p, gx0, gy0)
assert is_point_on_curve(a, b, p, gx1, gy1)
x, y = point_add(a, b, p, gx0, gy0, gx1, gy1)
assert is_point_on_curve(a, b, p, x, y)
assert (x,y) == (None, None)
示例5: test_Point_scalar_mult_double_and_add
# 需要导入模块: from petlib.ec import EcGroup [as 别名]
# 或者: from petlib.ec.EcGroup import parameters [as 别名]
def test_Point_scalar_mult_double_and_add():
"""
Test the scalar multiplication using double and add.
"""
from pytest import raises
from petlib.ec import EcGroup, EcPt
G = EcGroup(713) # NIST curve
d = G.parameters()
a, b, p = d["a"], d["b"], d["p"]
g = G.generator()
gx0, gy0 = g.get_affine()
r = G.order().random()
gx2, gy2 = (r*g).get_affine()
x2, y2 = point_scalar_multiplication_double_and_add(a, b, p, gx0, gy0, r)
assert is_point_on_curve(a, b, p, x2, y2)
assert gx2 == x2
assert gy2 == y2