DPE: Rename DeriveChild to DeriveContext

As per spec updates in v1.0 r9:
* Rename DeriveChild to DeriveContext.
* Rename its input argument allow_child_to_derive to
  allow_new_context_to_derive.

Also, update the context manager code to NOT preallocate the slot for
subsequent derivation request. Rather allocate and use the slot
as and when the request is made.

Signed-off-by: Maulik Patel <maulik.patel@arm.com>
Change-Id: I44ed2f54d8039b6326780f60b15d560453356e56
diff --git a/docs/partitions/dice_protection_environment.rst b/docs/partitions/dice_protection_environment.rst
index 12f4fe2..8f24291 100644
--- a/docs/partitions/dice_protection_environment.rst
+++ b/docs/partitions/dice_protection_environment.rst
@@ -78,8 +78,8 @@
 The DPE commands themselves are CBOR-encoded objects that the DPE decode layer
 decodes into calls to one of the following supported DICE functions.
 
-DeriveChild
------------
+DeriveContext
+-------------
 
 Adds a component context to the layer, consisting of:
 
@@ -120,7 +120,7 @@
 
 - Adds label (if supplied) to list of measurements.
 
-- Finalizes the layer (as for DeriveChild above).
+- Finalizes the layer (as for DeriveContext above).
 
 - Returns the certificate chain (collection of individual certificates) as a
   CBOR array with format [+COSE_Sign1, COSE_Key]. The (pre-provisioned) root
diff --git a/partitions/dice_protection_environment/dpe_boot_data.c b/partitions/dice_protection_environment/dpe_boot_data.c
index bdeaea9..8aa56dd 100644
--- a/partitions/dice_protection_environment/dpe_boot_data.c
+++ b/partitions/dice_protection_environment/dpe_boot_data.c
@@ -277,7 +277,7 @@
 }
 
 dpe_error_t derive_boot_data_contexts(int rot_ctx_handle,
-                                      int *child_ctx_handle)
+                                      int *new_ctx_handle)
 {
     int ret;
     dpe_error_t err;
@@ -295,14 +295,14 @@
     }
 
     /* Derive RoT layer */
-    err = derive_child_request(rot_ctx_handle,
-                               false,
-                               true,
-                               true, /* create certificate */
-                               &dice_inputs,
-                               0,
-                               &plat_ctx_handle,
-                               &invalid_ctx_handle);
+    err = derive_context_request(rot_ctx_handle,
+                                 false,
+                                 true,
+                                 true, /* create certificate */
+                                 &dice_inputs,
+                                 0,
+                                 &plat_ctx_handle,
+                                 &invalid_ctx_handle);
     if (err != DPE_NO_ERROR) {
         return err;
     }
@@ -316,14 +316,14 @@
     }
 
     /* Derive BL2 context */
-    err = derive_child_request(plat_ctx_handle,
-                               false, /* close parent context */
-                               true, /* allow BL2 child to derive further */
-                               false,
-                               &dice_inputs,
-                               0,
-                               &plat_ctx_handle,
-                               &invalid_ctx_handle);
+    err = derive_context_request(plat_ctx_handle,
+                                 false, /* close parent context */
+                                 true, /* allow BL2 to derive further */
+                                 false,
+                                 &dice_inputs,
+                                 0,
+                                 &plat_ctx_handle,
+                                 &invalid_ctx_handle);
     if (err != DPE_NO_ERROR) {
         return err;
     }
@@ -333,14 +333,14 @@
     while ((ret = get_measurement_for_slot_cond(&plat_cond, &itr,
                                                 &dice_inputs)) == 1) {
         /* Derive rest of platform contexts from retained BL2 context */
-        err = derive_child_request(plat_ctx_handle,
-                                   true, /* retain parent context */
-                                   false, /* do not allow child to derive */
-                                   false,
-                                   &dice_inputs,
-                                   0,
-                                   &invalid_ctx_handle,
-                                   &plat_ctx_handle);
+        err = derive_context_request(plat_ctx_handle,
+                                     true, /* retain parent context */
+                                     false, /* do not allow derived context to derive */
+                                     false,
+                                     &dice_inputs,
+                                     0,
+                                     &invalid_ctx_handle,
+                                     &plat_ctx_handle);
         if (err != DPE_NO_ERROR) {
             return err;
         }
@@ -359,15 +359,15 @@
         return DPE_INTERNAL_ERROR;
     }
 
-    /* Derive AP context, with the new child context handle returned to the
-     * caller in the child_ctx_handle output parameter.
+    /* Derive AP context, with the new derived context handle returned to the
+     * caller in the new_ctx_handle output parameter.
      */
-    return derive_child_request(plat_ctx_handle,
-                                false, /* close parent context */
-                                true, /* allow AP to derive */
-                                false,
-                                &dice_inputs,
-                                0,
-                                child_ctx_handle,
-                                &invalid_ctx_handle);
+    return derive_context_request(plat_ctx_handle,
+                                  false, /* close parent context */
+                                  true, /* allow AP to derive */
+                                  false,
+                                  &dice_inputs,
+                                  0,
+                                  new_ctx_handle,
+                                  &invalid_ctx_handle);
 }
diff --git a/partitions/dice_protection_environment/dpe_boot_data.h b/partitions/dice_protection_environment/dpe_boot_data.h
index 2864b2a..6d64a31 100644
--- a/partitions/dice_protection_environment/dpe_boot_data.h
+++ b/partitions/dice_protection_environment/dpe_boot_data.h
@@ -27,12 +27,12 @@
  *        area.
  *
  * \param[in]  rot_ctx_handle    Handle for the RoT context.
- * \param[out] child_ctx_handle  New handle for child context.
+ * \param[out] new_ctx_handle    New handle for the derived context.
  *
  * \return Returns error code of type dpe_error_t
  */
 dpe_error_t derive_boot_data_contexts(int rot_ctx_handle,
-                                      int *child_ctx_handle);
+                                      int *new_ctx_handle);
 
 #ifdef __cplusplus
 }
diff --git a/partitions/dice_protection_environment/dpe_cmd_decode.c b/partitions/dice_protection_environment/dpe_cmd_decode.c
index 5aec24e..b6dda5a 100644
--- a/partitions/dice_protection_environment/dpe_cmd_decode.c
+++ b/partitions/dice_protection_environment/dpe_cmd_decode.c
@@ -25,7 +25,7 @@
 
     /* The DICE inputs are encoded as a map wrapped into a byte string */
     QCBORDecode_EnterBstrWrappedFromMapN(decode_ctx,
-                                         DPE_DERIVE_CHILD_INPUT_DATA,
+                                         DPE_DERIVE_CONTEXT_INPUT_DATA,
                                          QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL);
     QCBORDecode_EnterMap(decode_ctx, NULL);
 
@@ -103,38 +103,38 @@
     return DPE_NO_ERROR;
 }
 
-static dpe_error_t decode_derive_child(QCBORDecodeContext *decode_ctx,
-                                       QCBOREncodeContext *encode_ctx,
-                                       int32_t client_id)
+static dpe_error_t decode_derive_context(QCBORDecodeContext *decode_ctx,
+                                         QCBOREncodeContext *encode_ctx,
+                                         int32_t client_id)
 {
     dpe_error_t dpe_err;
     QCBORError qcbor_err;
     UsefulBufC out;
     int context_handle;
     bool retain_parent_context;
-    bool allow_child_to_derive;
+    bool allow_new_context_to_derive;
     bool create_certificate;
     DiceInputValues dice_inputs;
-    int new_child_context_handle;
+    int new_context_handle;
     int new_parent_context_handle;
 
-    /* Decode DeriveChild command */
+    /* Decode DeriveContext command */
     QCBORDecode_EnterMap(decode_ctx, NULL);
 
-    QCBORDecode_GetByteStringInMapN(decode_ctx, DPE_DERIVE_CHILD_CONTEXT_HANDLE,
+    QCBORDecode_GetByteStringInMapN(decode_ctx, DPE_DERIVE_CONTEXT_CONTEXT_HANDLE,
                                     &out);
     if (out.len != sizeof(context_handle)) {
         return DPE_INVALID_COMMAND;
     }
     memcpy(&context_handle, out.ptr, out.len);
 
-    QCBORDecode_GetBoolInMapN(decode_ctx, DPE_DERIVE_CHILD_RETAIN_PARENT_CONTEXT,
+    QCBORDecode_GetBoolInMapN(decode_ctx, DPE_DERIVE_CONTEXT_RETAIN_PARENT_CONTEXT,
                               &retain_parent_context);
 
-    QCBORDecode_GetBoolInMapN(decode_ctx, DPE_DERIVE_CHILD_ALLOW_CHILD_TO_DERIVE,
-                              &allow_child_to_derive);
+    QCBORDecode_GetBoolInMapN(decode_ctx, DPE_DERIVE_CONTEXT_ALLOW_NEW_CONTEXT_TO_DERIVE,
+                              &allow_new_context_to_derive);
 
-    QCBORDecode_GetBoolInMapN(decode_ctx, DPE_DERIVE_CHILD_CREATE_CERTIFICATE,
+    QCBORDecode_GetBoolInMapN(decode_ctx, DPE_DERIVE_CONTEXT_CREATE_CERTIFICATE,
                               &create_certificate);
 
     dpe_err = decode_dice_inputs(decode_ctx, &dice_inputs);
@@ -153,11 +153,11 @@
         return DPE_INVALID_COMMAND;
     }
 
-    dpe_err = derive_child_request(context_handle, retain_parent_context,
-                                   allow_child_to_derive, create_certificate,
-                                   &dice_inputs, client_id,
-                                   &new_child_context_handle,
-                                   &new_parent_context_handle);
+    dpe_err = derive_context_request(context_handle, retain_parent_context,
+                                     allow_new_context_to_derive, create_certificate,
+                                     &dice_inputs, client_id,
+                                     &new_context_handle,
+                                     &new_parent_context_handle);
     if (dpe_err != DPE_NO_ERROR) {
         return dpe_err;
     }
@@ -167,11 +167,11 @@
     QCBOREncode_AddInt64(encode_ctx, DPE_NO_ERROR);
 
     QCBOREncode_OpenMap(encode_ctx);
-    QCBOREncode_AddBytesToMapN(encode_ctx, DPE_DERIVE_CHILD_NEW_CONTEXT_HANDLE,
-                               (UsefulBufC){ &new_child_context_handle,
-                                             sizeof(new_child_context_handle) });
+    QCBOREncode_AddBytesToMapN(encode_ctx, DPE_DERIVE_CONTEXT_NEW_CONTEXT_HANDLE,
+                               (UsefulBufC){ &new_context_handle,
+                                             sizeof(new_context_handle) });
     QCBOREncode_AddBytesToMapN(encode_ctx,
-                               DPE_DERIVE_CHILD_PARENT_CONTEXT_HANDLE,
+                               DPE_DERIVE_CONTEXT_PARENT_CONTEXT_HANDLE,
                                (UsefulBufC){ &new_parent_context_handle,
                                              sizeof(new_parent_context_handle) });
     QCBOREncode_CloseMap(encode_ctx);
@@ -353,8 +353,8 @@
 
     if (qcbor_err == QCBOR_SUCCESS) {
         switch (command_id) {
-        case DPE_DERIVE_CHILD:
-            dpe_err = decode_derive_child(&decode_ctx, &encode_ctx, client_id);
+        case DPE_DERIVE_CONTEXT:
+            dpe_err = decode_derive_context(&decode_ctx, &encode_ctx, client_id);
             break;
         case DPE_CERTIFY_KEY:
             dpe_err = decode_certify_key(&decode_ctx, &encode_ctx);
diff --git a/partitions/dice_protection_environment/dpe_context_mngr.c b/partitions/dice_protection_environment/dpe_context_mngr.c
index 6823fd5..4e05da3 100644
--- a/partitions/dice_protection_environment/dpe_context_mngr.c
+++ b/partitions/dice_protection_environment/dpe_context_mngr.c
@@ -47,11 +47,6 @@
     return i;
 }
 
-static inline void invalidate_handle(int *handle)
-{
-    *handle = INVALID_HANDLE;
-}
-
 static dpe_error_t renew_nonce(int *handle)
 {
     uint16_t nonce;
@@ -65,19 +60,6 @@
     return DPE_NO_ERROR;
 }
 
-static dpe_error_t generate_new_handle(int *out_handle)
-{
-    /* Find the free component array element */
-    int free_component_idx = get_free_component_context_index();
-    if (free_component_idx < 0) {
-        return DPE_INSUFFICIENT_MEMORY;
-    }
-
-    *out_handle = SET_IDX(*out_handle, free_component_idx);
-
-    return renew_nonce(out_handle);
-}
-
 static void set_context_to_default(int i)
 {
     component_ctx_array[i].in_use = false;
@@ -361,18 +343,18 @@
      * has some context data and certificate buffer of 3k, it is
      * causing RAM overflow. Hence until resoluton is reached, once all
      * layers are opened, link new compenents to the last layer.
-     * ISSUE DESCRIPTION: We derive AP_BL31 as child of AP BL2 with create_certificate
-     * as true. Hence we finalize Platform layer. Then we derive AP_SPM as child of
-     * AP BL2, but since AP BL2 is finalised, we open new layer (Hypervisor layer).
-     * Then we derive AP SPx as child of AP BL2. Again, since AP BL2 is finalised,
+     * ISSUE DESCRIPTION: AP BL2 derives AP_BL31 with create_certificate
+     * as true. Hence we finalize Platform layer. Then AP BL2 derives AP_SPM,
+     * but since AP BL2 is finalised, we open new layer (Hypervisor layer).
+     * AP BL2 further derives AP SPx. Again, since AP BL2 is finalised,
      * we open new layer! Here AP SPx should belong to same layer as AP SPM.
      */
     return MAX_NUM_OF_LAYERS - 1;
 }
 
-static inline void link_layer(uint16_t child_layer, uint16_t parent_layer)
+static inline void link_layer(uint16_t derived_ctx_layer, uint16_t parent_ctx_layer)
 {
-    layer_ctx_array[child_layer].parent_layer_idx = parent_layer;
+    layer_ctx_array[derived_ctx_layer].parent_layer_idx = parent_ctx_layer;
 }
 
 static inline bool is_input_client_id_valid(int32_t client_id)
@@ -391,7 +373,7 @@
     assert(parent_layer_idx < MAX_NUM_OF_LAYERS);
 
     if (layer_ctx_array[parent_layer_idx].state == LAYER_STATE_FINALISED) {
-        /* Parent comp's layer of new child is finalised; open a new layer */
+        /* Parent comp's layer of new derived context is finalised; open a new layer */
         new_layer_idx = open_new_layer();
         if (new_layer_idx == INVALID_LAYER_IDX) {
             return DPE_INTERNAL_ERROR;
@@ -432,7 +414,7 @@
 
     /* Open RoT layer */
     rot_layer_ctx->state = LAYER_STATE_OPEN;
-    /* Parent is same as child for RoT layer */
+    /* Parent layer for RoT context's layer is same */
     rot_layer_ctx->parent_layer_idx = DPE_ROT_LAYER_IDX;
 
 #ifndef DPE_TEST_MODE
@@ -452,10 +434,9 @@
         return DPE_INTERNAL_ERROR;
     }
 
-    /* Init RoT context, ready to be derived in next call to DeriveChild */
-    rot_comp_ctx->in_use = true;
+    /* Init RoT context, ready to be derived in next call to DeriveContext */
     rot_comp_ctx->nonce = 0;
-    /* Parent is same as child for RoT context */
+    /* Parent component index for derived RoT context is same */
     rot_comp_ctx->parent_idx = 0;
     /* Link context to RoT Layer */
     rot_comp_ctx->linked_layer_idx = DPE_ROT_LAYER_IDX;
@@ -480,25 +461,27 @@
     return create_rot_context(rot_ctx_handle);
 }
 
-dpe_error_t derive_child_request(int input_ctx_handle,
-                                 bool retain_parent_context,
-                                 bool allow_child_to_derive,
-                                 bool create_certificate,
-                                 const DiceInputValues *dice_inputs,
-                                 int32_t client_id,
-                                 int *new_child_ctx_handle,
-                                 int *new_parent_ctx_handle)
+dpe_error_t derive_context_request(int input_ctx_handle,
+                                   bool retain_parent_context,
+                                   bool allow_new_context_to_derive,
+                                   bool create_certificate,
+                                   const DiceInputValues *dice_inputs,
+                                   int32_t client_id,
+                                   int *new_context_handle,
+                                   int *new_parent_context_handle)
 {
     dpe_error_t err;
-    struct component_context_t *child_ctx, *parent_ctx, *new_ctx;
-    uint16_t input_child_idx, input_parent_idx;
+    struct component_context_t *parent_ctx, *derived_ctx;
+    uint16_t parent_ctx_idx;
+    int free_component_idx;
 
-    log_derive_child(input_ctx_handle, retain_parent_context,
-                     allow_child_to_derive, create_certificate, dice_inputs,
-                     client_id);
+    log_derive_context(input_ctx_handle, retain_parent_context,
+                       allow_new_context_to_derive, create_certificate, dice_inputs,
+                       client_id);
 
 #ifdef DPE_TEST_MODE
-    if (input_ctx_handle == 0) {
+    if ((input_ctx_handle == 0) &&
+        (layer_ctx_array[DPE_ROT_LAYER_IDX].state != LAYER_STATE_FINALISED)) {
         /* Deriving RoT context for tests */
         err = create_rot_context(&input_ctx_handle);
         if (err != DPE_NO_ERROR) {
@@ -516,90 +499,81 @@
     if (!is_input_handle_valid(input_ctx_handle)) {
         return DPE_INVALID_ARGUMENT;
     }
-    /* Get child component index from the input handle */
-    input_child_idx = GET_IDX(input_ctx_handle);
-    /* Get parent index of input referenced child component */
-    input_parent_idx = component_ctx_array[input_child_idx].parent_idx;
+    /* Get parent component index from the input handle */
+    parent_ctx_idx = GET_IDX(input_ctx_handle);
 
     /* Below check is for safety only; It should not happen
-     * input_child_idx is already checked above in is_input_handle_valid()
+     * parent_ctx_idx is already checked above in is_input_handle_valid()
      */
-    assert(input_parent_idx < MAX_NUM_OF_COMPONENTS);
+    assert(parent_ctx_idx < MAX_NUM_OF_COMPONENTS);
 
-    child_ctx = &component_ctx_array[input_child_idx];
-    parent_ctx = &component_ctx_array[input_parent_idx];
+    parent_ctx = &component_ctx_array[parent_ctx_idx];
 
     //TODO:  Question: how to get mhu id of incoming request?
     if (!is_input_client_id_valid(client_id)) {
         return DPE_INVALID_ARGUMENT;
     }
 
-    /* Copy dice input to the child component context */
-    err = copy_dice_input(child_ctx, dice_inputs);
+    /* Get next free component index to add new derived context */
+    free_component_idx = get_free_component_context_index();
+    if (free_component_idx < 0) {
+        return DPE_INSUFFICIENT_MEMORY;
+    }
+
+    derived_ctx = &component_ctx_array[free_component_idx];
+    /* Copy dice input to the new derived component context */
+    err = copy_dice_input(derived_ctx, dice_inputs);
     if (err != DPE_NO_ERROR) {
         return err;
     }
 
-    if (create_certificate) {
-        err = create_layer_certificate(child_ctx->linked_layer_idx);
-        if (err != DPE_NO_ERROR) {
-            return err;
-        }
-    }
-
-    /* Renew nonce of child context so it cannot be used again */
-    child_ctx->nonce = INVALID_NONCE_VALUE;
-
-    if (allow_child_to_derive) {
-        /* Generate new handle for child for subsequent requests */
-        if (generate_new_handle(new_child_ctx_handle) != DPE_NO_ERROR) {
-            return DPE_INTERNAL_ERROR;
-        }
-        /* Update the component context array element as pointed by newly generated handle */
-        new_ctx = &component_ctx_array[GET_IDX(*new_child_ctx_handle)];
-        /* Update nonce in new child component context */
-        new_ctx->nonce = GET_NONCE(*new_child_ctx_handle);
-        /* Update parent idx in new child component context */
-        new_ctx->parent_idx = input_child_idx;
-        /* Mark new child component index as in use */
-        new_ctx->in_use = true;
-        err = assign_layer_to_context(new_ctx);
-        if (err != DPE_NO_ERROR) {
-            return err;
-        }
-    } else {
-        /* Child not deriving any children */
-        /* Tag this component as a leaf */
-        child_ctx->is_leaf = true;
-        invalidate_handle(new_child_ctx_handle);
+    /* Update parent idx in new derived component context */
+    derived_ctx->parent_idx = parent_ctx_idx;
+    /* Mark new derived component index as in use */
+    derived_ctx->in_use = true;
+    err = assign_layer_to_context(derived_ctx);
+    if (err != DPE_NO_ERROR) {
+        return err;
     }
 
     if (retain_parent_context) {
-        /* Parent deriving multiple children */
-        /* Generate new handle for child for the same parent for subsequent requests */
-        if (generate_new_handle(new_parent_ctx_handle) != DPE_NO_ERROR) {
-            return DPE_INTERNAL_ERROR;
-        }
-        /* Update the component context array element as pointed by newly generated handle */
-        new_ctx = &component_ctx_array[GET_IDX(*new_parent_ctx_handle)];
-        /* Update nonce in new child component context */
-        new_ctx->nonce = GET_NONCE(*new_parent_ctx_handle);
-        /* Update parent idx in new child component context */
-        new_ctx->parent_idx = input_parent_idx;
-        /* Mark new child component index as in use */
-        new_ctx->in_use = true;
-        err = assign_layer_to_context(new_ctx);
+        /* Retain and return parent handle with renewed nonce */
+        *new_parent_context_handle = input_ctx_handle;
+        err = renew_nonce(new_parent_context_handle);
         if (err != DPE_NO_ERROR) {
             return err;
         }
+        parent_ctx->nonce = GET_NONCE(*new_parent_context_handle);
+
     } else {
-        /* Parent not deriving any more children */
-        /* No need to return parent handle */
-        invalidate_handle(new_parent_ctx_handle);
-        /* Renew nonce of parent context so it cannot be used again */
+        /* Return invalid handle */
+        *new_parent_context_handle = INVALID_HANDLE;
         parent_ctx->nonce = INVALID_NONCE_VALUE;
     }
 
+    if (allow_new_context_to_derive) {
+        /* Return handle to derived context */
+        *new_context_handle = SET_IDX(*new_context_handle, free_component_idx);
+        err = renew_nonce(new_context_handle);
+        if (err != DPE_NO_ERROR) {
+            return err;
+        }
+        /* Update nonce in new derived component context */
+        derived_ctx->nonce = GET_NONCE(*new_context_handle);
+
+    } else {
+        /* Return invalid handle */
+        *new_context_handle = INVALID_HANDLE;
+        derived_ctx->nonce = INVALID_NONCE_VALUE;
+    }
+
+    if (create_certificate) {
+        err = create_layer_certificate(derived_ctx->linked_layer_idx);
+        if (err != DPE_NO_ERROR) {
+            return err;
+        }
+    }
+
     return DPE_NO_ERROR;
 }
 
@@ -612,7 +586,7 @@
 
     log_destroy_context(input_ctx_handle, destroy_recursively);
 
-    /* Get child component index and linked layer from the input handle */
+    /* Get component index and linked layer from the input handle */
     input_ctx_idx = GET_IDX(input_ctx_handle);
 
     /* Validate input handle */
@@ -749,7 +723,7 @@
     }
 
     /* Correct layer should already be assigned in last call of
-     * derive child command
+     * derive context command
      */
     /* Finalise the current layer & create leaf certificate */
     err = create_layer_certificate(input_layer_idx);
diff --git a/partitions/dice_protection_environment/dpe_context_mngr.h b/partitions/dice_protection_environment/dpe_context_mngr.h
index fc9a7e8..df6cafd 100644
--- a/partitions/dice_protection_environment/dpe_context_mngr.h
+++ b/partitions/dice_protection_environment/dpe_context_mngr.h
@@ -102,34 +102,34 @@
 dpe_error_t initialise_context_mngr(int *rot_ctx_handle);
 
 /**
- * \brief Derives a child component context and optionally creates certificate
+ * \brief Derives a component context and optionally creates certificate
  *        chain.
  *
- * \param[in]  input_context_handle      Input handle to child component context
- * \param[in]  retain_parent_context     Flag to indicate if parent context need
- *                                       to be retained. TRUE only if a client
- *                                       is calling DPE commands multiple times
- * \param[in]  allow_child_to_derive     Flag to indicate if requested child can
- *                                       derive further.
- * \param[in]  create_certificate        Flag to indicate if certificate needs
- *                                       to be created. TRUE only if it is the
- *                                       last component in the layer.
- * \param[in]  dice_inputs               Pointer to dice_input buffer.
- * \param[in]  client_id                 Identifier of the client calling the
- *                                       service.
- * \param[out] new_child_context_handle  A new handle for child context.
- * \param[out] new_parent_context_handle A new handle for parent context.
+ * \param[in]  input_context_handle        Input handle to parent component context
+ * \param[in]  retain_parent_context       Flag to indicate if parent context need
+ *                                         to be retained. TRUE only if a client
+ *                                         is calling DPE commands multiple times
+ * \param[in]  allow_new_context_to_derive Flag to indicate if derived context can
+ *                                         derive further.
+ * \param[in]  create_certificate          Flag to indicate if certificate needs
+ *                                         to be created. TRUE only if it is the
+ *                                         last component in the layer.
+ * \param[in]  dice_inputs                 Pointer to dice_input buffer.
+ * \param[in]  client_id                   Identifier of the client calling the
+ *                                         service.
+ * \param[out] new_context_handle          A new handle for derived context.
+ * \param[out] new_parent_context_handle   A new handle for parent context.
  *
  * \return Returns error code of type dpe_error_t
  */
-dpe_error_t derive_child_request(int input_context_handle,
-                                 bool retain_parent_context,
-                                 bool allow_child_to_derive,
-                                 bool create_certificate,
-                                 const DiceInputValues *dice_inputs,
-                                 int32_t client_id,
-                                 int *new_child_context_handle,
-                                 int *new_parent_context_handle);
+dpe_error_t derive_context_request(int input_context_handle,
+                                   bool retain_parent_context,
+                                   bool allow_new_context_to_derive,
+                                   bool create_certificate,
+                                   const DiceInputValues *dice_inputs,
+                                   int32_t client_id,
+                                   int *new_context_handle,
+                                   int *new_parent_context_handle);
 
 /**
  * \brief Destroys a component context and optionally depending on argument
diff --git a/partitions/dice_protection_environment/dpe_log.c b/partitions/dice_protection_environment/dpe_log.c
index d81674c..1b57613 100644
--- a/partitions/dice_protection_environment/dpe_log.c
+++ b/partitions/dice_protection_environment/dpe_log.c
@@ -57,18 +57,18 @@
     log_dice_inputs(dice_inputs);
 }
 
-void log_derive_child(int context_handle,
-                      bool retain_parent_context,
-                      bool allow_child_to_derive,
-                      bool create_certificate,
-                      const DiceInputValues *dice_inputs,
-                      int32_t client_id)
+void log_derive_context(int context_handle,
+                        bool retain_parent_context,
+                        bool allow_new_context_to_derive,
+                        bool create_certificate,
+                        const DiceInputValues *dice_inputs,
+                        int32_t client_id)
 {
-    LOG_DBGFMT("DPE DeriveChild:\r\n");
+    LOG_DBGFMT("DPE DeriveContext:\r\n");
     LOG_DBGFMT(" - context_handle index = %d\r\n", GET_IDX(context_handle));
     LOG_DBGFMT(" - context_handle nonce = %d\r\n", GET_NONCE(context_handle));
     LOG_DBGFMT(" - retain_parent_context = %d\r\n", retain_parent_context);
-    LOG_DBGFMT(" - allow_child_to_derive = %d\r\n", allow_child_to_derive);
+    LOG_DBGFMT(" - allow_new_context_to_derive = %d\r\n", allow_new_context_to_derive);
     LOG_DBGFMT(" - create_certificate = %d\r\n", create_certificate);
     log_dice_inputs(dice_inputs);
     LOG_DBGFMT(" - client_id = %d\r\n", client_id);
diff --git a/partitions/dice_protection_environment/dpe_log.h b/partitions/dice_protection_environment/dpe_log.h
index 9061e27..1f08e94 100644
--- a/partitions/dice_protection_environment/dpe_log.h
+++ b/partitions/dice_protection_environment/dpe_log.h
@@ -23,14 +23,14 @@
 void log_derive_rot_context(const DiceInputValues *dice_inputs);
 
 /**
- * \brief Log the derive child command parameters.
+ * \brief Log the derive context command parameters.
  */
-void log_derive_child(int context_handle,
-                      bool retain_parent_context,
-                      bool allow_child_to_derive,
-                      bool create_certificate,
-                      const DiceInputValues *dice_inputs,
-                      int32_t client_id);
+void log_derive_context(int context_handle,
+                        bool retain_parent_context,
+                        bool allow_new_context_to_derive,
+                        bool create_certificate,
+                        const DiceInputValues *dice_inputs,
+                        int32_t client_id);
 
 /**
  * \brief Log the destroy context command parameters.
@@ -64,7 +64,7 @@
 #else /* TFM_PARTITION_LOG_LEVEL */
 
 #define log_derive_rot_context(...)
-#define log_derive_child(...)
+#define log_derive_context(...)
 #define log_destroy_context(...)
 #define log_certify_key(...)
 #define log_intermediate_certificate(...)
diff --git a/partitions/dice_protection_environment/interface/include/dice_protection_environment.h b/partitions/dice_protection_environment/interface/include/dice_protection_environment.h
index f1e0ef0..952bcd3 100644
--- a/partitions/dice_protection_environment/interface/include/dice_protection_environment.h
+++ b/partitions/dice_protection_environment/interface/include/dice_protection_environment.h
@@ -36,36 +36,36 @@
 #define DPE_ERR_CBOR_FORMATTING       ((dpe_error_t)129)
 
 /**
- * \brief Performs the DICE computation to derive a child context and optionally
+ * \brief Performs the DICE computation to derive a new context and optionally
  *        creates an intermediate certificate. Software component measurement
  *        must be provided in dice_inputs.
  *
- * \param[in]  context_handle             Input context handle for the DPE
- *                                        context.
- * \param[in]  retain_parent_context      Flag to indicate whether to retain the
- *                                        parent context. True only if a client
- *                                        will call further DPE commands on the
- *                                        same context.
- * \param[in]  allow_child_to_derive      Flag to indicate whether child context
- *                                        can derive further. True only if the
- *                                        child will load further components.
- * \param[in]  create_certificate         Flag to indicate whether to create an
- *                                        intermediate certificate. True only if
- *                                        it is the last component in the layer.
- * \param[in]  dice_inputs                DICE input values.
- * \param[out] new_child_context_handle   New handle for the child context.
- * \param[out] new_parent_context_handle  New handle for the parent context.
+ * \param[in]  context_handle              Input context handle for the DPE
+ *                                         context.
+ * \param[in]  retain_parent_context       Flag to indicate whether to retain the
+ *                                         parent context. True only if a client
+ *                                         will call further DPE commands on the
+ *                                         same context.
+ * \param[in]  allow_new_context_to_derive Flag to indicate whether derived context
+ *                                         can derive further. True only if the
+ *                                         new context will load further components.
+ * \param[in]  create_certificate          Flag to indicate whether to create an
+ *                                         intermediate certificate. True only if
+ *                                         it is the last component in the layer.
+ * \param[in]  dice_inputs                 DICE input values.
+ * \param[out] new_context_handle          New handle for the derived context.
+ * \param[out] new_parent_context_handle   New handle for the parent context.
  *
  * \return Returns error code of type dpe_error_t
  */
 dpe_error_t
-dpe_derive_child(int                    context_handle,
-                 bool                   retain_parent_context,
-                 bool                   allow_child_to_derive,
-                 bool                   create_certificate,
-                 const DiceInputValues *dice_inputs,
-                 int                   *new_child_context_handle,
-                 int                   *new_parent_context_handle);
+dpe_derive_context(int                    context_handle,
+                   bool                   retain_parent_context,
+                   bool                   allow_new_context_to_derive,
+                   bool                   create_certificate,
+                   const DiceInputValues *dice_inputs,
+                   int                   *new_context_handle,
+                   int                   *new_parent_context_handle);
 
 /**
  * \brief Destroys a DPE context.
diff --git a/partitions/dice_protection_environment/interface/include/dpe_client.h b/partitions/dice_protection_environment/interface/include/dpe_client.h
index ef4e376..eebef48 100644
--- a/partitions/dice_protection_environment/interface/include/dpe_client.h
+++ b/partitions/dice_protection_environment/interface/include/dpe_client.h
@@ -26,7 +26,7 @@
     DPE_EXPORT_SESSION = 5,
     DPE_IMPORT_SESSION = 6,
     DPE_INITIALIZE_CONTEXT = 7,
-    DPE_DERIVE_CHILD = 8,
+    DPE_DERIVE_CONTEXT = 8,
     DPE_CERTIFY_KEY = 9,
     DPE_SIGN = 10,
     DPE_SEAL = 11,
@@ -48,15 +48,15 @@
     DICE_HIDDEN = 9,
 };
 
-enum dpe_derive_child_input_labels_t {
-    DPE_DERIVE_CHILD_CONTEXT_HANDLE = 1,
-    DPE_DERIVE_CHILD_RETAIN_PARENT_CONTEXT = 2,
-    DPE_DERIVE_CHILD_ALLOW_CHILD_TO_DERIVE = 3,
-    DPE_DERIVE_CHILD_CREATE_CERTIFICATE = 4,
-    DPE_DERIVE_CHILD_NEW_SESSION_INITIATOR_HANDSHAKE = 5,
-    DPE_DERIVE_CHILD_NEW_SESSION_IS_MIGRATABLE = 6,
-    DPE_DERIVE_CHILD_INPUT_DATA = 7,
-    DPE_DERIVE_CHILD_INTERNAL_INPUTS = 8,
+enum dpe_derive_context_input_labels_t {
+    DPE_DERIVE_CONTEXT_CONTEXT_HANDLE = 1,
+    DPE_DERIVE_CONTEXT_RETAIN_PARENT_CONTEXT = 2,
+    DPE_DERIVE_CONTEXT_ALLOW_NEW_CONTEXT_TO_DERIVE = 3,
+    DPE_DERIVE_CONTEXT_CREATE_CERTIFICATE = 4,
+    DPE_DERIVE_CONTEXT_NEW_SESSION_INITIATOR_HANDSHAKE = 5,
+    DPE_DERIVE_CONTEXT_NEW_SESSION_IS_MIGRATABLE = 6,
+    DPE_DERIVE_CONTEXT_INPUT_DATA = 7,
+    DPE_DERIVE_CONTEXT_INTERNAL_INPUTS = 8,
 };
 
 enum dpe_destroy_context_input_labels_t {
@@ -64,10 +64,10 @@
     DPE_DESTROY_CONTEXT_RECURSIVELY = 2,
 };
 
-enum dpe_derive_child_output_labels_t {
-    DPE_DERIVE_CHILD_NEW_CONTEXT_HANDLE = 1,
-    DPE_DERIVE_CHILD_NEW_SESSION_RESPONDER_HANDSHAKE = 2,
-    DPE_DERIVE_CHILD_PARENT_CONTEXT_HANDLE = 3,
+enum dpe_derive_context_output_labels_t {
+    DPE_DERIVE_CONTEXT_NEW_CONTEXT_HANDLE = 1,
+    DPE_DERIVE_CONTEXT_NEW_SESSION_RESPONDER_HANDSHAKE = 2,
+    DPE_DERIVE_CONTEXT_PARENT_CONTEXT_HANDLE = 3,
 };
 
 enum dpe_certify_key_input_labels_t {
diff --git a/partitions/dice_protection_environment/interface/src/dpe_cmd_encode.c b/partitions/dice_protection_environment/interface/src/dpe_cmd_encode.c
index 8abf30f..2c4757d 100644
--- a/partitions/dice_protection_environment/interface/src/dpe_cmd_encode.c
+++ b/partitions/dice_protection_environment/interface/src/dpe_cmd_encode.c
@@ -12,16 +12,16 @@
 #include "qcbor/qcbor_decode.h"
 #include "qcbor/qcbor_spiffy_decode.h"
 
-struct derive_child_input_t {
+struct derive_context_input_t {
     int context_handle;
     bool retain_parent_context;
-    bool allow_child_to_derive;
+    bool allow_new_context_to_derive;
     bool create_certificate;
     const DiceInputValues *dice_inputs;
 };
 
-struct derive_child_output_t {
-    int new_child_context_handle;
+struct derive_context_output_t {
+    int new_context_handle;
     int new_parent_context_handle;
 };
 
@@ -51,7 +51,7 @@
                                const DiceInputValues *input)
 {
     /* Wrap the DICE inputs into a byte string */
-    QCBOREncode_BstrWrapInMapN(encode_ctx, DPE_DERIVE_CHILD_INPUT_DATA);
+    QCBOREncode_BstrWrapInMapN(encode_ctx, DPE_DERIVE_CONTEXT_INPUT_DATA);
 
     /* Inside the byte string the DICE inputs are encoded as a map */
     QCBOREncode_OpenMap(encode_ctx);
@@ -95,27 +95,27 @@
     QCBOREncode_CloseBstrWrap2(encode_ctx, true, NULL);
 }
 
-static QCBORError encode_derive_child(const struct derive_child_input_t *args,
-                                      UsefulBuf buf,
-                                      UsefulBufC *encoded_buf)
+static QCBORError encode_derive_context(const struct derive_context_input_t *args,
+                                        UsefulBuf buf,
+                                        UsefulBufC *encoded_buf)
 {
     QCBOREncodeContext encode_ctx;
 
     QCBOREncode_Init(&encode_ctx, buf);
 
     QCBOREncode_OpenArray(&encode_ctx);
-    QCBOREncode_AddUInt64(&encode_ctx, DPE_DERIVE_CHILD);
+    QCBOREncode_AddUInt64(&encode_ctx, DPE_DERIVE_CONTEXT);
 
-    /* Encode DeriveChild command */
+    /* Encode DeriveContext command */
     QCBOREncode_OpenMap(&encode_ctx);
-    QCBOREncode_AddBytesToMapN(&encode_ctx, DPE_DERIVE_CHILD_CONTEXT_HANDLE,
+    QCBOREncode_AddBytesToMapN(&encode_ctx, DPE_DERIVE_CONTEXT_CONTEXT_HANDLE,
                                (UsefulBufC){ &args->context_handle,
                                              sizeof(args->context_handle) });
-    QCBOREncode_AddBoolToMapN(&encode_ctx, DPE_DERIVE_CHILD_RETAIN_PARENT_CONTEXT,
+    QCBOREncode_AddBoolToMapN(&encode_ctx, DPE_DERIVE_CONTEXT_RETAIN_PARENT_CONTEXT,
                               args->retain_parent_context);
-    QCBOREncode_AddBoolToMapN(&encode_ctx, DPE_DERIVE_CHILD_ALLOW_CHILD_TO_DERIVE,
-                              args->allow_child_to_derive);
-    QCBOREncode_AddBoolToMapN(&encode_ctx, DPE_DERIVE_CHILD_CREATE_CERTIFICATE,
+    QCBOREncode_AddBoolToMapN(&encode_ctx, DPE_DERIVE_CONTEXT_ALLOW_NEW_CONTEXT_TO_DERIVE,
+                              args->allow_new_context_to_derive);
+    QCBOREncode_AddBoolToMapN(&encode_ctx, DPE_DERIVE_CONTEXT_CREATE_CERTIFICATE,
                               args->create_certificate);
     encode_dice_inputs(&encode_ctx, args->dice_inputs);
     QCBOREncode_CloseMap(&encode_ctx);
@@ -150,9 +150,9 @@
     return QCBOREncode_Finish(&encode_ctx, encoded_buf);
 }
 
-static QCBORError decode_derive_child_response(UsefulBufC encoded_buf,
-                                               struct derive_child_output_t *args,
-                                               dpe_error_t *dpe_err)
+static QCBORError decode_derive_context_response(UsefulBufC encoded_buf,
+                                                 struct derive_context_output_t *args,
+                                                 dpe_error_t *dpe_err)
 {
     QCBORDecodeContext decode_ctx;
     UsefulBufC out;
@@ -166,20 +166,20 @@
     QCBORDecode_GetInt64(&decode_ctx, &response_dpe_err);
     *dpe_err = (dpe_error_t)response_dpe_err;
 
-    /* Decode DeriveChild response if successful */
+    /* Decode DeriveContext response if successful */
     if (*dpe_err == DPE_NO_ERROR) {
         QCBORDecode_EnterMap(&decode_ctx, NULL);
 
         QCBORDecode_GetByteStringInMapN(&decode_ctx,
-                                        DPE_DERIVE_CHILD_NEW_CONTEXT_HANDLE,
+                                        DPE_DERIVE_CONTEXT_NEW_CONTEXT_HANDLE,
                                         &out);
-        if (out.len != sizeof(args->new_child_context_handle)) {
+        if (out.len != sizeof(args->new_context_handle)) {
             return QCBORDecode_Finish(&decode_ctx);
         }
-        memcpy(&args->new_child_context_handle, out.ptr, out.len);
+        memcpy(&args->new_context_handle, out.ptr, out.len);
 
         QCBORDecode_GetByteStringInMapN(&decode_ctx,
-                                        DPE_DERIVE_CHILD_PARENT_CONTEXT_HANDLE,
+                                        DPE_DERIVE_CONTEXT_PARENT_CONTEXT_HANDLE,
                                         &out);
         if (out.len != sizeof(args->new_parent_context_handle)) {
             return QCBORDecode_Finish(&decode_ctx);
@@ -291,13 +291,13 @@
     return QCBORDecode_Finish(&decode_ctx);
 }
 
-dpe_error_t dpe_derive_child(int context_handle,
-                             bool retain_parent_context,
-                             bool allow_child_to_derive,
-                             bool create_certificate,
-                             const DiceInputValues *dice_inputs,
-                             int *new_child_context_handle,
-                             int *new_parent_context_handle)
+dpe_error_t dpe_derive_context(int context_handle,
+                               bool retain_parent_context,
+                               bool allow_new_context_to_derive,
+                               bool create_certificate,
+                               const DiceInputValues *dice_inputs,
+                               int *new_context_handle,
+                               int *new_parent_context_handle)
 {
     int32_t service_err;
     dpe_error_t dpe_err;
@@ -305,16 +305,16 @@
     UsefulBufC encoded_buf;
     UsefulBuf_MAKE_STACK_UB(cmd_buf, 512);
 
-    const struct derive_child_input_t in_args = {
+    const struct derive_context_input_t in_args = {
         context_handle,
         retain_parent_context,
-        allow_child_to_derive,
+        allow_new_context_to_derive,
         create_certificate,
         dice_inputs,
     };
-    struct derive_child_output_t out_args;
+    struct derive_context_output_t out_args;
 
-    qcbor_err = encode_derive_child(&in_args, cmd_buf, &encoded_buf);
+    qcbor_err = encode_derive_context(&in_args, cmd_buf, &encoded_buf);
     if (qcbor_err != QCBOR_SUCCESS) {
         return DPE_INTERNAL_ERROR;
     }
@@ -325,8 +325,8 @@
         return DPE_INTERNAL_ERROR;
     }
 
-    qcbor_err = decode_derive_child_response(UsefulBuf_Const(cmd_buf),
-                                             &out_args, &dpe_err);
+    qcbor_err = decode_derive_context_response(UsefulBuf_Const(cmd_buf),
+                                               &out_args, &dpe_err);
     if (qcbor_err != QCBOR_SUCCESS) {
         return DPE_INTERNAL_ERROR;
     } else if (dpe_err != DPE_NO_ERROR) {
@@ -334,7 +334,7 @@
     }
 
     /* Copy returned values into caller's memory */
-    *new_child_context_handle = out_args.new_child_context_handle;
+    *new_context_handle = out_args.new_context_handle;
     *new_parent_context_handle = out_args.new_parent_context_handle;
 
     return DPE_NO_ERROR;