-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accumulator.cpp
70 lines (66 loc) · 1.92 KB
/
Accumulator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Accumulator.h"
Accumulator::Accumulator()
: sourceNode(NULL)
, sourceDeviceCount(0x0)
{
}
Accumulator::~Accumulator()
{
if (sourceNode != NULL)
{
if (sourceNode->next != NULL)
{
SourceNodeStruct *sourceNodeNext;
do
{
sourceNodeNext = sourceNode->next;
delete sourceNode;
sourceNode = sourceNodeNext;
} while (sourceNode != NULL);
} else
{
delete sourceNode;
}
}
}
bool Accumulator::registerEntropySource(Source *source)
{
if (sourceDeviceCount <= 255)
{
source->setSourceId(sourceDeviceCount);
if (sourceNode)
{
SourceNodeStruct *sourceNodeCpy = sourceNode;
while (sourceNodeCpy->next)
{
sourceNodeCpy = sourceNodeCpy->next;
}
SourceNodeStruct *newSourceNode = new SourceNodeStruct();
newSourceNode->source = source;
newSourceNode->sourceNumber = sourceDeviceCount++;
newSourceNode->next = NULL;
sourceNodeCpy->next = newSourceNode;
} else
{
//First entry
sourceNode = new SourceNodeStruct;
sourceNode->source = source;
sourceNode->sourceNumber = sourceDeviceCount++;
sourceNode->next = NULL;
}
return 1;
}
return 0;
}
void Accumulator::addEventData(PRNGState *prngState)
{
SourceNodeStruct *sourceNodeCopy = sourceNode;
for (uint8_t sourceIndex = 0; sourceIndex < sourceDeviceCount; sourceIndex++)
{
uint8_t poolNumber = 0;
uint8_t entropySize = 0;
uint8_t *entropy = sourceNodeCopy->source->getEntropy(&poolNumber, &entropySize);
prngState->getPool(poolNumber)->addEntropy(entropy, entropySize, sourceNodeCopy->source->getSourceNumber());
sourceNodeCopy = sourceNodeCopy->next;
}
}