aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-07-27 15:51:58 -0400
committerJack Lloyd <[email protected]>2016-07-27 15:51:58 -0400
commitd5e068a6827f3499bca62b2c0ec9fd8132ee15ca (patch)
tree5520fb64a66e4e32112ee377c2ad1aad8199ccbf /src/lib
parent5d50db6e964a9305d7271301804a1dcb4ce22606 (diff)
parent6566b41e7f1a65f52589016540cb9ad505724954 (diff)
Merge GH #553 EME/pubkey test improvements. Small EME refactor.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pk_pad/eme_oaep/oaep.cpp4
-rw-r--r--src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp20
2 files changed, 13 insertions, 11 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;
}