ARMmbed / ARMmbed/mbed-crypto

Maintenance: Use `offsetof()` instead of manual offset calculation

Open
#120 1 comment 0 reactions 0 assignees View on GitHub
enhancement Jira status: OPEN mirrored type: enhancement
Dominant language
C
Stars
108
Forks
95
PR merge metrics
No merged PRs in 30d

Description

### 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

Contributor guide

Open the contributing guide

Research direction

Start at psa_parse_key_data_from_storage() and inspect the manual offset use shown in the issue, including the GET_UINT32_LE call. Review the existing tests for struct padding and storage parsing; done means the relevant manual struct offsets use offsetof() and those tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cryptography
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.