Fix padding control: EVP_CipherUpdate

This commit is contained in:
Takashi Kojo
2017-02-07 11:22:11 +09:00
committed by Jacob Barthelmeh
parent 150481699f
commit 734e728fba
2 changed files with 15 additions and 8 deletions

View File

@@ -26714,7 +26714,7 @@ int wolfSSL_DH_generate_parameters_ex(WOLFSSL_DH* dh, int prime_len, int generat
void wolfSSL_ERR_load_crypto_strings(void) void wolfSSL_ERR_load_crypto_strings(void)
{ {
WOLFSSL_ENTER("wolfSSL_ERR_load_crypto_strings"); WOLFSSL_ENTER("wolfSSL_ERR_load_crypto_strings");
WOLFSSL_ENTER("wolfSSL_ERR_load_crypto_strings"); WOLFSSL_STUB("wolfSSL_ERR_load_crypto_strings");
return; return;
} }

View File

@@ -309,7 +309,7 @@ WOLFSSL_API int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
*outl+= ctx->block_size; *outl+= ctx->block_size;
out += ctx->block_size; out += ctx->block_size;
} }
if ((ctx->bufUsed == ctx->block_size) || (ctx->flags & WOLFSSL_EVP_CIPH_NO_PADDING)){ if (ctx->bufUsed == ctx->block_size){
/* the buff is full, flash out */ /* the buff is full, flash out */
PRINT_BUF(ctx->buf, ctx->block_size); PRINT_BUF(ctx->buf, ctx->block_size);
if (evpCipherBlock(ctx, out, ctx->buf, ctx->block_size) == 0) if (evpCipherBlock(ctx, out, ctx->buf, ctx->block_size) == 0)
@@ -328,16 +328,23 @@ WOLFSSL_API int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
blocks = inl / ctx->block_size; blocks = inl / ctx->block_size;
if (blocks > 0) { if (blocks > 0) {
/* process blocks */ /* process blocks */
if (evpCipherBlock(ctx, out, in, blocks*ctx->block_size) == 0) if (evpCipherBlock(ctx, out, in, blocks * ctx->block_size) == 0)
return 0; return 0;
PRINT_BUF(ctx->buf, ctx->block_size); PRINT_BUF(in, ctx->block_size);
PRINT_BUF(out, ctx->block_size); PRINT_BUF(out,ctx->block_size);
inl -= ctx->block_size * blocks; inl -= ctx->block_size * blocks;
in += ctx->block_size * blocks; in += ctx->block_size * blocks;
if(ctx->enc == 0){ if(ctx->enc == 0){
if ((ctx->flags & WOLFSSL_EVP_CIPH_NO_PADDING) ||
((inl % ctx->block_size) == 0)){
ctx->lastUsed = 0;
XMEMCPY(ctx->lastBlock, &out[ctx->block_size * blocks], ctx->block_size);
*outl+= ctx->block_size * blocks;
} else {
ctx->lastUsed = 1; ctx->lastUsed = 1;
XMEMCPY(ctx->lastBlock, &out[ctx->block_size * (blocks-1)], ctx->block_size); XMEMCPY(ctx->lastBlock, &out[ctx->block_size * (blocks-1)], ctx->block_size);
*outl+= ctx->block_size * (blocks-1); *outl+= ctx->block_size * (blocks-1);
}
} else { } else {
*outl+= ctx->block_size * blocks; *outl+= ctx->block_size * blocks;
} }