protocol-quic 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/ngtcp2/AUTHORS +44 -0
  4. data/ext/ngtcp2/CMakeLists.txt +431 -0
  5. data/ext/ngtcp2/CMakeOptions.txt +17 -0
  6. data/ext/ngtcp2/COPYING +22 -0
  7. data/ext/ngtcp2/ChangeLog +0 -0
  8. data/ext/ngtcp2/Makefile.am +60 -0
  9. data/ext/ngtcp2/NEWS +0 -0
  10. data/ext/ngtcp2/README +1 -0
  11. data/ext/ngtcp2/README.rst +258 -0
  12. data/ext/ngtcp2/ci/build_boringssl.sh +10 -0
  13. data/ext/ngtcp2/ci/build_nghttp3.sh +9 -0
  14. data/ext/ngtcp2/ci/build_openssl1.sh +8 -0
  15. data/ext/ngtcp2/ci/build_openssl1_cross.sh +9 -0
  16. data/ext/ngtcp2/ci/build_openssl3.sh +8 -0
  17. data/ext/ngtcp2/ci/build_picotls.sh +26 -0
  18. data/ext/ngtcp2/ci/build_wolfssl.sh +9 -0
  19. data/ext/ngtcp2/ci/gen-certificate.sh +8 -0
  20. data/ext/ngtcp2/cmake/ExtractValidFlags.cmake +31 -0
  21. data/ext/ngtcp2/cmake/FindCUnit.cmake +40 -0
  22. data/ext/ngtcp2/cmake/FindJemalloc.cmake +40 -0
  23. data/ext/ngtcp2/cmake/FindLibev.cmake +38 -0
  24. data/ext/ngtcp2/cmake/FindLibnghttp3.cmake +41 -0
  25. data/ext/ngtcp2/cmake/Findwolfssl.cmake +41 -0
  26. data/ext/ngtcp2/cmake/Version.cmake +11 -0
  27. data/ext/ngtcp2/cmakeconfig.h.in +36 -0
  28. data/ext/ngtcp2/configure.ac +755 -0
  29. data/ext/ngtcp2/crypto/CMakeLists.txt +56 -0
  30. data/ext/ngtcp2/crypto/Makefile.am +49 -0
  31. data/ext/ngtcp2/crypto/boringssl/CMakeLists.txt +64 -0
  32. data/ext/ngtcp2/crypto/boringssl/Makefile.am +39 -0
  33. data/ext/ngtcp2/crypto/boringssl/boringssl.c +630 -0
  34. data/ext/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.pc.in +33 -0
  35. data/ext/ngtcp2/crypto/gnutls/CMakeLists.txt +86 -0
  36. data/ext/ngtcp2/crypto/gnutls/Makefile.am +43 -0
  37. data/ext/ngtcp2/crypto/gnutls/gnutls.c +644 -0
  38. data/ext/ngtcp2/crypto/gnutls/libngtcp2_crypto_gnutls.pc.in +33 -0
  39. data/ext/ngtcp2/crypto/includes/CMakeLists.txt +56 -0
  40. data/ext/ngtcp2/crypto/includes/Makefile.am +45 -0
  41. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +893 -0
  42. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_boringssl.h +104 -0
  43. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_gnutls.h +107 -0
  44. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +132 -0
  45. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h +246 -0
  46. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  47. data/ext/ngtcp2/crypto/openssl/CMakeLists.txt +86 -0
  48. data/ext/ngtcp2/crypto/openssl/Makefile.am +43 -0
  49. data/ext/ngtcp2/crypto/openssl/libngtcp2_crypto_openssl.pc.in +33 -0
  50. data/ext/ngtcp2/crypto/openssl/openssl.c +807 -0
  51. data/ext/ngtcp2/crypto/picotls/CMakeLists.txt +65 -0
  52. data/ext/ngtcp2/crypto/picotls/Makefile.am +39 -0
  53. data/ext/ngtcp2/crypto/picotls/libngtcp2_crypto_picotls.pc.in +33 -0
  54. data/ext/ngtcp2/crypto/picotls/picotls.c +707 -0
  55. data/ext/ngtcp2/crypto/shared.c +1431 -0
  56. data/ext/ngtcp2/crypto/shared.h +350 -0
  57. data/ext/ngtcp2/crypto/wolfssl/CMakeLists.txt +84 -0
  58. data/ext/ngtcp2/crypto/wolfssl/Makefile.am +43 -0
  59. data/ext/ngtcp2/crypto/wolfssl/libngtcp2_crypto_wolfssl.pc.in +33 -0
  60. data/ext/ngtcp2/crypto/wolfssl/wolfssl.c +534 -0
  61. data/ext/ngtcp2/doc/Makefile.am +65 -0
  62. data/ext/ngtcp2/doc/make.bat +35 -0
  63. data/ext/ngtcp2/doc/mkapiref.py +356 -0
  64. data/ext/ngtcp2/doc/source/conf.py.in +94 -0
  65. data/ext/ngtcp2/doc/source/index.rst +22 -0
  66. data/ext/ngtcp2/doc/source/programmers-guide.rst +476 -0
  67. data/ext/ngtcp2/docker/Dockerfile +39 -0
  68. data/ext/ngtcp2/examples/CMakeLists.txt +361 -0
  69. data/ext/ngtcp2/examples/Makefile.am +228 -0
  70. data/ext/ngtcp2/examples/client.cc +3049 -0
  71. data/ext/ngtcp2/examples/client.h +192 -0
  72. data/ext/ngtcp2/examples/client_base.cc +202 -0
  73. data/ext/ngtcp2/examples/client_base.h +213 -0
  74. data/ext/ngtcp2/examples/debug.cc +298 -0
  75. data/ext/ngtcp2/examples/debug.h +124 -0
  76. data/ext/ngtcp2/examples/examplestest.cc +84 -0
  77. data/ext/ngtcp2/examples/gtlssimpleclient.c +720 -0
  78. data/ext/ngtcp2/examples/h09client.cc +2601 -0
  79. data/ext/ngtcp2/examples/h09client.h +196 -0
  80. data/ext/ngtcp2/examples/h09server.cc +3024 -0
  81. data/ext/ngtcp2/examples/h09server.h +237 -0
  82. data/ext/ngtcp2/examples/http.cc +138 -0
  83. data/ext/ngtcp2/examples/http.h +44 -0
  84. data/ext/ngtcp2/examples/network.h +80 -0
  85. data/ext/ngtcp2/examples/server.cc +3731 -0
  86. data/ext/ngtcp2/examples/server.h +256 -0
  87. data/ext/ngtcp2/examples/server_base.cc +58 -0
  88. data/ext/ngtcp2/examples/server_base.h +195 -0
  89. data/ext/ngtcp2/examples/shared.cc +385 -0
  90. data/ext/ngtcp2/examples/shared.h +96 -0
  91. data/ext/ngtcp2/examples/simpleclient.c +683 -0
  92. data/ext/ngtcp2/examples/template.h +71 -0
  93. data/ext/ngtcp2/examples/tests/README.rst +60 -0
  94. data/ext/ngtcp2/examples/tests/__init__.py +0 -0
  95. data/ext/ngtcp2/examples/tests/config.ini.in +32 -0
  96. data/ext/ngtcp2/examples/tests/conftest.py +28 -0
  97. data/ext/ngtcp2/examples/tests/ngtcp2test/__init__.py +6 -0
  98. data/ext/ngtcp2/examples/tests/ngtcp2test/certs.py +476 -0
  99. data/ext/ngtcp2/examples/tests/ngtcp2test/client.py +187 -0
  100. data/ext/ngtcp2/examples/tests/ngtcp2test/env.py +191 -0
  101. data/ext/ngtcp2/examples/tests/ngtcp2test/log.py +101 -0
  102. data/ext/ngtcp2/examples/tests/ngtcp2test/server.py +137 -0
  103. data/ext/ngtcp2/examples/tests/ngtcp2test/tls.py +983 -0
  104. data/ext/ngtcp2/examples/tests/test_01_handshake.py +30 -0
  105. data/ext/ngtcp2/examples/tests/test_02_resume.py +46 -0
  106. data/ext/ngtcp2/examples/tests/test_03_earlydata.py +56 -0
  107. data/ext/ngtcp2/examples/tests/test_04_clientcert.py +57 -0
  108. data/ext/ngtcp2/examples/tests/test_05_ciphers.py +46 -0
  109. data/ext/ngtcp2/examples/tls_client_context.h +52 -0
  110. data/ext/ngtcp2/examples/tls_client_context_boringssl.cc +126 -0
  111. data/ext/ngtcp2/examples/tls_client_context_boringssl.h +49 -0
  112. data/ext/ngtcp2/examples/tls_client_context_gnutls.cc +74 -0
  113. data/ext/ngtcp2/examples/tls_client_context_gnutls.h +50 -0
  114. data/ext/ngtcp2/examples/tls_client_context_openssl.cc +137 -0
  115. data/ext/ngtcp2/examples/tls_client_context_openssl.h +49 -0
  116. data/ext/ngtcp2/examples/tls_client_context_picotls.cc +158 -0
  117. data/ext/ngtcp2/examples/tls_client_context_picotls.h +53 -0
  118. data/ext/ngtcp2/examples/tls_client_context_wolfssl.cc +177 -0
  119. data/ext/ngtcp2/examples/tls_client_context_wolfssl.h +51 -0
  120. data/ext/ngtcp2/examples/tls_client_session.h +52 -0
  121. data/ext/ngtcp2/examples/tls_client_session_boringssl.cc +110 -0
  122. data/ext/ngtcp2/examples/tls_client_session_boringssl.h +52 -0
  123. data/ext/ngtcp2/examples/tls_client_session_gnutls.cc +190 -0
  124. data/ext/ngtcp2/examples/tls_client_session_gnutls.h +52 -0
  125. data/ext/ngtcp2/examples/tls_client_session_openssl.cc +113 -0
  126. data/ext/ngtcp2/examples/tls_client_session_openssl.h +52 -0
  127. data/ext/ngtcp2/examples/tls_client_session_picotls.cc +147 -0
  128. data/ext/ngtcp2/examples/tls_client_session_picotls.h +52 -0
  129. data/ext/ngtcp2/examples/tls_client_session_wolfssl.cc +160 -0
  130. data/ext/ngtcp2/examples/tls_client_session_wolfssl.h +52 -0
  131. data/ext/ngtcp2/examples/tls_server_context.h +52 -0
  132. data/ext/ngtcp2/examples/tls_server_context_boringssl.cc +257 -0
  133. data/ext/ngtcp2/examples/tls_server_context_boringssl.h +54 -0
  134. data/ext/ngtcp2/examples/tls_server_context_gnutls.cc +99 -0
  135. data/ext/ngtcp2/examples/tls_server_context_gnutls.h +59 -0
  136. data/ext/ngtcp2/examples/tls_server_context_openssl.cc +338 -0
  137. data/ext/ngtcp2/examples/tls_server_context_openssl.h +54 -0
  138. data/ext/ngtcp2/examples/tls_server_context_picotls.cc +321 -0
  139. data/ext/ngtcp2/examples/tls_server_context_picotls.h +58 -0
  140. data/ext/ngtcp2/examples/tls_server_context_wolfssl.cc +284 -0
  141. data/ext/ngtcp2/examples/tls_server_context_wolfssl.h +55 -0
  142. data/ext/ngtcp2/examples/tls_server_session.h +52 -0
  143. data/ext/ngtcp2/examples/tls_server_session_boringssl.cc +84 -0
  144. data/ext/ngtcp2/examples/tls_server_session_boringssl.h +47 -0
  145. data/ext/ngtcp2/examples/tls_server_session_gnutls.cc +155 -0
  146. data/ext/ngtcp2/examples/tls_server_session_gnutls.h +46 -0
  147. data/ext/ngtcp2/examples/tls_server_session_openssl.cc +54 -0
  148. data/ext/ngtcp2/examples/tls_server_session_openssl.h +47 -0
  149. data/ext/ngtcp2/examples/tls_server_session_picotls.cc +70 -0
  150. data/ext/ngtcp2/examples/tls_server_session_picotls.h +47 -0
  151. data/ext/ngtcp2/examples/tls_server_session_wolfssl.cc +55 -0
  152. data/ext/ngtcp2/examples/tls_server_session_wolfssl.h +47 -0
  153. data/ext/ngtcp2/examples/tls_session_base_gnutls.cc +87 -0
  154. data/ext/ngtcp2/examples/tls_session_base_gnutls.h +51 -0
  155. data/ext/ngtcp2/examples/tls_session_base_openssl.cc +54 -0
  156. data/ext/ngtcp2/examples/tls_session_base_openssl.h +52 -0
  157. data/ext/ngtcp2/examples/tls_session_base_picotls.cc +56 -0
  158. data/ext/ngtcp2/examples/tls_session_base_picotls.h +54 -0
  159. data/ext/ngtcp2/examples/tls_session_base_wolfssl.cc +54 -0
  160. data/ext/ngtcp2/examples/tls_session_base_wolfssl.h +54 -0
  161. data/ext/ngtcp2/examples/tls_shared_picotls.cc +59 -0
  162. data/ext/ngtcp2/examples/tls_shared_picotls.h +36 -0
  163. data/ext/ngtcp2/examples/util.cc +646 -0
  164. data/ext/ngtcp2/examples/util.h +361 -0
  165. data/ext/ngtcp2/examples/util_gnutls.cc +136 -0
  166. data/ext/ngtcp2/examples/util_openssl.cc +131 -0
  167. data/ext/ngtcp2/examples/util_test.cc +237 -0
  168. data/ext/ngtcp2/examples/util_test.h +45 -0
  169. data/ext/ngtcp2/examples/util_wolfssl.cc +130 -0
  170. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack +0 -0
  171. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack_ecn +0 -0
  172. data/ext/ngtcp2/fuzz/corpus/decode_frame/connection_close +0 -0
  173. data/ext/ngtcp2/fuzz/corpus/decode_frame/crypto +1 -0
  174. data/ext/ngtcp2/fuzz/corpus/decode_frame/data_blocked +1 -0
  175. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram +1 -0
  176. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram_len +1 -0
  177. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_data +1 -0
  178. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_stream_data +0 -0
  179. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_streams +0 -0
  180. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_connection_id +1 -0
  181. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_token +1 -0
  182. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_challenge +1 -0
  183. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_response +1 -0
  184. data/ext/ngtcp2/fuzz/corpus/decode_frame/reset_stream +0 -0
  185. data/ext/ngtcp2/fuzz/corpus/decode_frame/retire_connection_id +1 -0
  186. data/ext/ngtcp2/fuzz/corpus/decode_frame/stop_sending +0 -0
  187. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream +0 -0
  188. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_data_blocked +0 -0
  189. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_len +0 -0
  190. data/ext/ngtcp2/fuzz/corpus/decode_frame/streams_blocked +0 -0
  191. data/ext/ngtcp2/fuzz/corpus/ksl/random +0 -0
  192. data/ext/ngtcp2/fuzz/decode_frame.cc +25 -0
  193. data/ext/ngtcp2/fuzz/ksl.cc +77 -0
  194. data/ext/ngtcp2/interop/Dockerfile +39 -0
  195. data/ext/ngtcp2/interop/run_endpoint.sh +93 -0
  196. data/ext/ngtcp2/lib/CMakeLists.txt +110 -0
  197. data/ext/ngtcp2/lib/Makefile.am +122 -0
  198. data/ext/ngtcp2/lib/includes/CMakeLists.txt +4 -0
  199. data/ext/ngtcp2/lib/includes/Makefile.am +25 -0
  200. data/ext/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +5843 -0
  201. data/ext/ngtcp2/lib/includes/ngtcp2/version.h.in +51 -0
  202. data/ext/ngtcp2/lib/libngtcp2.pc.in +33 -0
  203. data/ext/ngtcp2/lib/ngtcp2_acktr.c +335 -0
  204. data/ext/ngtcp2/lib/ngtcp2_acktr.h +221 -0
  205. data/ext/ngtcp2/lib/ngtcp2_addr.c +117 -0
  206. data/ext/ngtcp2/lib/ngtcp2_addr.h +69 -0
  207. data/ext/ngtcp2/lib/ngtcp2_balloc.c +90 -0
  208. data/ext/ngtcp2/lib/ngtcp2_balloc.h +91 -0
  209. data/ext/ngtcp2/lib/ngtcp2_bbr.c +693 -0
  210. data/ext/ngtcp2/lib/ngtcp2_bbr.h +157 -0
  211. data/ext/ngtcp2/lib/ngtcp2_bbr2.c +1490 -0
  212. data/ext/ngtcp2/lib/ngtcp2_bbr2.h +149 -0
  213. data/ext/ngtcp2/lib/ngtcp2_buf.c +56 -0
  214. data/ext/ngtcp2/lib/ngtcp2_buf.h +108 -0
  215. data/ext/ngtcp2/lib/ngtcp2_cc.c +616 -0
  216. data/ext/ngtcp2/lib/ngtcp2_cc.h +422 -0
  217. data/ext/ngtcp2/lib/ngtcp2_cid.c +147 -0
  218. data/ext/ngtcp2/lib/ngtcp2_cid.h +175 -0
  219. data/ext/ngtcp2/lib/ngtcp2_conn.c +13731 -0
  220. data/ext/ngtcp2/lib/ngtcp2_conn.h +1119 -0
  221. data/ext/ngtcp2/lib/ngtcp2_conn_stat.h +131 -0
  222. data/ext/ngtcp2/lib/ngtcp2_conv.c +291 -0
  223. data/ext/ngtcp2/lib/ngtcp2_conv.h +208 -0
  224. data/ext/ngtcp2/lib/ngtcp2_crypto.c +895 -0
  225. data/ext/ngtcp2/lib/ngtcp2_crypto.h +148 -0
  226. data/ext/ngtcp2/lib/ngtcp2_err.c +154 -0
  227. data/ext/ngtcp2/lib/ngtcp2_err.h +34 -0
  228. data/ext/ngtcp2/lib/ngtcp2_gaptr.c +167 -0
  229. data/ext/ngtcp2/lib/ngtcp2_gaptr.h +98 -0
  230. data/ext/ngtcp2/lib/ngtcp2_idtr.c +79 -0
  231. data/ext/ngtcp2/lib/ngtcp2_idtr.h +89 -0
  232. data/ext/ngtcp2/lib/ngtcp2_ksl.c +819 -0
  233. data/ext/ngtcp2/lib/ngtcp2_ksl.h +345 -0
  234. data/ext/ngtcp2/lib/ngtcp2_log.c +822 -0
  235. data/ext/ngtcp2/lib/ngtcp2_log.h +123 -0
  236. data/ext/ngtcp2/lib/ngtcp2_macro.h +58 -0
  237. data/ext/ngtcp2/lib/ngtcp2_map.c +336 -0
  238. data/ext/ngtcp2/lib/ngtcp2_map.h +136 -0
  239. data/ext/ngtcp2/lib/ngtcp2_mem.c +113 -0
  240. data/ext/ngtcp2/lib/ngtcp2_mem.h +72 -0
  241. data/ext/ngtcp2/lib/ngtcp2_net.h +136 -0
  242. data/ext/ngtcp2/lib/ngtcp2_objalloc.c +40 -0
  243. data/ext/ngtcp2/lib/ngtcp2_objalloc.h +140 -0
  244. data/ext/ngtcp2/lib/ngtcp2_opl.c +46 -0
  245. data/ext/ngtcp2/lib/ngtcp2_opl.h +65 -0
  246. data/ext/ngtcp2/lib/ngtcp2_path.c +77 -0
  247. data/ext/ngtcp2/lib/ngtcp2_path.h +49 -0
  248. data/ext/ngtcp2/lib/ngtcp2_pkt.c +2527 -0
  249. data/ext/ngtcp2/lib/ngtcp2_pkt.h +1235 -0
  250. data/ext/ngtcp2/lib/ngtcp2_pmtud.c +160 -0
  251. data/ext/ngtcp2/lib/ngtcp2_pmtud.h +123 -0
  252. data/ext/ngtcp2/lib/ngtcp2_ppe.c +230 -0
  253. data/ext/ngtcp2/lib/ngtcp2_ppe.h +153 -0
  254. data/ext/ngtcp2/lib/ngtcp2_pq.c +164 -0
  255. data/ext/ngtcp2/lib/ngtcp2_pq.h +126 -0
  256. data/ext/ngtcp2/lib/ngtcp2_pv.c +172 -0
  257. data/ext/ngtcp2/lib/ngtcp2_pv.h +194 -0
  258. data/ext/ngtcp2/lib/ngtcp2_qlog.c +1219 -0
  259. data/ext/ngtcp2/lib/ngtcp2_qlog.h +161 -0
  260. data/ext/ngtcp2/lib/ngtcp2_range.c +61 -0
  261. data/ext/ngtcp2/lib/ngtcp2_range.h +80 -0
  262. data/ext/ngtcp2/lib/ngtcp2_rcvry.h +40 -0
  263. data/ext/ngtcp2/lib/ngtcp2_ringbuf.c +121 -0
  264. data/ext/ngtcp2/lib/ngtcp2_ringbuf.h +132 -0
  265. data/ext/ngtcp2/lib/ngtcp2_rob.c +319 -0
  266. data/ext/ngtcp2/lib/ngtcp2_rob.h +197 -0
  267. data/ext/ngtcp2/lib/ngtcp2_rst.c +138 -0
  268. data/ext/ngtcp2/lib/ngtcp2_rst.h +86 -0
  269. data/ext/ngtcp2/lib/ngtcp2_rtb.c +1676 -0
  270. data/ext/ngtcp2/lib/ngtcp2_rtb.h +468 -0
  271. data/ext/ngtcp2/lib/ngtcp2_str.c +233 -0
  272. data/ext/ngtcp2/lib/ngtcp2_str.h +94 -0
  273. data/ext/ngtcp2/lib/ngtcp2_strm.c +698 -0
  274. data/ext/ngtcp2/lib/ngtcp2_strm.h +310 -0
  275. data/ext/ngtcp2/lib/ngtcp2_unreachable.c +71 -0
  276. data/ext/ngtcp2/lib/ngtcp2_unreachable.h +46 -0
  277. data/ext/ngtcp2/lib/ngtcp2_vec.c +243 -0
  278. data/ext/ngtcp2/lib/ngtcp2_vec.h +120 -0
  279. data/ext/ngtcp2/lib/ngtcp2_version.c +39 -0
  280. data/ext/ngtcp2/lib/ngtcp2_window_filter.c +99 -0
  281. data/ext/ngtcp2/lib/ngtcp2_window_filter.h +65 -0
  282. data/ext/ngtcp2/m4/ax_check_compile_flag.m4 +74 -0
  283. data/ext/ngtcp2/m4/ax_cxx_compile_stdcxx.m4 +1009 -0
  284. data/ext/ngtcp2/tests/CMakeLists.txt +68 -0
  285. data/ext/ngtcp2/tests/Makefile.am +94 -0
  286. data/ext/ngtcp2/tests/main.c +358 -0
  287. data/ext/ngtcp2/tests/ngtcp2_acktr_test.c +367 -0
  288. data/ext/ngtcp2/tests/ngtcp2_acktr_test.h +37 -0
  289. data/ext/ngtcp2/tests/ngtcp2_conn_test.c +9821 -0
  290. data/ext/ngtcp2/tests/ngtcp2_conn_test.h +104 -0
  291. data/ext/ngtcp2/tests/ngtcp2_conv_test.c +430 -0
  292. data/ext/ngtcp2/tests/ngtcp2_conv_test.h +46 -0
  293. data/ext/ngtcp2/tests/ngtcp2_crypto_test.c +667 -0
  294. data/ext/ngtcp2/tests/ngtcp2_crypto_test.h +35 -0
  295. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.c +127 -0
  296. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.h +36 -0
  297. data/ext/ngtcp2/tests/ngtcp2_idtr_test.c +79 -0
  298. data/ext/ngtcp2/tests/ngtcp2_idtr_test.h +34 -0
  299. data/ext/ngtcp2/tests/ngtcp2_ksl_test.c +502 -0
  300. data/ext/ngtcp2/tests/ngtcp2_ksl_test.h +39 -0
  301. data/ext/ngtcp2/tests/ngtcp2_map_test.c +206 -0
  302. data/ext/ngtcp2/tests/ngtcp2_map_test.h +38 -0
  303. data/ext/ngtcp2/tests/ngtcp2_pkt_test.c +1645 -0
  304. data/ext/ngtcp2/tests/ngtcp2_pkt_test.h +68 -0
  305. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.c +153 -0
  306. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.h +34 -0
  307. data/ext/ngtcp2/tests/ngtcp2_pv_test.c +129 -0
  308. data/ext/ngtcp2/tests/ngtcp2_pv_test.h +35 -0
  309. data/ext/ngtcp2/tests/ngtcp2_range_test.c +105 -0
  310. data/ext/ngtcp2/tests/ngtcp2_range_test.h +36 -0
  311. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.c +91 -0
  312. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.h +35 -0
  313. data/ext/ngtcp2/tests/ngtcp2_rob_test.c +552 -0
  314. data/ext/ngtcp2/tests/ngtcp2_rob_test.h +37 -0
  315. data/ext/ngtcp2/tests/ngtcp2_rtb_test.c +470 -0
  316. data/ext/ngtcp2/tests/ngtcp2_rtb_test.h +38 -0
  317. data/ext/ngtcp2/tests/ngtcp2_str_test.c +96 -0
  318. data/ext/ngtcp2/tests/ngtcp2_str_test.h +36 -0
  319. data/ext/ngtcp2/tests/ngtcp2_strm_test.c +575 -0
  320. data/ext/ngtcp2/tests/ngtcp2_strm_test.h +36 -0
  321. data/ext/ngtcp2/tests/ngtcp2_test_helper.c +404 -0
  322. data/ext/ngtcp2/tests/ngtcp2_test_helper.h +191 -0
  323. data/ext/ngtcp2/tests/ngtcp2_vec_test.c +426 -0
  324. data/ext/ngtcp2/tests/ngtcp2_vec_test.h +36 -0
  325. data/ext/ngtcp2/third-party/CMakeLists.txt +34 -0
  326. data/ext/ngtcp2/third-party/Makefile.am +31 -0
  327. data/ext/ngtcp2/third-party/http-parser/AUTHORS +68 -0
  328. data/ext/ngtcp2/third-party/http-parser/LICENSE-MIT +23 -0
  329. data/ext/ngtcp2/third-party/http-parser/Makefile +157 -0
  330. data/ext/ngtcp2/third-party/http-parser/README.md +246 -0
  331. data/ext/ngtcp2/third-party/http-parser/bench.c +111 -0
  332. data/ext/ngtcp2/third-party/http-parser/contrib/parsertrace.c +160 -0
  333. data/ext/ngtcp2/third-party/http-parser/contrib/url_parser.c +47 -0
  334. data/ext/ngtcp2/third-party/http-parser/http_parser.c +2419 -0
  335. data/ext/ngtcp2/third-party/http-parser/http_parser.gyp +111 -0
  336. data/ext/ngtcp2/third-party/http-parser/http_parser.h +431 -0
  337. data/ext/ngtcp2/third-party/http-parser/test.c +4411 -0
  338. data/lib/protocol/quic/version.rb +10 -0
  339. data/lib/protocol/quic.rb +9 -0
  340. data/license.md +21 -0
  341. data.tar.gz.sig +1 -0
  342. metadata +424 -0
  343. metadata.gz.sig +1 -0
