Skip to content

Support GmSSL v3.2.0 - #2

Merged
yetsing merged 15 commits into
mainfrom
feature/support-GmSSL-v3.2.0
Sep 8, 2026
Merged

Support GmSSL v3.2.0#2
yetsing merged 15 commits into
mainfrom
feature/support-GmSSL-v3.2.0

Conversation

@yetsing

@yetsing yetsing commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Support GmSSL v3.2.0

yetsing added 13 commits August 6, 2026 16:24
- sm4_cbc_padding_decrypt/encrypt 检查 GmSSL 返回值,失败时抛异常,
  避免密文非 16 倍数或 padding 非法时返回未初始化堆内存
- sm2_z256_point_from_bytes 判断改为 != GMSSL_INNER_OK,拒绝无穷远点
  (全零公钥),避免 sm2_encrypt 产出无法解密的密文
- normalize_sm2_public_key 增加压缩前缀、x 越界、点在曲线上校验,
  非法 hex 统一抛 InvalidValueError
- sm9_enc_master_key_info_decrypt_from_pem_v3_1_1 加 static
- sm4_gcm_decrypt 增加 tag 长度校验(12~16),非法抛 InvalidValueError;
  长度校验后 GmSSL 失败只可能是 tag 不匹配,抛 'authentication failed'
  替代误导性的 GmsslInnerError
- normalize_sm2_public_key 新增 _is_on_curve 助手,64/65 字节公钥现在也
  校验点在曲线上(含全零无穷远点),与 33 字节压缩路径行为一致
- 补充对应回归测试并更新 pyi docstring

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A newly modified unit test is currently a no-op (pass), reducing test signal and potentially masking regressions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the Python C-extension wrapper and tests to be compatible with GmSSL v3.2.0, including behavioral changes around SM9 PEM headers, SM2 public-key handling, and stricter error propagation for SM4.

Changes:

  • Add SM9 PEM backward-compat handling for the v3.1.1 “ENCRYPTED SM9 …” headers while supporting the v3.2.0 generic header.
  • Harden SM2 public key parsing/validation (curve checks; reject infinity/all-zero) and adjust SM2/SM3 empty-message handling.
  • Improve SM4 error signaling (CBC padding errors must raise; GCM tag length/auth failure behavior), and expand tests accordingly.
File summaries
File Description
tests/test_sm9.py Unskips SM9 DER/issue regression tests.
tests/test_sm4.py Adds CBC padding failure expectations and GCM tag/auth failure tests.
tests/test_sm3.py Adds empty-message hash/HMAC vectors; relaxes prior “empty message” expectations.
tests/test_sm2.py Adds regression tests for invalid public keys (all-zero/infinity) and normalization error cases; allows empty-message signing.
README.md Documents GmSSL v3.2.0 support and SM9 PEM header change notes.
gmssl_pyx/sm2_utils.py Adds on-curve validation for decompression/normalization of SM2 public keys.
gmssl_pyx/gmsslmodule.c Updates SM2 key/public key plumbing to sm2_z256 APIs; tightens SM4 CBC/GCM error handling; CTR decrypt uses ctr_encrypt (CTR symmetry).
gmssl_pyx/gmsslext.pyi Fixes docstring mistakes and documents SM4 GCM tag constraints/raises.
gmssl_pyx/gmsslext_sm9.h Adds constants for legacy (v3.1.1) SM9 PEM labels.
gmssl_pyx/gmsslext_sm9.c Detects legacy SM9 PEM headers and decrypts accordingly; securely clears SM9 key material on dealloc.
.gitignore Ignores generated *.pem artifacts.
.github/workflows/wheels.yml Bumps actions/upload-artifact to a newer pinned revision.
Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_sm3.py Outdated
Comment thread gmssl_pyx/gmsslmodule.c Outdated
Co-authored-by: yetsing <39950553+yetsing@users.noreply.github.com>
Co-authored-by: yetsing <39950553+yetsing@users.noreply.github.com>
@yetsing
yetsing merged commit 15f7fd9 into main Sep 8, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants