aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-12 14:24:21 +0000
committerlloyd <[email protected]>2010-03-12 14:24:21 +0000
commit6a8c00e903ea63828319460133a651c410b86185 (patch)
treee74eada5d4a1a23b3568c8e77496653729020c4e /src/pubkey
parent47ad59e19b11b1f7ea4d15d86408d3ca675cd369 (diff)
parentc8e8fdab5f0253f5143ab9eb1a250ad69ffc4420 (diff)
propagate from branch 'net.randombit.botan' (head 0b404c8dc611e8cf8fec60cdcaffa823b925d09a)
to branch 'net.randombit.botan.c++0x' (head 60585d4c6a816c4d6a0ce269b63c1e28ec04e0de)
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/blinding.cpp6
-rw-r--r--src/pubkey/dl_group/dl_group.cpp8
-rw-r--r--src/pubkey/dsa/dsa.cpp21
-rw-r--r--src/pubkey/nr/nr.cpp6
-rw-r--r--src/pubkey/pkcs8.cpp4
-rw-r--r--src/pubkey/pubkey.cpp4
-rw-r--r--src/pubkey/rsa/rsa.cpp6
-rw-r--r--src/pubkey/rw/rw.cpp2
8 files changed, 37 insertions, 20 deletions
diff --git a/src/pubkey/blinding.cpp b/src/pubkey/blinding.cpp
index 819d0dd20..8da50249f 100644
--- a/src/pubkey/blinding.cpp
+++ b/src/pubkey/blinding.cpp
@@ -32,7 +32,7 @@ BigInt Blinder::choose_nonce(const BigInt& x, const BigInt& mod)
{
Algorithm_Factory& af = global_state().algorithm_factory();
- std::auto_ptr<HashFunction> hash(af.make_hash_function("SHA-512"));
+ std::unique_ptr<HashFunction> hash(af.make_hash_function("SHA-512"));
u64bit ns_clock = get_nanoseconds_clock();
for(size_t i = 0; i != sizeof(ns_clock); ++i)
@@ -41,7 +41,9 @@ BigInt Blinder::choose_nonce(const BigInt& x, const BigInt& mod)
hash->update(BigInt::encode(x));
hash->update(BigInt::encode(mod));
- u64bit timestamp = system_time();
+ auto timestamp = std::chrono::system_clock::to_time_t(
+ std::chrono::system_clock::now());
+
for(size_t i = 0; i != sizeof(timestamp); ++i)
hash->update(get_byte(i, timestamp));
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp
index 7940e69b2..55a83794c 100644
--- a/src/pubkey/dl_group/dl_group.cpp
+++ b/src/pubkey/dl_group/dl_group.cpp
@@ -46,7 +46,7 @@ DL_Group::DL_Group(RandomNumberGenerator& rng,
PrimeType type, u32bit pbits, u32bit qbits)
{
if(pbits < 512)
- throw Invalid_Argument("DL_Group: prime size " + to_string(pbits) +
+ throw Invalid_Argument("DL_Group: prime size " + std::to_string(pbits) +
" is too small");
if(type == Strong)
@@ -237,7 +237,7 @@ SecureVector<byte> DL_Group::DER_encode(Format format) const
.get_contents();
}
- throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
}
/*
@@ -253,7 +253,7 @@ std::string DL_Group::PEM_encode(Format format) const
else if(format == ANSI_X9_42)
return PEM_Code::encode(encoding, "X942 DH PARAMETERS");
else
- throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
}
/*
@@ -287,7 +287,7 @@ void DL_Group::BER_decode(DataSource& source, Format format)
.discard_remaining();
}
else
- throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
initialize(new_p, new_q, new_g);
}
diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp
index d1f721084..ca396204a 100644
--- a/src/pubkey/dsa/dsa.cpp
+++ b/src/pubkey/dsa/dsa.cpp
@@ -8,8 +8,7 @@
#include <botan/dsa.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
-
-#include <stdio.h>
+#include <future>
namespace Botan {
@@ -102,8 +101,12 @@ DSA_Signature_Operation::sign(const byte msg[], u32bit msg_len,
k.randomize(rng, q.bits());
while(k >= q);
- r = mod_q.reduce(powermod_g_p(k));
- s = mod_q.multiply(inverse_mod(k, q), mul_add(x, r, i));
+ auto future_r = std::async(std::launch::async,
+ [&]() { return mod_q.reduce(powermod_g_p(k)); });
+
+ s = inverse_mod(k, q);
+ r = future_r.get();
+ s = mod_q.multiply(s, mul_add(x, r, i));
}
SecureVector<byte> output(2*q.bytes());
@@ -137,8 +140,14 @@ bool DSA_Verification_Operation::verify(const byte msg[], u32bit msg_len,
return false;
s = inverse_mod(s, q);
- s = mod_p.multiply(powermod_g_p(mod_q.multiply(s, i)),
- powermod_y_p(mod_q.multiply(s, r)));
+
+ auto future_s_i = std::async(std::launch::async,
+ [&]() { return powermod_g_p(mod_q.multiply(s, i)); });
+
+ BigInt s_r = powermod_y_p(mod_q.multiply(s, r));
+ BigInt s_i = future_s_i.get();
+
+ s = mod_p.multiply(s_i, s_r);
return (mod_q.reduce(s) == r);
}
diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp
index f9ba37c41..50cf080fb 100644
--- a/src/pubkey/nr/nr.cpp
+++ b/src/pubkey/nr/nr.cpp
@@ -8,6 +8,7 @@
#include <botan/nr.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
+#include <future>
namespace Botan {
@@ -146,7 +147,10 @@ NR_Verification_Operation::verify_mr(const byte msg[], u32bit 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));
+ 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(mod_q.reduce(c - i));
}
diff --git a/src/pubkey/pkcs8.cpp b/src/pubkey/pkcs8.cpp
index 400fdbb48..d3a62aa01 100644
--- a/src/pubkey/pkcs8.cpp
+++ b/src/pubkey/pkcs8.cpp
@@ -89,7 +89,7 @@ SecureVector<byte> PKCS8_decode(DataSource& source, const User_Interface& ui,
if(is_encrypted)
{
DataSource_Memory params(pbe_alg_id.parameters);
- std::auto_ptr<PBE> pbe(get_pbe(pbe_alg_id.oid, params));
+ std::unique_ptr<PBE> pbe(get_pbe(pbe_alg_id.oid, params));
User_Interface::UI_Result result = User_Interface::OK;
const std::string passphrase =
@@ -171,7 +171,7 @@ void encrypt_key(const Private_Key& key,
encode(key, raw_key, RAW_BER);
raw_key.end_msg();
- std::auto_ptr<PBE> pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE)));
+ std::unique_ptr<PBE> pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE)));
pbe->new_params(rng);
pbe->set_key(pass);
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index 4a9f1be9d..751f20583 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -226,7 +226,7 @@ SecureVector<byte> PK_Signer::signature(RandomNumberGenerator& rng)
}
else
throw Encoding_Error("PK_Signer: Unknown signature format " +
- to_string(sig_format));
+ std::to_string(sig_format));
}
/*
@@ -313,7 +313,7 @@ bool PK_Verifier::check_signature(const byte sig[], u32bit length)
}
else
throw Decoding_Error("PK_Verifier: Unknown signature format " +
- to_string(sig_format));
+ std::to_string(sig_format));
}
catch(Invalid_Argument) { return false; }
}
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index 19ca27f40..51c9fd19c 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -9,6 +9,7 @@
#include <botan/parsing.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
+#include <future>
namespace Botan {
@@ -20,7 +21,7 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng,
{
if(bits < 512)
throw Invalid_Argument(algo_name() + ": Can't make a key that is only " +
- to_string(bits) + " bits long");
+ std::to_string(bits) + " bits long");
if(exp < 3 || exp % 2 == 0)
throw Invalid_Argument(algo_name() + ": Invalid encryption exponent");
@@ -89,8 +90,9 @@ BigInt RSA_Private_Operation::private_op(const BigInt& m) const
if(m >= n)
throw Invalid_Argument("RSA private op - input is too large");
- BigInt j1 = powermod_d1_p(m);
+ auto future_j1 = std::async(std::launch::async, powermod_d1_p, m);
BigInt j2 = powermod_d2_q(m);
+ BigInt j1 = future_j1.get();
j1 = mod_p.reduce(sub_mul(j1, j2, c));
diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp
index 508244112..9600ae709 100644
--- a/src/pubkey/rw/rw.cpp
+++ b/src/pubkey/rw/rw.cpp
@@ -21,7 +21,7 @@ RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng,
{
if(bits < 512)
throw Invalid_Argument(algo_name() + ": Can't make a key that is only " +
- to_string(bits) + " bits long");
+ std::to_string(bits) + " bits long");
if(exp < 2 || exp % 2 == 1)
throw Invalid_Argument(algo_name() + ": Invalid encryption exponent");