File tree Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Original file line number Diff line number Diff line change 25
25
/*
26
26
* Get Random number generator.
27
27
*/
28
+
29
+ #define PRNG_KEY_SIZE (0x20UL)
30
+
28
31
static volatile int g_PRNG_done ;
29
32
volatile int g_AES_done ;
30
33
@@ -82,18 +85,19 @@ void trng_free(trng_t *obj)
82
85
int trng_get_bytes (trng_t * obj , uint8_t * output , size_t length , size_t * output_length )
83
86
{
84
87
(void )obj ;
85
- unsigned char tmpBuff [32 ];
88
+ unsigned char tmpBuff [PRNG_KEY_SIZE ];
86
89
size_t cur_length = 0 ;
87
90
88
- for ( unsigned i = 0 ; i < ( length / 32 ); i ++ ) {
91
+ while ( length >= sizeof ( tmpBuff ) ) {
89
92
trng_get (output );
90
- cur_length += 32 ;
91
- output += 32 ;
92
- }
93
- if ( length > cur_length ) {
93
+ output += sizeof (tmpBuff );
94
+ cur_length += sizeof (tmpBuff );
95
+ length -= sizeof (tmpBuff );
96
+ }
97
+ if (length > 0 ) {
94
98
trng_get (tmpBuff );
95
- memcpy (output , & tmpBuff , ( length - cur_length ) );
96
- cur_length = length ;
99
+ memcpy (output , tmpBuff , length );
100
+ cur_length + = length ;
97
101
trng_zeroize (tmpBuff , sizeof (tmpBuff ));
98
102
}
99
103
* output_length = cur_length ;
Original file line number Diff line number Diff line change 30
30
/*
31
31
* Get Random number generator.
32
32
*/
33
+
34
+ #define PRNG_KEY_SIZE (0x20UL)
35
+
33
36
static volatile int g_PRNG_done ;
34
37
volatile int g_AES_done ;
35
38
@@ -87,18 +90,19 @@ void trng_free(trng_t *obj)
87
90
int trng_get_bytes (trng_t * obj , uint8_t * output , size_t length , size_t * output_length )
88
91
{
89
92
(void )obj ;
90
- unsigned char tmpBuff [32 ];
93
+ unsigned char tmpBuff [PRNG_KEY_SIZE ];
91
94
size_t cur_length = 0 ;
92
95
93
- for ( unsigned i = 0 ; i < ( length / 32 ); i ++ ) {
96
+ while ( length >= sizeof ( tmpBuff ) ) {
94
97
trng_get (output );
95
- cur_length += 32 ;
96
- output += 32 ;
97
- }
98
- if ( length > cur_length ) {
98
+ output += sizeof (tmpBuff );
99
+ cur_length += sizeof (tmpBuff );
100
+ length -= sizeof (tmpBuff );
101
+ }
102
+ if (length > 0 ) {
99
103
trng_get (tmpBuff );
100
- memcpy (output , & tmpBuff , ( length - cur_length ) );
101
- cur_length = length ;
104
+ memcpy (output , tmpBuff , length );
105
+ cur_length + = length ;
102
106
trng_zeroize (tmpBuff , sizeof (tmpBuff ));
103
107
}
104
108
* output_length = cur_length ;
You can’t perform that action at this time.
0 commit comments