@@ -133,7 +133,7 @@ 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+ if gmssl .sm3_pbkdf2 (c_char_p (passwd ), c_size_t (len (passwd )),
137137 salt , c_size_t (len (salt )), c_size_t (iterator ), c_size_t (keylen ), key ) != 1 :
138138 raise NativeError ('libgmssl inner error' )
139139
@@ -328,7 +328,8 @@ class Sm4Gcm(Structure):
328328 ("Y" , c_uint8 * 16 ),
329329 ("taglen" , c_size_t ),
330330 ("mac" , c_uint8 * 16 ),
331- ("maclen" , c_size_t )
331+ ("maclen" , c_size_t ),
332+ ("encedlen" , c_uint64 )
332333 ]
333334
334335 def __init__ (self , key , iv , aad , taglen = SM4_GCM_DEFAULT_TAG_SIZE , encrypt = True ):
@@ -387,16 +388,17 @@ def finish(self):
387388
388389class Sm2Point (Structure ):
389390 _fields_ = [
390- ("x" , c_uint8 * 32 ),
391- ("y" , c_uint8 * 32 )
391+ ("X" , c_uint64 * 4 ),
392+ ("Y" , c_uint64 * 4 ),
393+ ("Z" , c_uint64 * 4 )
392394 ]
393395
394396
395397class Sm2Key (Structure ):
396398
397399 _fields_ = [
398400 ("public_key" , Sm2Point ),
399- ("private_key" , c_uint8 * 32 )
401+ ("private_key" , c_uint64 * 4 )
400402 ]
401403
402404 def __init__ (self ):
@@ -503,17 +505,61 @@ def decrypt(self, ciphertext):
503505 raise NativeError ('libgmssl inner error' )
504506 return outbuf [:outlen .value ]
505507
508+ class X509Key (Structure ):
509+
510+ _fields_ = [
511+ ("algor" , c_int ),
512+ ("algor_param" , c_int ),
513+ ("sm2_key" , Sm2Key ),
514+ ("_padding" , c_uint8 * 20000 )
515+ ]
516+
506517
507518DO_ENCRYPT = True
508519DO_DECRYPT = False
509520DO_SIGN = True
510521DO_VERIFY = False
511522
512- class Sm2Signature (Structure ):
523+ class Sm2Z256Point (Structure ):
524+
525+ _fields_ = [
526+ ("X" , c_uint64 * 4 ),
527+ ("Y" , c_uint64 * 4 ),
528+ ("Z" , c_uint64 * 4 )
529+ ]
530+
531+ class Sm2SignPreComp (Structure ):
532+
533+ _fields_ = [
534+ ("k" , c_uint64 * 4 ),
535+ ("x1_modn" , c_uint64 * 4 )
536+ ]
537+
538+ class Sm2Sign (Structure ):
513539
514540 _fields_ = [
515541 ("sm3_ctx" , Sm3 ),
516- ("key" , Sm2Key )
542+ ("saved_sm3_ctx" , Sm3 ),
543+ ("key" , Sm2Key ),
544+ ("fast_sign_private" , c_uint64 * 4 ),
545+ ("pre_comp" , Sm2SignPreComp * 32 ),
546+ ("num_pre_comp" , c_uint ),
547+ ("public_point_table" , Sm2Z256Point * 16 )
548+ ]
549+
550+ class Sm2Verify (Structure ):
551+
552+ _fields_ = [
553+ ("sm3_ctx" , Sm3 ),
554+ ("saved_sm3_ctx" , Sm3 ),
555+ ("key" , Sm2Key ),
556+ ("public_point_table" , Sm2Z256Point * 16 )
557+ ]
558+
559+ class Sm2Signature (Structure ):
560+
561+ _fields_ = [
562+ ("ctx" , Sm2Sign )
517563 ]
518564
519565 def __init__ (self , sm2_key , signer_id = SM2_DEFAULT_ID , sign = DO_SIGN ):
@@ -559,7 +605,7 @@ def verify(self, signature):
559605
560606class sm9_bn_t (Structure ):
561607 _fields_ = [
562- ("d" , c_uint64 * 8 )
608+ ("d" , c_uint64 * 4 )
563609 ]
564610
565611class sm9_fp2_t (Structure ):
@@ -1013,7 +1059,11 @@ def get_subject(self):
10131059
10141060 def get_subject_public_key (self ):
10151061 public_key = Sm2Key ()
1016- gmssl .x509_cert_get_subject_public_key (self ._cert , c_size_t (len (self ._cert )), byref (public_key ))
1062+ x509_key = X509Key ()
1063+ if gmssl .x509_cert_get_subject_public_key (self ._cert , c_size_t (len (self ._cert )), byref (x509_key )) != 1 :
1064+ raise NativeError ('libgmssl inner error' )
1065+ public_key .public_key = x509_key .sm2_key .public_key
1066+ public_key .private_key = x509_key .sm2_key .private_key
10171067 public_key ._has_private_key = False
10181068 public_key ._has_public_key = True
10191069 return public_key
@@ -1037,5 +1087,3 @@ def verify_by_ca_certificate(self, cacert, sm2_id):
10371087 cacert_raw , c_size_t (len (cacert_raw )), c_char_p (sm2_id ), c_size_t (len (sm2_id ))) != 1 :
10381088 return False
10391089 return True
1040-
1041-
0 commit comments