Skip to content

Conversation

@Patater
Copy link
Contributor

@Patater Patater commented Nov 7, 2019

It was not obvious before that AES_KEY and RSA_KEY were shorthand
for key material. A user copy pasting the code snippet would run into a
compilation error if they didn't realize this. Make it more obvious that
key material must come from somewhere external by making the snippets
which use global keys into functions that take a key as a parameter.

Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example which is not targeted for very low-end platforms (if it was, it would use ECC, not RSA). Please don't include workarounds for platform limitations in such code.

@Patater
Copy link
Contributor Author

Patater commented Nov 7, 2019

This is a portability enhancement, not a workaround.

Yes, we should use ECDSA here and also in the Mbed OS example. It's not this PR's aim to change this. Another PR should do so.

This PR's aim is to help ensure we test the code snippets in our docs. The only testing our getting started doc currently has is the Mbed OS example. For ease of maintenance, as much as is possible, it's preferred to have parity between what we test and run in the Mbed OS example and what we list as code snippets in our docs. The ideal would be we run our getting started guide as a sort of literate program ala Knuth (which is out of scope for this PR), rather than copy pasting to an Mbed OS example for testing.

@gilles-peskine-arm
Copy link
Collaborator

No. Adding extra code to declare a non-standard scope variables has no place in example code. It's an additional cognitive burden. The example code needs to be easy to understand, not maximally portable.

It was not obvious before that `AES_KEY` and `RSA_KEY` were shorthand
for key material. A user copy pasting the code snippet would run into a
compilation error if they didn't realize this. Make it more obvious that
key material must come from somewhere external by making the snippets
which use global keys into functions that take a key as a parameter.
@Patater Patater changed the title getting_started: Reduce RSA sign stack usage getting_started: Make it clear that keys are passed in Nov 8, 2019
@Patater
Copy link
Contributor Author

Patater commented Nov 8, 2019

We need to do both readable and portable. New patch set changes snippets to avoid magic all-caps keys which always cause a compilation error when a user copy pastes. Now, it is more obvious that the key material must be supplied from elsewhere.

@Patater
Copy link
Contributor Author

Patater commented Nov 8, 2019

Adding extra code to declare a non-standard scope variables has no place in example code

Agreed. Removed static from signature, which was noise. Key would be OK as static const as that's idiomatic C for constants, but new tact is even better: function parameter for the key to show obviously that your key material should come from elsewhere.

@gilles-peskine-arm
Copy link
Collaborator

The corresponding change to the source code of the example has been merged. This pull request has been approved, and it only modifies a file that isn't used by CI so CI is irrelevant. Merging.

@gilles-peskine-arm gilles-peskine-arm merged commit c82ed6f into ARMmbed:development Nov 8, 2019
gilles-peskine-arm added a commit to gilles-peskine-arm/mbed-crypto that referenced this pull request Nov 15, 2019
* ARMmbed#292: Make psa_close_key(0) and psa_destroy_key(0) succeed
* ARMmbed#299: Allow xxx_drbg_set_entropy_len before xxx_drbg_seed
* ARMmbed#259: Check `len` against buffers size upper bound in PSA tests
* ARMmbed#288: Add ECDSA tests with hash and key of different lengths
* ARMmbed#305: CTR_DRBG: grab a nonce from the entropy source if needed
* ARMmbed#316: Stop transactions from being reentrant
* ARMmbed#317: getting_started: Make it clear that keys are passed in
* ARMmbed#314: Fix pk_write with EC key to use a constant size for the private value
* ARMmbed#298: Test a build without any asymmetric cryptography
* ARMmbed#284: Fix some possibly-undefined variable warnings
* ARMmbed#315: Define MBEDTLS_PK_SIGNATURE_MAX_SIZE
* ARMmbed#318: Finish side-porting commits from mbedtls-restricted that missed the split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants