grpc 1.43.1 → 1.44.0.pre2
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.
- checksums.yaml +4 -4
- data/Makefile +84 -64
- data/include/grpc/grpc_security.h +10 -0
- data/include/grpc/impl/codegen/compression_types.h +0 -2
- data/include/grpc/impl/codegen/grpc_types.h +6 -0
- data/src/core/ext/filters/client_channel/backend_metric.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +62 -68
- data/src/core/ext/filters/client_channel/client_channel.h +8 -8
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
- data/src/core/ext/filters/client_channel/config_selector.h +4 -4
- data/src/core/ext/filters/client_channel/dynamic_filters.h +1 -1
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +16 -14
- data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +6 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +3 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +31 -32
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +43 -29
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +120 -68
- data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +60 -48
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +62 -61
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +16 -11
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +11 -5
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +19 -15
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -12
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +50 -105
- data/src/core/ext/filters/client_channel/lb_policy.cc +15 -14
- data/src/core/ext/filters/client_channel/lb_policy.h +19 -3
- data/src/core/ext/filters/client_channel/resolver/binder/binder_resolver.cc +3 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +207 -81
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +22 -12
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +19 -15
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +23 -38
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +118 -207
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +25 -32
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +82 -73
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +10 -10
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +2 -5
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +5 -5
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +157 -67
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +2 -2
- data/src/core/ext/filters/client_channel/retry_filter.cc +37 -64
- data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -1
- data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
- data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +1 -1
- data/src/core/ext/filters/client_channel/subchannel.cc +12 -16
- data/src/core/ext/filters/client_channel/subchannel.h +2 -3
- data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +37 -48
- data/src/core/ext/filters/fault_injection/service_config_parser.cc +6 -8
- data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
- data/src/core/ext/filters/http/client/http_client_filter.cc +51 -122
- data/src/core/ext/filters/http/client_authority_filter.cc +8 -24
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +42 -140
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +5 -25
- data/src/core/ext/filters/http/server/http_server_filter.cc +50 -135
- data/src/core/ext/filters/message_size/message_size_filter.cc +1 -1
- data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
- data/src/core/ext/filters/rbac/rbac_filter.cc +157 -0
- data/src/core/ext/filters/rbac/rbac_filter.h +74 -0
- data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +605 -0
- data/src/core/ext/filters/rbac/rbac_service_config_parser.h +70 -0
- data/src/core/ext/filters/server_config_selector/server_config_selector.h +3 -2
- data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +11 -6
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +1 -1
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +89 -29
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +0 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +45 -186
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +0 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +341 -279
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +69 -159
- data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.h +2 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +19 -32
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +0 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +94 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +2 -24
- data/src/core/ext/transport/chttp2/transport/internal.h +0 -33
- data/src/core/ext/transport/chttp2/transport/parsing.cc +0 -6
- data/src/core/ext/transport/chttp2/transport/writing.cc +47 -116
- data/src/core/ext/transport/inproc/inproc_plugin.cc +0 -4
- data/src/core/ext/transport/inproc/inproc_transport.cc +11 -63
- data/src/core/ext/transport/inproc/inproc_transport.h +0 -3
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.c +61 -0
- data/src/core/ext/upb-generated/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +146 -0
- data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.c +188 -0
- data/src/core/ext/upbdefs-generated/envoy/config/rbac/v3/rbac.upbdefs.h +70 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.c +154 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/checked.upbdefs.h +95 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.c +58 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/eval.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.c +44 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/explain.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.c +153 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/syntax.upbdefs.h +100 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.c +75 -0
- data/src/core/ext/upbdefs-generated/google/api/expr/v1alpha1/value.upbdefs.h +55 -0
- data/src/core/ext/xds/upb_utils.h +65 -0
- data/src/core/ext/xds/xds_api.cc +81 -3458
- data/src/core/ext/xds/xds_api.h +56 -611
- data/src/core/ext/xds/xds_bootstrap.cc +189 -125
- data/src/core/ext/xds/xds_bootstrap.h +20 -15
- data/src/core/ext/xds/xds_certificate_provider.h +1 -0
- data/src/core/ext/xds/xds_channel_creds.cc +108 -0
- data/src/core/ext/xds/xds_channel_creds.h +50 -0
- data/src/core/ext/xds/xds_client.cc +584 -994
- data/src/core/ext/xds/xds_client.h +78 -135
- data/src/core/ext/xds/xds_cluster.cc +451 -0
- data/src/core/ext/xds/xds_cluster.h +111 -0
- data/src/core/ext/xds/xds_common_types.cc +388 -0
- data/src/core/ext/xds/xds_common_types.h +110 -0
- data/src/core/ext/xds/xds_endpoint.cc +364 -0
- data/src/core/ext/xds/xds_endpoint.h +135 -0
- data/src/core/ext/xds/xds_http_filters.cc +5 -0
- data/src/core/ext/xds/xds_http_rbac_filter.cc +563 -0
- data/src/core/ext/xds/xds_http_rbac_filter.h +54 -0
- data/src/core/ext/xds/xds_listener.cc +1036 -0
- data/src/core/ext/xds/xds_listener.h +220 -0
- data/src/core/ext/{transport/chttp2/transport/hpack_utils.h → xds/xds_resource_type.cc} +12 -9
- data/src/core/ext/xds/xds_resource_type.h +98 -0
- data/src/core/ext/xds/xds_resource_type_impl.h +87 -0
- data/src/core/ext/xds/xds_route_config.cc +993 -0
- data/src/core/ext/xds/xds_route_config.h +215 -0
- data/src/core/ext/xds/xds_routing.cc +11 -8
- data/src/core/ext/xds/xds_routing.h +8 -5
- data/src/core/ext/xds/xds_server_config_fetcher.cc +159 -99
- data/src/core/lib/address_utils/parse_address.cc +20 -0
- data/src/core/lib/address_utils/parse_address.h +5 -0
- data/src/core/lib/address_utils/sockaddr_utils.cc +33 -36
- data/src/core/lib/address_utils/sockaddr_utils.h +1 -16
- data/src/core/lib/backoff/backoff.cc +4 -30
- data/src/core/lib/backoff/backoff.h +3 -3
- data/src/core/lib/channel/channel_args.cc +0 -1
- data/src/core/lib/channel/channel_stack.cc +8 -0
- data/src/core/lib/channel/channel_stack.h +1 -1
- data/src/core/lib/channel/channel_stack_builder.cc +5 -9
- data/src/core/lib/channel/channel_stack_builder.h +4 -7
- data/src/core/lib/channel/channelz.cc +1 -0
- data/src/core/lib/compression/compression.cc +19 -111
- data/src/core/lib/compression/compression_internal.cc +142 -202
- data/src/core/lib/compression/compression_internal.h +64 -69
- data/src/core/lib/compression/message_compress.cc +11 -11
- data/src/core/lib/compression/message_compress.h +2 -2
- data/src/core/lib/gpr/useful.h +4 -0
- data/src/core/lib/gprpp/bitset.h +7 -0
- data/src/core/lib/gprpp/chunked_vector.h +45 -3
- data/src/core/lib/gprpp/status_helper.cc +20 -28
- data/src/core/lib/gprpp/status_helper.h +6 -19
- data/src/core/lib/gprpp/table.h +11 -0
- data/src/core/lib/http/httpcli.cc +37 -46
- data/src/core/lib/http/httpcli.h +3 -15
- data/src/core/lib/iomgr/call_combiner.cc +15 -4
- data/src/core/lib/iomgr/closure.h +29 -9
- data/src/core/lib/iomgr/combiner.cc +25 -3
- data/src/core/lib/iomgr/error.cc +2 -0
- data/src/core/lib/iomgr/error.h +3 -0
- data/src/core/lib/iomgr/event_engine/iomgr.cc +3 -2
- data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +6 -0
- data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +2 -0
- data/src/core/lib/iomgr/event_engine/resolver.cc +66 -48
- data/src/core/lib/iomgr/event_engine/resolver.h +56 -0
- data/src/core/lib/iomgr/exec_ctx.cc +22 -9
- data/src/core/lib/iomgr/executor.cc +10 -1
- data/src/core/lib/iomgr/fork_posix.cc +3 -2
- data/src/core/lib/iomgr/iomgr_custom.cc +4 -1
- data/src/core/lib/iomgr/iomgr_posix.cc +2 -2
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +2 -2
- data/src/core/lib/iomgr/iomgr_windows.cc +2 -2
- data/src/core/lib/iomgr/port.h +2 -2
- data/src/core/lib/iomgr/resolve_address.cc +5 -24
- data/src/core/lib/iomgr/resolve_address.h +47 -44
- data/src/core/lib/iomgr/resolve_address_custom.cc +131 -109
- data/src/core/lib/iomgr/resolve_address_custom.h +101 -19
- data/src/core/lib/iomgr/resolve_address_impl.h +59 -0
- data/src/core/lib/iomgr/resolve_address_posix.cc +82 -66
- data/src/core/lib/iomgr/resolve_address_posix.h +47 -0
- data/src/core/lib/iomgr/resolve_address_windows.cc +93 -74
- data/src/core/lib/iomgr/resolve_address_windows.h +47 -0
- data/src/core/lib/iomgr/resolved_address.h +39 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +1 -0
- data/src/core/lib/iomgr/unix_sockets_posix.cc +22 -34
- data/src/core/lib/iomgr/unix_sockets_posix.h +4 -7
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +6 -15
- data/src/core/lib/matchers/matchers.cc +1 -1
- data/src/core/lib/promise/activity.h +49 -20
- data/src/core/lib/promise/detail/status.h +5 -0
- data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.cc +17 -25
- data/src/core/{ext/filters/client_channel → lib/resolver}/resolver.h +43 -44
- data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_factory.h +10 -5
- data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.cc +3 -2
- data/src/core/{ext/filters/client_channel → lib/resolver}/resolver_registry.h +4 -5
- data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.cc +1 -1
- data/src/core/{ext/filters/client_channel → lib/resolver}/server_address.h +4 -4
- data/src/core/lib/resource_quota/api.h +0 -1
- data/src/core/lib/{gprpp → resource_quota}/arena.cc +16 -13
- data/src/core/lib/{gprpp → resource_quota}/arena.h +24 -13
- data/src/core/lib/security/authorization/evaluate_args.cc +30 -15
- data/src/core/lib/security/authorization/evaluate_args.h +1 -0
- data/src/core/lib/security/authorization/grpc_authorization_engine.cc +60 -0
- data/src/core/lib/security/authorization/grpc_authorization_engine.h +62 -0
- data/src/core/lib/security/authorization/matchers.cc +227 -0
- data/src/core/lib/security/authorization/matchers.h +211 -0
- data/src/core/lib/security/authorization/rbac_policy.cc +442 -0
- data/src/core/lib/security/authorization/rbac_policy.h +170 -0
- data/src/core/lib/security/context/security_context.cc +4 -2
- data/src/core/lib/security/context/security_context.h +1 -1
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +5 -5
- data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -3
- data/src/core/lib/security/credentials/credentials.h +10 -20
- data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +6 -9
- data/src/core/lib/security/credentials/external/external_account_credentials.cc +7 -9
- data/src/core/lib/security/credentials/external/external_account_credentials.h +2 -7
- data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +2 -3
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +5 -4
- data/src/core/lib/security/credentials/fake/fake_credentials.h +8 -7
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +16 -19
- data/src/core/lib/security/credentials/iam/iam_credentials.h +6 -5
- data/src/core/lib/security/credentials/jwt/json_token.cc +4 -6
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +16 -28
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +8 -8
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +6 -13
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +44 -57
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +13 -15
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -7
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +5 -4
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +1 -10
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +6 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +7 -0
- data/src/core/lib/security/credentials/xds/xds_credentials.h +1 -1
- data/src/core/lib/security/security_connector/security_connector.cc +0 -4
- data/src/core/lib/security/security_connector/security_connector.h +5 -1
- data/src/core/lib/security/security_connector/ssl_utils.cc +14 -24
- data/src/core/lib/security/security_connector/ssl_utils.h +5 -14
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +2 -3
- data/src/core/lib/security/transport/auth_filters.h +7 -0
- data/src/core/lib/security/transport/client_auth_filter.cc +53 -33
- data/src/core/lib/security/transport/server_auth_filter.cc +40 -35
- data/src/core/{ext → lib}/service_config/service_config.cc +2 -2
- data/src/core/{ext → lib}/service_config/service_config.h +4 -4
- data/src/core/{ext → lib}/service_config/service_config_call_data.h +5 -5
- data/src/core/{ext → lib}/service_config/service_config_parser.cc +1 -1
- data/src/core/{ext → lib}/service_config/service_config_parser.h +3 -3
- data/src/core/lib/slice/slice.cc +3 -1
- data/src/core/lib/slice/slice.h +43 -13
- data/src/core/lib/slice/slice_intern.cc +3 -101
- data/src/core/lib/slice/slice_internal.h +1 -2
- data/src/core/lib/slice/slice_refcount.h +4 -13
- data/src/core/lib/slice/slice_refcount_base.h +0 -16
- data/src/core/lib/surface/call.cc +140 -382
- data/src/core/lib/surface/call.h +4 -4
- data/src/core/lib/surface/channel.cc +42 -44
- data/src/core/lib/surface/channel.h +4 -4
- data/src/core/lib/surface/init.cc +0 -2
- data/src/core/lib/surface/lame_client.cc +0 -1
- data/src/core/lib/surface/server.cc +12 -29
- data/src/core/lib/surface/server.h +2 -2
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/error_utils.h +14 -0
- data/src/core/lib/transport/metadata_batch.h +799 -717
- data/src/core/lib/transport/parsed_metadata.cc +2 -0
- data/src/core/lib/transport/parsed_metadata.h +95 -92
- data/src/core/lib/transport/timeout_encoding.cc +200 -66
- data/src/core/lib/transport/timeout_encoding.h +40 -10
- data/src/core/lib/transport/transport.h +1 -1
- data/src/core/lib/transport/transport_op_string.cc +6 -39
- data/src/core/lib/uri/uri_parser.cc +223 -53
- data/src/core/lib/uri/uri_parser.h +36 -23
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -3
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
- data/src/core/tsi/ssl/session_cache/ssl_session.h +2 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +3 -5
- data/src/core/tsi/ssl_transport_security.cc +53 -13
- data/src/core/tsi/ssl_transport_security.h +18 -6
- data/src/ruby/ext/grpc/extconf.rb +10 -3
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -1
- data/third_party/abseil-cpp/absl/base/internal/fast_type_id.h +48 -0
- data/third_party/abseil-cpp/absl/random/bernoulli_distribution.h +200 -0
- data/third_party/abseil-cpp/absl/random/beta_distribution.h +427 -0
- data/third_party/abseil-cpp/absl/random/discrete_distribution.cc +98 -0
- data/third_party/abseil-cpp/absl/random/discrete_distribution.h +247 -0
- data/third_party/abseil-cpp/absl/random/distributions.h +452 -0
- data/third_party/abseil-cpp/absl/random/exponential_distribution.h +165 -0
- data/third_party/abseil-cpp/absl/random/gaussian_distribution.cc +104 -0
- data/third_party/abseil-cpp/absl/random/gaussian_distribution.h +275 -0
- data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +92 -0
- data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +268 -0
- data/third_party/abseil-cpp/absl/random/internal/fastmath.h +57 -0
- data/third_party/abseil-cpp/absl/random/internal/generate_real.h +144 -0
- data/third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h +245 -0
- data/third_party/abseil-cpp/absl/random/internal/nonsecure_base.h +150 -0
- data/third_party/abseil-cpp/absl/random/internal/pcg_engine.h +308 -0
- data/third_party/abseil-cpp/absl/random/internal/platform.h +171 -0
- data/third_party/abseil-cpp/absl/random/internal/pool_urbg.cc +253 -0
- data/third_party/abseil-cpp/absl/random/internal/pool_urbg.h +131 -0
- data/third_party/abseil-cpp/absl/random/internal/randen.cc +91 -0
- data/third_party/abseil-cpp/absl/random/internal/randen.h +102 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +221 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_detect.h +33 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +239 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.cc +526 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_hwaes.h +50 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_round_keys.cc +462 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_slow.cc +471 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_slow.h +40 -0
- data/third_party/abseil-cpp/absl/random/internal/randen_traits.h +88 -0
- data/third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h +167 -0
- data/third_party/abseil-cpp/absl/random/internal/seed_material.cc +267 -0
- data/third_party/abseil-cpp/absl/random/internal/seed_material.h +104 -0
- data/third_party/abseil-cpp/absl/random/internal/traits.h +101 -0
- data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +244 -0
- data/third_party/abseil-cpp/absl/random/internal/wide_multiply.h +111 -0
- data/third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h +257 -0
- data/third_party/abseil-cpp/absl/random/poisson_distribution.h +258 -0
- data/third_party/abseil-cpp/absl/random/random.h +189 -0
- data/third_party/abseil-cpp/absl/random/seed_gen_exception.cc +46 -0
- data/third_party/abseil-cpp/absl/random/seed_gen_exception.h +55 -0
- data/third_party/abseil-cpp/absl/random/seed_sequences.cc +29 -0
- data/third_party/abseil-cpp/absl/random/seed_sequences.h +110 -0
- data/third_party/abseil-cpp/absl/random/uniform_int_distribution.h +275 -0
- data/third_party/abseil-cpp/absl/random/uniform_real_distribution.h +202 -0
- data/third_party/abseil-cpp/absl/random/zipf_distribution.h +271 -0
- data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/base64/base64.c +13 -0
- data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +21 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +12 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +1 -2
- data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/mem.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7.c +29 -0
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +0 -1
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/base64.h +8 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +13 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +10 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +9 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +6 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +23 -2
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +4 -0
- data/third_party/xxhash/xxhash.h +607 -352
- metadata +149 -77
- data/src/core/ext/transport/chttp2/transport/hpack_encoder_index.h +0 -107
- data/src/core/ext/transport/chttp2/transport/hpack_utils.cc +0 -46
- data/src/core/ext/transport/chttp2/transport/popularity_count.h +0 -60
- data/src/core/lib/compression/algorithm_metadata.h +0 -62
- data/src/core/lib/compression/compression_args.cc +0 -140
- data/src/core/lib/compression/compression_args.h +0 -58
- data/src/core/lib/compression/stream_compression.cc +0 -81
- data/src/core/lib/compression/stream_compression.h +0 -117
- data/src/core/lib/compression/stream_compression_gzip.cc +0 -231
- data/src/core/lib/compression/stream_compression_gzip.h +0 -28
- data/src/core/lib/compression/stream_compression_identity.cc +0 -91
- data/src/core/lib/compression/stream_compression_identity.h +0 -29
- data/src/core/lib/security/credentials/credentials_metadata.cc +0 -61
- data/src/core/lib/slice/static_slice.cc +0 -377
- data/src/core/lib/slice/static_slice.h +0 -300
- data/src/core/lib/transport/metadata.cc +0 -714
- data/src/core/lib/transport/metadata.h +0 -449
- data/src/core/lib/transport/metadata_batch.cc +0 -99
- data/src/core/lib/transport/static_metadata.cc +0 -1032
- data/src/core/lib/transport/static_metadata.h +0 -322
- data/src/core/lib/transport/status_metadata.cc +0 -63
- data/src/core/lib/transport/status_metadata.h +0 -48
@@ -0,0 +1,167 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#ifndef ABSL_RANDOM_INTERNAL_SALTED_SEED_SEQ_H_
|
16
|
+
#define ABSL_RANDOM_INTERNAL_SALTED_SEED_SEQ_H_
|
17
|
+
|
18
|
+
#include <cstdint>
|
19
|
+
#include <cstdlib>
|
20
|
+
#include <initializer_list>
|
21
|
+
#include <iterator>
|
22
|
+
#include <memory>
|
23
|
+
#include <type_traits>
|
24
|
+
#include <utility>
|
25
|
+
|
26
|
+
#include "absl/container/inlined_vector.h"
|
27
|
+
#include "absl/meta/type_traits.h"
|
28
|
+
#include "absl/random/internal/seed_material.h"
|
29
|
+
#include "absl/types/optional.h"
|
30
|
+
#include "absl/types/span.h"
|
31
|
+
|
32
|
+
namespace absl {
|
33
|
+
ABSL_NAMESPACE_BEGIN
|
34
|
+
namespace random_internal {
|
35
|
+
|
36
|
+
// This class conforms to the C++ Standard "Seed Sequence" concept
|
37
|
+
// [rand.req.seedseq].
|
38
|
+
//
|
39
|
+
// A `SaltedSeedSeq` is meant to wrap an existing seed sequence and modify
|
40
|
+
// generated sequence by mixing with extra entropy. This entropy may be
|
41
|
+
// build-dependent or process-dependent. The implementation may change to be
|
42
|
+
// have either or both kinds of entropy. If salt is not available sequence is
|
43
|
+
// not modified.
|
44
|
+
template <typename SSeq>
|
45
|
+
class SaltedSeedSeq {
|
46
|
+
public:
|
47
|
+
using inner_sequence_type = SSeq;
|
48
|
+
using result_type = typename SSeq::result_type;
|
49
|
+
|
50
|
+
SaltedSeedSeq() : seq_(absl::make_unique<SSeq>()) {}
|
51
|
+
|
52
|
+
template <typename Iterator>
|
53
|
+
SaltedSeedSeq(Iterator begin, Iterator end)
|
54
|
+
: seq_(absl::make_unique<SSeq>(begin, end)) {}
|
55
|
+
|
56
|
+
template <typename T>
|
57
|
+
SaltedSeedSeq(std::initializer_list<T> il)
|
58
|
+
: SaltedSeedSeq(il.begin(), il.end()) {}
|
59
|
+
|
60
|
+
SaltedSeedSeq(const SaltedSeedSeq&) = delete;
|
61
|
+
SaltedSeedSeq& operator=(const SaltedSeedSeq&) = delete;
|
62
|
+
|
63
|
+
SaltedSeedSeq(SaltedSeedSeq&&) = default;
|
64
|
+
SaltedSeedSeq& operator=(SaltedSeedSeq&&) = default;
|
65
|
+
|
66
|
+
template <typename RandomAccessIterator>
|
67
|
+
void generate(RandomAccessIterator begin, RandomAccessIterator end) {
|
68
|
+
// The common case is that generate is called with ContiguousIterators
|
69
|
+
// to uint arrays. Such contiguous memory regions may be optimized,
|
70
|
+
// which we detect here.
|
71
|
+
using tag = absl::conditional_t<
|
72
|
+
(std::is_pointer<RandomAccessIterator>::value &&
|
73
|
+
std::is_same<absl::decay_t<decltype(*begin)>, uint32_t>::value),
|
74
|
+
ContiguousAndUint32Tag, DefaultTag>;
|
75
|
+
if (begin != end) {
|
76
|
+
generate_impl(begin, end, tag{});
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
template <typename OutIterator>
|
81
|
+
void param(OutIterator out) const {
|
82
|
+
seq_->param(out);
|
83
|
+
}
|
84
|
+
|
85
|
+
size_t size() const { return seq_->size(); }
|
86
|
+
|
87
|
+
private:
|
88
|
+
struct ContiguousAndUint32Tag {};
|
89
|
+
struct DefaultTag {};
|
90
|
+
|
91
|
+
// Generate which requires the iterators are contiguous pointers to uint32_t.
|
92
|
+
void generate_impl(uint32_t* begin, uint32_t* end, ContiguousAndUint32Tag) {
|
93
|
+
generate_contiguous(absl::MakeSpan(begin, end));
|
94
|
+
}
|
95
|
+
|
96
|
+
// The uncommon case for generate is that it is called with iterators over
|
97
|
+
// some other buffer type which is assignable from a 32-bit value. In this
|
98
|
+
// case we allocate a temporary 32-bit buffer and then copy-assign back
|
99
|
+
// to the initial inputs.
|
100
|
+
template <typename RandomAccessIterator>
|
101
|
+
void generate_impl(RandomAccessIterator begin, RandomAccessIterator end,
|
102
|
+
DefaultTag) {
|
103
|
+
return generate_and_copy(std::distance(begin, end), begin);
|
104
|
+
}
|
105
|
+
|
106
|
+
// Fills the initial seed buffer the underlying SSeq::generate() call,
|
107
|
+
// mixing in the salt material.
|
108
|
+
void generate_contiguous(absl::Span<uint32_t> buffer) {
|
109
|
+
seq_->generate(buffer.begin(), buffer.end());
|
110
|
+
const uint32_t salt = absl::random_internal::GetSaltMaterial().value_or(0);
|
111
|
+
MixIntoSeedMaterial(absl::MakeConstSpan(&salt, 1), buffer);
|
112
|
+
}
|
113
|
+
|
114
|
+
// Allocates a seed buffer of `n` elements, generates the seed, then
|
115
|
+
// copies the result into the `out` iterator.
|
116
|
+
template <typename Iterator>
|
117
|
+
void generate_and_copy(size_t n, Iterator out) {
|
118
|
+
// Allocate a temporary buffer, generate, and then copy.
|
119
|
+
absl::InlinedVector<uint32_t, 8> data(n, 0);
|
120
|
+
generate_contiguous(absl::MakeSpan(data.data(), data.size()));
|
121
|
+
std::copy(data.begin(), data.end(), out);
|
122
|
+
}
|
123
|
+
|
124
|
+
// Because [rand.req.seedseq] is not required to be copy-constructible,
|
125
|
+
// copy-assignable nor movable, we wrap it with unique pointer to be able
|
126
|
+
// to move SaltedSeedSeq.
|
127
|
+
std::unique_ptr<SSeq> seq_;
|
128
|
+
};
|
129
|
+
|
130
|
+
// is_salted_seed_seq indicates whether the type is a SaltedSeedSeq.
|
131
|
+
template <typename T, typename = void>
|
132
|
+
struct is_salted_seed_seq : public std::false_type {};
|
133
|
+
|
134
|
+
template <typename T>
|
135
|
+
struct is_salted_seed_seq<
|
136
|
+
T, typename std::enable_if<std::is_same<
|
137
|
+
T, SaltedSeedSeq<typename T::inner_sequence_type>>::value>::type>
|
138
|
+
: public std::true_type {};
|
139
|
+
|
140
|
+
// MakeSaltedSeedSeq returns a salted variant of the seed sequence.
|
141
|
+
// When provided with an existing SaltedSeedSeq, returns the input parameter,
|
142
|
+
// otherwise constructs a new SaltedSeedSeq which embodies the original
|
143
|
+
// non-salted seed parameters.
|
144
|
+
template <
|
145
|
+
typename SSeq, //
|
146
|
+
typename EnableIf = absl::enable_if_t<is_salted_seed_seq<SSeq>::value>>
|
147
|
+
SSeq MakeSaltedSeedSeq(SSeq&& seq) {
|
148
|
+
return SSeq(std::forward<SSeq>(seq));
|
149
|
+
}
|
150
|
+
|
151
|
+
template <
|
152
|
+
typename SSeq, //
|
153
|
+
typename EnableIf = absl::enable_if_t<!is_salted_seed_seq<SSeq>::value>>
|
154
|
+
SaltedSeedSeq<typename std::decay<SSeq>::type> MakeSaltedSeedSeq(SSeq&& seq) {
|
155
|
+
using sseq_type = typename std::decay<SSeq>::type;
|
156
|
+
using result_type = typename sseq_type::result_type;
|
157
|
+
|
158
|
+
absl::InlinedVector<result_type, 8> data;
|
159
|
+
seq.param(std::back_inserter(data));
|
160
|
+
return SaltedSeedSeq<sseq_type>(data.begin(), data.end());
|
161
|
+
}
|
162
|
+
|
163
|
+
} // namespace random_internal
|
164
|
+
ABSL_NAMESPACE_END
|
165
|
+
} // namespace absl
|
166
|
+
|
167
|
+
#endif // ABSL_RANDOM_INTERNAL_SALTED_SEED_SEQ_H_
|
@@ -0,0 +1,267 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#include "absl/random/internal/seed_material.h"
|
16
|
+
|
17
|
+
#include <fcntl.h>
|
18
|
+
|
19
|
+
#ifndef _WIN32
|
20
|
+
#include <unistd.h>
|
21
|
+
#else
|
22
|
+
#include <io.h>
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#include <algorithm>
|
26
|
+
#include <cerrno>
|
27
|
+
#include <cstdint>
|
28
|
+
#include <cstdlib>
|
29
|
+
#include <cstring>
|
30
|
+
|
31
|
+
#include "absl/base/dynamic_annotations.h"
|
32
|
+
#include "absl/base/internal/raw_logging.h"
|
33
|
+
#include "absl/strings/ascii.h"
|
34
|
+
#include "absl/strings/escaping.h"
|
35
|
+
#include "absl/strings/string_view.h"
|
36
|
+
#include "absl/strings/strip.h"
|
37
|
+
|
38
|
+
#if defined(__native_client__)
|
39
|
+
|
40
|
+
#include <nacl/nacl_random.h>
|
41
|
+
#define ABSL_RANDOM_USE_NACL_SECURE_RANDOM 1
|
42
|
+
|
43
|
+
#elif defined(_WIN32)
|
44
|
+
|
45
|
+
#include <windows.h>
|
46
|
+
#define ABSL_RANDOM_USE_BCRYPT 1
|
47
|
+
#pragma comment(lib, "bcrypt.lib")
|
48
|
+
|
49
|
+
#elif defined(__Fuchsia__)
|
50
|
+
#include <zircon/syscalls.h>
|
51
|
+
|
52
|
+
#endif
|
53
|
+
|
54
|
+
#if defined(__GLIBC__) && \
|
55
|
+
(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
|
56
|
+
// glibc >= 2.25 has getentropy()
|
57
|
+
#define ABSL_RANDOM_USE_GET_ENTROPY 1
|
58
|
+
#endif
|
59
|
+
|
60
|
+
#if defined(__EMSCRIPTEN__)
|
61
|
+
#include <sys/random.h>
|
62
|
+
// Emscripten has getentropy, but it resides in a different header.
|
63
|
+
#define ABSL_RANDOM_USE_GET_ENTROPY 1
|
64
|
+
#endif
|
65
|
+
|
66
|
+
#if defined(ABSL_RANDOM_USE_BCRYPT)
|
67
|
+
#include <bcrypt.h>
|
68
|
+
|
69
|
+
#ifndef BCRYPT_SUCCESS
|
70
|
+
#define BCRYPT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
|
71
|
+
#endif
|
72
|
+
// Also link bcrypt; this can be done via linker options or:
|
73
|
+
// #pragma comment(lib, "bcrypt.lib")
|
74
|
+
#endif
|
75
|
+
|
76
|
+
namespace absl {
|
77
|
+
ABSL_NAMESPACE_BEGIN
|
78
|
+
namespace random_internal {
|
79
|
+
namespace {
|
80
|
+
|
81
|
+
// Read OS Entropy for random number seeds.
|
82
|
+
// TODO(absl-team): Possibly place a cap on how much entropy may be read at a
|
83
|
+
// time.
|
84
|
+
|
85
|
+
#if defined(ABSL_RANDOM_USE_BCRYPT)
|
86
|
+
|
87
|
+
// On Windows potentially use the BCRYPT CNG API to read available entropy.
|
88
|
+
bool ReadSeedMaterialFromOSEntropyImpl(absl::Span<uint32_t> values) {
|
89
|
+
BCRYPT_ALG_HANDLE hProvider;
|
90
|
+
NTSTATUS ret;
|
91
|
+
ret = BCryptOpenAlgorithmProvider(&hProvider, BCRYPT_RNG_ALGORITHM,
|
92
|
+
MS_PRIMITIVE_PROVIDER, 0);
|
93
|
+
if (!(BCRYPT_SUCCESS(ret))) {
|
94
|
+
ABSL_RAW_LOG(ERROR, "Failed to open crypto provider.");
|
95
|
+
return false;
|
96
|
+
}
|
97
|
+
ret = BCryptGenRandom(
|
98
|
+
hProvider, // provider
|
99
|
+
reinterpret_cast<UCHAR*>(values.data()), // buffer
|
100
|
+
static_cast<ULONG>(sizeof(uint32_t) * values.size()), // bytes
|
101
|
+
0); // flags
|
102
|
+
BCryptCloseAlgorithmProvider(hProvider, 0);
|
103
|
+
return BCRYPT_SUCCESS(ret);
|
104
|
+
}
|
105
|
+
|
106
|
+
#elif defined(ABSL_RANDOM_USE_NACL_SECURE_RANDOM)
|
107
|
+
|
108
|
+
// On NaCL use nacl_secure_random to acquire bytes.
|
109
|
+
bool ReadSeedMaterialFromOSEntropyImpl(absl::Span<uint32_t> values) {
|
110
|
+
auto buffer = reinterpret_cast<uint8_t*>(values.data());
|
111
|
+
size_t buffer_size = sizeof(uint32_t) * values.size();
|
112
|
+
|
113
|
+
uint8_t* output_ptr = buffer;
|
114
|
+
while (buffer_size > 0) {
|
115
|
+
size_t nread = 0;
|
116
|
+
const int error = nacl_secure_random(output_ptr, buffer_size, &nread);
|
117
|
+
if (error != 0 || nread > buffer_size) {
|
118
|
+
ABSL_RAW_LOG(ERROR, "Failed to read secure_random seed data: %d", error);
|
119
|
+
return false;
|
120
|
+
}
|
121
|
+
output_ptr += nread;
|
122
|
+
buffer_size -= nread;
|
123
|
+
}
|
124
|
+
return true;
|
125
|
+
}
|
126
|
+
|
127
|
+
#elif defined(__Fuchsia__)
|
128
|
+
|
129
|
+
bool ReadSeedMaterialFromOSEntropyImpl(absl::Span<uint32_t> values) {
|
130
|
+
auto buffer = reinterpret_cast<uint8_t*>(values.data());
|
131
|
+
size_t buffer_size = sizeof(uint32_t) * values.size();
|
132
|
+
zx_cprng_draw(buffer, buffer_size);
|
133
|
+
return true;
|
134
|
+
}
|
135
|
+
|
136
|
+
#else
|
137
|
+
|
138
|
+
#if defined(ABSL_RANDOM_USE_GET_ENTROPY)
|
139
|
+
// On *nix, use getentropy() if supported. Note that libc may support
|
140
|
+
// getentropy(), but the kernel may not, in which case this function will return
|
141
|
+
// false.
|
142
|
+
bool ReadSeedMaterialFromGetEntropy(absl::Span<uint32_t> values) {
|
143
|
+
auto buffer = reinterpret_cast<uint8_t*>(values.data());
|
144
|
+
size_t buffer_size = sizeof(uint32_t) * values.size();
|
145
|
+
while (buffer_size > 0) {
|
146
|
+
// getentropy() has a maximum permitted length of 256.
|
147
|
+
size_t to_read = std::min<size_t>(buffer_size, 256);
|
148
|
+
int result = getentropy(buffer, to_read);
|
149
|
+
if (result < 0) {
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
// https://github.com/google/sanitizers/issues/1173
|
153
|
+
// MemorySanitizer can't see through getentropy().
|
154
|
+
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(buffer, to_read);
|
155
|
+
buffer += to_read;
|
156
|
+
buffer_size -= to_read;
|
157
|
+
}
|
158
|
+
return true;
|
159
|
+
}
|
160
|
+
#endif // defined(ABSL_RANDOM_GETENTROPY)
|
161
|
+
|
162
|
+
// On *nix, read entropy from /dev/urandom.
|
163
|
+
bool ReadSeedMaterialFromDevURandom(absl::Span<uint32_t> values) {
|
164
|
+
const char kEntropyFile[] = "/dev/urandom";
|
165
|
+
|
166
|
+
auto buffer = reinterpret_cast<uint8_t*>(values.data());
|
167
|
+
size_t buffer_size = sizeof(uint32_t) * values.size();
|
168
|
+
|
169
|
+
int dev_urandom = open(kEntropyFile, O_RDONLY);
|
170
|
+
bool success = (-1 != dev_urandom);
|
171
|
+
if (!success) {
|
172
|
+
return false;
|
173
|
+
}
|
174
|
+
|
175
|
+
while (success && buffer_size > 0) {
|
176
|
+
int bytes_read = read(dev_urandom, buffer, buffer_size);
|
177
|
+
int read_error = errno;
|
178
|
+
success = (bytes_read > 0);
|
179
|
+
if (success) {
|
180
|
+
buffer += bytes_read;
|
181
|
+
buffer_size -= bytes_read;
|
182
|
+
} else if (bytes_read == -1 && read_error == EINTR) {
|
183
|
+
success = true; // Need to try again.
|
184
|
+
}
|
185
|
+
}
|
186
|
+
close(dev_urandom);
|
187
|
+
return success;
|
188
|
+
}
|
189
|
+
|
190
|
+
bool ReadSeedMaterialFromOSEntropyImpl(absl::Span<uint32_t> values) {
|
191
|
+
#if defined(ABSL_RANDOM_USE_GET_ENTROPY)
|
192
|
+
if (ReadSeedMaterialFromGetEntropy(values)) {
|
193
|
+
return true;
|
194
|
+
}
|
195
|
+
#endif
|
196
|
+
// Libc may support getentropy, but the kernel may not, so we still have
|
197
|
+
// to fallback to ReadSeedMaterialFromDevURandom().
|
198
|
+
return ReadSeedMaterialFromDevURandom(values);
|
199
|
+
}
|
200
|
+
|
201
|
+
#endif
|
202
|
+
|
203
|
+
} // namespace
|
204
|
+
|
205
|
+
bool ReadSeedMaterialFromOSEntropy(absl::Span<uint32_t> values) {
|
206
|
+
assert(values.data() != nullptr);
|
207
|
+
if (values.data() == nullptr) {
|
208
|
+
return false;
|
209
|
+
}
|
210
|
+
if (values.empty()) {
|
211
|
+
return true;
|
212
|
+
}
|
213
|
+
return ReadSeedMaterialFromOSEntropyImpl(values);
|
214
|
+
}
|
215
|
+
|
216
|
+
void MixIntoSeedMaterial(absl::Span<const uint32_t> sequence,
|
217
|
+
absl::Span<uint32_t> seed_material) {
|
218
|
+
// Algorithm is based on code available at
|
219
|
+
// https://gist.github.com/imneme/540829265469e673d045
|
220
|
+
constexpr uint32_t kInitVal = 0x43b0d7e5;
|
221
|
+
constexpr uint32_t kHashMul = 0x931e8875;
|
222
|
+
constexpr uint32_t kMixMulL = 0xca01f9dd;
|
223
|
+
constexpr uint32_t kMixMulR = 0x4973f715;
|
224
|
+
constexpr uint32_t kShiftSize = sizeof(uint32_t) * 8 / 2;
|
225
|
+
|
226
|
+
uint32_t hash_const = kInitVal;
|
227
|
+
auto hash = [&](uint32_t value) {
|
228
|
+
value ^= hash_const;
|
229
|
+
hash_const *= kHashMul;
|
230
|
+
value *= hash_const;
|
231
|
+
value ^= value >> kShiftSize;
|
232
|
+
return value;
|
233
|
+
};
|
234
|
+
|
235
|
+
auto mix = [&](uint32_t x, uint32_t y) {
|
236
|
+
uint32_t result = kMixMulL * x - kMixMulR * y;
|
237
|
+
result ^= result >> kShiftSize;
|
238
|
+
return result;
|
239
|
+
};
|
240
|
+
|
241
|
+
for (const auto& seq_val : sequence) {
|
242
|
+
for (auto& elem : seed_material) {
|
243
|
+
elem = mix(elem, hash(seq_val));
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
absl::optional<uint32_t> GetSaltMaterial() {
|
249
|
+
// Salt must be common for all generators within the same process so read it
|
250
|
+
// only once and store in static variable.
|
251
|
+
static const auto salt_material = []() -> absl::optional<uint32_t> {
|
252
|
+
uint32_t salt_value = 0;
|
253
|
+
|
254
|
+
if (random_internal::ReadSeedMaterialFromOSEntropy(
|
255
|
+
MakeSpan(&salt_value, 1))) {
|
256
|
+
return salt_value;
|
257
|
+
}
|
258
|
+
|
259
|
+
return absl::nullopt;
|
260
|
+
}();
|
261
|
+
|
262
|
+
return salt_material;
|
263
|
+
}
|
264
|
+
|
265
|
+
} // namespace random_internal
|
266
|
+
ABSL_NAMESPACE_END
|
267
|
+
} // namespace absl
|
@@ -0,0 +1,104 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#ifndef ABSL_RANDOM_INTERNAL_SEED_MATERIAL_H_
|
16
|
+
#define ABSL_RANDOM_INTERNAL_SEED_MATERIAL_H_
|
17
|
+
|
18
|
+
#include <cassert>
|
19
|
+
#include <cstdint>
|
20
|
+
#include <cstdlib>
|
21
|
+
#include <string>
|
22
|
+
#include <vector>
|
23
|
+
|
24
|
+
#include "absl/base/attributes.h"
|
25
|
+
#include "absl/random/internal/fast_uniform_bits.h"
|
26
|
+
#include "absl/types/optional.h"
|
27
|
+
#include "absl/types/span.h"
|
28
|
+
|
29
|
+
namespace absl {
|
30
|
+
ABSL_NAMESPACE_BEGIN
|
31
|
+
namespace random_internal {
|
32
|
+
|
33
|
+
// Returns the number of 32-bit blocks needed to contain the given number of
|
34
|
+
// bits.
|
35
|
+
constexpr size_t SeedBitsToBlocks(size_t seed_size) {
|
36
|
+
return (seed_size + 31) / 32;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Amount of entropy (measured in bits) used to instantiate a Seed Sequence,
|
40
|
+
// with which to create a URBG.
|
41
|
+
constexpr size_t kEntropyBitsNeeded = 256;
|
42
|
+
|
43
|
+
// Amount of entropy (measured in 32-bit blocks) used to instantiate a Seed
|
44
|
+
// Sequence, with which to create a URBG.
|
45
|
+
constexpr size_t kEntropyBlocksNeeded =
|
46
|
+
random_internal::SeedBitsToBlocks(kEntropyBitsNeeded);
|
47
|
+
|
48
|
+
static_assert(kEntropyBlocksNeeded > 0,
|
49
|
+
"Entropy used to seed URBGs must be nonzero.");
|
50
|
+
|
51
|
+
// Attempts to fill a span of uint32_t-values using an OS-provided source of
|
52
|
+
// true entropy (eg. /dev/urandom) into an array of uint32_t blocks of data. The
|
53
|
+
// resulting array may be used to initialize an instance of a class conforming
|
54
|
+
// to the C++ Standard "Seed Sequence" concept [rand.req.seedseq].
|
55
|
+
//
|
56
|
+
// If values.data() == nullptr, the behavior is undefined.
|
57
|
+
ABSL_MUST_USE_RESULT
|
58
|
+
bool ReadSeedMaterialFromOSEntropy(absl::Span<uint32_t> values);
|
59
|
+
|
60
|
+
// Attempts to fill a span of uint32_t-values using variates generated by an
|
61
|
+
// existing instance of a class conforming to the C++ Standard "Uniform Random
|
62
|
+
// Bit Generator" concept [rand.req.urng]. The resulting data may be used to
|
63
|
+
// initialize an instance of a class conforming to the C++ Standard
|
64
|
+
// "Seed Sequence" concept [rand.req.seedseq].
|
65
|
+
//
|
66
|
+
// If urbg == nullptr or values.data() == nullptr, the behavior is undefined.
|
67
|
+
template <typename URBG>
|
68
|
+
ABSL_MUST_USE_RESULT bool ReadSeedMaterialFromURBG(
|
69
|
+
URBG* urbg, absl::Span<uint32_t> values) {
|
70
|
+
random_internal::FastUniformBits<uint32_t> distr;
|
71
|
+
|
72
|
+
assert(urbg != nullptr && values.data() != nullptr);
|
73
|
+
if (urbg == nullptr || values.data() == nullptr) {
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
|
77
|
+
for (uint32_t& seed_value : values) {
|
78
|
+
seed_value = distr(*urbg);
|
79
|
+
}
|
80
|
+
return true;
|
81
|
+
}
|
82
|
+
|
83
|
+
// Mixes given sequence of values with into given sequence of seed material.
|
84
|
+
// Time complexity of this function is O(sequence.size() *
|
85
|
+
// seed_material.size()).
|
86
|
+
//
|
87
|
+
// Algorithm is based on code available at
|
88
|
+
// https://gist.github.com/imneme/540829265469e673d045
|
89
|
+
// by Melissa O'Neill.
|
90
|
+
void MixIntoSeedMaterial(absl::Span<const uint32_t> sequence,
|
91
|
+
absl::Span<uint32_t> seed_material);
|
92
|
+
|
93
|
+
// Returns salt value.
|
94
|
+
//
|
95
|
+
// Salt is obtained only once and stored in static variable.
|
96
|
+
//
|
97
|
+
// May return empty value if optaining the salt was not possible.
|
98
|
+
absl::optional<uint32_t> GetSaltMaterial();
|
99
|
+
|
100
|
+
} // namespace random_internal
|
101
|
+
ABSL_NAMESPACE_END
|
102
|
+
} // namespace absl
|
103
|
+
|
104
|
+
#endif // ABSL_RANDOM_INTERNAL_SEED_MATERIAL_H_
|
@@ -0,0 +1,101 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#ifndef ABSL_RANDOM_INTERNAL_TRAITS_H_
|
16
|
+
#define ABSL_RANDOM_INTERNAL_TRAITS_H_
|
17
|
+
|
18
|
+
#include <cstdint>
|
19
|
+
#include <limits>
|
20
|
+
#include <type_traits>
|
21
|
+
|
22
|
+
#include "absl/base/config.h"
|
23
|
+
|
24
|
+
namespace absl {
|
25
|
+
ABSL_NAMESPACE_BEGIN
|
26
|
+
namespace random_internal {
|
27
|
+
|
28
|
+
// random_internal::is_widening_convertible<A, B>
|
29
|
+
//
|
30
|
+
// Returns whether a type A is widening-convertible to a type B.
|
31
|
+
//
|
32
|
+
// A is widening-convertible to B means:
|
33
|
+
// A a = <any number>;
|
34
|
+
// B b = a;
|
35
|
+
// A c = b;
|
36
|
+
// EXPECT_EQ(a, c);
|
37
|
+
template <typename A, typename B>
|
38
|
+
class is_widening_convertible {
|
39
|
+
// As long as there are enough bits in the exact part of a number:
|
40
|
+
// - unsigned can fit in float, signed, unsigned
|
41
|
+
// - signed can fit in float, signed
|
42
|
+
// - float can fit in float
|
43
|
+
// So we define rank to be:
|
44
|
+
// - rank(float) -> 2
|
45
|
+
// - rank(signed) -> 1
|
46
|
+
// - rank(unsigned) -> 0
|
47
|
+
template <class T>
|
48
|
+
static constexpr int rank() {
|
49
|
+
return !std::numeric_limits<T>::is_integer +
|
50
|
+
std::numeric_limits<T>::is_signed;
|
51
|
+
}
|
52
|
+
|
53
|
+
public:
|
54
|
+
// If an arithmetic-type B can represent at least as many digits as a type A,
|
55
|
+
// and B belongs to a rank no lower than A, then A can be safely represented
|
56
|
+
// by B through a widening-conversion.
|
57
|
+
static constexpr bool value =
|
58
|
+
std::numeric_limits<A>::digits <= std::numeric_limits<B>::digits &&
|
59
|
+
rank<A>() <= rank<B>();
|
60
|
+
};
|
61
|
+
|
62
|
+
// unsigned_bits<N>::type returns the unsigned int type with the indicated
|
63
|
+
// number of bits.
|
64
|
+
template <size_t N>
|
65
|
+
struct unsigned_bits;
|
66
|
+
|
67
|
+
template <>
|
68
|
+
struct unsigned_bits<8> {
|
69
|
+
using type = uint8_t;
|
70
|
+
};
|
71
|
+
template <>
|
72
|
+
struct unsigned_bits<16> {
|
73
|
+
using type = uint16_t;
|
74
|
+
};
|
75
|
+
template <>
|
76
|
+
struct unsigned_bits<32> {
|
77
|
+
using type = uint32_t;
|
78
|
+
};
|
79
|
+
template <>
|
80
|
+
struct unsigned_bits<64> {
|
81
|
+
using type = uint64_t;
|
82
|
+
};
|
83
|
+
|
84
|
+
#ifdef ABSL_HAVE_INTRINSIC_INT128
|
85
|
+
template <>
|
86
|
+
struct unsigned_bits<128> {
|
87
|
+
using type = __uint128_t;
|
88
|
+
};
|
89
|
+
#endif
|
90
|
+
|
91
|
+
template <typename IntType>
|
92
|
+
struct make_unsigned_bits {
|
93
|
+
using type = typename unsigned_bits<std::numeric_limits<
|
94
|
+
typename std::make_unsigned<IntType>::type>::digits>::type;
|
95
|
+
};
|
96
|
+
|
97
|
+
} // namespace random_internal
|
98
|
+
ABSL_NAMESPACE_END
|
99
|
+
} // namespace absl
|
100
|
+
|
101
|
+
#endif // ABSL_RANDOM_INTERNAL_TRAITS_H_
|