Coverage Report

Created: 2023-02-22 06:39

/src/botan/src/lib/entropy/getentropy/getentropy.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* System Call getentropy(2)
3
* (C) 2017 Alexander Bluhm (genua GmbH)
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/internal/getentropy.h>
9
10
#if defined(BOTAN_TARGET_OS_IS_OPENBSD) || defined(BOTAN_TARGET_OS_IS_FREEBSD) || defined(BOTAN_TARGET_OS_IS_SOLARIS)
11
   #include <unistd.h>
12
#else
13
   #include <sys/types.h> // older macOS needs this before sys/random.h
14
   #include <sys/random.h>
15
#endif
16
17
namespace Botan {
18
19
/**
20
* Gather 256 bytes entropy from getentropy(2).  Note that maximum
21
* buffer size is limited to 256 bytes.  On OpenBSD this does neither
22
* block nor fail.
23
*/
24
size_t Getentropy::poll(RandomNumberGenerator& rng)
25
0
   {
26
0
   secure_vector<uint8_t> buf(256);
27
28
0
   if(::getentropy(buf.data(), buf.size()) == 0)
29
0
      {
30
0
      rng.add_entropy(buf.data(), buf.size());
31
0
      return buf.size() * 8;
32
0
      }
33
34
0
   return 0;
35
0
   }
36
}