fix: extract hash and kdf from setup

This commit is contained in:
sangge 2023-10-16 22:30:15 +08:00
parent 96e04c155e
commit cd1e884713

View File

@ -118,8 +118,7 @@ def jacobianMultiply(
raise ValueError("jacobian Multiply error")
def Setup(sec: int) -> Tuple[CurveFp, Tuple[int, int],
Tuple[int, int], Callable,
Callable, Callable, Callable]:
Tuple[int, int]]:
'''
params:
sec: an init safety param
@ -128,10 +127,6 @@ def Setup(sec: int) -> Tuple[CurveFp, Tuple[int, int],
G: sm2 curve
g: generator
U: another generator
use sm3 as hash function
hash2: G^2 -> Zq
hash3: G^3 -> Zq
hash4: G^3 * Zq -> Zq
'''
G = sm2p256v1
@ -141,6 +136,8 @@ def Setup(sec: int) -> Tuple[CurveFp, Tuple[int, int],
tmp_u = random.randint(0, sm2p256v1.P)
U = multiply(g, tmp_u)
return G, g, U
def hash2(double_G: Tuple[Tuple[int, int], Tuple[int, int]]) -> int:
sm3 = Sm3() #pylint: disable=e0602
for i in double_G:
@ -183,9 +180,6 @@ def Setup(sec: int) -> Tuple[CurveFp, Tuple[int, int],
digest = int.from_bytes(digest, 'big') % sm2p256v1.P
return digest
return G, g, U, hash2, hash3, hash4, KDF
def GenerateKeyPair(
lamda_parma: int,
public_params: tuple
@ -281,7 +275,7 @@ pk_B, sk_B = GenerateKeyPair(0, ())
sec = 256
# 调用Setup函数
G, g, U, hash2, hash3, hash4, KDF = Setup(sec)
G, g, U= Setup(sec)
def GenerateReKey(sk_A, pk_B, N: int, T: int) -> list:
'''