grpc 1.38.0 → 1.40.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (340) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +68 -21
  3. data/include/grpc/event_engine/endpoint_config.h +48 -0
  4. data/include/grpc/event_engine/event_engine.h +23 -29
  5. data/include/grpc/event_engine/port.h +2 -0
  6. data/include/grpc/event_engine/slice_allocator.h +21 -36
  7. data/include/grpc/grpc.h +9 -2
  8. data/include/grpc/grpc_security.h +32 -0
  9. data/include/grpc/grpc_security_constants.h +1 -0
  10. data/include/grpc/impl/codegen/grpc_types.h +33 -19
  11. data/include/grpc/impl/codegen/port_platform.h +41 -0
  12. data/src/core/ext/filters/client_channel/client_channel.cc +415 -249
  13. data/src/core/ext/filters/client_channel/client_channel.h +42 -18
  14. data/src/core/ext/filters/client_channel/config_selector.h +19 -6
  15. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -0
  16. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  17. data/src/core/ext/filters/client_channel/http_proxy.cc +16 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +7 -8
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -21
  20. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +3 -5
  21. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +734 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -15
  24. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -6
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +18 -36
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -22
  27. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +2 -9
  28. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +68 -103
  29. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -15
  30. data/src/core/ext/filters/client_channel/lb_policy.h +70 -46
  31. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -3
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc +31 -0
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc +28 -0
  34. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -3
  35. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +7 -2
  36. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +116 -76
  37. data/src/core/ext/filters/client_channel/retry_filter.cc +967 -544
  38. data/src/core/ext/filters/client_channel/retry_service_config.cc +57 -28
  39. data/src/core/ext/filters/client_channel/retry_service_config.h +9 -3
  40. data/src/core/ext/filters/client_channel/service_config_call_data.h +45 -5
  41. data/src/core/ext/filters/client_idle/client_idle_filter.cc +1 -1
  42. data/src/core/ext/filters/http/client/http_client_filter.cc +5 -2
  43. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +2 -1
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +5 -1
  45. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +3 -2
  46. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +1 -1
  47. data/src/core/{lib/event_engine/slice_allocator.cc → ext/transport/chttp2/transport/chttp2_slice_allocator.cc} +23 -16
  48. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +74 -0
  49. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +12 -10
  50. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  51. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  52. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +8 -8
  53. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +5 -5
  54. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +639 -752
  55. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +190 -69
  56. data/src/core/ext/transport/chttp2/transport/internal.h +2 -1
  57. data/src/core/ext/transport/chttp2/transport/parsing.cc +72 -56
  58. data/src/core/ext/transport/chttp2/transport/varint.cc +6 -4
  59. data/src/core/ext/transport/inproc/inproc_transport.cc +42 -31
  60. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +56 -35
  61. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +180 -76
  62. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +35 -27
  63. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +97 -48
  64. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +45 -9
  65. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +67 -7
  66. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +66 -9
  67. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +227 -0
  68. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +46 -0
  69. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +121 -0
  70. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -0
  71. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +35 -0
  72. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +90 -0
  73. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +32 -24
  74. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +120 -73
  75. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +4 -2
  76. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +15 -0
  77. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +48 -0
  78. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +171 -0
  79. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +8 -6
  80. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +27 -19
  81. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +1 -0
  82. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +24 -7
  83. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +57 -0
  84. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +29 -17
  85. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +72 -0
  86. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +3 -2
  87. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +4 -0
  88. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +6 -5
  89. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +15 -11
  90. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +85 -43
  91. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +274 -91
  92. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +11 -8
  93. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +30 -13
  94. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +33 -5
  95. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +115 -0
  96. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +60 -0
  97. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +181 -0
  98. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +1 -0
  99. data/src/core/ext/upb-generated/validate/validate.upb.c +82 -66
  100. data/src/core/ext/upb-generated/validate/validate.upb.h +220 -124
  101. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +15 -7
  102. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +53 -52
  103. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +318 -277
  104. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +5 -0
  105. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +437 -410
  106. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +198 -170
  107. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +10 -0
  108. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +9 -8
  109. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +219 -163
  110. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +15 -0
  111. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.c +59 -0
  112. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.h +40 -0
  113. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +29 -25
  114. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.c +52 -0
  115. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.h +35 -0
  116. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +135 -125
  117. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +5 -0
  118. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +131 -123
  119. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.c +90 -0
  120. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.h +35 -0
  121. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +32 -24
  122. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +69 -55
  123. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +5 -0
  124. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +684 -664
  125. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  126. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +13 -10
  127. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +13 -10
  128. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +441 -375
  129. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +10 -0
  130. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +122 -114
  131. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +1 -1
  132. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c +112 -79
  133. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.h +5 -0
  134. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.c +64 -0
  135. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.h +50 -0
  136. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +35 -32
  137. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +4 -4
  138. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +182 -160
  139. data/src/core/ext/xds/certificate_provider_store.h +1 -1
  140. data/src/core/ext/xds/xds_api.cc +582 -257
  141. data/src/core/ext/xds/xds_api.h +46 -8
  142. data/src/core/ext/xds/xds_bootstrap.cc +4 -1
  143. data/src/core/ext/xds/xds_client.cc +66 -43
  144. data/src/core/ext/xds/xds_client.h +0 -4
  145. data/src/core/ext/xds/xds_http_filters.cc +3 -2
  146. data/src/core/ext/xds/xds_http_filters.h +3 -0
  147. data/src/core/lib/address_utils/sockaddr_utils.cc +13 -0
  148. data/src/core/lib/address_utils/sockaddr_utils.h +10 -0
  149. data/src/core/lib/channel/call_tracer.h +85 -0
  150. data/src/core/lib/channel/channel_stack.h +1 -1
  151. data/src/core/lib/channel/channelz.h +3 -0
  152. data/src/core/lib/channel/context.h +3 -0
  153. data/src/core/lib/channel/status_util.h +4 -0
  154. data/src/core/lib/compression/stream_compression.h +1 -1
  155. data/src/core/lib/compression/stream_compression_gzip.h +1 -1
  156. data/src/core/lib/compression/stream_compression_identity.h +1 -1
  157. data/src/core/lib/debug/stats.h +1 -1
  158. data/src/core/lib/event_engine/endpoint_config.cc +46 -0
  159. data/src/core/lib/event_engine/endpoint_config_internal.h +42 -0
  160. data/src/core/lib/event_engine/event_engine.cc +50 -0
  161. data/src/core/lib/event_engine/sockaddr.cc +14 -12
  162. data/src/core/lib/event_engine/sockaddr.h +44 -0
  163. data/src/core/lib/gpr/murmur_hash.cc +4 -2
  164. data/src/core/lib/gpr/wrap_memcpy.cc +2 -1
  165. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  166. data/src/core/lib/gprpp/orphanable.h +3 -3
  167. data/src/core/lib/gprpp/status_helper.h +3 -0
  168. data/src/core/lib/gprpp/sync.h +2 -30
  169. data/src/core/lib/iomgr/buffer_list.cc +1 -1
  170. data/src/core/lib/iomgr/endpoint_pair_event_engine.cc +33 -0
  171. data/src/core/lib/iomgr/error.cc +5 -4
  172. data/src/core/lib/iomgr/error.h +1 -1
  173. data/src/core/lib/iomgr/ev_apple.h +1 -1
  174. data/src/core/lib/iomgr/event_engine/closure.cc +54 -0
  175. data/src/core/lib/iomgr/event_engine/closure.h +33 -0
  176. data/src/core/lib/iomgr/event_engine/endpoint.cc +192 -0
  177. data/src/core/lib/iomgr/event_engine/endpoint.h +53 -0
  178. data/src/core/lib/iomgr/event_engine/iomgr.cc +105 -0
  179. data/src/core/lib/iomgr/event_engine/iomgr.h +24 -0
  180. data/src/core/lib/iomgr/event_engine/pollset.cc +87 -0
  181. data/{include/grpc/event_engine/channel_args.h → src/core/lib/iomgr/event_engine/pollset.h} +7 -10
  182. data/src/core/lib/iomgr/event_engine/promise.h +51 -0
  183. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +41 -0
  184. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +35 -0
  185. data/src/core/lib/iomgr/event_engine/resolver.cc +110 -0
  186. data/src/core/lib/iomgr/event_engine/tcp.cc +263 -0
  187. data/src/core/lib/iomgr/event_engine/timer.cc +57 -0
  188. data/src/core/lib/iomgr/exec_ctx.cc +8 -0
  189. data/src/core/lib/iomgr/exec_ctx.h +3 -4
  190. data/src/core/lib/iomgr/executor/threadpool.cc +2 -3
  191. data/src/core/lib/iomgr/executor/threadpool.h +2 -2
  192. data/src/core/lib/iomgr/iomgr.cc +1 -1
  193. data/src/core/lib/iomgr/iomgr_posix.cc +2 -0
  194. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +40 -10
  195. data/src/core/lib/iomgr/pollset_custom.cc +2 -2
  196. data/src/core/lib/iomgr/pollset_custom.h +3 -1
  197. data/src/core/lib/iomgr/pollset_uv.cc +3 -1
  198. data/src/core/lib/iomgr/pollset_uv.h +5 -1
  199. data/src/core/lib/iomgr/port.h +7 -5
  200. data/src/core/lib/iomgr/python_util.h +1 -1
  201. data/src/core/lib/iomgr/resolve_address.cc +5 -1
  202. data/src/core/lib/iomgr/resolve_address.h +6 -0
  203. data/src/core/lib/iomgr/resource_quota.cc +2 -0
  204. data/src/core/lib/iomgr/sockaddr.h +1 -0
  205. data/src/core/lib/iomgr/socket_mutator.cc +15 -2
  206. data/src/core/lib/iomgr/socket_mutator.h +26 -2
  207. data/src/core/lib/iomgr/socket_utils_common_posix.cc +4 -4
  208. data/src/core/lib/iomgr/socket_utils_posix.h +2 -2
  209. data/src/core/lib/iomgr/tcp_client_posix.cc +7 -2
  210. data/src/core/lib/iomgr/tcp_client_windows.cc +2 -0
  211. data/src/core/lib/iomgr/tcp_posix.cc +42 -39
  212. data/src/core/lib/iomgr/tcp_posix.h +8 -0
  213. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -4
  214. data/src/core/lib/iomgr/tcp_server_posix.cc +7 -0
  215. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +2 -1
  216. data/src/core/lib/iomgr/timer.h +6 -1
  217. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  218. data/src/core/lib/json/json_reader.cc +1 -2
  219. data/src/core/lib/matchers/matchers.cc +8 -20
  220. data/src/core/lib/matchers/matchers.h +2 -1
  221. data/src/core/lib/security/authorization/authorization_engine.h +44 -0
  222. data/src/core/lib/security/authorization/authorization_policy_provider.h +32 -0
  223. data/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +46 -0
  224. data/src/core/lib/security/authorization/evaluate_args.cc +209 -0
  225. data/src/core/lib/security/authorization/evaluate_args.h +91 -0
  226. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +3 -1
  227. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +49 -0
  228. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +7 -0
  229. data/src/core/lib/security/credentials/tls/tls_utils.cc +32 -0
  230. data/src/core/lib/security/credentials/tls/tls_utils.h +13 -0
  231. data/src/core/lib/security/security_connector/local/local_security_connector.cc +9 -6
  232. data/src/core/lib/security/security_connector/ssl_utils.cc +5 -0
  233. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +6 -18
  234. data/src/core/lib/security/transport/security_handshaker.cc +12 -4
  235. data/src/core/lib/security/transport/server_auth_filter.cc +0 -7
  236. data/src/core/lib/slice/slice.cc +12 -2
  237. data/src/core/lib/slice/slice_internal.h +1 -0
  238. data/src/core/lib/surface/call.cc +26 -7
  239. data/src/core/lib/surface/call.h +11 -0
  240. data/src/core/lib/surface/completion_queue.cc +22 -22
  241. data/src/core/lib/surface/completion_queue.h +1 -1
  242. data/src/core/lib/surface/completion_queue_factory.cc +1 -2
  243. data/src/core/lib/surface/init.cc +1 -3
  244. data/src/core/lib/surface/init.h +10 -1
  245. data/src/core/lib/surface/server.cc +3 -1
  246. data/src/core/lib/surface/server.h +3 -3
  247. data/src/core/lib/surface/version.cc +2 -4
  248. data/src/core/lib/transport/error_utils.cc +2 -2
  249. data/src/core/lib/transport/metadata_batch.cc +13 -2
  250. data/src/core/lib/transport/metadata_batch.h +7 -0
  251. data/src/core/lib/transport/transport.h +2 -0
  252. data/src/core/lib/transport/transport_op_string.cc +1 -1
  253. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  254. data/src/core/tsi/alts/crypt/gsec.h +2 -0
  255. data/src/ruby/ext/grpc/extconf.rb +2 -0
  256. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  257. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +10 -1
  258. data/src/ruby/lib/grpc/version.rb +1 -1
  259. data/third_party/boringssl-with-bazel/err_data.c +269 -263
  260. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +8 -6
  261. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/cipher_extra.c +4 -0
  262. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +1 -1
  263. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -1
  264. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +9 -0
  265. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.c +0 -4
  266. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +7 -0
  267. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +87 -121
  268. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +20 -30
  269. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +19 -30
  270. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +1 -4
  271. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +0 -13
  272. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +26 -24
  273. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -7
  274. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +28 -39
  275. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +48 -66
  276. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +4 -5
  277. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +362 -371
  278. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +4 -2
  279. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c +2 -2
  280. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_asn1.c +1 -2
  281. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +101 -11
  282. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509a.c +3 -0
  283. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +2 -2
  284. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +3 -0
  285. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +1 -1
  286. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +2 -0
  287. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +14 -15
  288. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +53 -73
  289. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +31 -0
  290. data/third_party/boringssl-with-bazel/src/crypto/x509/x509rset.c +3 -0
  291. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +3 -0
  292. data/third_party/boringssl-with-bazel/src/crypto/x509/x_req.c +5 -8
  293. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +5 -0
  294. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +3 -0
  295. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +7 -0
  296. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  297. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +5 -8
  298. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +1 -1
  299. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +66 -1
  300. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +40 -9
  301. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +1 -0
  302. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
  303. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +6 -2
  304. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +14 -0
  305. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +19 -11
  306. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +325 -0
  307. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +23 -7
  308. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +99 -63
  309. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +139 -109
  310. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +12 -19
  311. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +48 -50
  312. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +451 -435
  313. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +0 -1
  314. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +2 -2
  315. data/third_party/boringssl-with-bazel/src/ssl/d1_srtp.cc +1 -1
  316. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +773 -84
  317. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +80 -47
  318. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +24 -19
  319. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +189 -86
  320. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +45 -56
  321. data/third_party/boringssl-with-bazel/src/ssl/internal.h +272 -167
  322. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +2 -2
  323. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  324. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +14 -19
  325. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +34 -102
  326. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +2 -0
  327. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +8 -31
  328. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +3 -0
  329. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +4 -3
  330. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +7 -3
  331. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +576 -648
  332. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +31 -3
  333. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -39
  334. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +141 -94
  335. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +58 -68
  336. data/third_party/xxhash/xxhash.h +77 -195
  337. metadata +81 -39
  338. data/src/core/lib/gpr/arena.h +0 -47
  339. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +0 -267
  340. data/third_party/boringssl-with-bazel/src/crypto/x509/vpm_int.h +0 -71
@@ -0,0 +1,325 @@
1
+ /* Copyright (c) 2020, Google Inc.
2
+ *
3
+ * Permission to use, copy, modify, and/or distribute this software for any
4
+ * purpose with or without fee is hereby granted, provided that the above
5
+ * copyright notice and this permission notice appear in all copies.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
+
15
+ #ifndef OPENSSL_HEADER_CRYPTO_HPKE_INTERNAL_H
16
+ #define OPENSSL_HEADER_CRYPTO_HPKE_INTERNAL_H
17
+
18
+ #include <openssl/aead.h>
19
+ #include <openssl/base.h>
20
+ #include <openssl/curve25519.h>
21
+ #include <openssl/digest.h>
22
+
23
+ #if defined(__cplusplus)
24
+ extern "C" {
25
+ #endif
26
+
27
+
28
+ // Hybrid Public Key Encryption.
29
+ //
30
+ // Hybrid Public Key Encryption (HPKE) enables a sender to encrypt messages to a
31
+ // receiver with a public key.
32
+ //
33
+ // See https://tools.ietf.org/html/draft-irtf-cfrg-hpke-08.
34
+
35
+
36
+ // Parameters.
37
+ //
38
+ // An HPKE context is parameterized by KEM, KDF, and AEAD algorithms,
39
+ // represented by |EVP_HPKE_KEM|, |EVP_HPKE_KDF|, and |EVP_HPKE_AEAD| types,
40
+ // respectively.
41
+
42
+ // The following constants are KEM identifiers.
43
+ #define EVP_HPKE_DHKEM_X25519_HKDF_SHA256 0x0020
44
+
45
+ // The following functions are KEM algorithms which may be used with HPKE. Note
46
+ // that, while some HPKE KEMs use KDFs internally, this is separate from the
47
+ // |EVP_HPKE_KDF| selection.
48
+ OPENSSL_EXPORT const EVP_HPKE_KEM *EVP_hpke_x25519_hkdf_sha256(void);
49
+
50
+ // EVP_HPKE_KEM_id returns the HPKE KEM identifier for |kem|, which
51
+ // will be one of the |EVP_HPKE_KEM_*| constants.
52
+ OPENSSL_EXPORT uint16_t EVP_HPKE_KEM_id(const EVP_HPKE_KEM *kem);
53
+
54
+ // The following constants are KDF identifiers.
55
+ #define EVP_HPKE_HKDF_SHA256 0x0001
56
+
57
+ // The following functions are KDF algorithms which may be used with HPKE.
58
+ OPENSSL_EXPORT const EVP_HPKE_KDF *EVP_hpke_hkdf_sha256(void);
59
+
60
+ // EVP_HPKE_KDF_id returns the HPKE KDF identifier for |kdf|.
61
+ OPENSSL_EXPORT uint16_t EVP_HPKE_KDF_id(const EVP_HPKE_KDF *kdf);
62
+
63
+ // The following constants are AEAD identifiers.
64
+ #define EVP_HPKE_AES_128_GCM 0x0001
65
+ #define EVP_HPKE_AES_256_GCM 0x0002
66
+ #define EVP_HPKE_CHACHA20_POLY1305 0x0003
67
+
68
+ // The following functions are AEAD algorithms which may be used with HPKE.
69
+ OPENSSL_EXPORT const EVP_HPKE_AEAD *EVP_hpke_aes_128_gcm(void);
70
+ OPENSSL_EXPORT const EVP_HPKE_AEAD *EVP_hpke_aes_256_gcm(void);
71
+ OPENSSL_EXPORT const EVP_HPKE_AEAD *EVP_hpke_chacha20_poly1305(void);
72
+
73
+ // EVP_HPKE_AEAD_id returns the HPKE AEAD identifier for |aead|.
74
+ OPENSSL_EXPORT uint16_t EVP_HPKE_AEAD_id(const EVP_HPKE_AEAD *aead);
75
+
76
+ // EVP_HPKE_AEAD_aead returns the |EVP_AEAD| corresponding to |aead|.
77
+ OPENSSL_EXPORT const EVP_AEAD *EVP_HPKE_AEAD_aead(const EVP_HPKE_AEAD *aead);
78
+
79
+
80
+ // Recipient keys.
81
+ //
82
+ // An HPKE recipient maintains a long-term KEM key. This library represents keys
83
+ // with the |EVP_HPKE_KEY| type.
84
+
85
+ // EVP_HPKE_KEY_zero sets an uninitialized |EVP_HPKE_KEY| to the zero state. The
86
+ // caller should then use |EVP_HPKE_KEY_init|, |EVP_HPKE_KEY_copy|, or
87
+ // |EVP_HPKE_KEY_generate| to finish initializing |key|.
88
+ //
89
+ // It is safe, but not necessary to call |EVP_HPKE_KEY_cleanup| in this state.
90
+ // This may be used for more uniform cleanup of |EVP_HPKE_KEY|.
91
+ OPENSSL_EXPORT void EVP_HPKE_KEY_zero(EVP_HPKE_KEY *key);
92
+
93
+ // EVP_HPKE_KEY_cleanup releases memory referenced by |key|.
94
+ OPENSSL_EXPORT void EVP_HPKE_KEY_cleanup(EVP_HPKE_KEY *key);
95
+
96
+ // EVP_HPKE_KEY_copy sets |dst| to a copy of |src|. It returns one on success
97
+ // and zero on error. On success, the caller must call |EVP_HPKE_KEY_cleanup| to
98
+ // release |dst|. On failure, calling |EVP_HPKE_KEY_cleanup| is safe, but not
99
+ // necessary.
100
+ OPENSSL_EXPORT int EVP_HPKE_KEY_copy(EVP_HPKE_KEY *dst,
101
+ const EVP_HPKE_KEY *src);
102
+
103
+ // EVP_HPKE_KEY_init decodes |priv_key| as a private key for |kem| and
104
+ // initializes |key| with the result. It returns one on success and zero if
105
+ // |priv_key| was invalid. On success, the caller must call
106
+ // |EVP_HPKE_KEY_cleanup| to release the key. On failure, calling
107
+ // |EVP_HPKE_KEY_cleanup| is safe, but not necessary.
108
+ OPENSSL_EXPORT int EVP_HPKE_KEY_init(EVP_HPKE_KEY *key, const EVP_HPKE_KEM *kem,
109
+ const uint8_t *priv_key,
110
+ size_t priv_key_len);
111
+
112
+ // EVP_HPKE_KEY_generate sets |key| to a newly-generated key using |kem|.
113
+ OPENSSL_EXPORT int EVP_HPKE_KEY_generate(EVP_HPKE_KEY *key,
114
+ const EVP_HPKE_KEM *kem);
115
+
116
+ // EVP_HPKE_KEY_kem returns the HPKE KEM used by |key|.
117
+ OPENSSL_EXPORT const EVP_HPKE_KEM *EVP_HPKE_KEY_kem(const EVP_HPKE_KEY *key);
118
+
119
+ // EVP_HPKE_MAX_PUBLIC_KEY_LENGTH is the maximum length of a public key for all
120
+ // KEMs supported by this library.
121
+ #define EVP_HPKE_MAX_PUBLIC_KEY_LENGTH 32
122
+
123
+ // EVP_HPKE_KEY_public_key writes |key|'s public key to |out| and sets
124
+ // |*out_len| to the number of bytes written. On success, it returns one and
125
+ // writes at most |max_out| bytes. If |max_out| is too small, it returns zero.
126
+ // Setting |max_out| to |EVP_HPKE_MAX_PUBLIC_KEY_LENGTH| will ensure the public
127
+ // key fits.
128
+ OPENSSL_EXPORT int EVP_HPKE_KEY_public_key(const EVP_HPKE_KEY *key,
129
+ uint8_t *out, size_t *out_len,
130
+ size_t max_out);
131
+
132
+ // EVP_HPKE_MAX_PRIVATE_KEY_LENGTH is the maximum length of a private key for
133
+ // all KEMs supported by this library.
134
+ #define EVP_HPKE_MAX_PRIVATE_KEY_LENGTH 32
135
+
136
+ // EVP_HPKE_KEY_private_key writes |key|'s private key to |out| and sets
137
+ // |*out_len| to the number of bytes written. On success, it returns one and
138
+ // writes at most |max_out| bytes. If |max_out| is too small, it returns zero.
139
+ // Setting |max_out| to |EVP_HPKE_MAX_PRIVATE_KEY_LENGTH| will ensure the
140
+ // private key fits.
141
+ OPENSSL_EXPORT int EVP_HPKE_KEY_private_key(const EVP_HPKE_KEY *key,
142
+ uint8_t *out, size_t *out_len,
143
+ size_t max_out);
144
+
145
+
146
+ // Encryption contexts.
147
+ //
148
+ // An HPKE encryption context is represented by the |EVP_HPKE_CTX| type.
149
+
150
+ // EVP_HPKE_CTX_zero sets an uninitialized |EVP_HPKE_CTX| to the zero state. The
151
+ // caller should then use one of the |EVP_HPKE_CTX_setup_*| functions to finish
152
+ // setting up |ctx|.
153
+ //
154
+ // It is safe, but not necessary to call |EVP_HPKE_CTX_cleanup| in this state.
155
+ // This may be used for more uniform cleanup of |EVP_HPKE_CTX|.
156
+ OPENSSL_EXPORT void EVP_HPKE_CTX_zero(EVP_HPKE_CTX *ctx);
157
+
158
+ // EVP_HPKE_CTX_cleanup releases memory referenced by |ctx|. |ctx| must have
159
+ // been initialized with |EVP_HPKE_CTX_zero| or one of the
160
+ // |EVP_HPKE_CTX_setup_*| functions.
161
+ OPENSSL_EXPORT void EVP_HPKE_CTX_cleanup(EVP_HPKE_CTX *ctx);
162
+
163
+ // EVP_HPKE_MAX_ENC_LENGTH is the maximum length of "enc", the encapsulated
164
+ // shared secret, for all supported KEMs in this library.
165
+ #define EVP_HPKE_MAX_ENC_LENGTH 32
166
+
167
+ // EVP_HPKE_CTX_setup_sender implements the SetupBaseS HPKE operation. It
168
+ // encapsulates a shared secret for |peer_public_key| and sets up |ctx| as a
169
+ // sender context. It writes the encapsulated shared secret to |out_enc| and
170
+ // sets |*out_enc_len| to the number of bytes written. It writes at most
171
+ // |max_enc| bytes and fails if the buffer is too small. Setting |max_enc| to at
172
+ // least |EVP_HPKE_MAX_ENC_LENGTH| will ensure the buffer is large enough.
173
+ //
174
+ // This function returns one on success and zero on error. Note that
175
+ // |peer_public_key| may be invalid, in which case this function will return an
176
+ // error.
177
+ //
178
+ // On success, callers may call |EVP_HPKE_CTX_seal| to encrypt messages for the
179
+ // recipient. Callers must then call |EVP_HPKE_CTX_cleanup| when done. On
180
+ // failure, calling |EVP_HPKE_CTX_cleanup| is safe, but not required.
181
+ OPENSSL_EXPORT int EVP_HPKE_CTX_setup_sender(
182
+ EVP_HPKE_CTX *ctx, uint8_t *out_enc, size_t *out_enc_len, size_t max_enc,
183
+ const EVP_HPKE_KEM *kem, const EVP_HPKE_KDF *kdf, const EVP_HPKE_AEAD *aead,
184
+ const uint8_t *peer_public_key, size_t peer_public_key_len,
185
+ const uint8_t *info, size_t info_len);
186
+
187
+ // EVP_HPKE_CTX_setup_sender_with_seed_for_testing behaves like
188
+ // |EVP_HPKE_CTX_setup_sender|, but takes a seed to behave deterministically.
189
+ // The seed's format depends on |kem|. For X25519, it is the sender's
190
+ // ephemeral private key.
191
+ OPENSSL_EXPORT int EVP_HPKE_CTX_setup_sender_with_seed_for_testing(
192
+ EVP_HPKE_CTX *ctx, uint8_t *out_enc, size_t *out_enc_len, size_t max_enc,
193
+ const EVP_HPKE_KEM *kem, const EVP_HPKE_KDF *kdf, const EVP_HPKE_AEAD *aead,
194
+ const uint8_t *peer_public_key, size_t peer_public_key_len,
195
+ const uint8_t *info, size_t info_len, const uint8_t *seed, size_t seed_len);
196
+
197
+ // EVP_HPKE_CTX_setup_recipient implements the SetupBaseR HPKE operation. It
198
+ // decapsulates the shared secret in |enc| with |key| and sets up |ctx| as a
199
+ // recipient context. It returns one on success and zero on failure. Note that
200
+ // |enc| may be invalid, in which case this function will return an error.
201
+ //
202
+ // On success, callers may call |EVP_HPKE_CTX_open| to decrypt messages from the
203
+ // sender. Callers must then call |EVP_HPKE_CTX_cleanup| when done. On failure,
204
+ // calling |EVP_HPKE_CTX_cleanup| is safe, but not required.
205
+ OPENSSL_EXPORT int EVP_HPKE_CTX_setup_recipient(
206
+ EVP_HPKE_CTX *ctx, const EVP_HPKE_KEY *key, const EVP_HPKE_KDF *kdf,
207
+ const EVP_HPKE_AEAD *aead, const uint8_t *enc, size_t enc_len,
208
+ const uint8_t *info, size_t info_len);
209
+
210
+
211
+ // Using an HPKE context.
212
+ //
213
+ // Once set up, callers may encrypt or decrypt with an |EVP_HPKE_CTX| using the
214
+ // following functions.
215
+
216
+ // EVP_HPKE_CTX_open uses the HPKE context |ctx| to authenticate |in_len| bytes
217
+ // from |in| and |ad_len| bytes from |ad| and to decrypt at most |in_len| bytes
218
+ // into |out|. It returns one on success, and zero otherwise.
219
+ //
220
+ // This operation will fail if the |ctx| context is not set up as a receiver.
221
+ //
222
+ // Note that HPKE encryption is stateful and ordered. The sender's first call to
223
+ // |EVP_HPKE_CTX_seal| must correspond to the recipient's first call to
224
+ // |EVP_HPKE_CTX_open|, etc.
225
+ //
226
+ // At most |in_len| bytes are written to |out|. In order to ensure success,
227
+ // |max_out_len| should be at least |in_len|. On successful return, |*out_len|
228
+ // is set to the actual number of bytes written.
229
+ OPENSSL_EXPORT int EVP_HPKE_CTX_open(EVP_HPKE_CTX *ctx, uint8_t *out,
230
+ size_t *out_len, size_t max_out_len,
231
+ const uint8_t *in, size_t in_len,
232
+ const uint8_t *ad, size_t ad_len);
233
+
234
+ // EVP_HPKE_CTX_seal uses the HPKE context |ctx| to encrypt and authenticate
235
+ // |in_len| bytes of ciphertext |in| and authenticate |ad_len| bytes from |ad|,
236
+ // writing the result to |out|. It returns one on success and zero otherwise.
237
+ //
238
+ // This operation will fail if the |ctx| context is not set up as a sender.
239
+ //
240
+ // Note that HPKE encryption is stateful and ordered. The sender's first call to
241
+ // |EVP_HPKE_CTX_seal| must correspond to the recipient's first call to
242
+ // |EVP_HPKE_CTX_open|, etc.
243
+ //
244
+ // At most, |max_out_len| encrypted bytes are written to |out|. On successful
245
+ // return, |*out_len| is set to the actual number of bytes written.
246
+ //
247
+ // To ensure success, |max_out_len| should be |in_len| plus the result of
248
+ // |EVP_HPKE_CTX_max_overhead| or |EVP_HPKE_MAX_OVERHEAD|.
249
+ OPENSSL_EXPORT int EVP_HPKE_CTX_seal(EVP_HPKE_CTX *ctx, uint8_t *out,
250
+ size_t *out_len, size_t max_out_len,
251
+ const uint8_t *in, size_t in_len,
252
+ const uint8_t *ad, size_t ad_len);
253
+
254
+ // EVP_HPKE_CTX_export uses the HPKE context |ctx| to export a secret of
255
+ // |secret_len| bytes into |out|. This function uses |context_len| bytes from
256
+ // |context| as a context string for the secret. This is necessary to separate
257
+ // different uses of exported secrets and bind relevant caller-specific context
258
+ // into the output. It returns one on success and zero otherwise.
259
+ OPENSSL_EXPORT int EVP_HPKE_CTX_export(const EVP_HPKE_CTX *ctx, uint8_t *out,
260
+ size_t secret_len,
261
+ const uint8_t *context,
262
+ size_t context_len);
263
+
264
+ // EVP_HPKE_MAX_OVERHEAD contains the largest value that
265
+ // |EVP_HPKE_CTX_max_overhead| would ever return for any context.
266
+ #define EVP_HPKE_MAX_OVERHEAD EVP_AEAD_MAX_OVERHEAD
267
+
268
+ // EVP_HPKE_CTX_max_overhead returns the maximum number of additional bytes
269
+ // added by sealing data with |EVP_HPKE_CTX_seal|. The |ctx| context must be set
270
+ // up as a sender.
271
+ OPENSSL_EXPORT size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *ctx);
272
+
273
+ // EVP_HPKE_CTX_aead returns |ctx|'s configured AEAD, or NULL if the context has
274
+ // not been set up.
275
+ OPENSSL_EXPORT const EVP_HPKE_AEAD *EVP_HPKE_CTX_aead(const EVP_HPKE_CTX *ctx);
276
+
277
+ // EVP_HPKE_CTX_kdf returns |ctx|'s configured KDF, or NULL if the context has
278
+ // not been set up.
279
+ OPENSSL_EXPORT const EVP_HPKE_KDF *EVP_HPKE_CTX_kdf(const EVP_HPKE_CTX *ctx);
280
+
281
+
282
+ // Private structures.
283
+ //
284
+ // The following structures are exported so their types are stack-allocatable,
285
+ // but accessing or modifying their fields is forbidden.
286
+
287
+ struct evp_hpke_ctx_st {
288
+ const EVP_HPKE_AEAD *aead;
289
+ const EVP_HPKE_KDF *kdf;
290
+ EVP_AEAD_CTX aead_ctx;
291
+ uint8_t base_nonce[EVP_AEAD_MAX_NONCE_LENGTH];
292
+ uint8_t exporter_secret[EVP_MAX_MD_SIZE];
293
+ uint64_t seq;
294
+ int is_sender;
295
+ };
296
+
297
+ struct evp_hpke_key_st {
298
+ const EVP_HPKE_KEM *kem;
299
+ uint8_t private_key[X25519_PRIVATE_KEY_LEN];
300
+ uint8_t public_key[X25519_PUBLIC_VALUE_LEN];
301
+ };
302
+
303
+
304
+ #if defined(__cplusplus)
305
+ } // extern C
306
+ #endif
307
+
308
+ #if !defined(BORINGSSL_NO_CXX)
309
+ extern "C++" {
310
+
311
+ BSSL_NAMESPACE_BEGIN
312
+
313
+ using ScopedEVP_HPKE_CTX =
314
+ internal::StackAllocated<EVP_HPKE_CTX, void, EVP_HPKE_CTX_zero,
315
+ EVP_HPKE_CTX_cleanup>;
316
+ using ScopedEVP_HPKE_KEY =
317
+ internal::StackAllocated<EVP_HPKE_KEY, void, EVP_HPKE_KEY_zero,
318
+ EVP_HPKE_KEY_cleanup>;
319
+
320
+ BSSL_NAMESPACE_END
321
+
322
+ } // extern C++
323
+ #endif
324
+
325
+ #endif // OPENSSL_HEADER_CRYPTO_HPKE_INTERNAL_H
@@ -38,7 +38,10 @@ DECLARE_STACK_OF(X509_CRL)
38
38
  // success and zero on error. |cbs| is advanced passed the structure.
39
39
  //
40
40
  // Note that a SignedData structure may contain no certificates, in which case
41
- // this function succeeds but does not append any certificates.
41
+ // this function succeeds but does not append any certificates. Additionally,
42
+ // certificates in SignedData structures are unordered. Callers should not
43
+ // assume a particular order in |*out_certs| and may need to search for matches
44
+ // or run path-building algorithms.
42
45
  OPENSSL_EXPORT int PKCS7_get_raw_certificates(
43
46
  STACK_OF(CRYPTO_BUFFER) *out_certs, CBS *cbs, CRYPTO_BUFFER_POOL *pool);
44
47
 
@@ -47,7 +50,9 @@ OPENSSL_EXPORT int PKCS7_get_raw_certificates(
47
50
  OPENSSL_EXPORT int PKCS7_get_certificates(STACK_OF(X509) *out_certs, CBS *cbs);
48
51
 
49
52
  // PKCS7_bundle_certificates appends a PKCS#7, SignedData structure containing
50
- // |certs| to |out|. It returns one on success and zero on error.
53
+ // |certs| to |out|. It returns one on success and zero on error. Note that
54
+ // certificates in SignedData structures are unordered. The order in |certs|
55
+ // will not be preserved.
51
56
  OPENSSL_EXPORT int PKCS7_bundle_certificates(
52
57
  CBB *out, const STACK_OF(X509) *certs);
53
58
 
@@ -56,11 +61,15 @@ OPENSSL_EXPORT int PKCS7_bundle_certificates(
56
61
  // |cbs| is advanced passed the structure.
57
62
  //
58
63
  // Note that a SignedData structure may contain no CRLs, in which case this
59
- // function succeeds but does not append any CRLs.
64
+ // function succeeds but does not append any CRLs. Additionally, CRLs in
65
+ // SignedData structures are unordered. Callers should not assume an order in
66
+ // |*out_crls| and may need to search for matches.
60
67
  OPENSSL_EXPORT int PKCS7_get_CRLs(STACK_OF(X509_CRL) *out_crls, CBS *cbs);
61
68
 
62
69
  // PKCS7_bundle_CRLs appends a PKCS#7, SignedData structure containing
63
- // |crls| to |out|. It returns one on success and zero on error.
70
+ // |crls| to |out|. It returns one on success and zero on error. Note that CRLs
71
+ // in SignedData structures are unordered. The order in |crls| will not be
72
+ // preserved.
64
73
  OPENSSL_EXPORT int PKCS7_bundle_CRLs(CBB *out, const STACK_OF(X509_CRL) *crls);
65
74
 
66
75
  // PKCS7_get_PEM_certificates reads a PEM-encoded, PKCS#7, SignedData structure
@@ -68,7 +77,10 @@ OPENSSL_EXPORT int PKCS7_bundle_CRLs(CBB *out, const STACK_OF(X509_CRL) *crls);
68
77
  // returns one on success and zero on error.
69
78
  //
70
79
  // Note that a SignedData structure may contain no certificates, in which case
71
- // this function succeeds but does not append any certificates.
80
+ // this function succeeds but does not append any certificates. Additionally,
81
+ // certificates in SignedData structures are unordered. Callers should not
82
+ // assume a particular order in |*out_certs| and may need to search for matches
83
+ // or run path-building algorithms.
72
84
  OPENSSL_EXPORT int PKCS7_get_PEM_certificates(STACK_OF(X509) *out_certs,
73
85
  BIO *pem_bio);
74
86
 
@@ -77,7 +89,9 @@ OPENSSL_EXPORT int PKCS7_get_PEM_certificates(STACK_OF(X509) *out_certs,
77
89
  // success and zero on error.
78
90
  //
79
91
  // Note that a SignedData structure may contain no CRLs, in which case this
80
- // function succeeds but does not append any CRLs.
92
+ // function succeeds but does not append any CRLs. Additionally, CRLs in
93
+ // SignedData structures are unordered. Callers should not assume an order in
94
+ // |*out_crls| and may need to search for matches.
81
95
  OPENSSL_EXPORT int PKCS7_get_PEM_CRLs(STACK_OF(X509_CRL) *out_crls,
82
96
  BIO *pem_bio);
83
97
 
@@ -192,7 +206,9 @@ OPENSSL_EXPORT int PKCS7_type_is_signedAndEnveloped(const PKCS7 *p7);
192
206
  // ignored. |flags| must be equal to |PKCS7_DETACHED|.
193
207
  //
194
208
  // Note this function only implements a subset of the corresponding OpenSSL
195
- // function. It is provided for backwards compatibility only.
209
+ // function. It is provided for backwards compatibility only. Additionally,
210
+ // certificates in SignedData structures are unordered. The order of |certs|
211
+ // will not be preserved.
196
212
  OPENSSL_EXPORT PKCS7 *PKCS7_sign(X509 *sign_cert, EVP_PKEY *pkey,
197
213
  STACK_OF(X509) *certs, BIO *data, int flags);
198
214
 
@@ -283,120 +283,155 @@ OPENSSL_EXPORT int RSA_private_decrypt(size_t flen, const uint8_t *from,
283
283
  // These functions are considered non-mutating for thread-safety purposes and
284
284
  // may be used concurrently.
285
285
 
286
- // RSA_sign signs |in_len| bytes of digest from |in| with |rsa| using
286
+ // RSA_sign signs |digest_len| bytes of digest from |digest| with |rsa| using
287
287
  // RSASSA-PKCS1-v1_5. It writes, at most, |RSA_size(rsa)| bytes to |out|. On
288
288
  // successful return, the actual number of bytes written is written to
289
289
  // |*out_len|.
290
290
  //
291
- // The |hash_nid| argument identifies the hash function used to calculate |in|
292
- // and is embedded in the resulting signature. For example, it might be
291
+ // The |hash_nid| argument identifies the hash function used to calculate
292
+ // |digest| and is embedded in the resulting signature. For example, it might be
293
293
  // |NID_sha256|.
294
294
  //
295
295
  // It returns 1 on success and zero on error.
296
- OPENSSL_EXPORT int RSA_sign(int hash_nid, const uint8_t *in,
297
- unsigned int in_len, uint8_t *out,
298
- unsigned int *out_len, RSA *rsa);
296
+ //
297
+ // WARNING: |digest| must be the result of hashing the data to be signed with
298
+ // |hash_nid|. Passing unhashed inputs will not result in a secure signature
299
+ // scheme.
300
+ OPENSSL_EXPORT int RSA_sign(int hash_nid, const uint8_t *digest,
301
+ unsigned digest_len, uint8_t *out,
302
+ unsigned *out_len, RSA *rsa);
299
303
 
300
- // RSA_sign_pss_mgf1 signs |in_len| bytes from |in| with the public key from
301
- // |rsa| using RSASSA-PSS with MGF1 as the mask generation function. It writes,
302
- // at most, |max_out| bytes of signature data to |out|. The |max_out| argument
303
- // must be, at least, |RSA_size| in order to ensure success. It returns 1 on
304
- // success or zero on error.
304
+ // RSA_sign_pss_mgf1 signs |digest_len| bytes from |digest| with the public key
305
+ // from |rsa| using RSASSA-PSS with MGF1 as the mask generation function. It
306
+ // writes, at most, |max_out| bytes of signature data to |out|. The |max_out|
307
+ // argument must be, at least, |RSA_size| in order to ensure success. It returns
308
+ // 1 on success or zero on error.
305
309
  //
306
- // The |md| and |mgf1_md| arguments identify the hash used to calculate |msg|
310
+ // The |md| and |mgf1_md| arguments identify the hash used to calculate |digest|
307
311
  // and the MGF1 hash, respectively. If |mgf1_md| is NULL, |md| is
308
312
  // used.
309
313
  //
310
314
  // |salt_len| specifies the expected salt length in bytes. If |salt_len| is -1,
311
315
  // then the salt length is the same as the hash length. If -2, then the salt
312
316
  // length is maximal given the size of |rsa|. If unsure, use -1.
317
+ //
318
+ // WARNING: |digest| must be the result of hashing the data to be signed with
319
+ // |md|. Passing unhashed inputs will not result in a secure signature scheme.
313
320
  OPENSSL_EXPORT int RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, uint8_t *out,
314
- size_t max_out, const uint8_t *in,
315
- size_t in_len, const EVP_MD *md,
321
+ size_t max_out, const uint8_t *digest,
322
+ size_t digest_len, const EVP_MD *md,
316
323
  const EVP_MD *mgf1_md, int salt_len);
317
324
 
318
- // RSA_sign_raw signs |in_len| bytes from |in| with the public key from |rsa|
319
- // and writes, at most, |max_out| bytes of signature data to |out|. The
320
- // |max_out| argument must be, at least, |RSA_size| in order to ensure success.
321
- //
322
- // It returns 1 on success or zero on error.
323
- //
324
- // The |padding| argument must be one of the |RSA_*_PADDING| values. If in
325
- // doubt, |RSA_PKCS1_PADDING| is the most common but |RSA_PKCS1_PSS_PADDING|
326
- // (via |RSA_sign_pss_mgf1| or the |EVP_PKEY| interface) is preferred for new
327
- // protocols.
325
+ // RSA_sign_raw performs the private key portion of computing a signature with
326
+ // |rsa|. It writes, at most, |max_out| bytes of signature data to |out|. The
327
+ // |max_out| argument must be, at least, |RSA_size| in order to ensure the
328
+ // output fits. It returns 1 on success or zero on error.
329
+ //
330
+ // If |padding| is |RSA_PKCS1_PADDING|, this function wraps |in| with the
331
+ // padding portion of RSASSA-PKCS1-v1_5 and then performs the raw private key
332
+ // operation. The caller is responsible for hashing the input and wrapping it in
333
+ // a DigestInfo structure.
334
+ //
335
+ // If |padding| is |RSA_NO_PADDING|, this function only performs the raw private
336
+ // key operation, interpreting |in| as a integer modulo n. The caller is
337
+ // responsible for hashing the input and encoding it for the signature scheme
338
+ // being implemented.
339
+ //
340
+ // WARNING: This function is a building block for a signature scheme, not a
341
+ // complete one. |in| must be the result of hashing and encoding the data as
342
+ // needed for the scheme being implemented. Passing in arbitrary inputs will not
343
+ // result in a secure signature scheme.
328
344
  OPENSSL_EXPORT int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out,
329
345
  size_t max_out, const uint8_t *in,
330
346
  size_t in_len, int padding);
331
347
 
332
348
  // RSA_verify verifies that |sig_len| bytes from |sig| are a valid,
333
- // RSASSA-PKCS1-v1_5 signature of |msg_len| bytes at |msg| by |rsa|.
349
+ // RSASSA-PKCS1-v1_5 signature of |digest_len| bytes at |digest| by |rsa|.
334
350
  //
335
- // The |hash_nid| argument identifies the hash function used to calculate |msg|
336
- // and is embedded in the resulting signature in order to prevent hash
351
+ // The |hash_nid| argument identifies the hash function used to calculate
352
+ // |digest| and is embedded in the resulting signature in order to prevent hash
337
353
  // confusion attacks. For example, it might be |NID_sha256|.
338
354
  //
339
355
  // It returns one if the signature is valid and zero otherwise.
340
356
  //
341
357
  // WARNING: this differs from the original, OpenSSL function which additionally
342
358
  // returned -1 on error.
343
- OPENSSL_EXPORT int RSA_verify(int hash_nid, const uint8_t *msg, size_t msg_len,
344
- const uint8_t *sig, size_t sig_len, RSA *rsa);
359
+ //
360
+ // WARNING: |digest| must be the result of hashing the data to be verified with
361
+ // |hash_nid|. Passing unhashed input will not result in a secure signature
362
+ // scheme.
363
+ OPENSSL_EXPORT int RSA_verify(int hash_nid, const uint8_t *digest,
364
+ size_t digest_len, const uint8_t *sig,
365
+ size_t sig_len, RSA *rsa);
345
366
 
346
367
  // RSA_verify_pss_mgf1 verifies that |sig_len| bytes from |sig| are a valid,
347
- // RSASSA-PSS signature of |msg_len| bytes at |msg| by |rsa|. It returns one if
348
- // the signature is valid and zero otherwise. MGF1 is used as the mask
368
+ // RSASSA-PSS signature of |digest_len| bytes at |digest| by |rsa|. It returns
369
+ // one if the signature is valid and zero otherwise. MGF1 is used as the mask
349
370
  // generation function.
350
371
  //
351
- // The |md| and |mgf1_md| arguments identify the hash used to calculate |msg|
372
+ // The |md| and |mgf1_md| arguments identify the hash used to calculate |digest|
352
373
  // and the MGF1 hash, respectively. If |mgf1_md| is NULL, |md| is
353
374
  // used. |salt_len| specifies the expected salt length in bytes.
354
375
  //
355
376
  // If |salt_len| is -1, then the salt length is the same as the hash length. If
356
377
  // -2, then the salt length is recovered and all values accepted. If unsure, use
357
378
  // -1.
358
- OPENSSL_EXPORT int RSA_verify_pss_mgf1(RSA *rsa, const uint8_t *msg,
359
- size_t msg_len, const EVP_MD *md,
379
+ //
380
+ // WARNING: |digest| must be the result of hashing the data to be verified with
381
+ // |md|. Passing unhashed input will not result in a secure signature scheme.
382
+ OPENSSL_EXPORT int RSA_verify_pss_mgf1(RSA *rsa, const uint8_t *digest,
383
+ size_t digest_len, const EVP_MD *md,
360
384
  const EVP_MD *mgf1_md, int salt_len,
361
385
  const uint8_t *sig, size_t sig_len);
362
386
 
363
- // RSA_verify_raw verifies |in_len| bytes of signature from |in| using the
364
- // public key from |rsa| and writes, at most, |max_out| bytes of plaintext to
365
- // |out|. The |max_out| argument must be, at least, |RSA_size| in order to
366
- // ensure success.
387
+ // RSA_verify_raw performs the public key portion of verifying |in_len| bytes of
388
+ // signature from |in| using the public key from |rsa|. On success, it returns
389
+ // one and writes, at most, |max_out| bytes of output to |out|. The |max_out|
390
+ // argument must be, at least, |RSA_size| in order to ensure the output fits. On
391
+ // failure or invalid input, it returns zero.
367
392
  //
368
- // It returns 1 on success or zero on error.
393
+ // If |padding| is |RSA_PKCS1_PADDING|, this function checks the padding portion
394
+ // of RSASSA-PKCS1-v1_5 and outputs the remainder of the encoded digest. The
395
+ // caller is responsible for checking the output is a DigestInfo-wrapped digest
396
+ // of the message.
369
397
  //
370
- // The |padding| argument must be one of the |RSA_*_PADDING| values. If in
371
- // doubt, |RSA_PKCS1_PADDING| is the most common but |RSA_PKCS1_PSS_PADDING|
372
- // (via |RSA_verify_pss_mgf1| or the |EVP_PKEY| interface) is preferred for new
373
- // protocols.
398
+ // If |padding| is |RSA_NO_PADDING|, this function only performs the raw public
399
+ // key operation. The caller is responsible for checking the output is a valid
400
+ // result for the signature scheme being implemented.
401
+ //
402
+ // WARNING: This function is a building block for a signature scheme, not a
403
+ // complete one. Checking for arbitrary strings in |out| will not result in a
404
+ // secure signature scheme.
374
405
  OPENSSL_EXPORT int RSA_verify_raw(RSA *rsa, size_t *out_len, uint8_t *out,
375
406
  size_t max_out, const uint8_t *in,
376
407
  size_t in_len, int padding);
377
408
 
378
- // RSA_private_encrypt encrypts |flen| bytes from |from| with the private key in
379
- // |rsa| and writes the encrypted data to |to|. The |to| buffer must have at
380
- // least |RSA_size| bytes of space. It returns the number of bytes written, or
381
- // -1 on error. The |padding| argument must be one of the |RSA_*_PADDING|
382
- // values. If in doubt, |RSA_PKCS1_PADDING| is the most common but
383
- // |RSA_PKCS1_PSS_PADDING| (via the |EVP_PKEY| interface) is preferred for new
384
- // protocols.
409
+ // RSA_private_encrypt performs the private key portion of computing a signature
410
+ // with |rsa|. It takes |flen| bytes from |from| as input and writes the result
411
+ // to |to|. The |to| buffer must have at least |RSA_size| bytes of space. It
412
+ // returns the number of bytes written, or -1 on error.
385
413
  //
386
- // WARNING: this function is dangerous because it breaks the usual return value
414
+ // For the interpretation of |padding| and the input, see |RSA_sign_raw|.
415
+ //
416
+ // WARNING: This function is a building block for a signature scheme, not a
417
+ // complete one. See |RSA_sign_raw| for details.
418
+ //
419
+ // WARNING: This function is dangerous because it breaks the usual return value
387
420
  // convention. Use |RSA_sign_raw| instead.
388
421
  OPENSSL_EXPORT int RSA_private_encrypt(size_t flen, const uint8_t *from,
389
422
  uint8_t *to, RSA *rsa, int padding);
390
423
 
391
- // RSA_public_decrypt verifies |flen| bytes of signature from |from| using the
392
- // public key in |rsa| and writes the plaintext to |to|. The |to| buffer must
393
- // have at least |RSA_size| bytes of space. It returns the number of bytes
394
- // written, or -1 on error. The |padding| argument must be one of the
395
- // |RSA_*_PADDING| values. If in doubt, |RSA_PKCS1_PADDING| is the most common
396
- // but |RSA_PKCS1_PSS_PADDING| (via the |EVP_PKEY| interface) is preferred for
397
- // new protocols.
424
+ // RSA_public_decrypt performs the public key portion of verifying |flen| bytes
425
+ // of signature from |from| using the public key from |rsa|. It writes the
426
+ // result to |to|, which must have at least |RSA_size| bytes of space. It
427
+ // returns the number of bytes written, or -1 on error.
398
428
  //
399
- // WARNING: this function is dangerous because it breaks the usual return value
429
+ // For the interpretation of |padding| and the result, see |RSA_verify_raw|.
430
+ //
431
+ // WARNING: This function is a building block for a signature scheme, not a
432
+ // complete one. See |RSA_verify_raw| for details.
433
+ //
434
+ // WARNING: This function is dangerous because it breaks the usual return value
400
435
  // convention. Use |RSA_verify_raw| instead.
401
436
  OPENSSL_EXPORT int RSA_public_decrypt(size_t flen, const uint8_t *from,
402
437
  uint8_t *to, RSA *rsa, int padding);
@@ -479,13 +514,14 @@ OPENSSL_EXPORT int RSA_padding_add_PKCS1_OAEP_mgf1(
479
514
  const uint8_t *param, size_t param_len, const EVP_MD *md,
480
515
  const EVP_MD *mgf1md);
481
516
 
482
- // RSA_add_pkcs1_prefix builds a version of |msg| prefixed with the DigestInfo
483
- // header for the given hash function and sets |out_msg| to point to it. On
484
- // successful return, if |*is_alloced| is one, the caller must release
517
+ // RSA_add_pkcs1_prefix builds a version of |digest| prefixed with the
518
+ // DigestInfo header for the given hash function and sets |out_msg| to point to
519
+ // it. On successful return, if |*is_alloced| is one, the caller must release
485
520
  // |*out_msg| with |OPENSSL_free|.
486
521
  OPENSSL_EXPORT int RSA_add_pkcs1_prefix(uint8_t **out_msg, size_t *out_msg_len,
487
522
  int *is_alloced, int hash_nid,
488
- const uint8_t *msg, size_t msg_len);
523
+ const uint8_t *digest,
524
+ size_t digest_len);
489
525
 
490
526
 
491
527
  // ASN.1 functions.