Check parameters before comparing pqdsa public keys#3229
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3229 +/- ##
==========================================
- Coverage 78.12% 78.11% -0.01%
==========================================
Files 689 689
Lines 123214 123232 +18
Branches 17137 17141 +4
==========================================
+ Hits 96257 96261 +4
- Misses 26047 26061 +14
Partials 910 910 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| static int pqdsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { | ||
| const PQDSA_KEY *a_key = a->pkey.pqdsa_key; |
There was a problem hiding this comment.
do we need NULL checks on a and b here before the dereference?
also, can we document this functions return values in a comment above? why return -2 instead of 0? callers might inadvertently do !pqdsa_cmp_parameters(...) and have unexpected behavior
There was a problem hiding this comment.
Added NULL checks and a doc comment.
I was confused about this at first too, but the tri-state return is intentional to align with EVP_PKEY_cmp's convention (1 = equal, 0 = not equal, negative = error). Also mirrored the same NULL check and docstring onto kem_cmp_parameters since it's applicable there as well.
Lines 56 to 61 in 9651480
There was a problem hiding this comment.
thanks. if we need to return negative on error, -2 still "feels" like an odd return value vs. -1 but if "negative" is the documented contract it doesn't really matter.
9db9e77 to
306a578
Compare
306a578 to
39ccb42
Compare
| } | ||
|
|
||
| static int pqdsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { | ||
| const PQDSA_KEY *a_key = a->pkey.pqdsa_key; |
There was a problem hiding this comment.
thanks. if we need to return negative on error, -2 still "feels" like an odd return value vs. -1 but if "negative" is the documented contract it doesn't really matter.
Issues:
Addresses
V2196133741Description of changes:
pqdsa_pub_cmpmemcmp'd two public keys using the length froma's variant, with no check thataandbwere the same ML-DSA parameter set. Adds apqdsa_cmp_parametershelper (mirroringkem_cmp_parametersinp_kem_asn1.c) that validates both keys are populated and share the same NID, and makespqdsa_pub_cmpreturn early when parameters don't match.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.