]> git.saurik.com Git - apple/securityd.git/blob - src/entropy.h
2dbdc07735760aa06c0960ebafb34b6c1b229bcb
[apple/securityd.git] / src / entropy.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27 //
28 // yarrowseed - periodical to collect and seed entropy into /dev/random
29 //
30 #ifndef _H_ENTROPY
31 #define _H_ENTROPY
32
33 #include <security_utilities/machserver.h>
34 #include <security_utilities/timeflow.h>
35 #include <security_utilities/devrandom.h>
36
37 using namespace Security;
38 using MachPlusPlus::MachServer;
39
40
41 //
42 // A (one-off) timer object that manages system entropy
43 //
44 class EntropyManager : public MachServer::Timer, private DevRandomGenerator {
45 // all the parameters you ever (should) want to change :-)
46 static const int collectInterval = 600; // collect every 10 minutes
47 static const int updateInterval = 3600; // update file every hour
48 static const int timingsToCollect = 40; // how many timings?
49
50 public:
51 EntropyManager(MachPlusPlus::MachServer &srv, const char *entropyFile);
52
53 void action();
54
55 MachPlusPlus::MachServer &server; // to which we do setTimer()
56
57 private:
58 string mEntropyFilePath; // absolute path to entropy file
59 Time::Absolute mNextUpdate; // next time for entropy file update
60
61 void collectEntropy(); // collect system timings and seed RNG
62 void updateEntropyFile(); // update entropy file from RNG if it's time
63
64 static const size_t entropyFileSize = 20; // bytes (effectively one SHA-1 worth)
65 };
66
67 #endif //_H_ENTROPY