aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp
diff options
context:
space:
mode:
authorDaniel Seither <[email protected]>2015-09-25 14:10:01 +0200
committerDaniel Seither <[email protected]>2015-09-25 14:10:01 +0200
commitee0460cff538a3de7ca89fb54d37215757659a42 (patch)
tree9e2c04abf1b84c7cadbd81cd819aab1cf4e508fd /src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp
parent84fc298cce26305f7eae59ce59a82ebd9801a04e (diff)
Add the Darwin_SecRandom entropy source
It uses the SecRandomCopyBytes function from the Security framework of OS X and iOS. We need this because it is the official way to get cryptographically secure random numbers on iOS, where /dev/random is not accessible due to sandboxing.
Diffstat (limited to 'src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp')
-rw-r--r--src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp b/src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp
new file mode 100644
index 000000000..f04b75a12
--- /dev/null
+++ b/src/lib/entropy/darwin_secrandom/darwin_secrandom.cpp
@@ -0,0 +1,28 @@
+/*
+* Darwin SecRandomCopyBytes EntropySource
+* (C) 2015 Daniel Seither (Kullo GmbH)
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/internal/darwin_secrandom.h>
+#include <Security/Security.h>
+
+namespace Botan {
+
+/**
+* Gather entropy from SecRandomCopyBytes
+*/
+void Darwin_SecRandom::poll(Entropy_Accumulator& accum)
+ {
+ const size_t ENTROPY_BITS_PER_BYTE = 8;
+ const size_t BUF_SIZE = 256;
+
+ m_buf.resize(BUF_SIZE);
+ if (0 == SecRandomCopyBytes(kSecRandomDefault, m_buf.size(), m_buf.data()))
+ {
+ accum.add(m_buf.data(), m_buf.size(), ENTROPY_BITS_PER_BYTE);
+ }
+ }
+
+}