LCOV - code coverage report
Current view: top level - src/edhoc - prk.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 4 11 36.4 %
Date: 2024-09-16 20:15:30 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 14 7.1 %

           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/buffer_sizes.h"
      15                 :            : 
      16                 :            : #include "edhoc/suites.h"
      17                 :            : #include "edhoc/prk.h"
      18                 :            : #include "edhoc/okm.h"
      19                 :            : 
      20                 :            : #include "common/crypto_wrapper.h"
      21                 :            : #include "common/oscore_edhoc_error.h"
      22                 :            : #include "common/print_util.h"
      23                 :            : #include "common/memcpy_s.h"
      24                 :            : 
      25                 :         12 : enum err prk_derive(bool static_dh_auth, struct suite suite, uint8_t label,
      26                 :            :                     struct byte_array *context, const struct byte_array *prk_in,
      27                 :            :                     const struct byte_array *stat_pk,
      28                 :            :                     const struct byte_array *stat_sk, uint8_t *prk_out)
      29                 :            : {
      30         [ -  + ]:         12 :         if (static_dh_auth) {
      31         [ #  # ]:          0 :                 BYTE_ARRAY_NEW(dh_secret, ECDH_SECRET_SIZE, ECDH_SECRET_SIZE);
      32                 :            : 
      33         [ #  # ]:          0 :                 TRY(shared_secret_derive(suite.edhoc_ecdh, stat_sk, stat_pk,
      34                 :            :                                          dh_secret.ptr));
      35                 :          0 :                 PRINT_ARRAY("dh_secret", dh_secret.ptr, dh_secret.len);
      36                 :            : 
      37   [ #  #  #  # ]:          0 :                 BYTE_ARRAY_NEW(salt, HASH_SIZE, get_hash_len(suite.edhoc_hash));
      38         [ #  # ]:          0 :                 TRY(edhoc_kdf(suite.edhoc_hash, prk_in, label, context, &salt));
      39                 :          0 :                 PRINT_ARRAY("SALT_3e2m or SALT4e3m", salt.ptr, salt.len);
      40                 :            : 
      41         [ #  # ]:          0 :                 TRY(hkdf_extract(suite.edhoc_hash, &salt, &dh_secret, prk_out));
      42                 :            :         } else {
      43                 :            :                 /*it is save to do that since prks have the same size*/
      44                 :         12 :                 memcpy(prk_out, prk_in->ptr, prk_in->len);
      45                 :            :         }
      46                 :         12 :         return ok;
      47                 :            : }

Generated by: LCOV version 1.14