Return max *outlen in SM4 CTX update/finish

This commit is contained in:
Zhi Guan
2024-05-11 15:05:27 +08:00
parent cd5cb85592
commit 2c125fbaa5
6 changed files with 135 additions and 12 deletions

View File

@@ -32,10 +32,14 @@ int sm4_ecb_encrypt_update(SM4_ECB_CTX *ctx,
size_t nblocks;
size_t len;
if (!ctx || !in || !out || !outlen) {
if (!ctx || !in || !outlen) {
error_print();
return -1;
}
if (!out) {
*outlen = 16 * ((inlen + 15)/16);
return 1;
}
if (ctx->block_nbytes >= SM4_BLOCK_SIZE) {
error_print();
return -1;
@@ -77,6 +81,10 @@ int sm4_ecb_encrypt_finish(SM4_ECB_CTX *ctx, uint8_t *out, size_t *outlen)
error_print();
return -1;
}
if (!out) {
*outlen = SM4_BLOCK_SIZE; // anyway, caller should prepare a block buffer to support any length input
return 1;
}
if (ctx->block_nbytes >= SM4_BLOCK_SIZE) {
error_print();
return -1;