tls-extensions.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. /*
  2. * Embedded Linux library
  3. *
  4. * Copyright (C) 2018 Intel Corporation. All rights reserved.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23. #include <errno.h>
  24. #include "util.h"
  25. #include "tls.h"
  26. #include "cipher.h"
  27. #include "checksum.h"
  28. #include "cert.h"
  29. #include "tls-private.h"
  30. /* RFC 7919, Section A.1 */
  31. static const uint8_t tls_ffdhe2048_prime[] = {
  32. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xad, 0xf8, 0x54, 0x58,
  33. 0xa2, 0xbb, 0x4a, 0x9a, 0xaf, 0xdc, 0x56, 0x20, 0x27, 0x3d, 0x3c, 0xf1,
  34. 0xd8, 0xb9, 0xc5, 0x83, 0xce, 0x2d, 0x36, 0x95, 0xa9, 0xe1, 0x36, 0x41,
  35. 0x14, 0x64, 0x33, 0xfb, 0xcc, 0x93, 0x9d, 0xce, 0x24, 0x9b, 0x3e, 0xf9,
  36. 0x7d, 0x2f, 0xe3, 0x63, 0x63, 0x0c, 0x75, 0xd8, 0xf6, 0x81, 0xb2, 0x02,
  37. 0xae, 0xc4, 0x61, 0x7a, 0xd3, 0xdf, 0x1e, 0xd5, 0xd5, 0xfd, 0x65, 0x61,
  38. 0x24, 0x33, 0xf5, 0x1f, 0x5f, 0x06, 0x6e, 0xd0, 0x85, 0x63, 0x65, 0x55,
  39. 0x3d, 0xed, 0x1a, 0xf3, 0xb5, 0x57, 0x13, 0x5e, 0x7f, 0x57, 0xc9, 0x35,
  40. 0x98, 0x4f, 0x0c, 0x70, 0xe0, 0xe6, 0x8b, 0x77, 0xe2, 0xa6, 0x89, 0xda,
  41. 0xf3, 0xef, 0xe8, 0x72, 0x1d, 0xf1, 0x58, 0xa1, 0x36, 0xad, 0xe7, 0x35,
  42. 0x30, 0xac, 0xca, 0x4f, 0x48, 0x3a, 0x79, 0x7a, 0xbc, 0x0a, 0xb1, 0x82,
  43. 0xb3, 0x24, 0xfb, 0x61, 0xd1, 0x08, 0xa9, 0x4b, 0xb2, 0xc8, 0xe3, 0xfb,
  44. 0xb9, 0x6a, 0xda, 0xb7, 0x60, 0xd7, 0xf4, 0x68, 0x1d, 0x4f, 0x42, 0xa3,
  45. 0xde, 0x39, 0x4d, 0xf4, 0xae, 0x56, 0xed, 0xe7, 0x63, 0x72, 0xbb, 0x19,
  46. 0x0b, 0x07, 0xa7, 0xc8, 0xee, 0x0a, 0x6d, 0x70, 0x9e, 0x02, 0xfc, 0xe1,
  47. 0xcd, 0xf7, 0xe2, 0xec, 0xc0, 0x34, 0x04, 0xcd, 0x28, 0x34, 0x2f, 0x61,
  48. 0x91, 0x72, 0xfe, 0x9c, 0xe9, 0x85, 0x83, 0xff, 0x8e, 0x4f, 0x12, 0x32,
  49. 0xee, 0xf2, 0x81, 0x83, 0xc3, 0xfe, 0x3b, 0x1b, 0x4c, 0x6f, 0xad, 0x73,
  50. 0x3b, 0xb5, 0xfc, 0xbc, 0x2e, 0xc2, 0x20, 0x05, 0xc5, 0x8e, 0xf1, 0x83,
  51. 0x7d, 0x16, 0x83, 0xb2, 0xc6, 0xf3, 0x4a, 0x26, 0xc1, 0xb2, 0xef, 0xfa,
  52. 0x88, 0x6b, 0x42, 0x38, 0x61, 0x28, 0x5c, 0x97, 0xff, 0xff, 0xff, 0xff,
  53. 0xff, 0xff, 0xff, 0xff,
  54. };
  55. /* RFC 7919, Section A.2 */
  56. static const uint8_t tls_ffdhe3072_prime[] = {
  57. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xad, 0xf8, 0x54, 0x58,
  58. 0xa2, 0xbb, 0x4a, 0x9a, 0xaf, 0xdc, 0x56, 0x20, 0x27, 0x3d, 0x3c, 0xf1,
  59. 0xd8, 0xb9, 0xc5, 0x83, 0xce, 0x2d, 0x36, 0x95, 0xa9, 0xe1, 0x36, 0x41,
  60. 0x14, 0x64, 0x33, 0xfb, 0xcc, 0x93, 0x9d, 0xce, 0x24, 0x9b, 0x3e, 0xf9,
  61. 0x7d, 0x2f, 0xe3, 0x63, 0x63, 0x0c, 0x75, 0xd8, 0xf6, 0x81, 0xb2, 0x02,
  62. 0xae, 0xc4, 0x61, 0x7a, 0xd3, 0xdf, 0x1e, 0xd5, 0xd5, 0xfd, 0x65, 0x61,
  63. 0x24, 0x33, 0xf5, 0x1f, 0x5f, 0x06, 0x6e, 0xd0, 0x85, 0x63, 0x65, 0x55,
  64. 0x3d, 0xed, 0x1a, 0xf3, 0xb5, 0x57, 0x13, 0x5e, 0x7f, 0x57, 0xc9, 0x35,
  65. 0x98, 0x4f, 0x0c, 0x70, 0xe0, 0xe6, 0x8b, 0x77, 0xe2, 0xa6, 0x89, 0xda,
  66. 0xf3, 0xef, 0xe8, 0x72, 0x1d, 0xf1, 0x58, 0xa1, 0x36, 0xad, 0xe7, 0x35,
  67. 0x30, 0xac, 0xca, 0x4f, 0x48, 0x3a, 0x79, 0x7a, 0xbc, 0x0a, 0xb1, 0x82,
  68. 0xb3, 0x24, 0xfb, 0x61, 0xd1, 0x08, 0xa9, 0x4b, 0xb2, 0xc8, 0xe3, 0xfb,
  69. 0xb9, 0x6a, 0xda, 0xb7, 0x60, 0xd7, 0xf4, 0x68, 0x1d, 0x4f, 0x42, 0xa3,
  70. 0xde, 0x39, 0x4d, 0xf4, 0xae, 0x56, 0xed, 0xe7, 0x63, 0x72, 0xbb, 0x19,
  71. 0x0b, 0x07, 0xa7, 0xc8, 0xee, 0x0a, 0x6d, 0x70, 0x9e, 0x02, 0xfc, 0xe1,
  72. 0xcd, 0xf7, 0xe2, 0xec, 0xc0, 0x34, 0x04, 0xcd, 0x28, 0x34, 0x2f, 0x61,
  73. 0x91, 0x72, 0xfe, 0x9c, 0xe9, 0x85, 0x83, 0xff, 0x8e, 0x4f, 0x12, 0x32,
  74. 0xee, 0xf2, 0x81, 0x83, 0xc3, 0xfe, 0x3b, 0x1b, 0x4c, 0x6f, 0xad, 0x73,
  75. 0x3b, 0xb5, 0xfc, 0xbc, 0x2e, 0xc2, 0x20, 0x05, 0xc5, 0x8e, 0xf1, 0x83,
  76. 0x7d, 0x16, 0x83, 0xb2, 0xc6, 0xf3, 0x4a, 0x26, 0xc1, 0xb2, 0xef, 0xfa,
  77. 0x88, 0x6b, 0x42, 0x38, 0x61, 0x1f, 0xcf, 0xdc, 0xde, 0x35, 0x5b, 0x3b,
  78. 0x65, 0x19, 0x03, 0x5b, 0xbc, 0x34, 0xf4, 0xde, 0xf9, 0x9c, 0x02, 0x38,
  79. 0x61, 0xb4, 0x6f, 0xc9, 0xd6, 0xe6, 0xc9, 0x07, 0x7a, 0xd9, 0x1d, 0x26,
  80. 0x91, 0xf7, 0xf7, 0xee, 0x59, 0x8c, 0xb0, 0xfa, 0xc1, 0x86, 0xd9, 0x1c,
  81. 0xae, 0xfe, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xb4, 0x13, 0x0c, 0x93,
  82. 0xbc, 0x43, 0x79, 0x44, 0xf4, 0xfd, 0x44, 0x52, 0xe2, 0xd7, 0x4d, 0xd3,
  83. 0x64, 0xf2, 0xe2, 0x1e, 0x71, 0xf5, 0x4b, 0xff, 0x5c, 0xae, 0x82, 0xab,
  84. 0x9c, 0x9d, 0xf6, 0x9e, 0xe8, 0x6d, 0x2b, 0xc5, 0x22, 0x36, 0x3a, 0x0d,
  85. 0xab, 0xc5, 0x21, 0x97, 0x9b, 0x0d, 0xea, 0xda, 0x1d, 0xbf, 0x9a, 0x42,
  86. 0xd5, 0xc4, 0x48, 0x4e, 0x0a, 0xbc, 0xd0, 0x6b, 0xfa, 0x53, 0xdd, 0xef,
  87. 0x3c, 0x1b, 0x20, 0xee, 0x3f, 0xd5, 0x9d, 0x7c, 0x25, 0xe4, 0x1d, 0x2b,
  88. 0x66, 0xc6, 0x2e, 0x37, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  89. };
  90. /* RFC 7919, Section A.3 */
  91. static const uint8_t tls_ffdhe4096_prime[] = {
  92. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xad, 0xf8, 0x54, 0x58,
  93. 0xa2, 0xbb, 0x4a, 0x9a, 0xaf, 0xdc, 0x56, 0x20, 0x27, 0x3d, 0x3c, 0xf1,
  94. 0xd8, 0xb9, 0xc5, 0x83, 0xce, 0x2d, 0x36, 0x95, 0xa9, 0xe1, 0x36, 0x41,
  95. 0x14, 0x64, 0x33, 0xfb, 0xcc, 0x93, 0x9d, 0xce, 0x24, 0x9b, 0x3e, 0xf9,
  96. 0x7d, 0x2f, 0xe3, 0x63, 0x63, 0x0c, 0x75, 0xd8, 0xf6, 0x81, 0xb2, 0x02,
  97. 0xae, 0xc4, 0x61, 0x7a, 0xd3, 0xdf, 0x1e, 0xd5, 0xd5, 0xfd, 0x65, 0x61,
  98. 0x24, 0x33, 0xf5, 0x1f, 0x5f, 0x06, 0x6e, 0xd0, 0x85, 0x63, 0x65, 0x55,
  99. 0x3d, 0xed, 0x1a, 0xf3, 0xb5, 0x57, 0x13, 0x5e, 0x7f, 0x57, 0xc9, 0x35,
  100. 0x98, 0x4f, 0x0c, 0x70, 0xe0, 0xe6, 0x8b, 0x77, 0xe2, 0xa6, 0x89, 0xda,
  101. 0xf3, 0xef, 0xe8, 0x72, 0x1d, 0xf1, 0x58, 0xa1, 0x36, 0xad, 0xe7, 0x35,
  102. 0x30, 0xac, 0xca, 0x4f, 0x48, 0x3a, 0x79, 0x7a, 0xbc, 0x0a, 0xb1, 0x82,
  103. 0xb3, 0x24, 0xfb, 0x61, 0xd1, 0x08, 0xa9, 0x4b, 0xb2, 0xc8, 0xe3, 0xfb,
  104. 0xb9, 0x6a, 0xda, 0xb7, 0x60, 0xd7, 0xf4, 0x68, 0x1d, 0x4f, 0x42, 0xa3,
  105. 0xde, 0x39, 0x4d, 0xf4, 0xae, 0x56, 0xed, 0xe7, 0x63, 0x72, 0xbb, 0x19,
  106. 0x0b, 0x07, 0xa7, 0xc8, 0xee, 0x0a, 0x6d, 0x70, 0x9e, 0x02, 0xfc, 0xe1,
  107. 0xcd, 0xf7, 0xe2, 0xec, 0xc0, 0x34, 0x04, 0xcd, 0x28, 0x34, 0x2f, 0x61,
  108. 0x91, 0x72, 0xfe, 0x9c, 0xe9, 0x85, 0x83, 0xff, 0x8e, 0x4f, 0x12, 0x32,
  109. 0xee, 0xf2, 0x81, 0x83, 0xc3, 0xfe, 0x3b, 0x1b, 0x4c, 0x6f, 0xad, 0x73,
  110. 0x3b, 0xb5, 0xfc, 0xbc, 0x2e, 0xc2, 0x20, 0x05, 0xc5, 0x8e, 0xf1, 0x83,
  111. 0x7d, 0x16, 0x83, 0xb2, 0xc6, 0xf3, 0x4a, 0x26, 0xc1, 0xb2, 0xef, 0xfa,
  112. 0x88, 0x6b, 0x42, 0x38, 0x61, 0x1f, 0xcf, 0xdc, 0xde, 0x35, 0x5b, 0x3b,
  113. 0x65, 0x19, 0x03, 0x5b, 0xbc, 0x34, 0xf4, 0xde, 0xf9, 0x9c, 0x02, 0x38,
  114. 0x61, 0xb4, 0x6f, 0xc9, 0xd6, 0xe6, 0xc9, 0x07, 0x7a, 0xd9, 0x1d, 0x26,
  115. 0x91, 0xf7, 0xf7, 0xee, 0x59, 0x8c, 0xb0, 0xfa, 0xc1, 0x86, 0xd9, 0x1c,
  116. 0xae, 0xfe, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xb4, 0x13, 0x0c, 0x93,
  117. 0xbc, 0x43, 0x79, 0x44, 0xf4, 0xfd, 0x44, 0x52, 0xe2, 0xd7, 0x4d, 0xd3,
  118. 0x64, 0xf2, 0xe2, 0x1e, 0x71, 0xf5, 0x4b, 0xff, 0x5c, 0xae, 0x82, 0xab,
  119. 0x9c, 0x9d, 0xf6, 0x9e, 0xe8, 0x6d, 0x2b, 0xc5, 0x22, 0x36, 0x3a, 0x0d,
  120. 0xab, 0xc5, 0x21, 0x97, 0x9b, 0x0d, 0xea, 0xda, 0x1d, 0xbf, 0x9a, 0x42,
  121. 0xd5, 0xc4, 0x48, 0x4e, 0x0a, 0xbc, 0xd0, 0x6b, 0xfa, 0x53, 0xdd, 0xef,
  122. 0x3c, 0x1b, 0x20, 0xee, 0x3f, 0xd5, 0x9d, 0x7c, 0x25, 0xe4, 0x1d, 0x2b,
  123. 0x66, 0x9e, 0x1e, 0xf1, 0x6e, 0x6f, 0x52, 0xc3, 0x16, 0x4d, 0xf4, 0xfb,
  124. 0x79, 0x30, 0xe9, 0xe4, 0xe5, 0x88, 0x57, 0xb6, 0xac, 0x7d, 0x5f, 0x42,
  125. 0xd6, 0x9f, 0x6d, 0x18, 0x77, 0x63, 0xcf, 0x1d, 0x55, 0x03, 0x40, 0x04,
  126. 0x87, 0xf5, 0x5b, 0xa5, 0x7e, 0x31, 0xcc, 0x7a, 0x71, 0x35, 0xc8, 0x86,
  127. 0xef, 0xb4, 0x31, 0x8a, 0xed, 0x6a, 0x1e, 0x01, 0x2d, 0x9e, 0x68, 0x32,
  128. 0xa9, 0x07, 0x60, 0x0a, 0x91, 0x81, 0x30, 0xc4, 0x6d, 0xc7, 0x78, 0xf9,
  129. 0x71, 0xad, 0x00, 0x38, 0x09, 0x29, 0x99, 0xa3, 0x33, 0xcb, 0x8b, 0x7a,
  130. 0x1a, 0x1d, 0xb9, 0x3d, 0x71, 0x40, 0x00, 0x3c, 0x2a, 0x4e, 0xce, 0xa9,
  131. 0xf9, 0x8d, 0x0a, 0xcc, 0x0a, 0x82, 0x91, 0xcd, 0xce, 0xc9, 0x7d, 0xcf,
  132. 0x8e, 0xc9, 0xb5, 0x5a, 0x7f, 0x88, 0xa4, 0x6b, 0x4d, 0xb5, 0xa8, 0x51,
  133. 0xf4, 0x41, 0x82, 0xe1, 0xc6, 0x8a, 0x00, 0x7e, 0x5e, 0x65, 0x5f, 0x6a,
  134. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  135. };
  136. /* RFC 7919, Section A.4 */
  137. static const uint8_t tls_ffdhe6144_prime[] = {
  138. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xad, 0xf8, 0x54, 0x58,
  139. 0xa2, 0xbb, 0x4a, 0x9a, 0xaf, 0xdc, 0x56, 0x20, 0x27, 0x3d, 0x3c, 0xf1,
  140. 0xd8, 0xb9, 0xc5, 0x83, 0xce, 0x2d, 0x36, 0x95, 0xa9, 0xe1, 0x36, 0x41,
  141. 0x14, 0x64, 0x33, 0xfb, 0xcc, 0x93, 0x9d, 0xce, 0x24, 0x9b, 0x3e, 0xf9,
  142. 0x7d, 0x2f, 0xe3, 0x63, 0x63, 0x0c, 0x75, 0xd8, 0xf6, 0x81, 0xb2, 0x02,
  143. 0xae, 0xc4, 0x61, 0x7a, 0xd3, 0xdf, 0x1e, 0xd5, 0xd5, 0xfd, 0x65, 0x61,
  144. 0x24, 0x33, 0xf5, 0x1f, 0x5f, 0x06, 0x6e, 0xd0, 0x85, 0x63, 0x65, 0x55,
  145. 0x3d, 0xed, 0x1a, 0xf3, 0xb5, 0x57, 0x13, 0x5e, 0x7f, 0x57, 0xc9, 0x35,
  146. 0x98, 0x4f, 0x0c, 0x70, 0xe0, 0xe6, 0x8b, 0x77, 0xe2, 0xa6, 0x89, 0xda,
  147. 0xf3, 0xef, 0xe8, 0x72, 0x1d, 0xf1, 0x58, 0xa1, 0x36, 0xad, 0xe7, 0x35,
  148. 0x30, 0xac, 0xca, 0x4f, 0x48, 0x3a, 0x79, 0x7a, 0xbc, 0x0a, 0xb1, 0x82,
  149. 0xb3, 0x24, 0xfb, 0x61, 0xd1, 0x08, 0xa9, 0x4b, 0xb2, 0xc8, 0xe3, 0xfb,
  150. 0xb9, 0x6a, 0xda, 0xb7, 0x60, 0xd7, 0xf4, 0x68, 0x1d, 0x4f, 0x42, 0xa3,
  151. 0xde, 0x39, 0x4d, 0xf4, 0xae, 0x56, 0xed, 0xe7, 0x63, 0x72, 0xbb, 0x19,
  152. 0x0b, 0x07, 0xa7, 0xc8, 0xee, 0x0a, 0x6d, 0x70, 0x9e, 0x02, 0xfc, 0xe1,
  153. 0xcd, 0xf7, 0xe2, 0xec, 0xc0, 0x34, 0x04, 0xcd, 0x28, 0x34, 0x2f, 0x61,
  154. 0x91, 0x72, 0xfe, 0x9c, 0xe9, 0x85, 0x83, 0xff, 0x8e, 0x4f, 0x12, 0x32,
  155. 0xee, 0xf2, 0x81, 0x83, 0xc3, 0xfe, 0x3b, 0x1b, 0x4c, 0x6f, 0xad, 0x73,
  156. 0x3b, 0xb5, 0xfc, 0xbc, 0x2e, 0xc2, 0x20, 0x05, 0xc5, 0x8e, 0xf1, 0x83,
  157. 0x7d, 0x16, 0x83, 0xb2, 0xc6, 0xf3, 0x4a, 0x26, 0xc1, 0xb2, 0xef, 0xfa,
  158. 0x88, 0x6b, 0x42, 0x38, 0x61, 0x1f, 0xcf, 0xdc, 0xde, 0x35, 0x5b, 0x3b,
  159. 0x65, 0x19, 0x03, 0x5b, 0xbc, 0x34, 0xf4, 0xde, 0xf9, 0x9c, 0x02, 0x38,
  160. 0x61, 0xb4, 0x6f, 0xc9, 0xd6, 0xe6, 0xc9, 0x07, 0x7a, 0xd9, 0x1d, 0x26,
  161. 0x91, 0xf7, 0xf7, 0xee, 0x59, 0x8c, 0xb0, 0xfa, 0xc1, 0x86, 0xd9, 0x1c,
  162. 0xae, 0xfe, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xb4, 0x13, 0x0c, 0x93,
  163. 0xbc, 0x43, 0x79, 0x44, 0xf4, 0xfd, 0x44, 0x52, 0xe2, 0xd7, 0x4d, 0xd3,
  164. 0x64, 0xf2, 0xe2, 0x1e, 0x71, 0xf5, 0x4b, 0xff, 0x5c, 0xae, 0x82, 0xab,
  165. 0x9c, 0x9d, 0xf6, 0x9e, 0xe8, 0x6d, 0x2b, 0xc5, 0x22, 0x36, 0x3a, 0x0d,
  166. 0xab, 0xc5, 0x21, 0x97, 0x9b, 0x0d, 0xea, 0xda, 0x1d, 0xbf, 0x9a, 0x42,
  167. 0xd5, 0xc4, 0x48, 0x4e, 0x0a, 0xbc, 0xd0, 0x6b, 0xfa, 0x53, 0xdd, 0xef,
  168. 0x3c, 0x1b, 0x20, 0xee, 0x3f, 0xd5, 0x9d, 0x7c, 0x25, 0xe4, 0x1d, 0x2b,
  169. 0x66, 0x9e, 0x1e, 0xf1, 0x6e, 0x6f, 0x52, 0xc3, 0x16, 0x4d, 0xf4, 0xfb,
  170. 0x79, 0x30, 0xe9, 0xe4, 0xe5, 0x88, 0x57, 0xb6, 0xac, 0x7d, 0x5f, 0x42,
  171. 0xd6, 0x9f, 0x6d, 0x18, 0x77, 0x63, 0xcf, 0x1d, 0x55, 0x03, 0x40, 0x04,
  172. 0x87, 0xf5, 0x5b, 0xa5, 0x7e, 0x31, 0xcc, 0x7a, 0x71, 0x35, 0xc8, 0x86,
  173. 0xef, 0xb4, 0x31, 0x8a, 0xed, 0x6a, 0x1e, 0x01, 0x2d, 0x9e, 0x68, 0x32,
  174. 0xa9, 0x07, 0x60, 0x0a, 0x91, 0x81, 0x30, 0xc4, 0x6d, 0xc7, 0x78, 0xf9,
  175. 0x71, 0xad, 0x00, 0x38, 0x09, 0x29, 0x99, 0xa3, 0x33, 0xcb, 0x8b, 0x7a,
  176. 0x1a, 0x1d, 0xb9, 0x3d, 0x71, 0x40, 0x00, 0x3c, 0x2a, 0x4e, 0xce, 0xa9,
  177. 0xf9, 0x8d, 0x0a, 0xcc, 0x0a, 0x82, 0x91, 0xcd, 0xce, 0xc9, 0x7d, 0xcf,
  178. 0x8e, 0xc9, 0xb5, 0x5a, 0x7f, 0x88, 0xa4, 0x6b, 0x4d, 0xb5, 0xa8, 0x51,
  179. 0xf4, 0x41, 0x82, 0xe1, 0xc6, 0x8a, 0x00, 0x7e, 0x5e, 0x0d, 0xd9, 0x02,
  180. 0x0b, 0xfd, 0x64, 0xb6, 0x45, 0x03, 0x6c, 0x7a, 0x4e, 0x67, 0x7d, 0x2c,
  181. 0x38, 0x53, 0x2a, 0x3a, 0x23, 0xba, 0x44, 0x42, 0xca, 0xf5, 0x3e, 0xa6,
  182. 0x3b, 0xb4, 0x54, 0x32, 0x9b, 0x76, 0x24, 0xc8, 0x91, 0x7b, 0xdd, 0x64,
  183. 0xb1, 0xc0, 0xfd, 0x4c, 0xb3, 0x8e, 0x8c, 0x33, 0x4c, 0x70, 0x1c, 0x3a,
  184. 0xcd, 0xad, 0x06, 0x57, 0xfc, 0xcf, 0xec, 0x71, 0x9b, 0x1f, 0x5c, 0x3e,
  185. 0x4e, 0x46, 0x04, 0x1f, 0x38, 0x81, 0x47, 0xfb, 0x4c, 0xfd, 0xb4, 0x77,
  186. 0xa5, 0x24, 0x71, 0xf7, 0xa9, 0xa9, 0x69, 0x10, 0xb8, 0x55, 0x32, 0x2e,
  187. 0xdb, 0x63, 0x40, 0xd8, 0xa0, 0x0e, 0xf0, 0x92, 0x35, 0x05, 0x11, 0xe3,
  188. 0x0a, 0xbe, 0xc1, 0xff, 0xf9, 0xe3, 0xa2, 0x6e, 0x7f, 0xb2, 0x9f, 0x8c,
  189. 0x18, 0x30, 0x23, 0xc3, 0x58, 0x7e, 0x38, 0xda, 0x00, 0x77, 0xd9, 0xb4,
  190. 0x76, 0x3e, 0x4e, 0x4b, 0x94, 0xb2, 0xbb, 0xc1, 0x94, 0xc6, 0x65, 0x1e,
  191. 0x77, 0xca, 0xf9, 0x92, 0xee, 0xaa, 0xc0, 0x23, 0x2a, 0x28, 0x1b, 0xf6,
  192. 0xb3, 0xa7, 0x39, 0xc1, 0x22, 0x61, 0x16, 0x82, 0x0a, 0xe8, 0xdb, 0x58,
  193. 0x47, 0xa6, 0x7c, 0xbe, 0xf9, 0xc9, 0x09, 0x1b, 0x46, 0x2d, 0x53, 0x8c,
  194. 0xd7, 0x2b, 0x03, 0x74, 0x6a, 0xe7, 0x7f, 0x5e, 0x62, 0x29, 0x2c, 0x31,
  195. 0x15, 0x62, 0xa8, 0x46, 0x50, 0x5d, 0xc8, 0x2d, 0xb8, 0x54, 0x33, 0x8a,
  196. 0xe4, 0x9f, 0x52, 0x35, 0xc9, 0x5b, 0x91, 0x17, 0x8c, 0xcf, 0x2d, 0xd5,
  197. 0xca, 0xce, 0xf4, 0x03, 0xec, 0x9d, 0x18, 0x10, 0xc6, 0x27, 0x2b, 0x04,
  198. 0x5b, 0x3b, 0x71, 0xf9, 0xdc, 0x6b, 0x80, 0xd6, 0x3f, 0xdd, 0x4a, 0x8e,
  199. 0x9a, 0xdb, 0x1e, 0x69, 0x62, 0xa6, 0x95, 0x26, 0xd4, 0x31, 0x61, 0xc1,
  200. 0xa4, 0x1d, 0x57, 0x0d, 0x79, 0x38, 0xda, 0xd4, 0xa4, 0x0e, 0x32, 0x9c,
  201. 0xd0, 0xe4, 0x0e, 0x65, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  202. };
  203. /* RFC 7919, Section A.5 */
  204. static const uint8_t tls_ffdhe8192_prime[] = {
  205. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xad, 0xf8, 0x54, 0x58,
  206. 0xa2, 0xbb, 0x4a, 0x9a, 0xaf, 0xdc, 0x56, 0x20, 0x27, 0x3d, 0x3c, 0xf1,
  207. 0xd8, 0xb9, 0xc5, 0x83, 0xce, 0x2d, 0x36, 0x95, 0xa9, 0xe1, 0x36, 0x41,
  208. 0x14, 0x64, 0x33, 0xfb, 0xcc, 0x93, 0x9d, 0xce, 0x24, 0x9b, 0x3e, 0xf9,
  209. 0x7d, 0x2f, 0xe3, 0x63, 0x63, 0x0c, 0x75, 0xd8, 0xf6, 0x81, 0xb2, 0x02,
  210. 0xae, 0xc4, 0x61, 0x7a, 0xd3, 0xdf, 0x1e, 0xd5, 0xd5, 0xfd, 0x65, 0x61,
  211. 0x24, 0x33, 0xf5, 0x1f, 0x5f, 0x06, 0x6e, 0xd0, 0x85, 0x63, 0x65, 0x55,
  212. 0x3d, 0xed, 0x1a, 0xf3, 0xb5, 0x57, 0x13, 0x5e, 0x7f, 0x57, 0xc9, 0x35,
  213. 0x98, 0x4f, 0x0c, 0x70, 0xe0, 0xe6, 0x8b, 0x77, 0xe2, 0xa6, 0x89, 0xda,
  214. 0xf3, 0xef, 0xe8, 0x72, 0x1d, 0xf1, 0x58, 0xa1, 0x36, 0xad, 0xe7, 0x35,
  215. 0x30, 0xac, 0xca, 0x4f, 0x48, 0x3a, 0x79, 0x7a, 0xbc, 0x0a, 0xb1, 0x82,
  216. 0xb3, 0x24, 0xfb, 0x61, 0xd1, 0x08, 0xa9, 0x4b, 0xb2, 0xc8, 0xe3, 0xfb,
  217. 0xb9, 0x6a, 0xda, 0xb7, 0x60, 0xd7, 0xf4, 0x68, 0x1d, 0x4f, 0x42, 0xa3,
  218. 0xde, 0x39, 0x4d, 0xf4, 0xae, 0x56, 0xed, 0xe7, 0x63, 0x72, 0xbb, 0x19,
  219. 0x0b, 0x07, 0xa7, 0xc8, 0xee, 0x0a, 0x6d, 0x70, 0x9e, 0x02, 0xfc, 0xe1,
  220. 0xcd, 0xf7, 0xe2, 0xec, 0xc0, 0x34, 0x04, 0xcd, 0x28, 0x34, 0x2f, 0x61,
  221. 0x91, 0x72, 0xfe, 0x9c, 0xe9, 0x85, 0x83, 0xff, 0x8e, 0x4f, 0x12, 0x32,
  222. 0xee, 0xf2, 0x81, 0x83, 0xc3, 0xfe, 0x3b, 0x1b, 0x4c, 0x6f, 0xad, 0x73,
  223. 0x3b, 0xb5, 0xfc, 0xbc, 0x2e, 0xc2, 0x20, 0x05, 0xc5, 0x8e, 0xf1, 0x83,
  224. 0x7d, 0x16, 0x83, 0xb2, 0xc6, 0xf3, 0x4a, 0x26, 0xc1, 0xb2, 0xef, 0xfa,
  225. 0x88, 0x6b, 0x42, 0x38, 0x61, 0x1f, 0xcf, 0xdc, 0xde, 0x35, 0x5b, 0x3b,
  226. 0x65, 0x19, 0x03, 0x5b, 0xbc, 0x34, 0xf4, 0xde, 0xf9, 0x9c, 0x02, 0x38,
  227. 0x61, 0xb4, 0x6f, 0xc9, 0xd6, 0xe6, 0xc9, 0x07, 0x7a, 0xd9, 0x1d, 0x26,
  228. 0x91, 0xf7, 0xf7, 0xee, 0x59, 0x8c, 0xb0, 0xfa, 0xc1, 0x86, 0xd9, 0x1c,
  229. 0xae, 0xfe, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xb4, 0x13, 0x0c, 0x93,
  230. 0xbc, 0x43, 0x79, 0x44, 0xf4, 0xfd, 0x44, 0x52, 0xe2, 0xd7, 0x4d, 0xd3,
  231. 0x64, 0xf2, 0xe2, 0x1e, 0x71, 0xf5, 0x4b, 0xff, 0x5c, 0xae, 0x82, 0xab,
  232. 0x9c, 0x9d, 0xf6, 0x9e, 0xe8, 0x6d, 0x2b, 0xc5, 0x22, 0x36, 0x3a, 0x0d,
  233. 0xab, 0xc5, 0x21, 0x97, 0x9b, 0x0d, 0xea, 0xda, 0x1d, 0xbf, 0x9a, 0x42,
  234. 0xd5, 0xc4, 0x48, 0x4e, 0x0a, 0xbc, 0xd0, 0x6b, 0xfa, 0x53, 0xdd, 0xef,
  235. 0x3c, 0x1b, 0x20, 0xee, 0x3f, 0xd5, 0x9d, 0x7c, 0x25, 0xe4, 0x1d, 0x2b,
  236. 0x66, 0x9e, 0x1e, 0xf1, 0x6e, 0x6f, 0x52, 0xc3, 0x16, 0x4d, 0xf4, 0xfb,
  237. 0x79, 0x30, 0xe9, 0xe4, 0xe5, 0x88, 0x57, 0xb6, 0xac, 0x7d, 0x5f, 0x42,
  238. 0xd6, 0x9f, 0x6d, 0x18, 0x77, 0x63, 0xcf, 0x1d, 0x55, 0x03, 0x40, 0x04,
  239. 0x87, 0xf5, 0x5b, 0xa5, 0x7e, 0x31, 0xcc, 0x7a, 0x71, 0x35, 0xc8, 0x86,
  240. 0xef, 0xb4, 0x31, 0x8a, 0xed, 0x6a, 0x1e, 0x01, 0x2d, 0x9e, 0x68, 0x32,
  241. 0xa9, 0x07, 0x60, 0x0a, 0x91, 0x81, 0x30, 0xc4, 0x6d, 0xc7, 0x78, 0xf9,
  242. 0x71, 0xad, 0x00, 0x38, 0x09, 0x29, 0x99, 0xa3, 0x33, 0xcb, 0x8b, 0x7a,
  243. 0x1a, 0x1d, 0xb9, 0x3d, 0x71, 0x40, 0x00, 0x3c, 0x2a, 0x4e, 0xce, 0xa9,
  244. 0xf9, 0x8d, 0x0a, 0xcc, 0x0a, 0x82, 0x91, 0xcd, 0xce, 0xc9, 0x7d, 0xcf,
  245. 0x8e, 0xc9, 0xb5, 0x5a, 0x7f, 0x88, 0xa4, 0x6b, 0x4d, 0xb5, 0xa8, 0x51,
  246. 0xf4, 0x41, 0x82, 0xe1, 0xc6, 0x8a, 0x00, 0x7e, 0x5e, 0x0d, 0xd9, 0x02,
  247. 0x0b, 0xfd, 0x64, 0xb6, 0x45, 0x03, 0x6c, 0x7a, 0x4e, 0x67, 0x7d, 0x2c,
  248. 0x38, 0x53, 0x2a, 0x3a, 0x23, 0xba, 0x44, 0x42, 0xca, 0xf5, 0x3e, 0xa6,
  249. 0x3b, 0xb4, 0x54, 0x32, 0x9b, 0x76, 0x24, 0xc8, 0x91, 0x7b, 0xdd, 0x64,
  250. 0xb1, 0xc0, 0xfd, 0x4c, 0xb3, 0x8e, 0x8c, 0x33, 0x4c, 0x70, 0x1c, 0x3a,
  251. 0xcd, 0xad, 0x06, 0x57, 0xfc, 0xcf, 0xec, 0x71, 0x9b, 0x1f, 0x5c, 0x3e,
  252. 0x4e, 0x46, 0x04, 0x1f, 0x38, 0x81, 0x47, 0xfb, 0x4c, 0xfd, 0xb4, 0x77,
  253. 0xa5, 0x24, 0x71, 0xf7, 0xa9, 0xa9, 0x69, 0x10, 0xb8, 0x55, 0x32, 0x2e,
  254. 0xdb, 0x63, 0x40, 0xd8, 0xa0, 0x0e, 0xf0, 0x92, 0x35, 0x05, 0x11, 0xe3,
  255. 0x0a, 0xbe, 0xc1, 0xff, 0xf9, 0xe3, 0xa2, 0x6e, 0x7f, 0xb2, 0x9f, 0x8c,
  256. 0x18, 0x30, 0x23, 0xc3, 0x58, 0x7e, 0x38, 0xda, 0x00, 0x77, 0xd9, 0xb4,
  257. 0x76, 0x3e, 0x4e, 0x4b, 0x94, 0xb2, 0xbb, 0xc1, 0x94, 0xc6, 0x65, 0x1e,
  258. 0x77, 0xca, 0xf9, 0x92, 0xee, 0xaa, 0xc0, 0x23, 0x2a, 0x28, 0x1b, 0xf6,
  259. 0xb3, 0xa7, 0x39, 0xc1, 0x22, 0x61, 0x16, 0x82, 0x0a, 0xe8, 0xdb, 0x58,
  260. 0x47, 0xa6, 0x7c, 0xbe, 0xf9, 0xc9, 0x09, 0x1b, 0x46, 0x2d, 0x53, 0x8c,
  261. 0xd7, 0x2b, 0x03, 0x74, 0x6a, 0xe7, 0x7f, 0x5e, 0x62, 0x29, 0x2c, 0x31,
  262. 0x15, 0x62, 0xa8, 0x46, 0x50, 0x5d, 0xc8, 0x2d, 0xb8, 0x54, 0x33, 0x8a,
  263. 0xe4, 0x9f, 0x52, 0x35, 0xc9, 0x5b, 0x91, 0x17, 0x8c, 0xcf, 0x2d, 0xd5,
  264. 0xca, 0xce, 0xf4, 0x03, 0xec, 0x9d, 0x18, 0x10, 0xc6, 0x27, 0x2b, 0x04,
  265. 0x5b, 0x3b, 0x71, 0xf9, 0xdc, 0x6b, 0x80, 0xd6, 0x3f, 0xdd, 0x4a, 0x8e,
  266. 0x9a, 0xdb, 0x1e, 0x69, 0x62, 0xa6, 0x95, 0x26, 0xd4, 0x31, 0x61, 0xc1,
  267. 0xa4, 0x1d, 0x57, 0x0d, 0x79, 0x38, 0xda, 0xd4, 0xa4, 0x0e, 0x32, 0x9c,
  268. 0xcf, 0xf4, 0x6a, 0xaa, 0x36, 0xad, 0x00, 0x4c, 0xf6, 0x00, 0xc8, 0x38,
  269. 0x1e, 0x42, 0x5a, 0x31, 0xd9, 0x51, 0xae, 0x64, 0xfd, 0xb2, 0x3f, 0xce,
  270. 0xc9, 0x50, 0x9d, 0x43, 0x68, 0x7f, 0xeb, 0x69, 0xed, 0xd1, 0xcc, 0x5e,
  271. 0x0b, 0x8c, 0xc3, 0xbd, 0xf6, 0x4b, 0x10, 0xef, 0x86, 0xb6, 0x31, 0x42,
  272. 0xa3, 0xab, 0x88, 0x29, 0x55, 0x5b, 0x2f, 0x74, 0x7c, 0x93, 0x26, 0x65,
  273. 0xcb, 0x2c, 0x0f, 0x1c, 0xc0, 0x1b, 0xd7, 0x02, 0x29, 0x38, 0x88, 0x39,
  274. 0xd2, 0xaf, 0x05, 0xe4, 0x54, 0x50, 0x4a, 0xc7, 0x8b, 0x75, 0x82, 0x82,
  275. 0x28, 0x46, 0xc0, 0xba, 0x35, 0xc3, 0x5f, 0x5c, 0x59, 0x16, 0x0c, 0xc0,
  276. 0x46, 0xfd, 0x82, 0x51, 0x54, 0x1f, 0xc6, 0x8c, 0x9c, 0x86, 0xb0, 0x22,
  277. 0xbb, 0x70, 0x99, 0x87, 0x6a, 0x46, 0x0e, 0x74, 0x51, 0xa8, 0xa9, 0x31,
  278. 0x09, 0x70, 0x3f, 0xee, 0x1c, 0x21, 0x7e, 0x6c, 0x38, 0x26, 0xe5, 0x2c,
  279. 0x51, 0xaa, 0x69, 0x1e, 0x0e, 0x42, 0x3c, 0xfc, 0x99, 0xe9, 0xe3, 0x16,
  280. 0x50, 0xc1, 0x21, 0x7b, 0x62, 0x48, 0x16, 0xcd, 0xad, 0x9a, 0x95, 0xf9,
  281. 0xd5, 0xb8, 0x01, 0x94, 0x88, 0xd9, 0xc0, 0xa0, 0xa1, 0xfe, 0x30, 0x75,
  282. 0xa5, 0x77, 0xe2, 0x31, 0x83, 0xf8, 0x1d, 0x4a, 0x3f, 0x2f, 0xa4, 0x57,
  283. 0x1e, 0xfc, 0x8c, 0xe0, 0xba, 0x8a, 0x4f, 0xe8, 0xb6, 0x85, 0x5d, 0xfe,
  284. 0x72, 0xb0, 0xa6, 0x6e, 0xde, 0xd2, 0xfb, 0xab, 0xfb, 0xe5, 0x8a, 0x30,
  285. 0xfa, 0xfa, 0xbe, 0x1c, 0x5d, 0x71, 0xa8, 0x7e, 0x2f, 0x74, 0x1e, 0xf8,
  286. 0xc1, 0xfe, 0x86, 0xfe, 0xa6, 0xbb, 0xfd, 0xe5, 0x30, 0x67, 0x7f, 0x0d,
  287. 0x97, 0xd1, 0x1d, 0x49, 0xf7, 0xa8, 0x44, 0x3d, 0x08, 0x22, 0xe5, 0x06,
  288. 0xa9, 0xf4, 0x61, 0x4e, 0x01, 0x1e, 0x2a, 0x94, 0x83, 0x8f, 0xf8, 0x8c,
  289. 0xd6, 0x8c, 0x8b, 0xb7, 0xc5, 0xc6, 0x42, 0x4c, 0xff, 0xff, 0xff, 0xff,
  290. 0xff, 0xff, 0xff, 0xff,
  291. };
  292. /* RFC 3526, Section 3 */
  293. static const uint8_t tls_dh14_prime[] = {
  294. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2,
  295. 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1,
  296. 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6,
  297. 0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd,
  298. 0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d,
  299. 0xf2, 0x5f, 0x14, 0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45,
  300. 0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4, 0x4c, 0x42, 0xe9,
  301. 0xa6, 0x37, 0xed, 0x6b, 0x0b, 0xff, 0x5c, 0xb6, 0xf4, 0x06, 0xb7, 0xed,
  302. 0xee, 0x38, 0x6b, 0xfb, 0x5a, 0x89, 0x9f, 0xa5, 0xae, 0x9f, 0x24, 0x11,
  303. 0x7c, 0x4b, 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe4, 0x5b, 0x3d,
  304. 0xc2, 0x00, 0x7c, 0xb8, 0xa1, 0x63, 0xbf, 0x05, 0x98, 0xda, 0x48, 0x36,
  305. 0x1c, 0x55, 0xd3, 0x9a, 0x69, 0x16, 0x3f, 0xa8, 0xfd, 0x24, 0xcf, 0x5f,
  306. 0x83, 0x65, 0x5d, 0x23, 0xdc, 0xa3, 0xad, 0x96, 0x1c, 0x62, 0xf3, 0x56,
  307. 0x20, 0x85, 0x52, 0xbb, 0x9e, 0xd5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6d,
  308. 0x67, 0x0c, 0x35, 0x4e, 0x4a, 0xbc, 0x98, 0x04, 0xf1, 0x74, 0x6c, 0x08,
  309. 0xca, 0x18, 0x21, 0x7c, 0x32, 0x90, 0x5e, 0x46, 0x2e, 0x36, 0xce, 0x3b,
  310. 0xe3, 0x9e, 0x77, 0x2c, 0x18, 0x0e, 0x86, 0x03, 0x9b, 0x27, 0x83, 0xa2,
  311. 0xec, 0x07, 0xa2, 0x8f, 0xb5, 0xc5, 0x5d, 0xf0, 0x6f, 0x4c, 0x52, 0xc9,
  312. 0xde, 0x2b, 0xcb, 0xf6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7c,
  313. 0xea, 0x95, 0x6a, 0xe5, 0x15, 0xd2, 0x26, 0x18, 0x98, 0xfa, 0x05, 0x10,
  314. 0x15, 0x72, 0x8e, 0x5a, 0x8a, 0xac, 0xaa, 0x68, 0xff, 0xff, 0xff, 0xff,
  315. 0xff, 0xff, 0xff, 0xff,
  316. };
  317. static const struct tls_named_group tls_group_pref[] = {
  318. { "secp256r1", 23, TLS_GROUP_TYPE_EC },
  319. { "secp384r1", 24, TLS_GROUP_TYPE_EC },
  320. {
  321. "ffdhe2048", 256, TLS_GROUP_TYPE_FF,
  322. .ff = {
  323. .prime = tls_ffdhe2048_prime,
  324. .prime_len = sizeof(tls_ffdhe2048_prime),
  325. .generator = 2,
  326. },
  327. },
  328. {
  329. "ffdhe3072", 257, TLS_GROUP_TYPE_FF,
  330. .ff = {
  331. .prime = tls_ffdhe3072_prime,
  332. .prime_len = sizeof(tls_ffdhe3072_prime),
  333. .generator = 2,
  334. },
  335. },
  336. {
  337. "ffdhe4096", 258, TLS_GROUP_TYPE_FF,
  338. .ff = {
  339. .prime = tls_ffdhe4096_prime,
  340. .prime_len = sizeof(tls_ffdhe4096_prime),
  341. .generator = 2,
  342. },
  343. },
  344. {
  345. "ffdhe6144", 259, TLS_GROUP_TYPE_FF,
  346. .ff = {
  347. .prime = tls_ffdhe6144_prime,
  348. .prime_len = sizeof(tls_ffdhe6144_prime),
  349. .generator = 2,
  350. },
  351. },
  352. {
  353. "ffdhe8192", 260, TLS_GROUP_TYPE_FF,
  354. .ff = {
  355. .prime = tls_ffdhe8192_prime,
  356. .prime_len = sizeof(tls_ffdhe8192_prime),
  357. .generator = 2,
  358. },
  359. },
  360. };
  361. /*
  362. * For now hardcode a default group for non-RFC7919 clients - same group
  363. * as some other TLS servers use, which is actually a downside because the
  364. * more common the group parameters are the less secure they are assumed
  365. * to be, but it is also a test that the group is sufficiently good.
  366. *
  367. * Eventually we need to make this configurable so that a unique
  368. * likely-prime number generated by either 'openssl dhparam' or
  369. * 'ssh-keygen -G' can be set, or parse /etc/ssh/moduli to select
  370. * a random pre-generated FFDH group each time.
  371. */
  372. static const struct tls_named_group tls_default_ffdh_group = {
  373. "RFC3526/Oakley Group 14", 0, TLS_GROUP_TYPE_FF,
  374. .ff = {
  375. .prime = tls_dh14_prime,
  376. .prime_len = sizeof(tls_dh14_prime),
  377. .generator = 2,
  378. },
  379. };
  380. /* RFC 8422, Section 5.1 + RFC 7919 */
  381. static ssize_t tls_elliptic_curves_client_write(struct l_tls *tls,
  382. uint8_t *buf, size_t len)
  383. {
  384. uint8_t *ptr = buf;
  385. unsigned int i;
  386. if (len < 2 + L_ARRAY_SIZE(tls_group_pref) * 2)
  387. return -ENOMEM;
  388. l_put_be16(L_ARRAY_SIZE(tls_group_pref) * 2, ptr);
  389. ptr += 2;
  390. for (i = 0; i < L_ARRAY_SIZE(tls_group_pref); i++) {
  391. l_put_be16(tls_group_pref[i].id, ptr);
  392. ptr += 2;
  393. }
  394. return ptr - buf;
  395. }
  396. static bool tls_elliptic_curves_client_handle(struct l_tls *tls,
  397. const uint8_t *buf, size_t len)
  398. {
  399. bool ffdh_offered = false;
  400. if (len < 2)
  401. return false;
  402. if (l_get_be16(buf) != len - 2 || (len & 1))
  403. return false;
  404. buf += 2;
  405. len -= 2;
  406. /*
  407. * We select one group for DH and one group for ECDH and we'll
  408. * let the cipher suite selection logic decide which one is actually
  409. * used. It will take into account the client's cipher suite
  410. * preference but it could just as well look at the strengths of
  411. * the groups chosen. This is not done for simplicity but RFC 7919
  412. * suggests the Supported Groups should actually overrule the
  413. * cipher suite preference list in case of a conflict:
  414. * "A server that encounters such a contradiction when selecting
  415. * between an ECDHE or FFDHE key exchange mechanism while trying
  416. * to respect client preferences SHOULD give priority to the
  417. * Supported Groups extension (...) but MAY resolve the
  418. * contradiction any way it sees fit."
  419. *
  420. * Not implemented: "If a non-anonymous FFDHE cipher suite is
  421. * selected and the TLS client has used this extension to offer
  422. * an FFDHE group of comparable or greater strength than the server's
  423. * public key, the server SHOULD select an FFDHE group at least
  424. * as strong as the server's public key."
  425. */
  426. while (len) {
  427. unsigned int i;
  428. uint16_t id;
  429. const struct tls_named_group *group = NULL;
  430. id = l_get_be16(buf);
  431. buf += 2;
  432. len -= 2;
  433. if (id >> 8 == 1) /* RFC 7919 ids */
  434. ffdh_offered = true;
  435. for (i = 0; i < L_ARRAY_SIZE(tls_group_pref); i++)
  436. if (tls_group_pref[i].id == id) {
  437. group = &tls_group_pref[i];
  438. break;
  439. }
  440. if (!group)
  441. continue;
  442. switch (group->type) {
  443. case TLS_GROUP_TYPE_EC:
  444. if (!tls->negotiated_curve)
  445. tls->negotiated_curve = group;
  446. break;
  447. case TLS_GROUP_TYPE_FF:
  448. if (!tls->negotiated_ff_group)
  449. tls->negotiated_ff_group = group;
  450. break;
  451. }
  452. }
  453. /*
  454. * Note we need to treat DH slightly differently from ECDH groups
  455. * here because the extension is defined in RFC 8422 and if the
  456. * client offers no elliptic curves we can't use ECDH at all:
  457. * "If a server (...) is unable to complete the ECC handshake while
  458. * restricting itself to the enumerated curves (...), it MUST NOT
  459. * negotiate the use of an ECC cipher suite. Depending on what
  460. * other cipher suites are proposed by the client and supported by
  461. * the server, this may result in a fatal handshake failure alert
  462. * due to the lack of common cipher suites."
  463. *
  464. * On the other hand if the client offers no FFDH groups we can
  465. * only assume the client is okay with us picking a group. Note
  466. * the "includes any FFDHE group" part in RFC 7919 Section 4:
  467. * "If a compatible TLS server receives a Supported Groups
  468. * extension from a client that includes any FFDHE group (i.e.,
  469. * any codepoint between 256 and 511, inclusive, even if unknown
  470. * to the server), and if none of the client-proposed FFDHE groups
  471. * are known and acceptable to the server, then the server MUST
  472. * NOT select an FFDHE cipher suite."
  473. */
  474. if (tls->negotiated_curve)
  475. TLS_DEBUG("Negotiated %s", tls->negotiated_curve->name);
  476. else
  477. TLS_DEBUG("non-fatal: No common supported elliptic curves "
  478. "for ECDHE");
  479. if (tls->negotiated_ff_group)
  480. TLS_DEBUG("Negotiated %s", tls->negotiated_ff_group->name);
  481. else if (ffdh_offered)
  482. TLS_DEBUG("non-fatal: No common supported finite-field groups "
  483. "for DHE");
  484. else
  485. tls->negotiated_ff_group = &tls_default_ffdh_group;
  486. return true;
  487. }
  488. static bool tls_elliptic_curves_client_absent(struct l_tls *tls)
  489. {
  490. unsigned int i;
  491. for (i = 0; i < L_ARRAY_SIZE(tls_group_pref); i++)
  492. if (tls_group_pref[i].type == TLS_GROUP_TYPE_EC) {
  493. tls->negotiated_curve = &tls_group_pref[i];
  494. break;
  495. }
  496. tls->negotiated_ff_group = &tls_default_ffdh_group;
  497. return true;
  498. }
  499. static bool tls_ec_point_formats_client_handle(struct l_tls *tls,
  500. const uint8_t *buf, size_t len)
  501. {
  502. if (len < 2)
  503. return false;
  504. if (buf[0] != len - 1)
  505. return false;
  506. if (!memchr(buf + 1, 0, len - 1)) {
  507. TLS_DEBUG("Uncompressed point format missing");
  508. return false;
  509. }
  510. return true;
  511. }
  512. /*
  513. * For compatibility with clients respond to a valid Client Hello Supported
  514. * Point Formats extension with the hardcoded confirmation that we do
  515. * support the single valid point format. As a client we never send this
  516. * extension so we never have to handle a server response to it either.
  517. */
  518. static ssize_t tls_ec_point_formats_server_write(struct l_tls *tls,
  519. uint8_t *buf, size_t len)
  520. {
  521. if (len < 2)
  522. return -ENOMEM;
  523. buf[0] = 0x01; /* ec_point_format_list length */
  524. buf[1] = 0x00; /* uncompressed */
  525. return 2;
  526. }
  527. /*
  528. * This is used to append the list of signature algorithm and hash type
  529. * combinations we support to the Signature Algorithms client hello
  530. * extension (on the client) and the Certificate Request message (on the
  531. * server). In both cases we need to list the algorithms we support for
  532. * two use cases: certificate chain verification and signing/verifying
  533. * Server Key Exchange params (server->client) or Certificate Verify
  534. * data (client->server).
  535. *
  536. * For the server side RFC 5462, Section 7.4.1.4.1 says:
  537. * "If the client [...] is willing to use them for verifying
  538. * messages sent by the server, i.e., server certificates and
  539. * server key exchange [...] it MUST send the
  540. * signature_algorithms extension, listing the algorithms it
  541. * is willing to accept."
  542. *
  543. * As for the certificate chains we mostly rely on the kernel to do
  544. * this so when we receive the list we do not currently verify the
  545. * that the whole chain uses only algorithms from the list on either
  546. * side (TODO). But we know that the chain verification in the kernel
  547. * can use a superset of the hash algorithms l_checksum supports.
  548. * For the Server Key Exchange and Certificate Verify signatures we
  549. * use l_checksum but we need to map the TLS-specific hash IDs to
  550. * enum l_checksum_type using the tls_handshake_hash_data list in
  551. * signature->sign() and signature->verify(), so we use
  552. * tls_handshake_hash_data as the definitive list of allowed hash
  553. * algorithms.
  554. *
  555. * Our supported signature algorithms can work with any hash type so we
  556. * basically have to send all possible combinations of the signature
  557. * algorithm IDs from the supported cipher suites (except anonymous)
  558. * with the hash algorithms we can use for signature verification,
  559. * i.e. those in the tls_handshake_hash_data table.
  560. */
  561. ssize_t tls_write_signature_algorithms(struct l_tls *tls,
  562. uint8_t *buf, size_t len)
  563. {
  564. uint8_t *ptr = buf;
  565. unsigned int i, j;
  566. struct tls_cipher_suite **suite;
  567. uint8_t sig_alg_ids[16];
  568. uint8_t hash_ids[16];
  569. unsigned int sig_alg_cnt = 0;
  570. unsigned int hash_cnt = 0;
  571. for (suite = tls->cipher_suite_pref_list; *suite; suite++) {
  572. uint8_t id;
  573. if (!(*suite)->signature)
  574. continue;
  575. id = (*suite)->signature->id;
  576. if (memchr(sig_alg_ids, id, sig_alg_cnt))
  577. continue;
  578. if (!tls_cipher_suite_is_compatible(tls, *suite, NULL))
  579. continue;
  580. if (sig_alg_cnt >= sizeof(sig_alg_ids))
  581. return -ENOMEM;
  582. sig_alg_ids[sig_alg_cnt++] = id;
  583. }
  584. for (i = 0; i < __HANDSHAKE_HASH_COUNT; i++) {
  585. const struct tls_hash_algorithm *hash =
  586. &tls_handshake_hash_data[i];
  587. bool supported;
  588. /*
  589. * The hash types in the Signature Algorithms extension are
  590. * all supported hashes but the ones in the Certificate
  591. * Request (server->client) must be in the set for which we
  592. * maintain handshake message hashes because that is going
  593. * to be used in Certificate Verify.
  594. */
  595. if (tls->server)
  596. supported = !!tls->handshake_hash[i];
  597. else
  598. supported = l_checksum_is_supported(hash->l_id, false);
  599. if (supported)
  600. hash_ids[hash_cnt++] = hash->tls_id;
  601. }
  602. if (len < 2 + sig_alg_cnt * hash_cnt * 2)
  603. return -ENOMEM;
  604. l_put_be16(sig_alg_cnt * hash_cnt * 2, ptr);
  605. ptr += 2;
  606. for (i = 0; i < sig_alg_cnt; i++)
  607. for (j = 0; j < hash_cnt; j++) {
  608. *ptr++ = hash_ids[j];
  609. *ptr++ = sig_alg_ids[i];
  610. }
  611. return ptr - buf;
  612. }
  613. ssize_t tls_parse_signature_algorithms(struct l_tls *tls,
  614. const uint8_t *buf, size_t len)
  615. {
  616. const uint8_t *ptr = buf;
  617. enum handshake_hash_type first_supported, hash;
  618. const struct tls_hash_algorithm *preferred;
  619. struct tls_cipher_suite **suite;
  620. uint8_t sig_alg_ids[16];
  621. unsigned int sig_alg_cnt = 0;
  622. /*
  623. * This only makes sense as a variable-length field, assume
  624. * there's a typo in RFC5246 7.4.4 here.
  625. */
  626. if (len < 4)
  627. return -EINVAL;
  628. if (l_get_be16(ptr) > len - 2)
  629. return -EINVAL;
  630. len = l_get_be16(ptr);
  631. ptr += 2;
  632. if (len & 1)
  633. return -EINVAL;
  634. for (suite = tls->cipher_suite_pref_list; *suite; suite++) {
  635. uint8_t id;
  636. if (!(*suite)->signature)
  637. continue;
  638. id = (*suite)->signature->id;
  639. if (memchr(sig_alg_ids, id, sig_alg_cnt))
  640. continue;
  641. if (!tls_cipher_suite_is_compatible(tls, *suite, NULL))
  642. continue;
  643. if (sig_alg_cnt >= sizeof(sig_alg_ids))
  644. return -ENOMEM;
  645. sig_alg_ids[sig_alg_cnt++] = id;
  646. }
  647. /*
  648. * In 1.2 we force our preference for SHA256/SHA384 (depending on
  649. * cipher suite's PRF hmac) if it is supported by the peer because
  650. * that must be supported anyway for the PRF and the Finished hash
  651. * meaning that we only need to keep one hash instead of two.
  652. * If not available fall back to the first common hash algorithm.
  653. */
  654. first_supported = -1;
  655. if (tls->prf_hmac)
  656. preferred = tls->prf_hmac;
  657. else
  658. preferred = &tls_handshake_hash_data[HANDSHAKE_HASH_SHA256];
  659. while (len) {
  660. uint8_t hash_id = *ptr++;
  661. uint8_t sig_alg_id = *ptr++;
  662. bool supported;
  663. len -= 2;
  664. /* Ignore hash types for signatures other than ours */
  665. if (tls->pending.cipher_suite &&
  666. (!tls->pending.cipher_suite->signature ||
  667. tls->pending.cipher_suite->signature->id !=
  668. sig_alg_id))
  669. continue;
  670. if (!tls->pending.cipher_suite &&
  671. !memchr(sig_alg_ids, sig_alg_id, sig_alg_cnt))
  672. continue;
  673. if (hash_id == preferred->tls_id) {
  674. for (hash = 0; hash < __HANDSHAKE_HASH_COUNT; hash++)
  675. if (&tls_handshake_hash_data[hash] == preferred)
  676. break;
  677. break;
  678. }
  679. if ((int) first_supported != -1)
  680. continue;
  681. for (hash = 0; hash < __HANDSHAKE_HASH_COUNT; hash++)
  682. if (hash_id == tls_handshake_hash_data[hash].tls_id)
  683. break;
  684. if (hash == __HANDSHAKE_HASH_COUNT)
  685. continue;
  686. if (tls->server)
  687. supported = l_checksum_is_supported(
  688. tls_handshake_hash_data[hash].l_id,
  689. false);
  690. else
  691. supported = !!tls->handshake_hash[hash];
  692. if (supported)
  693. first_supported = hash;
  694. }
  695. if (len)
  696. tls->signature_hash = hash;
  697. else if ((int) first_supported != -1)
  698. tls->signature_hash = first_supported;
  699. else
  700. return -ENOTSUP;
  701. return ptr + len - buf;
  702. }
  703. /* RFC 5462, Section 7.4.1.4.1 */
  704. static ssize_t tls_signature_algorithms_client_write(struct l_tls *tls,
  705. uint8_t *buf, size_t len)
  706. {
  707. /*
  708. * "Note: this extension is not meaningful for TLS versions
  709. * prior to 1.2. Clients MUST NOT offer it if they are offering
  710. * prior versions."
  711. */
  712. if (tls->max_version < L_TLS_V12)
  713. return -ENOMSG;
  714. return tls_write_signature_algorithms(tls, buf, len);
  715. }
  716. static bool tls_signature_algorithms_client_handle(struct l_tls *tls,
  717. const uint8_t *buf, size_t len)
  718. {
  719. ssize_t ret;
  720. /*
  721. * "However, even if clients do offer it, the rules specified in
  722. * [TLSEXT] require servers to ignore extensions they do not
  723. * understand."
  724. */
  725. if (tls->max_version < L_TLS_V12)
  726. return true;
  727. ret = tls_parse_signature_algorithms(tls, buf, len);
  728. if (ret == -ENOTSUP)
  729. TLS_DEBUG("No common signature algorithms");
  730. /*
  731. * TODO: also check our certificate chain against the parsed
  732. * signature algorithms.
  733. */
  734. return ret == (ssize_t) len;
  735. }
  736. static bool tls_signature_algorithms_client_absent(struct l_tls *tls)
  737. {
  738. /*
  739. * "If the client does not send the signature_algorithms extension,
  740. * the server MUST do the following:
  741. * - [...] behave as if client had sent the value {sha1,rsa}.
  742. * - [...] behave as if client had sent the value {sha1,dsa}.
  743. * - [...] behave as if client had sent the value {sha1,ecdsa}.
  744. */
  745. if (tls->max_version >= L_TLS_V12)
  746. tls->signature_hash = HANDSHAKE_HASH_SHA1;
  747. return true;
  748. }
  749. const struct tls_hello_extension tls_extensions[] = {
  750. {
  751. "Supported Groups", "elliptic_curves", 10,
  752. tls_elliptic_curves_client_write,
  753. tls_elliptic_curves_client_handle,
  754. tls_elliptic_curves_client_absent,
  755. NULL, NULL, NULL,
  756. },
  757. {
  758. "Supported Point Formats", "ec_point_formats", 11,
  759. NULL,
  760. tls_ec_point_formats_client_handle,
  761. NULL,
  762. tls_ec_point_formats_server_write,
  763. NULL, NULL,
  764. },
  765. {
  766. "Signature Algorithms", "signature_algoritms", 13,
  767. tls_signature_algorithms_client_write,
  768. tls_signature_algorithms_client_handle,
  769. tls_signature_algorithms_client_absent,
  770. NULL, NULL, NULL,
  771. },
  772. {}
  773. };
  774. const struct tls_named_group *tls_find_group(uint16_t id)
  775. {
  776. unsigned int i;
  777. for (i = 0; i < L_ARRAY_SIZE(tls_group_pref); i++)
  778. if (tls_group_pref[i].id == id)
  779. return &tls_group_pref[i];
  780. return NULL;
  781. }
  782. const struct tls_named_group *tls_find_ff_group(const uint8_t *prime,
  783. size_t prime_len,
  784. const uint8_t *generator,
  785. size_t generator_len)
  786. {
  787. unsigned int i;
  788. if (generator_len != 1)
  789. return NULL;
  790. for (i = 0; i < L_ARRAY_SIZE(tls_group_pref); i++) {
  791. const struct tls_named_group *g = &tls_group_pref[i];
  792. if (g->type != TLS_GROUP_TYPE_FF)
  793. continue;
  794. if (g->ff.prime_len != prime_len ||
  795. memcmp(prime, g->ff.prime, prime_len))
  796. continue;
  797. if (g->ff.generator != *generator)
  798. continue;
  799. return g;
  800. }
  801. return NULL;
  802. }