From: Chenghai Huang huangchenghai2@huawei.com
In the decrypted filled data update process, the input size will be zero when the input size is smaller than the block size. As a result, an error message indicating that the output size is 0 is reported by UDAK.
Therefore, it need to check whether the input length is 0 before UADK encryption/decryption.
In addition, if the input length is greater than 0 and smaller than the block size, that is, the length of the data currently to be processed is 0, the data needs to be cached in the buffer through ossl_cipher_trailingdata() and sent to the next step.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com Signed-off-by: JiangShui Yang yangjiangshui@h-partners.com --- src/uadk_prov_cipher.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index 7188954..53ff589 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -679,28 +679,28 @@ static int uadk_prov_do_cipher(struct cipher_priv_ctx *priv, unsigned char *out, out += blksz; }
- if (nextblocks > 0) { - if (!priv->enc && priv->pad && nextblocks == inlen) - nextblocks -= blksz; - outlint += nextblocks; - } + if (nextblocks == 0) + goto out; + + if (!priv->enc && priv->pad && nextblocks == inlen) + nextblocks -= blksz;
if (nextblocks > 0) { ret = uadk_prov_hw_cipher(priv, out, outl, outsize, in, nextblocks); if (ret != UADK_E_SUCCESS) { - fprintf(stderr, "do hw ciphers failed.\n"); + fprintf(stderr, "last block do hw ciphers failed.\n"); if (priv->sw_cipher) goto do_soft; return ret; }
+ outlint += nextblocks; in += nextblocks; inlen -= nextblocks; } - - if (inlen != 0 - && !ossl_cipher_trailingdata(priv->buf, &priv->bufsz, - blksz, &in, &inlen)) +out: + if (inlen != 0 && !ossl_cipher_trailingdata(priv->buf, + &priv->bufsz, blksz, &in, &inlen)) return UADK_E_FAIL;
*outl = outlint;