From f515ef955ab8c07c0e9906acb2866c4504f192cc Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 24 Jun 2017 22:48:10 +0800 Subject: [PATCH] initialise with appropriate size --- bn_mp_exptmod_fast.c | 6 +++--- bn_mp_mod.c | 2 +- bn_mp_mulmod.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bn_mp_exptmod_fast.c b/bn_mp_exptmod_fast.c index 8075848..33e7643 100644 --- a/bn_mp_exptmod_fast.c +++ b/bn_mp_exptmod_fast.c @@ -67,13 +67,13 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode /* init M array */ /* init first cell */ - if ((err = mp_init(&M[1])) != MP_OKAY) { + if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) { return err; } /* now init the second half of the array */ for (x = 1<<(winsize-1); x < (1 << winsize); x++) { - if ((err = mp_init(&M[x])) != MP_OKAY) { + if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) { for (y = 1<<(winsize-1); y < x; y++) { mp_clear (&M[y]); } @@ -133,7 +133,7 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode } /* setup result */ - if ((err = mp_init (&res)) != MP_OKAY) { + if ((err = mp_init_size (&res, P->alloc)) != MP_OKAY) { goto LBL_M; } diff --git a/bn_mp_mod.c b/bn_mp_mod.c index b67467d..67b6796 100644 --- a/bn_mp_mod.c +++ b/bn_mp_mod.c @@ -22,7 +22,7 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c) mp_int t; int res; - if ((res = mp_init (&t)) != MP_OKAY) { + if ((res = mp_init_size (&t, b->used)) != MP_OKAY) { return res; } diff --git a/bn_mp_mulmod.c b/bn_mp_mulmod.c index 5ea88ef..edd8fcb 100644 --- a/bn_mp_mulmod.c +++ b/bn_mp_mulmod.c @@ -21,7 +21,7 @@ int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) int res; mp_int t; - if ((res = mp_init (&t)) != MP_OKAY) { + if ((res = mp_init_size (&t, c->used)) != MP_OKAY) { return res; }