Security libcrypto module implementation file. More...
#include "security_libcrypto.h"
#include "memory.h"
#include "definitions.h"
#include "log_util.h"
#include "base64.h"
#include "string_util.h"
Go to the source code of this file.
Macros | |
#define | KEY_LENGTH_BITS 3072 |
Functions | |
static E_MCL_ERROR_CODE | _base64_encode_big_number (BIGNUM *big_number, char **encoded) |
static E_MCL_ERROR_CODE | _get_rsa_public_key (RSA *rsa, char **public_key) |
static E_MCL_ERROR_CODE | _get_rsa_private_key (RSA *rsa, char **private_key) |
static void * | _libcrypto_malloc (size_t size, const char *file, int line) |
static void * | _libcrypto_realloc (void *p, size_t size, const char *file, int line) |
static void | _libcrypto_free (void *p, const char *file, int line) |
void | security_initialize (void) |
E_MCL_ERROR_CODE | security_hash_sha256 (const mcl_uint8_t *data, mcl_size_t data_size, mcl_uint8_t **hash, mcl_size_t *hash_size) |
E_MCL_ERROR_CODE | security_rsa_sign (char *rsa_key, char *data, mcl_size_t data_size, mcl_uint8_t **signature, mcl_size_t *signature_size) |
To be used to sign data with RSA key. More... | |
E_MCL_ERROR_CODE | security_generate_rsa_key (char **public_key, char **private_key) |
To be used to generate the RSA public/private keys. More... | |
E_MCL_ERROR_CODE | security_rsa_get_modulus_and_exponent (char *public_key, char **modulus, char **exponent) |
To be used to get the modulus (n) and public exponent (e) parameters of RSA key in Base64 format. More... | |
E_MCL_ERROR_CODE | security_generate_random_bytes (unsigned char *buffer, mcl_size_t size) |
To be used to generate random bytes. More... | |
Security libcrypto module implementation file.
Definition in file security_libcrypto.c.
#define KEY_LENGTH_BITS 3072 |
Definition at line 53 of file security_libcrypto.c.
Referenced by security_generate_rsa_key().
|
static |
Definition at line 231 of file security_libcrypto.c.
References ASSERT_CODE, base64_url_encode(), string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by security_rsa_get_modulus_and_exponent().
|
static |
Definition at line 259 of file security_libcrypto.c.
References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR_RETURN, MCL_FAIL, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by security_generate_rsa_key().
|
static |
Definition at line 294 of file security_libcrypto.c.
References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR_RETURN, MCL_FAIL, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by security_generate_rsa_key().
|
static |
Definition at line 365 of file security_libcrypto.c.
References memory_free(), VERBOSE_ENTRY, and VERBOSE_LEAVE.
Referenced by security_initialize().
|
static |
Definition at line 329 of file security_libcrypto.c.
References MCL_NULL, memory_malloc(), VERBOSE_ENTRY, and VERBOSE_LEAVE.
Referenced by security_initialize().
|
static |
Definition at line 347 of file security_libcrypto.c.
References memory_realloc(), VERBOSE_ENTRY, and VERBOSE_LEAVE.
Referenced by security_initialize().
E_MCL_ERROR_CODE security_generate_random_bytes | ( | unsigned char * | buffer, |
mcl_size_t | size | ||
) |
To be used to generate random bytes.
[out] | buffer | Buffer which will be filled with random bytes. |
[in] | size | Size of the buffer. |
Definition at line 214 of file security_libcrypto.c.
References DEBUG_ENTRY, DEBUG_LEAVE, MCL_FAIL, and MCL_OK.
Referenced by _generate_correlation_id_string(), random_generate_array(), random_generate_guid(), and random_generate_number().
E_MCL_ERROR_CODE security_generate_rsa_key | ( | char ** | public_key, |
char ** | private_key | ||
) |
To be used to generate the RSA public/private keys.
Generated keys will be returned as out parameters.
[out] | public_key | Generated public key. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space. |
[out] | private_key | Generated private key. New memory space will be allocated for this parameter. Ownership passed to caller. Caller must free the space. |
Definition at line 137 of file security_libcrypto.c.
References _get_rsa_private_key(), _get_rsa_public_key(), ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, KEY_LENGTH_BITS, MCL_FAIL, MCL_FREE, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by security_handler_generate_rsa_key().
E_MCL_ERROR_CODE security_hash_sha256 | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
mcl_uint8_t ** | hash, | ||
mcl_size_t * | hash_size | ||
) |
Definition at line 78 of file security_libcrypto.c.
References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_CALLOC, MCL_DEBUG, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by hmac_sha256(), security_handler_hash_sha256(), and security_rsa_sign().
void security_initialize | ( | void | ) |
Initializes security module. This function is used e.g. to set memory callback functions.
Definition at line 69 of file security_libcrypto.c.
References _libcrypto_free(), _libcrypto_malloc(), _libcrypto_realloc(), DEBUG_ENTRY, and DEBUG_LEAVE.
Referenced by http_processor_initialize().
E_MCL_ERROR_CODE security_rsa_get_modulus_and_exponent | ( | char * | public_key, |
char ** | modulus, | ||
char ** | exponent | ||
) |
To be used to get the modulus (n) and public exponent (e) parameters of RSA key in Base64 format.
public_key | Public key in PEM format. |
modulus | Base64 encoded modulus of RSA key. |
exponent | Base64 encoded public exponent of RSA key. |
Definition at line 180 of file security_libcrypto.c.
References _base64_encode_big_number(), ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_FAIL, MCL_FREE, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, and string_util_strlen().
Referenced by _compose_rsa_key_rotation_json(), and _compose_rsa_onboarding_json().
E_MCL_ERROR_CODE security_rsa_sign | ( | char * | rsa_key, |
char * | data, | ||
mcl_size_t | data_size, | ||
mcl_uint8_t ** | signature, | ||
mcl_size_t * | signature_size | ||
) |
To be used to sign data with RSA key.
Received key will be used to sign.
[in] | rsa_key | Private key to be used in signing. |
[in] | data | The data to be signed. |
[in] | data_size | Size of the data. |
[out] | signature | Generated signature. |
[out] | signature_size | Size of signature. |
Definition at line 99 of file security_libcrypto.c.
References ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_FAIL, MCL_FALSE, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, security_hash_sha256(), and string_util_strlen().
Referenced by security_handler_rsa_sign().