aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--checks/pk_bench.cpp53
-rw-r--r--doc/log.txt1
-rw-r--r--src/engine/def_engine/def_pk_ops.cpp6
-rw-r--r--src/libstate/libstate.cpp3
-rw-r--r--src/pubkey/ecdsa/ecdsa.cpp12
-rw-r--r--src/pubkey/ecdsa/ecdsa.h2
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp4
-rw-r--r--src/pubkey/gost_3410/gost_3410.h4
-rw-r--r--src/utils/mlock.cpp9
-rw-r--r--src/utils/mlock.h5
10 files changed, 49 insertions, 50 deletions
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp
index 6893917fd..513a84f76 100644
--- a/checks/pk_bench.cpp
+++ b/checks/pk_bench.cpp
@@ -7,6 +7,7 @@
#include <botan/pkcs8.h>
#include <botan/mem_ops.h>
#include <botan/parsing.h>
+#include <botan/oids.h>
#include <map>
#if defined(BOTAN_HAS_RSA)
@@ -66,6 +67,16 @@ using namespace Botan;
namespace {
+const char* ec_domains[] = {
+ "secp160r2",
+ "secp192r1",
+ "secp224r1",
+ "secp256r1",
+ "secp384r1",
+ "secp521r1",
+ 0
+};
+
class Benchmark_Report
{
public:
@@ -293,20 +304,9 @@ void benchmark_ecdsa(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
- const char* domains[] = { "1.3.132.0.6", // secp112r1
- "1.3.132.0.28", // secp128r1
- "1.3.132.0.30", // secp160r2
- "1.2.840.10045.3.1.1", // secp192r1
- "1.3.132.0.33", // secp224r1
- "1.2.840.10045.3.1.7", // secp256r1
- "1.3.132.0.34", // secp384r1
- "1.3.132.0.35", // secp512r1
- NULL };
-
- for(size_t j = 0; domains[j]; j++)
+ for(size_t j = 0; ec_domains[j]; j++)
{
- OID oid(domains[j]);
- EC_Domain_Params params(oid);
+ EC_Domain_Params params(OIDS::lookup(ec_domains[j]));
u32bit pbits = params.get_curve().get_p().bits();
@@ -353,19 +353,9 @@ void benchmark_gost_3410(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
- const char* domains[] = { "1.3.132.0.6", // secp112r1
- "1.3.132.0.28", // secp128r1
- "1.3.132.0.30", // secp160r2
- "1.3.132.0.33", // secp224r1
- "1.2.643.2.2.35.1", // gost 256p
- "1.3.132.0.34", // secp384r1
- "1.3.132.0.35", // secp512r1
- NULL };
-
- for(size_t j = 0; domains[j]; j++)
+ for(size_t j = 0; ec_domains[j]; j++)
{
- OID oid(domains[j]);
- EC_Domain_Params params(oid);
+ EC_Domain_Params params(OIDS::lookup(ec_domains[j]));
u32bit pbits = params.get_curve().get_p().bits();
@@ -412,18 +402,9 @@ void benchmark_ecdh(RandomNumberGenerator& rng,
double seconds,
Benchmark_Report& report)
{
- const char* domains[] = { "1.3.132.0.6", // secp112r1
- "1.3.132.0.28", // secp128r1
- "1.3.132.0.30", // secp160r2
- "1.3.132.0.33", // secp224r1
- "1.3.132.0.34", // secp384r1
- "1.3.132.0.35", // secp512r1
- NULL };
-
- for(size_t j = 0; domains[j]; j++)
+ for(size_t j = 0; ec_domains[j]; j++)
{
- OID oid(domains[j]);
- EC_Domain_Params params(oid);
+ EC_Domain_Params params(OIDS::lookup(ec_domains[j]));
u32bit pbits = params.get_curve().get_p().bits();
diff --git a/doc/log.txt b/doc/log.txt
index 3a37e3a5e..be13cd880 100644
--- a/doc/log.txt
+++ b/doc/log.txt
@@ -2,6 +2,7 @@
* 1.9.5-dev, ????-??-??
- Numerous ECC optimizations
- Allow PK_Signer's fault protection checks to be toggled off
+ - Avoid using pool-based locking allocator if we can't mlock
- Remove all runtime options
- Fix crash in MemoryRegion if Allocator::get failed
- Fix small compilation problem on FreeBSD
diff --git a/src/engine/def_engine/def_pk_ops.cpp b/src/engine/def_engine/def_pk_ops.cpp
index d3264e67e..878d7d35c 100644
--- a/src/engine/def_engine/def_pk_ops.cpp
+++ b/src/engine/def_engine/def_pk_ops.cpp
@@ -27,7 +27,7 @@
#include <botan/elgamal.h>
#endif
-#if defined(BOTAN_HAS_GOST_3410_2001)
+#if defined(BOTAN_HAS_GOST_34_10_2001)
#include <botan/gost_3410.h>
#endif
@@ -116,7 +116,7 @@ Default_Engine::get_signature_op(const Private_Key& key) const
return new ECDSA_Signature_Operation(*s);
#endif
-#if defined(BOTAN_HAS_GOST_3410_2001)
+#if defined(BOTAN_HAS_GOST_34_10_2001)
if(const GOST_3410_PrivateKey* s =
dynamic_cast<const GOST_3410_PrivateKey*>(&key))
return new GOST_3410_Signature_Operation(*s);
@@ -153,7 +153,7 @@ Default_Engine::get_verify_op(const Public_Key& key) const
return new ECDSA_Verification_Operation(*s);
#endif
-#if defined(BOTAN_HAS_GOST_3410_2001)
+#if defined(BOTAN_HAS_GOST_34_10_2001)
if(const GOST_3410_PublicKey* s =
dynamic_cast<const GOST_3410_PublicKey*>(&key))
return new GOST_3410_Verification_Operation(*s);
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index c2e0ae80d..8e18703e6 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -10,6 +10,7 @@
#include <botan/internal/defalloc.h>
#include <botan/internal/default_engine.h>
#include <botan/internal/stl_util.h>
+#include <botan/internal/mlock.h>
#include <algorithm>
#if defined(BOTAN_HAS_SELFTESTS)
@@ -211,7 +212,7 @@ void Library_State::initialize()
throw Invalid_State("Library_State has already been initialized");
cached_default_allocator = 0;
- default_allocator_name = "locking";
+ default_allocator_name = has_mlock() ? "locking" : "malloc";
add_allocator(new Malloc_Allocator);
add_allocator(new Locking_Allocator);
diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp
index afca6cc73..40ae7c3b9 100644
--- a/src/pubkey/ecdsa/ecdsa.cpp
+++ b/src/pubkey/ecdsa/ecdsa.cpp
@@ -14,7 +14,8 @@ namespace Botan {
ECDSA_Signature_Operation::ECDSA_Signature_Operation(const ECDSA_PrivateKey& ecdsa) :
base_point(ecdsa.domain().get_base_point()),
order(ecdsa.domain().get_order()),
- x(ecdsa.private_value())
+ x(ecdsa.private_value()),
+ mod_order(order)
{
}
@@ -30,17 +31,15 @@ ECDSA_Signature_Operation::sign(const byte msg[], u32bit msg_len,
while(k >= order)
k.randomize(rng, order.bits() - 1);
- BigInt e(msg, msg_len);
+ BigInt m(msg, msg_len);
PointGFp k_times_P = base_point * k;
- BigInt r = k_times_P.get_affine_x() % order;
+ BigInt r = mod_order.reduce(k_times_P.get_affine_x());
if(r == 0)
throw Internal_Error("ECDSA_Signature_Operation: r was zero");
- BigInt k_inv = inverse_mod(k, order);
-
- BigInt s = (((r * x) + e) * k_inv) % order;
+ BigInt s = mod_order.multiply(inverse_mod(k, order), mul_add(x, r, m));
SecureVector<byte> output(2*order.bytes());
r.binary_encode(output + (output.size() / 2 - r.bytes()));
@@ -72,6 +71,7 @@ bool ECDSA_Verification_Operation::verify(const byte msg[], u32bit msg_len,
BigInt w = inverse_mod(s, order);
PointGFp R = w * (e * base_point + r * public_point);
+
if(R.is_zero())
return false;
diff --git a/src/pubkey/ecdsa/ecdsa.h b/src/pubkey/ecdsa/ecdsa.h
index e20a234fc..cb4893002 100644
--- a/src/pubkey/ecdsa/ecdsa.h
+++ b/src/pubkey/ecdsa/ecdsa.h
@@ -11,6 +11,7 @@
#define BOTAN_ECDSA_KEY_H__
#include <botan/ecc_key.h>
+#include <botan/reducer.h>
#include <botan/pk_ops.h>
namespace Botan {
@@ -102,6 +103,7 @@ class BOTAN_DLL ECDSA_Signature_Operation : public PK_Ops::Signature
const PointGFp& base_point;
const BigInt& order;
const BigInt& x;
+ Modular_Reducer mod_order;
};
class BOTAN_DLL ECDSA_Verification_Operation : public PK_Ops::Verification
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index c5cc1ddbd..0ba55cdd9 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -79,7 +79,7 @@ GOST_3410_Signature_Operation::GOST_3410_Signature_Operation(
SecureVector<byte>
GOST_3410_Signature_Operation::sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng) const
+ RandomNumberGenerator& rng)
{
BigInt k;
do
@@ -117,7 +117,7 @@ GOST_3410_Verification_Operation::GOST_3410_Verification_Operation(const GOST_34
}
bool GOST_3410_Verification_Operation::verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len) const
+ const byte sig[], u32bit sig_len)
{
if(sig_len != order.bytes()*2)
return false;
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index ffdbc6e19..36fa2912d 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -106,7 +106,7 @@ class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature
u32bit max_input_bits() const { return order.bits(); }
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
- RandomNumberGenerator& rng) const;
+ RandomNumberGenerator& rng);
private:
const PointGFp& base_point;
@@ -126,7 +126,7 @@ class BOTAN_DLL GOST_3410_Verification_Operation : public PK_Ops::Verification
bool with_recovery() const { return false; }
bool verify(const byte msg[], u32bit msg_len,
- const byte sig[], u32bit sig_len) const;
+ const byte sig[], u32bit sig_len);
private:
const PointGFp& base_point;
const PointGFp& public_point;
diff --git a/src/utils/mlock.cpp b/src/utils/mlock.cpp
index 5d6fc3591..bc6ddc67e 100644
--- a/src/utils/mlock.cpp
+++ b/src/utils/mlock.cpp
@@ -16,6 +16,15 @@
namespace Botan {
+bool has_mlock()
+ {
+ byte buf[4096];
+ if(!lock_mem(&buf, sizeof(buf)))
+ return false;
+ unlock_mem(&buf, sizeof(buf));
+ return true;
+ }
+
/*
* Lock an area of memory into RAM
*/
diff --git a/src/utils/mlock.h b/src/utils/mlock.h
index 66ced9e63..fea56d438 100644
--- a/src/utils/mlock.h
+++ b/src/utils/mlock.h
@@ -13,6 +13,11 @@
namespace Botan {
/**
+* Check if we can at least potentially lock memory
+*/
+bool has_mlock();
+
+/**
* Lock memory into RAM if possible
* @param addr the start of the memory block
* @param length the length of the memory block in bytes