fix for OpenSSL 1.0

This commit is contained in:
Günter Obiltschnig 2018-03-06 22:58:14 +01:00
parent 943595c937
commit e7d2b4593a
3 changed files with 26 additions and 26 deletions

View File

@ -45,12 +45,12 @@ public:
/// Returns the block size for this CryptoTransform. /// Returns the block size for this CryptoTransform.
virtual int setPadding(int padding); virtual int setPadding(int padding);
/// Enables or disables padding. By default encryption operations are padded using standard block /// Enables or disables padding. By default encryption operations are padded using standard block
/// padding and the padding is checked and removed when decrypting. If the padding parameter is zero then /// padding and the padding is checked and removed when decrypting. If the padding parameter is zero then
/// no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of /// no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of
/// the block size or an error will occur. /// the block size or an error will occur.
virtual std::string getTag(std::size_t tagSize = 16) const = 0; virtual std::string getTag(std::size_t tagSize = 16) = 0;
/// Returns the GCM tag after encrypting using GCM mode. /// Returns the GCM tag after encrypting using GCM mode.
/// ///
/// Must be called after finalize(). /// Must be called after finalize().

View File

@ -29,7 +29,7 @@ namespace
{ {
unsigned long err; unsigned long err;
std::string msg; std::string msg;
while ((err = ERR_get_error())) while ((err = ERR_get_error()))
{ {
if (!msg.empty()) if (!msg.empty())
@ -59,10 +59,10 @@ namespace
Direction dir); Direction dir);
~CryptoTransformImpl(); ~CryptoTransformImpl();
std::size_t blockSize() const; std::size_t blockSize() const;
int setPadding(int padding); int setPadding(int padding);
std::string getTag(std::size_t tagSize) const; std::string getTag(std::size_t tagSize);
void setTag(const std::string& tag); void setTag(const std::string& tag);
std::streamsize transform( std::streamsize transform(
@ -70,7 +70,7 @@ namespace
std::streamsize inputLength, std::streamsize inputLength,
unsigned char* output, unsigned char* output,
std::streamsize outputLength); std::streamsize outputLength);
std::streamsize finalize( std::streamsize finalize(
unsigned char* output, unsigned char* output,
std::streamsize length); std::streamsize length);
@ -147,7 +147,7 @@ namespace
#endif #endif
} }
int CryptoTransformImpl::setPadding(int padding) int CryptoTransformImpl::setPadding(int padding)
{ {
#if OPENSSL_VERSION_NUMBER >= 0x10100000L #if OPENSSL_VERSION_NUMBER >= 0x10100000L
@ -156,9 +156,9 @@ namespace
return EVP_CIPHER_CTX_set_padding(&_context, padding); return EVP_CIPHER_CTX_set_padding(&_context, padding);
#endif #endif
} }
std::string CryptoTransformImpl::getTag(std::size_t tagSize) const
std::string CryptoTransformImpl::getTag(std::size_t tagSize)
{ {
std::string tag; std::string tag;
#if OPENSSL_VERSION_NUMBER >= 0x10000000L #if OPENSSL_VERSION_NUMBER >= 0x10000000L
@ -224,7 +224,7 @@ namespace
std::streamsize length) std::streamsize length)
{ {
poco_assert (length >= blockSize()); poco_assert (length >= blockSize());
int len = static_cast<int>(length); int len = static_cast<int>(length);
// Use the '_ex' version that does not perform implicit cleanup since we // Use the '_ex' version that does not perform implicit cleanup since we
@ -238,7 +238,7 @@ namespace
if (rc == 0) if (rc == 0)
throwError(); throwError();
return static_cast<std::streamsize>(len); return static_cast<std::streamsize>(len);
} }
} }

View File

@ -30,7 +30,7 @@ namespace
{ {
unsigned long err; unsigned long err;
std::string msg; std::string msg;
while ((err = ERR_get_error())) while ((err = ERR_get_error()))
{ {
if (!msg.empty()) if (!msg.empty())
@ -66,10 +66,10 @@ namespace
public: public:
RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode); RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
~RSAEncryptImpl(); ~RSAEncryptImpl();
std::size_t blockSize() const; std::size_t blockSize() const;
std::size_t maxDataSize() const; std::size_t maxDataSize() const;
std::string getTag(std::size_t) const; std::string getTag(std::size_t);
void setTag(const std::string&); void setTag(const std::string&);
std::streamsize transform( std::streamsize transform(
@ -77,7 +77,7 @@ namespace
std::streamsize inputLength, std::streamsize inputLength,
unsigned char* output, unsigned char* output,
std::streamsize outputLength); std::streamsize outputLength);
std::streamsize finalize(unsigned char* output, std::streamsize length); std::streamsize finalize(unsigned char* output, std::streamsize length);
private: private:
@ -129,7 +129,7 @@ namespace
} }
std::string RSAEncryptImpl::getTag(std::size_t) const std::string RSAEncryptImpl::getTag(std::size_t)
{ {
return std::string(); return std::string();
} }
@ -167,7 +167,7 @@ namespace
output += n; output += n;
outputLength -= n; outputLength -= n;
_pos = 0; _pos = 0;
} }
else else
{ {
@ -203,9 +203,9 @@ namespace
public: public:
RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode); RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
~RSADecryptImpl(); ~RSADecryptImpl();
std::size_t blockSize() const; std::size_t blockSize() const;
std::string getTag(std::size_t) const; std::string getTag(std::size_t);
void setTag(const std::string&); void setTag(const std::string&);
std::streamsize transform( std::streamsize transform(
@ -213,7 +213,7 @@ namespace
std::streamsize inputLength, std::streamsize inputLength,
unsigned char* output, unsigned char* output,
std::streamsize outputLength); std::streamsize outputLength);
std::streamsize finalize( std::streamsize finalize(
unsigned char* output, unsigned char* output,
std::streamsize length); std::streamsize length);
@ -248,7 +248,7 @@ namespace
} }
std::string RSADecryptImpl::getTag(std::size_t) const std::string RSADecryptImpl::getTag(std::size_t)
{ {
return std::string(); return std::string();
} }
@ -265,7 +265,7 @@ namespace
unsigned char* output, unsigned char* output,
std::streamsize outputLength) std::streamsize outputLength)
{ {
// always fill up the buffer before decrypting! // always fill up the buffer before decrypting!
std::streamsize rsaSize = static_cast<std::streamsize>(blockSize()); std::streamsize rsaSize = static_cast<std::streamsize>(blockSize());
poco_assert_dbg(_pos <= rsaSize); poco_assert_dbg(_pos <= rsaSize);
@ -285,7 +285,7 @@ namespace
output += tmp; output += tmp;
outputLength -= tmp; outputLength -= tmp;
_pos = 0; _pos = 0;
} }
else else
{ {