Coverage Report

Created: 2025-07-18 06:52

/src/dropbear/src/ltc_prng.c
Line
Count
Source (jump to first uncovered line)
1
/* Copied from libtomcrypt/src/prngs/sprng.c and modified to
2
 * use Dropbear's genrandom(). */
3
4
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
5
 *
6
 * LibTomCrypt is a library that provides various cryptographic
7
 * algorithms in a highly modular and flexible manner.
8
 *
9
 * The library is free for all purposes without any express
10
 * guarantee it works.
11
 *
12
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
13
 */
14
#include "includes.h"
15
#include "dbrandom.h"
16
#include "ltc_prng.h"
17
18
/**
19
   @file sprng.c
20
   Secure PRNG, Tom St Denis
21
*/
22
   
23
/* A secure PRNG using the RNG functions.  Basically this is a
24
 * wrapper that allows you to use a secure RNG as a PRNG
25
 * in the various other functions.
26
 */
27
28
#if DROPBEAR_LTC_PRNG
29
30
/**
31
  Start the PRNG
32
  @param prng     [out] The PRNG state to initialize
33
  @return CRYPT_OK if successful
34
*/  
35
int dropbear_prng_start(prng_state* UNUSED(prng))
36
0
{
37
0
   return CRYPT_OK;  
38
0
}
39
40
/**
41
  Add entropy to the PRNG state
42
  @param in       The data to add
43
  @param inlen    Length of the data to add
44
  @param prng     PRNG state to update
45
  @return CRYPT_OK if successful
46
*/  
47
int dropbear_prng_add_entropy(const unsigned char* UNUSED(in), unsigned long UNUSED(inlen), prng_state* UNUSED(prng))
48
0
{
49
0
   return CRYPT_OK;
50
0
}
51
52
/**
53
  Make the PRNG ready to read from
54
  @param prng   The PRNG to make active
55
  @return CRYPT_OK if successful
56
*/  
57
int dropbear_prng_ready(prng_state* UNUSED(prng))
58
0
{
59
0
   return CRYPT_OK;
60
0
}
61
62
/**
63
  Read from the PRNG
64
  @param out      Destination
65
  @param outlen   Length of output
66
  @param prng     The active PRNG to read from
67
  @return Number of octets read
68
*/  
69
unsigned long dropbear_prng_read(unsigned char* out, unsigned long outlen, prng_state* UNUSED(prng))
70
0
{
71
0
   LTC_ARGCHK(out != NULL);
72
0
   genrandom(out, outlen);
73
0
   return outlen;
74
0
}
75
76
/**
77
  Terminate the PRNG
78
  @param prng   The PRNG to terminate
79
  @return CRYPT_OK if successful
80
*/  
81
int dropbear_prng_done(prng_state* UNUSED(prng))
82
0
{
83
0
   return CRYPT_OK;
84
0
}
85
86
/**
87
  Export the PRNG state
88
  @param out       [out] Destination
89
  @param outlen    [in/out] Max size and resulting size of the state
90
  @param prng      The PRNG to export
91
  @return CRYPT_OK if successful
92
*/  
93
int dropbear_prng_export(unsigned char* UNUSED(out), unsigned long* outlen, prng_state* UNUSED(prng))
94
0
{
95
0
   LTC_ARGCHK(outlen != NULL);
96
97
0
   *outlen = 0;
98
0
   return CRYPT_OK;
99
0
}
100
 
101
/**
102
  Import a PRNG state
103
  @param in       The PRNG state
104
  @param inlen    Size of the state
105
  @param prng     The PRNG to import
106
  @return CRYPT_OK if successful
107
*/  
108
int dropbear_prng_import(const unsigned char* UNUSED(in), unsigned long UNUSED(inlen), prng_state* UNUSED(prng))
109
0
{
110
0
   return CRYPT_OK;
111
0
}
112
113
/**
114
  PRNG self-test
115
  @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
116
*/  
117
int dropbear_prng_test(void)
118
0
{
119
0
   return CRYPT_OK;
120
0
}
121
122
const struct ltc_prng_descriptor dropbear_prng_desc =
123
{
124
    "dropbear_prng", 0,
125
    dropbear_prng_start,
126
    dropbear_prng_add_entropy,
127
    dropbear_prng_ready,
128
    dropbear_prng_read,
129
    dropbear_prng_done,
130
    dropbear_prng_export,
131
    dropbear_prng_import,
132
    dropbear_prng_test
133
};
134
135
136
#endif /* DROPBEAR_LTC_PRNG */