Repository navigation
sp_int: use r5 for the high half in clang Thumb SP_ASM_SQR_ADD_NO - #12123
yosuke-wolfssl wants to merge 1 commit into
Conversation
- The clang copy of SP_ASM_SQR_ADD_NO in the WOLFSSL_SP_ARM_THUMB block holds the high 16 bits of va in r5 and the low 16 bits in r6. Issue: F-18178
|
@claude review |
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12123
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
|
@claude review |
There was a problem hiding this comment.
I reviewed this and didn't find any bugs. The fix looks correct, but it changes bignum squaring asm in wolfCrypt, so a maintainer should still take a look.
What was reviewed:
- The arithmetic now works out. al^2 goes into l, and ah^2 goes into h with the carry from l. The cross term 2alah2^16 is split into (alah << 17) for l and (alah >> 15) for h, which is right because alah fits in 32 bits.
- The rewritten clang Thumb macro has the same instructions and register use as the other two Thumb copies of SP_ASM_SQR_ADD_NO in sp_int.c (around lines 2462 and 2945). Only the syntax differs.
- r5 and r6 are both clobbered, so the compiler cannot put the "l" operands va, vl or vh in either register.
- I only read the code. I did not build or run anything.
Extended reasoning...
The change touches 7 lines in one wolfCrypt inline-asm macro, the clang ARM Thumb SP_ASM_SQR_ADD_NO in wolfcrypt/src/sp_int.c. That macro is used for multi-precision squaring in RSA, DH and ECC. The old code loaded both 16-bit halves into r6, so the squares came out wrong. The new code matches the existing GCC and older-syntax Thumb versions of the macro exactly. I deferred rather than approved because this is crypto math that no CI job builds, and the review threads from other reviewers are not visible here.
Problem
The clang copy of
SP_ASM_SQR_ADD_NOin theWOLFSSL_SP_ARM_THUMBblock loads both 16-bit halves ofvaintor6, so the high half is overwritten before it is used.Affected builds: sp_int with
WOLFSSL_SP_ARM_THUMBand 32-bit digits, compiled by clang or Arm Compiler 6 (Cortex-M0/M0+ class).Fix (
wolfcrypt/src/sp_int.c)The high half now goes in
r5, which is already in the clobber list, and the low half inr6.Closes f-18178.
Verification
ARMv6 Thumb-1 under qemu-arm 8.2.2,
--with-arm-target=thumb, comparingmp_sqr()withmp_mul(a, a)and runningtestwolfcrypt:mp_sqrtestwolfcryptdh_test()mp,DH,ECC)The clang runs also needed some local workarounds for issues already on master, none of them in this PR.
They are tracked separately.
No test is added. No CI job builds clang Thumb, it's also taken as follow-up.