grpc 1.56.2 → 1.57.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (383) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +29 -22
  3. data/include/grpc/event_engine/event_engine.h +22 -32
  4. data/include/grpc/impl/grpc_types.h +3 -0
  5. data/include/grpc/support/port_platform.h +29 -23
  6. data/src/core/ext/filters/client_channel/client_channel.cc +44 -8
  7. data/src/core/ext/filters/client_channel/dynamic_filters.h +3 -3
  8. data/src/core/ext/filters/client_channel/http_proxy.cc +5 -0
  9. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +21 -52
  10. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +19 -7
  11. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +25 -35
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +78 -132
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +2 -1
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +4 -3
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -1
  16. data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +38 -15
  17. data/src/core/ext/filters/client_channel/lb_policy/health_check_client.h +3 -5
  18. data/src/core/ext/filters/client_channel/lb_policy/health_check_client_internal.h +22 -6
  19. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric_internal.h +2 -0
  20. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +97 -71
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +2 -16
  22. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +56 -11
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.h +25 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +6 -32
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +4 -6
  26. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +20 -79
  27. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +1 -1
  28. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -19
  29. data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +1 -1
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +7 -41
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +3 -67
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +8 -0
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +31 -74
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +7 -51
  35. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +16 -87
  36. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc +16 -50
  37. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc +12 -74
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -4
  39. data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +69 -59
  40. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +7 -2
  41. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +1 -0
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +25 -13
  43. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +366 -311
  44. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +17 -1
  45. data/src/core/ext/filters/client_channel/retry_filter.cc +39 -2498
  46. data/src/core/ext/filters/client_channel/retry_filter.h +91 -1
  47. data/src/core/ext/filters/client_channel/retry_filter_legacy_call_data.cc +2052 -0
  48. data/src/core/ext/filters/client_channel/retry_filter_legacy_call_data.h +442 -0
  49. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +38 -58
  50. data/src/core/ext/filters/client_channel/subchannel.h +3 -3
  51. data/src/core/ext/filters/client_channel/subchannel_interface_internal.h +3 -0
  52. data/src/core/ext/filters/rbac/rbac_filter.cc +40 -111
  53. data/src/core/ext/filters/rbac/rbac_filter.h +12 -30
  54. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +162 -86
  55. data/src/core/ext/filters/stateful_session/stateful_session_filter.h +0 -6
  56. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +7 -4
  57. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +131 -186
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +6569 -174
  59. data/src/core/ext/transport/chttp2/transport/decode_huff.h +2278 -441
  60. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +2 -3
  61. data/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +4 -3
  62. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +9 -8
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +4 -4
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +3 -2
  65. data/src/core/ext/transport/chttp2/transport/internal.h +8 -4
  66. data/src/core/ext/transport/chttp2/transport/parsing.cc +15 -3
  67. data/src/core/ext/transport/chttp2/transport/writing.cc +2 -3
  68. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +27 -6
  69. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +143 -0
  70. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +2 -9
  71. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +0 -39
  72. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +13 -8
  73. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +35 -6
  74. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +17 -13
  75. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +85 -20
  76. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +26 -7
  77. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +45 -3
  78. data/src/core/ext/upb-generated/envoy/config/metrics/v3/metrics_service.upb.c +4 -3
  79. data/src/core/ext/upb-generated/envoy/config/metrics/v3/metrics_service.upb.h +21 -0
  80. data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.c +30 -6
  81. data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.h +180 -0
  82. data/src/core/ext/upb-generated/envoy/data/accesslog/v3/accesslog.upb.c +558 -0
  83. data/src/core/ext/upb-generated/envoy/data/accesslog/v3/accesslog.upb.h +2710 -0
  84. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +30 -11
  85. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +53 -24
  86. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +30 -5
  87. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +110 -0
  88. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +41 -15
  89. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +150 -27
  90. data/src/core/ext/upb-generated/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb.c +1 -0
  91. data/src/core/ext/upb-generated/envoy/extensions/load_balancing_policies/pick_first/v3/pick_first.upb.c +47 -0
  92. data/src/core/ext/upb-generated/envoy/extensions/load_balancing_policies/pick_first/v3/pick_first.upb.h +93 -0
  93. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +88 -76
  94. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +5 -0
  95. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +11 -12
  96. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +0 -5
  97. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +162 -160
  98. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +129 -118
  99. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +141 -135
  100. data/src/core/ext/upbdefs-generated/envoy/config/metrics/v3/metrics_service.upbdefs.c +19 -12
  101. data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.c +38 -30
  102. data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.h +5 -0
  103. data/src/core/ext/upbdefs-generated/envoy/data/accesslog/v3/accesslog.upbdefs.c +402 -0
  104. data/src/core/ext/upbdefs-generated/envoy/data/accesslog/v3/accesslog.upbdefs.h +111 -0
  105. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +80 -74
  106. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +63 -47
  107. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.h +5 -0
  108. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +315 -293
  109. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -0
  110. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +29 -29
  111. data/src/core/ext/xds/xds_bootstrap_grpc.cc +33 -30
  112. data/src/core/ext/xds/xds_bootstrap_grpc.h +5 -13
  113. data/src/core/ext/xds/xds_client_grpc.cc +11 -6
  114. data/src/core/ext/xds/xds_client_grpc.h +16 -2
  115. data/src/core/ext/xds/xds_client_stats.h +10 -0
  116. data/src/core/ext/xds/xds_cluster.cc +26 -16
  117. data/src/core/ext/xds/xds_endpoint.cc +4 -7
  118. data/src/core/ext/xds/xds_health_status.cc +0 -17
  119. data/src/core/ext/xds/xds_health_status.h +5 -25
  120. data/src/core/ext/xds/xds_lb_policy_registry.cc +39 -0
  121. data/src/core/ext/xds/xds_route_config.cc +4 -0
  122. data/src/core/ext/xds/xds_transport_grpc.cc +1 -3
  123. data/src/core/lib/address_utils/parse_address.cc +63 -1
  124. data/src/core/lib/address_utils/parse_address.h +8 -0
  125. data/src/core/lib/address_utils/sockaddr_utils.cc +46 -1
  126. data/src/core/lib/address_utils/sockaddr_utils.h +2 -2
  127. data/src/core/lib/channel/channel_args.cc +21 -10
  128. data/src/core/lib/channel/channel_args.h +3 -0
  129. data/src/core/lib/channel/connected_channel.cc +4 -1
  130. data/src/core/lib/channel/promise_based_filter.h +1 -0
  131. data/src/core/lib/debug/trace.cc +1 -4
  132. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +2 -1
  133. data/src/core/lib/event_engine/cf_engine/cf_engine.h +1 -1
  134. data/src/core/lib/event_engine/event_engine.cc +0 -12
  135. data/src/core/lib/event_engine/forkable.cc +47 -42
  136. data/src/core/lib/event_engine/handle_containers.h +0 -4
  137. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +4 -6
  138. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +4 -6
  139. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +25 -11
  140. data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +3 -1
  141. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +2 -1
  142. data/src/core/lib/event_engine/posix_engine/posix_engine.h +8 -12
  143. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +37 -27
  144. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.h +2 -0
  145. data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +4 -2
  146. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +42 -2
  147. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +6 -0
  148. data/src/core/lib/event_engine/posix_engine/timer.h +10 -37
  149. data/src/core/lib/event_engine/tcp_socket_utils.cc +67 -7
  150. data/src/core/lib/event_engine/tcp_socket_utils.h +3 -0
  151. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +90 -37
  152. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +32 -12
  153. data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.cc +12 -21
  154. data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.h +8 -12
  155. data/src/core/lib/event_engine/windows/windows_endpoint.cc +55 -54
  156. data/src/core/lib/event_engine/windows/windows_endpoint.h +15 -12
  157. data/src/core/lib/event_engine/windows/windows_engine.cc +2 -1
  158. data/src/core/lib/event_engine/windows/windows_engine.h +8 -12
  159. data/src/core/lib/experiments/config.cc +60 -22
  160. data/src/core/lib/experiments/config.h +20 -8
  161. data/src/core/lib/experiments/experiments.cc +278 -0
  162. data/src/core/lib/experiments/experiments.h +59 -1
  163. data/src/core/lib/gprpp/dual_ref_counted.h +9 -9
  164. data/src/core/lib/gprpp/fork.cc +8 -9
  165. data/src/core/lib/gprpp/fork.h +6 -5
  166. data/src/core/lib/gprpp/if_list.h +4530 -0
  167. data/src/core/lib/gprpp/orphanable.h +3 -3
  168. data/src/core/lib/gprpp/ref_counted.h +6 -6
  169. data/src/core/lib/gprpp/sorted_pack.h +3 -12
  170. data/src/core/lib/gprpp/status_helper.h +16 -15
  171. data/src/core/lib/gprpp/time.h +12 -0
  172. data/src/core/lib/gprpp/type_list.h +32 -0
  173. data/src/core/lib/http/httpcli.h +6 -9
  174. data/src/core/lib/iomgr/error.cc +32 -2
  175. data/src/core/lib/iomgr/error.h +9 -10
  176. data/src/core/lib/iomgr/ev_epoll1_linux.cc +5 -7
  177. data/src/core/lib/iomgr/ev_poll_posix.cc +6 -5
  178. data/src/core/lib/iomgr/exec_ctx.h +11 -0
  179. data/src/core/lib/iomgr/pollset.h +4 -5
  180. data/src/core/lib/iomgr/port.h +10 -0
  181. data/src/core/lib/iomgr/resolve_address.cc +13 -1
  182. data/src/core/lib/iomgr/resolve_address.h +17 -3
  183. data/src/core/lib/iomgr/sockaddr_posix.h +7 -0
  184. data/src/core/lib/iomgr/socket_utils_common_posix.cc +29 -0
  185. data/src/core/lib/iomgr/socket_utils_posix.cc +2 -0
  186. data/src/core/lib/iomgr/socket_utils_posix.h +6 -0
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
  188. data/src/core/lib/iomgr/tcp_posix.cc +21 -4
  189. data/src/core/lib/iomgr/tcp_server_posix.cc +3 -2
  190. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -2
  191. data/src/core/lib/iomgr/tcp_windows.cc +1 -3
  192. data/src/core/lib/iomgr/vsock.cc +59 -0
  193. data/src/core/lib/iomgr/vsock.h +38 -0
  194. data/src/core/lib/iomgr/wakeup_fd_posix.h +3 -6
  195. data/src/core/lib/load_balancing/delegating_helper.h +115 -0
  196. data/src/core/lib/load_balancing/lb_policy.h +20 -0
  197. data/src/core/lib/load_balancing/subchannel_interface.h +6 -0
  198. data/src/core/lib/promise/party.h +1 -1
  199. data/src/core/lib/resolver/resolver_factory.h +3 -2
  200. data/src/core/lib/resolver/server_address.cc +9 -94
  201. data/src/core/lib/resolver/server_address.h +10 -64
  202. data/src/core/lib/resource_quota/memory_quota.h +1 -1
  203. data/src/core/lib/security/credentials/channel_creds_registry.h +51 -27
  204. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +169 -9
  205. data/src/core/lib/security/credentials/composite/composite_credentials.cc +1 -1
  206. data/src/core/lib/security/credentials/composite/composite_credentials.h +3 -1
  207. data/src/core/lib/security/credentials/external/external_account_credentials.cc +40 -1
  208. data/src/core/lib/security/credentials/external/external_account_credentials.h +6 -0
  209. data/src/core/lib/security/credentials/fake/fake_credentials.cc +30 -38
  210. data/src/core/lib/security/credentials/fake/fake_credentials.h +28 -0
  211. data/src/core/lib/security/credentials/tls/tls_credentials.cc +1 -1
  212. data/src/core/lib/security/credentials/tls/tls_credentials.h +3 -1
  213. data/src/core/lib/service_config/service_config_call_data.h +5 -0
  214. data/src/core/lib/slice/slice.h +16 -0
  215. data/src/core/lib/surface/call.cc +31 -29
  216. data/src/core/lib/surface/server.h +2 -2
  217. data/src/core/lib/surface/version.cc +2 -2
  218. data/src/core/lib/transport/metadata_batch.cc +7 -7
  219. data/src/core/lib/transport/metadata_batch.h +86 -48
  220. data/src/core/lib/transport/parsed_metadata.h +34 -20
  221. data/src/core/lib/transport/simple_slice_based_metadata.h +9 -2
  222. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +4 -6
  223. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -2
  224. data/src/core/tsi/ssl_transport_security.cc +28 -7
  225. data/src/ruby/bin/math_pb.rb +24 -18
  226. data/src/ruby/ext/grpc/extconf.rb +19 -18
  227. data/src/ruby/ext/grpc/rb_call.c +62 -39
  228. data/src/ruby/ext/grpc/rb_call_credentials.c +0 -1
  229. data/src/ruby/ext/grpc/rb_channel.c +126 -49
  230. data/src/ruby/ext/grpc/rb_channel.h +1 -0
  231. data/src/ruby/ext/grpc/rb_channel_args.c +16 -2
  232. data/src/ruby/ext/grpc/rb_channel_args.h +4 -0
  233. data/src/ruby/ext/grpc/rb_channel_credentials.c +0 -1
  234. data/src/ruby/ext/grpc/rb_compression_options.c +0 -1
  235. data/src/ruby/ext/grpc/rb_event_thread.c +22 -6
  236. data/src/ruby/ext/grpc/rb_event_thread.h +1 -0
  237. data/src/ruby/ext/grpc/rb_grpc.c +192 -30
  238. data/src/ruby/ext/grpc/rb_grpc.h +8 -2
  239. data/src/ruby/ext/grpc/rb_server.c +62 -45
  240. data/src/ruby/ext/grpc/rb_server_credentials.c +0 -1
  241. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +0 -1
  242. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +0 -1
  243. data/src/ruby/lib/grpc/generic/bidi_call.rb +2 -0
  244. data/src/ruby/lib/grpc/version.rb +1 -1
  245. data/src/ruby/pb/grpc/health/v1/health_pb.rb +24 -13
  246. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +24 -3
  247. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +25 -111
  248. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +25 -2
  249. data/third_party/boringssl-with-bazel/err_data.c +552 -552
  250. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strnid.c +5 -5
  251. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +34 -1
  252. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +4 -1
  253. data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +3 -3
  254. data/third_party/boringssl-with-bazel/src/crypto/bio/bio_mem.c +7 -8
  255. data/third_party/boringssl-with-bazel/src/crypto/bio/connect.c +2 -2
  256. data/third_party/boringssl-with-bazel/src/crypto/bio/fd.c +2 -2
  257. data/third_party/boringssl-with-bazel/src/crypto/bio/file.c +8 -8
  258. data/third_party/boringssl-with-bazel/src/crypto/bio/socket.c +2 -2
  259. data/third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.c +2 -2
  260. data/third_party/boringssl-with-bazel/src/crypto/chacha/chacha.c +19 -1
  261. data/third_party/boringssl-with-bazel/src/crypto/chacha/internal.h +8 -1
  262. data/third_party/boringssl-with-bazel/src/crypto/conf/conf.c +28 -185
  263. data/third_party/boringssl-with-bazel/src/crypto/conf/conf_def.h +3 -7
  264. data/third_party/boringssl-with-bazel/src/crypto/conf/internal.h +8 -0
  265. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_apple.c +3 -0
  266. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +49 -46
  267. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519_64_adx.c +18 -0
  268. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519_tables.h +2809 -7417
  269. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +27 -5
  270. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +20 -0
  271. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/ec_asn1.c +110 -72
  272. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/ec_derive.c +4 -3
  273. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +15 -14
  274. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +13 -10
  275. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +35 -12
  276. data/third_party/boringssl-with-bazel/src/crypto/evp/p_ec.c +2 -4
  277. data/third_party/boringssl-with-bazel/src/crypto/evp/p_ec_asn1.c +3 -7
  278. data/third_party/boringssl-with-bazel/src/crypto/evp/pbkdf.c +3 -3
  279. data/third_party/boringssl-with-bazel/src/crypto/evp/print.c +7 -6
  280. data/third_party/boringssl-with-bazel/src/crypto/ex_data.c +34 -72
  281. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +1 -1
  282. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/div.c +12 -5
  283. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/gcd.c +5 -6
  284. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +12 -6
  285. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +17 -18
  286. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery_inv.c +51 -15
  287. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/rsaz_exp.c +7 -7
  288. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/delocate.h +5 -6
  289. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/internal.h +2 -0
  290. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/builtin_curves.h +277 -0
  291. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +180 -404
  292. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +3 -3
  293. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +24 -57
  294. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/felem.c +17 -13
  295. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +33 -71
  296. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +18 -17
  297. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +5 -7
  298. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-nistz.c +15 -18
  299. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +9 -11
  300. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/scalar.c +24 -24
  301. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +11 -27
  302. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +8 -8
  303. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +4 -4
  304. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +9 -3
  305. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/hkdf/hkdf.c +1 -1
  306. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +40 -26
  307. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +21 -7
  308. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +38 -19
  309. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +2 -29
  310. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +55 -0
  311. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +33 -52
  312. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +3 -8
  313. data/third_party/boringssl-with-bazel/src/crypto/internal.h +198 -79
  314. data/third_party/boringssl-with-bazel/src/crypto/kyber/kyber.c +5 -4
  315. data/third_party/boringssl-with-bazel/src/crypto/mem.c +7 -8
  316. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +19 -23
  317. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +3 -3
  318. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/p5_pbev2.c +3 -3
  319. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +7 -7
  320. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +8 -5
  321. data/third_party/boringssl-with-bazel/src/crypto/pool/internal.h +1 -0
  322. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +7 -6
  323. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/forkunsafe.c +6 -12
  324. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/getentropy.c +48 -0
  325. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{fuchsia.c → ios.c} +8 -8
  326. data/third_party/boringssl-with-bazel/src/crypto/{refcount_no_threads.c → rand_extra/trusty.c} +15 -19
  327. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +41 -19
  328. data/third_party/boringssl-with-bazel/src/crypto/{refcount_c11.c → refcount.c} +11 -17
  329. data/third_party/boringssl-with-bazel/src/crypto/stack/stack.c +147 -72
  330. data/third_party/boringssl-with-bazel/src/crypto/thread_none.c +0 -8
  331. data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +6 -35
  332. data/third_party/boringssl-with-bazel/src/crypto/thread_win.c +5 -26
  333. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +14 -18
  334. data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +54 -143
  335. data/third_party/boringssl-with-bazel/src/crypto/x509/by_dir.c +7 -13
  336. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +1 -1
  337. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +1 -1
  338. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_lu.c +2 -4
  339. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +2 -2
  340. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +1 -1
  341. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +8 -12
  342. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +19 -20
  343. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +11 -15
  344. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +5 -5
  345. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +1 -1
  346. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +7 -7
  347. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_lib.c +2 -3
  348. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +4 -6
  349. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +4 -119
  350. data/third_party/boringssl-with-bazel/src/include/openssl/asm_base.h +207 -0
  351. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +5 -0
  352. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +2 -116
  353. data/third_party/boringssl-with-bazel/src/include/openssl/bn.h +0 -2
  354. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +6 -0
  355. data/third_party/boringssl-with-bazel/src/include/openssl/conf.h +5 -1
  356. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +0 -21
  357. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +21 -2
  358. data/third_party/boringssl-with-bazel/src/include/openssl/ec_key.h +19 -6
  359. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +11 -7
  360. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +13 -14
  361. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +0 -61
  362. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +127 -81
  363. data/third_party/boringssl-with-bazel/src/include/openssl/stack.h +224 -209
  364. data/third_party/boringssl-with-bazel/src/include/openssl/target.h +154 -0
  365. data/third_party/boringssl-with-bazel/src/include/openssl/thread.h +1 -29
  366. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +4 -4
  367. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +3 -2
  368. data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +9 -65
  369. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +20 -20
  370. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  371. data/third_party/boringssl-with-bazel/src/ssl/internal.h +4 -11
  372. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +24 -18
  373. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +37 -30
  374. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +125 -26
  375. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +2 -3
  376. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64_adx.h +691 -0
  377. data/third_party/upb/upb/collections/map.c +3 -3
  378. metadata +27 -12
  379. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.cc +0 -42
  380. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h +0 -64
  381. data/src/core/ext/transport/chttp2/transport/stream_map.cc +0 -177
  382. data/src/core/ext/transport/chttp2/transport/stream_map.h +0 -68
  383. data/third_party/boringssl-with-bazel/src/crypto/refcount_win.c +0 -89
@@ -80,270 +80,147 @@
80
80
  #include "../bn/internal.h"
81
81
  #include "../delocate.h"
82
82
 
83
+ #include "builtin_curves.h"
83
84
 
84
- static void ec_point_free(EC_POINT *point, int free_group);
85
-
86
- static const uint8_t kP224Params[6 * 28] = {
87
- // p = 2^224 - 2^96 + 1
88
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
89
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90
- 0x00, 0x00, 0x00, 0x01,
91
- // a
92
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
93
- 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
94
- 0xFF, 0xFF, 0xFF, 0xFE,
95
- // b
96
- 0xB4, 0x05, 0x0A, 0x85, 0x0C, 0x04, 0xB3, 0xAB, 0xF5, 0x41, 0x32, 0x56,
97
- 0x50, 0x44, 0xB0, 0xB7, 0xD7, 0xBF, 0xD8, 0xBA, 0x27, 0x0B, 0x39, 0x43,
98
- 0x23, 0x55, 0xFF, 0xB4,
99
- // x
100
- 0xB7, 0x0E, 0x0C, 0xBD, 0x6B, 0xB4, 0xBF, 0x7F, 0x32, 0x13, 0x90, 0xB9,
101
- 0x4A, 0x03, 0xC1, 0xD3, 0x56, 0xC2, 0x11, 0x22, 0x34, 0x32, 0x80, 0xD6,
102
- 0x11, 0x5C, 0x1D, 0x21,
103
- // y
104
- 0xbd, 0x37, 0x63, 0x88, 0xb5, 0xf7, 0x23, 0xfb, 0x4c, 0x22, 0xdf, 0xe6,
105
- 0xcd, 0x43, 0x75, 0xa0, 0x5a, 0x07, 0x47, 0x64, 0x44, 0xd5, 0x81, 0x99,
106
- 0x85, 0x00, 0x7e, 0x34,
107
- // order
108
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
109
- 0xFF, 0xFF, 0x16, 0xA2, 0xE0, 0xB8, 0xF0, 0x3E, 0x13, 0xDD, 0x29, 0x45,
110
- 0x5C, 0x5C, 0x2A, 0x3D,
111
- };
112
-
113
- static const uint8_t kP256Params[6 * 32] = {
114
- // p = 2^256 - 2^224 + 2^192 + 2^96 - 1
115
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
116
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
117
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
118
- // a
119
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
120
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
121
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC,
122
- // b
123
- 0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, 0x55,
124
- 0x76, 0x98, 0x86, 0xBC, 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6,
125
- 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B,
126
- // x
127
- 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, 0xE5,
128
- 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
129
- 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96,
130
- // y
131
- 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a,
132
- 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
133
- 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
134
- // order
135
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
136
- 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
137
- 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51,
138
- };
139
-
140
- static const uint8_t kP384Params[6 * 48] = {
141
- // p = 2^384 - 2^128 - 2^96 + 2^32 - 1
142
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
143
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
144
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
145
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
146
- // a
147
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
148
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
149
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
150
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFC,
151
- // b
152
- 0xB3, 0x31, 0x2F, 0xA7, 0xE2, 0x3E, 0xE7, 0xE4, 0x98, 0x8E, 0x05, 0x6B,
153
- 0xE3, 0xF8, 0x2D, 0x19, 0x18, 0x1D, 0x9C, 0x6E, 0xFE, 0x81, 0x41, 0x12,
154
- 0x03, 0x14, 0x08, 0x8F, 0x50, 0x13, 0x87, 0x5A, 0xC6, 0x56, 0x39, 0x8D,
155
- 0x8A, 0x2E, 0xD1, 0x9D, 0x2A, 0x85, 0xC8, 0xED, 0xD3, 0xEC, 0x2A, 0xEF,
156
- // x
157
- 0xAA, 0x87, 0xCA, 0x22, 0xBE, 0x8B, 0x05, 0x37, 0x8E, 0xB1, 0xC7, 0x1E,
158
- 0xF3, 0x20, 0xAD, 0x74, 0x6E, 0x1D, 0x3B, 0x62, 0x8B, 0xA7, 0x9B, 0x98,
159
- 0x59, 0xF7, 0x41, 0xE0, 0x82, 0x54, 0x2A, 0x38, 0x55, 0x02, 0xF2, 0x5D,
160
- 0xBF, 0x55, 0x29, 0x6C, 0x3A, 0x54, 0x5E, 0x38, 0x72, 0x76, 0x0A, 0xB7,
161
- // y
162
- 0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f, 0x5d, 0x9e, 0x98, 0xbf,
163
- 0x92, 0x92, 0xdc, 0x29, 0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c,
164
- 0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0, 0x0a, 0x60, 0xb1, 0xce,
165
- 0x1d, 0x7e, 0x81, 0x9d, 0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f,
166
- // order
167
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
168
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
169
- 0xC7, 0x63, 0x4D, 0x81, 0xF4, 0x37, 0x2D, 0xDF, 0x58, 0x1A, 0x0D, 0xB2,
170
- 0x48, 0xB0, 0xA7, 0x7A, 0xEC, 0xEC, 0x19, 0x6A, 0xCC, 0xC5, 0x29, 0x73,
171
- };
172
-
173
- static const uint8_t kP521Params[6 * 66] = {
174
- // p = 2^521 - 1
175
- 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
176
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
177
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
178
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
179
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
180
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
181
- // a
182
- 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
183
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
184
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
185
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
186
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
187
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC,
188
- // b
189
- 0x00, 0x51, 0x95, 0x3E, 0xB9, 0x61, 0x8E, 0x1C, 0x9A, 0x1F, 0x92, 0x9A,
190
- 0x21, 0xA0, 0xB6, 0x85, 0x40, 0xEE, 0xA2, 0xDA, 0x72, 0x5B, 0x99, 0xB3,
191
- 0x15, 0xF3, 0xB8, 0xB4, 0x89, 0x91, 0x8E, 0xF1, 0x09, 0xE1, 0x56, 0x19,
192
- 0x39, 0x51, 0xEC, 0x7E, 0x93, 0x7B, 0x16, 0x52, 0xC0, 0xBD, 0x3B, 0xB1,
193
- 0xBF, 0x07, 0x35, 0x73, 0xDF, 0x88, 0x3D, 0x2C, 0x34, 0xF1, 0xEF, 0x45,
194
- 0x1F, 0xD4, 0x6B, 0x50, 0x3F, 0x00,
195
- // x
196
- 0x00, 0xC6, 0x85, 0x8E, 0x06, 0xB7, 0x04, 0x04, 0xE9, 0xCD, 0x9E, 0x3E,
197
- 0xCB, 0x66, 0x23, 0x95, 0xB4, 0x42, 0x9C, 0x64, 0x81, 0x39, 0x05, 0x3F,
198
- 0xB5, 0x21, 0xF8, 0x28, 0xAF, 0x60, 0x6B, 0x4D, 0x3D, 0xBA, 0xA1, 0x4B,
199
- 0x5E, 0x77, 0xEF, 0xE7, 0x59, 0x28, 0xFE, 0x1D, 0xC1, 0x27, 0xA2, 0xFF,
200
- 0xA8, 0xDE, 0x33, 0x48, 0xB3, 0xC1, 0x85, 0x6A, 0x42, 0x9B, 0xF9, 0x7E,
201
- 0x7E, 0x31, 0xC2, 0xE5, 0xBD, 0x66,
202
- // y
203
- 0x01, 0x18, 0x39, 0x29, 0x6a, 0x78, 0x9a, 0x3b, 0xc0, 0x04, 0x5c, 0x8a,
204
- 0x5f, 0xb4, 0x2c, 0x7d, 0x1b, 0xd9, 0x98, 0xf5, 0x44, 0x49, 0x57, 0x9b,
205
- 0x44, 0x68, 0x17, 0xaf, 0xbd, 0x17, 0x27, 0x3e, 0x66, 0x2c, 0x97, 0xee,
206
- 0x72, 0x99, 0x5e, 0xf4, 0x26, 0x40, 0xc5, 0x50, 0xb9, 0x01, 0x3f, 0xad,
207
- 0x07, 0x61, 0x35, 0x3c, 0x70, 0x86, 0xa2, 0x72, 0xc2, 0x40, 0x88, 0xbe,
208
- 0x94, 0x76, 0x9f, 0xd1, 0x66, 0x50,
209
- // order
210
- 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
211
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
212
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFA, 0x51, 0x86,
213
- 0x87, 0x83, 0xBF, 0x2F, 0x96, 0x6B, 0x7F, 0xCC, 0x01, 0x48, 0xF7, 0x09,
214
- 0xA5, 0xD0, 0x3B, 0xB5, 0xC9, 0xB8, 0x89, 0x9C, 0x47, 0xAE, 0xBB, 0x6F,
215
- 0xB7, 0x1E, 0x91, 0x38, 0x64, 0x09,
216
- };
217
-
218
- DEFINE_METHOD_FUNCTION(struct built_in_curves, OPENSSL_built_in_curves) {
219
- // 1.3.132.0.35
220
- static const uint8_t kOIDP521[] = {0x2b, 0x81, 0x04, 0x00, 0x23};
221
- out->curves[0].nid = NID_secp521r1;
222
- out->curves[0].oid = kOIDP521;
223
- out->curves[0].oid_len = sizeof(kOIDP521);
224
- out->curves[0].comment = "NIST P-521";
225
- out->curves[0].param_len = 66;
226
- out->curves[0].params = kP521Params;
227
- out->curves[0].method = EC_GFp_mont_method();
228
85
 
229
- // 1.3.132.0.34
230
- static const uint8_t kOIDP384[] = {0x2b, 0x81, 0x04, 0x00, 0x22};
231
- out->curves[1].nid = NID_secp384r1;
232
- out->curves[1].oid = kOIDP384;
233
- out->curves[1].oid_len = sizeof(kOIDP384);
234
- out->curves[1].comment = "NIST P-384";
235
- out->curves[1].param_len = 48;
236
- out->curves[1].params = kP384Params;
237
- out->curves[1].method = EC_GFp_mont_method();
86
+ static void ec_point_free(EC_POINT *point, int free_group);
238
87
 
239
- // 1.2.840.10045.3.1.7
240
- static const uint8_t kOIDP256[] = {0x2a, 0x86, 0x48, 0xce,
241
- 0x3d, 0x03, 0x01, 0x07};
242
- out->curves[2].nid = NID_X9_62_prime256v1;
243
- out->curves[2].oid = kOIDP256;
244
- out->curves[2].oid_len = sizeof(kOIDP256);
245
- out->curves[2].comment = "NIST P-256";
246
- out->curves[2].param_len = 32;
247
- out->curves[2].params = kP256Params;
248
- out->curves[2].method =
249
- #if !defined(OPENSSL_NO_ASM) && \
250
- (defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)) && \
251
- !defined(OPENSSL_SMALL)
252
- EC_GFp_nistz256_method();
88
+ static void ec_group_init_static_mont(BN_MONT_CTX *mont, size_t num_words,
89
+ const BN_ULONG *modulus,
90
+ const BN_ULONG *rr, uint64_t n0) {
91
+ bn_set_static_words(&mont->N, modulus, num_words);
92
+ bn_set_static_words(&mont->RR, rr, num_words);
93
+ #if defined(OPENSSL_64_BIT)
94
+ mont->n0[0] = n0;
95
+ #elif defined(OPENSSL_32_BIT)
96
+ mont->n0[0] = (uint32_t)n0;
97
+ mont->n0[1] = (uint32_t)(n0 >> 32);
253
98
  #else
254
- EC_GFp_nistp256_method();
99
+ #error "unknown word length"
255
100
  #endif
101
+ }
256
102
 
