add new test
This commit is contained in:
parent
9c1b3996f3
commit
a8e3dd7f1e
54
test.py
54
test.py
@ -1,5 +1,7 @@
|
||||
import ecc_rs
|
||||
import time
|
||||
|
||||
point = tuple[int, int]
|
||||
# Example point coordinates for P1 and P2 as tuples (x1, y1) and (x2, y2)
|
||||
p1 = (
|
||||
1234567890123456789012345678901234567890123456789012345678901234,
|
||||
@ -17,3 +19,55 @@ print(f"Resulting Point: x = {result_x}, y = {result_y}")
|
||||
|
||||
result = ecc_rs.multiply(p1, 2)
|
||||
print(f"Resulting Point: x = {result[0]}, y = {result[1]}")
|
||||
|
||||
|
||||
# 生成密钥对模块
|
||||
class CurveFp:
|
||||
def __init__(self, A, B, P, N, Gx, Gy, name):
|
||||
self.A = A
|
||||
self.B = B
|
||||
self.P = P
|
||||
self.N = N
|
||||
self.Gx = Gx
|
||||
self.Gy = Gy
|
||||
self.name = name
|
||||
|
||||
|
||||
sm2p256v1 = CurveFp(
|
||||
name="sm2p256v1",
|
||||
A=0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC,
|
||||
B=0x28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93,
|
||||
P=0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF,
|
||||
N=0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123,
|
||||
Gx=0x32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7,
|
||||
Gy=0xBC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0,
|
||||
)
|
||||
|
||||
# 生成元
|
||||
g = (sm2p256v1.Gx, sm2p256v1.Gy)
|
||||
|
||||
|
||||
def multiply(a: point, n: int) -> point:
|
||||
|
||||
result = ecc_rs.multiply(a, n)
|
||||
return result
|
||||
|
||||
|
||||
def add(a: point, b: point) -> point:
|
||||
result = ecc_rs.add(a, b)
|
||||
return result
|
||||
|
||||
|
||||
start_time = time.time() # 获取开始时间
|
||||
for i in range(10):
|
||||
result = multiply(g, 10000) # 执行函数
|
||||
end_time = time.time() # 获取结束时间
|
||||
elapsed_time = end_time - start_time # 计算执行时间
|
||||
print(f"rust multiply 执行时间: {elapsed_time:.6f} 秒")
|
||||
|
||||
start_time = time.time() # 获取开始时间
|
||||
for i in range(10):
|
||||
result = add(g, g) # 执行函数
|
||||
end_time = time.time() # 获取结束时间
|
||||
elapsed_time = end_time - start_time # 计算执行时间
|
||||
print(f"rust add 执行时间: {elapsed_time:.6f} 秒")
|
||||
|
Loading…
x
Reference in New Issue
Block a user