26#ifndef MYSQLROUTER_ROUTING_AUTH_DIGEST_H
27#define MYSQLROUTER_ROUTING_AUTH_DIGEST_H
46template <
class Ret,
bool nonce_before_
double_hashed_password>
47inline std::optional<Ret>
scramble(std::string_view nonce,
49 const EVP_MD *digest_func) {
50 using return_type = Ret;
53 if (
password.size() == 0)
return Ret{};
57 const int digest_size = func.
size();
65 return_type hashed_password;
66 hashed_password.resize(digest_size);
68 if (!digest.
finalize(hashed_password) || !digest.
init() ||
69 !digest.
update(hashed_password)) {
75 digest2.resize(digest_size);
81 if (nonce_before_double_hashed_password) {
99 for (
int i = 0; i < digest_size; ++i) {
100 hashed_password[i] ^= digest2[i];
103 return hashed_password;
109 std::string_view pwd) {
110 return routing::impl::scramble<Ret, true>(nonce, pwd, EVP_sha1());
115 std::string_view pwd) {
116 return routing::impl::scramble<Ret, false>(nonce, pwd, EVP_sha256());
std::optional< Ret > mysql_native_password_scramble(std::string_view nonce, std::string_view pwd)
Definition: auth_digest.h:108
std::optional< Ret > caching_sha2_password_scramble(std::string_view nonce, std::string_view pwd)
Definition: auth_digest.h:114
Definition: openssl_digest.h:49
bool update(const T &data)
Definition: openssl_digest.h:81
bool init()
Definition: openssl_digest.h:66
bool finalize(T &out)
Definition: openssl_digest.h:86
Definition: openssl_digest.h:37
int size() const
Definition: openssl_digest.h:41
static char * password
Definition: mysql_secure_installation.cc:58
Definition: auth_digest.h:34
std::optional< Ret > scramble(std::string_view nonce, std::string_view password, const EVP_MD *digest_func)
Definition: auth_digest.h:47