The analysis began by identifying the patched version (0.41.1) and the last vulnerable version (0.41.0) from the provided information. By comparing the commits between these two tags in the emmansun/gmsm repository, the specific security patch was located in commit 1085b2ee75a32dadb7bbec3748269d8de0f7a177. The commit message, "SM9: reject infinity points in decrypt, unwrap, verify, and key exchange," clearly indicated its purpose.
The root cause of the vulnerability is the failure to reject the elliptic curve "point at infinity" when processing external inputs like ciphertexts, signatures, or key exchange messages. The patch rectifies this by adding an IsInfinity() check after deserializing and verifying the curve point in several functions within internal/sm9/sm9.go.
The primary function associated with the described ciphertext forgery is EncryptPrivateKey.UnwrapKey. This internal function is called by the public API functions sm9.Decrypt and sm9.DecryptASN1, which are the entry points for an attacker. During exploitation, a profiler would show a call to sm9.Decrypt leading to the vulnerable EncryptPrivateKey.UnwrapKey method.
The same logical flaw was also present and fixed in other parts of the SM9 implementation, including signature verification (SignMasterPublicKey.Verify) and key exchange (KeyExchange.ConfirmResponder, respondKeyExchange), preventing similar forgery or manipulation attacks in those contexts.