This repository has been archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entropy.h
109 lines (100 loc) · 3.63 KB
/
entropy.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (c)
* (c) 2015-2016 Chintalagiri Shashank, Quazar Technologies Pvt. Ltd.
*
* This file is part of
* Embedded bootstraps : hal-uC
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file hal_uc_entropy.h
* @brief HAL for uC entropy source
*
* This file is the hardware abstraction layer for generation of entropy
* from the uC.
*
* It must be noted that in most, if not all platforms, the actual entropy
* sources may not be available during program execution. Typical utilization
* of the Entropy API in most cases should be limited to an initial
* accumulation of sufficient entropy as needed by the application to
* initialize a PRNG. This period of entropy accumulation should occur before
* major subsystem initialization, and it should be assumed that during this
* period various peripherals would not behave as expected otherwise.
*
* For example, the MSP430 entropy sources will take over both ACLK and SMCLK,
* and anything depending on those clocks, including system time, for
* instance, will misbehave. On other platforms, ADCs may be unavailable
* during accumulation.
*
* The application must ensure to exit the entropy accumulation mode after it
* has sufficient entropy and before any major initialization steps are takem.
*
* This layer should not and does not do any hashing or heavy computation.
* Using such mathematical means to generate a byte stream is left to the
* application layer, which may use whatever algorithms or libraries to
* provide a bulk pseudo-random stream if needed.
*
*/
#ifndef HAL_UC_ENTROPY_H
#define HAL_UC_ENTROPY_H
#include "map.h"
/**
* @name Entropy API Functions
*
*/
/**@{*/
/**
* @brief Enter the entropy accumulation mode.
*
* This function will take over and reconfigure some peripherals in order
* to accumulate entropy. The implementation of this function should ensure
* that it keeps a copy of everything it changes so that it can later be
* restored during deinitialization.
*
* @warning You should make sure that doing this does not interfere with
* any peripherals you may already have initialized on your
* application and on your platform.
*
* @see entropy_deinit()
*
*/
void entropy_init(void);
/**
* @brief Get one byte of entropy.
*
* When called when in the entropy accumulation mode, this function will
* accumulate and return one byte of entropy. This should be assumed to
* be a blocking call and is expected to be used only in the early stages
* of application initialization.
*
*/
uint8_t entropy_get_byte(void);
/**
* @brief Leave the entropy accumulation mode.
*
* This function should also return everything that it changed to how it
* found it during initialization.
*
* @warning This function should be called to exit the entropy accumulation
* mode before any major perhipheral or subsystem initialization.
*
* @see entropy_deinit()
*
*/
void entropy_deinit(void);
/**@}*/
// Set up the implementation
#include "uc/entropy_impl.h"
#endif