summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2019-01-23 23:29:56 +0000
committertb <>2019-01-23 23:29:56 +0000
commit4a91b4654c78d359cb9e0cc479b358b673046f5d (patch)
tree00e8a6dabd3ac7eb9c0d1d00b72dadf795283d7c /src
parent06e6b71d917b831ea28543a745e306fa001eaf62 (diff)
downloadopenbsd-4a91b4654c78d359cb9e0cc479b358b673046f5d.tar.gz
openbsd-4a91b4654c78d359cb9e0cc479b358b673046f5d.tar.bz2
openbsd-4a91b4654c78d359cb9e0cc479b358b673046f5d.zip
Rename NUM_HANDSHAKE to handshake_count and make it a variable
so it can be used from regress. Update regress accordingly. Make sure the print target generates the entire table as it currently is in tls13_handshake.c discussed with beck and jsing ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/tls13_handshake.c6
-rw-r--r--src/regress/lib/libssl/handshake/handshake_table.c50
-rw-r--r--src/regress/lib/libssl/handshake/valid_handshakes_terminate.c4
3 files changed, 47 insertions, 13 deletions
diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c
index 5863b0363b..f9cb3e5b47 100644
--- a/src/lib/libssl/tls13_handshake.c
+++ b/src/lib/libssl/tls13_handshake.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_handshake.c,v 1.21 2019/01/23 11:11:52 tb Exp $ */ 1/* $OpenBSD: tls13_handshake.c,v 1.22 2019/01/23 23:29:56 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org>
4 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
@@ -246,14 +246,14 @@ enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES] = {
246 }, 246 },
247}; 247};
248 248
249#define NUM_HANDSHAKES (sizeof(handshakes) / sizeof(handshakes[0])) 249const size_t handshake_count = sizeof(handshakes) / sizeof(handshakes[0]);
250 250
251enum tls13_message_type 251enum tls13_message_type
252tls13_handshake_active_state(struct tls13_ctx *ctx) 252tls13_handshake_active_state(struct tls13_ctx *ctx)
253{ 253{
254 struct tls13_handshake_stage hs = ctx->handshake_stage; 254 struct tls13_handshake_stage hs = ctx->handshake_stage;
255 255
256 if (hs.hs_type >= NUM_HANDSHAKES) 256 if (hs.hs_type >= handshake_count)
257 return INVALID; 257 return INVALID;
258 if (hs.message_number >= TLS13_NUM_MESSAGE_TYPES) 258 if (hs.message_number >= TLS13_NUM_MESSAGE_TYPES)
259 return INVALID; 259 return INVALID;
diff --git a/src/regress/lib/libssl/handshake/handshake_table.c b/src/regress/lib/libssl/handshake/handshake_table.c
index 183fd3417b..9ddd6a5b67 100644
--- a/src/regress/lib/libssl/handshake/handshake_table.c
+++ b/src/regress/lib/libssl/handshake/handshake_table.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: handshake_table.c,v 1.2 2019/01/23 08:42:05 tb Exp $ */ 1/* $OpenBSD: handshake_table.c,v 1.3 2019/01/23 23:29:56 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2019 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -75,8 +75,6 @@
75 * 75 *
76 */ 76 */
77 77
78extern enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES];
79
80struct child { 78struct child {
81 enum tls13_message_type mt; 79 enum tls13_message_type mt;
82 uint8_t flag; 80 uint8_t flag;
@@ -131,6 +129,7 @@ static struct child stateinfo[][TLS13_NUM_MESSAGE_TYPES] = {
131 }, 129 },
132}; 130};
133 131
132size_t count_handshakes(void);
134const char *flag2str(uint8_t flag); 133const char *flag2str(uint8_t flag);
135void print_flags(uint8_t flags); 134void print_flags(uint8_t flags);
136const char *mt2str(enum tls13_message_type mt); 135const char *mt2str(enum tls13_message_type mt);
@@ -152,8 +151,8 @@ flag2str(uint8_t flag)
152 errx(1, "more than one bit is set"); 151 errx(1, "more than one bit is set");
153 152
154 switch (flag) { 153 switch (flag) {
155 case DEFAULT: 154 case INITIAL:
156 ret = ""; 155 ret = "INITIAL";
157 break; 156 break;
158 case NEGOTIATED: 157 case NEGOTIATED:
159 ret = "NEGOTIATED"; 158 ret = "NEGOTIATED";
@@ -250,6 +249,11 @@ print_flags(uint8_t flags)
250{ 249{
251 int first = 1, i; 250 int first = 1, i;
252 251
252 if (flags == 0) {
253 printf("%s", flag2str(flags));
254 return;
255 }
256
253 for (i = 0; i < 8; i++) { 257 for (i = 0; i < 8; i++) {
254 uint8_t set = flags & (1U << i); 258 uint8_t set = flags & (1U << i);
255 259
@@ -278,6 +282,22 @@ print_entry(enum tls13_message_type path[TLS13_NUM_MESSAGE_TYPES],
278 printf("\t},\n"); 282 printf("\t},\n");
279} 283}
280 284
285extern enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES];
286extern size_t handshake_count;
287
288size_t
289count_handshakes(void)
290{
291 size_t ret = 0, i;
292
293 for (i = 0; i < handshake_count; i++) {
294 if (handshakes[i][0] != INVALID)
295 ret++;
296 }
297
298 return ret;
299}
300
281void 301void
282build_table(enum tls13_message_type table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES], 302build_table(enum tls13_message_type table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES],
283 struct child current, struct child end, struct child path[], uint8_t flags, 303 struct child current, struct child end, struct child path[], uint8_t flags,
@@ -322,13 +342,15 @@ verify_table(enum tls13_message_type table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES],
322 int print) 342 int print)
323{ 343{
324 int success = 1, i; 344 int success = 1, i;
345 size_t num_valid, num_found = 0;
325 uint8_t flags = 0; 346 uint8_t flags = 0;
326 347
327 do { 348 do {
328 flags++;
329 if (table[flags][0] == 0) 349 if (table[flags][0] == 0)
330 continue; 350 continue;
331 351
352 num_found++;
353
332 for (i = 0; i < TLS13_NUM_MESSAGE_TYPES; i++) { 354 for (i = 0; i < TLS13_NUM_MESSAGE_TYPES; i++) {
333 if (table[flags][i] != handshakes[flags][i]) { 355 if (table[flags][i] != handshakes[flags][i]) {
334 printf("incorrect entry %d of handshake ", i); 356 printf("incorrect entry %d of handshake ", i);
@@ -340,7 +362,14 @@ verify_table(enum tls13_message_type table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES],
340 362
341 if (print) 363 if (print)
342 print_entry(table[flags], flags); 364 print_entry(table[flags], flags);
343 } while(flags != UINT8_MAX); 365 } while(++flags != 0);
366
367 num_valid = count_handshakes();
368 if (num_valid != num_found) {
369 printf("incorrect number of handshakes: want %zu, got %zu.\n",
370 num_valid, num_found);
371 success = 0;
372 }
344 373
345 return success; 374 return success;
346} 375}
@@ -356,7 +385,12 @@ int
356main(int argc, char *argv[]) 385main(int argc, char *argv[])
357{ 386{
358 static enum tls13_message_type 387 static enum tls13_message_type
359 hs_table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES]; 388 hs_table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES] = {
389 [INITIAL] = {
390 CLIENT_HELLO,
391 SERVER_HELLO,
392 },
393 };
360 struct child start = { 394 struct child start = {
361 CLIENT_HELLO, NEGOTIATED, 0, 0, 395 CLIENT_HELLO, NEGOTIATED, 0, 0,
362 }; 396 };
diff --git a/src/regress/lib/libssl/handshake/valid_handshakes_terminate.c b/src/regress/lib/libssl/handshake/valid_handshakes_terminate.c
index df87087644..18e441d1a1 100644
--- a/src/regress/lib/libssl/handshake/valid_handshakes_terminate.c
+++ b/src/regress/lib/libssl/handshake/valid_handshakes_terminate.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: valid_handshakes_terminate.c,v 1.1 2019/01/20 06:47:38 tb Exp $ */ 1/* $OpenBSD: valid_handshakes_terminate.c,v 1.2 2019/01/23 23:29:56 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2019 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -27,7 +27,7 @@ main(int argc, char *argv[])
27 int terminates; 27 int terminates;
28 int fail = 0; 28 int fail = 0;
29 29
30 for (i = 1; i < NUM_HANDSHAKES; i++) { 30 for (i = 1; i < handshake_count; i++) {
31 enum tls13_message_type mt = handshakes[i][0]; 31 enum tls13_message_type mt = handshakes[i][0];
32 32
33 if (mt == INVALID) 33 if (mt == INVALID)