@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,695 +1,702 @@
1
- /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
2
- * project 2005.
3
- */
4
- /* ====================================================================
5
- * Copyright (c) 2005 The OpenSSL Project. All rights reserved.
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions
9
- * are met:
10
- *
11
- * 1. Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- *
14
- * 2. Redistributions in binary form must reproduce the above copyright
15
- * notice, this list of conditions and the following disclaimer in
16
- * the documentation and/or other materials provided with the
17
- * distribution.
18
- *
19
- * 3. All advertising materials mentioning features or use of this
20
- * software must display the following acknowledgment:
21
- * "This product includes software developed by the OpenSSL Project
22
- * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23
- *
24
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25
- * endorse or promote products derived from this software without
26
- * prior written permission. For written permission, please contact
27
- * licensing@OpenSSL.org.
28
- *
29
- * 5. Products derived from this software may not be called "OpenSSL"
30
- * nor may "OpenSSL" appear in their names without prior written
31
- * permission of the OpenSSL Project.
32
- *
33
- * 6. Redistributions of any form whatsoever must retain the following
34
- * acknowledgment:
35
- * "This product includes software developed by the OpenSSL Project
36
- * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37
- *
38
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49
- * OF THE POSSIBILITY OF SUCH DAMAGE.
50
- * ====================================================================
51
- *
52
- * This product includes cryptographic software written by Eric Young
53
- * (eay@cryptsoft.com). This product includes software written by Tim
54
- * Hudson (tjh@cryptsoft.com). */
55
-
56
- #include <openssl/rsa.h>
57
-
58
- #include <assert.h>
59
- #include <limits.h>
60
- #include <string.h>
61
-
62
- #include <openssl/bn.h>
63
- #include <openssl/digest.h>
64
- #include <openssl/err.h>
65
- #include <openssl/mem.h>
66
- #include <openssl/rand.h>
67
- #include <openssl/sha.h>
68
-
69
- #include "internal.h"
70
- #include "../../internal.h"
71
-
72
-
73
- #define RSA_PKCS1_PADDING_SIZE 11
74
-
75
- int RSA_padding_add_PKCS1_type_1(uint8_t *to, size_t to_len,
76
- const uint8_t *from, size_t from_len) {
77
- // See RFC 8017, section 9.2.
78
- if (to_len < RSA_PKCS1_PADDING_SIZE) {
79
- OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
80
- return 0;
81
- }
82
-
83
- if (from_len > to_len - RSA_PKCS1_PADDING_SIZE) {
84
- OPENSSL_PUT_ERROR(RSA, RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
85
- return 0;
86
- }
87
-
88
- to[0] = 0;
89
- to[1] = 1;
90
- OPENSSL_memset(to + 2, 0xff, to_len - 3 - from_len);
91
- to[to_len - from_len - 1] = 0;
92
- OPENSSL_memcpy(to + to_len - from_len, from, from_len);
93
- return 1;
94
- }
95
-
96
- int RSA_padding_check_PKCS1_type_1(uint8_t *out, size_t *out_len,
97
- size_t max_out, const uint8_t *from,
98
- size_t from_len) {
99
- // See RFC 8017, section 9.2. This is part of signature verification and thus
100
- // does not need to run in constant-time.
101
- if (from_len < 2) {
102
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_SMALL);
103
- return 0;
104
- }
105
-
106
- // Check the header.
107
- if (from[0] != 0 || from[1] != 1) {
108
- OPENSSL_PUT_ERROR(RSA, RSA_R_BLOCK_TYPE_IS_NOT_01);
109
- return 0;
110
- }
111
-
112
- // Scan over padded data, looking for the 00.
113
- size_t pad;
114
- for (pad = 2 /* header */; pad < from_len; pad++) {
115
- if (from[pad] == 0x00) {
116
- break;
117
- }
118
-
119
- if (from[pad] != 0xff) {
120
- OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_FIXED_HEADER_DECRYPT);
121
- return 0;
122
- }
123
- }
124
-
125
- if (pad == from_len) {
126
- OPENSSL_PUT_ERROR(RSA, RSA_R_NULL_BEFORE_BLOCK_MISSING);
127
- return 0;
128
- }
129
-
130
- if (pad < 2 /* header */ + 8) {
131
- OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_PAD_BYTE_COUNT);
132
- return 0;
133
- }
134
-
135
- // Skip over the 00.
136
- pad++;
137
-
138
- if (from_len - pad > max_out) {
139
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE);
140
- return 0;
141
- }
142
-
143
- OPENSSL_memcpy(out, from + pad, from_len - pad);
144
- *out_len = from_len - pad;
145
- return 1;
146
- }
147
-
148
- static int rand_nonzero(uint8_t *out, size_t len) {
149
- if (!RAND_bytes(out, len)) {
150
- return 0;
151
- }
152
-
153
- for (size_t i = 0; i < len; i++) {
154
- while (out[i] == 0) {
155
- if (!RAND_bytes(out + i, 1)) {
156
- return 0;
157
- }
158
- }
159
- }
160
-
161
- return 1;
162
- }
163
-
164
- int RSA_padding_add_PKCS1_type_2(uint8_t *to, size_t to_len,
165
- const uint8_t *from, size_t from_len) {
166
- // See RFC 8017, section 7.2.1.
167
- if (to_len < RSA_PKCS1_PADDING_SIZE) {
168
- OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
169
- return 0;
170
- }
171
-
172
- if (from_len > to_len - RSA_PKCS1_PADDING_SIZE) {
173
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
174
- return 0;
175
- }
176
-
177
- to[0] = 0;
178
- to[1] = 2;
179
-
180
- size_t padding_len = to_len - 3 - from_len;
181
- if (!rand_nonzero(to + 2, padding_len)) {
182
- return 0;
183
- }
184
-
185
- to[2 + padding_len] = 0;
186
- OPENSSL_memcpy(to + to_len - from_len, from, from_len);
187
- return 1;
188
- }
189
-
190
- int RSA_padding_check_PKCS1_type_2(uint8_t *out, size_t *out_len,
191
- size_t max_out, const uint8_t *from,
192
- size_t from_len) {
193
- if (from_len == 0) {
194
- OPENSSL_PUT_ERROR(RSA, RSA_R_EMPTY_PUBLIC_KEY);
195
- return 0;
196
- }
197
-
198
- // PKCS#1 v1.5 decryption. See "PKCS #1 v2.2: RSA Cryptography
199
- // Standard", section 7.2.2.
200
- if (from_len < RSA_PKCS1_PADDING_SIZE) {
201
- // |from| is zero-padded to the size of the RSA modulus, a public value, so
202
- // this can be rejected in non-constant time.
203
- OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
204
- return 0;
205
- }
206
-
207
- crypto_word_t first_byte_is_zero = constant_time_eq_w(from[0], 0);
208
- crypto_word_t second_byte_is_two = constant_time_eq_w(from[1], 2);
209
-
210
- crypto_word_t zero_index = 0, looking_for_index = CONSTTIME_TRUE_W;
211
- for (size_t i = 2; i < from_len; i++) {
212
- crypto_word_t equals0 = constant_time_is_zero_w(from[i]);
213
- zero_index =
214
- constant_time_select_w(looking_for_index & equals0, i, zero_index);
215
- looking_for_index = constant_time_select_w(equals0, 0, looking_for_index);
216
- }
217
-
218
- // The input must begin with 00 02.
219
- crypto_word_t valid_index = first_byte_is_zero;
220
- valid_index &= second_byte_is_two;
221
-
222
- // We must have found the end of PS.
223
- valid_index &= ~looking_for_index;
224
-
225
- // PS must be at least 8 bytes long, and it starts two bytes into |from|.
226
- valid_index &= constant_time_ge_w(zero_index, 2 + 8);
227
-
228
- // Skip the zero byte.
229
- zero_index++;
230
-
231
- // NOTE: Although this logic attempts to be constant time, the API contracts
232
- // of this function and |RSA_decrypt| with |RSA_PKCS1_PADDING| make it
233
- // impossible to completely avoid Bleichenbacher's attack. Consumers should
234
- // use |RSA_PADDING_NONE| and perform the padding check in constant-time
235
- // combined with a swap to a random session key or other mitigation.
236
- CONSTTIME_DECLASSIFY(&valid_index, sizeof(valid_index));
237
- CONSTTIME_DECLASSIFY(&zero_index, sizeof(zero_index));
238
-
239
- if (!valid_index) {
240
- OPENSSL_PUT_ERROR(RSA, RSA_R_PKCS_DECODING_ERROR);
241
- return 0;
242
- }
243
-
244
- const size_t msg_len = from_len - zero_index;
245
- if (msg_len > max_out) {
246
- // This shouldn't happen because this function is always called with
247
- // |max_out| as the key size and |from_len| is bounded by the key size.
248
- OPENSSL_PUT_ERROR(RSA, RSA_R_PKCS_DECODING_ERROR);
249
- return 0;
250
- }
251
-
252
- OPENSSL_memcpy(out, &from[zero_index], msg_len);
253
- *out_len = msg_len;
254
- return 1;
255
- }
256
-
257
- int RSA_padding_add_none(uint8_t *to, size_t to_len, const uint8_t *from,
258
- size_t from_len) {
259
- if (from_len > to_len) {
260
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
261
- return 0;
262
- }
263
-
264
- if (from_len < to_len) {
265
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_SMALL);
266
- return 0;
267
- }
268
-
269
- OPENSSL_memcpy(to, from, from_len);
270
- return 1;
271
- }
272
-
273
- static int PKCS1_MGF1(uint8_t *out, size_t len, const uint8_t *seed,
274
- size_t seed_len, const EVP_MD *md) {
275
- int ret = 0;
276
- EVP_MD_CTX ctx;
277
- EVP_MD_CTX_init(&ctx);
278
-
279
- size_t md_len = EVP_MD_size(md);
280
-
281
- for (uint32_t i = 0; len > 0; i++) {
282
- uint8_t counter[4];
283
- counter[0] = (uint8_t)(i >> 24);
284
- counter[1] = (uint8_t)(i >> 16);
285
- counter[2] = (uint8_t)(i >> 8);
286
- counter[3] = (uint8_t)i;
287
- if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
288
- !EVP_DigestUpdate(&ctx, seed, seed_len) ||
289
- !EVP_DigestUpdate(&ctx, counter, sizeof(counter))) {
290
- goto err;
291
- }
292
-
293
- if (md_len <= len) {
294
- if (!EVP_DigestFinal_ex(&ctx, out, NULL)) {
295
- goto err;
296
- }
297
- out += md_len;
298
- len -= md_len;
299
- } else {
300
- uint8_t digest[EVP_MAX_MD_SIZE];
301
- if (!EVP_DigestFinal_ex(&ctx, digest, NULL)) {
302
- goto err;
303
- }
304
- OPENSSL_memcpy(out, digest, len);
305
- len = 0;
306
- }
307
- }
308
-
309
- ret = 1;
310
-
311
- err:
312
- EVP_MD_CTX_cleanup(&ctx);
313
- return ret;
314
- }
315
-
316
- int RSA_padding_add_PKCS1_OAEP_mgf1(uint8_t *to, size_t to_len,
317
- const uint8_t *from, size_t from_len,
318
- const uint8_t *param, size_t param_len,
319
- const EVP_MD *md, const EVP_MD *mgf1md) {
320
- if (md == NULL) {
321
- md = EVP_sha1();
322
- }
323
- if (mgf1md == NULL) {
324
- mgf1md = md;
325
- }
326
-
327
- size_t mdlen = EVP_MD_size(md);
328
-
329
- if (to_len < 2 * mdlen + 2) {
330
- OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
331
- return 0;
332
- }
333
-
334
- size_t emlen = to_len - 1;
335
- if (from_len > emlen - 2 * mdlen - 1) {
336
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
337
- return 0;
338
- }
339
-
340
- if (emlen < 2 * mdlen + 1) {
341
- OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
342
- return 0;
343
- }
344
-
345
- to[0] = 0;
346
- uint8_t *seed = to + 1;
347
- uint8_t *db = to + mdlen + 1;
348
-
349
- if (!EVP_Digest(param, param_len, db, NULL, md, NULL)) {
350
- return 0;
351
- }
352
- OPENSSL_memset(db + mdlen, 0, emlen - from_len - 2 * mdlen - 1);
353
- db[emlen - from_len - mdlen - 1] = 0x01;
354
- OPENSSL_memcpy(db + emlen - from_len - mdlen, from, from_len);
355
- if (!RAND_bytes(seed, mdlen)) {
356
- return 0;
357
- }
358
-
359
- uint8_t *dbmask = OPENSSL_malloc(emlen - mdlen);
360
- if (dbmask == NULL) {
361
- OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
362
- return 0;
363
- }
364
-
365
- int ret = 0;
366
- if (!PKCS1_MGF1(dbmask, emlen - mdlen, seed, mdlen, mgf1md)) {
367
- goto out;
368
- }
369
- for (size_t i = 0; i < emlen - mdlen; i++) {
370
- db[i] ^= dbmask[i];
371
- }
372
-
373
- uint8_t seedmask[EVP_MAX_MD_SIZE];
374
- if (!PKCS1_MGF1(seedmask, mdlen, db, emlen - mdlen, mgf1md)) {
375
- goto out;
376
- }
377
- for (size_t i = 0; i < mdlen; i++) {
378
- seed[i] ^= seedmask[i];
379
- }
380
- ret = 1;
381
-
382
- out:
383
- OPENSSL_free(dbmask);
384
- return ret;
385
- }
386
-
387
- int RSA_padding_check_PKCS1_OAEP_mgf1(uint8_t *out, size_t *out_len,
388
- size_t max_out, const uint8_t *from,
389
- size_t from_len, const uint8_t *param,
390
- size_t param_len, const EVP_MD *md,
391
- const EVP_MD *mgf1md) {
392
- uint8_t *db = NULL;
393
-
394
- if (md == NULL) {
395
- md = EVP_sha1();
396
- }
397
- if (mgf1md == NULL) {
398
- mgf1md = md;
399
- }
400
-
401
- size_t mdlen = EVP_MD_size(md);
402
-
403
- // The encoded message is one byte smaller than the modulus to ensure that it
404
- // doesn't end up greater than the modulus. Thus there's an extra "+1" here
405
- // compared to https://tools.ietf.org/html/rfc2437#section-9.1.1.2.
406
- if (from_len < 1 + 2*mdlen + 1) {
407
- // 'from_len' is the length of the modulus, i.e. does not depend on the
408
- // particular ciphertext.
409
- goto decoding_err;
410
- }
411
-
412
- size_t dblen = from_len - mdlen - 1;
413
- db = OPENSSL_malloc(dblen);
414
- if (db == NULL) {
415
- OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
416
- goto err;
417
- }
418
-
419
- const uint8_t *maskedseed = from + 1;
420
- const uint8_t *maskeddb = from + 1 + mdlen;
421
-
422
- uint8_t seed[EVP_MAX_MD_SIZE];
423
- if (!PKCS1_MGF1(seed, mdlen, maskeddb, dblen, mgf1md)) {
424
- goto err;
425
- }
426
- for (size_t i = 0; i < mdlen; i++) {
427
- seed[i] ^= maskedseed[i];
428
- }
429
-
430
- if (!PKCS1_MGF1(db, dblen, seed, mdlen, mgf1md)) {
431
- goto err;
432
- }
433
- for (size_t i = 0; i < dblen; i++) {
434
- db[i] ^= maskeddb[i];
435
- }
436
-
437
- uint8_t phash[EVP_MAX_MD_SIZE];
438
- if (!EVP_Digest(param, param_len, phash, NULL, md, NULL)) {
439
- goto err;
440
- }
441
-
442
- crypto_word_t bad = ~constant_time_is_zero_w(CRYPTO_memcmp(db, phash, mdlen));
443
- bad |= ~constant_time_is_zero_w(from[0]);
444
-
445
- crypto_word_t looking_for_one_byte = CONSTTIME_TRUE_W;
446
- size_t one_index = 0;
447
- for (size_t i = mdlen; i < dblen; i++) {
448
- crypto_word_t equals1 = constant_time_eq_w(db[i], 1);
449
- crypto_word_t equals0 = constant_time_eq_w(db[i], 0);
450
- one_index =
451
- constant_time_select_w(looking_for_one_byte & equals1, i, one_index);
452
- looking_for_one_byte =
453
- constant_time_select_w(equals1, 0, looking_for_one_byte);
454
- bad |= looking_for_one_byte & ~equals0;
455
- }
456
-
457
- bad |= looking_for_one_byte;
458
-
459
- if (bad) {
460
- goto decoding_err;
461
- }
462
-
463
- one_index++;
464
- size_t mlen = dblen - one_index;
465
- if (max_out < mlen) {
466
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE);
467
- goto err;
468
- }
469
-
470
- OPENSSL_memcpy(out, db + one_index, mlen);
471
- *out_len = mlen;
472
- OPENSSL_free(db);
473
- return 1;
474
-
475
- decoding_err:
476
- // to avoid chosen ciphertext attacks, the error message should not reveal
477
- // which kind of decoding error happened
478
- OPENSSL_PUT_ERROR(RSA, RSA_R_OAEP_DECODING_ERROR);
479
- err:
480
- OPENSSL_free(db);
481
- return 0;
482
- }
483
-
484
- static const uint8_t kPSSZeroes[] = {0, 0, 0, 0, 0, 0, 0, 0};
485
-
486
- int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash,
487
- const EVP_MD *Hash, const EVP_MD *mgf1Hash,
488
- const uint8_t *EM, int sLen) {
489
- int i;
490
- int ret = 0;
491
- int maskedDBLen, MSBits, emLen;
492
- size_t hLen;
493
- const uint8_t *H;
494
- uint8_t *DB = NULL;
495
- EVP_MD_CTX ctx;
496
- uint8_t H_[EVP_MAX_MD_SIZE];
497
- EVP_MD_CTX_init(&ctx);
498
-
499
- if (mgf1Hash == NULL) {
500
- mgf1Hash = Hash;
501
- }
502
-
503
- hLen = EVP_MD_size(Hash);
504
-
505
- // Negative sLen has special meanings:
506
- // -1 sLen == hLen
507
- // -2 salt length is autorecovered from signature
508
- // -N reserved
509
- if (sLen == -1) {
510
- sLen = hLen;
511
- } else if (sLen == -2) {
512
- sLen = -2;
513
- } else if (sLen < -2) {
514
- OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED);
515
- goto err;
516
- }
517
-
518
- MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
519
- emLen = RSA_size(rsa);
520
- if (EM[0] & (0xFF << MSBits)) {
521
- OPENSSL_PUT_ERROR(RSA, RSA_R_FIRST_OCTET_INVALID);
522
- goto err;
523
- }
524
- if (MSBits == 0) {
525
- EM++;
526
- emLen--;
527
- }
528
- if (emLen < (int)hLen + 2 || emLen < ((int)hLen + sLen + 2)) {
529
- // sLen can be small negative
530
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE);
531
- goto err;
532
- }
533
- if (EM[emLen - 1] != 0xbc) {
534
- OPENSSL_PUT_ERROR(RSA, RSA_R_LAST_OCTET_INVALID);
535
- goto err;
536
- }
537
- maskedDBLen = emLen - hLen - 1;
538
- H = EM + maskedDBLen;
539
- DB = OPENSSL_malloc(maskedDBLen);
540
- if (!DB) {
541
- OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
542
- goto err;
543
- }
544
- if (!PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash)) {
545
- goto err;
546
- }
547
- for (i = 0; i < maskedDBLen; i++) {
548
- DB[i] ^= EM[i];
549
- }
550
- if (MSBits) {
551
- DB[0] &= 0xFF >> (8 - MSBits);
552
- }
553
- for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++) {
554
- ;
555
- }
556
- if (DB[i++] != 0x1) {
557
- OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_RECOVERY_FAILED);
558
- goto err;
559
- }
560
- if (sLen >= 0 && (maskedDBLen - i) != sLen) {
561
- OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED);
562
- goto err;
563
- }
564
- if (!EVP_DigestInit_ex(&ctx, Hash, NULL) ||
565
- !EVP_DigestUpdate(&ctx, kPSSZeroes, sizeof(kPSSZeroes)) ||
566
- !EVP_DigestUpdate(&ctx, mHash, hLen) ||
567
- !EVP_DigestUpdate(&ctx, DB + i, maskedDBLen - i) ||
568
- !EVP_DigestFinal_ex(&ctx, H_, NULL)) {
569
- goto err;
570
- }
571
- if (OPENSSL_memcmp(H_, H, hLen)) {
572
- OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_SIGNATURE);
573
- ret = 0;
574
- } else {
575
- ret = 1;
576
- }
577
-
578
- err:
579
- OPENSSL_free(DB);
580
- EVP_MD_CTX_cleanup(&ctx);
581
-
582
- return ret;
583
- }
584
-
585
- int RSA_padding_add_PKCS1_PSS_mgf1(const RSA *rsa, unsigned char *EM,
586
- const unsigned char *mHash,
587
- const EVP_MD *Hash, const EVP_MD *mgf1Hash,
588
- int sLenRequested) {
589
- int ret = 0;
590
- size_t maskedDBLen, MSBits, emLen;
591
- size_t hLen;
592
- unsigned char *H, *salt = NULL, *p;
593
-
594
- if (mgf1Hash == NULL) {
595
- mgf1Hash = Hash;
596
- }
597
-
598
- hLen = EVP_MD_size(Hash);
599
-
600
- if (BN_is_zero(rsa->n)) {
601
- OPENSSL_PUT_ERROR(RSA, RSA_R_EMPTY_PUBLIC_KEY);
602
- goto err;
603
- }
604
-
605
- MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
606
- emLen = RSA_size(rsa);
607
- if (MSBits == 0) {
608
- assert(emLen >= 1);
609
- *EM++ = 0;
610
- emLen--;
611
- }
612
-
613
- if (emLen < hLen + 2) {
614
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
615
- goto err;
616
- }
617
-
618
- // Negative sLenRequested has special meanings:
619
- // -1 sLen == hLen
620
- // -2 salt length is maximized
621
- // -N reserved
622
- size_t sLen;
623
- if (sLenRequested == -1) {
624
- sLen = hLen;
625
- } else if (sLenRequested == -2) {
626
- sLen = emLen - hLen - 2;
627
- } else if (sLenRequested < 0) {
628
- OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED);
629
- goto err;
630
- } else {
631
- sLen = (size_t)sLenRequested;
632
- }
633
-
634
- if (emLen - hLen - 2 < sLen) {
635
- OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
636
- goto err;
637
- }
638
-
639
- if (sLen > 0) {
640
- salt = OPENSSL_malloc(sLen);
641
- if (!salt) {
642
- OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
643
- goto err;
644
- }
645
- if (!RAND_bytes(salt, sLen)) {
646
- goto err;
647
- }
648
- }
649
- maskedDBLen = emLen - hLen - 1;
650
- H = EM + maskedDBLen;
651
-
652
- EVP_MD_CTX ctx;
653
- EVP_MD_CTX_init(&ctx);
654
- int digest_ok = EVP_DigestInit_ex(&ctx, Hash, NULL) &&
655
- EVP_DigestUpdate(&ctx, kPSSZeroes, sizeof(kPSSZeroes)) &&
656
- EVP_DigestUpdate(&ctx, mHash, hLen) &&
657
- EVP_DigestUpdate(&ctx, salt, sLen) &&
658
- EVP_DigestFinal_ex(&ctx, H, NULL);
659
- EVP_MD_CTX_cleanup(&ctx);
660
- if (!digest_ok) {
661
- goto err;
662
- }
663
-
664
- // Generate dbMask in place then perform XOR on it
665
- if (!PKCS1_MGF1(EM, maskedDBLen, H, hLen, mgf1Hash)) {
666
- goto err;
667
- }
668
-
669
- p = EM;
670
-
671
- // Initial PS XORs with all zeroes which is a NOP so just update
672
- // pointer. Note from a test above this value is guaranteed to
673
- // be non-negative.
674
- p += emLen - sLen - hLen - 2;
675
- *p++ ^= 0x1;
676
- if (sLen > 0) {
677
- for (size_t i = 0; i < sLen; i++) {
678
- *p++ ^= salt[i];
679
- }
680
- }
681
- if (MSBits) {
682
- EM[0] &= 0xFF >> (8 - MSBits);
683
- }
684
-
685
- // H is already in place so just set final 0xbc
686
-
687
- EM[emLen - 1] = 0xbc;
688
-
689
- ret = 1;
690
-
691
- err:
692
- OPENSSL_free(salt);
693
-
694
- return ret;
695
- }
1
+ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
2
+ * project 2005.
3
+ */
4
+ /* ====================================================================
5
+ * Copyright (c) 2005 The OpenSSL Project. All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions
9
+ * are met:
10
+ *
11
+ * 1. Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ *
14
+ * 2. Redistributions in binary form must reproduce the above copyright
15
+ * notice, this list of conditions and the following disclaimer in
16
+ * the documentation and/or other materials provided with the
17
+ * distribution.
18
+ *
19
+ * 3. All advertising materials mentioning features or use of this
20
+ * software must display the following acknowledgment:
21
+ * "This product includes software developed by the OpenSSL Project
22
+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23
+ *
24
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25
+ * endorse or promote products derived from this software without
26
+ * prior written permission. For written permission, please contact
27
+ * licensing@OpenSSL.org.
28
+ *
29
+ * 5. Products derived from this software may not be called "OpenSSL"
30
+ * nor may "OpenSSL" appear in their names without prior written
31
+ * permission of the OpenSSL Project.
32
+ *
33
+ * 6. Redistributions of any form whatsoever must retain the following
34
+ * acknowledgment:
35
+ * "This product includes software developed by the OpenSSL Project
36
+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37
+ *
38
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
50
+ * ====================================================================
51
+ *
52
+ * This product includes cryptographic software written by Eric Young
53
+ * (eay@cryptsoft.com). This product includes software written by Tim
54
+ * Hudson (tjh@cryptsoft.com). */
55
+
56
+ #include <openssl/rsa.h>
57
+
58
+ #include <assert.h>
59
+ #include <limits.h>
60
+ #include <string.h>
61
+
62
+ #include <openssl/bn.h>
63
+ #include <openssl/digest.h>
64
+ #include <openssl/err.h>
65
+ #include <openssl/mem.h>
66
+ #include <openssl/rand.h>
67
+ #include <openssl/sha.h>
68
+
69
+ #include "internal.h"
70
+ #include "../service_indicator/internal.h"
71
+ #include "../../internal.h"
72
+
73
+
74
+ #define RSA_PKCS1_PADDING_SIZE 11
75
+
76
+ int RSA_padding_add_PKCS1_type_1(uint8_t *to, size_t to_len,
77
+ const uint8_t *from, size_t from_len) {
78
+ // See RFC 8017, section 9.2.
79
+ if (to_len < RSA_PKCS1_PADDING_SIZE) {
80
+ OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
81
+ return 0;
82
+ }
83
+
84
+ if (from_len > to_len - RSA_PKCS1_PADDING_SIZE) {
85
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
86
+ return 0;
87
+ }
88
+
89
+ to[0] = 0;
90
+ to[1] = 1;
91
+ OPENSSL_memset(to + 2, 0xff, to_len - 3 - from_len);
92
+ to[to_len - from_len - 1] = 0;
93
+ OPENSSL_memcpy(to + to_len - from_len, from, from_len);
94
+ return 1;
95
+ }
96
+
97
+ int RSA_padding_check_PKCS1_type_1(uint8_t *out, size_t *out_len,
98
+ size_t max_out, const uint8_t *from,
99
+ size_t from_len) {
100
+ // See RFC 8017, section 9.2. This is part of signature verification and thus
101
+ // does not need to run in constant-time.
102
+ if (from_len < 2) {
103
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_SMALL);
104
+ return 0;
105
+ }
106
+
107
+ // Check the header.
108
+ if (from[0] != 0 || from[1] != 1) {
109
+ OPENSSL_PUT_ERROR(RSA, RSA_R_BLOCK_TYPE_IS_NOT_01);
110
+ return 0;
111
+ }
112
+
113
+ // Scan over padded data, looking for the 00.
114
+ size_t pad;
115
+ for (pad = 2 /* header */; pad < from_len; pad++) {
116
+ if (from[pad] == 0x00) {
117
+ break;
118
+ }
119
+
120
+ if (from[pad] != 0xff) {
121
+ OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_FIXED_HEADER_DECRYPT);
122
+ return 0;
123
+ }
124
+ }
125
+
126
+ if (pad == from_len) {
127
+ OPENSSL_PUT_ERROR(RSA, RSA_R_NULL_BEFORE_BLOCK_MISSING);
128
+ return 0;
129
+ }
130
+
131
+ if (pad < 2 /* header */ + 8) {
132
+ OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_PAD_BYTE_COUNT);
133
+ return 0;
134
+ }
135
+
136
+ // Skip over the 00.
137
+ pad++;
138
+
139
+ if (from_len - pad > max_out) {
140
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE);
141
+ return 0;
142
+ }
143
+
144
+ OPENSSL_memcpy(out, from + pad, from_len - pad);
145
+ *out_len = from_len - pad;
146
+ return 1;
147
+ }
148
+
149
+ static void rand_nonzero(uint8_t *out, size_t len) {
150
+ FIPS_service_indicator_lock_state();
151
+ RAND_bytes(out, len);
152
+
153
+ for (size_t i = 0; i < len; i++) {
154
+ while (out[i] == 0) {
155
+ RAND_bytes(out + i, 1);
156
+ }
157
+ }
158
+
159
+ FIPS_service_indicator_unlock_state();
160
+ }
161
+
162
+ int RSA_padding_add_PKCS1_type_2(uint8_t *to, size_t to_len,
163
+ const uint8_t *from, size_t from_len) {
164
+ // See RFC 8017, section 7.2.1.
165
+ if (to_len < RSA_PKCS1_PADDING_SIZE) {
166
+ OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
167
+ return 0;
168
+ }
169
+
170
+ if (from_len > to_len - RSA_PKCS1_PADDING_SIZE) {
171
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
172
+ return 0;
173
+ }
174
+
175
+ to[0] = 0;
176
+ to[1] = 2;
177
+
178
+ size_t padding_len = to_len - 3 - from_len;
179
+ rand_nonzero(to + 2, padding_len);
180
+ to[2 + padding_len] = 0;
181
+ OPENSSL_memcpy(to + to_len - from_len, from, from_len);
182
+ return 1;
183
+ }
184
+
185
+ int RSA_padding_check_PKCS1_type_2(uint8_t *out, size_t *out_len,
186
+ size_t max_out, const uint8_t *from,
187
+ size_t from_len) {
188
+ if (from_len == 0) {
189
+ OPENSSL_PUT_ERROR(RSA, RSA_R_EMPTY_PUBLIC_KEY);
190
+ return 0;
191
+ }
192
+
193
+ // PKCS#1 v1.5 decryption. See "PKCS #1 v2.2: RSA Cryptography
194
+ // Standard", section 7.2.2.
195
+ if (from_len < RSA_PKCS1_PADDING_SIZE) {
196
+ // |from| is zero-padded to the size of the RSA modulus, a public value, so
197
+ // this can be rejected in non-constant time.
198
+ OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
199
+ return 0;
200
+ }
201
+
202
+ crypto_word_t first_byte_is_zero = constant_time_eq_w(from[0], 0);
203
+ crypto_word_t second_byte_is_two = constant_time_eq_w(from[1], 2);
204
+
205
+ crypto_word_t zero_index = 0, looking_for_index = CONSTTIME_TRUE_W;
206
+ for (size_t i = 2; i < from_len; i++) {
207
+ crypto_word_t equals0 = constant_time_is_zero_w(from[i]);
208
+ zero_index =
209
+ constant_time_select_w(looking_for_index & equals0, i, zero_index);
210
+ looking_for_index = constant_time_select_w(equals0, 0, looking_for_index);
211
+ }
212
+
213
+ // The input must begin with 00 02.
214
+ crypto_word_t valid_index = first_byte_is_zero;
215
+ valid_index &= second_byte_is_two;
216
+
217
+ // We must have found the end of PS.
218
+ valid_index &= ~looking_for_index;
219
+
220
+ // PS must be at least 8 bytes long, and it starts two bytes into |from|.
221
+ valid_index &= constant_time_ge_w(zero_index, 2 + 8);
222
+
223
+ // Skip the zero byte.
224
+ zero_index++;
225
+
226
+ // NOTE: Although this logic attempts to be constant time, the API contracts
227
+ // of this function and |RSA_decrypt| with |RSA_PKCS1_PADDING| make it
228
+ // impossible to completely avoid Bleichenbacher's attack. Consumers should
229
+ // use |RSA_PADDING_NONE| and perform the padding check in constant-time
230
+ // combined with a swap to a random session key or other mitigation.
231
+ CONSTTIME_DECLASSIFY(&valid_index, sizeof(valid_index));
232
+ CONSTTIME_DECLASSIFY(&zero_index, sizeof(zero_index));
233
+
234
+ if (!valid_index) {
235
+ OPENSSL_PUT_ERROR(RSA, RSA_R_PKCS_DECODING_ERROR);
236
+ return 0;
237
+ }
238
+
239
+ const size_t msg_len = from_len - zero_index;
240
+ if (msg_len > max_out) {
241
+ // This shouldn't happen because this function is always called with
242
+ // |max_out| as the key size and |from_len| is bounded by the key size.
243
+ OPENSSL_PUT_ERROR(RSA, RSA_R_PKCS_DECODING_ERROR);
244
+ return 0;
245
+ }
246
+
247
+ OPENSSL_memcpy(out, &from[zero_index], msg_len);
248
+ *out_len = msg_len;
249
+ return 1;
250
+ }
251
+
252
+ int RSA_padding_add_none(uint8_t *to, size_t to_len, const uint8_t *from,
253
+ size_t from_len) {
254
+ if (from_len > to_len) {
255
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
256
+ return 0;
257
+ }
258
+
259
+ if (from_len < to_len) {
260
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_SMALL);
261
+ return 0;
262
+ }
263
+
264
+ OPENSSL_memcpy(to, from, from_len);
265
+ return 1;
266
+ }
267
+
268
+ static int PKCS1_MGF1(uint8_t *out, size_t len, const uint8_t *seed,
269
+ size_t seed_len, const EVP_MD *md) {
270
+ int ret = 0;
271
+ EVP_MD_CTX ctx;
272
+ EVP_MD_CTX_init(&ctx);
273
+ FIPS_service_indicator_lock_state();
274
+
275
+ size_t md_len = EVP_MD_size(md);
276
+
277
+ for (uint32_t i = 0; len > 0; i++) {
278
+ uint8_t counter[4];
279
+ counter[0] = (uint8_t)(i >> 24);
280
+ counter[1] = (uint8_t)(i >> 16);
281
+ counter[2] = (uint8_t)(i >> 8);
282
+ counter[3] = (uint8_t)i;
283
+ if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
284
+ !EVP_DigestUpdate(&ctx, seed, seed_len) ||
285
+ !EVP_DigestUpdate(&ctx, counter, sizeof(counter))) {
286
+ goto err;
287
+ }
288
+
289
+ if (md_len <= len) {
290
+ if (!EVP_DigestFinal_ex(&ctx, out, NULL)) {
291
+ goto err;
292
+ }
293
+ out += md_len;
294
+ len -= md_len;
295
+ } else {
296
+ uint8_t digest[EVP_MAX_MD_SIZE];
297
+ if (!EVP_DigestFinal_ex(&ctx, digest, NULL)) {
298
+ goto err;
299
+ }
300
+ OPENSSL_memcpy(out, digest, len);
301
+ len = 0;
302
+ }
303
+ }
304
+
305
+ ret = 1;
306
+
307
+ err:
308
+ EVP_MD_CTX_cleanup(&ctx);
309
+ FIPS_service_indicator_unlock_state();
310
+ return ret;
311
+ }
312
+
313
+ int RSA_padding_add_PKCS1_OAEP_mgf1(uint8_t *to, size_t to_len,
314
+ const uint8_t *from, size_t from_len,
315
+ const uint8_t *param, size_t param_len,
316
+ const EVP_MD *md, const EVP_MD *mgf1md) {
317
+ if (md == NULL) {
318
+ md = EVP_sha1();
319
+ }
320
+ if (mgf1md == NULL) {
321
+ mgf1md = md;
322
+ }
323
+
324
+ size_t mdlen = EVP_MD_size(md);
325
+
326
+ if (to_len < 2 * mdlen + 2) {
327
+ OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
328
+ return 0;
329
+ }
330
+
331
+ size_t emlen = to_len - 1;
332
+ if (from_len > emlen - 2 * mdlen - 1) {
333
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
334
+ return 0;
335
+ }
336
+
337
+ if (emlen < 2 * mdlen + 1) {
338
+ OPENSSL_PUT_ERROR(RSA, RSA_R_KEY_SIZE_TOO_SMALL);
339
+ return 0;
340
+ }
341
+
342
+ to[0] = 0;
343
+ uint8_t *seed = to + 1;
344
+ uint8_t *db = to + mdlen + 1;
345
+
346
+ uint8_t *dbmask = NULL;
347
+ int ret = 0;
348
+ FIPS_service_indicator_lock_state();
349
+ if (!EVP_Digest(param, param_len, db, NULL, md, NULL)) {
350
+ goto out;
351
+ }
352
+ OPENSSL_memset(db + mdlen, 0, emlen - from_len - 2 * mdlen - 1);
353
+ db[emlen - from_len - mdlen - 1] = 0x01;
354
+ OPENSSL_memcpy(db + emlen - from_len - mdlen, from, from_len);
355
+ if (!RAND_bytes(seed, mdlen)) {
356
+ goto out;
357
+ }
358
+
359
+ dbmask = OPENSSL_malloc(emlen - mdlen);
360
+ if (dbmask == NULL) {
361
+ OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
362
+ goto out;
363
+ }
364
+
365
+ if (!PKCS1_MGF1(dbmask, emlen - mdlen, seed, mdlen, mgf1md)) {
366
+ goto out;
367
+ }
368
+ for (size_t i = 0; i < emlen - mdlen; i++) {
369
+ db[i] ^= dbmask[i];
370
+ }
371
+
372
+ uint8_t seedmask[EVP_MAX_MD_SIZE];
373
+ if (!PKCS1_MGF1(seedmask, mdlen, db, emlen - mdlen, mgf1md)) {
374
+ goto out;
375
+ }
376
+ for (size_t i = 0; i < mdlen; i++) {
377
+ seed[i] ^= seedmask[i];
378
+ }
379
+ ret = 1;
380
+
381
+ out:
382
+ OPENSSL_free(dbmask);
383
+ FIPS_service_indicator_unlock_state();
384
+ return ret;
385
+ }
386
+
387
+ int RSA_padding_check_PKCS1_OAEP_mgf1(uint8_t *out, size_t *out_len,
388
+ size_t max_out, const uint8_t *from,
389
+ size_t from_len, const uint8_t *param,
390
+ size_t param_len, const EVP_MD *md,
391
+ const EVP_MD *mgf1md) {
392
+ uint8_t *db = NULL;
393
+
394
+ if (md == NULL) {
395
+ md = EVP_sha1();
396
+ }
397
+ if (mgf1md == NULL) {
398
+ mgf1md = md;
399
+ }
400
+
401
+ size_t mdlen = EVP_MD_size(md);
402
+
403
+ // The encoded message is one byte smaller than the modulus to ensure that it
404
+ // doesn't end up greater than the modulus. Thus there's an extra "+1" here
405
+ // compared to https://tools.ietf.org/html/rfc2437#section-9.1.1.2.
406
+ if (from_len < 1 + 2*mdlen + 1) {
407
+ // 'from_len' is the length of the modulus, i.e. does not depend on the
408
+ // particular ciphertext.
409
+ goto decoding_err;
410
+ }
411
+
412
+ size_t dblen = from_len - mdlen - 1;
413
+ FIPS_service_indicator_lock_state();
414
+ db = OPENSSL_malloc(dblen);
415
+ if (db == NULL) {
416
+ OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
417
+ goto err;
418
+ }
419
+
420
+ const uint8_t *maskedseed = from + 1;
421
+ const uint8_t *maskeddb = from + 1 + mdlen;
422
+
423
+ uint8_t seed[EVP_MAX_MD_SIZE];
424
+ if (!PKCS1_MGF1(seed, mdlen, maskeddb, dblen, mgf1md)) {
425
+ goto err;
426
+ }
427
+ for (size_t i = 0; i < mdlen; i++) {
428
+ seed[i] ^= maskedseed[i];
429
+ }
430
+
431
+ if (!PKCS1_MGF1(db, dblen, seed, mdlen, mgf1md)) {
432
+ goto err;
433
+ }
434
+ for (size_t i = 0; i < dblen; i++) {
435
+ db[i] ^= maskeddb[i];
436
+ }
437
+
438
+ uint8_t phash[EVP_MAX_MD_SIZE];
439
+ if (!EVP_Digest(param, param_len, phash, NULL, md, NULL)) {
440
+ goto err;
441
+ }
442
+
443
+ crypto_word_t bad = ~constant_time_is_zero_w(CRYPTO_memcmp(db, phash, mdlen));
444
+ bad |= ~constant_time_is_zero_w(from[0]);
445
+
446
+ crypto_word_t looking_for_one_byte = CONSTTIME_TRUE_W;
447
+ size_t one_index = 0;
448
+ for (size_t i = mdlen; i < dblen; i++) {
449
+ crypto_word_t equals1 = constant_time_eq_w(db[i], 1);
450
+ crypto_word_t equals0 = constant_time_eq_w(db[i], 0);
451
+ one_index =
452
+ constant_time_select_w(looking_for_one_byte & equals1, i, one_index);
453
+ looking_for_one_byte =
454
+ constant_time_select_w(equals1, 0, looking_for_one_byte);
455
+ bad |= looking_for_one_byte & ~equals0;
456
+ }
457
+
458
+ bad |= looking_for_one_byte;
459
+
460
+ if (bad) {
461
+ goto decoding_err;
462
+ }
463
+
464
+ one_index++;
465
+ size_t mlen = dblen - one_index;
466
+ if (max_out < mlen) {
467
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE);
468
+ goto err;
469
+ }
470
+
471
+ OPENSSL_memcpy(out, db + one_index, mlen);
472
+ *out_len = mlen;
473
+ OPENSSL_free(db);
474
+ FIPS_service_indicator_unlock_state();
475
+ return 1;
476
+
477
+ decoding_err:
478
+ // to avoid chosen ciphertext attacks, the error message should not reveal
479
+ // which kind of decoding error happened
480
+ OPENSSL_PUT_ERROR(RSA, RSA_R_OAEP_DECODING_ERROR);
481
+ err:
482
+ OPENSSL_free(db);
483
+ FIPS_service_indicator_unlock_state();
484
+ return 0;
485
+ }
486
+
487
+ static const uint8_t kPSSZeroes[] = {0, 0, 0, 0, 0, 0, 0, 0};
488
+
489
+ int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash,
490
+ const EVP_MD *Hash, const EVP_MD *mgf1Hash,
491
+ const uint8_t *EM, int sLen) {
492
+ int i;
493
+ int ret = 0;
494
+ int maskedDBLen, MSBits, emLen;
495
+ size_t hLen;
496
+ const uint8_t *H;
497
+ uint8_t *DB = NULL;
498
+ EVP_MD_CTX ctx;
499
+ uint8_t H_[EVP_MAX_MD_SIZE];
500
+ EVP_MD_CTX_init(&ctx);
501
+
502
+ if (mgf1Hash == NULL) {
503
+ mgf1Hash = Hash;
504
+ }
505
+
506
+ hLen = EVP_MD_size(Hash);
507
+ FIPS_service_indicator_lock_state();
508
+
509
+ // Negative sLen has special meanings:
510
+ // -1 sLen == hLen
511
+ // -2 salt length is autorecovered from signature
512
+ // -N reserved
513
+ if (sLen == -1) {
514
+ sLen = hLen;
515
+ } else if (sLen == -2) {
516
+ sLen = -2;
517
+ } else if (sLen < -2) {
518
+ OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED);
519
+ goto err;
520
+ }
521
+
522
+ MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
523
+ emLen = RSA_size(rsa);
524
+ if (EM[0] & (0xFF << MSBits)) {
525
+ OPENSSL_PUT_ERROR(RSA, RSA_R_FIRST_OCTET_INVALID);
526
+ goto err;
527
+ }
528
+ if (MSBits == 0) {
529
+ EM++;
530
+ emLen--;
531
+ }
532
+ if (emLen < (int)hLen + 2 || emLen < ((int)hLen + sLen + 2)) {
533
+ // sLen can be small negative
534
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE);
535
+ goto err;
536
+ }
537
+ if (EM[emLen - 1] != 0xbc) {
538
+ OPENSSL_PUT_ERROR(RSA, RSA_R_LAST_OCTET_INVALID);
539
+ goto err;
540
+ }
541
+ maskedDBLen = emLen - hLen - 1;
542
+ H = EM + maskedDBLen;
543
+ DB = OPENSSL_malloc(maskedDBLen);
544
+ if (!DB) {
545
+ OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
546
+ goto err;
547
+ }
548
+ if (!PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash)) {
549
+ goto err;
550
+ }
551
+ for (i = 0; i < maskedDBLen; i++) {
552
+ DB[i] ^= EM[i];
553
+ }
554
+ if (MSBits) {
555
+ DB[0] &= 0xFF >> (8 - MSBits);
556
+ }
557
+ for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++) {
558
+ ;
559
+ }
560
+ if (DB[i++] != 0x1) {
561
+ OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_RECOVERY_FAILED);
562
+ goto err;
563
+ }
564
+ if (sLen >= 0 && (maskedDBLen - i) != sLen) {
565
+ OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED);
566
+ goto err;
567
+ }
568
+ if (!EVP_DigestInit_ex(&ctx, Hash, NULL) ||
569
+ !EVP_DigestUpdate(&ctx, kPSSZeroes, sizeof(kPSSZeroes)) ||
570
+ !EVP_DigestUpdate(&ctx, mHash, hLen) ||
571
+ !EVP_DigestUpdate(&ctx, DB + i, maskedDBLen - i) ||
572
+ !EVP_DigestFinal_ex(&ctx, H_, NULL)) {
573
+ goto err;
574
+ }
575
+ if (OPENSSL_memcmp(H_, H, hLen)) {
576
+ OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_SIGNATURE);
577
+ ret = 0;
578
+ } else {
579
+ ret = 1;
580
+ }
581
+
582
+ err:
583
+ OPENSSL_free(DB);
584
+ EVP_MD_CTX_cleanup(&ctx);
585
+ FIPS_service_indicator_unlock_state();
586
+
587
+ return ret;
588
+ }
589
+
590
+ int RSA_padding_add_PKCS1_PSS_mgf1(const RSA *rsa, unsigned char *EM,
591
+ const unsigned char *mHash,
592
+ const EVP_MD *Hash, const EVP_MD *mgf1Hash,
593
+ int sLenRequested) {
594
+ int ret = 0;
595
+ size_t maskedDBLen, MSBits, emLen;
596
+ size_t hLen;
597
+ unsigned char *H, *salt = NULL, *p;
598
+
599
+ if (mgf1Hash == NULL) {
600
+ mgf1Hash = Hash;
601
+ }
602
+
603
+ FIPS_service_indicator_lock_state();
604
+ hLen = EVP_MD_size(Hash);
605
+
606
+ if (BN_is_zero(rsa->n)) {
607
+ OPENSSL_PUT_ERROR(RSA, RSA_R_EMPTY_PUBLIC_KEY);
608
+ goto err;
609
+ }
610
+
611
+ MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
612
+ emLen = RSA_size(rsa);
613
+ if (MSBits == 0) {
614
+ assert(emLen >= 1);
615
+ *EM++ = 0;
616
+ emLen--;
617
+ }
618
+
619
+ if (emLen < hLen + 2) {
620
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
621
+ goto err;
622
+ }
623
+
624
+ // Negative sLenRequested has special meanings:
625
+ // -1 sLen == hLen
626
+ // -2 salt length is maximized
627
+ // -N reserved
628
+ size_t sLen;
629
+ if (sLenRequested == -1) {
630
+ sLen = hLen;
631
+ } else if (sLenRequested == -2) {
632
+ sLen = emLen - hLen - 2;
633
+ } else if (sLenRequested < 0) {
634
+ OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED);
635
+ goto err;
636
+ } else {
637
+ sLen = (size_t)sLenRequested;
638
+ }
639
+
640
+ if (emLen - hLen - 2 < sLen) {
641
+ OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
642
+ goto err;
643
+ }
644
+
645
+ if (sLen > 0) {
646
+ salt = OPENSSL_malloc(sLen);
647
+ if (!salt) {
648
+ OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
649
+ goto err;
650
+ }
651
+ if (!RAND_bytes(salt, sLen)) {
652
+ goto err;
653
+ }
654
+ }
655
+ maskedDBLen = emLen - hLen - 1;
656
+ H = EM + maskedDBLen;
657
+
658
+ EVP_MD_CTX ctx;
659
+ EVP_MD_CTX_init(&ctx);
660
+ int digest_ok = EVP_DigestInit_ex(&ctx, Hash, NULL) &&
661
+ EVP_DigestUpdate(&ctx, kPSSZeroes, sizeof(kPSSZeroes)) &&
662
+ EVP_DigestUpdate(&ctx, mHash, hLen) &&
663
+ EVP_DigestUpdate(&ctx, salt, sLen) &&
664
+ EVP_DigestFinal_ex(&ctx, H, NULL);
665
+ EVP_MD_CTX_cleanup(&ctx);
666
+ if (!digest_ok) {
667
+ goto err;
668
+ }
669
+
670
+ // Generate dbMask in place then perform XOR on it
671
+ if (!PKCS1_MGF1(EM, maskedDBLen, H, hLen, mgf1Hash)) {
672
+ goto err;
673
+ }
674
+
675
+ p = EM;
676
+
677
+ // Initial PS XORs with all zeroes which is a NOP so just update
678
+ // pointer. Note from a test above this value is guaranteed to
679
+ // be non-negative.
680
+ p += emLen - sLen - hLen - 2;
681
+ *p++ ^= 0x1;
682
+ if (sLen > 0) {
683
+ for (size_t i = 0; i < sLen; i++) {
684
+ *p++ ^= salt[i];
685
+ }
686
+ }
687
+ if (MSBits) {
688
+ EM[0] &= 0xFF >> (8 - MSBits);
689
+ }
690
+
691
+ // H is already in place so just set final 0xbc
692
+
693
+ EM[emLen - 1] = 0xbc;
694
+
695
+ ret = 1;
696
+
697
+ err:
698
+ OPENSSL_free(salt);
699
+ FIPS_service_indicator_unlock_state();
700
+
701
+ return ret;
702
+ }