Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[Bug]: Wrong offset used for authentication tag comparison in KWE_AesAeadDecrypt

Open
#5 1 comment 0 reactions 1 assignee View on GitHub

@KRASTM is already working on this.

Since Mar 26, 2026.

Assessment

This issue has not been assessed yet.

Description

bug internal bug tracker kwe mw
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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.