103
+ static void ec_group_set_a_minus3(EC_GROUP *group) {
104
+ const EC_FELEM *one = ec_felem_one(group);
105
+ group->a_is_minus3 = 1;
106
+ ec_felem_neg(group, &group->a, one);
107
+ ec_felem_sub(group, &group->a, &group->a, one);
108
+ ec_felem_sub(group, &group->a, &group->a, one);
109
+ }
110
+
111
+ DEFINE_METHOD_FUNCTION(EC_GROUP, EC_group_p224) {
112
+ out->curve_name = NID_secp224r1;
113
+ out->comment = "NIST P-224";
257
114
  // 1.3.132.0.33
258
115
  static const uint8_t kOIDP224[] = {0x2b, 0x81, 0x04, 0x00, 0x21};
259
- out->curves[3].nid = NID_secp224r1;
260
- out->curves[3].oid = kOIDP224;
261
- out->curves[3].oid_len = sizeof(kOIDP224);
262
- out->curves[3].comment = "NIST P-224";
263
- out->curves[3].param_len = 28;
264
- out->curves[3].params = kP224Params;
265
- out->curves[3].method =
116
+ OPENSSL_memcpy(out->oid, kOIDP224, sizeof(kOIDP224));
117
+ out->oid_len = sizeof(kOIDP224);
118
+
119
+ ec_group_init_static_mont(&out->field, OPENSSL_ARRAY_SIZE(kP224Field),
120
+ kP224Field, kP224FieldRR, kP224FieldN0);
121
+ ec_group_init_static_mont(&out->order, OPENSSL_ARRAY_SIZE(kP224Order),
122
+ kP224Order, kP224OrderRR, kP224OrderN0);
123
+
266
124
  #if defined(BORINGSSL_HAS_UINT128) && !defined(OPENSSL_SMALL)
267
- EC_GFp_nistp224_method();
125
+ out->meth = EC_GFp_nistp224_method();
126
+ OPENSSL_memcpy(out->generator.raw.X.words, kP224GX, sizeof(kP224GX));
127
+ OPENSSL_memcpy(out->generator.raw.Y.words, kP224GY, sizeof(kP224GY));
128
+ out->generator.raw.Z.words[0] = 1;
129
+ OPENSSL_memcpy(out->b.words, kP224B, sizeof(kP224B));
268
130
  #else
269
- EC_GFp_mont_method();
131
+ out->meth = EC_GFp_mont_method();
132
+ OPENSSL_memcpy(out->generator.raw.X.words, kP224MontGX, sizeof(kP224MontGX));
133
+ OPENSSL_memcpy(out->generator.raw.Y.words, kP224MontGY, sizeof(kP224MontGY));
134
+ OPENSSL_memcpy(out->generator.raw.Z.words, kP224FieldR, sizeof(kP224FieldR));
135
+ OPENSSL_memcpy(out->b.words, kP224MontB, sizeof(kP224MontB));
270
136
  #endif
271
- }
272
-
273
- EC_GROUP *ec_group_new(const EC_METHOD *meth) {
274
- EC_GROUP *ret;
275
-
276
- if (meth == NULL) {
277
- OPENSSL_PUT_ERROR(EC, EC_R_SLOT_FULL);
278
- return NULL;
279
- }
280
-
281
- if (meth->group_init == 0) {
282
- OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
283
- return NULL;
284
- }
285
-
286
- ret = OPENSSL_malloc(sizeof(EC_GROUP));
287
- if (ret == NULL) {
288
- return NULL;
289
- }
290
- OPENSSL_memset(ret, 0, sizeof(EC_GROUP));
137
+ out->generator.group = out;
291
138
 
292
- ret->references = 1;
293
- ret->meth = meth;
294
- BN_init(&ret->order);
295
-
296
- if (!meth->group_init(ret)) {
297
- OPENSSL_free(ret);
298
- return NULL;
299
- }
300
-
301
- return ret;
139
+ ec_group_set_a_minus3(out);
140
+ out->has_order = 1;
141
+ out->field_greater_than_order = 1;
302
142
  }
