0005-Revert-Reduce-stack-usage-in-tls13_hkdf_expand.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From 56e0f123dc17cb99f50efbae4bbbab77f360818f Mon Sep 17 00:00:00 2001
  2. From: Matt Caswell <matt@openssl.org>
  3. Date: Mon, 3 Dec 2018 18:14:57 +0000
  4. Subject: [PATCH] Revert "Reduce stack usage in tls13_hkdf_expand"
  5. This reverts commit ec0c5f5693e39c5a013f81e6dd9dfd09ec65162d.
  6. SSL_export_keying_material() may use longer label lengths.
  7. Fixes #7712
  8. Reviewed-by: Tim Hudson <tjh@openssl.org>
  9. (Merged from https://github.com/openssl/openssl/pull/7755)
  10. (cherry picked from commit ed371b8cbac0d0349667558c061c1ae380cf75eb)
  11. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  12. ---
  13. ssl/tls13_enc.c | 16 ++++------------
  14. 1 file changed, 4 insertions(+), 12 deletions(-)
  15. diff --git a/ssl/tls13_enc.c b/ssl/tls13_enc.c
  16. index b6825d20c2..f7ab0fa470 100644
  17. --- a/ssl/tls13_enc.c
  18. +++ b/ssl/tls13_enc.c
  19. @@ -13,14 +13,7 @@
  20. #include <openssl/evp.h>
  21. #include <openssl/kdf.h>
  22. -/*
  23. - * RFC 8446, 7.1 Key Schedule, says:
  24. - * Note: With common hash functions, any label longer than 12 characters
  25. - * requires an additional iteration of the hash function to compute.
  26. - * The labels in this specification have all been chosen to fit within
  27. - * this limit.
  28. - */
  29. -#define TLS13_MAX_LABEL_LEN 12
  30. +#define TLS13_MAX_LABEL_LEN 246
  31. /* Always filled with zeros */
  32. static const unsigned char default_zeros[EVP_MAX_MD_SIZE];
  33. @@ -36,15 +29,14 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
  34. const unsigned char *data, size_t datalen,
  35. unsigned char *out, size_t outlen)
  36. {
  37. - static const unsigned char label_prefix[] = "tls13 ";
  38. + const unsigned char label_prefix[] = "tls13 ";
  39. EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
  40. int ret;
  41. size_t hkdflabellen;
  42. size_t hashlen;
  43. /*
  44. - * 2 bytes for length of derived secret + 1 byte for length of combined
  45. - * prefix and label + bytes for the label itself + 1 byte length of hash
  46. - * + bytes for the hash itself
  47. + * 2 bytes for length of whole HkdfLabel + 1 byte for length of combined
  48. + * prefix and label + bytes for the label itself + bytes for the hash
  49. */
  50. unsigned char hkdflabel[sizeof(uint16_t) + sizeof(uint8_t) +
  51. + sizeof(label_prefix) + TLS13_MAX_LABEL_LEN
  52. --
  53. 2.20.1