aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/nr/nr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pubkey/nr/nr.cpp')
-rw-r--r--src/pubkey/nr/nr.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp
index 61cf7eb3f..87cf3d038 100644
--- a/src/pubkey/nr/nr.cpp
+++ b/src/pubkey/nr/nr.cpp
@@ -8,11 +8,12 @@
#include <botan/nr.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
+#include <future>
namespace Botan {
NR_PublicKey::NR_PublicKey(const AlgorithmIdentifier& alg_id,
- const MemoryRegion<byte>& key_bits) :
+ const secure_vector<byte>& key_bits) :
DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
{
}
@@ -48,7 +49,7 @@ NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng,
}
NR_PrivateKey::NR_PrivateKey(const AlgorithmIdentifier& alg_id,
- const MemoryRegion<byte>& key_bits,
+ const secure_vector<byte>& key_bits,
RandomNumberGenerator& rng) :
DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
{
@@ -79,7 +80,7 @@ NR_Signature_Operation::NR_Signature_Operation(const NR_PrivateKey& nr) :
{
}
-SecureVector<byte>
+secure_vector<byte>
NR_Signature_Operation::sign(const byte msg[], size_t msg_len,
RandomNumberGenerator& rng)
{
@@ -103,7 +104,7 @@ NR_Signature_Operation::sign(const byte msg[], size_t msg_len,
d = mod_q.reduce(k - x * c);
}
- SecureVector<byte> output(2*q.bytes());
+ secure_vector<byte> output(2*q.bytes());
c.binary_encode(&output[output.size() / 2 - c.bytes()]);
d.binary_encode(&output[output.size() - d.bytes()]);
return output;
@@ -118,13 +119,13 @@ NR_Verification_Operation::NR_Verification_Operation(const NR_PublicKey& nr) :
mod_q = Modular_Reducer(nr.group_q());
}
-SecureVector<byte>
+secure_vector<byte>
NR_Verification_Operation::verify_mr(const byte msg[], size_t msg_len)
{
const BigInt& q = mod_q.get_modulus();
if(msg_len != 2*q.bytes())
- return false;
+ throw Invalid_Argument("NR verification: Invalid signature");
BigInt c(msg, q.bytes());
BigInt d(msg + q.bytes(), q.bytes());
@@ -132,8 +133,11 @@ NR_Verification_Operation::verify_mr(const byte msg[], size_t msg_len)
if(c.is_zero() || c >= q || d >= q)
throw Invalid_Argument("NR verification: Invalid signature");
- BigInt i = mod_p.multiply(powermod_g_p(d), powermod_y_p(c));
- return BigInt::encode(mod_q.reduce(c - i));
+ auto future_y_c = std::async(std::launch::async, powermod_y_p, c);
+ BigInt g_d = powermod_g_p(d);
+
+ BigInt i = mod_p.multiply(g_d, future_y_c.get());
+ return BigInt::encode_locked(mod_q.reduce(c - i));
}
}