303
143
 
304
- static int ec_group_set_generator(EC_GROUP *group, const EC_AFFINE *generator,
305
- const BIGNUM *order) {
306
- assert(group->generator == NULL);
307
-
308
- if (!BN_copy(&group->order, order)) {
309
- return 0;
310
- }
311
- // Store the order in minimal form, so it can be used with |BN_ULONG| arrays.
312
- bn_set_minimal_width(&group->order);
144
+ DEFINE_METHOD_FUNCTION(EC_GROUP, EC_group_p256) {
145
+ out->curve_name = NID_X9_62_prime256v1;
146
+ out->comment = "NIST P-256";
147
+ // 1.2.840.10045.3.1.7
148
+ static const uint8_t kOIDP256[] = {0x2a, 0x86, 0x48, 0xce,
149
+ 0x3d, 0x03, 0x01, 0x07};
150
+ OPENSSL_memcpy(out->oid, kOIDP256, sizeof(kOIDP256));
151
+ out->oid_len = sizeof(kOIDP256);
313
152
 
314
- BN_MONT_CTX_free(group->order_mont);
315
- group->order_mont = BN_MONT_CTX_new_for_modulus(&group->order, NULL);
316
- if (group->order_mont == NULL) {
317
- return 0;
318
- }
153
+ ec_group_init_static_mont(&out->field, OPENSSL_ARRAY_SIZE(kP256Field),
154
+ kP256Field, kP256FieldRR, kP256FieldN0);
155
+ ec_group_init_static_mont(&out->order, OPENSSL_ARRAY_SIZE(kP256Order),
156
+ kP256Order, kP256OrderRR, kP256OrderN0);
319
157
 
320
- group->field_greater_than_order = BN_cmp(&group->field, order) > 0;
321
- if (group->field_greater_than_order) {
322
- BIGNUM tmp;
323
- BN_init(&tmp);
324
- int ok =
325
- BN_sub(&tmp, &group->field, order) &&
326
- bn_copy_words(group->field_minus_order.words, group->field.width, &tmp);
327
- BN_free(&tmp);
328
- if (!ok) {
329
- return 0;
330
- }
331
- }
332
-
333
- group->generator = EC_POINT_new(group);
334
- if (group->generator == NULL) {
335
- return 0;
336
- }
337
- ec_affine_to_jacobian(group, &group->generator->raw, generator);
338
- assert(ec_felem_equal(group, &group->one, &group->generator->raw.Z));
158
+ #if !defined(OPENSSL_NO_ASM) && \
159
+ (defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)) && \
160
+ !defined(OPENSSL_SMALL)
161
+ out->meth = EC_GFp_nistz256_method();
162
+ #else
163
+ out->meth = EC_GFp_nistp256_method();
164
+ #endif
165
+ out->generator.group = out;
166
+ OPENSSL_memcpy(out->generator.raw.X.words, kP256MontGX, sizeof(kP256MontGX));
167
+ OPENSSL_memcpy(out->generator.raw.Y.words, kP256MontGY, sizeof(kP256MontGY));
168
+ OPENSSL_memcpy(out->generator.raw.Z.words, kP256FieldR, sizeof(kP256FieldR));
169
+ OPENSSL_memcpy(out->b.words, kP256MontB, sizeof(kP256MontB));
170
+
171
+ ec_group_set_a_minus3(out);
172
+ out->has_order = 1;
173
+ out->field_greater_than_order = 1;
174
+ }
339
175
 
340
- // Avoid a reference cycle. |group->generator| does not maintain an owning
341
- // pointer to |group|.
342
- int is_zero = CRYPTO_refcount_dec_and_test_zero(&group->references);
176
+ DEFINE_METHOD_FUNCTION(EC_GROUP, EC_group_p384) {
177
+ out->curve_name = NID_secp384r1;
178
+ out->comment = "NIST P-384";
179
+ // 1.3.132.0.34
180
+ static const uint8_t kOIDP384[] = {0x2b, 0x81, 0x04, 0x00, 0x22};
181
+ OPENSSL_memcpy(out->oid, kOIDP384, sizeof(kOIDP384));
182
+ out->oid_len = sizeof(kOIDP384);
183
+
184
+ ec_group_init_static_mont(&out->field, OPENSSL_ARRAY_SIZE(kP384Field),
185
+ kP384Field, kP384FieldRR, kP384FieldN0);
186
+ ec_group_init_static_mont(&out->order, OPENSSL_ARRAY_SIZE(kP384Order),
187
+ kP384Order, kP384OrderRR, kP384OrderN0);
188
+
189
+ out->meth = EC_GFp_mont_method();
190
+ out->generator.group = out;
191
+ OPENSSL_memcpy(out->generator.raw.X.words, kP384MontGX, sizeof(kP384MontGX));
192
+ OPENSSL_memcpy(out->generator.raw.Y.words, kP384MontGY, sizeof(kP384MontGY));
193
+ OPENSSL_memcpy(out->generator.raw.Z.words, kP384FieldR, sizeof(kP384FieldR));
194
+ OPENSSL_memcpy(out->b.words, kP384MontB, sizeof(kP384MontB));
195
+
196
+ ec_group_set_a_minus3(out);
197
+ out->has_order = 1;
198
+ out->field_greater_than_order = 1;
199
+ }
343
200
 
344
- assert(!is_zero);
345
- (void)is_zero;
346
- return 1;
201
+ DEFINE_METHOD_FUNCTION(EC_GROUP, EC_group_p521) {
202
+ out->curve_name = NID_secp521r1;
203
+ out->comment = "NIST P-521";
204
+ // 1.3.132.0.35
205
+ static const uint8_t kOIDP521[] = {0x2b, 0x81, 0x04, 0x00, 0x23};
206
+ OPENSSL_memcpy(out->oid, kOIDP521, sizeof(kOIDP521));
207
+ out->oid_len = sizeof(kOIDP521);
208
+
209
+ ec_group_init_static_mont(&out->field, OPENSSL_ARRAY_SIZE(kP521Field),
210
+ kP521Field, kP521FieldRR, kP521FieldN0);
211
+ ec_group_init_static_mont(&out->order, OPENSSL_ARRAY_SIZE(kP521Order),
212
+ kP521Order, kP521OrderRR, kP521OrderN0);
213
+
214
+ out->meth = EC_GFp_mont_method();
215
+ out->generator.group = out;
216
+ OPENSSL_memcpy(out->generator.raw.X.words, kP521MontGX, sizeof(kP521MontGX));
217
+ OPENSSL_memcpy(out->generator.raw.Y.words, kP521MontGY, sizeof(kP521MontGY));
218
+ OPENSSL_memcpy(out->generator.raw.Z.words, kP521FieldR, sizeof(kP521FieldR));
219
+ OPENSSL_memcpy(out->b.words, kP521MontB, sizeof(kP521MontB));
220
+
221
+ ec_group_set_a_minus3(out);
222
+ out->has_order = 1;
223
+ out->field_greater_than_order = 1;
347
224
  }
348
225
 
349
226
  EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
@@ -373,9 +250,17 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
373
250
  goto err;
374
251
  }
375
252
 
376
- ret = ec_group_new(EC_GFp_mont_method());
377
- if (ret == NULL ||
378
- !ret->meth->group_set_curve(ret, p, a_reduced, b_reduced, ctx)) {
253
+ ret = OPENSSL_malloc(sizeof(EC_GROUP));
254
+ if (ret == NULL) {
255
+ return NULL;
256
+ }
257
+ OPENSSL_memset(ret, 0, sizeof(EC_GROUP));
258
+ ret->references = 1;
259
+ ret->meth = EC_GFp_mont_method();
260
+ bn_mont_ctx_init(&ret->field);
261
+ bn_mont_ctx_init(&ret->order);
262
+ ret->generator.group = ret;
263
+ if (!ec_GFp_simple_group_set_curve(ret, p, a_reduced, b_reduced, ctx)) {
379
264
  EC_GROUP_free(ret);
380
265
  ret = NULL;
381
266
  goto err;
@@ -389,7 +274,7 @@ err:
389
274
 
390
275
  int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
391
276
  const BIGNUM *order, const BIGNUM *cofactor) {
392
- if (group->curve_name != NID_undef || group->generator != NULL ||
277
+ if (group->curve_name != NID_undef || group->has_order ||
393
278
  generator->group != group) {
394
279
  // |EC_GROUP_set_generator| may only be used with |EC_GROUP|s returned by
395
280
  // |EC_GROUP_new_curve_GFp| and may only used once on each group.
@@ -421,17 +306,22 @@ int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
421
306
  !BN_lshift1(tmp, order)) {
422
307
  goto err;
423
308
  }
424
- if (BN_cmp(tmp, &group->field) <= 0) {
309
+ if (BN_cmp(tmp, &group->field.N) <= 0) {
425
310
  OPENSSL_PUT_ERROR(EC, EC_R_INVALID_GROUP_ORDER);
426
311
  goto err;
427
312
  }
428
313
 
429
314
  EC_AFFINE affine;
430
315
  if (!ec_jacobian_to_affine(group, &affine, &generator->raw) ||
431
- !ec_group_set_generator(group, &affine, order)) {
316
+ !BN_MONT_CTX_set(&group->order, order, NULL)) {
432
317
  goto err;
433
318
  }
434
319
 
320
+ group->field_greater_than_order = BN_cmp(&group->field.N, order) > 0;
321
+ group->generator.raw.X = affine.X;
322
+ group->generator.raw.Y = affine.Y;
323
+ // |raw.Z| was set to 1 by |EC_GROUP_new_curve_GFp|.
324
+ group->has_order = 1;
435
325
  ret = 1;
436
326
 
437
327
  err:
@@ -439,114 +329,20 @@ err:
439
329
  return ret;
440
330
  }
441
331
 
442
- static EC_GROUP *ec_group_new_from_data(const struct built_in_curve *curve) {
443
- EC_GROUP *group = NULL;
444
- BIGNUM *p = NULL, *a = NULL, *b = NULL, *order = NULL;
445
- int ok = 0;
446
-
447
- BN_CTX *ctx = BN_CTX_new();
448
- if (ctx == NULL) {
449
- goto err;
450
- }
451
-
452
- const unsigned param_len = curve->param_len;
453
- const uint8_t *params = curve->params;
454
-
455
- if (!(p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) ||
456
- !(a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) ||
457
- !(b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) ||
458
- !(order = BN_bin2bn(params + 5 * param_len, param_len, NULL))) {
459
- OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
460
- goto err;
461
- }
462
-
463
- group = ec_group_new(curve->method);
464
- if (group == NULL ||
465
- !group->meth->group_set_curve(group, p, a, b, ctx)) {
466
- OPENSSL_PUT_ERROR(EC, ERR_R_EC_LIB);
467
- goto err;
468
- }
469
-
470
- EC_AFFINE G;
471
- EC_FELEM x, y;
472
- if (!ec_felem_from_bytes(group, &x, params + 3 * param_len, param_len) ||
473
- !ec_felem_from_bytes(group, &y, params + 4 * param_len, param_len) ||
474
- !ec_point_set_affine_coordinates(group, &G, &x, &y)) {
475
- goto err;
476
- }
477
-
478
- if (!ec_group_set_generator(group, &G, order)) {
479
- goto err;
480
- }
481
-
482
- ok = 1;
483
-
484
- err:
485
- if (!ok) {
486
- EC_GROUP_free(group);
487
- group = NULL;
488
- }
489
- BN_CTX_free(ctx);
490
- BN_free(p);
491
- BN_free(a);
492
- BN_free(b);
493
- BN_free(order);
494
- return group;
495
- }
496
-
497
- // Built-in groups are allocated lazily and static once allocated.
498
- // TODO(davidben): Make these actually static. https://crbug.com/boringssl/20.
499
- struct built_in_groups_st {
500
- EC_GROUP *groups[OPENSSL_NUM_BUILT_IN_CURVES];
501
- };
502
- DEFINE_BSS_GET(struct built_in_groups_st, built_in_groups)
503
- DEFINE_STATIC_MUTEX(built_in_groups_lock)
504
-
505
332
  EC_GROUP *EC_GROUP_new_by_curve_name(int nid) {
506
- struct built_in_groups_st *groups = built_in_groups_bss_get();
507
- EC_GROUP **group_ptr = NULL;
508
- const struct built_in_curves *const curves = OPENSSL_built_in_curves();
509
- const struct built_in_curve *curve = NULL;
510
- for (size_t i = 0; i < OPENSSL_NUM_BUILT_IN_CURVES; i++) {
511
- if (curves->curves[i].nid == nid) {
512
- curve = &curves->curves[i];
513
- group_ptr = &groups->groups[i];
514
- break;
515
- }
516
- }
517
-
518
- if (curve == NULL) {
519
- OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
520
- return NULL;
521
- }
522
-
523
- CRYPTO_STATIC_MUTEX_lock_read(built_in_groups_lock_bss_get());
524
- EC_GROUP *ret = *group_ptr;
525
- CRYPTO_STATIC_MUTEX_unlock_read(built_in_groups_lock_bss_get());
526
- if (ret != NULL) {
527
- return ret;
528
- }
529
-
530
- ret = ec_group_new_from_data(curve);
531
- if (ret == NULL) {
532
- return NULL;
533
- }
534
-
535
- EC_GROUP *to_free = NULL;
536
- CRYPTO_STATIC_MUTEX_lock_write(built_in_groups_lock_bss_get());
537
- if (*group_ptr == NULL) {
538
- *group_ptr = ret;
539
- // Filling in |ret->curve_name| makes |EC_GROUP_free| and |EC_GROUP_dup|
540
- // into no-ops. At this point, |ret| is considered static.
541
- ret->curve_name = nid;
542
- } else {
543
- to_free = ret;
544
- ret = *group_ptr;
333
+ switch (nid) {
334
+ case NID_secp224r1:
335
+ return (EC_GROUP *)EC_group_p224();
336
+ case NID_X9_62_prime256v1:
337
+ return (EC_GROUP *)EC_group_p256();
338
+ case NID_secp384r1:
339
+ return (EC_GROUP *)EC_group_p384();
340
+ case NID_secp521r1:
341
+ return (EC_GROUP *)EC_group_p521();
342
+ default:
343
+ OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
344
+ return NULL;
545
345
  }
546
- CRYPTO_STATIC_MUTEX_unlock_write(built_in_groups_lock_bss_get());
547
-
548
- EC_GROUP_free(to_free);
549
- return ret;
550
346
  }
551
347
 
552
348
  void EC_GROUP_free(EC_GROUP *group) {
@@ -557,14 +353,8 @@ void EC_GROUP_free(EC_GROUP *group) {
557
353
  return;
558
354
  }
559
355
 
560
- if (group->meth->group_finish != NULL) {
561
- group->meth->group_finish(group);
562
- }
563
-
564
- ec_point_free(group->generator, 0 /* don't free group */);
565
- BN_free(&group->order);
566
- BN_MONT_CTX_free(group->order_mont);
567
-
356
+ bn_mont_ctx_cleanup(&group->order);
357
+ bn_mont_ctx_cleanup(&group->field);
568
358
  OPENSSL_free(group);
569
359
  }
570
360
 
@@ -599,23 +389,22 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ignored) {
599
389
  // structure. If |a| or |b| is incomplete (due to legacy OpenSSL mistakes,
600
390
  // custom curve construction is sadly done in two parts) but otherwise not the
601
391
  // same object, we consider them always unequal.
602
- return a->meth != b->meth ||
603
- a->generator == NULL ||
604
- b->generator == NULL ||
605
- BN_cmp(&a->order, &b->order) != 0 ||
606
- BN_cmp(&a->field, &b->field) != 0 ||
607
- !ec_felem_equal(a, &a->a, &b->a) ||
392
+ return a->meth != b->meth || //
393
+ !a->has_order || !b->has_order ||
394
+ BN_cmp(&a->order.N, &b->order.N) != 0 ||
395
+ BN_cmp(&a->field.N, &b->field.N) != 0 ||
396
+ !ec_felem_equal(a, &a->a, &b->a) || //
608
397
  !ec_felem_equal(a, &a->b, &b->b) ||
609
- !ec_GFp_simple_points_equal(a, &a->generator->raw, &b->generator->raw);
398
+ !ec_GFp_simple_points_equal(a, &a->generator.raw, &b->generator.raw);
610
399
  }
611
400
 
612
401
  const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group) {
613
- return group->generator;
402
+ return group->has_order ? &group->generator : NULL;
614
403
  }
615
404
 
616
405
  const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group) {
617
- assert(!BN_is_zero(&group->order));
618
- return &group->order;
406
+ assert(group->has_order);
407
+ return &group->order.N;
619
408
  }
620
409
 
621
410
  int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx) {
@@ -626,7 +415,7 @@ int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx) {
626
415
  }
627
416
 
628
417
  int EC_GROUP_order_bits(const EC_GROUP *group) {
629
- return BN_num_bits(&group->order);
418
+ return BN_num_bits(&group->order.N);
630
419
  }
631
420
 
632
421
  int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
@@ -643,7 +432,7 @@ int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p, BIGNUM *out_a,
643
432
  int EC_GROUP_get_curve_name(const EC_GROUP *group) { return group->curve_name; }
644
433
 
645
434
  unsigned EC_GROUP_get_degree(const EC_GROUP *group) {
646
- return BN_num_bits(&group->field);
435
+ return BN_num_bits(&group->field.N);
647
436
  }
648
437
 
649
438
  const char *EC_curve_nid2nist(int nid) {
@@ -805,7 +594,7 @@ void ec_affine_to_jacobian(const EC_GROUP *group, EC_JACOBIAN *out,
805
594
  const EC_AFFINE *p) {
806
595
  out->X = p->X;
807
596
  out->Y = p->Y;
808
- out->Z = group->one;
597
+ out->Z = *ec_felem_one(group);
809
598
  }
810
599
 
811
600
  int ec_jacobian_to_affine(const EC_GROUP *group, EC_AFFINE *out,
@@ -842,10 +631,9 @@ int ec_point_set_affine_coordinates(const EC_GROUP *group, EC_AFFINE *out,
842
631
  // return value by setting a known safe value. Note this may not be possible
843
632
  // if the caller is in the process of constructing an arbitrary group and
844
633
  // the generator is missing.
845
- if (group->generator != NULL) {
846
- assert(ec_felem_equal(group, &group->one, &group->generator->raw.Z));
847
- out->X = group->generator->raw.X;
848
- out->Y = group->generator->raw.Y;
634
+ if (group->has_order) {
635
+ out->X = group->generator.raw.X;
636
+ out->Y = group->generator.raw.Y;
849
637
  }
850
638
  return 0;
851
639
  }
@@ -931,11 +719,10 @@ static int arbitrary_bignum_to_scalar(const EC_GROUP *group, EC_SCALAR *out,
931
719
  ERR_clear_error();
932
720
 
933
721
  // This is an unusual input, so we do not guarantee constant-time processing.
934
- const BIGNUM *order = &group->order;
935
722
  BN_CTX_start(ctx);
936
723
  BIGNUM *tmp = BN_CTX_get(ctx);
937
724
  int ok = tmp != NULL &&
938
- BN_nnmod(tmp, in, order, ctx) &&
725
+ BN_nnmod(tmp, in, EC_GROUP_get0_order(group), ctx) &&
939
726
  ec_bignum_to_scalar(group, out, tmp);
940
727
  BN_CTX_end(ctx);
941
728
  return ok;
@@ -1074,8 +861,10 @@ int ec_point_mul_scalar_base(const EC_GROUP *group, EC_JACOBIAN *r,
1074
861
  group->meth->mul_base(group, r, scalar);
1075
862
 
1076
863
  // Check the result is on the curve to defend against fault attacks or bugs.
1077
- // This has negligible cost compared to the multiplication.
1078
- if (!ec_GFp_simple_is_on_curve(group, r)) {
864
+ // This has negligible cost compared to the multiplication. This can only
865
+ // happen on bug or CPU fault, so it okay to leak this. The alternative would
866
+ // be to proceed with bad data.
867
+ if (!constant_time_declassify_int(ec_GFp_simple_is_on_curve(group, r))) {
1079
868
  OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
1080
869
  return 0;
1081
870
  }
@@ -1191,7 +980,7 @@ int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out,
1191
980
  //
1192
981
  // Additionally, one can manually check this property for built-in curves. It
1193
982
  // is enforced for legacy custom curves in |EC_GROUP_set_generator|.
1194
- const BIGNUM *order = &group->order;
983
+ const BIGNUM *order = EC_GROUP_get0_order(group);
1195
984
  BN_ULONG words[EC_MAX_WORDS + 1] = {0};
1196
985
  bn_big_endian_to_words(words, order->width + 1, bytes, len);
1197
986
  bn_reduce_once(out->words, words, /*carry=*/words[order->width], order->d,
@@ -1202,7 +991,7 @@ int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out,
1202
991
  int ec_get_x_coordinate_as_bytes(const EC_GROUP *group, uint8_t *out,
1203
992
  size_t *out_len, size_t max_out,
1204
993
  const EC_JACOBIAN *p) {
1205
- size_t len = BN_num_bytes(&group->field);
994
+ size_t len = BN_num_bytes(&group->field.N);
1206
995
  assert(len <= EC_MAX_BYTES);
1207
996
  if (max_out < len) {
1208
997
  OPENSSL_PUT_ERROR(EC, EC_R_BUFFER_TOO_SMALL);
@@ -1220,8 +1009,8 @@ int ec_get_x_coordinate_as_bytes(const EC_GROUP *group, uint8_t *out,
1220
1009
  }
1221
1010
 
1222
1011
  void ec_set_to_safe_point(const EC_GROUP *group, EC_JACOBIAN *out) {
1223
- if (group->generator != NULL) {
1224
- ec_GFp_simple_point_copy(out, &group->generator->raw);
1012
+ if (group->has_order) {
1013
+ ec_GFp_simple_point_copy(out, &group->generator.raw);
1225
1014
  } else {
1226
1015
  // The generator can be missing if the caller is in the process of
1227
1016
  // constructing an arbitrary group. In this case, we give up and use the
@@ -1253,16 +1042,3 @@ void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
1253
1042
  abort();
1254
1043
  }
1255
1044
  }
1256
-
1257
- size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
1258
- size_t max_num_curves) {
1259
- const struct built_in_curves *const curves = OPENSSL_built_in_curves();
1260
-
1261
- for (size_t i = 0; i < max_num_curves && i < OPENSSL_NUM_BUILT_IN_CURVES;
1262
- i++) {
1263
- out_curves[i].comment = curves->curves[i].comment;
1264
- out_curves[i].nid = curves->curves[i].nid;
1265
- }
1266
-
1267
- return OPENSSL_NUM_BUILT_IN_CURVES;
1268
- }