Skip to content

memory.c: add wc_ConstantCompare wrapper.#10867

Open
philljj wants to merge 2 commits into
wolfSSL:masterfrom
philljj:wc_const_comp
Open

memory.c: add wc_ConstantCompare wrapper.#10867
philljj wants to merge 2 commits into
wolfSSL:masterfrom
philljj:wc_const_comp

Conversation

@philljj

@philljj philljj commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Add a public wc_ConstantCompare wrapper, similar to the existing wc_ForceZero wrapper. Other project integrations regularly reuse wc_ForceZero, but then reimplement their own ConstantCompare if they don't include misc.c.

The wc_ConstantCompare is guarded by #ifndef WOLFSSL_NO_CONST_CMP.

Update linuxkm to use wc_ForceZero and wc_ConstantCompare where it wasn't. linuxkm and bsdkm were already using wc_ForceZero in a few spots.

Testing

Tested with bsdkm, linuxkm, and all-c89-clang-tidy.

@philljj philljj self-assigned this Jul 8, 2026
Copilot AI review requested due to automatic review settings July 8, 2026 21:45

Copilot AI 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.

Pull request overview

This PR introduces a new public wolfCrypt API wrapper wc_ConstantCompare() (patterned after the existing wc_ForceZero() wrapper) and updates Linux kernel module glue code to prefer the public wc_ wrappers over internal ForceZero() / ConstantCompare().

Changes:

  • Add public wc_ConstantCompare() declaration to wolfssl/wolfcrypt/memory.h.
  • Implement wc_ConstantCompare() in wolfcrypt/src/memory.c as a thin wrapper around ConstantCompare().
  • Update several linuxkm/*_glue.c call sites to use wc_ForceZero() and wc_ConstantCompare().

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
wolfssl/wolfcrypt/memory.h Exposes new public wc_ConstantCompare() API (guarded by WOLFSSL_NO_CONST_CMP).
wolfcrypt/src/memory.c Implements wc_ConstantCompare() wrapper calling ConstantCompare().
linuxkm/lkcapi_sha_glue.c Switches sensitive-buffer clearing to wc_ForceZero().
linuxkm/lkcapi_rsa_glue.c Switches buffer clearing to wc_ForceZero() and signature comparisons to wc_ConstantCompare().
linuxkm/lkcapi_ecdh_glue.c Switches shared-secret clearing to wc_ForceZero().
linuxkm/lkcapi_dh_glue.c Switches key/shared-secret clearing to wc_ForceZero().
linuxkm/lkcapi_aes_glue.c Switches temp buffer clearing to wc_ForceZero().

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

Comment thread linuxkm/lkcapi_sha_glue.c
Comment thread linuxkm/lkcapi_dh_glue.c
Comment thread linuxkm/lkcapi_ecdh_glue.c
Comment thread linuxkm/lkcapi_aes_glue.c
Comment thread linuxkm/lkcapi_rsa_glue.c
Comment thread linuxkm/lkcapi_rsa_glue.c
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m0plus

  • FLASH: .text +28 B (+0.0%, 64,183 B / 262,144 B, total: 24% used)

gcc-arm-cortex-m3

  • FLASH: .text +24 B (+0.0%, 122,473 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +64 B (+0.1%, 66,827 B / 262,144 B, total: 25% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +64 B (+0.0%, 770,828 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 279,300 B / 1,048,576 B, total: 27% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +64 B (+0.0%, 235,982 B / 262,144 B, total: 90% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 200,284 B / 262,144 B, total: 76% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +64 B (+0.0%, 279,876 B / 1,048,576 B, total: 27% used)

linuxkm-pie

  • Data: __patchable_function_entries +8 B (+0.0%, 25,520 B)

linuxkm-standard

@philljj

philljj commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

No Malloc Tests failure will be fixed here:

@douzzer douzzer 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.

We want the fast inline version, ForceZero, in the linuxkm glue layer -- it's faster and avoids some a little stack burden.

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.

3 participants