Skip to content

Conversation

@tretter
Copy link
Contributor

@tretter tretter commented Oct 9, 2025

The size of the buffer that is used to persist the HUK in the OTP and the size of the buffer that is used to read the HUK from the OTP must have the same size as the HUK key data.

Add a static_assert to ensure that this is actually the case.

Suggested by @etienne-lms in #7545 (comment).

The size of the buffer that is used to persist the HUK in the OTP and
the size of the buffer that is used to read the HUK from the OTP must
have the same size as the HUK key data.

Add a static_assert to ensure that this is actually the case.

Signed-off-by: Michael Tretter <[email protected]>
{
TEE_Result res = TEE_SUCCESS;
uint32_t buffer[ROCKCHIP_OTP_HUK_SIZE] = { };
static_assert(sizeof(buffer) == sizeof(hwkey->data));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an empty line above to separate from variable definitions.

Suggestion:

	TEE_Result res = TEE_SUCCESS;
	uint32_t buffer[ROCKCHIP_OTP_HUK_SIZE] = { };

	static_assert(sizeof(buffer) == sizeof(hwkey->data));
	memcpy(buffer, hwkey->data, HW_UNIQUE_KEY_LENGTH);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I was putting the static_assert next to the memcpy, too. In this case, the compiler is warning about mixing declarations and code. (In this instance, the compiler is not warning, because the static_assert is still above the code, but in read_huk it's not.) I didn't look deeper into the macro expansion, but it seems that static_assert somehow expands to a declaration.

Should I ignore the compiler warning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants