LCOV - code coverage report
Current view: top level - src/edhoc - hkdf_info.c (source / functions) Coverage Total Hit
Test: lcov.info Lines: 92.3 % 13 12
Test Date: 2026-03-12 12:01:18 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 66.7 % 6 4

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :    Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
       3                 :             :    file at the top-level directory of this distribution.
       4                 :             : 
       5                 :             :    Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
       6                 :             :    http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
       7                 :             :    <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
       8                 :             :    option. This file may not be copied, modified, or distributed
       9                 :             :    except according to those terms.
      10                 :             : */
      11                 :             : 
      12                 :             : #include <string.h>
      13                 :             : 
      14                 :             : #include "edhoc/suites.h"
      15                 :             : #include "edhoc/hkdf_info.h"
      16                 :             : 
      17                 :             : #include "common/byte_array.h"
      18                 :             : #include "common/oscore_edhoc_error.h"
      19                 :             : 
      20                 :             : #include "cbor/edhoc_encode_info.h"
      21                 :             : 
      22                 :          52 : enum err create_hkdf_info(uint8_t label, struct byte_array *context,
      23                 :             :                           uint32_t okm_len, struct byte_array *out)
      24                 :             : {
      25                 :             :         struct info info;
      26                 :             : 
      27                 :          52 :         info.info_label = label;
      28                 :             : 
      29                 :             :         /* NULL context with zero size is acceptable from EDHOC point of view,
      30                 :             :          * but CBOR encoder does not accept NULL as input argument.
      31                 :             :          * Internally it calls memmove that generates runtime error when input
      32                 :             :          * is NULL even if length is set to 0.
      33                 :             :          * Workaround is to provide dummy buffer to avoid passing NULL. It does not
      34                 :             :          * impact the EDHOC process, since context length is set to 0 and no value
      35                 :             :          * is copied to the EDHOC message. */
      36                 :             :         const char dummy_buffer;
      37                 :             : 
      38         [ +  + ]:          52 :         if (NULL == context->ptr) {
      39         [ -  + ]:          15 :                 if (0 != context->len) {
      40                 :           0 :                         return wrong_parameter;
      41                 :             :                 } else {
      42                 :          15 :                         info.info_context.value =
      43                 :             :                                 (const uint8_t *)&dummy_buffer;
      44                 :             :                 }
      45                 :             :         } else {
      46                 :          37 :                 info.info_context.value = context->ptr;
      47                 :             :         }
      48                 :             : 
      49                 :          52 :         info.info_context.len = context->len;
      50                 :             : 
      51                 :          52 :         info.info_length = okm_len;
      52                 :             : 
      53                 :          52 :         size_t payload_len_out = 0;
      54         [ -  + ]:          52 :         TRY_EXPECT(cbor_encode_info(out->ptr, out->len, &info,
      55                 :             :                                     &payload_len_out),
      56                 :             :                    0);
      57                 :             : 
      58                 :          52 :         out->len = (uint32_t)payload_len_out;
      59                 :             : 
      60                 :          52 :         return ok;
      61                 :             : }
        

Generated by: LCOV version 2.0-1