@@ -133,7 +133,12 @@ def sm3_pbkdf2(passwd, salt, iterator, keylen):
133133 passwd = passwd .encode ('utf-8' )
134134 key = create_string_buffer (keylen )
135135
136- if gmssl .pbkdf2_hmac_sm3_genkey (c_char_p (passwd ), c_size_t (len (passwd )),
136+ try :
137+ pbkdf2_func = gmssl .pbkdf2_hmac_sm3_genkey
138+ except AttributeError :
139+ pbkdf2_func = gmssl .sm3_pbkdf2
140+
141+ if pbkdf2_func (c_char_p (passwd ), c_size_t (len (passwd )),
137142 salt , c_size_t (len (salt )), c_size_t (iterator ), c_size_t (keylen ), key ) != 1 :
138143 raise NativeError ('libgmssl inner error' )
139144
@@ -387,8 +392,9 @@ def finish(self):
387392
388393class Sm2Point (Structure ):
389394 _fields_ = [
390- ("x" , c_uint8 * 32 ),
391- ("y" , c_uint8 * 32 )
395+ ("x" , c_uint64 * 4 ),
396+ ("y" , c_uint64 * 4 ),
397+ ("z" , c_uint64 * 4 )
392398 ]
393399
394400
@@ -509,11 +515,24 @@ def decrypt(self, ciphertext):
509515DO_SIGN = True
510516DO_VERIFY = False
511517
518+ class Sm2SignPreComp (Structure ):
519+
520+ _fields_ = [
521+ ("k" , c_uint64 * 4 ),
522+ ("x1_modn" , c_uint64 * 4 )
523+ ]
524+
525+
512526class Sm2Signature (Structure ):
513527
514528 _fields_ = [
515529 ("sm3_ctx" , Sm3 ),
516- ("key" , Sm2Key )
530+ ("saved_sm3_ctx" , Sm3 ),
531+ ("key" , Sm2Key ),
532+ ("fast_sign_private" , c_uint64 * 4 ),
533+ ("pre_comp" , Sm2SignPreComp * 32 ),
534+ ("num_pre_comp" , c_uint ),
535+ ("public_point_table" , Sm2Point * 16 )
517536 ]
518537
519538 def __init__ (self , sm2_key , signer_id = SM2_DEFAULT_ID , sign = DO_SIGN ):
@@ -1037,5 +1056,3 @@ def verify_by_ca_certificate(self, cacert, sm2_id):
10371056 cacert_raw , c_size_t (len (cacert_raw )), c_char_p (sm2_id ), c_size_t (len (sm2_id ))) != 1 :
10381057 return False
10391058 return True
1040-
1041-
0 commit comments