diff --git a/src/IO/FileEncryptionCommon.cpp b/src/IO/FileEncryptionCommon.cpp index 5529c813c407..6f4db4975f70 100644 --- a/src/IO/FileEncryptionCommon.cpp +++ b/src/IO/FileEncryptionCommon.cpp @@ -8,10 +8,11 @@ #include #include -#include -#include -#include +# include +# include +# include +# include namespace DB { @@ -20,6 +21,7 @@ namespace ErrorCodes { extern const int BAD_ARGUMENTS; extern const int DATA_ENCRYPTION_ERROR; + extern const int OPENSSL_ERROR; } namespace FileEncryption @@ -260,12 +262,11 @@ void InitVector::write(WriteBuffer & out) const InitVector InitVector::random() { - std::random_device rd; - std::mt19937 gen{rd()}; - std::uniform_int_distribution dis; UInt128 counter; - for (auto & i : counter.items) - i = dis(gen); + auto * buf = reinterpret_cast(counter.items); + auto ret = RAND_bytes(buf, sizeof(counter.items)); + if (ret != 1) + throw Exception(DB::ErrorCodes::OPENSSL_ERROR, "OpenSSL error code: {}", ERR_get_error()); return InitVector{counter}; }