diff options
author | Jack Lloyd <[email protected]> | 2019-06-05 08:57:07 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-06-05 08:57:07 -0400 |
commit | da0ab423a62180ef5ac027a97c994b98075b25e9 (patch) | |
tree | 748f2592aa7aada11a781bfa9318bb7af4c3f27a | |
parent | 55562154191077f5bdc71d0ca8714a0f97f2d753 (diff) | |
parent | 4a759ef0164942d3908841cb047f00892921b753 (diff) |
Merge GH #1979 Fix PKCS11 buffer output sizing
-rw-r--r-- | src/lib/prov/pkcs11/p11.h | 40 | ||||
-rw-r--r-- | src/tests/test_pkcs11_high_level.cpp | 3 |
2 files changed, 30 insertions, 13 deletions
diff --git a/src/lib/prov/pkcs11/p11.h b/src/lib/prov/pkcs11/p11.h index 043b1795a..46545b925 100644 --- a/src/lib/prov/pkcs11/p11.h +++ b/src/lib/prov/pkcs11/p11.h @@ -1817,11 +1817,16 @@ class BOTAN_PUBLIC_API(2,0) LowLevel } encrypted_data.resize(encrypted_size); - return C_Encrypt(session, + if (!C_Encrypt(session, const_cast<Byte*>(plaintext_data.data()), static_cast<Ulong>(plaintext_data.size()), encrypted_data.data(), - &encrypted_size, return_value); + &encrypted_size, return_value)) + { + return false; + } + encrypted_data.resize(encrypted_size); + return true; } /** @@ -1950,11 +1955,16 @@ class BOTAN_PUBLIC_API(2,0) LowLevel } decrypted_data.resize(decrypted_size); - return C_Decrypt(session, - const_cast<Byte*>(encrypted_data.data()), - static_cast<Ulong>(encrypted_data.size()), - decrypted_data.data(), - &decrypted_size, return_value); + if(!C_Decrypt(session, + const_cast<Byte*>(encrypted_data.data()), + static_cast<Ulong>(encrypted_data.size()), + decrypted_data.data(), + &decrypted_size, return_value)) + { + return false; + } + decrypted_data.resize(decrypted_size); + return true; } /** @@ -2189,12 +2199,17 @@ class BOTAN_PUBLIC_API(2,0) LowLevel } signature.resize(signature_size); - return C_Sign(session, + if (!C_Sign(session, const_cast<Byte*>(data.data()), static_cast<Ulong>(data.size()), signature.data(), &signature_size, - return_value); + return_value)) + { + return false; + } + signature.resize(signature_size); + return true; } /** @@ -2290,7 +2305,12 @@ class BOTAN_PUBLIC_API(2,0) LowLevel } signature.resize(signature_size); - return C_SignFinal(session, signature.data(), &signature_size, return_value); + if (!C_SignFinal(session, signature.data(), &signature_size, return_value)) + { + return false; + } + signature.resize(signature_size); + return true; } /** diff --git a/src/tests/test_pkcs11_high_level.cpp b/src/tests/test_pkcs11_high_level.cpp index c9c34a28b..077e0240f 100644 --- a/src/tests/test_pkcs11_high_level.cpp +++ b/src/tests/test_pkcs11_high_level.cpp @@ -831,9 +831,6 @@ Test::Result test_rsa_encrypt_decrypt() Botan::PK_Decryptor_EME decryptor(keypair.second, Test::rng(), padding); auto decrypted = decryptor.decrypt(encrypted); - // some token / middlewares do not remove the padding bytes - decrypted.resize(plaintext.size()); - result.test_eq("RSA PKCS11 encrypt and decrypt: " + padding, decrypted, plaintext); }; |