FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/wc_port.c
/* Used to initialize state for wolfcrypt
   return 0 on success
 */
Used to initialize state for wolfcrypt
return 0 on success
Used to initialize state for wolfcrypt return 0 on success
int wolfCrypt_Init(void)
{
    int ret = 0;
    if (initRefCount == 0) {
        WOLFSSL_ENTER("wolfCrypt_Init");
    #ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST
        {
            word32 rngMallocFail;
            time_t seed = time(NULL);
            srand((word32)seed);
            rngMallocFail = rand() % 2000; 
            printf("\n--- RNG MALLOC FAIL AT %d---\n", rngMallocFail);
            wolfSSL_SetMemFailCount(rngMallocFail);
        }
    #endif
    #ifdef WOLF_CRYPTO_CB
        wc_CryptoCb_Init();
    #endif
    #ifdef WOLFSSL_ASYNC_CRYPT
        ret = wolfAsync_HardwareStart();
        if (ret != 0) {
            WOLFSSL_MSG("Async hardware start failed");
        }
    #endif
    #if defined(WOLFSSL_RENESAS_TSIP_CRYPT)
        ret = tsip_Open( );
        if( ret != TSIP_SUCCESS ) {
            WOLFSSL_MSG("RENESAS TSIP Open failed");
            ret = -1;
            return ret;
        }
    #endif
    #if defined(WOLFSSL_TRACK_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY)
        ret = InitMemoryTracker();
        if (ret != 0) {
            WOLFSSL_MSG("InitMemoryTracker failed");
            return ret;
        }
    #endif
    #if WOLFSSL_CRYPT_HW_MUTEX
        ret = wolfSSL_CryptHwMutexInit();
        if (ret != 0) {
            WOLFSSL_MSG("Hw crypt mutex init failed");
            return ret;
        }
    #endif
    #ifdef HAVE_FAST_RSA
        WOLFSSL_MSG("Attempting to use optimized IPP Library");
        if ((ret = ippInit()) != ippStsNoErr) {
            WOLFSSL_MSG("Warning when trying to set up optimization");
            WOLFSSL_MSG(ippGetStatusString(ret));
            WOLFSSL_MSG("Using default fast IPP library");
            ret = 0;
            (void)ret; 
        }
    #endif
    #if defined(FREESCALE_LTC_TFM) || defined(FREESCALE_LTC_ECC)
        ret = ksdk_port_init();
        if (ret != 0) {
            WOLFSSL_MSG("KSDK port init failed");
            return ret;
        }
    #endif
    #if defined(WOLFSSL_ATMEL) || defined(WOLFSSL_ATECC508A) || \
        defined(WOLFSSL_ATECC608A)
        ret = atmel_init();
        if (ret != 0) {
            WOLFSSL_MSG("CryptoAuthLib init failed");
            return ret;
        }
    #endif
    #if defined(WOLFSSL_CRYPTOCELL)
        ret = cc310_Init();
        if (ret != 0) {
            WOLFSSL_MSG("CRYPTOCELL init failed");
            return ret;
        }
    #endif
    #if defined(WOLFSSL_STSAFEA100)
        stsafe_interface_init();
    #endif
    #if defined(WOLFSSL_PSOC6_CRYPTO)
        ret = psoc6_crypto_port_init();
        if (ret != 0) {
            WOLFSSL_MSG("PSoC6 crypto engine init failed");
            return ret;
        }
    #endif
    #ifdef WOLFSSL_ARMASM
        WOLFSSL_MSG("Using ARM hardware acceleration");
    #endif
    #ifdef WOLFSSL_AFALG
	WOLFSSL_MSG("Using AF_ALG for crypto acceleration");
    #endif
    #if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
        wolfSSL_EVP_init();
    #endif
    #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
        if ((ret = wc_LoggingInit()) != 0) {
            WOLFSSL_MSG("Error creating logging mutex");
            return ret;
        }
    #endif
#ifdef HAVE_ECC
    #ifdef FP_ECC
        wc_ecc_fp_init();
    #endif
    #ifdef ECC_CACHE_CURVE
        if ((ret = wc_ecc_curve_cache_init()) != 0) {
            WOLFSSL_MSG("Error creating curve cache");
            return ret;
        }
    #endif
#endif
#ifdef WOLFSSL_SCE
        ret = (int)WOLFSSL_SCE_GSCE_HANDLE.p_api->open(
                WOLFSSL_SCE_GSCE_HANDLE.p_ctrl, WOLFSSL_SCE_GSCE_HANDLE.p_cfg);
        if (ret == SSP_ERR_CRYPTO_SCE_ALREADY_OPEN) {
            WOLFSSL_MSG("SCE already open");
            ret = 0;
        }
        if (ret != SSP_SUCCESS) {
            WOLFSSL_MSG("Error opening SCE");
            return -1; 
        }
#endif
#if defined(WOLFSSL_IMX6_CAAM) || defined(WOLFSSL_IMX6_CAAM_RNG) || \
    defined(WOLFSSL_IMX6_CAAM_BLOB)
        if ((ret = wc_caamInit()) != 0) {
            return ret;
        }
#endif
#if defined(WOLFSSL_DSP) && !defined(WOLFSSL_DSP_BUILD)
	if ((ret = wolfSSL_InitHandle()) != 0) {
            return ret;
        }
        rpcmem_init();
#endif
    }
    initRefCount++;
    return ret;
}
int wolfCrypt_Init ( void ) { int ret = 0 ; if ( initRefCount == 0 ) { WOLFSSL_ENTER ( " " ) ; #ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST { word32 rngMallocFail ; time_t seed = time ( NULL ) ; srand ( ( word32 ) seed ) ; rngMallocFail = rand ( ) % 2000 ; printf ( " \n \n " , rngMallocFail ) ; wolfSSL_SetMemFailCount ( rngMallocFail ) ; } #endif #ifdef WOLF_CRYPTO_CB wc_CryptoCb_Init ( ) ; #endif #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfAsync_HardwareStart ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; } #endif #if defined ( WOLFSSL_RENESAS_TSIP_CRYPT ) ret = tsip_Open ( ) ; if ( ret != TSIP_SUCCESS ) { WOLFSSL_MSG ( " " ) ; ret = -1 ; return ret ; } #endif #if defined ( WOLFSSL_TRACK_MEMORY ) && ! defined ( WOLFSSL_STATIC_MEMORY ) ret = InitMemoryTracker ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #if WOLFSSL_CRYPT_HW_MUTEX ret = wolfSSL_CryptHwMutexInit ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #ifdef HAVE_FAST_RSA WOLFSSL_MSG ( " " ) ; if ( ( ret = ippInit ( ) ) != ippStsNoErr ) { WOLFSSL_MSG ( " " ) ; WOLFSSL_MSG ( ippGetStatusString ( ret ) ) ; WOLFSSL_MSG ( " " ) ; ret = 0 ; ( void ) ret ; } #endif #if defined ( FREESCALE_LTC_TFM ) || defined ( FREESCALE_LTC_ECC ) ret = ksdk_port_init ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #if defined ( WOLFSSL_ATMEL ) || defined ( WOLFSSL_ATECC508A ) || defined ( WOLFSSL_ATECC608A ) ret = atmel_init ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #if defined ( WOLFSSL_CRYPTOCELL ) ret = cc310_Init ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #if defined ( WOLFSSL_STSAFEA100 ) stsafe_interface_init ( ) ; #endif #if defined ( WOLFSSL_PSOC6_CRYPTO ) ret = psoc6_crypto_port_init ( ) ; if ( ret != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #ifdef WOLFSSL_ARMASM WOLFSSL_MSG ( " " ) ; #endif #ifdef WOLFSSL_AFALG WOLFSSL_MSG ( " " ) ; #endif #if ! defined ( WOLFCRYPT_ONLY ) && defined ( OPENSSL_EXTRA ) wolfSSL_EVP_init ( ) ; #endif #if defined ( OPENSSL_EXTRA ) || defined ( DEBUG_WOLFSSL_VERBOSE ) if ( ( ret = wc_LoggingInit ( ) ) != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #ifdef HAVE_ECC #ifdef FP_ECC wc_ecc_fp_init ( ) ; #endif #ifdef ECC_CACHE_CURVE if ( ( ret = wc_ecc_curve_cache_init ( ) ) != 0 ) { WOLFSSL_MSG ( " " ) ; return ret ; } #endif #endif #ifdef WOLFSSL_SCE ret = ( int ) WOLFSSL_SCE_GSCE_HANDLE . p_api -> open ( WOLFSSL_SCE_GSCE_HANDLE . p_ctrl , WOLFSSL_SCE_GSCE_HANDLE . p_cfg ) ; if ( ret == SSP_ERR_CRYPTO_SCE_ALREADY_OPEN ) { WOLFSSL_MSG ( " " ) ; ret = 0 ; } if ( ret != SSP_SUCCESS ) { WOLFSSL_MSG ( " " ) ; return -1 ; } #endif #if defined ( WOLFSSL_IMX6_CAAM ) || defined ( WOLFSSL_IMX6_CAAM_RNG ) || defined ( WOLFSSL_IMX6_CAAM_BLOB ) if ( ( ret = wc_caamInit ( ) ) != 0 ) { return ret ; } #endif #if defined ( WOLFSSL_DSP ) && ! defined ( WOLFSSL_DSP_BUILD ) if ( ( ret = wolfSSL_InitHandle ( ) ) != 0 ) { return ret ; } rpcmem_init ( ) ; #endif } initRefCount ++ ; return ret ; }
Used to initialize state for wolfcrypt
return 0 on success
Used to initialize state for wolfcrypt return 0 on success
/* max 2000 */ /* don't return failure, allow operation to continue */ /* not return 1 since WOLFSSL_SUCCESS=1*/ /* FATAL ERROR */ /* If crypto hardware mutex protection is enabled, then initialize it */ /* if defined have fast RSA then initialize Intel IPP */ /* possible to get a CPU feature support status on optimized IPP
              library but still use default library and see competitive speeds */ /* suppress not read warning */ /* enable and initialize the ARM CryptoCell 3xx runtime library */ /* FATAL_ERROR */