aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/filters/out_buf.cpp13
-rw-r--r--src/kdf/ssl_prf/prf_ssl3.cpp6
-rw-r--r--src/pubkey/dl_group/dl_group.cpp18
-rw-r--r--src/pubkey/ec_dompar/ec_dompar.cpp4
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp9
-rw-r--r--src/pubkey/ecdh/ecdh.cpp5
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp9
-rw-r--r--src/pubkey/pubkey.cpp8
-rw-r--r--src/pubkey/rsa/rsa.cpp5
9 files changed, 43 insertions, 34 deletions
diff --git a/src/filters/out_buf.cpp b/src/filters/out_buf.cpp
index e3ea0cfb5..f00cbb866 100644
--- a/src/filters/out_buf.cpp
+++ b/src/filters/out_buf.cpp
@@ -7,6 +7,7 @@
#include <botan/internal/out_buf.h>
#include <botan/secqueue.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -51,11 +52,10 @@ u32bit Output_Buffers::remaining(Pipe::message_id msg) const
*/
void Output_Buffers::add(SecureQueue* queue)
{
- if(!queue)
- throw Internal_Error("Output_Buffers::add: Argument was NULL");
+ BOTAN_ASSERT(queue, "argument was NULL");
- if(buffers.size() == buffers.max_size())
- throw Internal_Error("Output_Buffers::add: No more room in container");
+ BOTAN_ASSERT(buffers.size() < buffers.max_size(),
+ "No more room in container");
buffers.push_back(queue);
}
@@ -85,8 +85,9 @@ SecureQueue* Output_Buffers::get(Pipe::message_id msg) const
{
if(msg < offset)
return 0;
- if(msg > message_count())
- throw Internal_Error("Output_Buffers::get: msg > size");
+
+ BOTAN_ASSERT(msg < message_count(),
+ "Message number out of range");
return buffers[msg-offset];
}
diff --git a/src/kdf/ssl_prf/prf_ssl3.cpp b/src/kdf/ssl_prf/prf_ssl3.cpp
index 1d896a63c..952158378 100644
--- a/src/kdf/ssl_prf/prf_ssl3.cpp
+++ b/src/kdf/ssl_prf/prf_ssl3.cpp
@@ -10,6 +10,7 @@
#include <botan/exceptn.h>
#include <botan/sha160.h>
#include <botan/md5.h>
+#include <botan/internal/assert.h>
#include <memory>
namespace Botan {
@@ -24,8 +25,7 @@ OctetString next_hash(u32bit where, u32bit want,
const byte secret[], u32bit secret_len,
const byte seed[], u32bit seed_len)
{
- if(want > md5.OUTPUT_LENGTH)
- throw Internal_Error("SSL3_PRF:next_hash: want is too big");
+ BOTAN_ASSERT(want <= md5.OUTPUT_LENGTH, "Desired output too large");
const byte ASCII_A_CHAR = 0x41;
@@ -52,7 +52,7 @@ SecureVector<byte> SSL3_PRF::derive(u32bit key_len,
const byte seed[], u32bit seed_len) const
{
if(key_len > 416)
- throw Internal_Error("SSL3_PRF: Requested key length is too large");
+ throw Invalid_Argument("SSL3_PRF: Requested key length is too large");
MD5 md5;
SHA_160 sha1;
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp
index d4e306ac3..d714bc154 100644
--- a/src/pubkey/dl_group/dl_group.cpp
+++ b/src/pubkey/dl_group/dl_group.cpp
@@ -14,6 +14,7 @@
#include <botan/pipe.h>
#include <botan/pem.h>
#include <botan/internal/workfactor.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -312,23 +313,22 @@ void DL_Group::PEM_decode(DataSource& source)
}
/*
-* Create a random DSA-style generator
+* Create generator of the q-sized subgroup (DSA style generator)
*/
BigInt DL_Group::make_dsa_generator(const BigInt& p, const BigInt& q)
{
BigInt g, e = (p - 1) / q;
- for(u32bit j = 0; j != PRIME_TABLE_SIZE; ++j)
+ BOTAN_ASSERT(e > 0, "q does not divide p, invalid group");
+
+ for(u32bit i = 0; i != PRIME_TABLE_SIZE; ++i)
{
- g = power_mod(PRIMES[j], e, p);
- if(g != 1)
- break;
+ g = power_mod(PRIMES[i], e, p);
+ if(g > 1)
+ return g;
}
- if(g == 1)
- throw Internal_Error("DL_Group: Couldn't create a suitable generator");
-
- return g;
+ throw Internal_Error("DL_Group: Couldn't create a suitable generator");
}
}
diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp
index 512d8d769..c1b969103 100644
--- a/src/pubkey/ec_dompar/ec_dompar.cpp
+++ b/src/pubkey/ec_dompar/ec_dompar.cpp
@@ -124,8 +124,8 @@ EC_Domain_Params::DER_encode(EC_Domain_Params_Encoding form) const
return DER_Encoder().encode(get_oid()).get_contents();
else if(form == EC_DOMPAR_ENC_IMPLICITCA)
return DER_Encoder().encode_null().get_contents();
-
- throw Internal_Error("EC_Domain_Params::encode_DER: Unknown encoding");
+ else
+ throw Internal_Error("EC_Domain_Params::DER_encode: Unknown encoding");
}
std::string EC_Domain_Params::PEM_encode() const
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index 4f90fa321..bf221aad0 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -14,6 +14,7 @@
#include <botan/ber_dec.h>
#include <botan/secmem.h>
#include <botan/point_gfp.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -99,8 +100,8 @@ EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng,
private_key = BigInt::random_integer(rng, 1, domain().get_order());
public_key = domain().get_base_point() * private_key;
- if(!public_key.on_the_curve())
- throw Internal_Error("ECC private key generation failed");
+ BOTAN_ASSERT(public_key.on_the_curve(),
+ "generated ECC private key was not on the curve");
}
MemoryVector<byte> EC_PrivateKey::pkcs8_private_key() const
@@ -129,8 +130,8 @@ EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
public_key = domain().get_base_point() * private_key;
- if(!public_key.on_the_curve())
- throw Internal_Error("Loaded ECC private key failed self test");
+ BOTAN_ASSERT(public_key.on_the_curve(),
+ "Loaded ECC private key not on the curve");
}
}
diff --git a/src/pubkey/ecdh/ecdh.cpp b/src/pubkey/ecdh/ecdh.cpp
index 8d13e7f65..2c78b65a6 100644
--- a/src/pubkey/ecdh/ecdh.cpp
+++ b/src/pubkey/ecdh/ecdh.cpp
@@ -8,6 +8,7 @@
*/
#include <botan/ecdh.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -25,8 +26,8 @@ SecureVector<byte> ECDH_KA_Operation::agree(const byte w[], u32bit w_len)
PointGFp S = (cofactor * point) * l_times_priv;
- if(!S.on_the_curve())
- throw Internal_Error("ECDH: Agreed value was not on the curve");
+ BOTAN_ASSERT(S.on_the_curve(),
+ "ECDH agreed value not on the curve");
return BigInt::encode_1363(S.get_affine_x(),
curve.get_p().bytes());
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index 1cff9e081..50878634b 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -10,6 +10,7 @@
#include <botan/gost_3410.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -74,8 +75,8 @@ GOST_3410_PublicKey::GOST_3410_PublicKey(const AlgorithmIdentifier& alg_id,
public_key = PointGFp(domain().get_curve(), x, y);
- if(!public_key.on_the_curve())
- throw Internal_Error("Loaded GOST 34.10 public key failed self test");
+ BOTAN_ASSERT(public_key.on_the_curve(),
+ "Loaded GOST 34.10 public key not on the curve");
}
namespace {
@@ -118,8 +119,8 @@ GOST_3410_Signature_Operation::sign(const byte msg[], u32bit msg_len,
PointGFp k_times_P = base_point * k;
- if(!k_times_P.on_the_curve())
- throw Internal_Error("GOST 34.10 k*g not on the curve");
+ BOTAN_ASSERT(k_times_P.on_the_curve(),
+ "GOST 34.10 k*g not on the curve");
BigInt r = k_times_P.get_affine_x() % order;
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index 725cdacf7..3b7d81fb2 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -14,6 +14,7 @@
#include <botan/engine.h>
#include <botan/lookup.h>
#include <botan/internal/bit_ops.h>
+#include <botan/internal/assert.h>
#include <memory>
namespace Botan {
@@ -169,6 +170,9 @@ void PK_Signer::update(const byte in[], u32bit length)
bool PK_Signer::self_test_signature(const MemoryRegion<byte>& msg,
const MemoryRegion<byte>& sig) const
{
+ if(!verify_op)
+ return true; // checking disabled, assume ok
+
if(verify_op->with_recovery())
{
SecureVector<byte> recovered =
@@ -203,8 +207,8 @@ SecureVector<byte> PK_Signer::signature(RandomNumberGenerator& rng)
SecureVector<byte> plain_sig = op->sign(&encoded[0], encoded.size(), rng);
- if(verify_op && !self_test_signature(encoded, plain_sig))
- throw Internal_Error("PK_Signer consistency check failed");
+ BOTAN_ASSERT(self_test_signature(encoded, plain_sig),
+ "PK_Signer consistency check failed");
if(op->message_parts() == 1 || sig_format == IEEE_1363)
return plain_sig;
diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp
index 84048fa2e..54c8fed0b 100644
--- a/src/pubkey/rsa/rsa.cpp
+++ b/src/pubkey/rsa/rsa.cpp
@@ -10,6 +10,7 @@
#include <botan/parsing.h>
#include <botan/numthry.h>
#include <botan/keypair.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -108,8 +109,8 @@ RSA_Private_Operation::decrypt(const byte msg[], u32bit msg_len)
BigInt m(msg, msg_len);
BigInt x = blinder.unblind(private_op(blinder.blind(m)));
- if(m != powermod_e_n(x))
- throw Internal_Error("RSA private op failed consistency check");
+ BOTAN_ASSERT(m == powermod_e_n(x),
+ "RSA private op failed consistency check");
return BigInt::encode(x);
}