MySQL 9.5.0
Source Code Documentation
crypt_genhash_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/**
25 @file include/crypt_genhash_impl.h
26*/
27
28#ifndef CRYPT_HASHGEN_IMPL_H
29#define CRYPT_HASHGEN_IMPL_H
30
31// sha256 rounds
32#define ROUNDS_DEFAULT 5000
33#define ROUNDS_MIN ROUNDS_DEFAULT
34#define ROUNDS_MAX (0xFFF * 1000)
35
36// caching_sha2 rounds
37#define SHA2_ROUNDS_DEFAULT 10000
38#define SHA2_ROUNDS_MIN 5000
39#define SHA2_ROUNDS_MAX (0xFFF * 1000)
40
41#define MIXCHARS 32
42#define CRYPT_SALT_LENGTH 20
43#define CRYPT_MAGIC_LENGTH 3
44#define CRYPT_PARAM_LENGTH 13
45#define SHA256_HASH_LENGTH 43
46#define CRYPT_MAX_PASSWORD_SIZE \
47 (CRYPT_SALT_LENGTH + SHA256_HASH_LENGTH + CRYPT_MAGIC_LENGTH + \
48 CRYPT_PARAM_LENGTH)
49#define MAX_PLAINTEXT_LENGTH 256
50
51#include <stddef.h>
52
53#include "my_macros.h"
54
55int extract_user_salt(const char **salt_begin, const char **salt_end);
56char *my_crypt_genhash(char *ctbuffer, size_t ctbufflen, const char *plaintext,
57 size_t plaintext_len, const char *switchsalt,
58 const char **params, unsigned int *num_rounds = nullptr);
59void generate_user_salt(char *buffer, int buffer_len);
60void xor_string(char *to, int to_len, char *pattern, int pattern_len);
61
62// extern "C" since it is an (undocumented) part of the libmysql ABI.
63extern "C" void my_make_scrambled_password(char *to, const char *password,
64 size_t pass_len);
65
66#endif
void my_make_scrambled_password(char *to, const char *password, size_t pass_len)
Definition: crypt_genhash_impl.cc:444
void xor_string(char *to, int to_len, char *pattern, int pattern_len)
Definition: crypt_genhash_impl.cc:435
void generate_user_salt(char *buffer, int buffer_len)
Generate a random string using ASCII characters but avoid separator character.
Definition: crypt_genhash_impl.cc:422
char * my_crypt_genhash(char *ctbuffer, size_t ctbufflen, const char *plaintext, size_t plaintext_len, const char *switchsalt, const char **params, unsigned int *num_rounds=nullptr)
Definition: crypt_genhash_impl.cc:235
int extract_user_salt(const char **salt_begin, const char **salt_end)
Finds the interval which envelopes the user salt in a crypt password The crypt format is assumed to b...
Definition: crypt_genhash_impl.cc:187
Some common macros.
static char * password
Definition: mysql_secure_installation.cc:58
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418