Skip to content

Commit 085b7be

Browse files
authored
sm2: fix SM2PKE decryption DoS vulnerability [SECURITY] (#1602)
This fixes a potential denial-of-service attack in the SM2PKE decryption implementation originally reported as GHSA-78p6-6878-8mj6 by @XlabAITeam The implementation parses the ciphertext, extracting the bytes that represent the `C1` curve point, however previously after attempting to invoke `AffinePoint::from_encoded_point` the result was subsequently being `unwrap()`ed in the event the provided candidate encoded point is not actually a valid point on the SM2 elliptic curve, leading to a potential DoS in this case. This is unfortunate because it was not caught by the `clippy::unwrap_used` lint, most likely because the actual method being invoked was `subtle::CtOption::unwrap` and it seems clippy does not check for every "unwrap" method invocation on every type, only `std::option::Option`/`Result`. The problem was corrected by replacing the `unwrap` by converting to `Result` and then propagating the error.
1 parent 86ca4a6 commit 085b7be

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sm2/src/pke/decrypting.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ fn decrypt(
167167
let encoded_c1 = EncodedPoint::from_bytes(c1).map_err(Error::from)?;
168168

169169
// verify that point c1 satisfies the elliptic curve
170-
let mut c1_point = AffinePoint::from_encoded_point(&encoded_c1).unwrap();
170+
let mut c1_point = AffinePoint::from_encoded_point(&encoded_c1)
171+
.into_option()
172+
.ok_or(Error)?;
171173

172174
// B2: compute point 𝑆 = [ℎ]𝐶1
173175
let s = c1_point * Scalar::reduce(&U256::from_u32(FieldElement::S));

0 commit comments

Comments
 (0)