CUBRID Engine  latest
crypt_opfunc.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "CRC.h"
#include "thread_compat.hpp"
#include "porting.h"
#include "error_code.h"
#include "error_manager.h"
#include "memory_alloc.h"
#include "crypt_opfunc.h"
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/rand.h>

Go to the source code of this file.

Macros

#define AES128_BLOCK_LEN   (128/8)
 
#define AES128_KEY_LEN   (128/8)
 
#define DES_BLOCK_LEN   (8)
 
#define MD5_CHECKSUM_LEN   16
 
#define MD5_CHECKSUM_HEX_LEN   (32 + 1)
 

Typedefs

template<typename T >
using deleted_unique_ptr = std::unique_ptr< T, std::function< void(T *)>>
 

Enumerations

enum  CRYPT_LIB_ERROR {
  CRYPT_LIB_INIT_ERR = 0, CRYPT_LIB_OPEN_CIPHER_ERR, CRYPT_LIB_SET_KEY_ERR, CRYPT_LIB_CRYPT_ERR,
  CRYPT_LIB_UNKNOWN_ERR
}
 
enum  SHA_FUNCTION {
  SHA_ONE, SHA_TWO_224, SHA_TWO_256, SHA_TWO_384,
  SHA_TWO_512
}
 

Functions

static int crypt_sha_functions (THREAD_ENTRY *thread_p, const char *src, int src_len, SHA_FUNCTION sha_func, char **dest_p, int *dest_len_p)
 
static int crypt_md5_buffer_binary (const char *buffer, size_t len, char *resblock)
 
static void aes_default_gen_key (const char *key, int key_len, char *dest_key, int dest_key_len)
 
void str_to_hex_prealloced (const char *src, int src_len, char *dest, int dest_len, HEX_LETTERCASE lettercase)
 
char * str_to_hex (THREAD_ENTRY *thread_p, const char *src, int src_len, char **dest_p, int *dest_len_p, HEX_LETTERCASE lettercase)
 
int crypt_default_encrypt (THREAD_ENTRY *thread_p, const char *src, int src_len, const char *key, int key_len, char **dest_p, int *dest_len_p, CIPHER_ENCRYPTION_TYPE enc_type)
 
int crypt_default_decrypt (THREAD_ENTRY *thread_p, const char *src, int src_len, const char *key, int key_len, char **dest_p, int *dest_len_p, CIPHER_ENCRYPTION_TYPE enc_type)
 
int crypt_sha_one (THREAD_ENTRY *thread_p, const char *src, int src_len, char **dest_p, int *dest_len_p)
 
int crypt_sha_two (THREAD_ENTRY *thread_p, const char *src, int src_len, int need_hash_len, char **dest_p, int *dest_len_p)
 
int crypt_md5_buffer_hex (const char *buffer, size_t len, char *resblock)
 
void crypt_crc32 (const char *src, int src_len, int *dest)
 
int crypt_generate_random_bytes (char *dest, int length)
 

Variables

static const char *const crypt_lib_fail_info []
 
static const char lower_hextable [] = "0123456789abcdef"
 
static const char upper_hextable [] = "0123456789ABCDEF"
 

Macro Definition Documentation

#define AES128_BLOCK_LEN   (128/8)

Definition at line 57 of file crypt_opfunc.c.

Referenced by crypt_default_decrypt(), and crypt_default_encrypt().

#define AES128_KEY_LEN   (128/8)

Definition at line 58 of file crypt_opfunc.c.

Referenced by crypt_default_decrypt(), and crypt_default_encrypt().

#define DES_BLOCK_LEN   (8)

Definition at line 59 of file crypt_opfunc.c.

Referenced by crypt_default_decrypt(), and crypt_default_encrypt().

#define MD5_CHECKSUM_HEX_LEN   (32 + 1)

Definition at line 61 of file crypt_opfunc.c.

Referenced by crypt_md5_buffer_hex().

#define MD5_CHECKSUM_LEN   16

Definition at line 60 of file crypt_opfunc.c.

Referenced by crypt_md5_buffer_hex().

Typedef Documentation

template<typename T >
using deleted_unique_ptr = std::unique_ptr<T, std::function<void (T *)>>

Definition at line 83 of file crypt_opfunc.c.

Enumeration Type Documentation

Enumerator
CRYPT_LIB_INIT_ERR 
CRYPT_LIB_OPEN_CIPHER_ERR 
CRYPT_LIB_SET_KEY_ERR 
CRYPT_LIB_CRYPT_ERR 
CRYPT_LIB_UNKNOWN_ERR 

Definition at line 63 of file crypt_opfunc.c.

Enumerator
SHA_ONE 
SHA_TWO_224 
SHA_TWO_256 
SHA_TWO_384 
SHA_TWO_512 

Definition at line 72 of file crypt_opfunc.c.

Function Documentation

static void aes_default_gen_key ( const char *  key,
int  key_len,
char *  dest_key,
int  dest_key_len 
)
static

