Maintenance: Use offsetof() instead of manual offset calculation #120

Open
opened 2019-05-21 11:24:17 -05:00 by Patater · 1 comment
Patater commented 2019-05-21 11:24:17 -05:00 (Migrated from github.com)

Description

It's fragile to manually calculate offsets within structs like so, which the current code does in psa_parse_key_data_from_storage().

GET_UINT32_LE(policy->alg2, storage_format->policy, 2 * sizeof( uint32_t ));

We should instead look into using offsetof(). This will make the library more portable and easier to maintain. it's not likely to be "more correct", since we have tests that would catch these types of padding issues in this instance.

Issue request type

[ ] Question
[X] Enhancement
[ ] Bug
### Description It's fragile to manually calculate offsets within structs like so, which the current code does in `psa_parse_key_data_from_storage()`. ```GET_UINT32_LE(policy->alg2, storage_format->policy, 2 * sizeof( uint32_t ));``` We should instead look into using `offsetof()`. This will make the library more portable and easier to maintain. it's not likely to be "more correct", since we have tests that would catch these types of padding issues in this instance. ### Issue request type [ ] Question [X] Enhancement [ ] Bug
ciarmcom commented 2019-05-27 11:01:23 -05:00 (Migrated from github.com)

Internal Jira reference: https://jira.arm.com/browse/IOTCRYPT-782

*Internal Jira reference: https://jira.arm.com/browse/IOTCRYPT-782*
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-ARMmbed/mbed-crypto#120
No description provided.