-
Notifications
You must be signed in to change notification settings - Fork 3
/
prandom.h
77 lines (64 loc) · 2.58 KB
/
prandom.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
/** \file prandom.h
*
* \brief Describes functions exported by prandom.c.
*
* This file is licensed as described by the file LICENCE.
*/
#ifndef PRANDOM_H_INCLUDED
#define PRANDOM_H_INCLUDED
#include "common.h"
#include "bignum256.h"
#include "storage_common.h"
#ifdef TEST
#include "ecdsa.h"
#endif // #ifdef TEST
#ifdef __cplusplus
extern "C" {
#endif
/** Length, in bytes, of the seed that generateDeterministic256() requires.
* \warning This must be a multiple of 16 in order for backupWallet() to work
* properly.
*/
#define SEED_LENGTH 64
/** Length, in bytes, of the persistent entropy pool. This should be at least
* 32 to ensure that even in the event of complete undetected failure of the
* HWRNG, the outputs of getRandom256() still have nearly 256 bits of
* entropy.
*/
#define ENTROPY_POOL_LENGTH 32
/** Length, in bytes, of the persistent entropy pool checksum. This can be
* less than 32 because the checksum is only used to detect modification to
* the persistent entropy pool.
*/
#define POOL_CHECKSUM_LENGTH 16
/** Length, in characters, of the OTP (one-time password) generated by
* the generateInsecureOTP() function. This includes the terminating null.
*/
#define OTP_LENGTH 5
// Some sanity checks.
#if ENTROPY_POOL_LENGTH > (POOL_CHECKSUM_ADDRESS - ADDRESS_ENTROPY_POOL)
#error ENTROPY_POOL_LENGTH is too big
#endif
#if POOL_CHECKSUM_LENGTH > (DEVICE_UUID_ADDRESS - POOL_CHECKSUM_ADDRESS)
#error POOL_CHECKSUM_LENGTH is too big
#endif
extern void clearParentPublicKeyCache(void);
extern bool setEntropyPool(uint8_t *in_pool_state);
extern bool getEntropyPool(uint8_t *out_pool_state);
extern bool initialiseEntropyPool(uint8_t *initial_pool_state);
extern bool getRandom256(BigNum256 n);
extern bool getRandom256TemporaryPool(BigNum256 n, uint8_t *pool_state);
extern void generateInsecureOTP(char *otp);
extern void generateInsecurePIN(char *otp, int length);
extern bool generateDeterministic256(BigNum256 out, const uint8_t *seed, const uint32_t chain_lvl_1, const uint32_t chain_lvl_2, const uint32_t chain_lvl_3);
//extern bool generateDeterministic256(BigNum256 out, const uint8_t *seed, const uint32_t num);
extern bool getXPUBfromNode(BigNum256 out, const uint8_t *seed, const uint32_t num);
#ifdef TEST
extern void initialiseDefaultEntropyPool(void);
extern void corruptEntropyPool(void);
extern void generateDeterministicPublicKey(PointAffine *out_public_key, PointAffine *in_parent_public_key, const uint8_t *chain_code, const uint32_t num);
#endif // #ifdef TEST
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif // #ifndef PRANDOM_H_INCLUDED