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