LCOV - code coverage report
Current view: top level - os_stub/rnglib - rng_linux.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 58.3 % 12 7
Test Date: 2025-06-29 08:09:00 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-2022 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 <base.h>
       8              : #include <stdlib.h>
       9              : #include "stdio.h"
      10              : #include <unistd.h>
      11              : #include <fcntl.h>
      12              : #include <assert.h>
      13              : 
      14              : /**
      15              :  * Generates a 64-bit random number.
      16              :  *
      17              :  * if rand is NULL, then LIBSPDM_ASSERT().
      18              :  *
      19              :  * @param[out] rand_data     buffer pointer to store the 64-bit random value.
      20              :  *
      21              :  * @retval true         Random number generated successfully.
      22              :  * @retval false        Failed to generate the random number.
      23              :  *
      24              :  **/
      25        13956 : bool libspdm_get_random_number_64(uint64_t *rand_data)
      26              : {
      27              :     int fd;
      28              : 
      29        13956 :     assert(rand_data != NULL);
      30              : 
      31        13956 :     fd = open("/dev/urandom", O_RDONLY);
      32        13956 :     if (fd < 0) {
      33            0 :         printf("cannot open /dev/urandom\n");
      34            0 :         return false;
      35              :     }
      36        13956 :     if (read(fd, rand_data, sizeof(*rand_data)) != sizeof(*rand_data)) {
      37            0 :         printf("Cannot read /dev/urandom\n");
      38            0 :         close(fd);
      39            0 :         return false;
      40              :     }
      41        13956 :     close(fd);
      42              : 
      43        13956 :     return true;
      44              : }
        

Generated by: LCOV version 2.0-1