Fix aes_cbc_padding_decrypt bug

This commit is contained in:
Zhi Guan
2026-06-01 15:16:35 +08:00
parent 57c9433cc9
commit ec1ec5988a

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved. * Copyright 2014-2026 The GmSSL Project. All Rights Reserved.
* *
* Licensed under the Apache License, Version 2.0 (the License); you may * Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License. * not use this file except in compliance with the License.
@@ -71,6 +71,7 @@ int aes_cbc_padding_decrypt(const AES_KEY *key, const uint8_t iv[16],
uint8_t block[16]; uint8_t block[16];
size_t len = sizeof(block); size_t len = sizeof(block);
int padding; int padding;
int i;
if (inlen == 0) { if (inlen == 0) {
error_print(); error_print();
@@ -90,6 +91,11 @@ int aes_cbc_padding_decrypt(const AES_KEY *key, const uint8_t iv[16],
error_print(); error_print();
return -1; return -1;
} }
for (i = 16 - padding; i < 16; i++) {
error_print();
return -1;
}
len -= padding; len -= padding;
memcpy(out + inlen - 16, block, len); memcpy(out + inlen - 16, block, len);
*outlen = inlen - padding; *outlen = inlen - padding;