summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls13_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/tls13_lib.c')
-rw-r--r--src/lib/libssl/tls13_lib.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c
index 174da2f9c3..b5939aecab 100644
--- a/src/lib/libssl/tls13_lib.c
+++ b/src/lib/libssl/tls13_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_lib.c,v 1.50 2020/05/22 02:37:27 beck Exp $ */ 1/* $OpenBSD: tls13_lib.c,v 1.51 2020/06/06 01:40:09 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2019 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2019 Bob Beck <beck@openbsd.org>
@@ -486,3 +486,82 @@ tls13_synthetic_handshake_message(struct tls13_ctx *ctx)
486 486
487 return ret; 487 return ret;
488} 488}
489
490int
491tls13_clienthello_hash_init(struct tls13_ctx *ctx)
492{
493 if (ctx->hs->clienthello_md_ctx != NULL)
494 return 0;
495 if ((ctx->hs->clienthello_md_ctx = EVP_MD_CTX_new()) == NULL)
496 return 0;
497 if (!EVP_DigestInit_ex(ctx->hs->clienthello_md_ctx,
498 EVP_sha256(), NULL))
499 return 0;
500
501 if ((ctx->hs->clienthello_hash == NULL) &&
502 (ctx->hs->clienthello_hash = calloc(1, EVP_MAX_MD_SIZE)) ==
503 NULL)
504 return 0;
505
506 return 1;
507}
508
509void
510tls13_clienthello_hash_clear(struct ssl_handshake_tls13_st *hs)
511{
512 EVP_MD_CTX_free(hs->clienthello_md_ctx);
513 hs->clienthello_md_ctx = NULL;
514 freezero(hs->clienthello_hash, EVP_MAX_MD_SIZE);
515 hs->clienthello_hash = NULL;
516}
517
518int
519tls13_clienthello_hash_update_bytes(struct tls13_ctx *ctx, void *data,
520 size_t len)
521{
522 return EVP_DigestUpdate(ctx->hs->clienthello_md_ctx, data, len);
523}
524
525int
526tls13_clienthello_hash_update(struct tls13_ctx *ctx, CBS *cbs)
527{
528 return tls13_clienthello_hash_update_bytes(ctx, (void *)CBS_data(cbs),
529 CBS_len(cbs));
530}
531
532int
533tls13_clienthello_hash_finalize(struct tls13_ctx *ctx)
534{
535 if (!EVP_DigestFinal_ex(ctx->hs->clienthello_md_ctx,
536 ctx->hs->clienthello_hash,
537 &ctx->hs->clienthello_hash_len))
538 return 0;
539 EVP_MD_CTX_free(ctx->hs->clienthello_md_ctx);
540 ctx->hs->clienthello_md_ctx = NULL;
541 return 1;
542}
543
544int
545tls13_clienthello_hash_validate(struct tls13_ctx *ctx)
546{
547 unsigned char new_ch_hash[EVP_MAX_MD_SIZE];
548 unsigned int new_ch_hash_len;
549
550 if (ctx->hs->clienthello_hash == NULL)
551 return 0;
552
553 if (!EVP_DigestFinal_ex(ctx->hs->clienthello_md_ctx,
554 new_ch_hash, &new_ch_hash_len))
555 return 0;
556 EVP_MD_CTX_free(ctx->hs->clienthello_md_ctx);
557 ctx->hs->clienthello_md_ctx = NULL;
558
559 if (ctx->hs->clienthello_hash_len != new_ch_hash_len)
560 return 0;
561 if (memcmp(ctx->hs->clienthello_hash, new_ch_hash,
562 new_ch_hash_len) != 0)
563 return 0;
564
565 return 1;
566}
567