aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/pk_pad/eme_oaep/oaep.cpp4
-rw-r--r--src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp20
-rw-r--r--src/lib/utils/simd/simd_32.h2
-rw-r--r--src/tests/test_bigint.cpp9
-rw-r--r--src/tests/test_block.cpp6
-rw-r--r--src/tests/test_pubkey.cpp25
6 files changed, 48 insertions, 18 deletions
diff --git a/src/lib/pk_pad/eme_oaep/oaep.cpp b/src/lib/pk_pad/eme_oaep/oaep.cpp
index 0ae0d8554..1ae1068a7 100644
--- a/src/lib/pk_pad/eme_oaep/oaep.cpp
+++ b/src/lib/pk_pad/eme_oaep/oaep.cpp
@@ -35,8 +35,10 @@ secure_vector<byte> OAEP::pad(const byte in[], size_t in_length,
{
key_length /= 8;
- if(key_length < in_length + 2*m_Phash.size() + 1)
+ if(in_length > maximum_input_size(key_length * 8))
+ {
throw Invalid_Argument("OAEP: Input is too large");
+ }
secure_vector<byte> out(key_length);
diff --git a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
index 8148b7bc9..9bab8eb95 100644
--- a/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
+++ b/src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp
@@ -14,22 +14,22 @@ namespace Botan {
* PKCS1 Pad Operation
*/
secure_vector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen,
- size_t olen,
+ size_t key_length,
RandomNumberGenerator& rng) const
{
- olen /= 8;
+ key_length /= 8;
- if(olen < 10)
- throw Encoding_Error("PKCS1: Output space too small");
- if(inlen > olen - 10)
- throw Encoding_Error("PKCS1: Input is too large");
+ if(inlen > maximum_input_size(key_length * 8))
+ {
+ throw Invalid_Argument("PKCS1: Input is too large");
+ }
- secure_vector<byte> out(olen);
+ secure_vector<byte> out(key_length);
out[0] = 0x02;
- rng.randomize(out.data() + 1, (olen - inlen - 2));
+ rng.randomize(out.data() + 1, (key_length - inlen - 2));
- for(size_t j = 1; j != olen - inlen - 1; ++j)
+ for(size_t j = 1; j != key_length - inlen - 1; ++j)
{
if(out[j] == 0)
{
@@ -37,7 +37,7 @@ secure_vector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen,
}
}
- buffer_insert(out, olen - inlen, in, inlen);
+ buffer_insert(out, key_length - inlen, in, inlen);
return out;
}
diff --git a/src/lib/utils/simd/simd_32.h b/src/lib/utils/simd/simd_32.h
index 351146f22..0b4ca8f03 100644
--- a/src/lib/utils/simd/simd_32.h
+++ b/src/lib/utils/simd/simd_32.h
@@ -12,7 +12,7 @@
#include <botan/loadstor.h>
#include <botan/bswap.h>
-#if defined(BOTAN_TARGET_SUPPORTS_SSE2) && 0
+#if defined(BOTAN_TARGET_SUPPORTS_SSE2)
#include <emmintrin.h>
#define BOTAN_SIMD_USE_SSE2
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index a7e00498f..6f3d603db 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -303,6 +303,15 @@ class BigInt_Mod_Test : public Text_Based_Test
e %= b;
result.test_eq("a %= b", e, c);
+ // if b fits into a Botan::word test %= operator for words
+ if(b.bytes() <= sizeof(Botan::word))
+ {
+ Botan::word b_word = b.word_at( 0 );
+ e = a;
+ e %= b_word;
+ result.test_eq("a %= b (as word)", e, c);
+ }
+
return result;
}
};
diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp
index 75a460bc7..0863cb891 100644
--- a/src/tests/test_block.cpp
+++ b/src/tests/test_block.cpp
@@ -45,6 +45,12 @@ class Block_Cipher_Tests : public Text_Based_Test
result.test_gte(provider, cipher->block_size(), 8);
result.test_gte(provider, cipher->parallel_bytes(), cipher->block_size() * cipher->parallelism());
+ // Test to make sure clear() resets what we need it to
+ cipher->set_key(Test::rng().random_vec(cipher->key_spec().minimum_keylength()));
+ Botan::secure_vector<byte> garbage = Test::rng().random_vec(cipher->block_size());
+ cipher->encrypt(garbage);
+ cipher->clear();
+
cipher->set_key(key);
std::vector<uint8_t> buf = input;
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp
index cdd0c99b0..c7bd8f932 100644
--- a/src/tests/test_pubkey.cpp
+++ b/src/tests/test_pubkey.cpp
@@ -197,6 +197,19 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va
//std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(Botan::X509::BER_encode(*privkey)));
Botan::Public_Key* pubkey = privkey.get();
+ // test EME::maximum_input_size()
+ std::unique_ptr<Botan::EME> eme(Botan::get_eme(padding));
+
+ if(eme)
+ {
+ size_t max_input_size = eme->maximum_input_size(1);
+ result.test_eq("maximum input size( 1 ) should always return 0", max_input_size, 0);
+
+ size_t keybits = pubkey->max_input_bits();
+ max_input_size = eme->maximum_input_size(keybits);
+ result.test_gte("maximum input size( keybits ) > 0", max_input_size, 1);
+ }
+
for(auto&& enc_provider : possible_pk_providers())
{
std::unique_ptr<Botan::PK_Encryptor> encryptor;
@@ -370,7 +383,7 @@ PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_K
Botan::DataSource_Memory data_src(Botan::X509::PEM_encode(key));
std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src));
- result.test_eq("recovered public key from private", loaded.get(), true);
+ result.confirm("recovered public key from private", loaded.get() != nullptr);
result.test_eq("public key has same type", loaded->algo_name(), key.algo_name());
result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true);
}
@@ -384,7 +397,7 @@ PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_K
Botan::DataSource_Memory data_src(Botan::X509::BER_encode(key));
std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src));
- result.test_eq("recovered public key from private", loaded.get(), true);
+ result.confirm("recovered public key from private", loaded.get() != nullptr);
result.test_eq("public key has same type", loaded->algo_name(), key.algo_name());
result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true);
}
@@ -399,7 +412,7 @@ PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_K
std::unique_ptr<Botan::Private_Key> loaded(
Botan::PKCS8::load_key(data_src, Test::rng()));
- result.test_eq("recovered private key from PEM blob", loaded.get(), true);
+ result.confirm("recovered private key from PEM blob", loaded.get() != nullptr);
result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name());
result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true);
}
@@ -413,7 +426,7 @@ PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_K
Botan::DataSource_Memory data_src(Botan::PKCS8::BER_encode(key));
std::unique_ptr<Botan::Public_Key> loaded(Botan::PKCS8::load_key(data_src, Test::rng()));
- result.test_eq("recovered public key from private", loaded.get(), true);
+ result.confirm("recovered public key from private", loaded.get() != nullptr);
result.test_eq("public key has same type", loaded->algo_name(), key.algo_name());
result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true);
}
@@ -433,7 +446,7 @@ PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_K
std::unique_ptr<Botan::Private_Key> loaded(
Botan::PKCS8::load_key(data_src, Test::rng(), passphrase));
- result.test_eq("recovered private key from encrypted blob", loaded.get(), true);
+ result.confirm("recovered private key from encrypted blob", loaded.get() != nullptr);
result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name());
result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true);
}
@@ -451,7 +464,7 @@ PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_K
std::unique_ptr<Botan::Private_Key> loaded(
Botan::PKCS8::load_key(data_src, Test::rng(), passphrase));
- result.test_eq("recovered private key from BER blob", loaded.get(), true);
+ result.confirm("recovered private key from BER blob", loaded.get() != nullptr);
result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name());
result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true);
}