-
Notifications
You must be signed in to change notification settings - Fork 218
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
PSA implementation of ed25519 image verification and x25519 random key encryption/decryption #323
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c2cc2ab
[nrf fromtree] boot: Fix ASN.1 for mbedtls >= 3.1
d3zd3z acf52b0
[nrf fromtree] bootutil: Keep image encrypted in scratch area
taltenbach 543a630
[nrf fromtree] boot: Remove pointless slot identification
de-nordic 257125e
[nrf fromtree] boot: Rename boot_enc_decrypt to boot_decrypt_key
de-nordic 774813a
[nrf fromtree] boot: Move encryption context invalidation to boot_enc…
de-nordic 5507a5e
[nrf fromtree] boot: Change boot_enc_load to take slot number instead…
de-nordic 728d056
[nrf fromtree] boot: Reduce repeating code in boot_decrypt_and_copy_i…
de-nordic 0bd46d6
[nrf fromtree] Fix style issues
utzig 9c75592
[nrf fromtree] boot: Remove image_index from boot_encrypt
de-nordic 2023198
[nrf fromtree] boot: Simplify copy loop in boot_copy_region
de-nordic e02b962
[nrf fromtree] boot: Make boot_enc_valid take slot instead of image i…
de-nordic 34f51df
[nrf fromlist] boot: Replace boot_encrypt by boot_enc_encrypt and boo…
de-nordic 691d763
[nrf noup] PSA configuration required changes
de-nordic 0d4c91e
[nrf noup] PSA implementation of x25519 and ed25519 verification
de-nordic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2020 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <stdint.h> | ||
|
||
#include <mcuboot_config/mcuboot_config.h> | ||
#include "bootutil/bootutil_log.h" | ||
|
||
#include <psa/crypto.h> | ||
#include <psa/crypto_types.h> | ||
|
||
BOOT_LOG_MODULE_DECLARE(ed25519_psa); | ||
|
||
#define SHA512_DIGEST_LENGTH 64 | ||
#define EDDSA_KEY_LENGTH 32 | ||
#define EDDSA_SIGNAGURE_LENGTH 64 | ||
|
||
int ED25519_verify(const uint8_t *message, size_t message_len, | ||
const uint8_t signature[EDDSA_SIGNAGURE_LENGTH], | ||
const uint8_t public_key[EDDSA_KEY_LENGTH]) | ||
{ | ||
/* Set to any error */ | ||
psa_status_t status = PSA_ERROR_BAD_STATE; | ||
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; | ||
psa_key_id_t kid; | ||
int ret = 0; /* Fail by default */ | ||
|
||
/* Initialize PSA Crypto */ | ||
status = psa_crypto_init(); | ||
if (status != PSA_SUCCESS) { | ||
BOOT_LOG_ERR("PSA crypto init failed %d\n", status); | ||
return 0; | ||
} | ||
|
||
status = PSA_ERROR_BAD_STATE; | ||
|
||
psa_set_key_type(&key_attr, | ||
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_TWISTED_EDWARDS)); | ||
psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_VERIFY_MESSAGE); | ||
psa_set_key_algorithm(&key_attr, PSA_ALG_PURE_EDDSA); | ||
|
||
status = psa_import_key(&key_attr, public_key, EDDSA_KEY_LENGTH, &kid); | ||
if (status != PSA_SUCCESS) { | ||
BOOT_LOG_ERR("ED25519 key import failed %d", status); | ||
return 0; | ||
} | ||
|
||
status = psa_verify_message(kid, PSA_ALG_PURE_EDDSA, message, message_len, | ||
signature, EDDSA_SIGNAGURE_LENGTH); | ||
if (status != PSA_SUCCESS) { | ||
BOOT_LOG_ERR("ED25519 signature verification failed %d", status); | ||
ret = 0; | ||
/* Pass through to destroy key */ | ||
} else { | ||
ret = 1; | ||
/* Pass through to destroy key */ | ||
} | ||
|
||
status = psa_destroy_key(kid); | ||
|
||
if (status != PSA_SUCCESS) { | ||
/* Just for logging */ | ||
BOOT_LOG_WRN("Failed to destroy key %d", status); | ||
} | ||
|
||
return ret; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this the place where psa_verify_hash() will be used instead for full sha512 based signature check?
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.
Yes. Exactly. In the following PR 33a7ec4 there is already that part done.
The difference is that instead of the sha256, which is the
messge
here, we will get sha512, and therefore we do not rely on the internal sha512 calculation ofpsa_verify_message
, but rather just verify the hash.