diff options
author | lloyd <[email protected]> | 2010-09-23 22:45:29 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-23 22:45:29 +0000 |
commit | 2e80fe0f6995cb71d01c2486103a8443b651cc34 (patch) | |
tree | 0e69c753c10f4d154eeeee98f9025c93fe97c772 /src | |
parent | e48b527ed80c966fb5a9f12b69973745b2e0b6ea (diff) |
Cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/math/bigint/mp_core.h | 4 | ||||
-rw-r--r-- | src/math/bigint/mp_misc.cpp | 36 |
2 files changed, 24 insertions, 16 deletions
diff --git a/src/math/bigint/mp_core.h b/src/math/bigint/mp_core.h index bbe6b1310..4bc04ed52 100644 --- a/src/math/bigint/mp_core.h +++ b/src/math/bigint/mp_core.h @@ -86,8 +86,8 @@ void bigint_monty_redc(word z[], u32bit z_size, /* * Misc Utility Operations */ -u32bit bigint_divcore(word q, word y1, word y2, - word x1, word x2, word x3); +u32bit bigint_divcore(word q, word y2, word y1, + word x3, word x2, word x1); /** * Compare x and y diff --git a/src/math/bigint/mp_misc.cpp b/src/math/bigint/mp_misc.cpp index 86d5f3d50..77b8e6f51 100644 --- a/src/math/bigint/mp_misc.cpp +++ b/src/math/bigint/mp_misc.cpp @@ -15,19 +15,23 @@ extern "C" { /* * Core Division Operation */ -u32bit bigint_divcore(word q, word y1, word y2, - word x1, word x2, word x3) +u32bit bigint_divcore(word q, word y2, word y1, + word x3, word x2, word x1) { - word y0 = 0; - y2 = word_madd2(q, y2, &y0); - y1 = word_madd2(q, y1, &y0); - - if(y0 > x1) return 1; - if(y0 < x1) return 0; - if(y1 > x2) return 1; - if(y1 < x2) return 0; - if(y2 > x3) return 1; - if(y2 < x3) return 0; + // Compute (y2,y1) * q + + word y3 = 0; + y1 = word_madd2(q, y1, &y3); + y2 = word_madd2(q, y2, &y3); + + // Return (y3,y2,y1) >? (x3,x2,x1) + + if(y3 > x3) return 1; + if(y3 < x3) return 0; + if(y2 > x2) return 1; + if(y2 < x2) return 0; + if(y1 > x1) return 1; + if(y1 < x1) return 0; return 0; } @@ -45,11 +49,15 @@ s32bit bigint_cmp(const word x[], u32bit x_size, return 1; x_size--; } + for(u32bit j = x_size; j > 0; --j) { - if(x[j-1] > y[j-1]) return 1; - if(x[j-1] < y[j-1]) return -1; + if(x[j-1] > y[j-1]) + return 1; + if(x[j-1] < y[j-1]) + return -1; } + return 0; } |