mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-29 18:27:29 +02:00
EVP decrypt with padding fix
This commit is contained in:
@ -430,6 +430,11 @@ WOLFSSL_API int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
|
||||
*outl = 0;
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
if ((ctx->bufUsed % ctx->block_size) != 0) {
|
||||
*outl = 0;
|
||||
/* not enough padding for decrypt */
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
if (ctx->lastUsed) {
|
||||
PRINT_BUF(ctx->lastBlock, ctx->block_size);
|
||||
if ((fl = checkPad(ctx, ctx->lastBlock)) >= 0) {
|
||||
|
@ -13399,32 +13399,44 @@ int openssl_test(void)
|
||||
if (EVP_CipherInit(&ctx, EVP_aes_128_cbc(), key, iv, 0) == 0)
|
||||
return -7417;
|
||||
|
||||
if (EVP_CipherUpdate(&ctx, plain, &idx, cipher, cipherSz) == 0)
|
||||
/* check partial decrypt (not enough padding for full block) */
|
||||
if (EVP_CipherUpdate(&ctx, plain, &idx, cipher, 1) == 0)
|
||||
return -7418;
|
||||
|
||||
plainSz = idx;
|
||||
if (EVP_CipherFinal(&ctx, plain + plainSz, &idx) == 0)
|
||||
if (EVP_CipherFinal(&ctx, plain + plainSz, &idx) != 0)
|
||||
return -7419;
|
||||
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
if (EVP_CipherInit(&ctx, EVP_aes_128_cbc(), key, iv, 0) == 0)
|
||||
return -7420;
|
||||
|
||||
if (EVP_CipherUpdate(&ctx, plain, &idx, cipher, cipherSz) == 0)
|
||||
return -7421;
|
||||
|
||||
plainSz = idx;
|
||||
if (EVP_CipherFinal(&ctx, plain + plainSz, &idx) == 0)
|
||||
return -7422;
|
||||
plainSz += idx;
|
||||
|
||||
if ((plainSz != sizeof(msg)) || XMEMCMP(plain, msg, sizeof(msg)))
|
||||
return -7420;
|
||||
return -7423;
|
||||
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
if (EVP_CipherInit(&ctx, EVP_aes_128_cbc(), key, iv, 1) == 0)
|
||||
return -7421;
|
||||
return -7424;
|
||||
|
||||
if (EVP_CipherUpdate(&ctx, cipher, &idx, msg, AES_BLOCK_SIZE) == 0)
|
||||
return -7422;
|
||||
return -7425;
|
||||
|
||||
cipherSz = idx;
|
||||
if (EVP_CipherFinal(&ctx, cipher + cipherSz, &idx) == 0)
|
||||
return -7423;
|
||||
return -7426;
|
||||
cipherSz += idx;
|
||||
|
||||
if ((cipherSz != (int)sizeof(verify2)) ||
|
||||
XMEMCMP(cipher, verify2, cipherSz))
|
||||
return -7424;
|
||||
return -7427;
|
||||
|
||||
} /* end evp_cipher test: EVP_aes_128_cbc*/
|
||||
#endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
|
||||
|
Reference in New Issue
Block a user