@fails-components/webtransport 0.0.1-rc.0 → 0.0.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (384) hide show
  1. package/.github/workflows/npm-publish-packages.yml +0 -0
  2. package/CMakeLists.txt +2 -0
  3. package/package.json +1 -1
  4. package/readme.md +0 -0
  5. package/src/http3serversession.h +1 -1
  6. package/src/webtransport.js +4 -2
  7. package/third_party/boringssl/src/CMakeLists.txt +9 -12
  8. package/third_party/boringssl/src/crypto/CMakeLists.txt +2 -3
  9. package/third_party/boringssl/src/crypto/asn1/time_support.c +206 -206
  10. package/third_party/boringssl/src/crypto/bio/socket_helper.c +124 -122
  11. package/third_party/boringssl/src/crypto/evp/digestsign.c +268 -231
  12. package/third_party/boringssl/src/crypto/evp/p_ec.c +286 -286
  13. package/third_party/boringssl/src/crypto/fipsmodule/aes/key_wrap.c +246 -236
  14. package/third_party/boringssl/src/crypto/fipsmodule/aes/mode_wrappers.c +124 -122
  15. package/third_party/boringssl/src/crypto/fipsmodule/bcm.c +3 -0
  16. package/third_party/boringssl/src/crypto/fipsmodule/bn/bytes.c +246 -230
  17. package/third_party/boringssl/src/crypto/fipsmodule/bn/internal.h +734 -715
  18. package/third_party/boringssl/src/crypto/fipsmodule/bn/random.c +349 -341
  19. package/third_party/boringssl/src/crypto/fipsmodule/cipher/cipher.c +670 -648
  20. package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aes.c +1504 -1472
  21. package/third_party/boringssl/src/crypto/{cipher_extra → fipsmodule/cipher}/e_aesccm.c +435 -446
  22. package/third_party/boringssl/src/crypto/{cmac → fipsmodule/cmac}/cavp_3des_cmac_tests.txt +0 -0
  23. package/third_party/boringssl/src/crypto/{cmac → fipsmodule/cmac}/cavp_aes128_cmac_tests.txt +0 -0
  24. package/third_party/boringssl/src/crypto/{cmac → fipsmodule/cmac}/cavp_aes192_cmac_tests.txt +0 -0
  25. package/third_party/boringssl/src/crypto/{cmac → fipsmodule/cmac}/cavp_aes256_cmac_tests.txt +0 -0
  26. package/third_party/boringssl/src/crypto/{cmac → fipsmodule/cmac}/cmac.c +318 -278
  27. package/third_party/boringssl/src/crypto/{cmac → fipsmodule/cmac}/cmac_test.cc +268 -267
  28. package/third_party/boringssl/src/crypto/fipsmodule/dh/dh.c +5 -1
  29. package/third_party/boringssl/src/crypto/fipsmodule/ec/ec.c +11 -17
  30. package/third_party/boringssl/src/crypto/fipsmodule/ec/ec_key.c +15 -4
  31. package/third_party/boringssl/src/crypto/fipsmodule/ec/internal.h +2 -6
  32. package/third_party/boringssl/src/crypto/fipsmodule/ec/p224-64.c +1164 -1180
  33. package/third_party/boringssl/src/crypto/fipsmodule/ec/p256-nistz.c +3 -3
  34. package/third_party/boringssl/src/crypto/fipsmodule/ec/p256-nistz_test.cc +2 -2
  35. package/third_party/boringssl/src/crypto/fipsmodule/ec/p256.c +44 -33
  36. package/third_party/boringssl/src/crypto/fipsmodule/ec/scalar.c +169 -175
  37. package/third_party/boringssl/src/crypto/fipsmodule/ec/simple.c +352 -357
  38. package/third_party/boringssl/src/crypto/fipsmodule/ecdh/ecdh.c +4 -0
  39. package/third_party/boringssl/src/crypto/fipsmodule/ecdsa/ecdsa.c +14 -9
  40. package/third_party/boringssl/src/crypto/fipsmodule/hmac/hmac.c +256 -235
  41. package/third_party/boringssl/src/crypto/fipsmodule/rand/ctrdrbg.c +204 -202
  42. package/third_party/boringssl/src/crypto/fipsmodule/rsa/padding.c +702 -695
  43. package/third_party/boringssl/src/crypto/fipsmodule/rsa/rsa_impl.c +7 -2
  44. package/third_party/boringssl/src/crypto/fipsmodule/self_check/self_check.c +7 -0
  45. package/third_party/boringssl/src/crypto/fipsmodule/service_indicator/internal.h +89 -0
  46. package/third_party/boringssl/src/crypto/fipsmodule/service_indicator/service_indicator.c +333 -0
  47. package/third_party/boringssl/src/crypto/fipsmodule/service_indicator/service_indicator_test.cc +2410 -0
  48. package/third_party/boringssl/src/crypto/fipsmodule/sha/sha1.c +359 -357
  49. package/third_party/boringssl/src/crypto/fipsmodule/sha/sha256.c +325 -321
  50. package/third_party/boringssl/src/crypto/fipsmodule/sha/sha512.c +510 -508
  51. package/third_party/boringssl/src/crypto/fipsmodule/tls/kdf.c +177 -165
  52. package/third_party/boringssl/src/crypto/internal.h +13 -0
  53. package/third_party/boringssl/src/crypto/trust_token/trust_token_test.cc +884 -884
  54. package/third_party/boringssl/src/crypto/x509/internal.h +0 -2
  55. package/third_party/boringssl/src/crypto/x509/t_crl.c +148 -148
  56. package/third_party/boringssl/src/crypto/x509/t_req.c +249 -250
  57. package/third_party/boringssl/src/crypto/x509/t_x509.c +2 -3
  58. package/third_party/boringssl/src/crypto/x509/x509_req.c +262 -304
  59. package/third_party/boringssl/src/crypto/x509/x509_set.c +250 -240
  60. package/third_party/boringssl/src/crypto/x509/x509_test.cc +466 -4
  61. package/third_party/boringssl/src/crypto/x509/x509cset.c +292 -279
  62. package/third_party/boringssl/src/crypto/x509/x509rset.c +89 -86
  63. package/third_party/boringssl/src/crypto/x509/x_crl.c +37 -125
  64. package/third_party/boringssl/src/crypto/x509/x_req.c +114 -109
  65. package/third_party/boringssl/src/crypto/x509/x_x509.c +394 -394
  66. package/third_party/boringssl/src/crypto/x509v3/v3_akey.c +11 -16
  67. package/third_party/boringssl/src/crypto/x509v3/v3_alt.c +644 -642
  68. package/third_party/boringssl/src/crypto/x509v3/v3_bcons.c +130 -133
  69. package/third_party/boringssl/src/crypto/x509v3/v3_bitst.c +149 -144
  70. package/third_party/boringssl/src/crypto/x509v3/v3_cpols.c +496 -500
  71. package/third_party/boringssl/src/crypto/x509v3/v3_enum.c +105 -106
  72. package/third_party/boringssl/src/crypto/x509v3/v3_ia5.c +126 -121
  73. package/third_party/boringssl/src/crypto/x509v3/v3_info.c +206 -218
  74. package/third_party/boringssl/src/crypto/x509v3/v3_int.c +97 -91
  75. package/third_party/boringssl/src/crypto/x509v3/v3_pci.c +290 -289
  76. package/third_party/boringssl/src/crypto/x509v3/v3_skey.c +161 -156
  77. package/third_party/boringssl/src/crypto/x509v3/v3_utl.c +5 -3
  78. package/third_party/boringssl/src/include/openssl/aead.h +480 -480
  79. package/third_party/boringssl/src/include/openssl/asn1.h +2 -0
  80. package/third_party/boringssl/src/include/openssl/base.h +1 -1
  81. package/third_party/boringssl/src/include/openssl/service_indicator.h +96 -0
  82. package/third_party/boringssl/src/include/openssl/ssl.h +7 -0
  83. package/third_party/boringssl/src/include/openssl/x509.h +11 -33
  84. package/third_party/boringssl/src/include/openssl/x509v3.h +990 -1018
  85. package/third_party/boringssl/src/sources.cmake +4 -4
  86. package/third_party/boringssl/src/ssl/internal.h +10 -0
  87. package/third_party/boringssl/src/ssl/ssl_lib.cc +3081 -3072
  88. package/third_party/boringssl/src/ssl/ssl_test.cc +46 -0
  89. package/third_party/boringssl/src/ssl/tls13_server.cc +4 -6
  90. package/third_party/boringssl/src/util/bot/DEPS +14 -27
  91. package/third_party/boringssl/src/util/bot/UPDATING +3 -9
  92. package/third_party/boringssl/src/util/bot/update_clang.py +172 -172
  93. package/third_party/boringssl/src/util/bot/vs_toolchain.py +3 -3
  94. package/third_party/quiche/.bazelrc +8 -0
  95. package/third_party/quiche/BUILD.bazel +7 -0
  96. package/third_party/quiche/WHITESPACE +3 -1
  97. package/third_party/quiche/WORKSPACE.bazel +87 -0
  98. package/third_party/quiche/build/BUILD.bazel +7 -0
  99. package/third_party/quiche/build/source_list.bzl +1511 -0
  100. package/third_party/quiche/build/source_list.gni +1511 -0
  101. package/third_party/quiche/build/source_list.json +1511 -0
  102. package/third_party/quiche/build/test.bzl +26 -0
  103. package/third_party/quiche/build/zlib.BUILD +25 -0
  104. package/third_party/quiche/quiche/BUILD.bazel +270 -0
  105. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_enums.cc +3 -3
  106. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_enums.h +7 -7
  107. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_frame.cc +39 -18
  108. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_frame.h +11 -10
  109. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_frame_test.cc +67 -63
  110. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_headers.cc +13 -12
  111. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_headers.h +16 -8
  112. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_headers_test.cc +9 -9
  113. package/third_party/quiche/quiche/{common/balsa → balsa}/balsa_visitor_interface.h +4 -4
  114. package/third_party/quiche/quiche/{common/balsa → balsa}/framer_interface.h +3 -3
  115. package/third_party/quiche/quiche/{common/balsa → balsa}/header_api.h +3 -3
  116. package/third_party/quiche/quiche/{common/balsa → balsa}/header_properties.cc +1 -1
  117. package/third_party/quiche/quiche/{common/balsa → balsa}/header_properties.h +3 -3
  118. package/third_party/quiche/quiche/{common/balsa → balsa}/header_properties_test.cc +1 -1
  119. package/third_party/quiche/quiche/{common/balsa → balsa}/http_validation_policy.cc +1 -1
  120. package/third_party/quiche/quiche/{common/balsa → balsa}/http_validation_policy.h +3 -3
  121. package/third_party/quiche/quiche/{common/balsa → balsa}/noop_balsa_visitor.h +4 -4
  122. package/third_party/quiche/quiche/{common/balsa → balsa}/simple_buffer.cc +22 -29
  123. package/third_party/quiche/quiche/{common/balsa → balsa}/simple_buffer.h +18 -16
  124. package/third_party/quiche/quiche/{common/balsa → balsa}/simple_buffer_test.cc +79 -32
  125. package/third_party/quiche/quiche/{common/balsa → balsa}/standard_header_map.cc +1 -1
  126. package/third_party/quiche/quiche/{common/balsa → balsa}/standard_header_map.h +3 -3
  127. package/third_party/quiche/quiche/common/platform/api/quiche_command_line_flags.h +6 -1
  128. package/third_party/quiche/quiche/common/platform/api/quiche_flags.h +8 -0
  129. package/third_party/quiche/quiche/common/platform/api/quiche_logging.h +0 -3
  130. package/third_party/quiche/quiche/common/platform/api/quiche_lower_case_string_test.cc +29 -0
  131. package/third_party/quiche/quiche/common/platform/api/quiche_test.h +5 -7
  132. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quic_flags_impl.h +1 -1
  133. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_bug_tracker_impl.h +3 -2
  134. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_command_line_flags_impl.cc +41 -0
  135. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_command_line_flags_impl.h +33 -0
  136. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_expect_bug_impl.h +15 -0
  137. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_logging_impl.h +84 -50
  138. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_lower_case_string_impl.h +25 -0
  139. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_stack_trace_impl.cc +1 -1
  140. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_test_impl.cc +25 -0
  141. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_test_impl.h +56 -0
  142. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_test_output_impl.h +27 -0
  143. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_thread_impl.h +26 -0
  144. package/third_party/quiche/quiche/common/platform/default/quiche_platform_impl/quiche_url_utils_impl.cc +1 -0
  145. package/third_party/quiche/quiche/common/quiche_buffer_allocator_test.cc +1 -1
  146. package/third_party/quiche/quiche/common/quiche_mem_slice_storage.h +2 -3
  147. package/third_party/quiche/quiche/common/structured_headers.cc +14 -12
  148. package/third_party/quiche/quiche/http2/adapter/event_forwarder.cc +7 -5
  149. package/third_party/quiche/quiche/http2/adapter/event_forwarder.h +4 -2
  150. package/third_party/quiche/quiche/http2/adapter/event_forwarder_test.cc +14 -9
  151. package/third_party/quiche/quiche/http2/adapter/header_validator.cc +43 -19
  152. package/third_party/quiche/quiche/http2/adapter/header_validator.h +11 -40
  153. package/third_party/quiche/quiche/http2/adapter/header_validator_base.h +69 -0
  154. package/third_party/quiche/quiche/http2/adapter/header_validator_test.cc +73 -1
  155. package/third_party/quiche/quiche/http2/adapter/nghttp2_adapter_test.cc +66 -0
  156. package/third_party/quiche/quiche/http2/adapter/nghttp2_session_test.cc +8 -5
  157. package/third_party/quiche/quiche/http2/adapter/nghttp2_test.cc +1 -1
  158. package/third_party/quiche/quiche/http2/adapter/noop_header_validator.cc +22 -0
  159. package/third_party/quiche/quiche/http2/adapter/noop_header_validator.h +25 -0
  160. package/third_party/quiche/quiche/http2/adapter/noop_header_validator_test.cc +523 -0
  161. package/third_party/quiche/quiche/http2/adapter/oghttp2_adapter_test.cc +186 -5
  162. package/third_party/quiche/quiche/http2/adapter/oghttp2_session.cc +37 -43
  163. package/third_party/quiche/quiche/http2/adapter/oghttp2_session.h +22 -23
  164. package/third_party/quiche/quiche/http2/adapter/test_utils.cc +1 -1
  165. package/third_party/quiche/quiche/http2/adapter/window_manager_test.cc +11 -5
  166. package/third_party/quiche/quiche/http2/core/http2_trace_logging.cc +13 -11
  167. package/third_party/quiche/quiche/http2/core/http2_trace_logging.h +5 -4
  168. package/third_party/quiche/quiche/http2/core/priority_write_scheduler.h +42 -36
  169. package/third_party/quiche/quiche/http2/core/priority_write_scheduler_test.cc +2 -2
  170. package/third_party/quiche/quiche/http2/decoder/decode_buffer_test.cc +9 -9
  171. package/third_party/quiche/quiche/http2/decoder/decode_http2_structures_test.cc +1 -1
  172. package/third_party/quiche/quiche/http2/decoder/http2_frame_decoder_test.cc +14 -14
  173. package/third_party/quiche/quiche/http2/decoder/http2_structure_decoder_test.cc +17 -17
  174. package/third_party/quiche/quiche/http2/decoder/payload_decoders/altsvc_payload_decoder_test.cc +1 -1
  175. package/third_party/quiche/quiche/http2/decoder/payload_decoders/continuation_payload_decoder_test.cc +1 -1
  176. package/third_party/quiche/quiche/http2/decoder/payload_decoders/data_payload_decoder_test.cc +2 -2
  177. package/third_party/quiche/quiche/http2/decoder/payload_decoders/goaway_payload_decoder_test.cc +1 -1
  178. package/third_party/quiche/quiche/http2/decoder/payload_decoders/headers_payload_decoder_test.cc +1 -1
  179. package/third_party/quiche/quiche/http2/decoder/payload_decoders/ping_payload_decoder_test.cc +1 -1
  180. package/third_party/quiche/quiche/http2/decoder/payload_decoders/priority_payload_decoder_test.cc +1 -1
  181. package/third_party/quiche/quiche/http2/decoder/payload_decoders/priority_update_payload_decoder_test.cc +1 -1
  182. package/third_party/quiche/quiche/http2/decoder/payload_decoders/push_promise_payload_decoder_test.cc +1 -1
  183. package/third_party/quiche/quiche/http2/decoder/payload_decoders/rst_stream_payload_decoder_test.cc +1 -1
  184. package/third_party/quiche/quiche/http2/decoder/payload_decoders/settings_payload_decoder_test.cc +1 -1
  185. package/third_party/quiche/quiche/http2/decoder/payload_decoders/unknown_payload_decoder_test.cc +1 -1
  186. package/third_party/quiche/quiche/http2/decoder/payload_decoders/window_update_payload_decoder_test.cc +1 -1
  187. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_block_decoder_test.cc +2 -2
  188. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_decoder_state_test.cc +8 -8
  189. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_decoder_string_buffer_test.cc +4 -3
  190. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_decoder_tables_test.cc +17 -17
  191. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_decoder_test.cc +25 -25
  192. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_entry_decoder_test.cc +2 -2
  193. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_entry_type_decoder_test.cc +7 -6
  194. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_string_decoder_test.cc +6 -6
  195. package/third_party/quiche/quiche/http2/hpack/decoder/hpack_whole_entry_buffer_test.cc +1 -1
  196. package/third_party/quiche/quiche/http2/hpack/huffman/hpack_huffman_decoder_test.cc +2 -2
  197. package/third_party/quiche/quiche/http2/hpack/huffman/hpack_huffman_encoder_test.cc +1 -1
  198. package/third_party/quiche/quiche/http2/hpack/huffman/hpack_huffman_transcoder_test.cc +5 -5
  199. package/third_party/quiche/quiche/http2/hpack/varint/hpack_varint_decoder_test.cc +4 -4
  200. package/third_party/quiche/quiche/http2/hpack/varint/hpack_varint_round_trip_test.cc +1 -1
  201. package/third_party/quiche/quiche/http2/http2_constants_test.cc +1 -1
  202. package/third_party/quiche/quiche/http2/http2_structures_test.cc +23 -22
  203. package/third_party/quiche/quiche/http2/test_tools/frame_decoder_state_test_util.cc +1 -1
  204. package/third_party/quiche/quiche/http2/test_tools/frame_decoder_state_test_util.h +1 -1
  205. package/third_party/quiche/quiche/http2/test_tools/frame_parts.cc +38 -38
  206. package/third_party/quiche/quiche/http2/test_tools/hpack_block_collector.cc +15 -15
  207. package/third_party/quiche/quiche/http2/test_tools/hpack_entry_collector.cc +24 -22
  208. package/third_party/quiche/quiche/http2/test_tools/hpack_string_collector.cc +5 -5
  209. package/third_party/quiche/quiche/http2/test_tools/http2_frame_builder_test.cc +70 -89
  210. package/third_party/quiche/quiche/http2/test_tools/payload_decoder_base_test_util.cc +1 -1
  211. package/third_party/quiche/quiche/http2/test_tools/payload_decoder_base_test_util.h +29 -26
  212. package/third_party/quiche/quiche/http2/test_tools/{random_decoder_test.cc → random_decoder_test_base.cc} +13 -10
  213. package/third_party/quiche/quiche/http2/test_tools/{random_decoder_test.h → random_decoder_test_base.h} +15 -17
  214. package/third_party/quiche/quiche/http2/test_tools/{random_decoder_test_test.cc → random_decoder_test_base_test.cc} +1 -1
  215. package/third_party/quiche/quiche/http2/test_tools/verify_macros.h +32 -0
  216. package/third_party/quiche/quiche/quic/core/congestion_control/bbr2_sender.cc +2 -1
  217. package/third_party/quiche/quiche/quic/core/congestion_control/bbr2_simulator_test.cc +3 -2
  218. package/third_party/quiche/quiche/quic/core/congestion_control/bbr_sender_test.cc +3 -2
  219. package/third_party/quiche/quiche/quic/core/congestion_control/rtt_stats.cc +3 -2
  220. package/third_party/quiche/quiche/quic/core/congestion_control/rtt_stats.h +2 -1
  221. package/third_party/quiche/quiche/quic/core/congestion_control/rtt_stats_test.cc +2 -13
  222. package/third_party/quiche/quiche/quic/core/crypto/certificate_view.cc +15 -0
  223. package/third_party/quiche/quiche/quic/core/crypto/certificate_view.h +7 -0
  224. package/third_party/quiche/quiche/quic/core/crypto/certificate_view_test.cc +16 -0
  225. package/third_party/quiche/quiche/quic/core/crypto/crypto_protocol.h +1 -0
  226. package/third_party/quiche/quiche/quic/core/crypto/proof_source.h +2 -2
  227. package/third_party/quiche/quiche/quic/core/crypto/proof_source_x509.cc +3 -5
  228. package/third_party/quiche/quiche/quic/core/crypto/proof_source_x509.h +1 -2
  229. package/third_party/quiche/quiche/quic/core/crypto/quic_crypto_server_config.cc +1 -1
  230. package/third_party/quiche/quiche/quic/core/crypto/quic_crypto_server_config.h +3 -3
  231. package/third_party/quiche/quiche/quic/core/frames/quic_blocked_frame.cc +2 -8
  232. package/third_party/quiche/quiche/quic/core/frames/quic_blocked_frame.h +0 -1
  233. package/third_party/quiche/quiche/quic/core/frames/quic_crypto_frame.h +2 -0
  234. package/third_party/quiche/quiche/quic/core/frames/quic_frames_test.cc +2 -1
  235. package/third_party/quiche/quiche/quic/core/http/capsule.cc +2 -22
  236. package/third_party/quiche/quiche/quic/core/http/capsule.h +0 -2
  237. package/third_party/quiche/quiche/quic/core/http/capsule_test.cc +1 -2
  238. package/third_party/quiche/quiche/quic/core/http/end_to_end_test.cc +148 -57
  239. package/third_party/quiche/quiche/quic/core/http/http_constants.cc +1 -1
  240. package/third_party/quiche/quiche/quic/core/http/http_constants.h +2 -2
  241. package/third_party/quiche/quiche/quic/core/http/quic_header_list_test.cc +2 -2
  242. package/third_party/quiche/quiche/quic/core/http/quic_headers_stream_test.cc +18 -14
  243. package/third_party/quiche/quiche/quic/core/http/quic_send_control_stream.h +2 -1
  244. package/third_party/quiche/quiche/quic/core/http/quic_send_control_stream_test.cc +3 -7
  245. package/third_party/quiche/quiche/quic/core/http/quic_server_session_base.h +4 -0
  246. package/third_party/quiche/quiche/quic/core/http/quic_spdy_session.cc +47 -65
  247. package/third_party/quiche/quiche/quic/core/http/quic_spdy_session.h +5 -17
  248. package/third_party/quiche/quiche/quic/core/http/quic_spdy_session_test.cc +63 -54
  249. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.cc +34 -91
  250. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.h +1 -9
  251. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream_test.cc +27 -134
  252. package/third_party/quiche/quiche/quic/core/http/spdy_utils.cc +0 -41
  253. package/third_party/quiche/quiche/quic/core/http/spdy_utils.h +0 -9
  254. package/third_party/quiche/quiche/quic/core/http/spdy_utils_test.cc +0 -32
  255. package/third_party/quiche/quiche/quic/core/http/web_transport_http3.cc +0 -1
  256. package/third_party/quiche/quiche/quic/core/packet_number_indexed_queue_test.cc +2 -2
  257. package/third_party/quiche/quiche/quic/core/qpack/qpack_header_table.cc +2 -1
  258. package/third_party/quiche/quiche/quic/core/qpack/qpack_send_stream.h +2 -1
  259. package/third_party/quiche/quiche/quic/core/quic_arena_scoped_ptr_test.cc +2 -2
  260. package/third_party/quiche/quiche/quic/core/quic_connection.cc +68 -46
  261. package/third_party/quiche/quiche/quic/core/quic_connection.h +7 -6
  262. package/third_party/quiche/quiche/quic/core/quic_connection_context_test.cc +2 -2
  263. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager_test.cc +2 -2
  264. package/third_party/quiche/quiche/quic/core/quic_connection_id_test.cc +2 -2
  265. package/third_party/quiche/quiche/quic/core/quic_connection_test.cc +45 -132
  266. package/third_party/quiche/quiche/quic/core/quic_constants.h +0 -7
  267. package/third_party/quiche/quiche/quic/core/quic_control_frame_manager.cc +11 -3
  268. package/third_party/quiche/quiche/quic/core/quic_control_frame_manager.h +1 -1
  269. package/third_party/quiche/quiche/quic/core/quic_control_frame_manager_test.cc +2 -2
  270. package/third_party/quiche/quiche/quic/core/quic_crypto_client_handshaker.cc +13 -1
  271. package/third_party/quiche/quiche/quic/core/quic_crypto_client_handshaker.h +3 -0
  272. package/third_party/quiche/quiche/quic/core/quic_crypto_client_handshaker_test.cc +2 -2
  273. package/third_party/quiche/quiche/quic/core/quic_crypto_client_stream.cc +6 -0
  274. package/third_party/quiche/quiche/quic/core/quic_crypto_client_stream.h +8 -0
  275. package/third_party/quiche/quiche/quic/core/quic_crypto_server_stream.cc +26 -13
  276. package/third_party/quiche/quiche/quic/core/quic_crypto_server_stream.h +5 -2
  277. package/third_party/quiche/quiche/quic/core/quic_crypto_stream.cc +55 -47
  278. package/third_party/quiche/quiche/quic/core/quic_crypto_stream.h +15 -10
  279. package/third_party/quiche/quiche/quic/core/quic_crypto_stream_test.cc +34 -5
  280. package/third_party/quiche/quiche/quic/core/quic_dispatcher.cc +20 -11
  281. package/third_party/quiche/quiche/quic/core/quic_dispatcher_test.cc +37 -13
  282. package/third_party/quiche/quiche/quic/core/quic_flags_list.h +6 -10
  283. package/third_party/quiche/quiche/quic/core/quic_flow_controller.cc +3 -3
  284. package/third_party/quiche/quiche/quic/core/quic_flow_controller.h +2 -2
  285. package/third_party/quiche/quiche/quic/core/quic_flow_controller_test.cc +15 -10
  286. package/third_party/quiche/quiche/quic/core/quic_framer.cc +1 -1
  287. package/third_party/quiche/quiche/quic/core/quic_one_block_arena.h +3 -2
  288. package/third_party/quiche/quiche/quic/core/quic_one_block_arena_test.cc +2 -2
  289. package/third_party/quiche/quiche/quic/core/quic_packet_creator.cc +3 -11
  290. package/third_party/quiche/quiche/quic/core/quic_packet_creator.h +0 -8
  291. package/third_party/quiche/quiche/quic/core/quic_ping_manager.cc +14 -14
  292. package/third_party/quiche/quiche/quic/core/quic_ping_manager_test.cc +48 -0
  293. package/third_party/quiche/quiche/quic/core/quic_received_packet_manager.cc +3 -18
  294. package/third_party/quiche/quiche/quic/core/quic_received_packet_manager_test.cc +4 -14
  295. package/third_party/quiche/quiche/quic/core/quic_server_id_test.cc +2 -2
  296. package/third_party/quiche/quiche/quic/core/quic_session.cc +4 -4
  297. package/third_party/quiche/quiche/quic/core/quic_session.h +1 -1
  298. package/third_party/quiche/quiche/quic/core/quic_session_test.cc +21 -1
  299. package/third_party/quiche/quiche/quic/core/quic_stream.cc +4 -7
  300. package/third_party/quiche/quiche/quic/core/quic_stream_test.cc +2 -4
  301. package/third_party/quiche/quiche/quic/core/quic_trace_visitor_test.cc +2 -2
  302. package/third_party/quiche/quiche/quic/core/quic_types.h +3 -8
  303. package/third_party/quiche/quiche/quic/core/quic_udp_socket_posix.cc +5 -4
  304. package/third_party/quiche/quiche/quic/core/quic_unacked_packet_map_test.cc +1 -1
  305. package/third_party/quiche/quiche/quic/core/quic_utils.cc +1 -1
  306. package/third_party/quiche/quiche/quic/core/quic_utils.h +2 -2
  307. package/third_party/quiche/quiche/quic/core/quic_versions_test.cc +0 -1
  308. package/third_party/quiche/quiche/quic/core/tls_client_handshaker.cc +13 -0
  309. package/third_party/quiche/quiche/quic/core/tls_client_handshaker.h +2 -0
  310. package/third_party/quiche/quiche/quic/core/tls_server_handshaker.cc +17 -3
  311. package/third_party/quiche/quiche/quic/core/tls_server_handshaker.h +3 -1
  312. package/third_party/quiche/quiche/quic/core/uber_received_packet_manager_test.cc +18 -10
  313. package/third_party/quiche/quiche/quic/masque/masque_client_bin.cc +6 -4
  314. package/third_party/quiche/quiche/quic/masque/masque_client_session.cc +23 -7
  315. package/third_party/quiche/quiche/quic/masque/masque_client_session.h +1 -1
  316. package/third_party/quiche/quiche/quic/masque/masque_server_backend.cc +13 -0
  317. package/third_party/quiche/quiche/quic/masque/masque_server_backend.h +2 -0
  318. package/third_party/quiche/quiche/quic/masque/masque_server_bin.cc +5 -4
  319. package/third_party/quiche/quiche/quic/masque/masque_server_session.cc +30 -40
  320. package/third_party/quiche/quiche/quic/masque/masque_server_session.h +1 -1
  321. package/third_party/quiche/quiche/quic/platform/api/quic_export.h +4 -4
  322. package/third_party/quiche/quiche/quic/platform/api/quic_flags.h +0 -1
  323. package/third_party/quiche/quiche/quic/platform/api/quic_logging.h +0 -6
  324. package/third_party/quiche/quiche/quic/platform/api/quic_test.h +6 -5
  325. package/third_party/quiche/quiche/quic/qbone/bonnet/icmp_reachable_test.cc +2 -2
  326. package/third_party/quiche/quiche/quic/qbone/bonnet/mock_qbone_tunnel.h +2 -0
  327. package/third_party/quiche/quiche/quic/qbone/bonnet/qbone_tunnel_interface.h +2 -0
  328. package/third_party/quiche/quiche/quic/qbone/bonnet/tun_device_controller_test.cc +2 -2
  329. package/third_party/quiche/quiche/quic/qbone/bonnet/tun_device_packet_exchanger_test.cc +2 -2
  330. package/third_party/quiche/quiche/quic/qbone/bonnet/tun_device_test.cc +2 -2
  331. package/third_party/quiche/quiche/quic/qbone/platform/netlink_test.cc +2 -2
  332. package/third_party/quiche/quiche/quic/qbone/platform/tcp_packet.cc +5 -4
  333. package/third_party/quiche/quiche/quic/qbone/qbone_client_session.cc +4 -2
  334. package/third_party/quiche/quiche/quic/qbone/qbone_packet_processor.cc +2 -1
  335. package/third_party/quiche/quiche/quic/qbone/qbone_packet_processor_test.cc +2 -2
  336. package/third_party/quiche/quiche/quic/qbone/qbone_server_session.cc +4 -2
  337. package/third_party/quiche/quiche/quic/qbone/qbone_session_base.cc +3 -2
  338. package/third_party/quiche/quiche/quic/qbone/qbone_stream.cc +4 -4
  339. package/third_party/quiche/quiche/quic/test_tools/quic_connection_peer.cc +1 -1
  340. package/third_party/quiche/quiche/quic/test_tools/quic_http_response_cache_data/test.example.com/index.html +63 -0
  341. package/third_party/quiche/quiche/quic/test_tools/quic_http_response_cache_data/test.example.com/map.html +65 -0
  342. package/third_party/quiche/quiche/quic/test_tools/quic_test_utils.cc +4 -3
  343. package/third_party/quiche/quiche/quic/test_tools/quic_test_utils.h +18 -1
  344. package/third_party/quiche/quiche/quic/test_tools/simulator/quic_endpoint_test.cc +1 -1
  345. package/third_party/quiche/quiche/quic/test_tools/simulator/simulator_test.cc +1 -1
  346. package/third_party/quiche/quiche/quic/test_tools/test_ticket_crypter.cc +1 -1
  347. package/third_party/quiche/quiche/quic/test_tools/test_ticket_crypter.h +2 -2
  348. package/third_party/quiche/quiche/quic/{core/crypto → tools}/crypto_message_printer_bin.cc +0 -0
  349. package/third_party/quiche/quiche/quic/{core/qpack → tools}/qpack_offline_decoder_bin.cc +0 -0
  350. package/third_party/quiche/quiche/quic/tools/quic_client_interop_test_bin.cc +4 -3
  351. package/third_party/quiche/quiche/quic/tools/quic_memory_cache_backend_test.cc +3 -31
  352. package/third_party/quiche/quiche/quic/tools/quic_packet_printer_bin.cc +2 -2
  353. package/third_party/quiche/quiche/quic/tools/quic_simple_server_session.h +1 -1
  354. package/third_party/quiche/quiche/quic/tools/quic_simple_server_session_test.cc +1 -1
  355. package/third_party/quiche/quiche/quic/tools/quic_toy_client.cc +52 -38
  356. package/third_party/quiche/quiche/quic/tools/quic_toy_server.cc +10 -7
  357. package/third_party/quiche/quiche/quic/tools/simple_ticket_crypter.cc +1 -1
  358. package/third_party/quiche/quiche/quic/tools/simple_ticket_crypter.h +1 -1
  359. package/third_party/quiche/quiche/quic/tools/web_transport_test_visitors.h +3 -2
  360. package/third_party/quiche/quiche/spdy/core/array_output_buffer.h +1 -1
  361. package/third_party/quiche/quiche/spdy/core/hpack/hpack_decoder_adapter_test.cc +1 -1
  362. package/third_party/quiche/quiche/spdy/core/hpack/hpack_encoder_test.cc +2 -1
  363. package/third_party/quiche/quiche/spdy/core/hpack/hpack_header_table_test.cc +1 -1
  364. package/third_party/quiche/quiche/spdy/core/hpack/hpack_round_trip_test.cc +2 -1
  365. package/third_party/quiche/quiche/spdy/core/hpack/hpack_static_table_test.cc +1 -1
  366. package/third_party/quiche/quiche/spdy/core/http2_frame_decoder_adapter.cc +8 -6
  367. package/third_party/quiche/quiche/spdy/core/http2_frame_decoder_adapter.h +17 -6
  368. package/third_party/quiche/quiche/spdy/core/metadata_extension.cc +1 -1
  369. package/third_party/quiche/quiche/spdy/core/metadata_extension_test.cc +1 -1
  370. package/third_party/quiche/quiche/spdy/core/spdy_framer_test.cc +21 -17
  371. package/third_party/quiche/quiche/spdy/core/spdy_intrusive_list_test.cc +3 -3
  372. package/third_party/quiche/quiche/spdy/core/spdy_no_op_visitor.h +6 -4
  373. package/third_party/quiche/quiche/spdy/core/spdy_pinnable_buffer_piece_test.cc +1 -1
  374. package/third_party/quiche/quiche/spdy/core/spdy_prefixed_buffer_reader_test.cc +1 -1
  375. package/third_party/quiche/quiche/spdy/core/spdy_protocol_test.cc +1 -1
  376. package/third_party/quiche/quiche/spdy/test_tools/mock_spdy_framer_visitor.h +5 -4
  377. package/third_party/boringssl/src/util/bot/cmake-win32.zip.sha1 +0 -1
  378. package/third_party/quiche/quiche/common/platform/api/quiche_mock_log.h +0 -18
  379. package/third_party/quiche/quiche/common/platform/api/quiche_test_helpers.h +0 -8
  380. package/third_party/quiche/quiche/quic/platform/api/quic_mock_log.h +0 -19
  381. package/third_party/quiche/quiche/quic/tools/quic_transport_simple_server_dispatcher.cc +0 -51
  382. package/third_party/quiche/quiche/quic/tools/quic_transport_simple_server_dispatcher.h +0 -41
  383. package/third_party/quiche/quiche/quic/tools/quic_transport_simple_server_session.cc +0 -168
  384. package/third_party/quiche/quiche/quic/tools/quic_transport_simple_server_session.h +0 -78
