From d48b1d1ab9ce1f150e0c7807dcd59ae5772f5bcf Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Wed, 16 Aug 2023 08:45:45 +0300 Subject: [PATCH] Squashed 'librocksdb-sys/rocksdb/' changes from 2776c764d..e542f605a e542f605a Revert "trying with memcpy in openssl" 1f28422b7 Revert "randomize only the IV part of prefix" git-subtree-dir: librocksdb-sys/rocksdb git-subtree-split: e542f605ac709ee497dbf7e6aedf97837bf8af8c --- .../plugin/openssl/openssl_provider.cc | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/librocksdb-sys/rocksdb/plugin/openssl/openssl_provider.cc b/librocksdb-sys/rocksdb/plugin/openssl/openssl_provider.cc index aeb22a9..0e75379 100644 --- a/librocksdb-sys/rocksdb/plugin/openssl/openssl_provider.cc +++ b/librocksdb-sys/rocksdb/plugin/openssl/openssl_provider.cc @@ -191,28 +191,28 @@ Status OpensslCipherStream::Encrypt(uint64_t fileOffset, char* data, EVP_CIPHER_CTX_set_padding(ctx_, 0); if (offset == 0) { - unsigned char *out = (unsigned char*)malloc(dataSize); - if( 1 != EVP_EncryptUpdate(ctx_, out, &len, reinterpret_cast(data), static_cast(dataSize))) {err_str="Failed to encrypt."; goto error;} - memcpy(data, out, dataSize); + //unsigned char *out = (unsigned char*)malloc(dataSize); + if( 1 != EVP_EncryptUpdate(ctx_, reinterpret_cast(data), &len, reinterpret_cast(data), static_cast(dataSize))) {err_str="Failed to encrypt."; goto error;} + //memcpy(data, out, dataSize); //EVP_EncryptFinal_ex(ctx_, reinterpret_cast(data) + len, &len); } else { unsigned char zero_block[kBlockSize]{0}; - unsigned char zero_block_out[kBlockSize]{0}; - if( 1 != EVP_EncryptUpdate(ctx_, zero_block_out, &len, zero_block, static_cast(kBlockSize))) {err_str="Failed to encrypt zero block."; goto error;} + //unsigned char zero_block_out[kBlockSize]{0}; + if( 1 != EVP_EncryptUpdate(ctx_, zero_block, &len, zero_block, static_cast(kBlockSize))) {err_str="Failed to encrypt zero block."; goto error;} //unsigned char * end = reinterpret_cast(zero_block) + len; size_t n = std::min(kBlockSize - offset, dataSize); - for (size_t i = 0; i < n; ++i) data[i] ^= zero_block_out[offset + i]; - //memset(zero_block, 0, kBlockSize); + for (size_t i = 0; i < n; ++i) data[i] ^= zero_block[offset + i]; + memset(zero_block, 0, kBlockSize); n = kBlockSize - offset; if (dataSize > n) { char* ptr = (char*)(data + n); - unsigned char *out = (unsigned char*)malloc(dataSize - n); - if( 1 != EVP_EncryptUpdate(ctx_, out, &len, reinterpret_cast(ptr), static_cast(dataSize - n))) {err_str="Failed to encrypt remaining."; goto error;} - memcpy(ptr, out, dataSize - n); + //unsigned char *out = (unsigned char*)malloc(dataSize - n); + if( 1 != EVP_EncryptUpdate(ctx_, reinterpret_cast(ptr), &len, reinterpret_cast(ptr), static_cast(dataSize - n))) {err_str="Failed to encrypt remaining."; goto error;} + //memcpy(ptr, out, dataSize - n); //end = reinterpret_cast(ptr) + len; } @@ -270,7 +270,7 @@ Status OpensslProvider::AddCipher(const std::string& /*descriptor*/, Status OpensslProvider::CreateNewPrefix(const std::string& /*fname*/, char* prefix, size_t prefixLength) const { - if (1 != RAND_bytes(reinterpret_cast(prefix), static_cast(OpensslCipherStream::kBlockSize)) ){ + if (1 != RAND_bytes(reinterpret_cast(prefix), static_cast(prefixLength)) ){ return handleErrors("Failed to get random numbers.");//Status::Aborted(ERR_reason_error_string(ERR_get_error())); } //if( 1 != EVP_CIPHER_up_ref(aes_cipher_)) return handleErrors("Failed to create OpensslCipherStream.");