- /* fixup result if Montgomery reduction is used */
- if ((err = mp_montgomery_reduce (&res, P, mp)) != MP_OKAY) {
- goto __RES;
+ /* fixup result if Montgomery reduction is used
+ * recall that any value in a Montgomery system is
+ * actually multiplied by R mod n. So we have
+ * to reduce one more time to cancel out the factor
+ * of R.
+ */
+ if ((err = redux(&res, P, mp)) != MP_OKAY) {
+ goto LBL_RES;