diff options
author | Jack Lloyd <[email protected]> | 2018-11-09 12:53:44 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-09 12:53:44 -0500 |
commit | 86f3dc55a652ccc4653d4617ea5a50e63bc818c7 (patch) | |
tree | deacfbbd54d146ad2b874fbcc945e4ffd4dd9672 | |
parent | ddb9808ef59168174e8299b02fea4e84ac2742e3 (diff) |
Use resize instead of shrink_to_fit
Avoid recalculating significant words which slows down reduction
-rw-r--r-- | src/lib/math/bigint/bigint.h | 7 | ||||
-rw-r--r-- | src/lib/math/numbertheory/nistp_redc.cpp | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index 530fd5ecf..bd63425fd 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -570,6 +570,8 @@ class BOTAN_PUBLIC_API(2,0) BigInt final m_data.shrink_to_fit(min_size); } + void resize(size_t s) { m_data.resize(s); } + /** * Fill BigInt with a random number with size of bitsize * @@ -910,6 +912,11 @@ class BOTAN_PUBLIC_API(2,0) BigInt final m_reg.resize(words); } + void resize(size_t s) + { + m_reg.resize(s); + } + void swap(Data& other) { m_reg.swap(other.m_reg); diff --git a/src/lib/math/numbertheory/nistp_redc.cpp b/src/lib/math/numbertheory/nistp_redc.cpp index abec38d75..5ad4515b4 100644 --- a/src/lib/math/numbertheory/nistp_redc.cpp +++ b/src/lib/math/numbertheory/nistp_redc.cpp @@ -247,7 +247,7 @@ void redc_p224(BigInt& x, secure_vector<word>& ws) const int64_t S6 = 0xFFFFFFFF + X06 + X10 - X13; x.mask_bits(224); - x.shrink_to_fit(p224_limbs + 1); + x.resize(p224_limbs + 1); int64_t S = 0; uint32_t R0 = 0, R1 = 0; @@ -358,7 +358,7 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) const int64_t S7 = 0xFFFFFFFA + X07 + X15*3 + X08 - X10 - X11 - X12 - X13; x.mask_bits(256); - x.shrink_to_fit(p256_limbs + 1); + x.resize(p256_limbs + 1); int64_t S = 0; @@ -505,7 +505,7 @@ void redc_p384(BigInt& x, secure_vector<word>& ws) const int64_t SB = 0xFFFFFFFF + X11 + X19 + X20 + X23 - X22; x.mask_bits(384); - x.shrink_to_fit(p384_limbs + 1); + x.resize(p384_limbs + 1); int64_t S = 0; |