add rust implementation
All checks were successful
Test CI / test speed (push) Successful in 15s
All checks were successful
Test CI / test speed (push) Successful in 15s
This commit is contained in:
parent
9654d8504b
commit
2d12e8c99c
28
src/tpre.py
28
src/tpre.py
@ -1,6 +1,7 @@
|
|||||||
from gmssl import Sm3, Sm2Key, Sm4Cbc, DO_ENCRYPT, DO_DECRYPT
|
from gmssl import Sm3, Sm2Key, Sm4Cbc, DO_ENCRYPT, DO_DECRYPT
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
import random
|
import random
|
||||||
|
import ecc_rs
|
||||||
|
|
||||||
point = Tuple[int, int]
|
point = Tuple[int, int]
|
||||||
capsule = Tuple[point, point, int]
|
capsule = Tuple[point, point, int]
|
||||||
@ -33,17 +34,26 @@ sm2p256v1 = CurveFp(
|
|||||||
g = (sm2p256v1.Gx, sm2p256v1.Gy)
|
g = (sm2p256v1.Gx, sm2p256v1.Gy)
|
||||||
|
|
||||||
|
|
||||||
def multiply(a: point, n: int) -> point:
|
def multiply(a: point, n: int, flag: int = 0) -> point:
|
||||||
N = sm2p256v1.N
|
if flag == 1:
|
||||||
A = sm2p256v1.A
|
|
||||||
P = sm2p256v1.P
|
result = ecc_rs.multiply(a, n)
|
||||||
return fromJacobian(jacobianMultiply(toJacobian(a), n, N, A, P), P)
|
return result
|
||||||
|
else:
|
||||||
|
N = sm2p256v1.N
|
||||||
|
A = sm2p256v1.A
|
||||||
|
P = sm2p256v1.P
|
||||||
|
return fromJacobian(jacobianMultiply(toJacobian(a), n, N, A, P), P)
|
||||||
|
|
||||||
|
|
||||||
def add(a: point, b: point) -> point:
|
def add(a: point, b: point, flag: int = 0) -> point:
|
||||||
A = sm2p256v1.A
|
if flag == 1:
|
||||||
P = sm2p256v1.P
|
result = ecc_rs.add(a, b)
|
||||||
return fromJacobian(jacobianAdd(toJacobian(a), toJacobian(b), A, P), P)
|
return result
|
||||||
|
else:
|
||||||
|
A = sm2p256v1.A
|
||||||
|
P = sm2p256v1.P
|
||||||
|
return fromJacobian(jacobianAdd(toJacobian(a), toJacobian(b), A, P), P)
|
||||||
|
|
||||||
|
|
||||||
def inv(a: int, n: int) -> int:
|
def inv(a: int, n: int) -> int:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user