MySQL 8.0.39
Source Code Documentation
crypt_genhash_impl.cc File Reference
#include "my_config.h"
#include <memory>
#include <sys/types.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "crypt_genhash_impl.h"
#include "m_string.h"
#include <errno.h>

Macros

#define DIGEST_CTX   EVP_MD_CTX
 
#define DIGEST_LEN   SHA256_DIGEST_LENGTH
 
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define b64_from_24bit(B2, B1, B0, N)
 
#define ROUNDS   "rounds="
 
#define ROUNDSLEN   (sizeof(ROUNDS) - 1)
 

Functions

static void DIGESTCreate (DIGEST_CTX **ctx)
 
static void DIGESTInit (DIGEST_CTX *ctx)
 
static void DIGESTUpdate (DIGEST_CTX *ctx, const void *plaintext, int len)
 
static void DIGESTFinal (void *txt, DIGEST_CTX *ctx)
 
static void DIGESTDestroy (DIGEST_CTX **ctx)
 
static size_t strlcat (char *dst, const char *src, size_t siz)
 Size-bounded string copying and concatenation This is a replacement for STRLCPY(3) More...
 
static uint getrounds (const char *s)
 Get the integer value after rounds= where ever it occurs in the string. More...
 
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 be $a$bbbb$cccccc\0 and the salt is found by counting the delimiters and marking begin and end. More...
 
char * my_crypt_genhash (char *ctbuffer, size_t ctbufflen, const char *plaintext, size_t plaintext_len, const char *switchsalt, const char **, unsigned int *num_rounds)
 
void generate_user_salt (char *buffer, int buffer_len)
 Generate a random string using ASCII characters but avoid separator character. More...
 
void xor_string (char *to, int to_len, char *pattern, int pattern_len)
 

Variables

static const char crypt_alg_magic [] = "$5"
 
static const int crypt_alg_magic_len = sizeof(crypt_alg_magic) - 1
 
static unsigned char b64t []
 

Macro Definition Documentation

◆ b64_from_24bit

#define b64_from_24bit (   B2,
  B1,
  B0,
 
)
Value:
{ \
uint32_t w = ((B2) << 16) | ((B1) << 8) | (B0); \
int n = (N); \
while (--n >= 0 && ctbufflen > 0) { \
*p++ = b64t[w & 0x3f]; \
w >>= 6; \
ctbufflen--; \
} \
}
static unsigned char b64t[]
Definition: crypt_genhash_impl.cc:121
const char * p
Definition: ctype-mb.cc:1237
std::atomic< Type > N
Definition: ut0counter.h:225
int n
Definition: xcom_base.cc:509

◆ DIGEST_CTX

#define DIGEST_CTX   EVP_MD_CTX

◆ DIGEST_LEN

#define DIGEST_LEN   SHA256_DIGEST_LENGTH

◆ MAX

#define MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

◆ MIN

#define MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

◆ ROUNDS

#define ROUNDS   "rounds="

◆ ROUNDSLEN

#define ROUNDSLEN   (sizeof(ROUNDS) - 1)

Function Documentation

◆ DIGESTCreate()

static void DIGESTCreate ( DIGEST_CTX **  ctx)
static

◆ DIGESTDestroy()

static void DIGESTDestroy ( DIGEST_CTX **  ctx)
static

◆ DIGESTFinal()

static void DIGESTFinal ( void *  txt,
DIGEST_CTX ctx 
)
static

◆ DIGESTInit()

static void DIGESTInit ( DIGEST_CTX ctx)
static

◆ DIGESTUpdate()

static void DIGESTUpdate ( DIGEST_CTX ctx,
const void *  plaintext,
int  len 
)
static

◆ extract_user_salt()

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 be $a$bbbb$cccccc\0 and the salt is found by counting the delimiters and marking begin and end.

Parameters
[in,out]salt_beginAs input, pointer to start of crypt passwd, as output, pointer to first byte of the salt
[in,out]salt_endAs input, pointer to the last byte in passwd, as output, pointer to the byte immediately following the salt ($)
Returns
The size of the salt identified

◆ generate_user_salt()

void generate_user_salt ( char *  buffer,
int  buffer_len 
)

Generate a random string using ASCII characters but avoid separator character.

Stdlib rand and srand are used to produce pseudo random numbers between with about 7 bit worth of entropty between 1-127.

◆ getrounds()

static uint getrounds ( const char *  s)
static

Get the integer value after rounds= where ever it occurs in the string.

if the last char after the int is a , or $ that is fine anything else is an error.

◆ my_crypt_genhash()

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 
)

◆ strlcat()

static size_t strlcat ( char *  dst,
const char *  src,
size_t  siz 
)
static

Size-bounded string copying and concatenation This is a replacement for STRLCPY(3)

◆ xor_string()

void xor_string ( char *  to,
int  to_len,
char *  pattern,
int  pattern_len 
)

Variable Documentation

◆ b64t

unsigned char b64t[]
static
Initial value:
=
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

◆ crypt_alg_magic

const char crypt_alg_magic[] = "$5"
static

◆ crypt_alg_magic_len

const int crypt_alg_magic_len = sizeof(crypt_alg_magic) - 1
static