diff options
author | Daniel Neus <[email protected]> | 2016-07-21 14:55:34 +0200 |
---|---|---|
committer | Daniel Neus <[email protected]> | 2016-07-25 14:08:10 +0200 |
commit | 6566b41e7f1a65f52589016540cb9ad505724954 (patch) | |
tree | 6252f97ebbb09374e793105925cb2354f8635585 /src/lib/pk_pad/eme_pkcs1 | |
parent | cbe70db412126518b705545d666159a496a9e63d (diff) |
eme / pubkey test improvements
- add test for EME::maximum_input_size()
- additionally use maximum_input_size() before pad() in OAEP and PKCS1 (remove code duplication)
- prevent C4800 MSVC warning
Diffstat (limited to 'src/lib/pk_pad/eme_pkcs1')
-rw-r--r-- | src/lib/pk_pad/eme_pkcs1/eme_pkcs.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
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; } |