From 7979dbede2757f5c8a00b79afe75618339510457 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Tue, 23 Jan 2018 19:42:56 -0500 Subject: [PATCH] Use bn_resize_words in BN_from_montgomery_word. Saves a bit of work, and we get a width sanity-check. Bug: 232 Change-Id: I1c6bc376c9d8aaf60a078fdc39f35b6f44a688c6 Reviewed-on: https://boringssl-review.googlesource.com/25251 Reviewed-by: Adam Langley --- crypto/fipsmodule/bn/montgomery.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crypto/fipsmodule/bn/montgomery.c b/crypto/fipsmodule/bn/montgomery.c index 624ab5fc..eaf2ba04 100644 --- a/crypto/fipsmodule/bn/montgomery.c +++ b/crypto/fipsmodule/bn/montgomery.c @@ -316,15 +316,10 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, } int max = (2 * n->top); // carry is stored separately - if (!bn_wexpand(r, max) || + if (!bn_resize_words(r, max) || !bn_wexpand(ret, n->top)) { return 0; } - // Clear the top words of |r|. - if (max > r->top) { - OPENSSL_memset(r->d + r->top, 0, (max - r->top) * sizeof(BN_ULONG)); - } - r->top = max; ret->top = n->top; if (!bn_from_montgomery_in_place(ret->d, ret->top, r->d, r->top, mont)) {