diff options
-rw-r--r-- | lib/libssl/tls13_handshake.c | 6 | ||||
-rw-r--r-- | regress/lib/libssl/handshake/handshake_table.c | 50 | ||||
-rw-r--r-- | regress/lib/libssl/handshake/valid_handshakes_terminate.c | 4 |
3 files changed, 47 insertions, 13 deletions
diff --git a/lib/libssl/tls13_handshake.c b/lib/libssl/tls13_handshake.c index 5863b0363be..f9cb3e5b476 100644 --- a/lib/libssl/tls13_handshake.c +++ b/lib/libssl/tls13_handshake.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_handshake.c,v 1.21 2019/01/23 11:11:52 tb Exp $ */ +/* $OpenBSD: tls13_handshake.c,v 1.22 2019/01/23 23:29:56 tb Exp $ */ /* * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> @@ -246,14 +246,14 @@ enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES] = { }, }; -#define NUM_HANDSHAKES (sizeof(handshakes) / sizeof(handshakes[0])) +const size_t handshake_count = sizeof(handshakes) / sizeof(handshakes[0]); enum tls13_message_type tls13_handshake_active_state(struct tls13_ctx *ctx) { struct tls13_handshake_stage hs = ctx->handshake_stage; - if (hs.hs_type >= NUM_HANDSHAKES) + if (hs.hs_type >= handshake_count) return INVALID; if (hs.message_number >= TLS13_NUM_MESSAGE_TYPES) return INVALID; diff --git a/regress/lib/libssl/handshake/handshake_table.c b/regress/lib/libssl/handshake/handshake_table.c index 183fd3417bf..9ddd6a5b67b 100644 --- a/regress/lib/libssl/handshake/handshake_table.c +++ b/regress/lib/libssl/handshake/handshake_table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: handshake_table.c,v 1.2 2019/01/23 08:42:05 tb Exp $ */ +/* $OpenBSD: handshake_table.c,v 1.3 2019/01/23 23:29:56 tb Exp $ */ /* * Copyright (c) 2019 Theo Buehler <tb@openbsd.org> * @@ -75,8 +75,6 @@ * */ -extern enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES]; - struct child { enum tls13_message_type mt; uint8_t flag; @@ -131,6 +129,7 @@ static struct child stateinfo[][TLS13_NUM_MESSAGE_TYPES] = { }, }; +size_t count_handshakes(void); const char *flag2str(uint8_t flag); void print_flags(uint8_t flags); const char *mt2str(enum tls13_message_type mt); @@ -152,8 +151,8 @@ flag2str(uint8_t flag) errx(1, "more than one bit is set"); switch (flag) { - case DEFAULT: - ret = ""; + case INITIAL: + ret = "INITIAL"; break; case NEGOTIATED: ret = "NEGOTIATED"; @@ -250,6 +249,11 @@ print_flags(uint8_t flags) { int first = 1, i; + if (flags == 0) { + printf("%s", flag2str(flags)); + return; + } + for (i = 0; i < 8; i++) { uint8_t set = flags & (1U << i); @@ -278,6 +282,22 @@ print_entry(enum tls13_message_type path[TLS13_NUM_MESSAGE_TYPES], printf("\t},\n"); } +extern enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES]; +extern size_t handshake_count; + +size_t +count_handshakes(void) +{ + size_t ret = 0, i; + + for (i = 0; i < handshake_count; i++) { + if (handshakes[i][0] != INVALID) + ret++; + } + + return ret; +} + void build_table(enum tls13_message_type table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES], 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], int print) { int success = 1, i; + size_t num_valid, num_found = 0; uint8_t flags = 0; do { - flags++; if (table[flags][0] == 0) continue; + num_found++; + for (i = 0; i < TLS13_NUM_MESSAGE_TYPES; i++) { if (table[flags][i] != handshakes[flags][i]) { printf("incorrect entry %d of handshake ", i); @@ -340,7 +362,14 @@ verify_table(enum tls13_message_type table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES], if (print) print_entry(table[flags], flags); - } while(flags != UINT8_MAX); + } while(++flags != 0); + + num_valid = count_handshakes(); + if (num_valid != num_found) { + printf("incorrect number of handshakes: want %zu, got %zu.\n", + num_valid, num_found); + success = 0; + } return success; } @@ -356,7 +385,12 @@ int main(int argc, char *argv[]) { static enum tls13_message_type - hs_table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES]; + hs_table[UINT8_MAX][TLS13_NUM_MESSAGE_TYPES] = { + [INITIAL] = { + CLIENT_HELLO, + SERVER_HELLO, + }, + }; struct child start = { CLIENT_HELLO, NEGOTIATED, 0, 0, }; diff --git a/regress/lib/libssl/handshake/valid_handshakes_terminate.c b/regress/lib/libssl/handshake/valid_handshakes_terminate.c index df870876443..18e441d1a1b 100644 --- a/regress/lib/libssl/handshake/valid_handshakes_terminate.c +++ b/regress/lib/libssl/handshake/valid_handshakes_terminate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: valid_handshakes_terminate.c,v 1.1 2019/01/20 06:47:38 tb Exp $ */ +/* $OpenBSD: valid_handshakes_terminate.c,v 1.2 2019/01/23 23:29:56 tb Exp $ */ /* * Copyright (c) 2019 Theo Buehler <tb@openbsd.org> * @@ -27,7 +27,7 @@ main(int argc, char *argv[]) int terminates; int fail = 0; - for (i = 1; i < NUM_HANDSHAKES; i++) { + for (i = 1; i < handshake_count; i++) { enum tls13_message_type mt = handshakes[i][0]; if (mt == INVALID) |