forked from wolfSSL/wolfssl
SP int math; submod fix
Fix for sp_submod() to reduce by modulus when a or b are equal to modulus as well as when greater.
This commit is contained in:
@ -6494,13 +6494,13 @@ int sp_submod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
|
|||||||
|
|
||||||
ALLOC_SP_INT_ARRAY(t, used, 2, err, NULL);
|
ALLOC_SP_INT_ARRAY(t, used, 2, err, NULL);
|
||||||
if (err == MP_OKAY) {
|
if (err == MP_OKAY) {
|
||||||
if (_sp_cmp(a, m) == MP_GT) {
|
if (_sp_cmp(a, m) != MP_LT) {
|
||||||
err = sp_mod(a, m, t[0]);
|
err = sp_mod(a, m, t[0]);
|
||||||
a = t[0];
|
a = t[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (err == MP_OKAY) {
|
if (err == MP_OKAY) {
|
||||||
if (_sp_cmp(b, m) == MP_GT) {
|
if (_sp_cmp(b, m) != MP_LT) {
|
||||||
err = sp_mod(b, m, t[1]);
|
err = sp_mod(b, m, t[1]);
|
||||||
b = t[1];
|
b = t[1];
|
||||||
}
|
}
|
||||||
@ -6508,14 +6508,12 @@ int sp_submod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
|
|||||||
if (err == MP_OKAY) {
|
if (err == MP_OKAY) {
|
||||||
if (_sp_cmp(a, b) == MP_LT) {
|
if (_sp_cmp(a, b) == MP_LT) {
|
||||||
err = sp_add(a, m, t[0]);
|
err = sp_add(a, m, t[0]);
|
||||||
if (err == MP_OKAY) {
|
a = t[0];
|
||||||
err = sp_sub(t[0], b, r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
err = sp_sub(a, b, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (err == MP_OKAY) {
|
||||||
|
err = sp_sub(a, b, r);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (err == MP_OKAY) {
|
if (err == MP_OKAY) {
|
||||||
|
Reference in New Issue
Block a user