Support key file IDs encoding the key owner #59
No reviewers
Labels
No labels
api-spec
bug
CLA requested
CLA valid
compliance
DO NOT MERGE
duplicate
enhancement
feature branch
good first issue
HEADER FORMATTING ISSUE
help wanted
Information
invalid
Jira status: AWAITING REVIEW
Jira status: CLOSED
Jira status: DONE
Jira status: IN PROGRESS
Jira status: IN REVIEW
Jira status: OPEN
Jira status: REOPENED
Jira status: RESOLVED
mirrored
mirror internally
needs: backports
needs: ci
needs: design review
needs: preceding PR
needs: review
needs: work
notabug
open for community contribution
Product Backlog
question
ready for merge
security
stale
type: bug
type: enhancement
type: question
web pages
wontfix
writing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-ARMmbed/mbed-crypto!59
Loading…
Reference in a new issue
No description provided.
Delete branch "psa-its-64_bit_internal_key_id"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add support for key file identifier that encode the key owner. Use the type
psa_key_file_id_tto refer to key files, as opposed topsa_key_id_twhich is the key identifier specified by the application. The two types are identical except when building the library for a multi-client service (currently: only the PSA crypto service, under the build optionMBEDTLS_PSA_CRYPTO_SPM).Because
psa/crypto.handpsa/crypto_types.hare part of the source of the PSA Crypto API specification, use the standard types there. Definepsa_key_file_id_tinpsa/crypto_platform.hdepending on whetherMBEDTLS_PSA_CRYPTO_SPMis defined. We can make this cleaner by usingpsa_key_file_id_tinpsa/crypto.honce the specification is separated from the implementation.The file storage backend, and all of the tests, do not support
MBEDTLS_PSA_CRYPTO_SPM. I have manually checked that the build withMBEDTLS_PSA_CRYPTO_SPMandMBEDTLS_PSA_STORAGE_ITS_Cworks with dummypsa/error.handpsa/internal_trusted_storage.h. Testing without a board would require updating and mergin https://github.com/ARMmbed/mbedtls-psa/pull/204 .@ -52,0 +80,4 @@{uint32_t key_id;psa_key_owner_id_t owner;} psa_key_file_id_t;Not super important, but maybe the compiler will generate slightly more efficient code if this struct has the same binary representation as the UID we send to ITS.
Is changing
psa_key_id_ttopsa_key_file_id_teverywhere really the best option?If we keep this PR as-is and then do the following, we wouldn't require changing to
psa_key_file_id_teverywhere. Would this be a workable improvement?typedef uint32_t psa_key_id_t;from crypto_types.htypedef psa_app_key_id_t psa_key_id_tto crypto_platform.h for non-SPM platformsThen we'd have the following situation:
psa_key_file_id_taspsa_key_id_ton SPM platforms (what we sort of have in this PR now, but don't use it)psa_app_key_id_taspsa_key_id_ton non-SPM platformsMaybe there is a reason to keep defining psa_key_id_t in crypto_types.h that I'm not seeing. In which case, we can keep that as-is and actually use that type definition instead of
psa_key_file_id_teverywhere.@ -37,12 +36,31 @@#include "mbedtls/platform.h"Style: Add leasing
*on this line."the random seed file which have an identifier" parsing error. This should be "has"? But, that doesn't seem to have the right meaning. I don't believe the random seed file has an identifier in the range 0 through 0xffffffff.
Suggest adding commas and "for" like so:
key files don't clash with file names, such as for the random seed file, which have an identifier in the range 0..0xffffffff.Currently,
crypto_types.handcrypto.hare used to generate the specification, so they have to use the standard definitions. I wanted to minimize the incursion of MbedCrypto-specific stuff there.Once the specification and the implementation are fully split (which should take a couple of weeks), I think we should define
psa_key_file_id_tincrypto_types.hand use it incrypto.h.@ -52,0 +80,4 @@{uint32_t key_id;psa_key_owner_id_t owner;} psa_key_file_id_t;Indeed, putting the key id first saves a few instructions. From
make CC=arm-linux-gnueabi-gcc CFLAGS='-Os -mthumb'(not exactly v7m but should be close enough):I'm not fluent enough in arm assembly to explain the difference without spending more time than I care to right now.
@ -52,0 +80,4 @@{uint32_t key_id;psa_key_owner_id_t owner;} psa_key_file_id_t;I don't think it's so Arm specific. If the binary representation is the same, the program doesn't have to swap the order around before passing the 64-bit value on to ITS and may be able to use the binary representation as-is, assuming alignment works out and so forth.
Hi @gilles-peskine-arm, please see my comment.
@ -90,7 +90,14 @@ typedef uint32_t psa_key_lifetime_t;MBEDTLS_PSA_CRYPTO_SPMis defined for the entire secure side. This means that if another secure partition will try to communicate with crypto, this client will seepsa_key_id_tas the full struct (i.e.psa_key_file_id_t) as not asuint32_t.@ -90,7 +90,14 @@ typedef uint32_t psa_key_lifetime_t;This could work if the ifdefs in the header files are tested for
PSA_CRYPTO_SECUREinstead ofMBEDTLS_PSA_CRYPTO_SPM.@ -90,7 +90,14 @@ typedef uint32_t psa_key_lifetime_t;Ok, I'll change that.
I'm going to update this PR with a new commit history that splits up the original large commit that both renames
psa_key_id_tand adds owner-in-key-id support.@ -52,0 +60,4 @@* application, but also the the identity of the application.** Note that this is an internal concept of the library and the remote* call layer. The application itself never sees anything other thanStray leftover from a partial commit, I'll fix this in a rebase.
@ -37,12 +36,31 @@#include "mbedtls/platform.h"Fixed in the new history.
@ -37,12 +36,31 @@#include "mbedtls/platform.h"Reworded in the new history.
@ -52,0 +80,4 @@{uint32_t key_id;psa_key_owner_id_t owner;} psa_key_file_id_t;I put
key_idfirst in the rebased version. It's likely to be neutral or a tiny improvement on any little-endian platform. How much it saves depends on the ABI and of course on what the compiler makes of the code.I have pushed an updated version with a new, more granular history. The differences:
MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNERto gate the nonstandard definition ofpsa_key_file_id_t. This makes the code easier to follow than depending only onPSA_CRYPTO_SECURE. The crypto service must enable this option.PSA_CRYPTO_SECUREinstead ofMBEDTLS_PSA_CRYPTO_SPMto detect that the service is being built, as noted by Itay.psa_key_file_id_t.I made another, minor rebase to fix some issues reported by the CI:
config.hmust not have Doxygen formatting if it isn't enabled byscripts/config.pl all.generate_version_features.plafter adding an option toconfig.h.Previous history at https://github.com/gilles-peskine-arm/mbed-crypto/tree/psa-its-64_bit_internal_key_id-3
This needs CI to pass before we can merge it.
I fixed a typo in “Support encoding an owner in key file IDs” which should let the CI do its job.
Neither am I, but I'm even less a fan of writing
psa_key_id_twhere we mean something that isn't a key id.Actually, at that point, we'll change more occurrences of
psa_key_id_ttopsa_key_file_id_t, incrypto.h.I fixed another typo in “Support encoding an owner in key file IDs” which should let the CI do its job this time.
Minor style: Now the alignment is off, since
key_idandfile_iddon't have the name number of characters.library/psa_crypto_slot_management.c:192
Since I've been rebasing anyway, I'll rebase again to fix the alignment.
Aligned.
OK
LGTM