forked from wolfSSL/wolfssl
Merge pull request #5432 from embhorn/zd14172
Fix dead code warnings and build error
This commit is contained in:
@ -542,17 +542,14 @@ static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx,
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return WOLFSSL_FAILURE;
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
return WOLFSSL_FAILURE; /* failure */
|
||||
|
||||
(void)in;
|
||||
(void)inl;
|
||||
(void)out;
|
||||
|
||||
return WOLFSSL_SUCCESS; /* success */
|
||||
return (ret == 0) ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
|
||||
}
|
||||
|
||||
#if defined(HAVE_AESGCM)
|
||||
@ -5689,7 +5686,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
||||
|
||||
#if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || \
|
||||
defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_CFB) || \
|
||||
defined(WOLFSSL_AES_OFB)
|
||||
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_DIRECT)
|
||||
#define AES_SET_KEY
|
||||
#endif
|
||||
|
||||
|
@ -395,7 +395,7 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
int derivedLen = 0;
|
||||
int ret = 0;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
byte* key;
|
||||
byte* key = NULL;
|
||||
#else
|
||||
byte key[PKCS_MAX_KEY_SIZE];
|
||||
#endif
|
||||
@ -481,14 +481,18 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
default:
|
||||
WOLFSSL_MSG("Unknown/Unsupported encrypt/decrypt id");
|
||||
(void)shaOid;
|
||||
return ALGO_ID_E;
|
||||
ret = ALGO_ID_E;
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
if (ret == 0) {
|
||||
key = (byte*)XMALLOC(PKCS_MAX_KEY_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (key == NULL)
|
||||
return MEMORY_E;
|
||||
ret = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ret == 0) {
|
||||
#ifdef WOLFSSL_CHECK_MEM_ZERO
|
||||
wc_MemZero_Add("wc_CryptKey key", key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
@ -513,13 +517,8 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
byte unicodePasswd[MAX_UNICODE_SZ];
|
||||
|
||||
if ( (passwordSz * 2 + 2) > (int)sizeof(unicodePasswd)) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return UNICODE_SIZE_E;
|
||||
ret = UNICODE_SIZE_E;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < passwordSz; i++) {
|
||||
@ -533,33 +532,19 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
ret = wc_PKCS12_PBKDF(key, unicodePasswd, idx, salt, saltSz,
|
||||
iterations, derivedLen, typeH, 1);
|
||||
if (id != PBE_SHA1_RC4_128) {
|
||||
ret += wc_PKCS12_PBKDF(cbcIv, unicodePasswd, idx, salt, saltSz,
|
||||
iterations, 8, typeH, 2);
|
||||
ret += wc_PKCS12_PBKDF(cbcIv, unicodePasswd, idx, salt,
|
||||
saltSz, iterations, 8, typeH, 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* HAVE_PKCS12 */
|
||||
default:
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
WOLFSSL_MSG("Unknown/Unsupported PKCS version");
|
||||
return ALGO_ID_E;
|
||||
ret = ALGO_ID_E;
|
||||
} /* switch (version) */
|
||||
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
switch (id) {
|
||||
#ifndef NO_DES3
|
||||
#if !defined(NO_SHA) || !defined(NO_MD5)
|
||||
@ -578,22 +563,14 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
else {
|
||||
ret = wc_Des_SetKey(&des, key, desIv, DES_DECRYPTION);
|
||||
}
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
if (enc) {
|
||||
wc_Des_CbcEncrypt(&des, input, input, length);
|
||||
}
|
||||
else {
|
||||
wc_Des_CbcDecrypt(&des, input, input, length);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* !NO_SHA || !NO_MD5 */
|
||||
@ -609,13 +586,7 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
|
||||
ret = wc_Des3Init(&des, NULL, INVALID_DEVID);
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
if (enc) {
|
||||
ret = wc_Des3_SetKey(&des, key, desIv, DES_ENCRYPTION);
|
||||
@ -623,32 +594,15 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
else {
|
||||
ret = wc_Des3_SetKey(&des, key, desIv, DES_DECRYPTION);
|
||||
}
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
wc_Des3Free(&des);
|
||||
return ret;
|
||||
}
|
||||
if (ret == 0) {
|
||||
if (enc) {
|
||||
ret = wc_Des3_CbcEncrypt(&des, input, input, length);
|
||||
}
|
||||
else {
|
||||
ret = wc_Des3_CbcDecrypt(&des, input, input, length);
|
||||
}
|
||||
wc_Des3Free(&des);
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
wc_Des3Free(&des);
|
||||
break;
|
||||
}
|
||||
#endif /* !NO_SHA */
|
||||
@ -673,8 +627,10 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
Aes *aes;
|
||||
aes = (Aes *)XMALLOC(sizeof *aes, NULL, DYNAMIC_TYPE_AES);
|
||||
if (aes == NULL)
|
||||
return MEMORY_E;
|
||||
if (aes == NULL) {
|
||||
ret = MEMORY_E;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
Aes aes[1];
|
||||
#endif
|
||||
@ -703,15 +659,6 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
@ -728,37 +675,30 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
|
||||
else
|
||||
ret = wc_Rc2CbcDecrypt(&rc2, input, input, length);
|
||||
}
|
||||
if (ret != 0) {
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
if (ret == 0) {
|
||||
ForceZero(&rc2, sizeof(Rc2));
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
WOLFSSL_MSG("Unknown/Unsupported encrypt/decryption algorithm");
|
||||
return ALGO_ID_E;
|
||||
ret = ALGO_ID_E;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
if (key != NULL)
|
||||
#endif
|
||||
{
|
||||
ForceZero(key, PKCS_MAX_KEY_SIZE);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
|
||||
wc_MemZero_Check(key, PKCS_MAX_KEY_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user