summaryrefslogtreecommitdiff
path: root/src/KM_prng.cpp
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-11-09 15:25:08 +0000
committerCarl Hetherington <cth@carlh.net>2019-12-03 17:01:32 +0100
commit04cf4482e9bcd5329f717f4ccffd94ff3e751e2a (patch)
treee76ce9199c4b253acbbfb5e0e018956f2afb6305 /src/KM_prng.cpp
parent4d1b1c3f72376c920afc72834bba36e8fc9345e3 (diff)
Remove stack-allocated BIGNUM which is no longer allowed in OpenSSL 1.1.
Diffstat (limited to 'src/KM_prng.cpp')
-rwxr-xr-xsrc/KM_prng.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/KM_prng.cpp b/src/KM_prng.cpp
index 181c563..735289d 100755
--- a/src/KM_prng.cpp
+++ b/src/KM_prng.cpp
@@ -239,11 +239,12 @@ Kumu::Gen_FIPS_186_Value(const byte_t* key, ui32_t key_size, byte_t* out_buf, ui
key_size = SHA_DIGEST_LENGTH; // pad short key ( b < 160 )
// create the 2^b constant
- BIGNUM c_2powb, c_2, c_b;
- BN_init(&c_2powb); BN_init(&c_2); BN_init(&c_b);
- BN_set_word(&c_2, 2);
- BN_set_word(&c_b, key_size * 8);
- BN_exp(&c_2powb, &c_2, &c_b, ctx1);
+ BIGNUM* c_2powb = BN_new();
+ BIGNUM* c_2 = BN_new();
+ BIGNUM* c_b = BN_new();
+ BN_set_word(c_2, 2);
+ BN_set_word(c_b, key_size * 8);
+ BN_exp(c_2powb, c_2, c_b, ctx1);
for (;;)
{
@@ -268,21 +269,29 @@ Kumu::Gen_FIPS_186_Value(const byte_t* key, ui32_t key_size, byte_t* out_buf, ui
out_buf += SHA_DIGEST_LENGTH;
// step d -- XKEY = (1 + XKEY + x) mod 2^b
- BIGNUM bn_tmp, bn_xkey, bn_x_n;
- BN_init(&bn_tmp); BN_init(&bn_xkey); BN_init(&bn_x_n);
+ BIGNUM* bn_tmp = BN_new();
+ BIGNUM* bn_xkey = BN_new();
+ BIGNUM* bn_x_n = BN_new();
- BN_bin2bn(xkey, key_size, &bn_xkey);
- BN_bin2bn(sha_buf, SHA_DIGEST_LENGTH, &bn_x_n);
- BN_add_word(&bn_xkey, 1); // xkey += 1
- BN_add(&bn_tmp, &bn_xkey, &bn_x_n); // xkey += x
- BN_mod(&bn_xkey, &bn_tmp, &c_2powb, ctx1); // xkey = xkey mod (2^b)
+ BN_bin2bn(xkey, key_size, bn_xkey);
+ BN_bin2bn(sha_buf, SHA_DIGEST_LENGTH, bn_x_n);
+ BN_add_word(bn_xkey, 1); // xkey += 1
+ BN_add(bn_tmp, bn_xkey, bn_x_n); // xkey += x
+ BN_mod(bn_xkey, bn_tmp, c_2powb, ctx1); // xkey = xkey mod (2^b)
memset(xkey, 0, xkey_len);
- ui32_t bn_buf_len = BN_num_bytes(&bn_xkey);
+ ui32_t bn_buf_len = BN_num_bytes(bn_xkey);
ui32_t idx = ( bn_buf_len < key_size ) ? key_size - bn_buf_len : 0;
- BN_bn2bin(&bn_xkey, &xkey[idx]);
+ BN_bn2bin(bn_xkey, &xkey[idx]);
+
+ BN_free(bn_tmp);
+ BN_free(bn_xkey);
+ BN_free(bn_x_n);
}
+ BN_free(c_2powb);
+ BN_free(c_2);
+ BN_free(c_b);
BN_CTX_free(ctx1);
}