Skip to content

Honor restricted PSS min saltlen for AUTO verify - #3470

Open
justsmth wants to merge 1 commit into
aws:mainfrom
justsmth:fix/RSA_PSS_SALTLEN_AUTO-min-length
Open

justsmth wants to merge 1 commit into
aws:mainfrom
justsmth:fix/RSA_PSS_SALTLEN_AUTO-min-length

Conversation

@justsmth

@justsmth justsmth commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Context and motivation

An EVP_PKEY_RSA_PSS key can restrict the minimum salt length. That minimum was enforced everywhere except RSA_PSS_SALTLEN_AUTO, where verify recovered the salt length from the signature and accepted any value, including zero. EVP_PKEY_CTX_dup also dropped min_saltlen, so a duplicated context lost the restriction entirely.

Description of changes

RSA_PSS_SALTLEN_AUTO remains settable on a restricted key, but verify now checks the recovered salt length against the key's minimum, plumbed through new module-internal variants of RSA_verify_pss_mgf1 and RSA_verify_PKCS1_PSS_mgf1. The public functions pass "no minimum" and are unchanged. pkey_rsa_copy now propagates min_saltlen. The rest is readability: a public RSA_PSS_SALTLEN_AUTO (-2) alongside the existing RSA_PSS_SALTLEN_DIGEST, replacing the bare -2 literals and comments.

Two non-obvious points:

  • This differs from OpenSSL on purpose. OpenSSL rejects AUTO at EVP_PKEY_CTX_set_rsa_pss_saltlen time for a restricted verify; we accept it and enforce the floor on the recovered length instead, keeping AUTO's meaning intact. So we accept any salt at or above the minimum where OpenSSL requires exactly it, and the failure surfaces from EVP_PKEY_verify rather than the setter. Documented there.
  • Signing is unaffected: AUTO maximizes the salt and pkey_pss_init already rejects a key whose minimum exceeds that maximum, so signatures we produce still verify.

Testing

New EVPExtraTest.RestrictedPssAutoSaltlenHonorsMinimum uses kExampleRSAPSSKeyPKCS8, which omits saltLength and so carries the RFC 4055 default minimum of 20. It signs at the RSA layer with salt lengths 0, 1, 19, 20 and 24, then verifies each through EVP_PKEY_verify with AUTO set, on both the original and a duplicated context: below the minimum must fail, at or above must pass.

Each half of the fix was reverted in turn to confirm the test catches it -- disabling the floor check lets the short-salt signatures verify, dropping the min_saltlen copy breaks the duplicated context, and turning the floor into an equality test breaks the salt-24 case.

Review considerations

  • The behavior change is limited to restricted EVP_PKEY_RSA_PSS keys verifying with AUTO, where a verify can now fail that previously succeeded. That is the intent, but it is a tightening.
  • Inside the FIPS module boundary: both new functions are module-internal, called only from crypto/fipsmodule, and service indicator handling is unchanged.

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.

@justsmth
justsmth requested a review from a team as a code owner September 1, 2026 16:15

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

const uint8_t *EM, int sLen, int min_sLen) {
// We have to avoid the underlying SHA services updating the indicator
// state, so we lock the state here.
FIPS_service_indicator_lock_state();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: call to undeclared function 'FIPS_service_indicator_lock_state'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]

  FIPS_service_indicator_lock_state();
  ^

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🔒 Security ReviewView Report

Please review before merging.

@codecov-commenter

codecov-commenter commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.19%. Comparing base (f8f6fb5) to head (26a6bb1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3470      +/-   ##
==========================================
- Coverage   78.36%   78.19%   -0.17%     
==========================================
  Files         700      700              
  Lines      125744   125784      +40     
  Branches    17388    17388              
==========================================
- Hits        98540    98360     -180     
- Misses      26332    26554     +222     
+ Partials      872      870       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@justsmth
justsmth requested review from WillChilds-Klein, jakemas and nebeid and removed request for WillChilds-Klein September 8, 2026 16:55
RSA_PSS_SALTLEN_AUTO on an EVP_PKEY_RSA_PSS key recovered any salt on
verify, bypassing the key's minimum. Check the recovered length against
min_saltlen, and keep that restriction across EVP_PKEY_CTX_dup.
@justsmth
justsmth force-pushed the fix/RSA_PSS_SALTLEN_AUTO-min-length branch from 6887ca7 to 26a6bb1 Compare September 14, 2026 12:54
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.

2 participants