Public / private distinction in crypto.h, crypto_values.h, crypto_struct.h #339

Open
opened 2019-12-23 17:32:11 -06:00 by laurencelundblade · 2 comments
laurencelundblade commented 2019-12-23 17:32:11 -06:00 (Migrated from github.com)

Description

It seems clear that everything in crypto.h is public interface and can be depended on when using the PSA Crypto API, but it is not clear for the other files like crypto_values.h and crypto_struct.h.

For example it seems like most of crypto_values.h is public which makes you think the same is true for crypto_struct.h, but it's not. The internals of struct psa_hash_operation_s are clearly private and depend on how MBed works. It is different in the MBed in TF-M than it is in the source in this repository (and that seems perfectly OK).

Since C doesn't allow you to hide stuff in headers, the way to address this is to clearly label stuff that is private in a comment. Here's an example:

struct _QCBOREncodeContext {
   // PRIVATE DATA STRUCTURE
   UsefulOutBuf      OutBuf;  // Pointer to output buffer, its length and
                              // position in it
   uint8_t           uError;  // Error state, always from QCBORError enum
   QCBORTrackNesting nesting; // Keep track of array and map nesting
};

I noticed this when I started to write code against the internal of crypto_struct.h and then saw the difference between this repository and TF-M.

Issue request type

[ ] Question
[X] Enhancement
[ ] Bug
<!-- ************************************** WARNING ************************************** The ciarcom bot parses this header automatically. Any deviation from the template may cause the bot to automatically correct this header or may result in a warning message, requesting updates. Please ensure that nothing follows the Issue request type section, all issue details are within the Description section and no changes are made to the template format (as detailed below). ************************************************************************************* --> ### Description It seems clear that everything in crypto.h is public interface and can be depended on when using the PSA Crypto API, but it is not clear for the other files like crypto_values.h and crypto_struct.h. For example it seems like most of crypto_values.h is public which makes you think the same is true for crypto_struct.h, but it's not. The internals of `struct psa_hash_operation_s` are clearly private and depend on how MBed works. It is different in the MBed in TF-M than it is in the source in this repository (and that seems perfectly OK). Since C doesn't allow you to hide stuff in headers, the way to address this is to clearly label stuff that is private in a comment. Here's an example: ``` struct _QCBOREncodeContext { // PRIVATE DATA STRUCTURE UsefulOutBuf OutBuf; // Pointer to output buffer, its length and // position in it uint8_t uError; // Error state, always from QCBORError enum QCBORTrackNesting nesting; // Keep track of array and map nesting }; ``` I noticed this when I started to write code against the internal of crypto_struct.h and then saw the difference between this repository and TF-M. <!-- Required Add detailed description of what you are reporting. Good example: https://os.mbed.com/docs/latest/reference/workflow.html Things to consider sharing: - What target does this relate to? - What toolchain (name + version) are you using? - What tools (name + version - is it mbed-cli, online compiler or IDE) are you using? - What is the SHA of Mbed OS (git log -n1 --oneline)? - Steps to reproduce. (Did you publish code or a test case that exhibits the problem?) --> ### Issue request type <!-- Required Please add only one X to one of the following types. Do not fill multiple types (split the issue otherwise.) Please note this is not a GitHub task list, indenting the boxes or changing the format to add a '.' or '*' in front of them would change the meaning incorrectly. The only changes to be made are to add a description text under the description heading and to add a 'x' to the correct box. --> [ ] Question [X] Enhancement [ ] Bug
ciarmcom commented 2019-12-24 00:44:54 -06:00 (Migrated from github.com)
*Internal Jira reference: https://jira.arm.com/browse/IOTCRYPT-1036*
gilles-peskine-arm commented 2020-03-11 04:52:56 -05:00 (Migrated from github.com)

I'm puzzled by what you're asking here. There's a comment at the top of the file that states that everything in that file is implementation-specific. Do you want us to repeat this comment on every single definition in the file?

I'm puzzled by what you're asking here. There's a comment at the top of the file that states that _everything_ in that file is implementation-specific. Do you want us to repeat this comment on every single definition in the file?
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#339
No description provided.