Skip to content

crypto: tidy up names, fix compiler warnings in legacy algos - #2195

Closed
vszakats wants to merge 26 commits into
libssh2:masterfrom
vszakats:talloptions
Closed

vszakats wants to merge 26 commits into
libssh2:masterfrom
vszakats:talloptions

Conversation

@vszakats

@vszakats vszakats commented Jul 3, 2026 •

Copy link
Copy Markdown
Member
  • fix issues found in CI when enabling legacy crypto options.
  • crypto.h: sync order of function prototypes and reorder by function
    and similarity.
  • crypto: sync argument names used in prototypes and definitions,
    across all backends.
  • crypto: rename some arguments to be consistent across backends,
    prototype definition and other functions in the same group.
  • crypto: rename filedata to blob.
  • openssl: silence DSA-specific clang-tidy warning the same way its RSA
    sibling was silenced earlier.
  • hostkey: fix unused assignment in
    hostkey_method_ssh_dss_sig_verify()
  • crypto: reflow arg lists.
  • mbedtls: avoid cast in ssh2_rsa_new_private_frommemory().

@vszakats
vszakats marked this pull request as draft July 3, 2026 12:02
@vszakats vszakats changed the title [TEST] GHA: enable all crypto options crypto: naming tidy-ups, fix compiler warnings in legacy algos Jul 3, 2026
vszakats added 26 commits July 3, 2026 15:44
```
/home/runner/work/libssh2/libssh2/src/hostkey.c:618:5: error: Value stored to 'sig_len' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
  618 |     sig_len -= 15;
      |     ^          ~~
/home/runner/work/libssh2/libssh2/src/hostkey.c:618:5: note: Value stored to 'sig_len' is never read
  618 |     sig_len -= 15;
      |     ^          ~~
```
https://github.com/libssh2/libssh2/actions/runs/28659316347/job/84995915568?pr=2195
```
/home/runner/work/libssh2/libssh2/src/openssl.c:1534:5: error: the result from calling 'memcpy' is not null-terminated [bugprone-not-null-terminated-result,-warnings-as-errors]
 1534 |     memcpy(p, "ssh-dss", 7);
      |     ^~~~~~             ~~~
      |     strcpy (char *)
/home/runner/work/libssh2/libssh2/src/openssl.c:1588:5: error: the result from calling 'memcpy' is not null-terminated [bugprone-not-null-terminated-result,-warnings-as-errors]
 1588 |     memcpy(method_buf, "ssh-dss", 7);
      |     ^~~~~~                      ~~~
      |     strcpy (char *)
```
https://github.com/libssh2/libssh2/actions/runs/28660077020/job/84998323452?pr=2195
@vszakats
vszakats marked this pull request as ready for review July 3, 2026 13:44
@vszakats vszakats changed the title crypto: naming tidy-ups, fix compiler warnings in legacy algos crypto: tidy up names, fix compiler warnings in legacy algos Jul 3, 2026
@vszakats
vszakats requested a review from Copilot July 3, 2026 13:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes crypto API argument naming across backends (notably renaming filedata → blob and harmonizing rsa/dsa/ed_ctx parameter names), reorders/cleans up prototypes in crypto.h, and applies a few targeted warning-silencing fixes in legacy algorithms/backends.

Changes:

  • Unify parameter names across crypto backends (OpenSSL, mbedTLS, WinCNG, libgcrypt, OS/400 QC3) and reflow long argument lists.
  • Rename in-memory key input parameters from filedata/filedata_len to blob/blob_len across relevant APIs.
  • Address CI warnings (unused assignment in DSS verify path, clang-tidy suppression for fixed-length memcpy cases).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/crypto.h Reorders and normalizes crypto API prototypes/argument names.
src/hostkey.c Removes unused sig_len adjustment in DSS signature verify path.
src/libgcrypt.c Renames parameters for consistency and reflows a few signatures.
src/libgcrypt.h Normalizes macro parameter names for RSA/DSA free helpers.
src/mbedtls.c Renames in-memory key inputs to blob and adjusts local variable naming.
src/openssl.c Renames parameters for consistency; adds targeted clang-tidy suppression comments.
src/openssl.h Normalizes macro parameter names for RSA/DSA/ECDSA free helpers and types.
src/os400qc3.c Renames in-memory key inputs and RSA verify parameter names for consistency.
src/wincng.c Renames parameters for consistency and reflows argument lists.

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

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c Resolved
@vszakats vszakats closed this in db0d107 Jul 3, 2026
@vszakats
vszakats deleted the talloptions branch July 3, 2026 14:13
vszakats added a commit that referenced this pull request Jul 5, 2026
…-terminator

- fix memleak on internal buffer OOM in
  `ssh2_rsa_new_private_frommemory()`.

- fix to use mbedtls allocator to null-terminate the local buffer and
  match the free call in `ssh2_ecdsa_new_private_frommemory()`.

- drop redundant casts for `mbedtls_calloc()` pointers.

- fix to free rsa object with `ssh2_rsa_free()` on key parse error in
  `ssh2_rsa_new_private_frommemory()`.

- fix to use mbedtls alloc/free for rsa object (to match
  `ssh2_rsa_free()`) in `ssh2_rsa_new_private()`.

- include terminating byte in `mbed_safe_free()` calls in.
  `ssh2_rsa_new_private_frommemory()`, `ssh2_pub_priv_keyfilememory()`,
  `ssh2_ecdsa_new_private_frommemory()`. For consistency/clarity only,
  the terminating byte is normally zero.

- reset `*out_public_key_octal` to NULL on fail in
  `ssh2_ecdsa_create_key()`.

- fix to use mbedtls allocator in `ssh2_ecdsa_create_key()`. This buffer
  is freed with `ssh2_ecdsa_free()`.

- fix to use libssh2 safe-free for `*out_public_key_octal` on fail in
  `ssh2_ecdsa_create_key()`. This buffer is freed with libssh2 free in
  the codebase.

- explicitly null-terminate buffers required to be so by mbedtls. Do not
  rely on `mbedtls_calloc()` doing the zeroing. To ensure the bug in
  `ssh2_ecdsa_new_private_frommemory()` doesn't repeat.

- fix to use mbedtls allocator in `mbed_parse_eckey()`,.
  `mbed_parse_openssh_key()`. (also stop passing `sesssion *` where no
  longer used after this.)

- fixup a type to avoid cast.

- drop newlines.

TL;DR most of these could cause crashes/leaks when using a custom
allocator, some were causing leaking crypto-backend objects, some leaks
on error path, `ssh2_ecdsa_new_private_frommemory()` failing randomly.

Ref: #2195 (few of these reported by Copilot)

Closes #2196
vszakats added a commit that referenced this pull request Jul 6, 2026
- hostkey: move static functions to avoid forward declarations.
- drop redundant parentheses.
- add `const` to `strncmp()`, `strlen()` argument casts.
- cipher-chachapoly: make `chachapoly_timingsafe_bcmp()` static.
- HACKING-CRYPTO: update argument names.
  Follow-up to db0d107 #2195
- fix minor nits around.

Closes #2235
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