[Bug]: Wrong offset used for authentication tag comparison in KWE_AesAeadDecrypt
@KRASTM is already working on this.
Since Mar 26, 2026.
Assessment
This issue has not been assessed yet.
Description
Bug Summary
Authentication tag comparison in KWE_AesAeadDecrypt uses plaintext_size as offset instead of the actual ciphertext length.
Detailed Description
In KWE_AesAeadDecrypt the authentication tag generated by the hardware is compared with the tag contained in the input buffer using this line:
memcmp(check_tag, p_ciphertext + plaintext_size, tag_length)
plaintext_size is the size of the output buffer. It does not represent the length of the encrypted payload and therefore does not correspond to the start of the authentication tag in the input buffer.
The input buffer layout is:
ciphertext || tag
The correct tag position is therefore:
ciphertext_length - tag_length
If the output buffer is larger than the actual plaintext, the comparison may read from the wrong location or even outside the input buffer.
Suggested fix:
size_t cipher_length = ciphertext_length - tag_length;
memcmp(check_tag, p_ciphertext + cipher_length, tag_length)
Additionally, the returned plaintext length should reflect the actual decrypted data length:
*p_plaintext_length = cipher_length
Expected Behavior
The authentication tag should be compared against the tag located at the end of the ciphertext buffer.
Actual Behavior
The code uses plaintext_size as the offset, which may point to the wrong location if the output buffer is larger than the ciphertext.
Environment
STM32U385 KWE
Severity
Normal
- Dominant language
- C
- Stars
- 7
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ARM-software/CMSIS-DSP#354 ·
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ai-quokka-wannabe/link#40 ·
-
Add `pdfcpu` to the pantryPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
eunomia-bpf/agentsight#240 ·
Maintainers usually reply within 1 day