From 955b46534d83a157efd74b240cdc287e9044dc3f Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 7 Mar 2017 14:51:05 -0500 Subject: [PATCH] eliminate some BIGNUM allocation overhead --- Crypto.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Crypto.cpp b/Crypto.cpp index a110c38f..9ca5928c 100644 --- a/Crypto.cpp +++ b/Crypto.cpp @@ -331,7 +331,8 @@ namespace crypto uint8_t * data, bool zeroPadding) { BN_CTX * ctx = BN_CTX_new (); - BIGNUM * x = BN_new (), * a = BN_new (), * b = BN_new (); + BN_CTX_start (ctx); + BIGNUM * x = BN_CTX_get (ctx), * a = BN_CTX_get (ctx), * b = BN_CTX_get (ctx); BN_bin2bn (key, 256, x); BN_sub (x, elgp, x); BN_sub_word (x, 1); // x = elgp - x- 1 BN_bin2bn (zeroPadding ? encrypted + 1 : encrypted, 256, a); @@ -341,7 +342,7 @@ namespace crypto BN_mod_mul (b, b, x, elgp, ctx); uint8_t m[255]; bn2buf (b, m, 255); - BN_free (x); BN_free (a); BN_free (b); + BN_CTX_end (ctx); BN_CTX_free (ctx); uint8_t hash[32]; SHA256 (m + 33, 222, hash);