Skip to content

pss: pin salt length bounds in the AlgorithmIdentifier tests - #730

Open
choksi2212 wants to merge 1 commit into
RustCrypto:masterfrom
choksi2212:test/pss-salt-len-coverage-703
Open

choksi2212 wants to merge 1 commit into
RustCrypto:masterfrom
choksi2212:test/pss-salt-len-coverage-703

Conversation

@choksi2212

Copy link
Copy Markdown

Tests-only follow-up to #704, carrying over the additional pss salt length tests from #714, as invited in #714 (comment). No production code is touched.

What the tests pin

RsaPssParams::salt_len is a u8, so a salt_len of 256 or more cannot be represented in the PSS AlgorithmIdentifier. Before #704, the as u8 cast silently truncated such lengths (256 wrapped to 0), advertising a wrong salt length to verifiers and making valid signatures fail verification (issue #703). #704 added the u8::try_from rejection; this PR pins it down:

  1. test_pss_algo_id_salt_len_representable (255, 128): the encoded AlgorithmIdentifier parameters DER-round-trip back to the configured salt_len, for both SigningKey and BlindedSigningKey. This is stronger than an is_ok() check: it catches any future encoding change that succeeds but advertises a wrong value.
  2. test_pss_algo_id_salt_len_out_of_range (256, 300, usize::MAX): both key types error instead of truncating.
  3. test_pss_algo_id_default_salt_len_unchanged: the digest-size default (get_default_pss_signature_algo_id) still encodes and carries the digest's output size, i.e. the validation does not alter the default path.

Verification

  • Focused: 6/6 new test cases pass on top of Reject PSS salt lengths that do not fit in a u8 #704.
  • Negative control: with the u8::try_from guard removed (truncation restored), the three out-of-range cases fail (encoding wrongly succeeds) while the representable and default tests keep passing, so each test fails exactly when its target behavior regresses.
  • cargo test (default features): all suites green (87 lib + integration).
  • cargo test --all-features: all suites green (102 lib + integration).
  • cargo clippy --all -- -D warnings (the repo's CI invocation): clean.
  • cargo fmt --check: clean.

Refs #703

Complements the rejection added in RustCrypto#704 with the tests from RustCrypto#714:

- representable salt lengths (255 boundary, 128) DER-round-trip through the
  encoded AlgorithmIdentifier parameters back to the configured salt_len,
  for both SigningKey and BlindedSigningKey (pins that the advertised
  parameters carry the right value, not just that encoding succeeds)
- the out-of-range matrix (256, 300, usize::MAX) errors on both key types
  instead of truncating to u8 (verified: all three fail when the
  u8::try_from guard is removed)
- the digest-size default path still encodes with the digest's output size

Refs RustCrypto#703

Signed-off-by: Manas Choksi <12302040701105@mbit.edu.in>

This branch has not been deployed

No deployments
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.

1 participant