blob: 8335263daf5fa4644ed9be56b2004f3f3cf9f58f [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
26#define MAX_NUM_OF_COMPONENTS 30
27#define DPE_ROT_LAYER_IDX 0
28#define MAX_NUM_OF_LAYERS 10
29#define INVALID_LAYER_IDX 65535
30
31/* Most significant 16 bits represent nonce & remaining 16 bits represent component index */
32#define GET_IDX(handle) ((handle) & 0xffff)
33#define GET_NONCE(handle) ((handle >> 16) & 0xffff)
34
35#define SET_IDX(handle, idx) ((handle & 0xffff0000) | idx)
36#define SET_NONCE(handle, nonce) ((handle & 0x00ffff) | (nonce << 16))
37
38struct component_context_data_t {
39 uint8_t measurement_value[DICE_HASH_SIZE];
40 uint8_t measurement_descriptor[DICE_CODE_DESCRIPTOR_MAX_SIZE];
41 size_t measurement_descriptor_size;
42 uint8_t signer_id[DICE_HASH_SIZE];
43 uint8_t signer_id_descriptor[DICE_AUTHORITY_DESCRIPTOR_MAX_SIZE];
44 size_t signer_id_descriptor_size;
45 uint8_t config_value[DICE_INLINE_CONFIG_SIZE];
46 uint8_t config_descriptor[DICE_CONFIG_DESCRIPTOR_MAX_SIZE];
47 size_t config_descriptor_size;
48 DiceMode mode;
49 uint8_t hidden[DICE_HIDDEN_SIZE];
50};
51
52struct component_context_t {
53 struct component_context_data_t data; /* Component context data */
54 bool in_use; /* Flag to indicate if element is used */
55 bool is_leaf; /* Is the component allowed to derive */
56 uint16_t nonce; /* Context handle nonce for the component */
57 uint16_t parent_idx; /* Parent component's index */
58 uint16_t linked_layer_idx; /* Layer component is linked to */
59 uint32_t expected_mhu_id; /* Expected mhu to authorise derivation */
60};
61
62struct layer_context_data_t {
63 uint8_t cdi_attest[DICE_CDI_SIZE];
64 uint8_t cdi_seal[DICE_CDI_SIZE];
65 uint8_t wrapping_key[DICE_WRAPPING_KEY_SIZE];
66 uint8_t cert_buf[DICE_CERT_SIZE];
67 size_t cert_buf_size;
68};
69
70enum layer_state_t {
71 LAYER_STATE_CLOSED = 0,
72 LAYER_STATE_OPEN,
73 LAYER_STATE_FINALISED
74};
75
76struct layer_context_t {
77 struct layer_context_data_t data;
78 uint16_t parent_layer_idx;
79 enum layer_state_t state;
80};
81
82/**
83 * \brief Derives a root of trust component context and creates certificate.
84 *
85 * \param[in] dice_inputs Pointer to dice_input buffer.
86 * \param[out] new_child_context_handle A new handle for child context.
87 * \param[out] new_parent_context_handle A new handle for parent context.
88 *
89 * \return Returns error code of type dpe_error_t
90 */
91dpe_error_t derive_rot_context(const DiceInputValues *dice_inputs,
92 int *new_child_ctx_handle,
93 int *new_parent_ctx_handle);
94
95/**
96 * \brief Derives a child component context and optionally creates certificate
97 * chain.
98 *
99 * \param[in] input_context_handle Input handle to child component context
100 * \param[in] retain_parent_context Flag to indicate if parent context need
101 * to be retained. TRUE only if a client
102 * is calling DPE commands multiple times
103 * \param[in] allow_child_to_derive Flag to indicate if requested child can
104 * derive further.
105 * \param[in] create_certificate Flag to indicate if certificate needs
106 * to be created. TRUE only if it is the
107 * last component in the layer.
108 * \param[in] dice_inputs Pointer to dice_input buffer.
109 * \param[in] client_id Identifier of the client calling the
110 * service.
111 * \param[out] new_child_context_handle A new handle for child context.
112 * \param[out] new_parent_context_handle A new handle for parent context.
113 *
114 * \return Returns error code of type dpe_error_t
115 */
116dpe_error_t derive_child_request(int input_context_handle,
117 bool retain_parent_context,
118 bool allow_child_to_derive,
119 bool create_certificate,
120 const DiceInputValues *dice_inputs,
121 int32_t client_id,
122 int *new_child_context_handle,
123 int *new_parent_context_handle);
124
125/**
126 * \brief Initialise all DPE Layer and component contexts
127 *
128 */
129void initialise_all_dpe_contexts(void);
130
131#ifdef __cplusplus
132}
133#endif
134
135#endif /* __DPE_CONTEXT_MNGR_H__ */