mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 03:34:39 +02:00
wolfcrypt init
This commit is contained in:
@@ -2298,7 +2298,6 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, buffer der, int type, int verify)
|
||||
|
||||
#endif /* NO_SESSION_CACHE */
|
||||
|
||||
|
||||
int wolfSSL_Init(void)
|
||||
{
|
||||
int ret = SSL_SUCCESS;
|
||||
@@ -2318,6 +2317,11 @@ int wolfSSL_Init(void)
|
||||
WOLFSSL_MSG("Bad Lock Mutex count");
|
||||
return BAD_MUTEX_E;
|
||||
}
|
||||
|
||||
/* Initialize crypto for use with TLS connection */
|
||||
if (wolfcrypt_Init() != 0)
|
||||
ret = WC_FAILURE_E;
|
||||
|
||||
initRefCount++;
|
||||
UnLockMutex(&count_mutex);
|
||||
}
|
||||
|
@@ -244,6 +244,8 @@ int benchmark_test(void *args)
|
||||
{
|
||||
#endif
|
||||
|
||||
wolfcrypt_Init();
|
||||
|
||||
#if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
@@ -259,7 +261,7 @@ int benchmark_test(void *args)
|
||||
printf("Cavium OpenNitroxDevice failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
#endif /* HAVE_CAVIUM */
|
||||
#endif /* HAVE_CAVIUM */
|
||||
|
||||
#if defined(HAVE_LOCAL_RNG)
|
||||
{
|
||||
|
@@ -26,7 +26,13 @@
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
|
||||
/* IPP header files for library initialization */
|
||||
#ifdef HAVE_FAST_RSA
|
||||
#include <ipp.h>
|
||||
#include <ippcp.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
|
||||
@@ -34,6 +40,24 @@
|
||||
#endif
|
||||
|
||||
|
||||
/* Used to initialize state for wolfcrypt
|
||||
return 0 on success
|
||||
*/
|
||||
int wolfcrypt_Init()
|
||||
{
|
||||
/* if defined have fast RSA then initialize Intel IPP */
|
||||
#ifdef HAVE_FAST_RSA
|
||||
WOLFSSL_MSG("Setting up IPP Library");
|
||||
if (ippInit() != ippStsNoErr) {
|
||||
WOLFSSL_MSG("Error setting up optimized Intel library to use!");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if WOLFSSL_CRYPT_HW_MUTEX
|
||||
/* Mutex for protection of cryptograpghy hardware */
|
||||
static wolfSSL_Mutex wcCryptHwMutex;
|
||||
|
@@ -77,7 +77,6 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
static int ippSet = 0;
|
||||
int wc_InitRsaKey(RsaKey* key, void* heap)
|
||||
{
|
||||
|
||||
@@ -86,15 +85,6 @@ int wc_InitRsaKey(RsaKey* key, void* heap)
|
||||
if (key == NULL)
|
||||
return USER_CRYPTO_ERROR;
|
||||
|
||||
if (!ippSet) {
|
||||
USER_DEBUG(("Setting up IPP Library\n"));
|
||||
/* Selects the right optimizations to use */
|
||||
if (ippInit() != ippStsNoErr) {
|
||||
USER_DEBUG(("Error setting up optimized library to use!\n"));
|
||||
return USER_CRYPTO_ERROR;
|
||||
}
|
||||
ippSet = 1;
|
||||
}
|
||||
/* set full struct as 0 */
|
||||
ForceZero(key, sizeof(RsaKey));
|
||||
|
||||
@@ -579,39 +569,61 @@ int wc_FreeRsaKey(RsaKey* key)
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
|
||||
if (key->pPub != NULL)
|
||||
USER_DEBUG(("Entering wc_FreeRsaKey\n"));
|
||||
|
||||
if (key->pPub != NULL) {
|
||||
XFREE(key->pPub, NULL, DYNAMIC_TYPE_KEY);
|
||||
key->pPub = NULL;
|
||||
}
|
||||
|
||||
if (key->pPrv != NULL) {
|
||||
/* write over senstive information */
|
||||
ForceZero(key->pPrv, key->prvSz);
|
||||
XFREE(key->pPrv, NULL, DYNAMIC_TYPE_KEY);
|
||||
key->pPrv = NULL;
|
||||
}
|
||||
|
||||
if (key->n != NULL)
|
||||
if (key->n != NULL) {
|
||||
XFREE(key->n, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->n = NULL;
|
||||
}
|
||||
|
||||
if (key->e != NULL)
|
||||
if (key->e != NULL) {
|
||||
XFREE(key->e, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->e = NULL;
|
||||
}
|
||||
|
||||
if (key->dipp != NULL)
|
||||
if (key->dipp != NULL) {
|
||||
XFREE(key->dipp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->dipp = NULL;
|
||||
}
|
||||
|
||||
if (key->pipp != NULL)
|
||||
if (key->pipp != NULL) {
|
||||
XFREE(key->pipp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->pipp = NULL;
|
||||
}
|
||||
|
||||
if (key->qipp != NULL)
|
||||
if (key->qipp != NULL) {
|
||||
XFREE(key->qipp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->qipp = NULL;
|
||||
}
|
||||
|
||||
if (key->dPipp != NULL)
|
||||
if (key->dPipp != NULL) {
|
||||
XFREE(key->dPipp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->dPipp = NULL;
|
||||
}
|
||||
|
||||
if (key->dQipp != NULL)
|
||||
if (key->dQipp != NULL) {
|
||||
XFREE(key->dQipp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->dQipp = NULL;
|
||||
}
|
||||
|
||||
if (key->uipp != NULL)
|
||||
if (key->uipp != NULL) {
|
||||
XFREE(key->uipp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
key->uipp = NULL;
|
||||
}
|
||||
|
||||
USER_DEBUG(("\tExit wc_FreeRsaKey\n"));
|
||||
(void)key;
|
||||
|
||||
return 0;
|
||||
@@ -1151,12 +1163,26 @@ int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key)
|
||||
{
|
||||
int outSz;
|
||||
byte* tmp;
|
||||
|
||||
USER_DEBUG(("Entering wc_RsaPrivateDecryptInline\n"));
|
||||
|
||||
outSz = wc_RsaPrivateDecrypt(in, inLen, in, inLen, key);
|
||||
*out = in;
|
||||
/* allocate a buffer for max decrypted text */
|
||||
tmp = XMALLOC(key->sz, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
if (tmp == NULL)
|
||||
return USER_CRYPTO_ERROR;
|
||||
|
||||
outSz = wc_RsaPrivateDecrypt(in, inLen, tmp, key->sz, key);
|
||||
if (outSz >= 0) {
|
||||
XMEMCPY(in, tmp, outSz);
|
||||
*out = in;
|
||||
}
|
||||
else {
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
return USER_CRYPTO_ERROR;
|
||||
}
|
||||
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_ARRAYS);
|
||||
USER_DEBUG(("\tExit wc_RsaPrivateDecryptInline\n"));
|
||||
|
||||
return outSz;
|
||||
|
@@ -161,6 +161,8 @@ enum {
|
||||
KEYUSAGE_E = -226, /* Bad Key Usage value */
|
||||
CERTPOLICIES_E = -227, /* setting Certificate Policies error */
|
||||
|
||||
WC_FAILURE_E = -228, /* wolfcrypt failed to initialize */
|
||||
|
||||
MIN_CODE_E = -300 /* errors -101 - -299 */
|
||||
};
|
||||
|
||||
|
@@ -169,6 +169,8 @@ WOLFSSL_LOCAL int FreeMutex(wolfSSL_Mutex*);
|
||||
WOLFSSL_LOCAL int LockMutex(wolfSSL_Mutex*);
|
||||
WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*);
|
||||
|
||||
/* main crypto initialization function */
|
||||
WOLFSSL_API int wolfcrypt_Init(void);
|
||||
|
||||
/* filesystem abstraction layer, used by ssl.c */
|
||||
#ifndef NO_FILESYSTEM
|
||||
|
Reference in New Issue
Block a user