Skip to content

Commit 9b0b631

Browse files
theamirocohenYossi Levy
authored andcommitted
Fix messages
1 parent 11f1aaf commit 9b0b631

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

TESTS/mbed_hal/trng/main.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
8484
memset(buffer, 0, BUFFER_LEN);
8585

8686
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);
8888
TEST_ASSERT_EQUAL_INT_MESSAGE(0, trng_res, "trng_get_bytes error!");
8989
temp_size += output_length;
9090
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)
102102
static void compress_and_compare(char *key, char *value)
103103
{
104104
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};
106106
uint8_t input_buf[BUFFER_LEN * 4] = {0}, temp_buf[BUFFER_LEN * 2] = {0};
107107
size_t comp_sz = 0;
108108
unsigned int result = 0;
@@ -119,10 +119,12 @@ static void compress_and_compare(char *key, char *value)
119119
TEST_ASSERT_EQUAL(RESULT_SUCCESS, result);
120120
#else
121121
/*Using base64 to decode data sent from host*/
122+
122123
uint32_t lengthWritten = 0;
123124
uint32_t charsProcessed = 0;
124125
result = trng_DecodeNBase64((const char *)value,
125-
MSG_VALUE_LEN, buffer,
126+
MSG_VALUE_LEN,
127+
buffer,
126128
BUFFER_LEN,
127129
&lengthWritten,
128130
&charsProcessed);
@@ -131,20 +133,22 @@ static void compress_and_compare(char *key, char *value)
131133
memcpy(input_buf, buffer, sizeof(buffer));
132134
}
133135

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+
}
138142
/*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) {
140144

141145
comp_sz = pithy_Compress((char *)buffer,
142146
sizeof(buffer),
143147
(char *)out_comp_buf,
144148
sizeof(out_comp_buf),
145149
9);
146150
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");
148152

149153
/*pithy_Compress will try to compress the random data with a different buffer sizem*/
150154
result = fill_buffer_trng(temp_buf, &trng_obj, sizeof(temp_buf));
@@ -156,18 +160,17 @@ static void compress_and_compare(char *key, char *value)
156160
sizeof(out_comp_buf),
157161
9);
158162
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");
160164

161165
memcpy(input_buf + sizeof(buffer), temp_buf, sizeof(temp_buf));
162-
163166
/*pithy_Compress will try to compress the random data from before reset concatenated with new random data*/
164167
comp_sz = pithy_Compress((char *)input_buf,
165168
sizeof(temp_buf) + sizeof(buffer),
166169
(char *)out_comp_buf,
167170
sizeof(out_comp_buf),
168171
9);
169172
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");
171174
}
172175

173176
/*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)
178181
TEST_ASSERT_EQUAL(RESULT_SUCCESS, result);
179182
#else
180183
/*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));
182188
TEST_ASSERT_EQUAL(RESULT_SUCCESS, result);
189+
183190
greentea_send_kv(MSG_TRNG_BUFFER, (const char *)out_comp_buf);
184191
#endif
185192
system_reset();

0 commit comments

Comments
 (0)