blob: 8e679f648f12aef49aa50024881cbbe529287b8e [file] [log] [blame]
Maulik Patelad2f3db2023-05-17 15:41:36 +01001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __DPE_CONTEXT_MNGR_H__
9#define __DPE_CONTEXT_MNGR_H__
10
11#include <stddef.h>
12#include <stdint.h>
13#include <stdbool.h>
14#include "dice_protection_environment.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#define DICE_WRAPPING_KEY_SIZE 32
21#define DICE_CERT_SIZE 1024
22
23#define INVALID_HANDLE 0xFFFFFFFF
24#define INVALID_COMPONENT_IDX 0xFFFF
25#define INVALID_NONCE_VALUE 0xFFFF
Maulik Patelad2f3db2023-05-17 15:41:36 +010026#define INVALID_LAYER_IDX 65535
Maulik Patel54d65f72023-06-28 13:04:36 +010027#define DPE_ROT_LAYER_IDX 0
28
29/* Below configuration defines are platform dependant */
30#define MAX_NUM_OF_COMPONENTS 30
31#define MAX_NUM_OF_LAYERS 10
32#define DPE_PLATFORM_LAYER_IDX 1
33#define DPE_SECURE_WORLD_AND_HYPERVISOR_LAYER_IDX 2
34/* Below threshold defines the threshold below which a context cannot be destroyed */
35#define DPE_DESTROY_CONTEXT_THRESHOLD_LAYER_IDX DPE_SECURE_WORLD_AND_HYPERVISOR_LAYER_IDX
Maulik Patelad2f3db2023-05-17 15:41:36 +010036
37/* Most significant 16 bits represent nonce & remaining 16 bits represent component index */
38#define GET_IDX(handle) ((handle) & 0xffff)
39#define GET_NONCE(handle) ((handle >> 16) & 0xffff)
40
41#define SET_IDX(handle, idx) ((handle & 0xffff0000) | idx)
42#define SET_NONCE(handle, nonce) ((handle & 0x00ffff) | (nonce << 16))
43
44struct component_context_data_t {
45 uint8_t measurement_value[DICE_HASH_SIZE];
46 uint8_t measurement_descriptor[DICE_CODE_DESCRIPTOR_MAX_SIZE];
47 size_t measurement_descriptor_size;
48 uint8_t signer_id[DICE_HASH_SIZE];
49 uint8_t signer_id_descriptor[DICE_AUTHORITY_DESCRIPTOR_MAX_SIZE];
50 size_t signer_id_descriptor_size;
51 uint8_t config_value[DICE_INLINE_CONFIG_SIZE];
52 uint8_t config_descriptor[DICE_CONFIG_DESCRIPTOR_MAX_SIZE];
53 size_t config_descriptor_size;
54 DiceMode mode;
55 uint8_t hidden[DICE_HIDDEN_SIZE];
56};
57
58struct component_context_t {
59 struct component_context_data_t data; /* Component context data */
60 bool in_use; /* Flag to indicate if element is used */
61 bool is_leaf; /* Is the component allowed to derive */
62 uint16_t nonce; /* Context handle nonce for the component */
63 uint16_t parent_idx; /* Parent component's index */
64 uint16_t linked_layer_idx; /* Layer component is linked to */
65 uint32_t expected_mhu_id; /* Expected mhu to authorise derivation */
66};
67
68struct layer_context_data_t {
69 uint8_t cdi_attest[DICE_CDI_SIZE];
70 uint8_t cdi_seal[DICE_CDI_SIZE];
71 uint8_t wrapping_key[DICE_WRAPPING_KEY_SIZE];
72 uint8_t cert_buf[DICE_CERT_SIZE];
73 size_t cert_buf_size;
74};
75
76enum layer_state_t {
77 LAYER_STATE_CLOSED = 0,
78 LAYER_STATE_OPEN,
79 LAYER_STATE_FINALISED
80};
81
82struct layer_context_t {
83 struct layer_context_data_t data;
84 uint16_t parent_layer_idx;
85 enum layer_state_t state;
86};
87
88/**
89 * \brief Derives a root of trust component context and creates certificate.
90 *
91 * \param[in] dice_inputs Pointer to dice_input buffer.
92 * \param[out] new_child_context_handle A new handle for child context.
93 * \param[out] new_parent_context_handle A new handle for parent context.
94 *
95 * \return Returns error code of type dpe_error_t
96 */
97dpe_error_t derive_rot_context(const DiceInputValues *dice_inputs,
98 int *new_child_ctx_handle,
99 int *new_parent_ctx_handle);
100
101/**
102 * \brief Derives a child component context and optionally creates certificate
103 * chain.
104 *
105 * \param[in] input_context_handle Input handle to child component context
106 * \param[in] retain_parent_context Flag to indicate if parent context need
107 * to be retained. TRUE only if a client
108 * is calling DPE commands multiple times
109 * \param[in] allow_child_to_derive Flag to indicate if requested child can
110 * derive further.
111 * \param[in] create_certificate Flag to indicate if certificate needs
112 * to be created. TRUE only if it is the
113 * last component in the layer.
114 * \param[in] dice_inputs Pointer to dice_input buffer.
115 * \param[in] client_id Identifier of the client calling the
116 * service.
117 * \param[out] new_child_context_handle A new handle for child context.
118 * \param[out] new_parent_context_handle A new handle for parent context.
119 *
120 * \return Returns error code of type dpe_error_t
121 */
122dpe_error_t derive_child_request(int input_context_handle,
123 bool retain_parent_context,
124 bool allow_child_to_derive,
125 bool create_certificate,
126 const DiceInputValues *dice_inputs,
127 int32_t client_id,
128 int *new_child_context_handle,
129 int *new_parent_context_handle);
130
131/**
Maulik Patel54d65f72023-06-28 13:04:36 +0100132 * \brief Destroys a component context and optionally depending on argument
133 * destroy_recursively, destroys all its child context too.
134 *
135 * \param[in] input_context_handle Input handle to child component context
136 * \param[in] destroy_recursively Flag to indicate if all derived contexts
137 * should also be destroyed recursively.
138 *
139 * \return Returns error code of type dpe_error_t
140 */
141dpe_error_t destroy_context_request(int input_ctx_handle,
142 bool destroy_recursively);
143
144/**
Maulik Patelad2f3db2023-05-17 15:41:36 +0100145 * \brief Initialise all DPE Layer and component contexts
146 *
147 */
148void initialise_all_dpe_contexts(void);
149
150#ifdef __cplusplus
151}
152#endif
153
154#endif /* __DPE_CONTEXT_MNGR_H__ */