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-02-22 08:11:49 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 : bool libspdm_fips_selftest_sha256(void *fips_selftest_context)
      14              : {
      15            1 :     bool result = true;
      16              : 
      17              : #if LIBSPDM_SHA256_SUPPORT
      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 false;
      24              :     }
      25              : 
      26              :     /* check if run before.*/
      27            1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA256) != 0) {
      28            0 :         return true;
      29              :     }
      30              : 
      31            1 :     result = libspdm_fips_selftest_hmac_sha256(context);
      32              : 
      33              :     /* mark it as tested*/
      34            1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA256;
      35              : 
      36              :     /* record test result*/
      37            1 :     if (result) {
      38            1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA256;
      39              :     } else {
      40            0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA256;
      41              :     }
      42              : #endif /*LIBSPDM_SHA256_SUPPORT*/
      43              : 
      44            1 :     return result;
      45              : }
      46              : 
      47            1 : bool libspdm_fips_selftest_sha384(void *fips_selftest_context)
      48              : {
      49            1 :     bool result = true;
      50              : 
      51              : #if LIBSPDM_SHA384_SUPPORT
      52            1 :     libspdm_fips_selftest_context_t *context = fips_selftest_context;
      53            1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
      54              : 
      55              :     /* any test fail cause the FIPS fail*/
      56            1 :     if (context->tested_algo != context->self_test_result) {
      57            0 :         return false;
      58              :     }
      59              : 
      60              :     /* check if run before.*/
      61            1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA384) != 0) {
      62            0 :         return true;
      63              :     }
      64              : 
      65            1 :     result = libspdm_fips_selftest_hmac_sha384(context);
      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            1 :     return result;
      79              : }
      80              : 
      81            1 : bool libspdm_fips_selftest_sha512(void *fips_selftest_context)
      82              : {
      83            1 :     bool result = true;
      84              : 
      85              : #if LIBSPDM_SHA512_SUPPORT
      86            1 :     libspdm_fips_selftest_context_t *context = fips_selftest_context;
      87            1 :     LIBSPDM_ASSERT(fips_selftest_context != NULL);
      88              : 
      89              :     /* any test fail cause the FIPS fail*/
      90            1 :     if (context->tested_algo != context->self_test_result) {
      91            0 :         return false;
      92              :     }
      93              : 
      94              :     /* check if run before.*/
      95            1 :     if ((context->tested_algo & LIBSPDM_FIPS_SELF_TEST_SHA512) != 0) {
      96            0 :         return true;
      97              :     }
      98              : 
      99            1 :     result = libspdm_fips_selftest_hmac_sha512(context);
     100              : 
     101              :     /* mark it as tested*/
     102            1 :     context->tested_algo |= LIBSPDM_FIPS_SELF_TEST_SHA512;
     103              : 
     104              :     /* record test result*/
     105            1 :     if (result) {
     106            1 :         context->self_test_result |= LIBSPDM_FIPS_SELF_TEST_SHA512;
     107              :     } else {
     108            0 :         context->self_test_result &= ~LIBSPDM_FIPS_SELF_TEST_SHA512;
     109              :     }
     110              : #endif /*LIBSPDM_SHA512_SUPPORT*/
     111              : 
     112            1 :     return result;
     113              : }
     114              : 
     115              : #endif/*LIBSPDM_FIPS_MODE*/
        

Generated by: LCOV version 2.0-1