Botan  2.4.0
Crypto and TLS for C++11
darwin_secrandom.cpp
Go to the documentation of this file.
1 /*
2 * Darwin SecRandomCopyBytes EntropySource
3 * (C) 2015 Daniel Seither (Kullo GmbH)
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/internal/darwin_secrandom.h>
9 #include <Security/Security.h>
10 #include <Security/SecRandom.h>
11 
12 namespace Botan {
13 
14 /**
15 * Gather entropy from SecRandomCopyBytes
16 */
18  {
19  secure_vector<uint8_t> buf(BOTAN_SYSTEM_RNG_POLL_REQUEST);
20 
21  if(0 == SecRandomCopyBytes(kSecRandomDefault, buf.size(), buf.data()))
22  {
23  rng.add_entropy(buf.data(), buf.size());
24  return buf.size() * 8;
25  }
26 
27  return 0;
28  }
29 
30 }
virtual void add_entropy(const uint8_t input[], size_t length)=0
size_t poll(RandomNumberGenerator &rng) override
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88