@@ -84,7 +84,7 @@ static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
84
84
memset (buffer, 0 , BUFFER_LEN);
85
85
86
86
while (true ) {
87
- trng_res = trng_get_bytes (trng_obj, temp_in_buf, trng_len, &output_length);
87
+ trng_res = trng_get_bytes (trng_obj, temp_in_buf, trng_len - temp_size , &output_length);
88
88
TEST_ASSERT_EQUAL_INT_MESSAGE (0 , trng_res, " trng_get_bytes error!" );
89
89
temp_size += output_length;
90
90
temp_in_buf += output_length;
@@ -102,7 +102,7 @@ static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
102
102
static void compress_and_compare (char *key, char *value)
103
103
{
104
104
trng_t trng_obj;
105
- uint8_t out_comp_buf[(BUFFER_LEN * 8 ) + 32 ] = {0 }, buffer[BUFFER_LEN] = {0 };
105
+ uint8_t out_comp_buf[(BUFFER_LEN * 5 ) + 32 ] = {0 }, buffer[BUFFER_LEN] = {0 };
106
106
uint8_t input_buf[BUFFER_LEN * 4 ] = {0 }, temp_buf[BUFFER_LEN * 2 ] = {0 };
107
107
size_t comp_sz = 0 ;
108
108
unsigned int result = 0 ;
@@ -119,10 +119,12 @@ static void compress_and_compare(char *key, char *value)
119
119
TEST_ASSERT_EQUAL (RESULT_SUCCESS, result);
120
120
#else
121
121
/* Using base64 to decode data sent from host*/
122
+
122
123
uint32_t lengthWritten = 0 ;
123
124
uint32_t charsProcessed = 0 ;
124
125
result = trng_DecodeNBase64 ((const char *)value,
125
- MSG_VALUE_LEN, buffer,
126
+ MSG_VALUE_LEN,
127
+ buffer,
126
128
BUFFER_LEN,
127
129
&lengthWritten,
128
130
&charsProcessed);
@@ -131,20 +133,22 @@ static void compress_and_compare(char *key, char *value)
131
133
memcpy (input_buf, buffer, sizeof (buffer));
132
134
}
133
135
134
- /* Fill buffer with trng values*/
135
- result = fill_buffer_trng (buffer, &trng_obj, sizeof (buffer));
136
- TEST_ASSERT_EQUAL (0 , result);
137
-
136
+ if (strcmp (key, MSG_TRNG_TEST_STEP1) == 0 ) {
137
+ /* Fill buffer with trng values*/
138
+ result = fill_buffer_trng (buffer, &trng_obj, sizeof (buffer));
139
+ TEST_ASSERT_EQUAL (0 , result);
140
+ memcpy (input_buf, buffer, sizeof (buffer));
141
+ }
138
142
/* pithy_Compress will try to compress the random data, if it succeeded it means the data is not really random*/
139
- if (strcmp (key, MSG_TRNG_TEST_STEP2) == 0 ) {
143
+ else if (strcmp (key, MSG_TRNG_TEST_STEP2) == 0 ) {
140
144
141
145
comp_sz = pithy_Compress ((char *)buffer,
142
146
sizeof (buffer),
143
147
(char *)out_comp_buf,
144
148
sizeof (out_comp_buf),
145
149
9 );
146
150
TEST_ASSERT_MESSAGE (comp_sz > sizeof (buffer),
147
- " TRNG_TEST_STEP1: trng_get_bytes was able to compressed thus not random" );
151
+ " TRNG_TEST_STEP1: trng_get_bytes was able to compress thus not random" );
148
152
149
153
/* pithy_Compress will try to compress the random data with a different buffer sizem*/
150
154
result = fill_buffer_trng (temp_buf, &trng_obj, sizeof (temp_buf));
@@ -156,18 +160,17 @@ static void compress_and_compare(char *key, char *value)
156
160
sizeof (out_comp_buf),
157
161
9 );
158
162
TEST_ASSERT_MESSAGE (comp_sz > sizeof (temp_buf),
159
- " TRNG_TEST_STEP2: trng_get_bytes was able to compressed thus not random" );
163
+ " TRNG_TEST_STEP2: trng_get_bytes was able to compress thus not random" );
160
164
161
165
memcpy (input_buf + sizeof (buffer), temp_buf, sizeof (temp_buf));
162
-
163
166
/* pithy_Compress will try to compress the random data from before reset concatenated with new random data*/
164
167
comp_sz = pithy_Compress ((char *)input_buf,
165
168
sizeof (temp_buf) + sizeof (buffer),
166
169
(char *)out_comp_buf,
167
170
sizeof (out_comp_buf),
168
171
9 );
169
172
TEST_ASSERT_MESSAGE (comp_sz > sizeof (temp_buf) + sizeof (buffer),
170
- " TRNG_TEST_STEP3: concatenated buffer after reset was able to compressed thus not random" );
173
+ " TRNG_TEST_STEP3: concatenated buffer after reset was able to compress thus not random" );
171
174
}
172
175
173
176
/* At the end of step 1 store trng buffer and reset the device*/
@@ -178,8 +181,12 @@ static void compress_and_compare(char *key, char *value)
178
181
TEST_ASSERT_EQUAL (RESULT_SUCCESS, result);
179
182
#else
180
183
/* Using base64 to encode data sending from host*/
181
- result = trng_EncodeBase64 (buffer, BUFFER_LEN, (char *)out_comp_buf, sizeof (out_comp_buf));
184
+ result = trng_EncodeBase64 (buffer,
185
+ BUFFER_LEN,
186
+ (char *)out_comp_buf,
187
+ sizeof (out_comp_buf));
182
188
TEST_ASSERT_EQUAL (RESULT_SUCCESS, result);
189
+
183
190
greentea_send_kv (MSG_TRNG_BUFFER, (const char *)out_comp_buf);
184
191
#endif
185
192
system_reset ();
0 commit comments