-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring of pkcs11_store.c module #481
Conversation
Awaiting feedback (zd18366) |
src/pkcs11_store.c
Outdated
obj = vault_descriptors[found]; | ||
memcpy(&obj->hdr, vault_base + found * KEYVAULT_OBJ_SIZE, sizeof(struct obj_hdr)); | ||
} | ||
obj = XMALLOC(sizeof(struct store_object), NULL, DYNAMIC_TYPE_TMP_BUFFER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider cast (struct store_object*)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XMALLOC is gone now
src/pkcs11_store.c
Outdated
memcpy(&obj->hdr, vault_base + found * KEYVAULT_OBJ_SIZE, sizeof(struct obj_hdr)); | ||
} | ||
obj = XMALLOC(sizeof(struct store_object), NULL, DYNAMIC_TYPE_TMP_BUFFER); | ||
if (!obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer obj == NULL
... thus not assuming NULL == 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
src/pkcs11_store.c
Outdated
obj = vault_descriptors[found]; | ||
memcpy(&obj->hdr, vault_base + found * KEYVAULT_OBJ_SIZE, sizeof(struct obj_hdr)); | ||
} | ||
obj = XMALLOC(sizeof(struct store_object), NULL, DYNAMIC_TYPE_TMP_BUFFER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider version that doesn't require heap..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the dynamic allocation in the last refactoring, however it seems that wolfPKCS11 still requires a heap, so I re-introduced the _sbrk in the designated pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, since wolfPKCS11 uses its own area, this heap can be in a bank that is securely erased on powerdown
997847b
to
5b9278d
Compare
5b9278d
to
7384289
Compare
ac83256
to
ec8ad08
Compare
Ready to review |
f7704eb
to
6737d7e
Compare
pkcs11_store.c
This new design uses two sectors at the beginning of the keyvault partition.
The first sector contains the allocation tables for the nodes in flash, including
a bitmap to keep track of the free slots.
The second sector is a pre-commit 'backup' sector, used to update the content of the
vault in two steps. This guarantees powerfail protection.
All hal_flash_erase / hal_flash_write operations are now on entire sectors.
Sector content is cached to memory, then written to the backup sector, then
committed to the actual destination sector.