Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/autogenerated_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ SET(VERSION_MAJOR 25)
SET(VERSION_MINOR 8)
SET(VERSION_PATCH 12)
SET(VERSION_GITHASH fa393206741c830da77b8f1bcf18c753161932c8)
SET(VERSION_DESCRIBE v25.8.12.20000.altinityantalya)
SET(VERSION_STRING 25.8.12.20000.altinityantalya)
SET(VERSION_DESCRIBE v25.8.12.20000.altinitytest)
SET(VERSION_STRING 25.8.12.20000.altinitytest)
# end of autochange

# This is the 'base' tweak of the version, build scripts will
Expand Down
47 changes: 43 additions & 4 deletions src/Functions/FunctionsAES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include <string>
#include <cassert>
#include <array>
#include <cstring>
#include <string_view>

namespace DB
{
Expand Down Expand Up @@ -39,11 +42,47 @@ StringRef foldEncryptionKeyInMySQLCompatitableMode(size_t cipher_key_size, Strin

const EVP_CIPHER * getCipherByName(StringRef cipher_name)
{
// NOTE: cipher obtained not via EVP_CIPHER_fetch() would cause extra work on each context reset
// with EVP_CIPHER_CTX_reset() or EVP_EncryptInit_ex(), but using EVP_CIPHER_fetch()
// causes data race, so we stick to the slower but safer alternative here.
using CipherGetter = const EVP_CIPHER *(*)();
struct Entry
{
std::string_view name;
CipherGetter getter;
};

/// Fast path to avoid OBJ/namemap lookups in EVP_get_cipherbyname().
/// Statically linked OpenSSL provides direct getters for common AES modes.
static constexpr std::array<Entry, 21> fast_paths{{
{"aes-128-cbc", &EVP_aes_128_cbc},
{"aes-192-cbc", &EVP_aes_192_cbc},
{"aes-256-cbc", &EVP_aes_256_cbc},
{"aes-128-ecb", &EVP_aes_128_ecb},
{"aes-192-ecb", &EVP_aes_192_ecb},
{"aes-256-ecb", &EVP_aes_256_ecb},
{"aes-128-cfb", &EVP_aes_128_cfb},
{"aes-192-cfb", &EVP_aes_192_cfb},
{"aes-256-cfb", &EVP_aes_256_cfb},
{"aes-128-cfb8", &EVP_aes_128_cfb8},
{"aes-192-cfb8", &EVP_aes_192_cfb8},
{"aes-256-cfb8", &EVP_aes_256_cfb8},
{"aes-128-cfb1", &EVP_aes_128_cfb1},
{"aes-192-cfb1", &EVP_aes_192_cfb1},
{"aes-256-cfb1", &EVP_aes_256_cfb1},
{"aes-128-ofb", &EVP_aes_128_ofb},
{"aes-192-ofb", &EVP_aes_192_ofb},
{"aes-256-ofb", &EVP_aes_256_ofb},
{"aes-128-ctr", &EVP_aes_128_ctr},
{"aes-192-ctr", &EVP_aes_192_ctr},
{"aes-256-ctr", &EVP_aes_256_ctr},
}};

for (const auto & entry : fast_paths)
{
if (cipher_name.size == entry.name.size()
&& std::memcmp(cipher_name.data, entry.name.data(), entry.name.size()) == 0)
return entry.getter();
}

/// We need zero-terminated string here:
/// Fallback keeps compatibility with custom providers/algorithms.
return EVP_get_cipherbyname(cipher_name.toString().c_str());
}

Expand Down
Loading
Loading