@@ -0,0 +1,1431 @@
1
+ /*
2
+ * ngtcp2
3
+ *
4
+ * Copyright (c) 2019 ngtcp2 contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * "Software"), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+ #include "shared.h"
26
+
27
+ #ifdef WIN32
28
+ # include <winsock2.h>
29
+ # include <ws2tcpip.h>
30
+ #else
31
+ # include <netinet/in.h>
32
+ #endif
33
+
34
+ #include <string.h>
35
+ #include <assert.h>
36
+
37
+ #include "ngtcp2_macro.h"
38
+ #include "ngtcp2_net.h"
39
+
40
+ ngtcp2_crypto_md *ngtcp2_crypto_md_init(ngtcp2_crypto_md *md,
41
+ void *md_native_handle) {
42
+ md->native_handle = md_native_handle;
43
+ return md;
44
+ }
45
+
46
+ int ngtcp2_crypto_hkdf_expand_label(uint8_t *dest, size_t destlen,
47
+ const ngtcp2_crypto_md *md,
48
+ const uint8_t *secret, size_t secretlen,
49
+ const uint8_t *label, size_t labellen) {
50
+ static const uint8_t LABEL[] = "tls13 ";
51
+ uint8_t info[256];
52
+ uint8_t *p = info;
53
+
54
+ *p++ = (uint8_t)(destlen / 256);
55
+ *p++ = (uint8_t)(destlen % 256);
56
+ *p++ = (uint8_t)(sizeof(LABEL) - 1 + labellen);
57
+ memcpy(p, LABEL, sizeof(LABEL) - 1);
58
+ p += sizeof(LABEL) - 1;
59
+ memcpy(p, label, labellen);
60
+ p += labellen;
61
+ *p++ = 0;
62
+
63
+ return ngtcp2_crypto_hkdf_expand(dest, destlen, md, secret, secretlen, info,
64
+ (size_t)(p - info));
65
+ }
66
+
67
+ #define NGTCP2_CRYPTO_INITIAL_SECRETLEN 32
68
+
69
+ int ngtcp2_crypto_derive_initial_secrets(uint8_t *rx_secret, uint8_t *tx_secret,
70
+ uint8_t *initial_secret,
71
+ uint32_t version,
72
+ const ngtcp2_cid *client_dcid,
73
+ ngtcp2_crypto_side side) {
74
+ static const uint8_t CLABEL[] = "client in";
75
+ static const uint8_t SLABEL[] = "server in";
76
+ uint8_t initial_secret_buf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
77
+ uint8_t *client_secret;
78
+ uint8_t *server_secret;
79
+ ngtcp2_crypto_ctx ctx;
80
+ const uint8_t *salt;
81
+ size_t saltlen;
82
+
83
+ if (!initial_secret) {
84
+ initial_secret = initial_secret_buf;
85
+ }
86
+
87
+ ngtcp2_crypto_ctx_initial(&ctx);
88
+
89
+ switch (version) {
90
+ case NGTCP2_PROTO_VER_V1:
91
+ salt = (const uint8_t *)NGTCP2_INITIAL_SALT_V1;
92
+ saltlen = sizeof(NGTCP2_INITIAL_SALT_V1) - 1;
93
+ break;
94
+ case NGTCP2_PROTO_VER_V2:
95
+ salt = (const uint8_t *)NGTCP2_INITIAL_SALT_V2;
96
+ saltlen = sizeof(NGTCP2_INITIAL_SALT_V2) - 1;
97
+ break;
98
+ default:
99
+ salt = (const uint8_t *)NGTCP2_INITIAL_SALT_DRAFT;
100
+ saltlen = sizeof(NGTCP2_INITIAL_SALT_DRAFT) - 1;
101
+ }
102
+
103
+ if (ngtcp2_crypto_hkdf_extract(initial_secret, &ctx.md, client_dcid->data,
104
+ client_dcid->datalen, salt, saltlen) != 0) {
105
+ return -1;
106
+ }
107
+
108
+ if (side == NGTCP2_CRYPTO_SIDE_SERVER) {
109
+ client_secret = rx_secret;
110
+ server_secret = tx_secret;
111
+ } else {
112
+ client_secret = tx_secret;
113
+ server_secret = rx_secret;
114
+ }
115
+
116
+ if (ngtcp2_crypto_hkdf_expand_label(
117
+ client_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, &ctx.md,
118
+ initial_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, CLABEL,
119
+ sizeof(CLABEL) - 1) != 0 ||
120
+ ngtcp2_crypto_hkdf_expand_label(
121
+ server_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, &ctx.md,
122
+ initial_secret, NGTCP2_CRYPTO_INITIAL_SECRETLEN, SLABEL,
123
+ sizeof(SLABEL) - 1) != 0) {
124
+ return -1;
125
+ }
126
+
127
+ return 0;
128
+ }
129
+
130
+ size_t ngtcp2_crypto_packet_protection_ivlen(const ngtcp2_crypto_aead *aead) {
131
+ size_t noncelen = ngtcp2_crypto_aead_noncelen(aead);
132
+ return ngtcp2_max(8, noncelen);
133
+ }
134
+
135
+ int ngtcp2_crypto_derive_packet_protection_key(
136
+ uint8_t *key, uint8_t *iv, uint8_t *hp_key, uint32_t version,
137
+ const ngtcp2_crypto_aead *aead, const ngtcp2_crypto_md *md,
138
+ const uint8_t *secret, size_t secretlen) {
139
+ static const uint8_t KEY_LABEL_V1[] = "quic key";
140
+ static const uint8_t IV_LABEL_V1[] = "quic iv";
141
+ static const uint8_t HP_KEY_LABEL_V1[] = "quic hp";
142
+ static const uint8_t KEY_LABEL_V2[] = "quicv2 key";
143
+ static const uint8_t IV_LABEL_V2[] = "quicv2 iv";
144
+ static const uint8_t HP_KEY_LABEL_V2[] = "quicv2 hp";
145
+ size_t keylen = ngtcp2_crypto_aead_keylen(aead);
146
+ size_t ivlen = ngtcp2_crypto_packet_protection_ivlen(aead);
147
+ const uint8_t *key_label;
148
+ size_t key_labellen;
149
+ const uint8_t *iv_label;
150
+ size_t iv_labellen;
151
+ const uint8_t *hp_key_label;
152
+ size_t hp_key_labellen;
153
+
154
+ switch (version) {
155
+ case NGTCP2_PROTO_VER_V2:
156
+ key_label = KEY_LABEL_V2;
157
+ key_labellen = sizeof(KEY_LABEL_V2) - 1;
158
+ iv_label = IV_LABEL_V2;
159
+ iv_labellen = sizeof(IV_LABEL_V2) - 1;
160
+ hp_key_label = HP_KEY_LABEL_V2;
161
+ hp_key_labellen = sizeof(HP_KEY_LABEL_V2) - 1;
162
+ break;
163
+ default:
164
+ key_label = KEY_LABEL_V1;
165
+ key_labellen = sizeof(KEY_LABEL_V1) - 1;
166
+ iv_label = IV_LABEL_V1;
167
+ iv_labellen = sizeof(IV_LABEL_V1) - 1;
168
+ hp_key_label = HP_KEY_LABEL_V1;
169
+ hp_key_labellen = sizeof(HP_KEY_LABEL_V1) - 1;
170
+ }
171
+
172
+ if (ngtcp2_crypto_hkdf_expand_label(key, keylen, md, secret, secretlen,
173
+ key_label, key_labellen) != 0) {
174
+ return -1;
175
+ }
176
+
177
+ if (ngtcp2_crypto_hkdf_expand_label(iv, ivlen, md, secret, secretlen,
178
+ iv_label, iv_labellen) != 0) {
179
+ return -1;
180
+ }
181
+
182
+ if (hp_key != NULL &&
183
+ ngtcp2_crypto_hkdf_expand_label(hp_key, keylen, md, secret, secretlen,
184
+ hp_key_label, hp_key_labellen) != 0) {
185
+ return -1;
186
+ }
187
+
188
+ return 0;
189
+ }
190
+
191
+ int ngtcp2_crypto_update_traffic_secret(uint8_t *dest, uint32_t version,
192
+ const ngtcp2_crypto_md *md,
193
+ const uint8_t *secret,
194
+ size_t secretlen) {
195
+ static const uint8_t LABEL[] = "quic ku";
196
+ static const uint8_t LABEL_V2[] = "quicv2 ku";
197
+ const uint8_t *label;
198
+ size_t labellen;
199
+
200
+ switch (version) {
201
+ case NGTCP2_PROTO_VER_V2:
202
+ label = LABEL_V2;
203
+ labellen = sizeof(LABEL_V2) - 1;
204
+ break;
205
+ default:
206
+ label = LABEL;
207
+ labellen = sizeof(LABEL) - 1;
208
+ }
209
+
210
+ if (ngtcp2_crypto_hkdf_expand_label(dest, secretlen, md, secret, secretlen,
211
+ label, labellen) != 0) {
212
+ return -1;
213
+ }
214
+
215
+ return 0;
216
+ }
217
+
218
+ int ngtcp2_crypto_derive_and_install_rx_key(ngtcp2_conn *conn, uint8_t *key,
219
+ uint8_t *iv, uint8_t *hp_key,
220
+ ngtcp2_crypto_level level,
221
+ const uint8_t *secret,
222
+ size_t secretlen) {
223
+ const ngtcp2_crypto_ctx *ctx;
224
+ const ngtcp2_crypto_aead *aead;
225
+ const ngtcp2_crypto_md *md;
226
+ const ngtcp2_crypto_cipher *hp;
227
+ ngtcp2_crypto_aead_ctx aead_ctx = {0};
228
+ ngtcp2_crypto_cipher_ctx hp_ctx = {0};
229
+ void *tls = ngtcp2_conn_get_tls_native_handle(conn);
230
+ uint8_t keybuf[64], ivbuf[64], hp_keybuf[64];
231
+ size_t ivlen;
232
+ int rv;
233
+ ngtcp2_crypto_ctx cctx;
234
+ uint32_t version;
235
+
236
+ if (level == NGTCP2_CRYPTO_LEVEL_EARLY && !ngtcp2_conn_is_server(conn)) {
237
+ return 0;
238
+ }
239
+
240
+ if (!key) {
241
+ key = keybuf;
242
+ }
243
+ if (!iv) {
244
+ iv = ivbuf;
245
+ }
246
+ if (!hp_key) {
247
+ hp_key = hp_keybuf;
248
+ }
249
+
250
+ switch (level) {
251
+ case NGTCP2_CRYPTO_LEVEL_EARLY:
252
+ ngtcp2_crypto_ctx_tls_early(&cctx, tls);
253
+ ngtcp2_conn_set_early_crypto_ctx(conn, &cctx);
254
+ ctx = ngtcp2_conn_get_early_crypto_ctx(conn);
255
+ version = ngtcp2_conn_get_client_chosen_version(conn);
256
+ break;
257
+ case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
258
+ if (ngtcp2_conn_is_server(conn) &&
259
+ !ngtcp2_conn_get_negotiated_version(conn)) {
260
+ rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
261
+ if (rv != 0) {
262
+ return -1;
263
+ }
264
+ }
265
+ /* fall through */
266
+ default:
267
+ ctx = ngtcp2_conn_get_crypto_ctx(conn);
268
+ version = ngtcp2_conn_get_negotiated_version(conn);
269
+
270
+ if (!ctx->aead.native_handle) {
271
+ ngtcp2_crypto_ctx_tls(&cctx, tls);
272
+ ngtcp2_conn_set_crypto_ctx(conn, &cctx);
273
+ ctx = ngtcp2_conn_get_crypto_ctx(conn);
274
+ }
275
+ }
276
+
277
+ aead = &ctx->aead;
278
+ md = &ctx->md;
279
+ hp = &ctx->hp;
280
+ ivlen = ngtcp2_crypto_packet_protection_ivlen(aead);
281
+
282
+ if (ngtcp2_crypto_derive_packet_protection_key(key, iv, hp_key, version, aead,
283
+ md, secret, secretlen) != 0) {
284
+ return -1;
285
+ }
286
+
287
+ if (ngtcp2_crypto_aead_ctx_decrypt_init(&aead_ctx, aead, key, ivlen) != 0) {
288
+ goto fail;
289
+ }
290
+
291
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&hp_ctx, hp, hp_key) != 0) {
292
+ goto fail;
293
+ }
294
+
295
+ switch (level) {
296
+ case NGTCP2_CRYPTO_LEVEL_EARLY:
297
+ rv = ngtcp2_conn_install_early_key(conn, &aead_ctx, iv, ivlen, &hp_ctx);
298
+ if (rv != 0) {
299
+ goto fail;
300
+ }
301
+ break;
302
+ case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
303
+ rv = ngtcp2_conn_install_rx_handshake_key(conn, &aead_ctx, iv, ivlen,
304
+ &hp_ctx);
305
+ if (rv != 0) {
306
+ goto fail;
307
+ }
308
+ break;
309
+ case NGTCP2_CRYPTO_LEVEL_APPLICATION:
310
+ if (!ngtcp2_conn_is_server(conn)) {
311
+ rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
312
+ if (rv != 0) {
313
+ goto fail;
314
+ }
315
+ }
316
+
317
+ rv = ngtcp2_conn_install_rx_key(conn, secret, secretlen, &aead_ctx, iv,
318
+ ivlen, &hp_ctx);
319
+ if (rv != 0) {
320
+ goto fail;
321
+ }
322
+
323
+ break;
324
+ default:
325
+ goto fail;
326
+ }
327
+
328
+ return 0;
329
+
330
+ fail:
331
+ ngtcp2_crypto_cipher_ctx_free(&hp_ctx);
332
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
333
+
334
+ return -1;
335
+ }
336
+
337
+ /*
338
+ * crypto_set_local_transport_params gets local QUIC transport
339
+ * parameters from |conn| and sets it to |tls|.
340
+ *
341
+ * This function returns 0 if it succeeds, or -1.
342
+ */
343
+ static int crypto_set_local_transport_params(ngtcp2_conn *conn, void *tls) {
344
+ ngtcp2_ssize nwrite;
345
+ uint8_t buf[256];
346
+
347
+ nwrite = ngtcp2_conn_encode_local_transport_params(conn, buf, sizeof(buf));
348
+ if (nwrite < 0) {
349
+ return -1;
350
+ }
351
+
352
+ if (ngtcp2_crypto_set_local_transport_params(tls, buf, (size_t)nwrite) != 0) {
353
+ return -1;
354
+ }
355
+
356
+ return 0;
357
+ }
358
+
359
+ int ngtcp2_crypto_derive_and_install_tx_key(ngtcp2_conn *conn, uint8_t *key,
360
+ uint8_t *iv, uint8_t *hp_key,
361
+ ngtcp2_crypto_level level,
362
+ const uint8_t *secret,
363
+ size_t secretlen) {
364
+ const ngtcp2_crypto_ctx *ctx;
365
+ const ngtcp2_crypto_aead *aead;
366
+ const ngtcp2_crypto_md *md;
367
+ const ngtcp2_crypto_cipher *hp;
368
+ ngtcp2_crypto_aead_ctx aead_ctx = {0};
369
+ ngtcp2_crypto_cipher_ctx hp_ctx = {0};
370
+ void *tls = ngtcp2_conn_get_tls_native_handle(conn);
371
+ uint8_t keybuf[64], ivbuf[64], hp_keybuf[64];
372
+ size_t ivlen;
373
+ int rv;
374
+ ngtcp2_crypto_ctx cctx;
375
+ uint32_t version;
376
+
377
+ if (level == NGTCP2_CRYPTO_LEVEL_EARLY && ngtcp2_conn_is_server(conn)) {
378
+ return 0;
379
+ }
380
+
381
+ if (!key) {
382
+ key = keybuf;
383
+ }
384
+ if (!iv) {
385
+ iv = ivbuf;
386
+ }
387
+ if (!hp_key) {
388
+ hp_key = hp_keybuf;
389
+ }
390
+
391
+ switch (level) {
392
+ case NGTCP2_CRYPTO_LEVEL_EARLY:
393
+ ngtcp2_crypto_ctx_tls_early(&cctx, tls);
394
+ ngtcp2_conn_set_early_crypto_ctx(conn, &cctx);
395
+ ctx = ngtcp2_conn_get_early_crypto_ctx(conn);
396
+ version = ngtcp2_conn_get_client_chosen_version(conn);
397
+ break;
398
+ case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
399
+ if (ngtcp2_conn_is_server(conn) &&
400
+ !ngtcp2_conn_get_negotiated_version(conn)) {
401
+ rv = ngtcp2_crypto_set_remote_transport_params(conn, tls);
402
+ if (rv != 0) {
403
+ return -1;
404
+ }
405
+ }
406
+ /* fall through */
407
+ default:
408
+ ctx = ngtcp2_conn_get_crypto_ctx(conn);
409
+ version = ngtcp2_conn_get_negotiated_version(conn);
410
+
411
+ if (!ctx->aead.native_handle) {
412
+ ngtcp2_crypto_ctx_tls(&cctx, tls);
413
+ ngtcp2_conn_set_crypto_ctx(conn, &cctx);
414
+ ctx = ngtcp2_conn_get_crypto_ctx(conn);
415
+ }
416
+ }
417
+
418
+ aead = &ctx->aead;
419
+ md = &ctx->md;
420
+ hp = &ctx->hp;
421
+ ivlen = ngtcp2_crypto_packet_protection_ivlen(aead);
422
+
423
+ if (ngtcp2_crypto_derive_packet_protection_key(key, iv, hp_key, version, aead,
424
+ md, secret, secretlen) != 0) {
425
+ return -1;
426
+ }
427
+
428
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, aead, key, ivlen) != 0) {
429
+ goto fail;
430
+ }
431
+
432
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&hp_ctx, hp, hp_key) != 0) {
433
+ goto fail;
434
+ }
435
+
436
+ switch (level) {
437
+ case NGTCP2_CRYPTO_LEVEL_EARLY:
438
+ rv = ngtcp2_conn_install_early_key(conn, &aead_ctx, iv, ivlen, &hp_ctx);
439
+ if (rv != 0) {
440
+ goto fail;
441
+ }
442
+ break;
443
+ case NGTCP2_CRYPTO_LEVEL_HANDSHAKE:
444
+ rv = ngtcp2_conn_install_tx_handshake_key(conn, &aead_ctx, iv, ivlen,
445
+ &hp_ctx);
446
+ if (rv != 0) {
447
+ goto fail;
448
+ }
449
+
450
+ if (ngtcp2_conn_is_server(conn) &&
451
+ crypto_set_local_transport_params(conn, tls) != 0) {
452
+ goto fail;
453
+ }
454
+
455
+ break;
456
+ case NGTCP2_CRYPTO_LEVEL_APPLICATION:
457
+ rv = ngtcp2_conn_install_tx_key(conn, secret, secretlen, &aead_ctx, iv,
458
+ ivlen, &hp_ctx);
459
+ if (rv != 0) {
460
+ goto fail;
461
+ }
462
+
463
+ break;
464
+ default:
465
+ goto fail;
466
+ }
467
+
468
+ return 0;
469
+
470
+ fail:
471
+ ngtcp2_crypto_cipher_ctx_free(&hp_ctx);
472
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
473
+
474
+ return -1;
475
+ }
476
+
477
+ int ngtcp2_crypto_derive_and_install_initial_key(
478
+ ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret,
479
+ uint8_t *initial_secret, uint8_t *rx_key, uint8_t *rx_iv,
480
+ uint8_t *rx_hp_key, uint8_t *tx_key, uint8_t *tx_iv, uint8_t *tx_hp_key,
481
+ uint32_t version, const ngtcp2_cid *client_dcid) {
482
+ uint8_t rx_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
483
+ uint8_t tx_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
484
+ uint8_t initial_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
485
+ uint8_t rx_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
486
+ uint8_t rx_ivbuf[NGTCP2_CRYPTO_INITIAL_IVLEN];
487
+ uint8_t rx_hp_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
488
+ uint8_t tx_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
489
+ uint8_t tx_ivbuf[NGTCP2_CRYPTO_INITIAL_IVLEN];
490
+ uint8_t tx_hp_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
491
+ ngtcp2_crypto_ctx ctx;
492
+ ngtcp2_crypto_aead retry_aead;
493
+ ngtcp2_crypto_aead_ctx rx_aead_ctx = {0};
494
+ ngtcp2_crypto_cipher_ctx rx_hp_ctx = {0};
495
+ ngtcp2_crypto_aead_ctx tx_aead_ctx = {0};
496
+ ngtcp2_crypto_cipher_ctx tx_hp_ctx = {0};
497
+ ngtcp2_crypto_aead_ctx retry_aead_ctx = {0};
498
+ int rv;
499
+ int server = ngtcp2_conn_is_server(conn);
500
+ const uint8_t *retry_key;
501
+ size_t retry_noncelen;
502
+
503
+ ngtcp2_crypto_ctx_initial(&ctx);
504
+
505
+ if (!rx_secret) {
506
+ rx_secret = rx_secretbuf;
507
+ }
508
+ if (!tx_secret) {
509
+ tx_secret = tx_secretbuf;
510
+ }
511
+ if (!initial_secret) {
512
+ initial_secret = initial_secretbuf;
513
+ }
514
+
515
+ if (!rx_key) {
516
+ rx_key = rx_keybuf;
517
+ }
518
+ if (!rx_iv) {
519
+ rx_iv = rx_ivbuf;
520
+ }
521
+ if (!rx_hp_key) {
522
+ rx_hp_key = rx_hp_keybuf;
523
+ }
524
+ if (!tx_key) {
525
+ tx_key = tx_keybuf;
526
+ }
527
+ if (!tx_iv) {
528
+ tx_iv = tx_ivbuf;
529
+ }
530
+ if (!tx_hp_key) {
531
+ tx_hp_key = tx_hp_keybuf;
532
+ }
533
+
534
+ ngtcp2_conn_set_initial_crypto_ctx(conn, &ctx);
535
+
536
+ if (ngtcp2_crypto_derive_initial_secrets(
537
+ rx_secret, tx_secret, initial_secret, version, client_dcid,
538
+ server ? NGTCP2_CRYPTO_SIDE_SERVER : NGTCP2_CRYPTO_SIDE_CLIENT) !=
539
+ 0) {
540
+ return -1;
541
+ }
542
+
543
+ if (ngtcp2_crypto_derive_packet_protection_key(
544
+ rx_key, rx_iv, rx_hp_key, version, &ctx.aead, &ctx.md, rx_secret,
545
+ NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) {
546
+ return -1;
547
+ }
548
+
549
+ if (ngtcp2_crypto_derive_packet_protection_key(
550
+ tx_key, tx_iv, tx_hp_key, version, &ctx.aead, &ctx.md, tx_secret,
551
+ NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) {
552
+ return -1;
553
+ }
554
+
555
+ if (ngtcp2_crypto_aead_ctx_decrypt_init(&rx_aead_ctx, &ctx.aead, rx_key,
556
+ NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) {
557
+ goto fail;
558
+ }
559
+
560
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&rx_hp_ctx, &ctx.hp, rx_hp_key) !=
561
+ 0) {
562
+ goto fail;
563
+ }
564
+
565
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&tx_aead_ctx, &ctx.aead, tx_key,
566
+ NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) {
567
+ goto fail;
568
+ }
569
+
570
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&tx_hp_ctx, &ctx.hp, tx_hp_key) !=
571
+ 0) {
572
+ goto fail;
573
+ }
574
+
575
+ if (!server && !ngtcp2_conn_after_retry(conn)) {
576
+ ngtcp2_crypto_aead_retry(&retry_aead);
577
+
578
+ switch (version) {
579
+ case NGTCP2_PROTO_VER_V1:
580
+ retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_V1;
581
+ retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_V1) - 1;
582
+ break;
583
+ case NGTCP2_PROTO_VER_V2:
584
+ retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_V2;
585
+ retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_V2) - 1;
586
+ break;
587
+ default:
588
+ retry_key = (const uint8_t *)NGTCP2_RETRY_KEY_DRAFT;
589
+ retry_noncelen = sizeof(NGTCP2_RETRY_NONCE_DRAFT) - 1;
590
+ }
591
+
592
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&retry_aead_ctx, &retry_aead,
593
+ retry_key, retry_noncelen) != 0) {
594
+ goto fail;
595
+ }
596
+ }
597
+
598
+ rv = ngtcp2_conn_install_initial_key(conn, &rx_aead_ctx, rx_iv, &rx_hp_ctx,
599
+ &tx_aead_ctx, tx_iv, &tx_hp_ctx,
600
+ NGTCP2_CRYPTO_INITIAL_IVLEN);
601
+ if (rv != 0) {
602
+ goto fail;
603
+ }
604
+
605
+ if (retry_aead_ctx.native_handle) {
606
+ ngtcp2_conn_set_retry_aead(conn, &retry_aead, &retry_aead_ctx);
607
+ }
608
+
609
+ return 0;
610
+
611
+ fail:
612
+ ngtcp2_crypto_aead_ctx_free(&retry_aead_ctx);
613
+ ngtcp2_crypto_cipher_ctx_free(&tx_hp_ctx);
614
+ ngtcp2_crypto_aead_ctx_free(&tx_aead_ctx);
615
+ ngtcp2_crypto_cipher_ctx_free(&rx_hp_ctx);
616
+ ngtcp2_crypto_aead_ctx_free(&rx_aead_ctx);
617
+
618
+ return -1;
619
+ }
620
+
621
+ int ngtcp2_crypto_derive_and_install_vneg_initial_key(
622
+ ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret,
623
+ uint8_t *initial_secret, uint8_t *rx_key, uint8_t *rx_iv,
624
+ uint8_t *rx_hp_key, uint8_t *tx_key, uint8_t *tx_iv, uint8_t *tx_hp_key,
625
+ uint32_t version, const ngtcp2_cid *client_dcid) {
626
+ uint8_t rx_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
627
+ uint8_t tx_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
628
+ uint8_t initial_secretbuf[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
629
+ uint8_t rx_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
630
+ uint8_t rx_ivbuf[NGTCP2_CRYPTO_INITIAL_IVLEN];
631
+ uint8_t rx_hp_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
632
+ uint8_t tx_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
633
+ uint8_t tx_ivbuf[NGTCP2_CRYPTO_INITIAL_IVLEN];
634
+ uint8_t tx_hp_keybuf[NGTCP2_CRYPTO_INITIAL_KEYLEN];
635
+ const ngtcp2_crypto_ctx *ctx = ngtcp2_conn_get_initial_crypto_ctx(conn);
636
+ ngtcp2_crypto_aead_ctx rx_aead_ctx = {0};
637
+ ngtcp2_crypto_cipher_ctx rx_hp_ctx = {0};
638
+ ngtcp2_crypto_aead_ctx tx_aead_ctx = {0};
639
+ ngtcp2_crypto_cipher_ctx tx_hp_ctx = {0};
640
+ int rv;
641
+ int server = ngtcp2_conn_is_server(conn);
642
+
643
+ if (!rx_secret) {
644
+ rx_secret = rx_secretbuf;
645
+ }
646
+ if (!tx_secret) {
647
+ tx_secret = tx_secretbuf;
648
+ }
649
+ if (!initial_secret) {
650
+ initial_secret = initial_secretbuf;
651
+ }
652
+
653
+ if (!rx_key) {
654
+ rx_key = rx_keybuf;
655
+ }
656
+ if (!rx_iv) {
657
+ rx_iv = rx_ivbuf;
658
+ }
659
+ if (!rx_hp_key) {
660
+ rx_hp_key = rx_hp_keybuf;
661
+ }
662
+ if (!tx_key) {
663
+ tx_key = tx_keybuf;
664
+ }
665
+ if (!tx_iv) {
666
+ tx_iv = tx_ivbuf;
667
+ }
668
+ if (!tx_hp_key) {
669
+ tx_hp_key = tx_hp_keybuf;
670
+ }
671
+
672
+ if (ngtcp2_crypto_derive_initial_secrets(
673
+ rx_secret, tx_secret, initial_secret, version, client_dcid,
674
+ server ? NGTCP2_CRYPTO_SIDE_SERVER : NGTCP2_CRYPTO_SIDE_CLIENT) !=
675
+ 0) {
676
+ return -1;
677
+ }
678
+
679
+ if (ngtcp2_crypto_derive_packet_protection_key(
680
+ rx_key, rx_iv, rx_hp_key, version, &ctx->aead, &ctx->md, rx_secret,
681
+ NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) {
682
+ return -1;
683
+ }
684
+
685
+ if (ngtcp2_crypto_derive_packet_protection_key(
686
+ tx_key, tx_iv, tx_hp_key, version, &ctx->aead, &ctx->md, tx_secret,
687
+ NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) {
688
+ return -1;
689
+ }
690
+
691
+ if (ngtcp2_crypto_aead_ctx_decrypt_init(&rx_aead_ctx, &ctx->aead, rx_key,
692
+ NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) {
693
+ goto fail;
694
+ }
695
+
696
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&rx_hp_ctx, &ctx->hp, rx_hp_key) !=
697
+ 0) {
698
+ goto fail;
699
+ }
700
+
701
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&tx_aead_ctx, &ctx->aead, tx_key,
702
+ NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) {
703
+ goto fail;
704
+ }
705
+
706
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&tx_hp_ctx, &ctx->hp, tx_hp_key) !=
707
+ 0) {
708
+ goto fail;
709
+ }
710
+
711
+ rv = ngtcp2_conn_install_vneg_initial_key(
712
+ conn, version, &rx_aead_ctx, rx_iv, &rx_hp_ctx, &tx_aead_ctx, tx_iv,
713
+ &tx_hp_ctx, NGTCP2_CRYPTO_INITIAL_IVLEN);
714
+ if (rv != 0) {
715
+ goto fail;
716
+ }
717
+
718
+ return 0;
719
+
720
+ fail:
721
+ ngtcp2_crypto_cipher_ctx_free(&tx_hp_ctx);
722
+ ngtcp2_crypto_aead_ctx_free(&tx_aead_ctx);
723
+ ngtcp2_crypto_cipher_ctx_free(&rx_hp_ctx);
724
+ ngtcp2_crypto_aead_ctx_free(&rx_aead_ctx);
725
+
726
+ return -1;
727
+ }
728
+
729
+ int ngtcp2_crypto_update_key(
730
+ ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret,
731
+ ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_key, uint8_t *rx_iv,
732
+ ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_key, uint8_t *tx_iv,
733
+ const uint8_t *current_rx_secret, const uint8_t *current_tx_secret,
734
+ size_t secretlen) {
735
+ const ngtcp2_crypto_ctx *ctx = ngtcp2_conn_get_crypto_ctx(conn);
736
+ const ngtcp2_crypto_aead *aead = &ctx->aead;
737
+ const ngtcp2_crypto_md *md = &ctx->md;
738
+ size_t ivlen = ngtcp2_crypto_packet_protection_ivlen(aead);
739
+ uint32_t version = ngtcp2_conn_get_negotiated_version(conn);
740
+
741
+ if (ngtcp2_crypto_update_traffic_secret(rx_secret, version, md,
742
+ current_rx_secret, secretlen) != 0) {
743
+ return -1;
744
+ }
745
+
746
+ if (ngtcp2_crypto_derive_packet_protection_key(
747
+ rx_key, rx_iv, NULL, version, aead, md, rx_secret, secretlen) != 0) {
748
+ return -1;
749
+ }
750
+
751
+ if (ngtcp2_crypto_update_traffic_secret(tx_secret, version, md,
752
+ current_tx_secret, secretlen) != 0) {
753
+ return -1;
754
+ }
755
+
756
+ if (ngtcp2_crypto_derive_packet_protection_key(
757
+ tx_key, tx_iv, NULL, version, aead, md, tx_secret, secretlen) != 0) {
758
+ return -1;
759
+ }
760
+
761
+ if (ngtcp2_crypto_aead_ctx_decrypt_init(rx_aead_ctx, aead, rx_key, ivlen) !=
762
+ 0) {
763
+ return -1;
764
+ }
765
+
766
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(tx_aead_ctx, aead, tx_key, ivlen) !=
767
+ 0) {
768
+ ngtcp2_crypto_aead_ctx_free(rx_aead_ctx);
769
+ rx_aead_ctx->native_handle = NULL;
770
+ return -1;
771
+ }
772
+
773
+ return 0;
774
+ }
775
+
776
+ int ngtcp2_crypto_encrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
777
+ const ngtcp2_crypto_aead_ctx *aead_ctx,
778
+ const uint8_t *plaintext, size_t plaintextlen,
779
+ const uint8_t *nonce, size_t noncelen,
780
+ const uint8_t *aad, size_t aadlen) {
781
+ if (ngtcp2_crypto_encrypt(dest, aead, aead_ctx, plaintext, plaintextlen,
782
+ nonce, noncelen, aad, aadlen) != 0) {
783
+ return NGTCP2_ERR_CALLBACK_FAILURE;
784
+ }
785
+ return 0;
786
+ }
787
+
788
+ int ngtcp2_crypto_decrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
789
+ const ngtcp2_crypto_aead_ctx *aead_ctx,
790
+ const uint8_t *ciphertext, size_t ciphertextlen,
791
+ const uint8_t *nonce, size_t noncelen,
792
+ const uint8_t *aad, size_t aadlen) {
793
+ if (ngtcp2_crypto_decrypt(dest, aead, aead_ctx, ciphertext, ciphertextlen,
794
+ nonce, noncelen, aad, aadlen) != 0) {
795
+ return NGTCP2_ERR_DECRYPT;
796
+ }
797
+ return 0;
798
+ }
799
+
800
+ int ngtcp2_crypto_hp_mask_cb(uint8_t *dest, const ngtcp2_crypto_cipher *hp,
801
+ const ngtcp2_crypto_cipher_ctx *hp_ctx,
802
+ const uint8_t *sample) {
803
+ if (ngtcp2_crypto_hp_mask(dest, hp, hp_ctx, sample) != 0) {
804
+ return NGTCP2_ERR_CALLBACK_FAILURE;
805
+ }
806
+ return 0;
807
+ }
808
+
809
+ int ngtcp2_crypto_update_key_cb(
810
+ ngtcp2_conn *conn, uint8_t *rx_secret, uint8_t *tx_secret,
811
+ ngtcp2_crypto_aead_ctx *rx_aead_ctx, uint8_t *rx_iv,
812
+ ngtcp2_crypto_aead_ctx *tx_aead_ctx, uint8_t *tx_iv,
813
+ const uint8_t *current_rx_secret, const uint8_t *current_tx_secret,
814
+ size_t secretlen, void *user_data) {
815
+ uint8_t rx_key[64];
816
+ uint8_t tx_key[64];
817
+ (void)conn;
818
+ (void)user_data;
819
+
820
+ if (ngtcp2_crypto_update_key(conn, rx_secret, tx_secret, rx_aead_ctx, rx_key,
821
+ rx_iv, tx_aead_ctx, tx_key, tx_iv,
822
+ current_rx_secret, current_tx_secret,
823
+ secretlen) != 0) {
824
+ return NGTCP2_ERR_CALLBACK_FAILURE;
825
+ }
826
+ return 0;
827
+ }
828
+
829
+ int ngtcp2_crypto_generate_stateless_reset_token(uint8_t *token,
830
+ const uint8_t *secret,
831
+ size_t secretlen,
832
+ const ngtcp2_cid *cid) {
833
+ static const uint8_t info[] = "stateless_reset";
834
+ ngtcp2_crypto_md md;
835
+
836
+ if (ngtcp2_crypto_hkdf(token, NGTCP2_STATELESS_RESET_TOKENLEN,
837
+ ngtcp2_crypto_md_sha256(&md), secret, secretlen,
838
+ cid->data, cid->datalen, info,
839
+ sizeof(info) - 1) != 0) {
840
+ return -1;
841
+ }
842
+
843
+ return 0;
844
+ }
845
+
846
+ static int crypto_derive_token_key(uint8_t *key, size_t keylen, uint8_t *iv,
847
+ size_t ivlen, const ngtcp2_crypto_md *md,
848
+ const uint8_t *secret, size_t secretlen,
849
+ const uint8_t *salt, size_t saltlen,
850
+ const uint8_t *info_prefix,
851
+ size_t info_prefixlen) {
852
+ static const uint8_t key_info_suffix[] = " key";
853
+ static const uint8_t iv_info_suffix[] = " iv";
854
+ uint8_t intsecret[32];
855
+ uint8_t info[32];
856
+ uint8_t *p;
857
+
858
+ assert(ngtcp2_crypto_md_hashlen(md) == sizeof(intsecret));
859
+ assert(info_prefixlen + sizeof(key_info_suffix) - 1 <= sizeof(info));
860
+ assert(info_prefixlen + sizeof(iv_info_suffix) - 1 <= sizeof(info));
861
+
862
+ if (ngtcp2_crypto_hkdf_extract(intsecret, md, secret, secretlen, salt,
863
+ saltlen) != 0) {
864
+ return -1;
865
+ }
866
+
867
+ memcpy(info, info_prefix, info_prefixlen);
868
+ p = info + info_prefixlen;
869
+
870
+ memcpy(p, key_info_suffix, sizeof(key_info_suffix) - 1);
871
+ p += sizeof(key_info_suffix) - 1;
872
+
873
+ if (ngtcp2_crypto_hkdf_expand(key, keylen, md, intsecret, sizeof(intsecret),
874
+ info, (size_t)(p - info)) != 0) {
875
+ return -1;
876
+ }
877
+
878
+ p = info + info_prefixlen;
879
+
880
+ memcpy(p, iv_info_suffix, sizeof(iv_info_suffix) - 1);
881
+ p += sizeof(iv_info_suffix) - 1;
882
+
883
+ if (ngtcp2_crypto_hkdf_expand(iv, ivlen, md, intsecret, sizeof(intsecret),
884
+ info, (size_t)(p - info)) != 0) {
885
+ return -1;
886
+ }
887
+
888
+ return 0;
889
+ }
890
+
891
+ static size_t crypto_generate_retry_token_aad(uint8_t *dest, uint32_t version,
892
+ const ngtcp2_sockaddr *sa,
893
+ ngtcp2_socklen salen,
894
+ const ngtcp2_cid *retry_scid) {
895
+ uint8_t *p = dest;
896
+
897
+ version = ngtcp2_htonl(version);
898
+ memcpy(p, &version, sizeof(version));
899
+ memcpy(p, sa, (size_t)salen);
900
+ p += salen;
901
+ memcpy(p, retry_scid->data, retry_scid->datalen);
902
+ p += retry_scid->datalen;
903
+
904
+ return (size_t)(p - dest);
905
+ }
906
+
907
+ static const uint8_t retry_token_info_prefix[] = "retry_token";
908
+
909
+ ngtcp2_ssize ngtcp2_crypto_generate_retry_token(
910
+ uint8_t *token, const uint8_t *secret, size_t secretlen, uint32_t version,
911
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
912
+ const ngtcp2_cid *retry_scid, const ngtcp2_cid *odcid, ngtcp2_tstamp ts) {
913
+ uint8_t plaintext[NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN];
914
+ uint8_t rand_data[NGTCP2_CRYPTO_TOKEN_RAND_DATALEN];
915
+ uint8_t key[32];
916
+ uint8_t iv[32];
917
+ size_t keylen;
918
+ size_t ivlen;
919
+ ngtcp2_crypto_aead aead;
920
+ ngtcp2_crypto_md md;
921
+ ngtcp2_crypto_aead_ctx aead_ctx;
922
+ size_t plaintextlen;
923
+ uint8_t aad[sizeof(version) + sizeof(ngtcp2_sockaddr_storage) +
924
+ NGTCP2_MAX_CIDLEN];
925
+ size_t aadlen;
926
+ uint8_t *p = plaintext;
927
+ ngtcp2_tstamp ts_be = ngtcp2_htonl64(ts);
928
+ int rv;
929
+
930
+ memset(plaintext, 0, sizeof(plaintext));
931
+
932
+ *p++ = (uint8_t)odcid->datalen;
933
+ memcpy(p, odcid->data, odcid->datalen);
934
+ p += NGTCP2_MAX_CIDLEN;
935
+ memcpy(p, &ts_be, sizeof(ts_be));
936
+ p += sizeof(ts_be);
937
+
938
+ plaintextlen = (size_t)(p - plaintext);
939
+
940
+ if (ngtcp2_crypto_random(rand_data, sizeof(rand_data)) != 0) {
941
+ return -1;
942
+ }
943
+
944
+ ngtcp2_crypto_aead_aes_128_gcm(&aead);
945
+ ngtcp2_crypto_md_sha256(&md);
946
+
947
+ keylen = ngtcp2_crypto_aead_keylen(&aead);
948
+ ivlen = ngtcp2_crypto_aead_noncelen(&aead);
949
+
950
+ assert(sizeof(key) >= keylen);
951
+ assert(sizeof(iv) >= ivlen);
952
+
953
+ if (crypto_derive_token_key(key, keylen, iv, ivlen, &md, secret, secretlen,
954
+ rand_data, sizeof(rand_data),
955
+ retry_token_info_prefix,
956
+ sizeof(retry_token_info_prefix) - 1) != 0) {
957
+ return -1;
958
+ }
959
+
960
+ aadlen = crypto_generate_retry_token_aad(aad, version, remote_addr,
961
+ remote_addrlen, retry_scid);
962
+
963
+ p = token;
964
+ *p++ = NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY;
965
+
966
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &aead, key, ivlen) != 0) {
967
+ return -1;
968
+ }
969
+
970
+ rv = ngtcp2_crypto_encrypt(p, &aead, &aead_ctx, plaintext, plaintextlen, iv,
971
+ ivlen, aad, aadlen);
972
+
973
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
974
+
975
+ if (rv != 0) {
976
+ return -1;
977
+ }
978
+
979
+ p += plaintextlen + aead.max_overhead;
980
+ memcpy(p, rand_data, sizeof(rand_data));
981
+ p += sizeof(rand_data);
982
+
983
+ return p - token;
984
+ }
985
+
986
+ int ngtcp2_crypto_verify_retry_token(
987
+ ngtcp2_cid *odcid, const uint8_t *token, size_t tokenlen,
988
+ const uint8_t *secret, size_t secretlen, uint32_t version,
989
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
990
+ const ngtcp2_cid *dcid, ngtcp2_duration timeout, ngtcp2_tstamp ts) {
991
+ uint8_t
992
+ plaintext[/* cid len = */ 1 + NGTCP2_MAX_CIDLEN + sizeof(ngtcp2_tstamp)];
993
+ uint8_t key[32];
994
+ uint8_t iv[32];
995
+ size_t keylen;
996
+ size_t ivlen;
997
+ ngtcp2_crypto_aead_ctx aead_ctx;
998
+ ngtcp2_crypto_aead aead;
999
+ ngtcp2_crypto_md md;
1000
+ uint8_t aad[sizeof(version) + sizeof(ngtcp2_sockaddr_storage) +
1001
+ NGTCP2_MAX_CIDLEN];
1002
+ size_t aadlen;
1003
+ const uint8_t *rand_data;
1004
+ const uint8_t *ciphertext;
1005
+ size_t ciphertextlen;
1006
+ size_t cil;
1007
+ int rv;
1008
+ ngtcp2_tstamp gen_ts;
1009
+
1010
+ if (tokenlen != NGTCP2_CRYPTO_MAX_RETRY_TOKENLEN ||
1011
+ token[0] != NGTCP2_CRYPTO_TOKEN_MAGIC_RETRY) {
1012
+ return -1;
1013
+ }
1014
+
1015
+ rand_data = token + tokenlen - NGTCP2_CRYPTO_TOKEN_RAND_DATALEN;
1016
+ ciphertext = token + 1;
1017
+ ciphertextlen = tokenlen - 1 - NGTCP2_CRYPTO_TOKEN_RAND_DATALEN;
1018
+
1019
+ ngtcp2_crypto_aead_aes_128_gcm(&aead);
1020
+ ngtcp2_crypto_md_sha256(&md);
1021
+
1022
+ keylen = ngtcp2_crypto_aead_keylen(&aead);
1023
+ ivlen = ngtcp2_crypto_aead_noncelen(&aead);
1024
+
1025
+ if (crypto_derive_token_key(key, keylen, iv, ivlen, &md, secret, secretlen,
1026
+ rand_data, NGTCP2_CRYPTO_TOKEN_RAND_DATALEN,
1027
+ retry_token_info_prefix,
1028
+ sizeof(retry_token_info_prefix) - 1) != 0) {
1029
+ return -1;
1030
+ }
1031
+
1032
+ aadlen = crypto_generate_retry_token_aad(aad, version, remote_addr,
1033
+ remote_addrlen, dcid);
1034
+
1035
+ if (ngtcp2_crypto_aead_ctx_decrypt_init(&aead_ctx, &aead, key, ivlen) != 0) {
1036
+ return -1;
1037
+ }
1038
+
1039
+ rv = ngtcp2_crypto_decrypt(plaintext, &aead, &aead_ctx, ciphertext,
1040
+ ciphertextlen, iv, ivlen, aad, aadlen);
1041
+
1042
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
1043
+
1044
+ if (rv != 0) {
1045
+ return -1;
1046
+ }
1047
+
1048
+ cil = plaintext[0];
1049
+
1050
+ assert(cil == 0 || (cil >= NGTCP2_MIN_CIDLEN && cil <= NGTCP2_MAX_CIDLEN));
1051
+
1052
+ memcpy(&gen_ts, plaintext + /* cid len = */ 1 + NGTCP2_MAX_CIDLEN,
1053
+ sizeof(gen_ts));
1054
+
1055
+ gen_ts = ngtcp2_ntohl64(gen_ts);
1056
+ if (gen_ts + timeout <= ts) {
1057
+ return -1;
1058
+ }
1059
+
1060
+ ngtcp2_cid_init(odcid, plaintext + /* cid len = */ 1, cil);
1061
+
1062
+ return 0;
1063
+ }
1064
+
1065
+ static size_t crypto_generate_regular_token_aad(uint8_t *dest,
1066
+ const ngtcp2_sockaddr *sa) {
1067
+ const uint8_t *addr;
1068
+ size_t addrlen;
1069
+
1070
+ switch (sa->sa_family) {
1071
+ case AF_INET:
1072
+ addr = (const uint8_t *)&((const ngtcp2_sockaddr_in *)(void *)sa)->sin_addr;
1073
+ addrlen = sizeof(((const ngtcp2_sockaddr_in *)(void *)sa)->sin_addr);
1074
+ break;
1075
+ case AF_INET6:
1076
+ addr =
1077
+ (const uint8_t *)&((const ngtcp2_sockaddr_in6 *)(void *)sa)->sin6_addr;
1078
+ addrlen = sizeof(((const ngtcp2_sockaddr_in6 *)(void *)sa)->sin6_addr);
1079
+ break;
1080
+ default:
1081
+ assert(0);
1082
+ abort();
1083
+ }
1084
+
1085
+ memcpy(dest, addr, addrlen);
1086
+
1087
+ return addrlen;
1088
+ }
1089
+
1090
+ static const uint8_t regular_token_info_prefix[] = "regular_token";
1091
+
1092
+ ngtcp2_ssize ngtcp2_crypto_generate_regular_token(
1093
+ uint8_t *token, const uint8_t *secret, size_t secretlen,
1094
+ const ngtcp2_sockaddr *remote_addr, ngtcp2_socklen remote_addrlen,
1095
+ ngtcp2_tstamp ts) {
1096
+ uint8_t plaintext[sizeof(ngtcp2_tstamp)];
1097
+ uint8_t rand_data[NGTCP2_CRYPTO_TOKEN_RAND_DATALEN];
1098
+ uint8_t key[32];
1099
+ uint8_t iv[32];
1100
+ size_t keylen;
1101
+ size_t ivlen;
1102
+ ngtcp2_crypto_aead aead;
1103
+ ngtcp2_crypto_md md;
1104
+ ngtcp2_crypto_aead_ctx aead_ctx;
1105
+ size_t plaintextlen;
1106
+ uint8_t aad[sizeof(ngtcp2_sockaddr_in6)];
1107
+ size_t aadlen;
1108
+ uint8_t *p = plaintext;
1109
+ ngtcp2_tstamp ts_be = ngtcp2_htonl64(ts);
1110
+ int rv;
1111
+ (void)remote_addrlen;
1112
+
1113
+ memcpy(p, &ts_be, sizeof(ts_be));
1114
+ p += sizeof(ts_be);
1115
+
1116
+ plaintextlen = (size_t)(p - plaintext);
1117
+
1118
+ if (ngtcp2_crypto_random(rand_data, sizeof(rand_data)) != 0) {
1119
+ return -1;
1120
+ }
1121
+
1122
+ ngtcp2_crypto_aead_aes_128_gcm(&aead);
1123
+ ngtcp2_crypto_md_sha256(&md);
1124
+
1125
+ keylen = ngtcp2_crypto_aead_keylen(&aead);
1126
+ ivlen = ngtcp2_crypto_aead_noncelen(&aead);
1127
+
1128
+ assert(sizeof(key) >= keylen);
1129
+ assert(sizeof(iv) >= ivlen);
1130
+
1131
+ if (crypto_derive_token_key(key, keylen, iv, ivlen, &md, secret, secretlen,
1132
+ rand_data, sizeof(rand_data),
1133
+ regular_token_info_prefix,
1134
+ sizeof(regular_token_info_prefix) - 1) != 0) {
1135
+ return -1;
1136
+ }
1137
+
1138
+ aadlen = crypto_generate_regular_token_aad(aad, remote_addr);
1139
+
1140
+ p = token;
1141
+ *p++ = NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR;
1142
+
1143
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &aead, key, ivlen) != 0) {
1144
+ return -1;
1145
+ }
1146
+
1147
+ rv = ngtcp2_crypto_encrypt(p, &aead, &aead_ctx, plaintext, plaintextlen, iv,
1148
+ ivlen, aad, aadlen);
1149
+
1150
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
1151
+
1152
+ if (rv != 0) {
1153
+ return -1;
1154
+ }
1155
+
1156
+ p += plaintextlen + aead.max_overhead;
1157
+ memcpy(p, rand_data, sizeof(rand_data));
1158
+ p += sizeof(rand_data);
1159
+
1160
+ return p - token;
1161
+ }
1162
+
1163
+ int ngtcp2_crypto_verify_regular_token(const uint8_t *token, size_t tokenlen,
1164
+ const uint8_t *secret, size_t secretlen,
1165
+ const ngtcp2_sockaddr *remote_addr,
1166
+ ngtcp2_socklen remote_addrlen,
1167
+ ngtcp2_duration timeout,
1168
+ ngtcp2_tstamp ts) {
1169
+ uint8_t plaintext[sizeof(ngtcp2_tstamp)];
1170
+ uint8_t key[32];
1171
+ uint8_t iv[32];
1172
+ size_t keylen;
1173
+ size_t ivlen;
1174
+ ngtcp2_crypto_aead_ctx aead_ctx;
1175
+ ngtcp2_crypto_aead aead;
1176
+ ngtcp2_crypto_md md;
1177
+ uint8_t aad[sizeof(ngtcp2_sockaddr_in6)];
1178
+ size_t aadlen;
1179
+ const uint8_t *rand_data;
1180
+ const uint8_t *ciphertext;
1181
+ size_t ciphertextlen;
1182
+ int rv;
1183
+ ngtcp2_tstamp gen_ts;
1184
+ (void)remote_addrlen;
1185
+
1186
+ if (tokenlen != NGTCP2_CRYPTO_MAX_REGULAR_TOKENLEN ||
1187
+ token[0] != NGTCP2_CRYPTO_TOKEN_MAGIC_REGULAR) {
1188
+ return -1;
1189
+ }
1190
+
1191
+ rand_data = token + tokenlen - NGTCP2_CRYPTO_TOKEN_RAND_DATALEN;
1192
+ ciphertext = token + 1;
1193
+ ciphertextlen = tokenlen - 1 - NGTCP2_CRYPTO_TOKEN_RAND_DATALEN;
1194
+
1195
+ ngtcp2_crypto_aead_aes_128_gcm(&aead);
1196
+ ngtcp2_crypto_md_sha256(&md);
1197
+
1198
+ keylen = ngtcp2_crypto_aead_keylen(&aead);
1199
+ ivlen = ngtcp2_crypto_aead_noncelen(&aead);
1200
+
1201
+ if (crypto_derive_token_key(key, keylen, iv, ivlen, &md, secret, secretlen,
1202
+ rand_data, NGTCP2_CRYPTO_TOKEN_RAND_DATALEN,
1203
+ regular_token_info_prefix,
1204
+ sizeof(regular_token_info_prefix) - 1) != 0) {
1205
+ return -1;
1206
+ }
1207
+
1208
+ aadlen = crypto_generate_regular_token_aad(aad, remote_addr);
1209
+
1210
+ if (ngtcp2_crypto_aead_ctx_decrypt_init(&aead_ctx, &aead, key, ivlen) != 0) {
1211
+ return -1;
1212
+ }
1213
+
1214
+ rv = ngtcp2_crypto_decrypt(plaintext, &aead, &aead_ctx, ciphertext,
1215
+ ciphertextlen, iv, ivlen, aad, aadlen);
1216
+
1217
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
1218
+
1219
+ if (rv != 0) {
1220
+ return -1;
1221
+ }
1222
+
1223
+ memcpy(&gen_ts, plaintext, sizeof(gen_ts));
1224
+
1225
+ gen_ts = ngtcp2_ntohl64(gen_ts);
1226
+ if (gen_ts + timeout <= ts) {
1227
+ return -1;
1228
+ }
1229
+
1230
+ return 0;
1231
+ }
1232
+
1233
+ ngtcp2_ssize ngtcp2_crypto_write_connection_close(
1234
+ uint8_t *dest, size_t destlen, uint32_t version, const ngtcp2_cid *dcid,
1235
+ const ngtcp2_cid *scid, uint64_t error_code, const uint8_t *reason,
1236
+ size_t reasonlen) {
1237
+ uint8_t rx_secret[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
1238
+ uint8_t tx_secret[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
1239
+ uint8_t initial_secret[NGTCP2_CRYPTO_INITIAL_SECRETLEN];
1240
+ uint8_t tx_key[NGTCP2_CRYPTO_INITIAL_KEYLEN];
1241
+ uint8_t tx_iv[NGTCP2_CRYPTO_INITIAL_IVLEN];
1242
+ uint8_t tx_hp_key[NGTCP2_CRYPTO_INITIAL_KEYLEN];
1243
+ ngtcp2_crypto_ctx ctx;
1244
+ ngtcp2_ssize spktlen;
1245
+ ngtcp2_crypto_aead_ctx aead_ctx = {0};
1246
+ ngtcp2_crypto_cipher_ctx hp_ctx = {0};
1247
+
1248
+ ngtcp2_crypto_ctx_initial(&ctx);
1249
+
1250
+ if (ngtcp2_crypto_derive_initial_secrets(rx_secret, tx_secret, initial_secret,
1251
+ version, scid,
1252
+ NGTCP2_CRYPTO_SIDE_SERVER) != 0) {
1253
+ return -1;
1254
+ }
1255
+
1256
+ if (ngtcp2_crypto_derive_packet_protection_key(
1257
+ tx_key, tx_iv, tx_hp_key, version, &ctx.aead, &ctx.md, tx_secret,
1258
+ NGTCP2_CRYPTO_INITIAL_SECRETLEN) != 0) {
1259
+ return -1;
1260
+ }
1261
+
1262
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &ctx.aead, tx_key,
1263
+ NGTCP2_CRYPTO_INITIAL_IVLEN) != 0) {
1264
+ spktlen = -1;
1265
+ goto end;
1266
+ }
1267
+
1268
+ if (ngtcp2_crypto_cipher_ctx_encrypt_init(&hp_ctx, &ctx.hp, tx_hp_key) != 0) {
1269
+ spktlen = -1;
1270
+ goto end;
1271
+ }
1272
+
1273
+ spktlen = ngtcp2_pkt_write_connection_close(
1274
+ dest, destlen, version, dcid, scid, error_code, reason, reasonlen,
1275
+ ngtcp2_crypto_encrypt_cb, &ctx.aead, &aead_ctx, tx_iv,
1276
+ ngtcp2_crypto_hp_mask_cb, &ctx.hp, &hp_ctx);
1277
+ if (spktlen < 0) {
1278
+ spktlen = -1;
1279
+ }
1280
+
1281
+ end:
1282
+ ngtcp2_crypto_cipher_ctx_free(&hp_ctx);
1283
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
1284
+
1285
+ return spktlen;
1286
+ }
1287
+
1288
+ ngtcp2_ssize ngtcp2_crypto_write_retry(uint8_t *dest, size_t destlen,
1289
+ uint32_t version, const ngtcp2_cid *dcid,
1290
+ const ngtcp2_cid *scid,
1291
+ const ngtcp2_cid *odcid,
1292
+ const uint8_t *token, size_t tokenlen) {
1293
+ ngtcp2_crypto_aead aead;
1294
+ ngtcp2_ssize spktlen;
1295
+ ngtcp2_crypto_aead_ctx aead_ctx = {0};
1296
+ const uint8_t *key;
1297
+ size_t noncelen;
1298
+
1299
+ ngtcp2_crypto_aead_retry(&aead);
1300
+
1301
+ switch (version) {
1302
+ case NGTCP2_PROTO_VER_V1:
1303
+ key = (const uint8_t *)NGTCP2_RETRY_KEY_V1;
1304
+ noncelen = sizeof(NGTCP2_RETRY_NONCE_V1) - 1;
1305
+ break;
1306
+ case NGTCP2_PROTO_VER_V2:
1307
+ key = (const uint8_t *)NGTCP2_RETRY_KEY_V2;
1308
+ noncelen = sizeof(NGTCP2_RETRY_NONCE_V2) - 1;
1309
+ break;
1310
+ default:
1311
+ key = (const uint8_t *)NGTCP2_RETRY_KEY_DRAFT;
1312
+ noncelen = sizeof(NGTCP2_RETRY_NONCE_DRAFT) - 1;
1313
+ }
1314
+
1315
+ if (ngtcp2_crypto_aead_ctx_encrypt_init(&aead_ctx, &aead, key, noncelen) !=
1316
+ 0) {
1317
+ return -1;
1318
+ }
1319
+
1320
+ spktlen = ngtcp2_pkt_write_retry(dest, destlen, version, dcid, scid, odcid,
1321
+ token, tokenlen, ngtcp2_crypto_encrypt_cb,
1322
+ &aead, &aead_ctx);
1323
+ if (spktlen < 0) {
1324
+ spktlen = -1;
1325
+ }
1326
+
1327
+ ngtcp2_crypto_aead_ctx_free(&aead_ctx);
1328
+
1329
+ return spktlen;
1330
+ }
1331
+
1332
+ int ngtcp2_crypto_client_initial_cb(ngtcp2_conn *conn, void *user_data) {
1333
+ const ngtcp2_cid *dcid = ngtcp2_conn_get_dcid(conn);
1334
+ void *tls = ngtcp2_conn_get_tls_native_handle(conn);
1335
+ (void)user_data;
1336
+
1337
+ if (ngtcp2_crypto_derive_and_install_initial_key(
1338
+ conn, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1339
+ ngtcp2_conn_get_client_chosen_version(conn), dcid) != 0) {
1340
+ return NGTCP2_ERR_CALLBACK_FAILURE;
1341
+ }
1342
+
1343
+ if (crypto_set_local_transport_params(conn, tls) != 0) {
1344
+ return NGTCP2_ERR_CALLBACK_FAILURE;
1345
+ }
1346
+
1347
+ if (ngtcp2_crypto_read_write_crypto_data(conn, NGTCP2_CRYPTO_LEVEL_INITIAL,
1348
+ NULL, 0) != 0) {
1349
+ return NGTCP2_ERR_CALLBACK_FAILURE;
1350
+ }
1351
+
1352
+ return 0;
1353
+ }
1354
+
1355
+ int ngtcp2_crypto_recv_retry_cb(ngtcp2_conn *conn, const ngtcp2_pkt_hd *hd,
1356
+ void *user_data) {
1357
+ (void)user_data;
1358
+
1359
+ if (ngtcp2_crypto_derive_and_install_initial_key(
1360
+ conn, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1361
+ ngtcp2_conn_get_client_chosen_version(conn), &hd->scid) != 0) {
1362
+ return NGTCP2_ERR_CALLBACK_FAILURE;
1363
+ }
1364
+
1365
+ return 0;
1366
+ }
1367
+
1368
+ int ngtcp2_crypto_recv_client_initial_cb(ngtcp2_conn *conn,
1369
+ const ngtcp2_cid *dcid,
1370
+ void *user_data) {
1371
+ (void)user_data;
1372
+
1373
+ if (ngtcp2_crypto_derive_and_install_initial_key(
1374
+ conn, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1375
+ ngtcp2_conn_get_client_chosen_version(conn), dcid) != 0) {
1376
+ return NGTCP2_ERR_CALLBACK_FAILURE;
1377
+ }
1378
+
1379
+ return 0;
1380
+ }
1381
+
1382
+ int ngtcp2_crypto_version_negotiation_cb(ngtcp2_conn *conn, uint32_t version,
1383
+ const ngtcp2_cid *client_dcid,
1384
+ void *user_data) {
1385
+ (void)user_data;
1386
+
1387
+ if (ngtcp2_crypto_derive_and_install_vneg_initial_key(
1388
+ conn, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, version,
1389
+ client_dcid) != 0) {
1390
+ return NGTCP2_ERR_CALLBACK_FAILURE;
1391
+ }
1392
+
1393
+ return 0;
1394
+ }
1395
+
1396
+ void ngtcp2_crypto_delete_crypto_aead_ctx_cb(ngtcp2_conn *conn,
1397
+ ngtcp2_crypto_aead_ctx *aead_ctx,
1398
+ void *user_data) {
1399
+ (void)conn;
1400
+ (void)user_data;
1401
+
1402
+ ngtcp2_crypto_aead_ctx_free(aead_ctx);
1403
+ }
1404
+
1405
+ void ngtcp2_crypto_delete_crypto_cipher_ctx_cb(
1406
+ ngtcp2_conn *conn, ngtcp2_crypto_cipher_ctx *cipher_ctx, void *user_data) {
1407
+ (void)conn;
1408
+ (void)user_data;
1409
+
1410
+ ngtcp2_crypto_cipher_ctx_free(cipher_ctx);
1411
+ }
1412
+
1413
+ int ngtcp2_crypto_recv_crypto_data_cb(ngtcp2_conn *conn,
1414
+ ngtcp2_crypto_level crypto_level,
1415
+ uint64_t offset, const uint8_t *data,
1416
+ size_t datalen, void *user_data) {
1417
+ int rv;
1418
+ (void)offset;
1419
+ (void)user_data;
1420
+
1421
+ if (ngtcp2_crypto_read_write_crypto_data(conn, crypto_level, data, datalen) !=
1422
+ 0) {
1423
+ rv = ngtcp2_conn_get_tls_error(conn);
1424
+ if (rv) {
1425
+ return rv;
1426
+ }
1427
+ return NGTCP2_ERR_CRYPTO;
1428
+ }
1429
+
1430
+ return 0;
1431
+ }