Skip to content

F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output#216

Draft
miyazakh wants to merge 2 commits intowolfSSL:mainfrom
miyazakh:f-1483_sha1prefix
Draft

F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output#216
miyazakh wants to merge 2 commits intowolfSSL:mainfrom
miyazakh:f-1483_sha1prefix

Conversation

@miyazakh
Copy link
Copy Markdown
Contributor

@miyazakh miyazakh commented Apr 2, 2026

Summary

  • XSTRNCMP(alg, "sha", 3) in wolfCLU_hash and wolfCLU_hashSetup
    matched "sha256", "sha384", and "sha512", causing SHA-1 to overwrite
    the correct digest and size
  • Fixed by adding XSTRLEN(alg) == 3 guard to the SHA-1 branch in
    clu_hash.c and clu_hash_setup.c
  • Fixed algCheck loop in clu_hash_setup.c to use XSTRCMP for
    exact matching instead of prefix matching

Depend on : #211

Copilot AI review requested due to automatic review settings April 2, 2026 04:01
@miyazakh miyazakh self-assigned this Apr 2, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an algorithm-selection bug in the CLI hash command where SHA-1 prefix matching could incorrectly override SHA-256/384/512 digest output, and tightens algorithm validation to require exact matches.

Changes:

  • Guard SHA-1 selection in wolfCLU_hash / wolfCLU_hashSetup with XSTRLEN(alg) == 3 so only "sha" maps to SHA-1.
  • Change hash algorithm validation to exact string matching (XSTRCMP) to avoid prefix-based acceptance.
  • Broaden OCSP interop test error-message matching; update clu_x509_sign.c hash-type switch version gating / case handling.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/hash/clu_hash.c Prevents SHA-1 branch from matching sha256/sha384/sha512 by requiring exact "sha".
src/hash/clu_hash_setup.c Requires exact algorithm match during argument validation and ensures SHA-1 size only applies to "sha".
tests/ocsp/ocsp-interop-test.sh Accepts additional common “file not found” phrasing in Test 6 logs.
src/x509/clu_x509_sign.c Adjusts conditional compilation for unsupported hash-type cases in certificate signing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1277 to +1283
#if LIBWOLFSSL_VERSION_HEX >= 0x05009000
case WC_HASH_TYPE_SHA512_224:
case WC_HASH_TYPE_SHA512_256:
case WC_HASH_TYPE_SHAKE128:
case WC_HASH_TYPE_SHAKE256:
case WC_HASH_TYPE_SM3:
#elif LIBWOLFSSL_VERSION_HEX > 0x05001000
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The PR description doesn’t mention this change in certificate-signing hash handling. Also, introducing a new hard-coded wolfSSL version threshold (>= 0x05009000) is inconsistent with the rest of the codebase (which generally gates on > 0x05001000) and drops the previous per-feature guards (e.g., WOLFSSL_SHAKE128/WOLFSSL_SHAKE256). Consider documenting why 5.9.0 is required here, or switching to feature/enum-availability guards to avoid version-specific build regressions.

Copilot uses AI. Check for mistakes.
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