Tamas Ban | a00f285 | 2019-01-23 21:46:29 +0000 | [diff] [blame] | 1 | /* |
Mingyang Sun | c9bdcd7 | 2020-06-04 11:44:49 +0800 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
Tamas Ban | a00f285 | 2019-01-23 21:46:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
David Hu | 5469cea | 2019-12-05 18:36:51 +0800 | [diff] [blame] | 8 | #include <stddef.h> |
Tamas Ban | d09c38f | 2019-01-23 22:04:50 +0000 | [diff] [blame] | 9 | #include <stdint.h> |
Mingyang Sun | c9bdcd7 | 2020-06-04 11:44:49 +0800 | [diff] [blame] | 10 | #include "tfm_attest_hal.h" |
| 11 | #include "tfm_plat_boot_seed.h" |
| 12 | #include "tfm_plat_device_id.h" |
David Hu | 981ecb6 | 2019-12-05 17:58:29 +0800 | [diff] [blame] | 13 | |
| 14 | /*! |
| 15 | * \def BOOT_SEED |
| 16 | * |
| 17 | * \brief Fixed value for boot seed used for test. |
| 18 | */ |
| 19 | #define BOOT_SEED 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, \ |
| 20 | 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, \ |
| 21 | 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, \ |
| 22 | 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF |
| 23 | |
| 24 | static const uint8_t boot_seed[BOOT_SEED_SIZE] = {BOOT_SEED}; |
Tamas Ban | d09c38f | 2019-01-23 22:04:50 +0000 | [diff] [blame] | 25 | |
| 26 | /* Example verification service URL for initial attestation token */ |
| 27 | static const char verification_service_url[] = "www.trustedfirmware.org"; |
| 28 | |
| 29 | /* Example profile definition document for initial attestation token */ |
Tamas Ban | 12df1af | 2019-03-01 12:43:12 +0000 | [diff] [blame] | 30 | static const char attestation_profile_definition[] = "PSA_IOT_PROFILE_1"; |
Tamas Ban | a00f285 | 2019-01-23 21:46:29 +0000 | [diff] [blame] | 31 | |
David Hu | 5469cea | 2019-12-05 18:36:51 +0800 | [diff] [blame] | 32 | static const uint8_t implementation_id[] = { |
| 33 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
| 34 | 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, |
| 35 | 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, |
| 36 | 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, |
| 37 | }; |
| 38 | |
| 39 | static const uint8_t example_ean_13[] = "060456527282910010"; |
| 40 | |
Tamas Ban | a00f285 | 2019-01-23 21:46:29 +0000 | [diff] [blame] | 41 | enum tfm_security_lifecycle_t tfm_attest_hal_get_security_lifecycle(void) |
| 42 | { |
| 43 | return TFM_SLC_SECURED; |
| 44 | } |
Tamas Ban | d09c38f | 2019-01-23 22:04:50 +0000 | [diff] [blame] | 45 | |
| 46 | const char * |
| 47 | tfm_attest_hal_get_verification_service(uint32_t *size) |
| 48 | { |
| 49 | *size = sizeof(verification_service_url) - 1; |
| 50 | |
| 51 | return verification_service_url; |
| 52 | } |
| 53 | |
| 54 | const char * |
| 55 | tfm_attest_hal_get_profile_definition(uint32_t *size) |
| 56 | { |
| 57 | *size = sizeof(attestation_profile_definition) - 1; |
| 58 | |
| 59 | return attestation_profile_definition; |
| 60 | } |
David Hu | 981ecb6 | 2019-12-05 17:58:29 +0800 | [diff] [blame] | 61 | |
David Hu | 5469cea | 2019-12-05 18:36:51 +0800 | [diff] [blame] | 62 | /** |
| 63 | * \brief Copy data in source buffer to the destination buffer |
| 64 | * |
| 65 | * \param[out] p_dst Pointer to destation buffer |
| 66 | * \param[in] p_src Pointer to source buffer |
| 67 | * \param[in] size Length of data to be copied |
| 68 | */ |
| 69 | static inline void copy_buf(uint8_t *p_dst, const uint8_t *p_src, size_t size) |
| 70 | { |
| 71 | uint32_t i; |
| 72 | |
| 73 | for (i = size; i > 0; i--) { |
| 74 | *p_dst = *p_src; |
| 75 | p_src++; |
| 76 | p_dst++; |
| 77 | } |
| 78 | } |
| 79 | |
David Hu | 981ecb6 | 2019-12-05 17:58:29 +0800 | [diff] [blame] | 80 | enum tfm_plat_err_t tfm_plat_get_boot_seed(uint32_t size, uint8_t *buf) |
| 81 | { |
| 82 | /* FixMe: - This getter function must be ported per target platform. |
| 83 | * - Platform service shall provide an API to further interact this |
| 84 | * getter function to retrieve the boot seed. |
| 85 | */ |
| 86 | |
David Hu | 981ecb6 | 2019-12-05 17:58:29 +0800 | [diff] [blame] | 87 | uint8_t *p_dst = buf; |
| 88 | const uint8_t *p_src = boot_seed; |
| 89 | |
| 90 | if (size != BOOT_SEED_SIZE) { |
| 91 | return TFM_PLAT_ERR_SYSTEM_ERR; |
| 92 | } |
| 93 | |
David Hu | 5469cea | 2019-12-05 18:36:51 +0800 | [diff] [blame] | 94 | copy_buf(p_dst, p_src, size); |
| 95 | |
| 96 | return TFM_PLAT_ERR_SUCCESS; |
| 97 | } |
| 98 | |
| 99 | enum tfm_plat_err_t tfm_plat_get_implementation_id(uint32_t *size, |
| 100 | uint8_t *buf) |
| 101 | { |
| 102 | const uint8_t *p_impl_id = implementation_id; |
| 103 | uint32_t impl_id_size = sizeof(implementation_id); |
| 104 | |
| 105 | if (*size < impl_id_size) { |
| 106 | return TFM_PLAT_ERR_SYSTEM_ERR; |
David Hu | 981ecb6 | 2019-12-05 17:58:29 +0800 | [diff] [blame] | 107 | } |
| 108 | |
David Hu | 5469cea | 2019-12-05 18:36:51 +0800 | [diff] [blame] | 109 | copy_buf(buf, p_impl_id, impl_id_size); |
| 110 | *size = impl_id_size; |
| 111 | |
| 112 | return TFM_PLAT_ERR_SUCCESS; |
| 113 | } |
| 114 | |
| 115 | enum tfm_plat_err_t tfm_plat_get_hw_version(uint32_t *size, uint8_t *buf) |
| 116 | { |
| 117 | const uint8_t *p_hw_version = example_ean_13; |
| 118 | uint32_t hw_version_size = sizeof(example_ean_13) - 1; |
| 119 | |
| 120 | if (*size < hw_version_size) { |
| 121 | return TFM_PLAT_ERR_SYSTEM_ERR; |
| 122 | } |
| 123 | |
| 124 | copy_buf(buf, p_hw_version, hw_version_size); |
| 125 | *size = hw_version_size; |
| 126 | |
David Hu | 981ecb6 | 2019-12-05 17:58:29 +0800 | [diff] [blame] | 127 | return TFM_PLAT_ERR_SUCCESS; |
| 128 | } |