Repository navigation
Conversation
- fe_cswap/fe_cmov: put an optimization barrier on the mask so the compiler can't turn the swap into a branch (GCC -O3 on PPC64). - 128-bit field mul/sq/sq2: apply the x19/x2 multiples to 64-bit limbs before the products, so every product is a plain signed 64x64->128 multiply. Removes multiplies whose operand is a limb's sign word, which have operand-dependent latency on Cortex-A55. Faster on x86_64 (9-17%). Now the default. NO_CURVED25519_128BIT_FOLDED keeps the original form. - Cortex-A55/A53: WOLFSSL_CORTEX_A55/WOLFSSL_CORTEX_A53 turn on WOLFSSL_CURVE25519_FIXED_LATENCY_MUL. That forces the folded form and computes the 32-bit field's small multiples in unsigned arithmetic so Clang can't widen them into 64-bit multiplies. configure sets these when -mcpu/-mtune names cortex-a55 or cortex-a53.
Contributor
Author
|
Code generated with PR: |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The detection omits EXTRA_CFLAGS and EXTRA_CPPFLAGS, allowing Cortex-A55/A53 builds to select the 32-bit field implementation without enabling its timing mitigation.
1 open issue
What changed in this PR
This PR hardens wolfCrypt’s X25519/Ed25519 field operations against compiler-generated timing variations, while improving 128-bit arithmetic performance.
Changes:
- Add optimization barriers to conditional swaps and moves.
- Make folded 128-bit multiplication and squaring the default, with an opt-out.
- Add Cortex-A55/A53 detection and fixed-latency multiplication safeguards.
| File | Description |
|---|---|
wolfcrypt/src/fe_x25519_128.h |
Add mask barriers and folded multiplication/squaring implementations. |
wolfcrypt/src/fe_operations.c |
Define hardening controls and protect 32-bit small-multiple arithmetic. |
configure.ac |
Detect Cortex-A55/A53 targets to enable timing mitigations. |
Review effort: Balanced
| # fixed latency multiply code for the Curve25519/Ed25519 field operations when | ||
| # building for these cores (-mcpu/-mtune, including big.LITTLE e.g. | ||
| # cortex-a76.cortex-a55). | ||
| case "$CC $CFLAGS $CPPFLAGS" in |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Fixes zd#22787, zd#22796
Testing
Tested PPC64, Cortex-A55, x86_64.
./configure --enable-x25519 --enable-ed25519