@@ -1,648 +1,670 @@
1
- /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2
- * All rights reserved.
3
- *
4
- * This package is an SSL implementation written
5
- * by Eric Young (eay@cryptsoft.com).
6
- * The implementation was written so as to conform with Netscapes SSL.
7
- *
8
- * This library is free for commercial and non-commercial use as long as
9
- * the following conditions are aheared to. The following conditions
10
- * apply to all code found in this distribution, be it the RC4, RSA,
11
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12
- * included with this distribution is covered by the same copyright terms
13
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14
- *
15
- * Copyright remains Eric Young's, and as such any Copyright notices in
16
- * the code are not to be removed.
17
- * If this package is used in a product, Eric Young should be given attribution
18
- * as the author of the parts of the library used.
19
- * This can be in the form of a textual message at program startup or
20
- * in documentation (online or textual) provided with the package.
21
- *
22
- * Redistribution and use in source and binary forms, with or without
23
- * modification, are permitted provided that the following conditions
24
- * are met:
25
- * 1. Redistributions of source code must retain the copyright
26
- * notice, this list of conditions and the following disclaimer.
27
- * 2. Redistributions in binary form must reproduce the above copyright
28
- * notice, this list of conditions and the following disclaimer in the
29
- * documentation and/or other materials provided with the distribution.
30
- * 3. All advertising materials mentioning features or use of this software
31
- * must display the following acknowledgement:
32
- * "This product includes cryptographic software written by
33
- * Eric Young (eay@cryptsoft.com)"
34
- * The word 'cryptographic' can be left out if the rouines from the library
35
- * being used are not cryptographic related :-).
36
- * 4. If you include any Windows specific code (or a derivative thereof) from
37
- * the apps directory (application code) you must include an acknowledgement:
38
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39
- *
40
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
- * SUCH DAMAGE.
51
- *
52
- * The licence and distribution terms for any publically available version or
53
- * derivative of this code cannot be changed. i.e. this code cannot simply be
54
- * copied and put under another distribution licence
55
- * [including the GNU Public Licence.] */
56
-
57
- #include <openssl/cipher.h>
58
-
59
- #include <assert.h>
60
- #include <limits.h>
61
- #include <string.h>
62
-
63
- #include <openssl/err.h>
64
- #include <openssl/mem.h>
65
- #include <openssl/nid.h>
66
-
67
- #include "internal.h"
68
- #include "../../internal.h"
69
-
70
-
71
- void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) {
72
- OPENSSL_memset(ctx, 0, sizeof(EVP_CIPHER_CTX));
73
- }
74
-
75
- EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) {
76
- EVP_CIPHER_CTX *ctx = OPENSSL_malloc(sizeof(EVP_CIPHER_CTX));
77
- if (ctx) {
78
- EVP_CIPHER_CTX_init(ctx);
79
- }
80
- return ctx;
81
- }
82
-
83
- int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) {
84
- if (c->cipher != NULL && c->cipher->cleanup) {
85
- c->cipher->cleanup(c);
86
- }
87
- OPENSSL_free(c->cipher_data);
88
-
89
- OPENSSL_memset(c, 0, sizeof(EVP_CIPHER_CTX));
90
- return 1;
91
- }
92
-
93
- void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) {
94
- if (ctx) {
95
- EVP_CIPHER_CTX_cleanup(ctx);
96
- OPENSSL_free(ctx);
97
- }
98
- }
99
-
100
- int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) {
101
- if (in == NULL || in->cipher == NULL) {
102
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INPUT_NOT_INITIALIZED);
103
- return 0;
104
- }
105
-
106
- EVP_CIPHER_CTX_cleanup(out);
107
- OPENSSL_memcpy(out, in, sizeof(EVP_CIPHER_CTX));
108
-
109
- if (in->cipher_data && in->cipher->ctx_size) {
110
- out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
111
- if (!out->cipher_data) {
112
- out->cipher = NULL;
113
- OPENSSL_PUT_ERROR(CIPHER, ERR_R_MALLOC_FAILURE);
114
- return 0;
115
- }
116
- OPENSSL_memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
117
- }
118
-
119
- if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) {
120
- if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out)) {
121
- out->cipher = NULL;
122
- return 0;
123
- }
124
- }
125
-
126
- return 1;
127
- }
128
-
129
- int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) {
130
- EVP_CIPHER_CTX_cleanup(ctx);
131
- EVP_CIPHER_CTX_init(ctx);
132
- return 1;
133
- }
134
-
135
- int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
136
- ENGINE *engine, const uint8_t *key, const uint8_t *iv,
137
- int enc) {
138
- if (enc == -1) {
139
- enc = ctx->encrypt;
140
- } else {
141
- if (enc) {
142
- enc = 1;
143
- }
144
- ctx->encrypt = enc;
145
- }
146
-
147
- if (cipher) {
148
- // Ensure a context left from last time is cleared (the previous check
149
- // attempted to avoid this if the same ENGINE and EVP_CIPHER could be
150
- // used).
151
- if (ctx->cipher) {
152
- EVP_CIPHER_CTX_cleanup(ctx);
153
- // Restore encrypt and flags
154
- ctx->encrypt = enc;
155
- }
156
-
157
- ctx->cipher = cipher;
158
- if (ctx->cipher->ctx_size) {
159
- ctx->cipher_data = OPENSSL_malloc(ctx->cipher->ctx_size);
160
- if (!ctx->cipher_data) {
161
- ctx->cipher = NULL;
162
- OPENSSL_PUT_ERROR(CIPHER, ERR_R_MALLOC_FAILURE);
163
- return 0;
164
- }
165
- } else {
166
- ctx->cipher_data = NULL;
167
- }
168
-
169
- ctx->key_len = cipher->key_len;
170
- ctx->flags = 0;
171
-
172
- if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
173
- if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {
174
- ctx->cipher = NULL;
175
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INITIALIZATION_ERROR);
176
- return 0;
177
- }
178
- }
179
- } else if (!ctx->cipher) {
180
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_NO_CIPHER_SET);
181
- return 0;
182
- }
183
-
184
- // we assume block size is a power of 2 in *cryptUpdate
185
- assert(ctx->cipher->block_size == 1 || ctx->cipher->block_size == 8 ||
186
- ctx->cipher->block_size == 16);
187
-
188
- if (!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
189
- switch (EVP_CIPHER_CTX_mode(ctx)) {
190
- case EVP_CIPH_STREAM_CIPHER:
191
- case EVP_CIPH_ECB_MODE:
192
- break;
193
-
194
- case EVP_CIPH_CFB_MODE:
195
- ctx->num = 0;
196
- OPENSSL_FALLTHROUGH;
197
-
198
- case EVP_CIPH_CBC_MODE:
199
- assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof(ctx->iv));
200
- if (iv) {
201
- OPENSSL_memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
202
- }
203
- OPENSSL_memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
204
- break;
205
-
206
- case EVP_CIPH_CTR_MODE:
207
- case EVP_CIPH_OFB_MODE:
208
- ctx->num = 0;
209
- // Don't reuse IV for CTR mode
210
- if (iv) {
211
- OPENSSL_memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx));
212
- }
213
- break;
214
-
215
- default:
216
- return 0;
217
- }
218
- }
219
-
220
- if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
221
- if (!ctx->cipher->init(ctx, key, iv, enc)) {
222
- return 0;
223
- }
224
- }
225
-
226
- ctx->buf_len = 0;
227
- ctx->final_used = 0;
228
- return 1;
229
- }
230
-
231
- int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
232
- ENGINE *impl, const uint8_t *key, const uint8_t *iv) {
233
- return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
234
- }
235
-
236
- int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
237
- ENGINE *impl, const uint8_t *key, const uint8_t *iv) {
238
- return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
239
- }
240
-
241
- // block_remainder returns the number of bytes to remove from |len| to get a
242
- // multiple of |ctx|'s block size.
243
- static int block_remainder(const EVP_CIPHER_CTX *ctx, int len) {
244
- // |block_size| must be a power of two.
245
- assert(ctx->cipher->block_size != 0);
246
- assert((ctx->cipher->block_size & (ctx->cipher->block_size - 1)) == 0);
247
- return len & (ctx->cipher->block_size - 1);
248
- }
249
-
250
- int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len,
251
- const uint8_t *in, int in_len) {
252
- // Ciphers that use blocks may write up to |bl| extra bytes. Ensure the output
253
- // does not overflow |*out_len|.
254
- int bl = ctx->cipher->block_size;
255
- if (bl > 1 && in_len > INT_MAX - bl) {
256
- OPENSSL_PUT_ERROR(CIPHER, ERR_R_OVERFLOW);
257
- return 0;
258
- }
259
-
260
- if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
261
- int ret = ctx->cipher->cipher(ctx, out, in, in_len);
262
- if (ret < 0) {
263
- return 0;
264
- } else {
265
- *out_len = ret;
266
- }
267
- return 1;
268
- }
269
-
270
- if (in_len <= 0) {
271
- *out_len = 0;
272
- return in_len == 0;
273
- }
274
-
275
- if (ctx->buf_len == 0 && block_remainder(ctx, in_len) == 0) {
276
- if (ctx->cipher->cipher(ctx, out, in, in_len)) {
277
- *out_len = in_len;
278
- return 1;
279
- } else {
280
- *out_len = 0;
281
- return 0;
282
- }
283
- }
284
-
285
- int i = ctx->buf_len;
286
- assert(bl <= (int)sizeof(ctx->buf));
287
- if (i != 0) {
288
- if (bl - i > in_len) {
289
- OPENSSL_memcpy(&ctx->buf[i], in, in_len);
290
- ctx->buf_len += in_len;
291
- *out_len = 0;
292
- return 1;
293
- } else {
294
- int j = bl - i;
295
- OPENSSL_memcpy(&ctx->buf[i], in, j);
296
- if (!ctx->cipher->cipher(ctx, out, ctx->buf, bl)) {
297
- return 0;
298
- }
299
- in_len -= j;
300
- in += j;
301
- out += bl;
302
- *out_len = bl;
303
- }
304
- } else {
305
- *out_len = 0;
306
- }
307
-
308
- i = block_remainder(ctx, in_len);
309
- in_len -= i;
310
- if (in_len > 0) {
311
- if (!ctx->cipher->cipher(ctx, out, in, in_len)) {
312
- return 0;
313
- }
314
- *out_len += in_len;
315
- }
316
-
317
- if (i != 0) {
318
- OPENSSL_memcpy(ctx->buf, &in[in_len], i);
319
- }
320
- ctx->buf_len = i;
321
- return 1;
322
- }
323
-
324
- int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
325
- int n, ret;
326
- unsigned int i, b, bl;
327
-
328
- if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
329
- ret = ctx->cipher->cipher(ctx, out, NULL, 0);
330
- if (ret < 0) {
331
- return 0;
332
- } else {
333
- *out_len = ret;
334
- }
335
- return 1;
336
- }
337
-
338
- b = ctx->cipher->block_size;
339
- assert(b <= sizeof(ctx->buf));
340
- if (b == 1) {
341
- *out_len = 0;
342
- return 1;
343
- }
344
-
345
- bl = ctx->buf_len;
346
- if (ctx->flags & EVP_CIPH_NO_PADDING) {
347
- if (bl) {
348
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
349
- return 0;
350
- }
351
- *out_len = 0;
352
- return 1;
353
- }
354
-
355
- n = b - bl;
356
- for (i = bl; i < b; i++) {
357
- ctx->buf[i] = n;
358
- }
359
- ret = ctx->cipher->cipher(ctx, out, ctx->buf, b);
360
-
361
- if (ret) {
362
- *out_len = b;
363
- }
364
-
365
- return ret;
366
- }
367
-
368
- int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len,
369
- const uint8_t *in, int in_len) {
370
- // Ciphers that use blocks may write up to |bl| extra bytes. Ensure the output
371
- // does not overflow |*out_len|.
372
- unsigned int b = ctx->cipher->block_size;
373
- if (b > 1 && in_len > INT_MAX - (int)b) {
374
- OPENSSL_PUT_ERROR(CIPHER, ERR_R_OVERFLOW);
375
- return 0;
376
- }
377
-
378
- if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
379
- int r = ctx->cipher->cipher(ctx, out, in, in_len);
380
- if (r < 0) {
381
- *out_len = 0;
382
- return 0;
383
- } else {
384
- *out_len = r;
385
- }
386
- return 1;
387
- }
388
-
389
- if (in_len <= 0) {
390
- *out_len = 0;
391
- return in_len == 0;
392
- }
393
-
394
- if (ctx->flags & EVP_CIPH_NO_PADDING) {
395
- return EVP_EncryptUpdate(ctx, out, out_len, in, in_len);
396
- }
397
-
398
- assert(b <= sizeof(ctx->final));
399
- int fix_len = 0;
400
- if (ctx->final_used) {
401
- OPENSSL_memcpy(out, ctx->final, b);
402
- out += b;
403
- fix_len = 1;
404
- }
405
-
406
- if (!EVP_EncryptUpdate(ctx, out, out_len, in, in_len)) {
407
- return 0;
408
- }
409
-
410
- // if we have 'decrypted' a multiple of block size, make sure
411
- // we have a copy of this last block
412
- if (b > 1 && !ctx->buf_len) {
413
- *out_len -= b;
414
- ctx->final_used = 1;
415
- OPENSSL_memcpy(ctx->final, &out[*out_len], b);
416
- } else {
417
- ctx->final_used = 0;
418
- }
419
-
420
- if (fix_len) {
421
- *out_len += b;
422
- }
423
-
424
- return 1;
425
- }
426
-
427
- int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *out_len) {
428
- int i, n;
429
- unsigned int b;
430
- *out_len = 0;
431
-
432
- if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
433
- i = ctx->cipher->cipher(ctx, out, NULL, 0);
434
- if (i < 0) {
435
- return 0;
436
- } else {
437
- *out_len = i;
438
- }
439
- return 1;
440
- }
441
-
442
- b = ctx->cipher->block_size;
443
- if (ctx->flags & EVP_CIPH_NO_PADDING) {
444
- if (ctx->buf_len) {
445
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
446
- return 0;
447
- }
448
- *out_len = 0;
449
- return 1;
450
- }
451
-
452
- if (b > 1) {
453
- if (ctx->buf_len || !ctx->final_used) {
454
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_WRONG_FINAL_BLOCK_LENGTH);
455
- return 0;
456
- }
457
- assert(b <= sizeof(ctx->final));
458
-
459
- // The following assumes that the ciphertext has been authenticated.
460
- // Otherwise it provides a padding oracle.
461
- n = ctx->final[b - 1];
462
- if (n == 0 || n > (int)b) {
463
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
464
- return 0;
465
- }
466
-
467
- for (i = 0; i < n; i++) {
468
- if (ctx->final[--b] != n) {
469
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
470
- return 0;
471
- }
472
- }
473
-
474
- n = ctx->cipher->block_size - n;
475
- for (i = 0; i < n; i++) {
476
- out[i] = ctx->final[i];
477
- }
478
- *out_len = n;
479
- } else {
480
- *out_len = 0;
481
- }
482
-
483
- return 1;
484
- }
485
-
486
- int EVP_Cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
487
- size_t in_len) {
488
- return ctx->cipher->cipher(ctx, out, in, in_len);
489
- }
490
-
491
- int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len,
492
- const uint8_t *in, int in_len) {
493
- if (ctx->encrypt) {
494
- return EVP_EncryptUpdate(ctx, out, out_len, in, in_len);
495
- } else {
496
- return EVP_DecryptUpdate(ctx, out, out_len, in, in_len);
497
- }
498
- }
499
-
500
- int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
501
- if (ctx->encrypt) {
502
- return EVP_EncryptFinal_ex(ctx, out, out_len);
503
- } else {
504
- return EVP_DecryptFinal_ex(ctx, out, out_len);
505
- }
506
- }
507
-
508
- const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) {
509
- return ctx->cipher;
510
- }
511
-
512
- int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) {
513
- return ctx->cipher->nid;
514
- }
515
-
516
- int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx) {
517
- return ctx->encrypt;
518
- }
519
-
520
- unsigned EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) {
521
- return ctx->cipher->block_size;
522
- }
523
-
524
- unsigned EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) {
525
- return ctx->key_len;
526
- }
527
-
528
- unsigned EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) {
529
- return ctx->cipher->iv_len;
530
- }
531
-
532
- void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx) {
533
- return ctx->app_data;
534
- }
535
-
536
- void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data) {
537
- ctx->app_data = data;
538
- }
539
-
540
- uint32_t EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) {
541
- return ctx->cipher->flags & ~EVP_CIPH_MODE_MASK;
542
- }
543
-
544
- uint32_t EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *ctx) {
545
- return ctx->cipher->flags & EVP_CIPH_MODE_MASK;
546
- }
547
-
548
- int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int command, int arg, void *ptr) {
549
- int ret;
550
- if (!ctx->cipher) {
551
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_NO_CIPHER_SET);
552
- return 0;
553
- }
554
-
555
- if (!ctx->cipher->ctrl) {
556
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_CTRL_NOT_IMPLEMENTED);
557
- return 0;
558
- }
559
-
560
- ret = ctx->cipher->ctrl(ctx, command, arg, ptr);
561
- if (ret == -1) {
562
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_CTRL_OPERATION_NOT_IMPLEMENTED);
563
- return 0;
564
- }
565
-
566
- return ret;
567
- }
568
-
569
- int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad) {
570
- if (pad) {
571
- ctx->flags &= ~EVP_CIPH_NO_PADDING;
572
- } else {
573
- ctx->flags |= EVP_CIPH_NO_PADDING;
574
- }
575
- return 1;
576
- }
577
-
578
- int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, unsigned key_len) {
579
- if (c->key_len == key_len) {
580
- return 1;
581
- }
582
-
583
- if (key_len == 0 || !(c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
584
- OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_KEY_LENGTH);
585
- return 0;
586
- }
587
-
588
- c->key_len = key_len;
589
- return 1;
590
- }
591
-
592
- int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { return cipher->nid; }
593
-
594
- unsigned EVP_CIPHER_block_size(const EVP_CIPHER *cipher) {
595
- return cipher->block_size;
596
- }
597
-
598
- unsigned EVP_CIPHER_key_length(const EVP_CIPHER *cipher) {
599
- return cipher->key_len;
600
- }
601
-
602
- unsigned EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) {
603
- return cipher->iv_len;
604
- }
605
-
606
- uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) {
607
- return cipher->flags & ~EVP_CIPH_MODE_MASK;
608
- }
609
-
610
- uint32_t EVP_CIPHER_mode(const EVP_CIPHER *cipher) {
611
- return cipher->flags & EVP_CIPH_MODE_MASK;
612
- }
613
-
614
- int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
615
- const uint8_t *key, const uint8_t *iv, int enc) {
616
- if (cipher) {
617
- EVP_CIPHER_CTX_init(ctx);
618
- }
619
- return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc);
620
- }
621
-
622
- int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
623
- const uint8_t *key, const uint8_t *iv) {
624
- return EVP_CipherInit(ctx, cipher, key, iv, 1);
625
- }
626
-
627
- int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
628
- const uint8_t *key, const uint8_t *iv) {
629
- return EVP_CipherInit(ctx, cipher, key, iv, 0);
630
- }
631
-
632
- int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
633
- return EVP_CipherFinal_ex(ctx, out, out_len);
634
- }
635
-
636
- int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
637
- return EVP_EncryptFinal_ex(ctx, out, out_len);
638
- }
639
-
640
- int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
641
- return EVP_DecryptFinal_ex(ctx, out, out_len);
642
- }
643
-
644
- int EVP_add_cipher_alias(const char *a, const char *b) {
645
- return 1;
646
- }
647
-
648
- void EVP_CIPHER_CTX_set_flags(const EVP_CIPHER_CTX *ctx, uint32_t flags) {}
1
+ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2
+ * All rights reserved.
3
+ *
4
+ * This package is an SSL implementation written
5
+ * by Eric Young (eay@cryptsoft.com).
6
+ * The implementation was written so as to conform with Netscapes SSL.
7
+ *
8
+ * This library is free for commercial and non-commercial use as long as
9
+ * the following conditions are aheared to. The following conditions
10
+ * apply to all code found in this distribution, be it the RC4, RSA,
11
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12
+ * included with this distribution is covered by the same copyright terms
13
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14
+ *
15
+ * Copyright remains Eric Young's, and as such any Copyright notices in
16
+ * the code are not to be removed.
17
+ * If this package is used in a product, Eric Young should be given attribution
18
+ * as the author of the parts of the library used.
19
+ * This can be in the form of a textual message at program startup or
20
+ * in documentation (online or textual) provided with the package.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ * 3. All advertising materials mentioning features or use of this software
31
+ * must display the following acknowledgement:
32
+ * "This product includes cryptographic software written by
33
+ * Eric Young (eay@cryptsoft.com)"
34
+ * The word 'cryptographic' can be left out if the rouines from the library
35
+ * being used are not cryptographic related :-).
36
+ * 4. If you include any Windows specific code (or a derivative thereof) from
37
+ * the apps directory (application code) you must include an acknowledgement:
38
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39
+ *
40
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
+ * SUCH DAMAGE.
51
+ *
52
+ * The licence and distribution terms for any publically available version or
53
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
54
+ * copied and put under another distribution licence
55
+ * [including the GNU Public Licence.] */
56
+
57
+ #include <openssl/cipher.h>
58
+
59
+ #include <assert.h>
60
+ #include <limits.h>
61
+ #include <string.h>
62
+
63
+ #include <openssl/err.h>
64
+ #include <openssl/mem.h>
65
+ #include <openssl/nid.h>
66
+
67
+ #include "internal.h"
68
+ #include "../service_indicator/internal.h"
69
+ #include "../../internal.h"
70
+
71
+
72
+ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) {
73
+ OPENSSL_memset(ctx, 0, sizeof(EVP_CIPHER_CTX));
74
+ }
75
+
76
+ EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) {
77
+ EVP_CIPHER_CTX *ctx = OPENSSL_malloc(sizeof(EVP_CIPHER_CTX));
78
+ if (ctx) {
79
+ EVP_CIPHER_CTX_init(ctx);
80
+ }
81
+ return ctx;
82
+ }
83
+
84
+ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) {
85
+ if (c->cipher != NULL && c->cipher->cleanup) {
86
+ c->cipher->cleanup(c);
87
+ }
88
+ OPENSSL_free(c->cipher_data);
89
+
90
+ OPENSSL_memset(c, 0, sizeof(EVP_CIPHER_CTX));
91
+ return 1;
92
+ }
93
+
94
+ void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) {
95
+ if (ctx) {
96
+ EVP_CIPHER_CTX_cleanup(ctx);
97
+ OPENSSL_free(ctx);
98
+ }
99
+ }
100
+
101
+ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) {
102
+ if (in == NULL || in->cipher == NULL) {
103
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INPUT_NOT_INITIALIZED);
104
+ return 0;
105
+ }
106
+
107
+ EVP_CIPHER_CTX_cleanup(out);
108
+ OPENSSL_memcpy(out, in, sizeof(EVP_CIPHER_CTX));
109
+
110
+ if (in->cipher_data && in->cipher->ctx_size) {
111
+ out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
112
+ if (!out->cipher_data) {
113
+ out->cipher = NULL;
114
+ OPENSSL_PUT_ERROR(CIPHER, ERR_R_MALLOC_FAILURE);
115
+ return 0;
116
+ }
117
+ OPENSSL_memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
118
+ }
119
+
120
+ if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) {
121
+ if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out)) {
122
+ out->cipher = NULL;
123
+ return 0;
124
+ }
125
+ }
126
+
127
+ return 1;
128
+ }
129
+
130
+ int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) {
131
+ EVP_CIPHER_CTX_cleanup(ctx);
132
+ EVP_CIPHER_CTX_init(ctx);
133
+ return 1;
134
+ }
135
+
136
+ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
137
+ ENGINE *engine, const uint8_t *key, const uint8_t *iv,
138
+ int enc) {
139
+ if (enc == -1) {
140
+ enc = ctx->encrypt;
141
+ } else {
142
+ if (enc) {
143
+ enc = 1;
144
+ }
145
+ ctx->encrypt = enc;
146
+ }
147
+
148
+ if (cipher) {
149
+ // Ensure a context left from last time is cleared (the previous check
150
+ // attempted to avoid this if the same ENGINE and EVP_CIPHER could be
151
+ // used).
152
+ if (ctx->cipher) {
153
+ EVP_CIPHER_CTX_cleanup(ctx);
154
+ // Restore encrypt and flags
155
+ ctx->encrypt = enc;
156
+ }
157
+
158
+ ctx->cipher = cipher;
159
+ if (ctx->cipher->ctx_size) {
160
+ ctx->cipher_data = OPENSSL_malloc(ctx->cipher->ctx_size);
161
+ if (!ctx->cipher_data) {
162
+ ctx->cipher = NULL;
163
+ OPENSSL_PUT_ERROR(CIPHER, ERR_R_MALLOC_FAILURE);
164
+ return 0;
165
+ }
166
+ } else {
167
+ ctx->cipher_data = NULL;
168
+ }
169
+
170
+ ctx->key_len = cipher->key_len;
171
+ ctx->flags = 0;
172
+
173
+ if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
174
+ if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {
175
+ ctx->cipher = NULL;
176
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INITIALIZATION_ERROR);
177
+ return 0;
178
+ }
179
+ }
180
+ } else if (!ctx->cipher) {
181
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_NO_CIPHER_SET);
182
+ return 0;
183
+ }
184
+
185
+ // we assume block size is a power of 2 in *cryptUpdate
186
+ assert(ctx->cipher->block_size == 1 || ctx->cipher->block_size == 8 ||
187
+ ctx->cipher->block_size == 16);
188
+
189
+ if (!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
190
+ switch (EVP_CIPHER_CTX_mode(ctx)) {
191
+ case EVP_CIPH_STREAM_CIPHER:
192
+ case EVP_CIPH_ECB_MODE:
193
+ break;
194
+
195
+ case EVP_CIPH_CFB_MODE:
196
+ ctx->num = 0;
197
+ OPENSSL_FALLTHROUGH;
198
+
199
+ case EVP_CIPH_CBC_MODE:
200
+ assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof(ctx->iv));
201
+ if (iv) {
202
+ OPENSSL_memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
203
+ }
204
+ OPENSSL_memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
205
+ break;
206
+
207
+ case EVP_CIPH_CTR_MODE:
208
+ case EVP_CIPH_OFB_MODE:
209
+ ctx->num = 0;
210
+ // Don't reuse IV for CTR mode
211
+ if (iv) {
212
+ OPENSSL_memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx));
213
+ }
214
+ break;
215
+
216
+ default:
217
+ return 0;
218
+ }
219
+ }
220
+
221
+ if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
222
+ if (!ctx->cipher->init(ctx, key, iv, enc)) {
223
+ return 0;
224
+ }
225
+ }
226
+
227
+ ctx->buf_len = 0;
228
+ ctx->final_used = 0;
229
+ return 1;
230
+ }
231
+
232
+ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
233
+ ENGINE *impl, const uint8_t *key, const uint8_t *iv) {
234
+ return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
235
+ }
236
+
237
+ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
238
+ ENGINE *impl, const uint8_t *key, const uint8_t *iv) {
239
+ return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
240
+ }
241
+
242
+ // block_remainder returns the number of bytes to remove from |len| to get a
243
+ // multiple of |ctx|'s block size.
244
+ static int block_remainder(const EVP_CIPHER_CTX *ctx, int len) {
245
+ // |block_size| must be a power of two.
246
+ assert(ctx->cipher->block_size != 0);
247
+ assert((ctx->cipher->block_size & (ctx->cipher->block_size - 1)) == 0);
248
+ return len & (ctx->cipher->block_size - 1);
249
+ }
250
+
251
+ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len,
252
+ const uint8_t *in, int in_len) {
253
+ // Ciphers that use blocks may write up to |bl| extra bytes. Ensure the output
254
+ // does not overflow |*out_len|.
255
+ int bl = ctx->cipher->block_size;
256
+ if (bl > 1 && in_len > INT_MAX - bl) {
257
+ OPENSSL_PUT_ERROR(CIPHER, ERR_R_OVERFLOW);
258
+ return 0;
259
+ }
260
+
261
+ if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
262
+ int ret = ctx->cipher->cipher(ctx, out, in, in_len);
263
+ if (ret < 0) {
264
+ return 0;
265
+ } else {
266
+ *out_len = ret;
267
+ }
268
+ return 1;
269
+ }
270
+
271
+ if (in_len <= 0) {
272
+ *out_len = 0;
273
+ return in_len == 0;
274
+ }
275
+
276
+ if (ctx->buf_len == 0 && block_remainder(ctx, in_len) == 0) {
277
+ if (ctx->cipher->cipher(ctx, out, in, in_len)) {
278
+ *out_len = in_len;
279
+ return 1;
280
+ } else {
281
+ *out_len = 0;
282
+ return 0;
283
+ }
284
+ }
285
+
286
+ int i = ctx->buf_len;
287
+ assert(bl <= (int)sizeof(ctx->buf));
288
+ if (i != 0) {
289
+ if (bl - i > in_len) {
290
+ OPENSSL_memcpy(&ctx->buf[i], in, in_len);
291
+ ctx->buf_len += in_len;
292
+ *out_len = 0;
293
+ return 1;
294
+ } else {
295
+ int j = bl - i;
296
+ OPENSSL_memcpy(&ctx->buf[i], in, j);
297
+ if (!ctx->cipher->cipher(ctx, out, ctx->buf, bl)) {
298
+ return 0;
299
+ }
300
+ in_len -= j;
301
+ in += j;
302
+ out += bl;
303
+ *out_len = bl;
304
+ }
305
+ } else {
306
+ *out_len = 0;
307
+ }
308
+
309
+ i = block_remainder(ctx, in_len);
310
+ in_len -= i;
311
+ if (in_len > 0) {
312
+ if (!ctx->cipher->cipher(ctx, out, in, in_len)) {
313
+ return 0;
314
+ }
315
+ *out_len += in_len;
316
+ }
317
+
318
+ if (i != 0) {
319
+ OPENSSL_memcpy(ctx->buf, &in[in_len], i);
320
+ }
321
+ ctx->buf_len = i;
322
+ return 1;
323
+ }
324
+
325
+ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
326
+ int n;
327
+ unsigned int i, b, bl;
328
+
329
+ if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
330
+ // When EVP_CIPH_FLAG_CUSTOM_CIPHER is set, the return value of |cipher| is
331
+ // the number of bytes written, or -1 on error. Otherwise the return value
332
+ // is one on success and zero on error.
333
+ const int num_bytes = ctx->cipher->cipher(ctx, out, NULL, 0);
334
+ if (num_bytes < 0) {
335
+ return 0;
336
+ }
337
+ *out_len = num_bytes;
338
+ goto out;
339
+ }
340
+
341
+ b = ctx->cipher->block_size;
342
+ assert(b <= sizeof(ctx->buf));
343
+ if (b == 1) {
344
+ *out_len = 0;
345
+ goto out;
346
+ }
347
+
348
+ bl = ctx->buf_len;
349
+ if (ctx->flags & EVP_CIPH_NO_PADDING) {
350
+ if (bl) {
351
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
352
+ return 0;
353
+ }
354
+ *out_len = 0;
355
+ goto out;
356
+ }
357
+
358
+ n = b - bl;
359
+ for (i = bl; i < b; i++) {
360
+ ctx->buf[i] = n;
361
+ }
362
+ if (!ctx->cipher->cipher(ctx, out, ctx->buf, b)) {
363
+ return 0;
364
+ }
365
+ *out_len = b;
366
+
367
+ out:
368
+ EVP_Cipher_verify_service_indicator(ctx);
369
+ return 1;
370
+ }
371
+
372
+ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len,
373
+ const uint8_t *in, int in_len) {
374
+ // Ciphers that use blocks may write up to |bl| extra bytes. Ensure the output
375
+ // does not overflow |*out_len|.
376
+ unsigned int b = ctx->cipher->block_size;
377
+ if (b > 1 && in_len > INT_MAX - (int)b) {
378
+ OPENSSL_PUT_ERROR(CIPHER, ERR_R_OVERFLOW);
379
+ return 0;
380
+ }
381
+
382
+ if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
383
+ int r = ctx->cipher->cipher(ctx, out, in, in_len);
384
+ if (r < 0) {
385
+ *out_len = 0;
386
+ return 0;
387
+ } else {
388
+ *out_len = r;
389
+ }
390
+ return 1;
391
+ }
392
+
393
+ if (in_len <= 0) {
394
+ *out_len = 0;
395
+ return in_len == 0;
396
+ }
397
+
398
+ if (ctx->flags & EVP_CIPH_NO_PADDING) {
399
+ return EVP_EncryptUpdate(ctx, out, out_len, in, in_len);
400
+ }
401
+
402
+ assert(b <= sizeof(ctx->final));
403
+ int fix_len = 0;
404
+ if (ctx->final_used) {
405
+ OPENSSL_memcpy(out, ctx->final, b);
406
+ out += b;
407
+ fix_len = 1;
408
+ }
409
+
410
+ if (!EVP_EncryptUpdate(ctx, out, out_len, in, in_len)) {
411
+ return 0;
412
+ }
413
+
414
+ // if we have 'decrypted' a multiple of block size, make sure
415
+ // we have a copy of this last block
416
+ if (b > 1 && !ctx->buf_len) {
417
+ *out_len -= b;
418
+ ctx->final_used = 1;
419
+ OPENSSL_memcpy(ctx->final, &out[*out_len], b);
420
+ } else {
421
+ ctx->final_used = 0;
422
+ }
423
+
424
+ if (fix_len) {
425
+ *out_len += b;
426
+ }
427
+
428
+ return 1;
429
+ }
430
+
431
+ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *out_len) {
432
+ int i, n;
433
+ unsigned int b;
434
+ *out_len = 0;
435
+
436
+ if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
437
+ i = ctx->cipher->cipher(ctx, out, NULL, 0);
438
+ if (i < 0) {
439
+ return 0;
440
+ } else {
441
+ *out_len = i;
442
+ }
443
+ goto out;
444
+ }
445
+
446
+ b = ctx->cipher->block_size;
447
+ if (ctx->flags & EVP_CIPH_NO_PADDING) {
448
+ if (ctx->buf_len) {
449
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
450
+ return 0;
451
+ }
452
+ *out_len = 0;
453
+ goto out;
454
+ }
455
+
456
+ if (b > 1) {
457
+ if (ctx->buf_len || !ctx->final_used) {
458
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_WRONG_FINAL_BLOCK_LENGTH);
459
+ return 0;
460
+ }
461
+ assert(b <= sizeof(ctx->final));
462
+
463
+ // The following assumes that the ciphertext has been authenticated.
464
+ // Otherwise it provides a padding oracle.
465
+ n = ctx->final[b - 1];
466
+ if (n == 0 || n > (int)b) {
467
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
468
+ return 0;
469
+ }
470
+
471
+ for (i = 0; i < n; i++) {
472
+ if (ctx->final[--b] != n) {
473
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
474
+ return 0;
475
+ }
476
+ }
477
+
478
+ n = ctx->cipher->block_size - n;
479
+ for (i = 0; i < n; i++) {
480
+ out[i] = ctx->final[i];
481
+ }
482
+ *out_len = n;
483
+ } else {
484
+ *out_len = 0;
485
+ }
486
+
487
+ out:
488
+ EVP_Cipher_verify_service_indicator(ctx);
489
+ return 1;
490
+ }
491
+
492
+ int EVP_Cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
493
+ size_t in_len) {
494
+ const int ret = ctx->cipher->cipher(ctx, out, in, in_len);
495
+
496
+ // |EVP_CIPH_FLAG_CUSTOM_CIPHER| never sets the FIPS indicator via
497
+ // |EVP_Cipher| because it's complicated whether the operation has completed
498
+ // or not. E.g. AES-GCM with a non-NULL |in| argument hasn't completed an
499
+ // operation. Callers should use the |EVP_AEAD| API or, at least,
500
+ // |EVP_CipherUpdate| etc.
501
+ //
502
+ // This call can't be pushed into |EVP_Cipher_verify_service_indicator|
503
+ // because whether |ret| indicates success or not depends on whether
504
+ // |EVP_CIPH_FLAG_CUSTOM_CIPHER| is set. (This unreasonable, but matches
505
+ // OpenSSL.)
506
+ if (!(ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) && ret) {
507
+ EVP_Cipher_verify_service_indicator(ctx);
508
+ }
509
+
510
+ return ret;
511
+ }
512
+
513
+ int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len,
514
+ const uint8_t *in, int in_len) {
515
+ if (ctx->encrypt) {
516
+ return EVP_EncryptUpdate(ctx, out, out_len, in, in_len);
517
+ } else {
518
+ return EVP_DecryptUpdate(ctx, out, out_len, in, in_len);
519
+ }
520
+ }
521
+
522
+ int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
523
+ if (ctx->encrypt) {
524
+ return EVP_EncryptFinal_ex(ctx, out, out_len);
525
+ } else {
526
+ return EVP_DecryptFinal_ex(ctx, out, out_len);
527
+ }
528
+ }
529
+
530
+ const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) {
531
+ return ctx->cipher;
532
+ }
533
+
534
+ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) {
535
+ return ctx->cipher->nid;
536
+ }
537
+
538
+ int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx) {
539
+ return ctx->encrypt;
540
+ }
541
+
542
+ unsigned EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) {
543
+ return ctx->cipher->block_size;
544
+ }
545
+
546
+ unsigned EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) {
547
+ return ctx->key_len;
548
+ }
549
+
550
+ unsigned EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) {
551
+ return ctx->cipher->iv_len;
552
+ }
553
+
554
+ void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx) {
555
+ return ctx->app_data;
556
+ }
557
+
558
+ void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data) {
559
+ ctx->app_data = data;
560
+ }
561
+
562
+ uint32_t EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) {
563
+ return ctx->cipher->flags & ~EVP_CIPH_MODE_MASK;
564
+ }
565
+
566
+ uint32_t EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *ctx) {
567
+ return ctx->cipher->flags & EVP_CIPH_MODE_MASK;
568
+ }
569
+
570
+ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int command, int arg, void *ptr) {
571
+ int ret;
572
+ if (!ctx->cipher) {
573
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_NO_CIPHER_SET);
574
+ return 0;
575
+ }
576
+
577
+ if (!ctx->cipher->ctrl) {
578
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_CTRL_NOT_IMPLEMENTED);
579
+ return 0;
580
+ }
581
+
582
+ ret = ctx->cipher->ctrl(ctx, command, arg, ptr);
583
+ if (ret == -1) {
584
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_CTRL_OPERATION_NOT_IMPLEMENTED);
585
+ return 0;
586
+ }
587
+
588
+ return ret;
589
+ }
590
+
591
+ int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad) {
592
+ if (pad) {
593
+ ctx->flags &= ~EVP_CIPH_NO_PADDING;
594
+ } else {
595
+ ctx->flags |= EVP_CIPH_NO_PADDING;
596
+ }
597
+ return 1;
598
+ }
599
+
600
+ int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, unsigned key_len) {
601
+ if (c->key_len == key_len) {
602
+ return 1;
603
+ }
604
+
605
+ if (key_len == 0 || !(c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
606
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_KEY_LENGTH);
607
+ return 0;
608
+ }
609
+
610
+ c->key_len = key_len;
611
+ return 1;
612
+ }
613
+
614
+ int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { return cipher->nid; }
615
+
616
+ unsigned EVP_CIPHER_block_size(const EVP_CIPHER *cipher) {
617
+ return cipher->block_size;
618
+ }
619
+
620
+ unsigned EVP_CIPHER_key_length(const EVP_CIPHER *cipher) {
621
+ return cipher->key_len;
622
+ }
623
+
624
+ unsigned EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) {
625
+ return cipher->iv_len;
626
+ }
627
+
628
+ uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) {
629
+ return cipher->flags & ~EVP_CIPH_MODE_MASK;
630
+ }
631
+
632
+ uint32_t EVP_CIPHER_mode(const EVP_CIPHER *cipher) {
633
+ return cipher->flags & EVP_CIPH_MODE_MASK;
634
+ }
635
+
636
+ int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
637
+ const uint8_t *key, const uint8_t *iv, int enc) {
638
+ if (cipher) {
639
+ EVP_CIPHER_CTX_init(ctx);
640
+ }
641
+ return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, enc);
642
+ }
643
+
644
+ int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
645
+ const uint8_t *key, const uint8_t *iv) {
646
+ return EVP_CipherInit(ctx, cipher, key, iv, 1);
647
+ }
648
+
649
+ int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
650
+ const uint8_t *key, const uint8_t *iv) {
651
+ return EVP_CipherInit(ctx, cipher, key, iv, 0);
652
+ }
653
+
654
+ int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
655
+ return EVP_CipherFinal_ex(ctx, out, out_len);
656
+ }
657
+
658
+ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
659
+ return EVP_EncryptFinal_ex(ctx, out, out_len);
660
+ }
661
+
662
+ int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, uint8_t *out, int *out_len) {
663
+ return EVP_DecryptFinal_ex(ctx, out, out_len);
664
+ }
665
+
666
+ int EVP_add_cipher_alias(const char *a, const char *b) {
667
+ return 1;
668
+ }
669
+
670
+ void EVP_CIPHER_CTX_set_flags(const EVP_CIPHER_CTX *ctx, uint32_t flags) {}