blob: 69bafdddbfd79796287d4ddb251cbb71fe120c0f [file] [log] [blame]
Tamas Bana00f2852019-01-23 21:46:29 +00001/*
Mingyang Sunc9bdcd72020-06-04 11:44:49 +08002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Tamas Bana00f2852019-01-23 21:46:29 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
David Hu5469cea2019-12-05 18:36:51 +08008#include <stddef.h>
Tamas Band09c38f2019-01-23 22:04:50 +00009#include <stdint.h>
Mingyang Sunc9bdcd72020-06-04 11:44:49 +080010#include "tfm_attest_hal.h"
11#include "tfm_plat_boot_seed.h"
12#include "tfm_plat_device_id.h"
David Hu981ecb62019-12-05 17:58:29 +080013
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
24static const uint8_t boot_seed[BOOT_SEED_SIZE] = {BOOT_SEED};
Tamas Band09c38f2019-01-23 22:04:50 +000025
26/* Example verification service URL for initial attestation token */
27static const char verification_service_url[] = "www.trustedfirmware.org";
28
29/* Example profile definition document for initial attestation token */
Tamas Ban12df1af2019-03-01 12:43:12 +000030static const char attestation_profile_definition[] = "PSA_IOT_PROFILE_1";
Tamas Bana00f2852019-01-23 21:46:29 +000031
David Hu5469cea2019-12-05 18:36:51 +080032static 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
39static const uint8_t example_ean_13[] = "060456527282910010";
40
Tamas Bana00f2852019-01-23 21:46:29 +000041enum tfm_security_lifecycle_t tfm_attest_hal_get_security_lifecycle(void)
42{
43 return TFM_SLC_SECURED;
44}
Tamas Band09c38f2019-01-23 22:04:50 +000045
46const char *
47tfm_attest_hal_get_verification_service(uint32_t *size)
48{
49 *size = sizeof(verification_service_url) - 1;
50
51 return verification_service_url;
52}
53
54const char *
55tfm_attest_hal_get_profile_definition(uint32_t *size)
56{
57 *size = sizeof(attestation_profile_definition) - 1;
58
59 return attestation_profile_definition;
60}
David Hu981ecb62019-12-05 17:58:29 +080061
David Hu5469cea2019-12-05 18:36:51 +080062/**
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 */
69static 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 Hu981ecb62019-12-05 17:58:29 +080080enum 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 Hu981ecb62019-12-05 17:58:29 +080087 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 Hu5469cea2019-12-05 18:36:51 +080094 copy_buf(p_dst, p_src, size);
95
96 return TFM_PLAT_ERR_SUCCESS;
97}
98
99enum 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 Hu981ecb62019-12-05 17:58:29 +0800107 }
108
David Hu5469cea2019-12-05 18:36:51 +0800109 copy_buf(buf, p_impl_id, impl_id_size);
110 *size = impl_id_size;
111
112 return TFM_PLAT_ERR_SUCCESS;
113}
114
115enum 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 Hu981ecb62019-12-05 17:58:29 +0800127 return TFM_PLAT_ERR_SUCCESS;
128}