Files
m241Neelima/vxworks-6.9/target/src/openssl/ipcrypto/ipcrypto.c
T
2026-07-30 20:15:19 +05:30

117 lines
2.6 KiB
C

/*
* Copyright (c) 2014, 2016, 2018-2022, 2024 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
#include <stdlib.h>
#include <string.h>
#include <semLib.h>
#include <taskLib.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/evp.h>
#ifndef OPENSSL_NO_ENGINE
#include <openssl/engine.h>
#endif
#include <vxWorks.h>
#include "ipcrypto.h"
#include "ipcrypto_util.h"
#include "ipcrypto_config.h"
#ifdef _WRS_CONFIG_OPENSSL_FIPSMODULE
size_t ipcrypto_get_root_stack_size(void);
#endif
int ipcrypto_configure(void);
typedef struct Ipcrypto_data_st
{
mutex_t *crypto_locks;
}Ipcrypto_data;
CONF *ipcrypto_config = NULL;
int in_FIPS_mode=0;
extern int ipcrypto_init_internal(SEM_ID semId);
#ifdef _WRS_KERNEL
#ifdef IPCRYPTO_USE_TEST
int
ipcrypto_cmd_memory(int argc, char **argv)
{
#ifdef CRYPTO_MDEBUG
BIO *local_bio_out;
(void)argc;
(void)argv;
MemCheck_off();
local_bio_out = BIO_new_fp(ip_stdout, BIO_NOCLOSE);
MemCheck_on();
CRYPTO_mem_leaks(local_bio_out);
(void)BIO_flush(local_bio_out);
(void) BIO_free(local_bio_out);
#else
(void)argc;
(void)argv;
#endif
return 0;
}
#endif /* IPCRYPTO_USE_TEST */
#endif
#ifdef _WRS_KERNEL
/*******************************************************************************
*
* crypto_init - INCLUDE_IPCRYPTO init rtn
*/
int ipcrypto_init(void)
{
#ifdef _WRS_CONFIG_OPENSSL_FIPSMODULE
/* When the openssl the FIPS 140-2 module is included in the build, the FIPS 140-2 module
* init routines (that are called by the openssl init routines) call RAND_add which
* take a double as an argument. Hence the init routines must be called from a task
* with the VX_FP_TASK option set. */
SEM_ID semId;
TASK_ID taskId;
semId = semCCreate(SEM_Q_PRIORITY, 0);
if (!semId)
return ERROR;
taskId = taskSpawn("tOpensslInit",
0,
VX_FP_TASK,
(size_t)ipcrypto_get_root_stack_size(),
(FUNCPTR)ipcrypto_init_internal,
(_Vx_usr_arg_t)semId, 2, 3, 4, 5, 6, 7, 8, 9, 10);
if (taskId != TASK_ID_NULL)
semTake(semId, WAIT_FOREVER); /* Wait for init task to complete */
semDelete(semId);
if (taskId == TASK_ID_NULL)
return ERROR;
return OK;
#else
(void)ipcrypto_configure();
return ipcrypto_init_internal(SEM_ID_NULL);
#endif
}
#endif