Definition at line 181 of file crypt_opfunc.c.

References assert, i, and NULL.

Referenced by crypt_default_decrypt(), and crypt_default_encrypt().

Here is the caller graph for this function:

void crypt_crc32 ( const char *  src,
int  src_len,
int *  dest 
)

Definition at line 672 of file crypt_opfunc.c.

References assert, CRC::Calculate(), CRC::CRC_32(), and NULL.

Referenced by db_crc32_dbval(), logpb_compute_page_checksum(), and logwr_check_page_checksum().

Here is the caller graph for this function:

int crypt_default_decrypt ( THREAD_ENTRY thread_p,
const char *  src,
int  src_len,
const char *  key,
int  key_len,
char **  dest_p,
int *  dest_len_p,
CIPHER_ENCRYPTION_TYPE  enc_type 
)
int crypt_default_encrypt ( THREAD_ENTRY thread_p,
const char *  src,
int  src_len,
const char *  key,
int  key_len,
char **  dest_p,
int *  dest_len_p,
CIPHER_ENCRYPTION_TYPE  enc_type 
)
int crypt_generate_random_bytes ( char *  dest,
int  length 
)

Definition at line 688 of file crypt_opfunc.c.

References ARG_FILE_LINE, assert, CRYPT_LIB_CRYPT_ERR, crypt_lib_fail_info, ER_ENCRYPTION_LIB_FAILED, ER_ERROR_SEVERITY, er_set(), NO_ERROR, and NULL.

Referenced by db_guid().

Here is the caller graph for this function:

static int crypt_md5_buffer_binary ( const char *  buffer,
size_t  len,
char *  resblock 
)
static

Definition at line 603 of file crypt_opfunc.c.

References ARG_FILE_LINE, assert, CRYPT_LIB_CRYPT_ERR, crypt_lib_fail_info, CRYPT_LIB_INIT_ERR, ER_ENCRYPTION_LIB_FAILED, ER_ERROR_SEVERITY, ER_FAILED, er_set(), NO_ERROR, and NULL.

Referenced by crypt_md5_buffer_hex().

Here is the caller graph for this function:

int crypt_md5_buffer_hex ( const char *  buffer,
size_t  len,
char *  resblock 
)
static int crypt_sha_functions ( THREAD_ENTRY thread_p,
const char *  src,
int  src_len,
SHA_FUNCTION  sha_func,
char **  dest_p,
int *  dest_len_p 
)
static
int crypt_sha_one ( THREAD_ENTRY thread_p,
const char *  src,
int  src_len,
char **  dest_p,
int *  dest_len_p 
)

Definition at line 473 of file crypt_opfunc.c.

References crypt_sha_functions(), and SHA_ONE.

Referenced by db_string_sha_one().

Here is the caller graph for this function:

int crypt_sha_two ( THREAD_ENTRY thread_p,
const char *  src,
int  src_len,
int  need_hash_len,
char **  dest_p,
int *  dest_len_p 
)

Definition at line 490 of file crypt_opfunc.c.

References crypt_sha_functions(), NO_ERROR, SHA_TWO_224, SHA_TWO_256, SHA_TWO_384, and SHA_TWO_512.

Referenced by db_string_sha_two(), and encrypt_password_sha2_512().

Here is the caller graph for this function:

char* str_to_hex ( THREAD_ENTRY thread_p,
const char *  src,
int  src_len,
char **  dest_p,
int *  dest_len_p,
HEX_LETTERCASE  lettercase 
)

Definition at line 141 of file crypt_opfunc.c.

References assert, db_private_alloc, i, NULL, str_to_hex_prealloced(), and thread_get_thread_entry_info().

Referenced by crypt_sha_functions().

Here is the caller graph for this function:

void str_to_hex_prealloced ( const char *  src,
int  src_len,
char *  dest,
int  dest_len,
HEX_LETTERCASE  lettercase 
)

Definition at line 103 of file crypt_opfunc.c.

References assert, HEX_UPPERCASE, i, lower_hextable, NULL, and upper_hextable.

Referenced by crypt_md5_buffer_hex(), and str_to_hex().

Here is the caller graph for this function:

Variable Documentation

const char* const crypt_lib_fail_info[]
static
Initial value:
= {
"Initialization failure!",
"Open cipher failure!",
"Set secret key failure!",
"Encrypt/decrypt failure!",
"Unknown error!"
}

Definition at line 86 of file crypt_opfunc.c.

Referenced by crypt_default_decrypt(), crypt_default_encrypt(), crypt_generate_random_bytes(), crypt_md5_buffer_binary(), and crypt_sha_functions().

const char lower_hextable[] = "0123456789abcdef"
static

Definition at line 94 of file crypt_opfunc.c.

Referenced by str_to_hex_prealloced().

const char upper_hextable[] = "0123456789ABCDEF"
static

Definition at line 95 of file crypt_opfunc.c.

Referenced by str_to_hex_prealloced().