X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/e40955b56456a6191ebff48b00c667a0674b3bdb..f4535c6454395e6d56ce0091a07b6d4f7d54a47f:/mpmont.c diff --git a/mpmont.c b/mpmont.c index 24fc9a3..e62678d 100644 --- a/mpmont.c +++ b/mpmont.c @@ -49,7 +49,7 @@ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context * @mp *m@ = modulus to use * - * Returns: --- + * Returns: Zero on success, nonzero on error. * * Use: Initializes a Montgomery reduction context ready for use. * The argument @m@ must be a positive odd integer. @@ -57,18 +57,19 @@ #ifdef MPMONT_DISABLE -void mpmont_create(mpmont *mm, mp *m) +int mpmont_create(mpmont *mm, mp *m) { mp_shrink(m); mm->m = MP_COPY(m); mm->r = MP_ONE; mm->r2 = MP_ONE; mm->mi = MP_ONE; + return (0); } #else -void mpmont_create(mpmont *mm, mp *m) +int mpmont_create(mpmont *mm, mp *m) { size_t n = MP_LEN(m); mp *r2 = mp_new(2 * n + 1, 0); @@ -76,7 +77,8 @@ void mpmont_create(mpmont *mm, mp *m) /* --- Take a copy of the modulus --- */ - assert(MP_POSP(m) && MP_ODDP(m)); + if (!MP_POSP(m) || !MP_ODDP(m)) + return (-1); mm->m = MP_COPY(m); /* --- Determine %$R^2$% --- */ @@ -97,6 +99,7 @@ void mpmont_create(mpmont *mm, mp *m) mp_div(0, &mm->r2, r2, m); mm->r = mpmont_reduce(mm, MP_NEW, mm->r2); MP_DROP(r2); + return (0); } #endif