aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-13 19:31:27 +0000
committerlloyd <[email protected]>2010-03-13 19:31:27 +0000
commit634f3d27f7faad1dc558821382f71ecc2194637d (patch)
treedd4e626a4ac3ff5c928460b9e133007023d3321c /src
parent1fe724175fdad94d724d401c46b5187f5f539136 (diff)
parent72a154f3d7eef286b42a116232f8b7be88ccb6d6 (diff)
propagate from branch 'net.randombit.botan' (head aabb4c3bc2207ceac1920573293b95d138a185df)
to branch 'net.randombit.botan.c++0x' (head 179172dd6952f15f832855f4ec0ac48cb1e08188)
Diffstat (limited to 'src')
-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
8 files changed, 31 insertions, 14 deletions
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