mirror of https://github.com/wolfSSL/wolfssl.git
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.pull/5299/head
parent
f2acaa8ee9
commit
0159f17692
|
@ -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);
|
||||
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]);
|
||||
a = t[0];
|
||||
}
|
||||
}
|
||||
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]);
|
||||
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 (_sp_cmp(a, b) == MP_LT) {
|
||||
err = sp_add(a, m, t[0]);
|
||||
if (err == MP_OKAY) {
|
||||
err = sp_sub(t[0], b, r);
|
||||
}
|
||||
}
|
||||
else {
|
||||
err = sp_sub(a, b, r);
|
||||
a = t[0];
|
||||
}
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
err = sp_sub(a, b, r);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (err == MP_OKAY) {
|
||||
|
|
Loading…
Reference in New Issue