-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSA call to TFM overwrites math operands #6359
Comments
I'm removing the other issue assignees at this point, pending further code review. Although at the time, it certainly seemed like there was a problem with the RSA calls adjusting the operand pointers, it appears a more simple problem to the HW vs SW mismatch is at fault: sign. The esp32_mp.c honors the WOLFSSL_SP_INT_NEGATIVE setting. See sp_int.c. There's not a single instance of |
@gojimmypi OK keep at it -- and please keep an eye out for problems rooted in passing the same pointer as operand and result to SP functions. last week I ran across a situation where @SparkiDev will also be keenly interested in what you uncover. re the m68k
|
Version
latest master
Description
While working on an example Espressif app to address #6205, I noticed that the RSA call to
mp_mul
would modify the operand in the expressiontmp = tmpb + q * tmp
, specifically in the conditional check:if (ret == 0 && mp_mul(tmp, &key->q, tmp) != MP_OKAY)
This is not immediately obvious until one views the definition and notes that all of the parameters are pointers:
int mp_mul (mp_int * a, mp_int * b, mp_int * c)
In my specific case, in attempting to see where things go sideways with the HW acceleration result not being the same as the software calcs, I have the
A2
,B2
, andC2
values calculated in parallel and compared at runtime. A sample warning can be seen in the output log.As seen here in the rsa.c, the use of the identical pointer
tmp
for both the operanda
and resultsc
ends up modifying the pointer toa
to actually end up pointing toc
after the call:More explicitly, I don't think this should ever occur:
Although technically it would seem to usually work, one would think that a call to a multiplication operation should not actually ever change the operands
a
orb
in addition to the output result,c
eh?There's (what seems to be) an attempt to save the tmp operand in
tmpa
, but as it is just a pointer, bothtmpa
andtmp
of course point to the same memory location.I have a possible update that actually does save the operands, using a new tmpc declaration. Just before returning, I copy the value of
tmpc
to thetmp
return parameter.This solution may not be the best, but it is a successful, operating example. Before pursuing and further polish, I'm interested in feedback if this seems reasonable.
Thank you,
Y = Y * X
where the pointer adjusts the underlying address of an operandA
to match the address of the resultC
:The text was updated successfully, but these errors were encountered: