LCOV - code coverage report
Current view: top level - library/spdm_crypt_lib/fips - libspdm_selftest_sha2.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.6 % 42 33
Test Date: 2026-03-15 08:15:47 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2023-2026 DMTF. All rights reserved.
       4              :  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
       5              :  **/
       6              : 
       7              : #include "internal/libspdm_crypt_lib.h"
       8              : #include "internal/libspdm_fips_lib.h"
       9              : #include "internal/libspdm_common_lib.h"
      10              : 
      11              : #if LIBSPDM_FIPS_MODE
      12              : 
      13            1 : void libspdm_fips_selftest_sha256(void *fips_selftest_context)
      14              : {
      15              : #if LIBSPDM_SHA256_SUPPORT
      16            1 :     bool result = true;
      17              : 
      18            1 :     libspdm_fips_selftest_context_t *context = fips_selftest_context;
      19            1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
      20              : 
      21              :     /* any test fail cause the FIPS fail*/
      22            1 :     if (context->tested_algo != context->self_test_result) {
      23            0 :         return;
      24              :     }
      25              : 
      26              :     /* check if run before.*/
      27            1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA256) != 0) {
      28            0 :         return;
      29              :     }
      30              : 
      31            1 :     libspdm_fips_selftest_hmac_sha256(context);
      32            1 :     result = (context->self_test_result & LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256) != 0;
      33              : 
      34              :     /* mark it as tested*/
      35            1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA256;
      36              : 
      37              :     /* record test result*/
      38            1 :     if (result) {
      39            1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA256;
      40              :     } else {
      41            0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA256;
      42              :     }
      43              : #endif /*LIBSPDM_SHA256_SUPPORT*/
      44              : }
      45              : 
      46            1 : void libspdm_fips_selftest_sha384(void *fips_selftest_context)
      47              : {
      48              : #if LIBSPDM_SHA384_SUPPORT
      49            1 :     bool result = true;
      50              : 
      51            1 :     libspdm_fips_selftest_context_t *context = fips_selftest_context;
      52            1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
      53              : 
      54              :     /* any test fail cause the FIPS fail*/
      55            1 :     if (context->tested_algo != context->self_test_result) {
      56            0 :         return;
      57              :     }
      58              : 
      59              :     /* check if run before.*/
      60            1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA384) != 0) {
      61            0 :         return;
      62              :     }
      63              : 
      64            1 :     libspdm_fips_selftest_hmac_sha384(context);
      65            1 :     result = (context->self_test_result & LIBSPDM_FIPS_SELF_TEST_HMAC_SHA384) != 0;
      66              : 
      67              :     /* mark it as tested*/
      68            1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA384;
      69              : 
      70              :     /* record test result*/
      71            1 :     if (result) {
      72            1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA384;
      73              :     } else {
      74            0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA384;
      75              :     }
      76              : #endif /*LIBSPDM_SHA384_SUPPORT*/
      77              : }
      78              : 
      79            1 : void libspdm_fips_selftest_sha512(void *fips_selftest_context)
      80              : {
      81              : #if LIBSPDM_SHA512_SUPPORT
      82            1 :     bool result = true;
      83              : 
      84            1 :     libspdm_fips_selftest_context_t *context = fips_selftest_context;
      85            1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
      86              : 
      87              :     /* any test fail cause the FIPS fail*/
      88            1 :     if (context->tested_algo != context->self_test_result) {
      89            0 :         return;
      90              :     }
      91              : 
      92              :     /* check if run before.*/
      93            1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA512) != 0) {
      94            0 :         return;
      95              :     }
      96              : 
      97            1 :     libspdm_fips_selftest_hmac_sha512(context);
      98            1 :     result = (context->self_test_result & LIBSPDM_FIPS_SELF_TEST_HMAC_SHA512) != 0;
      99              : 
     100              :     /* mark it as tested*/
     101            1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA512;
     102              : 
     103              :     /* record test result*/
     104            1 :     if (result) {
     105            1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA512;
     106              :     } else {
     107            0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA512;
     108              :     }
     109              : #endif /*LIBSPDM_SHA512_SUPPORT*/
     110              : }
     111              : 
     112              : #endif/*LIBSPDM_FIPS_MODE*/
        

Generated by: LCOV version 2.0-1