Support GmSSL v3.2.0 - #2
Merged
Merged
Conversation
- 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
There was a problem hiding this comment.
🟡 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.
Co-authored-by: yetsing <39950553+yetsing@users.noreply.github.com>
Co-authored-by: yetsing <39950553+yetsing@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support GmSSL v3.2.0