Skip to content

ECCSI: blind modular inversion when signing - #12117

Open
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:eccsi_sign_blind_invmod
Open

SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:eccsi_sign_blind_invmod

Conversation

@SparkiDev

Copy link
Copy Markdown
Contributor

Description

wc_SignEccsiHash() inverted s = HE + r * SSK mod q with mp_invmod(), which is not constant time. The value depends on the secret signing key and the ephemeral nonce.

Multiply s by a random non-zero blinding value b before inverting and multiply the result by b afterwards, as is done for ECDSA signing. The blinding value is zeroized after use. Also erase the ephemeral key j on all paths after it is generated, not only when the inversion succeeds.

Fixes zd#22802

Testing

./configure --enable-eccsi

@SparkiDev SparkiDev self-assigned this Nov 12, 2026
Copilot AI balanced review requested due to automatic review settings November 12, 2026 23:29
@SparkiDev
SparkiDev force-pushed the eccsi_sign_blind_invmod branch from f4235ba to b0a33a0 Compare November 12, 2026 23:30

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.

🟡 Changes recommended

Targeted tests are missing to verify error propagation, secret zeroization, and successful signing and verification after recovery from blinding, inversion, and unblinding failures.

1 open issue
What changed in this PR

This PR hardens wolfCrypt’s ECCSI signing by blinding the secret-dependent modular inversion and extending ephemeral-key cleanup to failure paths.

Changes:

  • Generate a random non-zero blinding value, apply it around inversion, and erase it afterward.
  • Erase the ephemeral signing key on all paths after generation.
File Description
wolfcrypt/​src/​eccsi.c Adds inversion blinding and broadens secret cleanup in wc_SignEccsiHash().

Review effort: Balanced

Comment thread wolfcrypt/src/eccsi.c Resolved
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +36 B, text +11,624 B (+4.1%, 294,132 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@SparkiDev
SparkiDev force-pushed the eccsi_sign_blind_invmod branch from b0a33a0 to d8b9280 Compare November 13, 2026 00:17
@SparkiDev

Copy link
Copy Markdown
Contributor Author

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.

🟡 Changes recommended

The P-256 path bypasses blinding and exposes secret-dependent control flow, while small-stack allocations ignore the configured heap and can cause signing failures.

3 open issues

Review effort: Balanced

Comment thread wolfcrypt/src/eccsi.c Resolved
Comment thread wolfssl/wolfcrypt/sp.h Resolved

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.

🟡 Changes recommended

The new x86-64 path converts the unblinded secret using operand-dependent division, exposing secret-dependent timing on affected CPUs and requiring fixed-time conversion or retention of the blinded path.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread wolfcrypt/src/eccsi.c Resolved

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.

🟡 Changes recommended

Critical issues remain: secret-dependent conversion loops risk leaking secrets, and missing final Montgomery normalization can produce out-of-range ECCSI signature components.

3 open issues

Review effort: Balanced

Comment thread wolfcrypt/src/eccsi.c Resolved
Comment thread wolfcrypt/src/sp_x86_64.c Resolved
@SparkiDev
SparkiDev force-pushed the eccsi_sign_blind_invmod branch from 98faff7 to f95e9d6 Compare November 13, 2026 02:04
Return only s' from SP, which is public, rather than s^-1 - converting
a secret to an mp_int clamps it, which is not constant time. Convert to
Montgomery form by multiplying by R^2 rather than with division, and
reduce the result modulo the order before returning it. Also drops the
generic multiply by j. Use the key's heap for SP allocations.

Regenerated SP code: converting an mp_int with digits narrower than the
SP word now loops a fixed number of times with masked reads.

Add white-box tests that fail each step 5 operation after j is generated
and check the error is returned, the blind and j are erased, and signing
and verification succeed afterwards.
@SparkiDev
SparkiDev force-pushed the eccsi_sign_blind_invmod branch from f95e9d6 to 9e79194 Compare November 13, 2026 03:07
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