Fixes for GCC 7 build errors with evp.c and switch fall through. General EVP code formatting cleanup. Fix for wolfCrypt test un-used var when HAVE_AES_CBC not defined. Fix for async in test_wolfSSL_SESSION with err not being initialized.

This commit is contained in:
David Garske
2018-02-16 09:32:40 -08:00
parent 74ebf510a3
commit ae5dac8994
3 changed files with 83 additions and 76 deletions

View File

@@ -15919,6 +15919,7 @@ static void test_wolfSSL_SESSION(void)
tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl); tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
AssertIntEQ(wolfSSL_set_fd(ssl, sockfd), SSL_SUCCESS); AssertIntEQ(wolfSSL_set_fd(ssl, sockfd), SSL_SUCCESS);
err = 0; /* Reset error */
do { do {
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT
if (err == WC_PENDING_E) { if (err == WC_PENDING_E) {
@@ -15927,7 +15928,6 @@ static void test_wolfSSL_SESSION(void)
} }
#endif #endif
err = 0; /* Reset error */
ret = wolfSSL_connect(ssl); ret = wolfSSL_connect(ssl);
if (ret != SSL_SUCCESS) { if (ret != SSL_SUCCESS) {
err = wolfSSL_get_error(ssl, 0); err = wolfSSL_get_error(ssl, 0);

View File

@@ -205,7 +205,8 @@ WOLFSSL_API int wolfSSL_EVP_DigestInit_ex(WOLFSSL_EVP_MD_CTX* ctx,
} }
#ifdef DEBUG_WOLFSSL_EVP #ifdef DEBUG_WOLFSSL_EVP
#define PRINT_BUF(b, sz) { int _i; for(_i=0; _i<(sz); _i++){printf("%02x(%c),", (b)[_i], (b)[_i]); if((_i+1)%8==0)printf("\n");}} #define PRINT_BUF(b, sz) { int _i; for(_i=0; _i<(sz); _i++) { \
printf("%02x(%c),", (b)[_i], (b)[_i]); if ((_i+1)%8==0)printf("\n");}}
#else #else
#define PRINT_BUF(b, sz) #define PRINT_BUF(b, sz)
#endif #endif
@@ -415,7 +416,8 @@ WOLFSSL_API int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
} }
if (ctx->enc) { if (ctx->enc) {
if (ctx->block_size == 1) { if (ctx->block_size == 1) {
*outl = 0; return WOLFSSL_SUCCESS; *outl = 0;
return WOLFSSL_SUCCESS;
} }
if ((ctx->bufUsed >= 0) && (ctx->block_size != 1)) { if ((ctx->bufUsed >= 0) && (ctx->block_size != 1)) {
padBlock(ctx); padBlock(ctx);
@@ -428,7 +430,8 @@ WOLFSSL_API int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
} }
} else { } else {
if (ctx->block_size == 1) { if (ctx->block_size == 1) {
*outl = 0; return WOLFSSL_SUCCESS; *outl = 0;
return WOLFSSL_SUCCESS;
} }
if (ctx->lastUsed) { if (ctx->lastUsed) {
PRINT_BUF(ctx->lastBlock, ctx->block_size); PRINT_BUF(ctx->lastBlock, ctx->block_size);
@@ -713,7 +716,7 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_decrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
case EVP_PKEY_RSA: case EVP_PKEY_RSA:
len = wolfSSL_RSA_private_decrypt((int)inlen, (unsigned char*)in, out, len = wolfSSL_RSA_private_decrypt((int)inlen, (unsigned char*)in, out,
ctx->pkey->rsa, ctx->padding); ctx->pkey->rsa, ctx->padding);
if(len < 0)return 0; if (len < 0) break;
else { else {
*outlen = len; *outlen = len;
return WOLFSSL_SUCCESS; return WOLFSSL_SUCCESS;
@@ -722,10 +725,11 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_decrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
case EVP_PKEY_EC: case EVP_PKEY_EC:
WOLFSSL_MSG("not implemented"); WOLFSSL_MSG("not implemented");
/* not implemented */ FALL_THROUGH;
default: default:
return WOLFSSL_FAILURE; break;
} }
return WOLFSSL_FAILURE;
} }
@@ -743,14 +747,13 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_decrypt_init(WOLFSSL_EVP_PKEY_CTX *ctx)
case EVP_PKEY_RSA: case EVP_PKEY_RSA:
ctx->op = EVP_PKEY_OP_DECRYPT; ctx->op = EVP_PKEY_OP_DECRYPT;
return WOLFSSL_SUCCESS; return WOLFSSL_SUCCESS;
case EVP_PKEY_EC: case EVP_PKEY_EC:
WOLFSSL_MSG("not implemented"); WOLFSSL_MSG("not implemented");
/* not implemented */ FALL_THROUGH;
default: default:
break;
return WOLFSSL_FAILURE;
} }
return WOLFSSL_FAILURE;
} }
@@ -783,7 +786,8 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
case EVP_PKEY_RSA: case EVP_PKEY_RSA:
len = wolfSSL_RSA_public_encrypt((int)inlen, (unsigned char *)in, out, len = wolfSSL_RSA_public_encrypt((int)inlen, (unsigned char *)in, out,
ctx->pkey->rsa, ctx->padding); ctx->pkey->rsa, ctx->padding);
if (len < 0) return WOLFSSL_FAILURE; if (len < 0)
break;
else { else {
*outlen = len; *outlen = len;
return WOLFSSL_SUCCESS; return WOLFSSL_SUCCESS;
@@ -792,10 +796,11 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
case EVP_PKEY_EC: case EVP_PKEY_EC:
WOLFSSL_MSG("not implemented"); WOLFSSL_MSG("not implemented");
/* not implemented */ FALL_THROUGH;
default: default:
return WOLFSSL_FAILURE; break;
} }
return WOLFSSL_FAILURE;
} }
@@ -816,12 +821,11 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt_init(WOLFSSL_EVP_PKEY_CTX *ctx)
return WOLFSSL_SUCCESS; return WOLFSSL_SUCCESS;
case EVP_PKEY_EC: case EVP_PKEY_EC:
WOLFSSL_MSG("not implemented"); WOLFSSL_MSG("not implemented");
/* not implemented */ FALL_THROUGH;
default: default:
break;
return WOLFSSL_FAILURE;
} }
return WOLFSSL_FAILURE;
} }
@@ -860,18 +864,19 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_size(WOLFSSL_EVP_PKEY *pkey)
return (int)wolfSSL_RSA_size((const WOLFSSL_RSA*)(pkey->rsa)); return (int)wolfSSL_RSA_size((const WOLFSSL_RSA*)(pkey->rsa));
#endif /* NO_RSA */ #endif /* NO_RSA */
case EVP_PKEY_EC:
#ifdef HAVE_ECC #ifdef HAVE_ECC
case EVP_PKEY_EC:
if (pkey->ecc == NULL || pkey->ecc->internal == NULL) { if (pkey->ecc == NULL || pkey->ecc->internal == NULL) {
WOLFSSL_MSG("No ECC key has been set"); WOLFSSL_MSG("No ECC key has been set");
return 0; break;
} }
return wc_ecc_size((ecc_key*)(pkey->ecc->internal)); return wc_ecc_size((ecc_key*)(pkey->ecc->internal));
#endif /* HAVE_ECC */ #endif /* HAVE_ECC */
default: default:
return 0; break;
} }
return 0;
} }
@@ -932,7 +937,8 @@ static int md2nid(int md)
return NID_sha1; return NID_sha1;
} }
} }
if(XSTRNCMP(d, "MD5", 3) == 0)return NID_md5; if (XSTRNCMP(d, "MD5", 3) == 0)
return NID_md5;
return 0; return 0;
} }
#endif /* NO_RSA */ #endif /* NO_RSA */
@@ -963,10 +969,9 @@ WOLFSSL_API int wolfSSL_EVP_SignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *si
switch (pkey->type) { switch (pkey->type) {
#if !defined(NO_RSA) && !defined(HAVE_USER_RSA) #if !defined(NO_RSA) && !defined(HAVE_USER_RSA)
case EVP_PKEY_RSA: case EVP_PKEY_RSA: {
{
int nid = md2nid(ctx->macType); int nid = md2nid(ctx->macType);
if (nid < 0) return WOLFSSL_FAILURE; if (nid < 0) break;
return wolfSSL_RSA_sign(nid, md, mdsize, sigret, return wolfSSL_RSA_sign(nid, md, mdsize, sigret,
siglen, pkey->rsa); siglen, pkey->rsa);
} }
@@ -975,10 +980,11 @@ WOLFSSL_API int wolfSSL_EVP_SignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *si
case EVP_PKEY_DSA: case EVP_PKEY_DSA:
case EVP_PKEY_EC: case EVP_PKEY_EC:
WOLFSSL_MSG("not implemented"); WOLFSSL_MSG("not implemented");
/* not implemented */ FALL_THROUGH;
default: default:
return WOLFSSL_FAILURE; break;
} }
return WOLFSSL_FAILURE;
} }
@@ -1041,7 +1047,7 @@ WOLFSSL_API int wolfSSL_EVP_VerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
#if !defined(NO_RSA) && !defined(HAVE_USER_RSA) #if !defined(NO_RSA) && !defined(HAVE_USER_RSA)
case EVP_PKEY_RSA: { case EVP_PKEY_RSA: {
int nid = md2nid(ctx->macType); int nid = md2nid(ctx->macType);
if (nid < 0) return WOLFSSL_FAILURE; if (nid < 0) break;
return wolfSSL_RSA_verify(nid, md, mdsize, sig, return wolfSSL_RSA_verify(nid, md, mdsize, sig,
(unsigned int)siglen, pkey->rsa); (unsigned int)siglen, pkey->rsa);
} }
@@ -1050,10 +1056,11 @@ WOLFSSL_API int wolfSSL_EVP_VerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
case EVP_PKEY_DSA: case EVP_PKEY_DSA:
case EVP_PKEY_EC: case EVP_PKEY_EC:
WOLFSSL_MSG("not implemented"); WOLFSSL_MSG("not implemented");
/* not implemented */ FALL_THROUGH;
default: default:
return 0; break;
} }
return WOLFSSL_FAILURE;
} }
WOLFSSL_API int wolfSSL_EVP_add_cipher(const WOLFSSL_EVP_CIPHER *cipher) WOLFSSL_API int wolfSSL_EVP_add_cipher(const WOLFSSL_EVP_CIPHER *cipher)

View File

@@ -5894,7 +5894,7 @@ int aes256_test(void)
#endif /* HAVE_AES_CBC */ #endif /* HAVE_AES_CBC */
return 0; return ret;
} }