wearefair-grpc 1.3.1.pre.a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/Makefile +19484 -0
- data/etc/roots.pem +5288 -0
- data/include/grpc/byte_buffer.h +102 -0
- data/include/grpc/byte_buffer_reader.h +39 -0
- data/include/grpc/census.h +484 -0
- data/include/grpc/compression.h +85 -0
- data/include/grpc/grpc.h +509 -0
- data/include/grpc/grpc_cronet.h +51 -0
- data/include/grpc/grpc_posix.h +81 -0
- data/include/grpc/grpc_security.h +390 -0
- data/include/grpc/grpc_security_constants.h +114 -0
- data/include/grpc/impl/codegen/atm.h +100 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +97 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +97 -0
- data/include/grpc/impl/codegen/atm_windows.h +140 -0
- data/include/grpc/impl/codegen/byte_buffer_reader.h +57 -0
- data/include/grpc/impl/codegen/compression_types.h +122 -0
- data/include/grpc/impl/codegen/connectivity_state.h +61 -0
- data/include/grpc/impl/codegen/exec_ctx_fwd.h +41 -0
- data/include/grpc/impl/codegen/gpr_slice.h +84 -0
- data/include/grpc/impl/codegen/gpr_types.h +75 -0
- data/include/grpc/impl/codegen/grpc_types.h +550 -0
- data/include/grpc/impl/codegen/port_platform.h +421 -0
- data/include/grpc/impl/codegen/propagation_bits.h +67 -0
- data/include/grpc/impl/codegen/slice.h +157 -0
- data/include/grpc/impl/codegen/status.h +163 -0
- data/include/grpc/impl/codegen/sync.h +75 -0
- data/include/grpc/impl/codegen/sync_generic.h +55 -0
- data/include/grpc/impl/codegen/sync_posix.h +47 -0
- data/include/grpc/impl/codegen/sync_windows.h +49 -0
- data/include/grpc/load_reporting.h +63 -0
- data/include/grpc/module.modulemap +13 -0
- data/include/grpc/slice.h +168 -0
- data/include/grpc/slice_buffer.h +94 -0
- data/include/grpc/status.h +39 -0
- data/include/grpc/support/alloc.h +82 -0
- data/include/grpc/support/atm.h +39 -0
- data/include/grpc/support/atm_gcc_atomic.h +39 -0
- data/include/grpc/support/atm_gcc_sync.h +39 -0
- data/include/grpc/support/atm_windows.h +39 -0
- data/include/grpc/support/avl.h +97 -0
- data/include/grpc/support/cmdline.h +103 -0
- data/include/grpc/support/cpu.h +59 -0
- data/include/grpc/support/histogram.h +79 -0
- data/include/grpc/support/host_port.h +66 -0
- data/include/grpc/support/log.h +118 -0
- data/include/grpc/support/log_windows.h +53 -0
- data/include/grpc/support/port_platform.h +39 -0
- data/include/grpc/support/string_util.h +64 -0
- data/include/grpc/support/subprocess.h +59 -0
- data/include/grpc/support/sync.h +295 -0
- data/include/grpc/support/sync_generic.h +39 -0
- data/include/grpc/support/sync_posix.h +39 -0
- data/include/grpc/support/sync_windows.h +39 -0
- data/include/grpc/support/thd.h +91 -0
- data/include/grpc/support/time.h +105 -0
- data/include/grpc/support/tls.h +77 -0
- data/include/grpc/support/tls_gcc.h +100 -0
- data/include/grpc/support/tls_msvc.h +56 -0
- data/include/grpc/support/tls_pthread.h +60 -0
- data/include/grpc/support/useful.h +80 -0
- data/src/boringssl/err_data.c +1270 -0
- data/src/core/ext/census/aggregation.h +66 -0
- data/src/core/ext/census/base_resources.c +71 -0
- data/src/core/ext/census/base_resources.h +39 -0
- data/src/core/ext/census/census_interface.h +76 -0
- data/src/core/ext/census/census_rpc_stats.h +101 -0
- data/src/core/ext/census/context.c +509 -0
- data/src/core/ext/census/gen/census.pb.c +176 -0
- data/src/core/ext/census/gen/census.pb.h +295 -0
- data/src/core/ext/census/gen/trace_context.pb.c +54 -0
- data/src/core/ext/census/gen/trace_context.pb.h +93 -0
- data/src/core/ext/census/grpc_context.c +53 -0
- data/src/core/ext/census/grpc_filter.c +213 -0
- data/src/core/ext/census/grpc_filter.h +44 -0
- data/src/core/ext/census/grpc_plugin.c +85 -0
- data/src/core/ext/census/initialize.c +66 -0
- data/src/core/ext/census/mlog.c +600 -0
- data/src/core/ext/census/mlog.h +95 -0
- data/src/core/ext/census/operation.c +63 -0
- data/src/core/ext/census/placeholders.c +64 -0
- data/src/core/ext/census/resource.c +312 -0
- data/src/core/ext/census/resource.h +63 -0
- data/src/core/ext/census/rpc_metric_id.h +51 -0
- data/src/core/ext/census/trace_context.c +86 -0
- data/src/core/ext/census/trace_context.h +71 -0
- data/src/core/ext/census/trace_label.h +61 -0
- data/src/core/ext/census/trace_propagation.h +63 -0
- data/src/core/ext/census/trace_status.h +45 -0
- data/src/core/ext/census/trace_string.h +50 -0
- data/src/core/ext/census/tracing.c +71 -0
- data/src/core/ext/census/tracing.h +124 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.c +226 -0
- data/src/core/ext/filters/client_channel/client_channel.c +1410 -0
- data/src/core/ext/filters/client_channel/client_channel.h +64 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.c +87 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.h +92 -0
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +106 -0
- data/src/core/ext/filters/client_channel/connector.c +55 -0
- data/src/core/ext/filters/client_channel/connector.h +88 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.c +389 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +49 -0
- data/src/core/ext/filters/client_channel/http_proxy.c +125 -0
- data/src/core/ext/filters/client_channel/http_proxy.h +39 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +1419 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +44 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +57 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +249 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +105 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +88 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +158 -0
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +476 -0
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +795 -0
- data/src/core/ext/filters/client_channel/lb_policy.c +167 -0
- data/src/core/ext/filters/client_channel/lb_policy.h +209 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +163 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +134 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.c +85 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +55 -0
- data/src/core/ext/filters/client_channel/parse_address.c +170 -0
- data/src/core/ext/filters/client_channel/parse_address.h +54 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.c +63 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.h +89 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +139 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +59 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.c +325 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +234 -0
- data/src/core/ext/filters/client_channel/resolver.c +88 -0
- data/src/core/ext/filters/client_channel/resolver.h +101 -0
- data/src/core/ext/filters/client_channel/resolver_factory.c +56 -0
- data/src/core/ext/filters/client_channel/resolver_factory.h +85 -0
- data/src/core/ext/filters/client_channel/resolver_registry.c +174 -0
- data/src/core/ext/filters/client_channel/resolver_registry.h +84 -0
- data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
- data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
- data/src/core/ext/filters/client_channel/subchannel.c +835 -0
- data/src/core/ext/filters/client_channel/subchannel.h +203 -0
- data/src/core/ext/filters/client_channel/subchannel_index.c +262 -0
- data/src/core/ext/filters/client_channel/subchannel_index.h +77 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +315 -0
- data/src/core/ext/filters/client_channel/uri_parser.h +65 -0
- data/src/core/ext/filters/load_reporting/load_reporting.c +106 -0
- data/src/core/ext/filters/load_reporting/load_reporting.h +73 -0
- data/src/core/ext/filters/load_reporting/load_reporting_filter.c +218 -0
- data/src/core/ext/filters/load_reporting/load_reporting_filter.h +42 -0
- data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
- data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.c +56 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +49 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +221 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +41 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +121 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +239 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +304 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +47 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +59 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +90 -0
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +101 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +236 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +67 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +241 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +54 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +43 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +2847 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +53 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +61 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.c +287 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.h +104 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +198 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +78 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +145 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +59 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +125 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +58 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +239 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +76 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +134 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +57 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +661 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +107 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +1734 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +129 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +383 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +112 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.c +105 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.h +48 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +88 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +63 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +852 -0
- data/src/core/ext/transport/chttp2/transport/parsing.c +825 -0
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +194 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.c +176 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.h +83 -0
- data/src/core/ext/transport/chttp2/transport/varint.c +65 -0
- data/src/core/ext/transport/chttp2/transport/varint.h +75 -0
- data/src/core/ext/transport/chttp2/transport/writing.c +429 -0
- data/src/core/lib/channel/channel_args.c +355 -0
- data/src/core/lib/channel/channel_args.h +126 -0
- data/src/core/lib/channel/channel_stack.c +291 -0
- data/src/core/lib/channel/channel_stack.h +319 -0
- data/src/core/lib/channel/channel_stack_builder.c +284 -0
- data/src/core/lib/channel/channel_stack_builder.h +170 -0
- data/src/core/lib/channel/compress_filter.c +353 -0
- data/src/core/lib/channel/compress_filter.h +67 -0
- data/src/core/lib/channel/connected_channel.c +188 -0
- data/src/core/lib/channel/connected_channel.h +48 -0
- data/src/core/lib/channel/context.h +64 -0
- data/src/core/lib/channel/deadline_filter.c +348 -0
- data/src/core/lib/channel/deadline_filter.h +102 -0
- data/src/core/lib/channel/handshaker.c +281 -0
- data/src/core/lib/channel/handshaker.h +182 -0
- data/src/core/lib/channel/handshaker_factory.c +54 -0
- data/src/core/lib/channel/handshaker_factory.h +66 -0
- data/src/core/lib/channel/handshaker_registry.c +113 -0
- data/src/core/lib/channel/handshaker_registry.h +63 -0
- data/src/core/lib/channel/http_client_filter.c +601 -0
- data/src/core/lib/channel/http_client_filter.h +47 -0
- data/src/core/lib/channel/http_server_filter.c +445 -0
- data/src/core/lib/channel/http_server_filter.h +42 -0
- data/src/core/lib/channel/message_size_filter.c +270 -0
- data/src/core/lib/channel/message_size_filter.h +39 -0
- data/src/core/lib/compression/algorithm_metadata.h +53 -0
- data/src/core/lib/compression/compression.c +198 -0
- data/src/core/lib/compression/message_compress.c +204 -0
- data/src/core/lib/compression/message_compress.h +54 -0
- data/src/core/lib/debug/trace.c +140 -0
- data/src/core/lib/debug/trace.h +43 -0
- data/src/core/lib/http/format_request.c +135 -0
- data/src/core/lib/http/format_request.h +47 -0
- data/src/core/lib/http/httpcli.c +336 -0
- data/src/core/lib/http/httpcli.h +141 -0
- data/src/core/lib/http/httpcli_security_connector.c +199 -0
- data/src/core/lib/http/parser.c +379 -0
- data/src/core/lib/http/parser.h +126 -0
- data/src/core/lib/iomgr/closure.c +168 -0
- data/src/core/lib/iomgr/closure.h +153 -0
- data/src/core/lib/iomgr/combiner.c +460 -0
- data/src/core/lib/iomgr/combiner.h +83 -0
- data/src/core/lib/iomgr/endpoint.c +78 -0
- data/src/core/lib/iomgr/endpoint.h +117 -0
- data/src/core/lib/iomgr/endpoint_pair.h +47 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.c +87 -0
- data/src/core/lib/iomgr/endpoint_pair_uv.c +53 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.c +101 -0
- data/src/core/lib/iomgr/error.c +793 -0
- data/src/core/lib/iomgr/error.h +218 -0
- data/src/core/lib/iomgr/error_internal.h +75 -0
- data/src/core/lib/iomgr/ev_epoll_linux.c +1965 -0
- data/src/core/lib/iomgr/ev_epoll_linux.h +48 -0
- data/src/core/lib/iomgr/ev_poll_posix.c +1593 -0
- data/src/core/lib/iomgr/ev_poll_posix.h +42 -0
- data/src/core/lib/iomgr/ev_posix.c +287 -0
- data/src/core/lib/iomgr/ev_posix.h +189 -0
- data/src/core/lib/iomgr/exec_ctx.c +117 -0
- data/src/core/lib/iomgr/exec_ctx.h +117 -0
- data/src/core/lib/iomgr/executor.c +170 -0
- data/src/core/lib/iomgr/executor.h +51 -0
- data/src/core/lib/iomgr/iocp_windows.c +168 -0
- data/src/core/lib/iomgr/iocp_windows.h +55 -0
- data/src/core/lib/iomgr/iomgr.c +183 -0
- data/src/core/lib/iomgr/iomgr.h +47 -0
- data/src/core/lib/iomgr/iomgr_internal.h +58 -0
- data/src/core/lib/iomgr/iomgr_posix.c +56 -0
- data/src/core/lib/iomgr/iomgr_posix.h +39 -0
- data/src/core/lib/iomgr/iomgr_uv.c +49 -0
- data/src/core/lib/iomgr/iomgr_windows.c +76 -0
- data/src/core/lib/iomgr/load_file.c +92 -0
- data/src/core/lib/iomgr/load_file.h +56 -0
- data/src/core/lib/iomgr/lockfree_event.c +238 -0
- data/src/core/lib/iomgr/lockfree_event.h +54 -0
- data/src/core/lib/iomgr/network_status_tracker.c +48 -0
- data/src/core/lib/iomgr/network_status_tracker.h +45 -0
- data/src/core/lib/iomgr/polling_entity.c +104 -0
- data/src/core/lib/iomgr/polling_entity.h +81 -0
- data/src/core/lib/iomgr/pollset.h +97 -0
- data/src/core/lib/iomgr/pollset_set.h +62 -0
- data/src/core/lib/iomgr/pollset_set_uv.c +63 -0
- data/src/core/lib/iomgr/pollset_set_windows.c +64 -0
- data/src/core/lib/iomgr/pollset_set_windows.h +39 -0
- data/src/core/lib/iomgr/pollset_uv.c +156 -0
- data/src/core/lib/iomgr/pollset_uv.h +42 -0
- data/src/core/lib/iomgr/pollset_windows.c +232 -0
- data/src/core/lib/iomgr/pollset_windows.h +78 -0
- data/src/core/lib/iomgr/port.h +138 -0
- data/src/core/lib/iomgr/resolve_address.h +70 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +207 -0
- data/src/core/lib/iomgr/resolve_address_uv.c +284 -0
- data/src/core/lib/iomgr/resolve_address_windows.c +190 -0
- data/src/core/lib/iomgr/resource_quota.c +877 -0
- data/src/core/lib/iomgr/resource_quota.h +167 -0
- data/src/core/lib/iomgr/sockaddr.h +55 -0
- data/src/core/lib/iomgr/sockaddr_posix.h +44 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +272 -0
- data/src/core/lib/iomgr/sockaddr_utils.h +93 -0
- data/src/core/lib/iomgr/sockaddr_windows.h +43 -0
- data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
- data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
- data/src/core/lib/iomgr/socket_mutator.c +98 -0
- data/src/core/lib/iomgr/socket_mutator.h +80 -0
- data/src/core/lib/iomgr/socket_utils.h +42 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.c +330 -0
- data/src/core/lib/iomgr/socket_utils_linux.c +57 -0
- data/src/core/lib/iomgr/socket_utils_posix.c +73 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +147 -0
- data/src/core/lib/iomgr/socket_utils_uv.c +49 -0
- data/src/core/lib/iomgr/socket_utils_windows.c +52 -0
- data/src/core/lib/iomgr/socket_windows.c +167 -0
- data/src/core/lib/iomgr/socket_windows.h +125 -0
- data/src/core/lib/iomgr/tcp_client.h +55 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +368 -0
- data/src/core/lib/iomgr/tcp_client_posix.h +45 -0
- data/src/core/lib/iomgr/tcp_client_uv.c +192 -0
- data/src/core/lib/iomgr/tcp_client_windows.c +260 -0
- data/src/core/lib/iomgr/tcp_posix.c +677 -0
- data/src/core/lib/iomgr/tcp_posix.h +70 -0
- data/src/core/lib/iomgr/tcp_server.h +116 -0
- data/src/core/lib/iomgr/tcp_server_posix.c +579 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
- data/src/core/lib/iomgr/tcp_server_uv.c +393 -0
- data/src/core/lib/iomgr/tcp_server_windows.c +558 -0
- data/src/core/lib/iomgr/tcp_uv.c +374 -0
- data/src/core/lib/iomgr/tcp_uv.h +59 -0
- data/src/core/lib/iomgr/tcp_windows.c +462 -0
- data/src/core/lib/iomgr/tcp_windows.h +59 -0
- data/src/core/lib/iomgr/time_averaged_stats.c +77 -0
- data/src/core/lib/iomgr/time_averaged_stats.h +88 -0
- data/src/core/lib/iomgr/timer.h +111 -0
- data/src/core/lib/iomgr/timer_generic.c +567 -0
- data/src/core/lib/iomgr/timer_generic.h +49 -0
- data/src/core/lib/iomgr/timer_heap.c +152 -0
- data/src/core/lib/iomgr/timer_heap.h +57 -0
- data/src/core/lib/iomgr/timer_uv.c +103 -0
- data/src/core/lib/iomgr/timer_uv.h +47 -0
- data/src/core/lib/iomgr/udp_server.c +529 -0
- data/src/core/lib/iomgr/udp_server.h +89 -0
- data/src/core/lib/iomgr/unix_sockets_posix.c +108 -0
- data/src/core/lib/iomgr/unix_sockets_posix.h +56 -0
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +62 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.c +118 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.h +80 -0
- data/src/core/lib/iomgr/wakeup_fd_eventfd.c +97 -0
- data/src/core/lib/iomgr/wakeup_fd_nospecial.c +51 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.c +112 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.h +41 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.c +101 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.h +109 -0
- data/src/core/lib/iomgr/workqueue.h +87 -0
- data/src/core/lib/iomgr/workqueue_uv.c +65 -0
- data/src/core/lib/iomgr/workqueue_uv.h +37 -0
- data/src/core/lib/iomgr/workqueue_windows.c +63 -0
- data/src/core/lib/iomgr/workqueue_windows.h +37 -0
- data/src/core/lib/json/json.c +63 -0
- data/src/core/lib/json/json.h +88 -0
- data/src/core/lib/json/json_common.h +49 -0
- data/src/core/lib/json/json_reader.c +675 -0
- data/src/core/lib/json/json_reader.h +160 -0
- data/src/core/lib/json/json_string.c +379 -0
- data/src/core/lib/json/json_writer.c +258 -0
- data/src/core/lib/json/json_writer.h +97 -0
- data/src/core/lib/profiling/basic_timers.c +298 -0
- data/src/core/lib/profiling/stap_timers.c +65 -0
- data/src/core/lib/profiling/timers.h +121 -0
- data/src/core/lib/security/context/security_context.c +350 -0
- data/src/core/lib/security/context/security_context.h +134 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.c +274 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
- data/src/core/lib/security/credentials/credentials.c +308 -0
- data/src/core/lib/security/credentials/credentials.h +268 -0
- data/src/core/lib/security/credentials/credentials_metadata.c +103 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.c +141 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +71 -0
- data/src/core/lib/security/credentials/google_default/credentials_generic.c +54 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +337 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +60 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
- data/src/core/lib/security/credentials/jwt/json_token.c +321 -0
- data/src/core/lib/security/credentials/jwt/json_token.h +88 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +195 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +63 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +910 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +140 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +468 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +153 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +242 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
- data/src/core/lib/security/transport/auth_filters.h +42 -0
- data/src/core/lib/security/transport/client_auth_filter.c +384 -0
- data/src/core/lib/security/transport/lb_targets_info.c +70 -0
- data/src/core/lib/security/transport/lb_targets_info.h +47 -0
- data/src/core/lib/security/transport/secure_endpoint.c +427 -0
- data/src/core/lib/security/transport/secure_endpoint.h +49 -0
- data/src/core/lib/security/transport/security_connector.c +909 -0
- data/src/core/lib/security/transport/security_connector.h +252 -0
- data/src/core/lib/security/transport/security_handshaker.c +507 -0
- data/src/core/lib/security/transport/security_handshaker.h +49 -0
- data/src/core/lib/security/transport/server_auth_filter.c +277 -0
- data/src/core/lib/security/transport/tsi_error.c +42 -0
- data/src/core/lib/security/transport/tsi_error.h +42 -0
- data/src/core/lib/security/util/json_util.c +61 -0
- data/src/core/lib/security/util/json_util.h +55 -0
- data/src/core/lib/slice/b64.c +251 -0
- data/src/core/lib/slice/b64.h +65 -0
- data/src/core/lib/slice/percent_encoding.c +182 -0
- data/src/core/lib/slice/percent_encoding.h +78 -0
- data/src/core/lib/slice/slice.c +466 -0
- data/src/core/lib/slice/slice_buffer.c +355 -0
- data/src/core/lib/slice/slice_hash_table.c +125 -0
- data/src/core/lib/slice/slice_hash_table.h +77 -0
- data/src/core/lib/slice/slice_intern.c +346 -0
- data/src/core/lib/slice/slice_internal.h +64 -0
- data/src/core/lib/slice/slice_string_helpers.c +95 -0
- data/src/core/lib/slice/slice_string_helpers.h +63 -0
- data/src/core/lib/support/alloc.c +117 -0
- data/src/core/lib/support/arena.c +98 -0
- data/src/core/lib/support/arena.h +54 -0
- data/src/core/lib/support/atm.c +47 -0
- data/src/core/lib/support/avl.c +299 -0
- data/src/core/lib/support/backoff.c +87 -0
- data/src/core/lib/support/backoff.h +71 -0
- data/src/core/lib/support/block_annotate.h +48 -0
- data/src/core/lib/support/cmdline.c +345 -0
- data/src/core/lib/support/cpu_iphone.c +49 -0
- data/src/core/lib/support/cpu_linux.c +83 -0
- data/src/core/lib/support/cpu_posix.c +72 -0
- data/src/core/lib/support/cpu_windows.c +47 -0
- data/src/core/lib/support/env.h +58 -0
- data/src/core/lib/support/env_linux.c +89 -0
- data/src/core/lib/support/env_posix.c +57 -0
- data/src/core/lib/support/env_windows.c +79 -0
- data/src/core/lib/support/histogram.c +243 -0
- data/src/core/lib/support/host_port.c +110 -0
- data/src/core/lib/support/log.c +103 -0
- data/src/core/lib/support/log_android.c +87 -0
- data/src/core/lib/support/log_linux.c +105 -0
- data/src/core/lib/support/log_posix.c +106 -0
- data/src/core/lib/support/log_windows.c +112 -0
- data/src/core/lib/support/mpscq.c +83 -0
- data/src/core/lib/support/mpscq.h +65 -0
- data/src/core/lib/support/murmur_hash.c +94 -0
- data/src/core/lib/support/murmur_hash.h +44 -0
- data/src/core/lib/support/spinlock.h +52 -0
- data/src/core/lib/support/stack_lockfree.c +185 -0
- data/src/core/lib/support/stack_lockfree.h +53 -0
- data/src/core/lib/support/string.c +315 -0
- data/src/core/lib/support/string.h +128 -0
- data/src/core/lib/support/string_posix.c +86 -0
- data/src/core/lib/support/string_util_windows.c +94 -0
- data/src/core/lib/support/string_windows.c +83 -0
- data/src/core/lib/support/string_windows.h +47 -0
- data/src/core/lib/support/subprocess_posix.c +114 -0
- data/src/core/lib/support/subprocess_windows.c +141 -0
- data/src/core/lib/support/sync.c +137 -0
- data/src/core/lib/support/sync_posix.c +113 -0
- data/src/core/lib/support/sync_windows.c +133 -0
- data/src/core/lib/support/thd.c +64 -0
- data/src/core/lib/support/thd_internal.h +39 -0
- data/src/core/lib/support/thd_posix.c +95 -0
- data/src/core/lib/support/thd_windows.c +117 -0
- data/src/core/lib/support/time.c +262 -0
- data/src/core/lib/support/time_posix.c +176 -0
- data/src/core/lib/support/time_precise.c +89 -0
- data/src/core/lib/support/time_precise.h +42 -0
- data/src/core/lib/support/time_windows.c +116 -0
- data/src/core/lib/support/tls_pthread.c +45 -0
- data/src/core/lib/support/tmpfile.h +53 -0
- data/src/core/lib/support/tmpfile_msys.c +73 -0
- data/src/core/lib/support/tmpfile_posix.c +85 -0
- data/src/core/lib/support/tmpfile_windows.c +84 -0
- data/src/core/lib/support/wrap_memcpy.c +55 -0
- data/src/core/lib/surface/alarm.c +87 -0
- data/src/core/lib/surface/api_trace.c +36 -0
- data/src/core/lib/surface/api_trace.h +65 -0
- data/src/core/lib/surface/byte_buffer.c +103 -0
- data/src/core/lib/surface/byte_buffer_reader.c +140 -0
- data/src/core/lib/surface/call.c +1835 -0
- data/src/core/lib/surface/call.h +135 -0
- data/src/core/lib/surface/call_details.c +56 -0
- data/src/core/lib/surface/call_log_batch.c +131 -0
- data/src/core/lib/surface/call_test_only.h +64 -0
- data/src/core/lib/surface/channel.c +434 -0
- data/src/core/lib/surface/channel.h +99 -0
- data/src/core/lib/surface/channel_init.c +140 -0
- data/src/core/lib/surface/channel_init.h +96 -0
- data/src/core/lib/surface/channel_ping.c +80 -0
- data/src/core/lib/surface/channel_stack_type.c +54 -0
- data/src/core/lib/surface/channel_stack_type.h +58 -0
- data/src/core/lib/surface/completion_queue.c +692 -0
- data/src/core/lib/surface/completion_queue.h +102 -0
- data/src/core/lib/surface/completion_queue_factory.c +77 -0
- data/src/core/lib/surface/completion_queue_factory.h +51 -0
- data/src/core/lib/surface/event_string.c +81 -0
- data/src/core/lib/surface/event_string.h +42 -0
- data/src/core/lib/surface/init.c +261 -0
- data/src/core/lib/surface/init.h +42 -0
- data/src/core/lib/surface/init_secure.c +94 -0
- data/src/core/lib/surface/lame_client.c +188 -0
- data/src/core/lib/surface/lame_client.h +41 -0
- data/src/core/lib/surface/metadata_array.c +49 -0
- data/src/core/lib/surface/server.c +1529 -0
- data/src/core/lib/surface/server.h +71 -0
- data/src/core/lib/surface/validate_metadata.c +108 -0
- data/src/core/lib/surface/validate_metadata.h +43 -0
- data/src/core/lib/surface/version.c +41 -0
- data/src/core/lib/transport/bdp_estimator.c +104 -0
- data/src/core/lib/transport/bdp_estimator.h +76 -0
- data/src/core/lib/transport/byte_stream.c +81 -0
- data/src/core/lib/transport/byte_stream.h +85 -0
- data/src/core/lib/transport/connectivity_state.c +219 -0
- data/src/core/lib/transport/connectivity_state.h +101 -0
- data/src/core/lib/transport/error_utils.c +124 -0
- data/src/core/lib/transport/error_utils.h +56 -0
- data/src/core/lib/transport/http2_errors.h +56 -0
- data/src/core/lib/transport/metadata.c +529 -0
- data/src/core/lib/transport/metadata.h +186 -0
- data/src/core/lib/transport/metadata_batch.c +328 -0
- data/src/core/lib/transport/metadata_batch.h +166 -0
- data/src/core/lib/transport/pid_controller.c +78 -0
- data/src/core/lib/transport/pid_controller.h +77 -0
- data/src/core/lib/transport/service_config.c +266 -0
- data/src/core/lib/transport/service_config.h +77 -0
- data/src/core/lib/transport/static_metadata.c +801 -0
- data/src/core/lib/transport/static_metadata.h +557 -0
- data/src/core/lib/transport/status_conversion.c +113 -0
- data/src/core/lib/transport/status_conversion.h +49 -0
- data/src/core/lib/transport/timeout_encoding.c +190 -0
- data/src/core/lib/transport/timeout_encoding.h +49 -0
- data/src/core/lib/transport/transport.c +282 -0
- data/src/core/lib/transport/transport.h +354 -0
- data/src/core/lib/transport/transport_impl.h +90 -0
- data/src/core/lib/transport/transport_op_string.c +217 -0
- data/src/core/plugin_registry/grpc_plugin_registry.c +82 -0
- data/src/core/tsi/fake_transport_security.c +527 -0
- data/src/core/tsi/fake_transport_security.h +61 -0
- data/src/core/tsi/ssl_transport_security.c +1533 -0
- data/src/core/tsi/ssl_transport_security.h +214 -0
- data/src/core/tsi/ssl_types.h +55 -0
- data/src/core/tsi/transport_security.c +266 -0
- data/src/core/tsi/transport_security.h +111 -0
- data/src/core/tsi/transport_security_interface.h +353 -0
- data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
- data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
- data/src/ruby/bin/math_client.rb +147 -0
- data/src/ruby/bin/math_pb.rb +32 -0
- data/src/ruby/bin/math_server.rb +206 -0
- data/src/ruby/bin/math_services_pb.rb +66 -0
- data/src/ruby/bin/noproto_client.rb +108 -0
- data/src/ruby/bin/noproto_server.rb +112 -0
- data/src/ruby/ext/grpc/extconf.rb +131 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +77 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +50 -0
- data/src/ruby/ext/grpc/rb_call.c +1009 -0
- data/src/ruby/ext/grpc/rb_call.h +66 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +295 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
- data/src/ruby/ext/grpc/rb_channel.c +662 -0
- data/src/ruby/ext/grpc/rb_channel.h +49 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +168 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +268 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +117 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +51 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +472 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +44 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +158 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
- data/src/ruby/ext/grpc/rb_grpc.c +343 -0
- data/src/ruby/ext/grpc/rb_grpc.h +87 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +634 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +955 -0
- data/src/ruby/ext/grpc/rb_loader.c +72 -0
- data/src/ruby/ext/grpc/rb_loader.h +40 -0
- data/src/ruby/ext/grpc/rb_server.c +359 -0
- data/src/ruby/ext/grpc/rb_server.h +47 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
- data/src/ruby/lib/grpc/errors.rb +215 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +547 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +229 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +463 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +173 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +476 -0
- data/src/ruby/lib/grpc/generic/service.rb +225 -0
- data/src/ruby/lib/grpc/grpc.rb +39 -0
- data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/logconfig.rb +59 -0
- data/src/ruby/lib/grpc/notifier.rb +60 -0
- data/src/ruby/lib/grpc/version.rb +33 -0
- data/src/ruby/lib/grpc.rb +49 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +58 -0
- data/src/ruby/pb/grpc/health/checker.rb +77 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +28 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +56 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +58 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +64 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +15 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +82 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +14 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +117 -0
- data/src/ruby/pb/test/client.rb +779 -0
- data/src/ruby/pb/test/server.rb +267 -0
- data/src/ruby/spec/call_credentials_spec.rb +57 -0
- data/src/ruby/spec/call_spec.rb +162 -0
- data/src/ruby/spec/channel_connection_spec.rb +141 -0
- data/src/ruby/spec/channel_credentials_spec.rb +97 -0
- data/src/ruby/spec/channel_spec.rb +205 -0
- data/src/ruby/spec/client_server_spec.rb +491 -0
- data/src/ruby/spec/compression_options_spec.rb +164 -0
- data/src/ruby/spec/error_sanity_spec.rb +64 -0
- data/src/ruby/spec/generic/active_call_spec.rb +632 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +556 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +351 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +142 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +524 -0
- data/src/ruby/spec/generic/service_spec.rb +276 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +71 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +222 -0
- data/src/ruby/spec/server_credentials_spec.rb +94 -0
- data/src/ruby/spec/server_spec.rb +205 -0
- data/src/ruby/spec/spec_helper.rb +71 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +15 -0
- data/src/ruby/spec/testdata/server1.key +16 -0
- data/src/ruby/spec/testdata/server1.pem +16 -0
- data/src/ruby/spec/time_consts_spec.rb +89 -0
- data/third_party/boringssl/crypto/aes/aes.c +1142 -0
- data/third_party/boringssl/crypto/aes/internal.h +87 -0
- data/third_party/boringssl/crypto/aes/mode_wrappers.c +112 -0
- data/third_party/boringssl/crypto/asn1/a_bitstr.c +263 -0
- data/third_party/boringssl/crypto/asn1/a_bool.c +110 -0
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +282 -0
- data/third_party/boringssl/crypto/asn1/a_dup.c +111 -0
- data/third_party/boringssl/crypto/asn1/a_enum.c +181 -0
- data/third_party/boringssl/crypto/asn1/a_gentm.c +256 -0
- data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +147 -0
- data/third_party/boringssl/crypto/asn1/a_int.c +460 -0
- data/third_party/boringssl/crypto/asn1/a_mbstr.c +409 -0
- data/third_party/boringssl/crypto/asn1/a_object.c +400 -0
- data/third_party/boringssl/crypto/asn1/a_octet.c +77 -0
- data/third_party/boringssl/crypto/asn1/a_print.c +121 -0
- data/third_party/boringssl/crypto/asn1/a_strnid.c +309 -0
- data/third_party/boringssl/crypto/asn1/a_time.c +206 -0
- data/third_party/boringssl/crypto/asn1/a_type.c +151 -0
- data/third_party/boringssl/crypto/asn1/a_utctm.c +304 -0
- data/third_party/boringssl/crypto/asn1/a_utf8.c +234 -0
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +483 -0
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +63 -0
- data/third_party/boringssl/crypto/asn1/asn1_par.c +80 -0
- data/third_party/boringssl/crypto/asn1/asn_pack.c +105 -0
- data/third_party/boringssl/crypto/asn1/f_enum.c +93 -0
- data/third_party/boringssl/crypto/asn1/f_int.c +97 -0
- data/third_party/boringssl/crypto/asn1/f_string.c +91 -0
- data/third_party/boringssl/crypto/asn1/t_bitst.c +103 -0
- data/third_party/boringssl/crypto/asn1/tasn_dec.c +1221 -0
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +665 -0
- data/third_party/boringssl/crypto/asn1/tasn_fre.c +246 -0
- data/third_party/boringssl/crypto/asn1/tasn_new.c +381 -0
- data/third_party/boringssl/crypto/asn1/tasn_typ.c +131 -0
- data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
- data/third_party/boringssl/crypto/asn1/x_bignum.c +153 -0
- data/third_party/boringssl/crypto/asn1/x_long.c +197 -0
- data/third_party/boringssl/crypto/base64/base64.c +442 -0
- data/third_party/boringssl/crypto/bio/bio.c +598 -0
- data/third_party/boringssl/crypto/bio/bio_mem.c +328 -0
- data/third_party/boringssl/crypto/bio/buffer.c +496 -0
- data/third_party/boringssl/crypto/bio/connect.c +553 -0
- data/third_party/boringssl/crypto/bio/fd.c +277 -0
- data/third_party/boringssl/crypto/bio/file.c +313 -0
- data/third_party/boringssl/crypto/bio/hexdump.c +191 -0
- data/third_party/boringssl/crypto/bio/internal.h +111 -0
- data/third_party/boringssl/crypto/bio/pair.c +803 -0
- data/third_party/boringssl/crypto/bio/printf.c +119 -0
- data/third_party/boringssl/crypto/bio/socket.c +203 -0
- data/third_party/boringssl/crypto/bio/socket_helper.c +113 -0
- data/third_party/boringssl/crypto/bn/add.c +377 -0
- data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +531 -0
- data/third_party/boringssl/crypto/bn/bn.c +379 -0
- data/third_party/boringssl/crypto/bn/bn_asn1.c +80 -0
- data/third_party/boringssl/crypto/bn/cmp.c +225 -0
- data/third_party/boringssl/crypto/bn/convert.c +599 -0
- data/third_party/boringssl/crypto/bn/ctx.c +311 -0
- data/third_party/boringssl/crypto/bn/div.c +671 -0
- data/third_party/boringssl/crypto/bn/exponentiation.c +1258 -0
- data/third_party/boringssl/crypto/bn/gcd.c +628 -0
- data/third_party/boringssl/crypto/bn/generic.c +703 -0
- data/third_party/boringssl/crypto/bn/internal.h +245 -0
- data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
- data/third_party/boringssl/crypto/bn/montgomery.c +410 -0
- data/third_party/boringssl/crypto/bn/montgomery_inv.c +160 -0
- data/third_party/boringssl/crypto/bn/mul.c +869 -0
- data/third_party/boringssl/crypto/bn/prime.c +861 -0
- data/third_party/boringssl/crypto/bn/random.c +340 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.c +319 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.h +56 -0
- data/third_party/boringssl/crypto/bn/shift.c +299 -0
- data/third_party/boringssl/crypto/bn/sqrt.c +504 -0
- data/third_party/boringssl/crypto/buf/buf.c +239 -0
- data/third_party/boringssl/crypto/bytestring/asn1_compat.c +51 -0
- data/third_party/boringssl/crypto/bytestring/ber.c +263 -0
- data/third_party/boringssl/crypto/bytestring/cbb.c +473 -0
- data/third_party/boringssl/crypto/bytestring/cbs.c +439 -0
- data/third_party/boringssl/crypto/bytestring/internal.h +75 -0
- data/third_party/boringssl/crypto/chacha/chacha.c +167 -0
- data/third_party/boringssl/crypto/cipher/aead.c +156 -0
- data/third_party/boringssl/crypto/cipher/cipher.c +652 -0
- data/third_party/boringssl/crypto/cipher/derive_key.c +154 -0
- data/third_party/boringssl/crypto/cipher/e_aes.c +1717 -0
- data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +300 -0
- data/third_party/boringssl/crypto/cipher/e_des.c +205 -0
- data/third_party/boringssl/crypto/cipher/e_null.c +85 -0
- data/third_party/boringssl/crypto/cipher/e_rc2.c +443 -0
- data/third_party/boringssl/crypto/cipher/e_rc4.c +87 -0
- data/third_party/boringssl/crypto/cipher/e_ssl3.c +403 -0
- data/third_party/boringssl/crypto/cipher/e_tls.c +602 -0
- data/third_party/boringssl/crypto/cipher/internal.h +162 -0
- data/third_party/boringssl/crypto/cipher/tls_cbc.c +553 -0
- data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
- data/third_party/boringssl/crypto/conf/conf.c +788 -0
- data/third_party/boringssl/crypto/conf/conf_def.h +127 -0
- data/third_party/boringssl/crypto/conf/internal.h +31 -0
- data/third_party/boringssl/crypto/cpu-aarch64-linux.c +61 -0
- data/third_party/boringssl/crypto/cpu-arm-linux.c +360 -0
- data/third_party/boringssl/crypto/cpu-arm.c +38 -0
- data/third_party/boringssl/crypto/cpu-intel.c +263 -0
- data/third_party/boringssl/crypto/cpu-ppc64le.c +40 -0
- data/third_party/boringssl/crypto/crypto.c +164 -0
- data/third_party/boringssl/crypto/curve25519/curve25519.c +4944 -0
- data/third_party/boringssl/crypto/curve25519/internal.h +109 -0
- data/third_party/boringssl/crypto/curve25519/spake25519.c +464 -0
- data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +246 -0
- data/third_party/boringssl/crypto/des/des.c +771 -0
- data/third_party/boringssl/crypto/des/internal.h +212 -0
- data/third_party/boringssl/crypto/dh/check.c +218 -0
- data/third_party/boringssl/crypto/dh/dh.c +487 -0
- data/third_party/boringssl/crypto/dh/dh_asn1.c +160 -0
- data/third_party/boringssl/crypto/dh/params.c +253 -0
- data/third_party/boringssl/crypto/digest/digest.c +248 -0
- data/third_party/boringssl/crypto/digest/digests.c +321 -0
- data/third_party/boringssl/crypto/digest/internal.h +112 -0
- data/third_party/boringssl/crypto/digest/md32_common.h +262 -0
- data/third_party/boringssl/crypto/dsa/dsa.c +964 -0
- data/third_party/boringssl/crypto/dsa/dsa_asn1.c +339 -0
- data/third_party/boringssl/crypto/ec/ec.c +847 -0
- data/third_party/boringssl/crypto/ec/ec_asn1.c +549 -0
- data/third_party/boringssl/crypto/ec/ec_key.c +479 -0
- data/third_party/boringssl/crypto/ec/ec_montgomery.c +308 -0
- data/third_party/boringssl/crypto/ec/internal.h +276 -0
- data/third_party/boringssl/crypto/ec/oct.c +428 -0
- data/third_party/boringssl/crypto/ec/p224-64.c +1187 -0
- data/third_party/boringssl/crypto/ec/p256-64.c +1741 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9543 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64.c +574 -0
- data/third_party/boringssl/crypto/ec/simple.c +1117 -0
- data/third_party/boringssl/crypto/ec/util-64.c +109 -0
- data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
- data/third_party/boringssl/crypto/ecdh/ecdh.c +159 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa.c +478 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +227 -0
- data/third_party/boringssl/crypto/engine/engine.c +96 -0
- data/third_party/boringssl/crypto/err/err.c +756 -0
- data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
- data/third_party/boringssl/crypto/evp/evp.c +367 -0
- data/third_party/boringssl/crypto/evp/evp_asn1.c +337 -0
- data/third_party/boringssl/crypto/evp/evp_ctx.c +448 -0
- data/third_party/boringssl/crypto/evp/internal.h +237 -0
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +268 -0
- data/third_party/boringssl/crypto/evp/p_ec.c +236 -0
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +257 -0
- data/third_party/boringssl/crypto/evp/p_rsa.c +673 -0
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +200 -0
- data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
- data/third_party/boringssl/crypto/evp/print.c +520 -0
- data/third_party/boringssl/crypto/evp/sign.c +151 -0
- data/third_party/boringssl/crypto/ex_data.c +292 -0
- data/third_party/boringssl/crypto/hkdf/hkdf.c +110 -0
- data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
- data/third_party/boringssl/crypto/internal.h +527 -0
- data/third_party/boringssl/crypto/lhash/lhash.c +342 -0
- data/third_party/boringssl/crypto/md4/md4.c +234 -0
- data/third_party/boringssl/crypto/md5/md5.c +275 -0
- data/third_party/boringssl/crypto/mem.c +200 -0
- data/third_party/boringssl/crypto/modes/cbc.c +216 -0
- data/third_party/boringssl/crypto/modes/cfb.c +230 -0
- data/third_party/boringssl/crypto/modes/ctr.c +219 -0
- data/third_party/boringssl/crypto/modes/gcm.c +1288 -0
- data/third_party/boringssl/crypto/modes/internal.h +358 -0
- data/third_party/boringssl/crypto/modes/ofb.c +95 -0
- data/third_party/boringssl/crypto/newhope/error_correction.c +131 -0
- data/third_party/boringssl/crypto/newhope/internal.h +71 -0
- data/third_party/boringssl/crypto/newhope/newhope.c +174 -0
- data/third_party/boringssl/crypto/newhope/ntt.c +148 -0
- data/third_party/boringssl/crypto/newhope/poly.c +183 -0
- data/third_party/boringssl/crypto/newhope/precomp.c +306 -0
- data/third_party/boringssl/crypto/newhope/reduce.c +42 -0
- data/third_party/boringssl/crypto/obj/obj.c +640 -0
- data/third_party/boringssl/crypto/obj/obj_dat.h +5254 -0
- data/third_party/boringssl/crypto/obj/obj_xref.c +124 -0
- data/third_party/boringssl/crypto/obj/obj_xref.h +96 -0
- data/third_party/boringssl/crypto/pem/pem_all.c +262 -0
- data/third_party/boringssl/crypto/pem/pem_info.c +381 -0
- data/third_party/boringssl/crypto/pem/pem_lib.c +778 -0
- data/third_party/boringssl/crypto/pem/pem_oth.c +88 -0
- data/third_party/boringssl/crypto/pem/pem_pk8.c +257 -0
- data/third_party/boringssl/crypto/pem/pem_pkey.c +227 -0
- data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
- data/third_party/boringssl/crypto/pem/pem_xaux.c +67 -0
- data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +151 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +441 -0
- data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1219 -0
- data/third_party/boringssl/crypto/poly1305/internal.h +40 -0
- data/third_party/boringssl/crypto/poly1305/poly1305.c +324 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +304 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +890 -0
- data/third_party/boringssl/crypto/rand/deterministic.c +47 -0
- data/third_party/boringssl/crypto/rand/internal.h +32 -0
- data/third_party/boringssl/crypto/rand/rand.c +244 -0
- data/third_party/boringssl/crypto/rand/urandom.c +221 -0
- data/third_party/boringssl/crypto/rand/windows.c +53 -0
- data/third_party/boringssl/crypto/rc4/rc4.c +98 -0
- data/third_party/boringssl/crypto/refcount_c11.c +67 -0
- data/third_party/boringssl/crypto/refcount_lock.c +53 -0
- data/third_party/boringssl/crypto/rsa/blinding.c +264 -0
- data/third_party/boringssl/crypto/rsa/internal.h +148 -0
- data/third_party/boringssl/crypto/rsa/padding.c +708 -0
- data/third_party/boringssl/crypto/rsa/rsa.c +830 -0
- data/third_party/boringssl/crypto/rsa/rsa_asn1.c +446 -0
- data/third_party/boringssl/crypto/rsa/rsa_impl.c +1139 -0
- data/third_party/boringssl/crypto/sha/sha1.c +337 -0
- data/third_party/boringssl/crypto/sha/sha256.c +327 -0
- data/third_party/boringssl/crypto/sha/sha512.c +607 -0
- data/third_party/boringssl/crypto/stack/stack.c +377 -0
- data/third_party/boringssl/crypto/thread.c +110 -0
- data/third_party/boringssl/crypto/thread_none.c +59 -0
- data/third_party/boringssl/crypto/thread_pthread.c +176 -0
- data/third_party/boringssl/crypto/thread_win.c +237 -0
- data/third_party/boringssl/crypto/time_support.c +206 -0
- data/third_party/boringssl/crypto/x509/a_digest.c +96 -0
- data/third_party/boringssl/crypto/x509/a_sign.c +135 -0
- data/third_party/boringssl/crypto/x509/a_strex.c +633 -0
- data/third_party/boringssl/crypto/x509/a_verify.c +127 -0
- data/third_party/boringssl/crypto/x509/algorithm.c +137 -0
- data/third_party/boringssl/crypto/x509/asn1_gen.c +818 -0
- data/third_party/boringssl/crypto/x509/by_dir.c +453 -0
- data/third_party/boringssl/crypto/x509/by_file.c +275 -0
- data/third_party/boringssl/crypto/x509/charmap.h +15 -0
- data/third_party/boringssl/crypto/x509/i2d_pr.c +83 -0
- data/third_party/boringssl/crypto/x509/internal.h +66 -0
- data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
- data/third_party/boringssl/crypto/x509/rsa_pss.c +385 -0
- data/third_party/boringssl/crypto/x509/t_crl.c +128 -0
- data/third_party/boringssl/crypto/x509/t_req.c +246 -0
- data/third_party/boringssl/crypto/x509/t_x509.c +506 -0
- data/third_party/boringssl/crypto/x509/t_x509a.c +111 -0
- data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
- data/third_party/boringssl/crypto/x509/x509.c +157 -0
- data/third_party/boringssl/crypto/x509/x509_att.c +381 -0
- data/third_party/boringssl/crypto/x509/x509_cmp.c +474 -0
- data/third_party/boringssl/crypto/x509/x509_d2.c +106 -0
- data/third_party/boringssl/crypto/x509/x509_def.c +98 -0
- data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
- data/third_party/boringssl/crypto/x509/x509_lu.c +690 -0
- data/third_party/boringssl/crypto/x509/x509_obj.c +197 -0
- data/third_party/boringssl/crypto/x509/x509_r2x.c +117 -0
- data/third_party/boringssl/crypto/x509/x509_req.c +322 -0
- data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
- data/third_party/boringssl/crypto/x509/x509_trs.c +326 -0
- data/third_party/boringssl/crypto/x509/x509_txt.c +211 -0
- data/third_party/boringssl/crypto/x509/x509_v3.c +278 -0
- data/third_party/boringssl/crypto/x509/x509_vfy.c +2436 -0
- data/third_party/boringssl/crypto/x509/x509_vpm.c +647 -0
- data/third_party/boringssl/crypto/x509/x509cset.c +170 -0
- data/third_party/boringssl/crypto/x509/x509name.c +386 -0
- data/third_party/boringssl/crypto/x509/x509rset.c +81 -0
- data/third_party/boringssl/crypto/x509/x509spki.c +137 -0
- data/third_party/boringssl/crypto/x509/x509type.c +126 -0
- data/third_party/boringssl/crypto/x509/x_algor.c +151 -0
- data/third_party/boringssl/crypto/x509/x_all.c +501 -0
- data/third_party/boringssl/crypto/x509/x_attrib.c +111 -0
- data/third_party/boringssl/crypto/x509/x_crl.c +539 -0
- data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
- data/third_party/boringssl/crypto/x509/x_info.c +98 -0
- data/third_party/boringssl/crypto/x509/x_name.c +534 -0
- data/third_party/boringssl/crypto/x509/x_pkey.c +103 -0
- data/third_party/boringssl/crypto/x509/x_pubkey.c +368 -0
- data/third_party/boringssl/crypto/x509/x_req.c +109 -0
- data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
- data/third_party/boringssl/crypto/x509/x_spki.c +80 -0
- data/third_party/boringssl/crypto/x509/x_val.c +69 -0
- data/third_party/boringssl/crypto/x509/x_x509.c +289 -0
- data/third_party/boringssl/crypto/x509/x_x509a.c +205 -0
- data/third_party/boringssl/crypto/x509v3/ext_dat.h +135 -0
- data/third_party/boringssl/crypto/x509v3/pcy_cache.c +284 -0
- data/third_party/boringssl/crypto/x509v3/pcy_data.c +130 -0
- data/third_party/boringssl/crypto/x509v3/pcy_int.h +217 -0
- data/third_party/boringssl/crypto/x509v3/pcy_lib.c +164 -0
- data/third_party/boringssl/crypto/x509v3/pcy_map.c +130 -0
- data/third_party/boringssl/crypto/x509v3/pcy_node.c +188 -0
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +829 -0
- data/third_party/boringssl/crypto/x509v3/v3_akey.c +204 -0
- data/third_party/boringssl/crypto/x509v3/v3_akeya.c +72 -0
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +614 -0
- data/third_party/boringssl/crypto/x509v3/v3_bcons.c +133 -0
- data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
- data/third_party/boringssl/crypto/x509v3/v3_conf.c +462 -0
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +496 -0
- data/third_party/boringssl/crypto/x509v3/v3_crld.c +561 -0
- data/third_party/boringssl/crypto/x509v3/v3_enum.c +100 -0
- data/third_party/boringssl/crypto/x509v3/v3_extku.c +148 -0
- data/third_party/boringssl/crypto/x509v3/v3_genn.c +250 -0
- data/third_party/boringssl/crypto/x509v3/v3_ia5.c +119 -0
- data/third_party/boringssl/crypto/x509v3/v3_info.c +212 -0
- data/third_party/boringssl/crypto/x509v3/v3_int.c +91 -0
- data/third_party/boringssl/crypto/x509v3/v3_lib.c +362 -0
- data/third_party/boringssl/crypto/x509v3/v3_ncons.c +482 -0
- data/third_party/boringssl/crypto/x509v3/v3_pci.c +317 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcia.c +57 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcons.c +139 -0
- data/third_party/boringssl/crypto/x509v3/v3_pku.c +110 -0
- data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +154 -0
- data/third_party/boringssl/crypto/x509v3/v3_prn.c +229 -0
- data/third_party/boringssl/crypto/x509v3/v3_purp.c +874 -0
- data/third_party/boringssl/crypto/x509v3/v3_skey.c +152 -0
- data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +274 -0
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +1327 -0
- data/third_party/boringssl/include/openssl/aead.h +345 -0
- data/third_party/boringssl/include/openssl/aes.h +158 -0
- data/third_party/boringssl/include/openssl/arm_arch.h +121 -0
- data/third_party/boringssl/include/openssl/asn1.h +1038 -0
- data/third_party/boringssl/include/openssl/asn1_mac.h +18 -0
- data/third_party/boringssl/include/openssl/asn1t.h +896 -0
- data/third_party/boringssl/include/openssl/base.h +412 -0
- data/third_party/boringssl/include/openssl/base64.h +187 -0
- data/third_party/boringssl/include/openssl/bio.h +926 -0
- data/third_party/boringssl/include/openssl/blowfish.h +93 -0
- data/third_party/boringssl/include/openssl/bn.h +955 -0
- data/third_party/boringssl/include/openssl/buf.h +133 -0
- data/third_party/boringssl/include/openssl/buffer.h +18 -0
- data/third_party/boringssl/include/openssl/bytestring.h +437 -0
- data/third_party/boringssl/include/openssl/cast.h +96 -0
- data/third_party/boringssl/include/openssl/chacha.h +37 -0
- data/third_party/boringssl/include/openssl/cipher.h +588 -0
- data/third_party/boringssl/include/openssl/cmac.h +87 -0
- data/third_party/boringssl/include/openssl/conf.h +181 -0
- data/third_party/boringssl/include/openssl/cpu.h +181 -0
- data/third_party/boringssl/include/openssl/crypto.h +94 -0
- data/third_party/boringssl/include/openssl/curve25519.h +183 -0
- data/third_party/boringssl/include/openssl/des.h +177 -0
- data/third_party/boringssl/include/openssl/dh.h +297 -0
- data/third_party/boringssl/include/openssl/digest.h +285 -0
- data/third_party/boringssl/include/openssl/dsa.h +436 -0
- data/third_party/boringssl/include/openssl/dtls1.h +16 -0
- data/third_party/boringssl/include/openssl/ec.h +406 -0
- data/third_party/boringssl/include/openssl/ec_key.h +337 -0
- data/third_party/boringssl/include/openssl/ecdh.h +102 -0
- data/third_party/boringssl/include/openssl/ecdsa.h +217 -0
- data/third_party/boringssl/include/openssl/engine.h +109 -0
- data/third_party/boringssl/include/openssl/err.h +488 -0
- data/third_party/boringssl/include/openssl/evp.h +797 -0
- data/third_party/boringssl/include/openssl/ex_data.h +213 -0
- data/third_party/boringssl/include/openssl/hkdf.h +64 -0
- data/third_party/boringssl/include/openssl/hmac.h +174 -0
- data/third_party/boringssl/include/openssl/lhash.h +192 -0
- data/third_party/boringssl/include/openssl/lhash_macros.h +132 -0
- data/third_party/boringssl/include/openssl/md4.h +106 -0
- data/third_party/boringssl/include/openssl/md5.h +107 -0
- data/third_party/boringssl/include/openssl/mem.h +150 -0
- data/third_party/boringssl/include/openssl/newhope.h +158 -0
- data/third_party/boringssl/include/openssl/nid.h +4166 -0
- data/third_party/boringssl/include/openssl/obj.h +226 -0
- data/third_party/boringssl/include/openssl/obj_mac.h +18 -0
- data/third_party/boringssl/include/openssl/objects.h +18 -0
- data/third_party/boringssl/include/openssl/opensslconf.h +60 -0
- data/third_party/boringssl/include/openssl/opensslv.h +18 -0
- data/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
- data/third_party/boringssl/include/openssl/pem.h +517 -0
- data/third_party/boringssl/include/openssl/pkcs12.h +18 -0
- data/third_party/boringssl/include/openssl/pkcs7.h +16 -0
- data/third_party/boringssl/include/openssl/pkcs8.h +236 -0
- data/third_party/boringssl/include/openssl/poly1305.h +51 -0
- data/third_party/boringssl/include/openssl/rand.h +122 -0
- data/third_party/boringssl/include/openssl/rc4.h +96 -0
- data/third_party/boringssl/include/openssl/ripemd.h +107 -0
- data/third_party/boringssl/include/openssl/rsa.h +699 -0
- data/third_party/boringssl/include/openssl/safestack.h +16 -0
- data/third_party/boringssl/include/openssl/sha.h +260 -0
- data/third_party/boringssl/include/openssl/srtp.h +18 -0
- data/third_party/boringssl/include/openssl/ssl.h +4826 -0
- data/third_party/boringssl/include/openssl/ssl3.h +434 -0
- data/third_party/boringssl/include/openssl/stack.h +293 -0
- data/third_party/boringssl/include/openssl/stack_macros.h +3902 -0
- data/third_party/boringssl/include/openssl/thread.h +191 -0
- data/third_party/boringssl/include/openssl/time_support.h +91 -0
- data/third_party/boringssl/include/openssl/tls1.h +657 -0
- data/third_party/boringssl/include/openssl/type_check.h +91 -0
- data/third_party/boringssl/include/openssl/x509.h +1299 -0
- data/third_party/boringssl/include/openssl/x509_vfy.h +618 -0
- data/third_party/boringssl/include/openssl/x509v3.h +819 -0
- data/third_party/boringssl/ssl/custom_extensions.c +255 -0
- data/third_party/boringssl/ssl/d1_both.c +845 -0
- data/third_party/boringssl/ssl/d1_lib.c +270 -0
- data/third_party/boringssl/ssl/d1_pkt.c +419 -0
- data/third_party/boringssl/ssl/d1_srtp.c +236 -0
- data/third_party/boringssl/ssl/dtls_method.c +203 -0
- data/third_party/boringssl/ssl/dtls_record.c +309 -0
- data/third_party/boringssl/ssl/handshake_client.c +2002 -0
- data/third_party/boringssl/ssl/handshake_server.c +1932 -0
- data/third_party/boringssl/ssl/internal.h +1551 -0
- data/third_party/boringssl/ssl/s3_both.c +745 -0
- data/third_party/boringssl/ssl/s3_enc.c +412 -0
- data/third_party/boringssl/ssl/s3_lib.c +336 -0
- data/third_party/boringssl/ssl/s3_pkt.c +497 -0
- data/third_party/boringssl/ssl/ssl_aead_ctx.c +329 -0
- data/third_party/boringssl/ssl/ssl_asn1.c +748 -0
- data/third_party/boringssl/ssl/ssl_buffer.c +311 -0
- data/third_party/boringssl/ssl/ssl_cert.c +814 -0
- data/third_party/boringssl/ssl/ssl_cipher.c +2062 -0
- data/third_party/boringssl/ssl/ssl_ecdh.c +610 -0
- data/third_party/boringssl/ssl/ssl_file.c +586 -0
- data/third_party/boringssl/ssl/ssl_lib.c +3063 -0
- data/third_party/boringssl/ssl/ssl_rsa.c +793 -0
- data/third_party/boringssl/ssl/ssl_session.c +985 -0
- data/third_party/boringssl/ssl/ssl_stat.c +509 -0
- data/third_party/boringssl/ssl/t1_enc.c +547 -0
- data/third_party/boringssl/ssl/t1_lib.c +3279 -0
- data/third_party/boringssl/ssl/tls13_both.c +440 -0
- data/third_party/boringssl/ssl/tls13_client.c +682 -0
- data/third_party/boringssl/ssl/tls13_enc.c +391 -0
- data/third_party/boringssl/ssl/tls13_server.c +672 -0
- data/third_party/boringssl/ssl/tls_method.c +245 -0
- data/third_party/boringssl/ssl/tls_record.c +461 -0
- data/third_party/cares/ares_build.h +264 -0
- data/third_party/cares/cares/ares.h +636 -0
- data/third_party/cares/cares/ares__close_sockets.c +61 -0
- data/third_party/cares/cares/ares__get_hostent.c +261 -0
- data/third_party/cares/cares/ares__read_line.c +73 -0
- data/third_party/cares/cares/ares__timeval.c +111 -0
- data/third_party/cares/cares/ares_cancel.c +63 -0
- data/third_party/cares/cares/ares_create_query.c +202 -0
- data/third_party/cares/cares/ares_data.c +221 -0
- data/third_party/cares/cares/ares_data.h +72 -0
- data/third_party/cares/cares/ares_destroy.c +108 -0
- data/third_party/cares/cares/ares_dns.h +103 -0
- data/third_party/cares/cares/ares_expand_name.c +205 -0
- data/third_party/cares/cares/ares_expand_string.c +70 -0
- data/third_party/cares/cares/ares_fds.c +59 -0
- data/third_party/cares/cares/ares_free_hostent.c +41 -0
- data/third_party/cares/cares/ares_free_string.c +25 -0
- data/third_party/cares/cares/ares_getenv.c +30 -0
- data/third_party/cares/cares/ares_getenv.h +26 -0
- data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
- data/third_party/cares/cares/ares_gethostbyname.c +518 -0
- data/third_party/cares/cares/ares_getnameinfo.c +422 -0
- data/third_party/cares/cares/ares_getopt.c +122 -0
- data/third_party/cares/cares/ares_getopt.h +53 -0
- data/third_party/cares/cares/ares_getsock.c +66 -0
- data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
- data/third_party/cares/cares/ares_init.c +2146 -0
- data/third_party/cares/cares/ares_iphlpapi.h +221 -0
- data/third_party/cares/cares/ares_ipv6.h +78 -0
- data/third_party/cares/cares/ares_library_init.c +167 -0
- data/third_party/cares/cares/ares_library_init.h +42 -0
- data/third_party/cares/cares/ares_llist.c +63 -0
- data/third_party/cares/cares/ares_llist.h +39 -0
- data/third_party/cares/cares/ares_mkquery.c +24 -0
- data/third_party/cares/cares/ares_nowarn.c +260 -0
- data/third_party/cares/cares/ares_nowarn.h +61 -0
- data/third_party/cares/cares/ares_options.c +402 -0
- data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
- data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
- data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
- data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
- data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
- data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
- data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
- data/third_party/cares/cares/ares_platform.c +11035 -0
- data/third_party/cares/cares/ares_platform.h +43 -0
- data/third_party/cares/cares/ares_private.h +363 -0
- data/third_party/cares/cares/ares_process.c +1359 -0
- data/third_party/cares/cares/ares_query.c +186 -0
- data/third_party/cares/cares/ares_rules.h +125 -0
- data/third_party/cares/cares/ares_search.c +316 -0
- data/third_party/cares/cares/ares_send.c +131 -0
- data/third_party/cares/cares/ares_setup.h +217 -0
- data/third_party/cares/cares/ares_strcasecmp.c +66 -0
- data/third_party/cares/cares/ares_strcasecmp.h +30 -0
- data/third_party/cares/cares/ares_strdup.c +49 -0
- data/third_party/cares/cares/ares_strdup.h +24 -0
- data/third_party/cares/cares/ares_strerror.c +56 -0
- data/third_party/cares/cares/ares_timeout.c +88 -0
- data/third_party/cares/cares/ares_version.c +11 -0
- data/third_party/cares/cares/ares_version.h +24 -0
- data/third_party/cares/cares/ares_writev.c +79 -0
- data/third_party/cares/cares/bitncmp.c +59 -0
- data/third_party/cares/cares/bitncmp.h +26 -0
- data/third_party/cares/cares/config-win32.h +377 -0
- data/third_party/cares/cares/inet_net_pton.c +450 -0
- data/third_party/cares/cares/inet_ntop.c +208 -0
- data/third_party/cares/cares/setup_once.h +554 -0
- data/third_party/cares/cares/windows_port.c +22 -0
- data/third_party/cares/config_darwin/ares_config.h +523 -0
- data/third_party/cares/config_linux/ares_config.h +524 -0
- data/third_party/nanopb/pb.h +579 -0
- data/third_party/nanopb/pb_common.c +97 -0
- data/third_party/nanopb/pb_common.h +42 -0
- data/third_party/nanopb/pb_decode.c +1347 -0
- data/third_party/nanopb/pb_decode.h +149 -0
- data/third_party/nanopb/pb_encode.c +696 -0
- data/third_party/nanopb/pb_encode.h +154 -0
- data/third_party/zlib/adler32.c +179 -0
- data/third_party/zlib/compress.c +80 -0
- data/third_party/zlib/crc32.c +425 -0
- data/third_party/zlib/crc32.h +441 -0
- data/third_party/zlib/deflate.c +1967 -0
- data/third_party/zlib/deflate.h +346 -0
- data/third_party/zlib/gzclose.c +25 -0
- data/third_party/zlib/gzguts.h +209 -0
- data/third_party/zlib/gzlib.c +634 -0
- data/third_party/zlib/gzread.c +594 -0
- data/third_party/zlib/gzwrite.c +577 -0
- data/third_party/zlib/infback.c +640 -0
- data/third_party/zlib/inffast.c +340 -0
- data/third_party/zlib/inffast.h +11 -0
- data/third_party/zlib/inffixed.h +94 -0
- data/third_party/zlib/inflate.c +1512 -0
- data/third_party/zlib/inflate.h +122 -0
- data/third_party/zlib/inftrees.c +306 -0
- data/third_party/zlib/inftrees.h +62 -0
- data/third_party/zlib/trees.c +1226 -0
- data/third_party/zlib/trees.h +128 -0
- data/third_party/zlib/uncompr.c +59 -0
- data/third_party/zlib/zconf.h +511 -0
- data/third_party/zlib/zlib.h +1768 -0
- data/third_party/zlib/zutil.c +324 -0
- data/third_party/zlib/zutil.h +253 -0
- metadata +1397 -0
@@ -0,0 +1,1741 @@
|
|
1
|
+
/* Copyright (c) 2015, Google Inc.
|
2
|
+
*
|
3
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
* purpose with or without fee is hereby granted, provided that the above
|
5
|
+
* copyright notice and this permission notice appear in all copies.
|
6
|
+
*
|
7
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
10
|
+
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
12
|
+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
13
|
+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
14
|
+
|
15
|
+
/* A 64-bit implementation of the NIST P-256 elliptic curve point
|
16
|
+
* multiplication
|
17
|
+
*
|
18
|
+
* OpenSSL integration was taken from Emilia Kasper's work in ecp_nistp224.c.
|
19
|
+
* Otherwise based on Emilia's P224 work, which was inspired by my curve25519
|
20
|
+
* work which got its smarts from Daniel J. Bernstein's work on the same. */
|
21
|
+
|
22
|
+
#include <openssl/base.h>
|
23
|
+
|
24
|
+
#if defined(OPENSSL_64_BIT) && !defined(OPENSSL_WINDOWS)
|
25
|
+
|
26
|
+
#include <openssl/bn.h>
|
27
|
+
#include <openssl/ec.h>
|
28
|
+
#include <openssl/err.h>
|
29
|
+
#include <openssl/mem.h>
|
30
|
+
|
31
|
+
#include <string.h>
|
32
|
+
|
33
|
+
#include "internal.h"
|
34
|
+
#include "../internal.h"
|
35
|
+
|
36
|
+
|
37
|
+
typedef uint8_t u8;
|
38
|
+
typedef uint64_t u64;
|
39
|
+
typedef int64_t s64;
|
40
|
+
|
41
|
+
/* The underlying field. P256 operates over GF(2^256-2^224+2^192+2^96-1). We
|
42
|
+
* can serialise an element of this field into 32 bytes. We call this an
|
43
|
+
* felem_bytearray. */
|
44
|
+
typedef u8 felem_bytearray[32];
|
45
|
+
|
46
|
+
/* The representation of field elements.
|
47
|
+
* ------------------------------------
|
48
|
+
*
|
49
|
+
* We represent field elements with either four 128-bit values, eight 128-bit
|
50
|
+
* values, or four 64-bit values. The field element represented is:
|
51
|
+
* v[0]*2^0 + v[1]*2^64 + v[2]*2^128 + v[3]*2^192 (mod p)
|
52
|
+
* or:
|
53
|
+
* v[0]*2^0 + v[1]*2^64 + v[2]*2^128 + ... + v[8]*2^512 (mod p)
|
54
|
+
*
|
55
|
+
* 128-bit values are called 'limbs'. Since the limbs are spaced only 64 bits
|
56
|
+
* apart, but are 128-bits wide, the most significant bits of each limb overlap
|
57
|
+
* with the least significant bits of the next.
|
58
|
+
*
|
59
|
+
* A field element with four limbs is an 'felem'. One with eight limbs is a
|
60
|
+
* 'longfelem'
|
61
|
+
*
|
62
|
+
* A field element with four, 64-bit values is called a 'smallfelem'. Small
|
63
|
+
* values are used as intermediate values before multiplication. */
|
64
|
+
|
65
|
+
#define NLIMBS 4
|
66
|
+
|
67
|
+
typedef uint128_t limb;
|
68
|
+
typedef limb felem[NLIMBS];
|
69
|
+
typedef limb longfelem[NLIMBS * 2];
|
70
|
+
typedef u64 smallfelem[NLIMBS];
|
71
|
+
|
72
|
+
/* This is the value of the prime as four 64-bit words, little-endian. */
|
73
|
+
static const u64 kPrime[4] = {0xfffffffffffffffful, 0xffffffff, 0,
|
74
|
+
0xffffffff00000001ul};
|
75
|
+
static const u64 bottom63bits = 0x7ffffffffffffffful;
|
76
|
+
|
77
|
+
/* bin32_to_felem takes a little-endian byte array and converts it into felem
|
78
|
+
* form. This assumes that the CPU is little-endian. */
|
79
|
+
static void bin32_to_felem(felem out, const u8 in[32]) {
|
80
|
+
out[0] = *((const u64 *)&in[0]);
|
81
|
+
out[1] = *((const u64 *)&in[8]);
|
82
|
+
out[2] = *((const u64 *)&in[16]);
|
83
|
+
out[3] = *((const u64 *)&in[24]);
|
84
|
+
}
|
85
|
+
|
86
|
+
/* smallfelem_to_bin32 takes a smallfelem and serialises into a little endian,
|
87
|
+
* 32 byte array. This assumes that the CPU is little-endian. */
|
88
|
+
static void smallfelem_to_bin32(u8 out[32], const smallfelem in) {
|
89
|
+
*((u64 *)&out[0]) = in[0];
|
90
|
+
*((u64 *)&out[8]) = in[1];
|
91
|
+
*((u64 *)&out[16]) = in[2];
|
92
|
+
*((u64 *)&out[24]) = in[3];
|
93
|
+
}
|
94
|
+
|
95
|
+
/* To preserve endianness when using BN_bn2bin and BN_bin2bn. */
|
96
|
+
static void flip_endian(u8 *out, const u8 *in, size_t len) {
|
97
|
+
for (size_t i = 0; i < len; ++i) {
|
98
|
+
out[i] = in[len - 1 - i];
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
/* BN_to_felem converts an OpenSSL BIGNUM into an felem. */
|
103
|
+
static int BN_to_felem(felem out, const BIGNUM *bn) {
|
104
|
+
if (BN_is_negative(bn)) {
|
105
|
+
OPENSSL_PUT_ERROR(EC, EC_R_BIGNUM_OUT_OF_RANGE);
|
106
|
+
return 0;
|
107
|
+
}
|
108
|
+
|
109
|
+
felem_bytearray b_out;
|
110
|
+
/* BN_bn2bin eats leading zeroes */
|
111
|
+
memset(b_out, 0, sizeof(b_out));
|
112
|
+
size_t num_bytes = BN_num_bytes(bn);
|
113
|
+
if (num_bytes > sizeof(b_out)) {
|
114
|
+
OPENSSL_PUT_ERROR(EC, EC_R_BIGNUM_OUT_OF_RANGE);
|
115
|
+
return 0;
|
116
|
+
}
|
117
|
+
|
118
|
+
felem_bytearray b_in;
|
119
|
+
num_bytes = BN_bn2bin(bn, b_in);
|
120
|
+
flip_endian(b_out, b_in, num_bytes);
|
121
|
+
bin32_to_felem(out, b_out);
|
122
|
+
return 1;
|
123
|
+
}
|
124
|
+
|
125
|
+
/* felem_to_BN converts an felem into an OpenSSL BIGNUM. */
|
126
|
+
static BIGNUM *smallfelem_to_BN(BIGNUM *out, const smallfelem in) {
|
127
|
+
felem_bytearray b_in, b_out;
|
128
|
+
smallfelem_to_bin32(b_in, in);
|
129
|
+
flip_endian(b_out, b_in, sizeof(b_out));
|
130
|
+
return BN_bin2bn(b_out, sizeof(b_out), out);
|
131
|
+
}
|
132
|
+
|
133
|
+
/* Field operations. */
|
134
|
+
|
135
|
+
static void felem_assign(felem out, const felem in) {
|
136
|
+
out[0] = in[0];
|
137
|
+
out[1] = in[1];
|
138
|
+
out[2] = in[2];
|
139
|
+
out[3] = in[3];
|
140
|
+
}
|
141
|
+
|
142
|
+
/* felem_sum sets out = out + in. */
|
143
|
+
static void felem_sum(felem out, const felem in) {
|
144
|
+
out[0] += in[0];
|
145
|
+
out[1] += in[1];
|
146
|
+
out[2] += in[2];
|
147
|
+
out[3] += in[3];
|
148
|
+
}
|
149
|
+
|
150
|
+
/* felem_small_sum sets out = out + in. */
|
151
|
+
static void felem_small_sum(felem out, const smallfelem in) {
|
152
|
+
out[0] += in[0];
|
153
|
+
out[1] += in[1];
|
154
|
+
out[2] += in[2];
|
155
|
+
out[3] += in[3];
|
156
|
+
}
|
157
|
+
|
158
|
+
/* felem_scalar sets out = out * scalar */
|
159
|
+
static void felem_scalar(felem out, const u64 scalar) {
|
160
|
+
out[0] *= scalar;
|
161
|
+
out[1] *= scalar;
|
162
|
+
out[2] *= scalar;
|
163
|
+
out[3] *= scalar;
|
164
|
+
}
|
165
|
+
|
166
|
+
/* longfelem_scalar sets out = out * scalar */
|
167
|
+
static void longfelem_scalar(longfelem out, const u64 scalar) {
|
168
|
+
out[0] *= scalar;
|
169
|
+
out[1] *= scalar;
|
170
|
+
out[2] *= scalar;
|
171
|
+
out[3] *= scalar;
|
172
|
+
out[4] *= scalar;
|
173
|
+
out[5] *= scalar;
|
174
|
+
out[6] *= scalar;
|
175
|
+
out[7] *= scalar;
|
176
|
+
}
|
177
|
+
|
178
|
+
#define two105m41m9 (((limb)1) << 105) - (((limb)1) << 41) - (((limb)1) << 9)
|
179
|
+
#define two105 (((limb)1) << 105)
|
180
|
+
#define two105m41p9 (((limb)1) << 105) - (((limb)1) << 41) + (((limb)1) << 9)
|
181
|
+
|
182
|
+
/* zero105 is 0 mod p */
|
183
|
+
static const felem zero105 = {two105m41m9, two105, two105m41p9, two105m41p9};
|
184
|
+
|
185
|
+
/* smallfelem_neg sets |out| to |-small|
|
186
|
+
* On exit:
|
187
|
+
* out[i] < out[i] + 2^105 */
|
188
|
+
static void smallfelem_neg(felem out, const smallfelem small) {
|
189
|
+
/* In order to prevent underflow, we subtract from 0 mod p. */
|
190
|
+
out[0] = zero105[0] - small[0];
|
191
|
+
out[1] = zero105[1] - small[1];
|
192
|
+
out[2] = zero105[2] - small[2];
|
193
|
+
out[3] = zero105[3] - small[3];
|
194
|
+
}
|
195
|
+
|
196
|
+
/* felem_diff subtracts |in| from |out|
|
197
|
+
* On entry:
|
198
|
+
* in[i] < 2^104
|
199
|
+
* On exit:
|
200
|
+
* out[i] < out[i] + 2^105. */
|
201
|
+
static void felem_diff(felem out, const felem in) {
|
202
|
+
/* In order to prevent underflow, we add 0 mod p before subtracting. */
|
203
|
+
out[0] += zero105[0];
|
204
|
+
out[1] += zero105[1];
|
205
|
+
out[2] += zero105[2];
|
206
|
+
out[3] += zero105[3];
|
207
|
+
|
208
|
+
out[0] -= in[0];
|
209
|
+
out[1] -= in[1];
|
210
|
+
out[2] -= in[2];
|
211
|
+
out[3] -= in[3];
|
212
|
+
}
|
213
|
+
|
214
|
+
#define two107m43m11 (((limb)1) << 107) - (((limb)1) << 43) - (((limb)1) << 11)
|
215
|
+
#define two107 (((limb)1) << 107)
|
216
|
+
#define two107m43p11 (((limb)1) << 107) - (((limb)1) << 43) + (((limb)1) << 11)
|
217
|
+
|
218
|
+
/* zero107 is 0 mod p */
|
219
|
+
static const felem zero107 = {two107m43m11, two107, two107m43p11, two107m43p11};
|
220
|
+
|
221
|
+
/* An alternative felem_diff for larger inputs |in|
|
222
|
+
* felem_diff_zero107 subtracts |in| from |out|
|
223
|
+
* On entry:
|
224
|
+
* in[i] < 2^106
|
225
|
+
* On exit:
|
226
|
+
* out[i] < out[i] + 2^107. */
|
227
|
+
static void felem_diff_zero107(felem out, const felem in) {
|
228
|
+
/* In order to prevent underflow, we add 0 mod p before subtracting. */
|
229
|
+
out[0] += zero107[0];
|
230
|
+
out[1] += zero107[1];
|
231
|
+
out[2] += zero107[2];
|
232
|
+
out[3] += zero107[3];
|
233
|
+
|
234
|
+
out[0] -= in[0];
|
235
|
+
out[1] -= in[1];
|
236
|
+
out[2] -= in[2];
|
237
|
+
out[3] -= in[3];
|
238
|
+
}
|
239
|
+
|
240
|
+
/* longfelem_diff subtracts |in| from |out|
|
241
|
+
* On entry:
|
242
|
+
* in[i] < 7*2^67
|
243
|
+
* On exit:
|
244
|
+
* out[i] < out[i] + 2^70 + 2^40. */
|
245
|
+
static void longfelem_diff(longfelem out, const longfelem in) {
|
246
|
+
static const limb two70m8p6 =
|
247
|
+
(((limb)1) << 70) - (((limb)1) << 8) + (((limb)1) << 6);
|
248
|
+
static const limb two70p40 = (((limb)1) << 70) + (((limb)1) << 40);
|
249
|
+
static const limb two70 = (((limb)1) << 70);
|
250
|
+
static const limb two70m40m38p6 = (((limb)1) << 70) - (((limb)1) << 40) -
|
251
|
+
(((limb)1) << 38) + (((limb)1) << 6);
|
252
|
+
static const limb two70m6 = (((limb)1) << 70) - (((limb)1) << 6);
|
253
|
+
|
254
|
+
/* add 0 mod p to avoid underflow */
|
255
|
+
out[0] += two70m8p6;
|
256
|
+
out[1] += two70p40;
|
257
|
+
out[2] += two70;
|
258
|
+
out[3] += two70m40m38p6;
|
259
|
+
out[4] += two70m6;
|
260
|
+
out[5] += two70m6;
|
261
|
+
out[6] += two70m6;
|
262
|
+
out[7] += two70m6;
|
263
|
+
|
264
|
+
/* in[i] < 7*2^67 < 2^70 - 2^40 - 2^38 + 2^6 */
|
265
|
+
out[0] -= in[0];
|
266
|
+
out[1] -= in[1];
|
267
|
+
out[2] -= in[2];
|
268
|
+
out[3] -= in[3];
|
269
|
+
out[4] -= in[4];
|
270
|
+
out[5] -= in[5];
|
271
|
+
out[6] -= in[6];
|
272
|
+
out[7] -= in[7];
|
273
|
+
}
|
274
|
+
|
275
|
+
#define two64m0 (((limb)1) << 64) - 1
|
276
|
+
#define two110p32m0 (((limb)1) << 110) + (((limb)1) << 32) - 1
|
277
|
+
#define two64m46 (((limb)1) << 64) - (((limb)1) << 46)
|
278
|
+
#define two64m32 (((limb)1) << 64) - (((limb)1) << 32)
|
279
|
+
|
280
|
+
/* zero110 is 0 mod p. */
|
281
|
+
static const felem zero110 = {two64m0, two110p32m0, two64m46, two64m32};
|
282
|
+
|
283
|
+
/* felem_shrink converts an felem into a smallfelem. The result isn't quite
|
284
|
+
* minimal as the value may be greater than p.
|
285
|
+
*
|
286
|
+
* On entry:
|
287
|
+
* in[i] < 2^109
|
288
|
+
* On exit:
|
289
|
+
* out[i] < 2^64. */
|
290
|
+
static void felem_shrink(smallfelem out, const felem in) {
|
291
|
+
felem tmp;
|
292
|
+
u64 a, b, mask;
|
293
|
+
s64 high, low;
|
294
|
+
static const u64 kPrime3Test = 0x7fffffff00000001ul; /* 2^63 - 2^32 + 1 */
|
295
|
+
|
296
|
+
/* Carry 2->3 */
|
297
|
+
tmp[3] = zero110[3] + in[3] + ((u64)(in[2] >> 64));
|
298
|
+
/* tmp[3] < 2^110 */
|
299
|
+
|
300
|
+
tmp[2] = zero110[2] + (u64)in[2];
|
301
|
+
tmp[0] = zero110[0] + in[0];
|
302
|
+
tmp[1] = zero110[1] + in[1];
|
303
|
+
/* tmp[0] < 2**110, tmp[1] < 2^111, tmp[2] < 2**65 */
|
304
|
+
|
305
|
+
/* We perform two partial reductions where we eliminate the high-word of
|
306
|
+
* tmp[3]. We don't update the other words till the end. */
|
307
|
+
a = tmp[3] >> 64; /* a < 2^46 */
|
308
|
+
tmp[3] = (u64)tmp[3];
|
309
|
+
tmp[3] -= a;
|
310
|
+
tmp[3] += ((limb)a) << 32;
|
311
|
+
/* tmp[3] < 2^79 */
|
312
|
+
|
313
|
+
b = a;
|
314
|
+
a = tmp[3] >> 64; /* a < 2^15 */
|
315
|
+
b += a; /* b < 2^46 + 2^15 < 2^47 */
|
316
|
+
tmp[3] = (u64)tmp[3];
|
317
|
+
tmp[3] -= a;
|
318
|
+
tmp[3] += ((limb)a) << 32;
|
319
|
+
/* tmp[3] < 2^64 + 2^47 */
|
320
|
+
|
321
|
+
/* This adjusts the other two words to complete the two partial
|
322
|
+
* reductions. */
|
323
|
+
tmp[0] += b;
|
324
|
+
tmp[1] -= (((limb)b) << 32);
|
325
|
+
|
326
|
+
/* In order to make space in tmp[3] for the carry from 2 -> 3, we
|
327
|
+
* conditionally subtract kPrime if tmp[3] is large enough. */
|
328
|
+
high = tmp[3] >> 64;
|
329
|
+
/* As tmp[3] < 2^65, high is either 1 or 0 */
|
330
|
+
high = ~(high - 1);
|
331
|
+
/* high is:
|
332
|
+
* all ones if the high word of tmp[3] is 1
|
333
|
+
* all zeros if the high word of tmp[3] if 0 */
|
334
|
+
low = tmp[3];
|
335
|
+
mask = low >> 63;
|
336
|
+
/* mask is:
|
337
|
+
* all ones if the MSB of low is 1
|
338
|
+
* all zeros if the MSB of low if 0 */
|
339
|
+
low &= bottom63bits;
|
340
|
+
low -= kPrime3Test;
|
341
|
+
/* if low was greater than kPrime3Test then the MSB is zero */
|
342
|
+
low = ~low;
|
343
|
+
low >>= 63;
|
344
|
+
/* low is:
|
345
|
+
* all ones if low was > kPrime3Test
|
346
|
+
* all zeros if low was <= kPrime3Test */
|
347
|
+
mask = (mask & low) | high;
|
348
|
+
tmp[0] -= mask & kPrime[0];
|
349
|
+
tmp[1] -= mask & kPrime[1];
|
350
|
+
/* kPrime[2] is zero, so omitted */
|
351
|
+
tmp[3] -= mask & kPrime[3];
|
352
|
+
/* tmp[3] < 2**64 - 2**32 + 1 */
|
353
|
+
|
354
|
+
tmp[1] += ((u64)(tmp[0] >> 64));
|
355
|
+
tmp[0] = (u64)tmp[0];
|
356
|
+
tmp[2] += ((u64)(tmp[1] >> 64));
|
357
|
+
tmp[1] = (u64)tmp[1];
|
358
|
+
tmp[3] += ((u64)(tmp[2] >> 64));
|
359
|
+
tmp[2] = (u64)tmp[2];
|
360
|
+
/* tmp[i] < 2^64 */
|
361
|
+
|
362
|
+
out[0] = tmp[0];
|
363
|
+
out[1] = tmp[1];
|
364
|
+
out[2] = tmp[2];
|
365
|
+
out[3] = tmp[3];
|
366
|
+
}
|
367
|
+
|
368
|
+
/* smallfelem_expand converts a smallfelem to an felem */
|
369
|
+
static void smallfelem_expand(felem out, const smallfelem in) {
|
370
|
+
out[0] = in[0];
|
371
|
+
out[1] = in[1];
|
372
|
+
out[2] = in[2];
|
373
|
+
out[3] = in[3];
|
374
|
+
}
|
375
|
+
|
376
|
+
/* smallfelem_square sets |out| = |small|^2
|
377
|
+
* On entry:
|
378
|
+
* small[i] < 2^64
|
379
|
+
* On exit:
|
380
|
+
* out[i] < 7 * 2^64 < 2^67 */
|
381
|
+
static void smallfelem_square(longfelem out, const smallfelem small) {
|
382
|
+
limb a;
|
383
|
+
u64 high, low;
|
384
|
+
|
385
|
+
a = ((uint128_t)small[0]) * small[0];
|
386
|
+
low = a;
|
387
|
+
high = a >> 64;
|
388
|
+
out[0] = low;
|
389
|
+
out[1] = high;
|
390
|
+
|
391
|
+
a = ((uint128_t)small[0]) * small[1];
|
392
|
+
low = a;
|
393
|
+
high = a >> 64;
|
394
|
+
out[1] += low;
|
395
|
+
out[1] += low;
|
396
|
+
out[2] = high;
|
397
|
+
|
398
|
+
a = ((uint128_t)small[0]) * small[2];
|
399
|
+
low = a;
|
400
|
+
high = a >> 64;
|
401
|
+
out[2] += low;
|
402
|
+
out[2] *= 2;
|
403
|
+
out[3] = high;
|
404
|
+
|
405
|
+
a = ((uint128_t)small[0]) * small[3];
|
406
|
+
low = a;
|
407
|
+
high = a >> 64;
|
408
|
+
out[3] += low;
|
409
|
+
out[4] = high;
|
410
|
+
|
411
|
+
a = ((uint128_t)small[1]) * small[2];
|
412
|
+
low = a;
|
413
|
+
high = a >> 64;
|
414
|
+
out[3] += low;
|
415
|
+
out[3] *= 2;
|
416
|
+
out[4] += high;
|
417
|
+
|
418
|
+
a = ((uint128_t)small[1]) * small[1];
|
419
|
+
low = a;
|
420
|
+
high = a >> 64;
|
421
|
+
out[2] += low;
|
422
|
+
out[3] += high;
|
423
|
+
|
424
|
+
a = ((uint128_t)small[1]) * small[3];
|
425
|
+
low = a;
|
426
|
+
high = a >> 64;
|
427
|
+
out[4] += low;
|
428
|
+
out[4] *= 2;
|
429
|
+
out[5] = high;
|
430
|
+
|
431
|
+
a = ((uint128_t)small[2]) * small[3];
|
432
|
+
low = a;
|
433
|
+
high = a >> 64;
|
434
|
+
out[5] += low;
|
435
|
+
out[5] *= 2;
|
436
|
+
out[6] = high;
|
437
|
+
out[6] += high;
|
438
|
+
|
439
|
+
a = ((uint128_t)small[2]) * small[2];
|
440
|
+
low = a;
|
441
|
+
high = a >> 64;
|
442
|
+
out[4] += low;
|
443
|
+
out[5] += high;
|
444
|
+
|
445
|
+
a = ((uint128_t)small[3]) * small[3];
|
446
|
+
low = a;
|
447
|
+
high = a >> 64;
|
448
|
+
out[6] += low;
|
449
|
+
out[7] = high;
|
450
|
+
}
|
451
|
+
|
452
|
+
/*felem_square sets |out| = |in|^2
|
453
|
+
* On entry:
|
454
|
+
* in[i] < 2^109
|
455
|
+
* On exit:
|
456
|
+
* out[i] < 7 * 2^64 < 2^67. */
|
457
|
+
static void felem_square(longfelem out, const felem in) {
|
458
|
+
u64 small[4];
|
459
|
+
felem_shrink(small, in);
|
460
|
+
smallfelem_square(out, small);
|
461
|
+
}
|
462
|
+
|
463
|
+
/* smallfelem_mul sets |out| = |small1| * |small2|
|
464
|
+
* On entry:
|
465
|
+
* small1[i] < 2^64
|
466
|
+
* small2[i] < 2^64
|
467
|
+
* On exit:
|
468
|
+
* out[i] < 7 * 2^64 < 2^67. */
|
469
|
+
static void smallfelem_mul(longfelem out, const smallfelem small1,
|
470
|
+
const smallfelem small2) {
|
471
|
+
limb a;
|
472
|
+
u64 high, low;
|
473
|
+
|
474
|
+
a = ((uint128_t)small1[0]) * small2[0];
|
475
|
+
low = a;
|
476
|
+
high = a >> 64;
|
477
|
+
out[0] = low;
|
478
|
+
out[1] = high;
|
479
|
+
|
480
|
+
a = ((uint128_t)small1[0]) * small2[1];
|
481
|
+
low = a;
|
482
|
+
high = a >> 64;
|
483
|
+
out[1] += low;
|
484
|
+
out[2] = high;
|
485
|
+
|
486
|
+
a = ((uint128_t)small1[1]) * small2[0];
|
487
|
+
low = a;
|
488
|
+
high = a >> 64;
|
489
|
+
out[1] += low;
|
490
|
+
out[2] += high;
|
491
|
+
|
492
|
+
a = ((uint128_t)small1[0]) * small2[2];
|
493
|
+
low = a;
|
494
|
+
high = a >> 64;
|
495
|
+
out[2] += low;
|
496
|
+
out[3] = high;
|
497
|
+
|
498
|
+
a = ((uint128_t)small1[1]) * small2[1];
|
499
|
+
low = a;
|
500
|
+
high = a >> 64;
|
501
|
+
out[2] += low;
|
502
|
+
out[3] += high;
|
503
|
+
|
504
|
+
a = ((uint128_t)small1[2]) * small2[0];
|
505
|
+
low = a;
|
506
|
+
high = a >> 64;
|
507
|
+
out[2] += low;
|
508
|
+
out[3] += high;
|
509
|
+
|
510
|
+
a = ((uint128_t)small1[0]) * small2[3];
|
511
|
+
low = a;
|
512
|
+
high = a >> 64;
|
513
|
+
out[3] += low;
|
514
|
+
out[4] = high;
|
515
|
+
|
516
|
+
a = ((uint128_t)small1[1]) * small2[2];
|
517
|
+
low = a;
|
518
|
+
high = a >> 64;
|
519
|
+
out[3] += low;
|
520
|
+
out[4] += high;
|
521
|
+
|
522
|
+
a = ((uint128_t)small1[2]) * small2[1];
|
523
|
+
low = a;
|
524
|
+
high = a >> 64;
|
525
|
+
out[3] += low;
|
526
|
+
out[4] += high;
|
527
|
+
|
528
|
+
a = ((uint128_t)small1[3]) * small2[0];
|
529
|
+
low = a;
|
530
|
+
high = a >> 64;
|
531
|
+
out[3] += low;
|
532
|
+
out[4] += high;
|
533
|
+
|
534
|
+
a = ((uint128_t)small1[1]) * small2[3];
|
535
|
+
low = a;
|
536
|
+
high = a >> 64;
|
537
|
+
out[4] += low;
|
538
|
+
out[5] = high;
|
539
|
+
|
540
|
+
a = ((uint128_t)small1[2]) * small2[2];
|
541
|
+
low = a;
|
542
|
+
high = a >> 64;
|
543
|
+
out[4] += low;
|
544
|
+
out[5] += high;
|
545
|
+
|
546
|
+
a = ((uint128_t)small1[3]) * small2[1];
|
547
|
+
low = a;
|
548
|
+
high = a >> 64;
|
549
|
+
out[4] += low;
|
550
|
+
out[5] += high;
|
551
|
+
|
552
|
+
a = ((uint128_t)small1[2]) * small2[3];
|
553
|
+
low = a;
|
554
|
+
high = a >> 64;
|
555
|
+
out[5] += low;
|
556
|
+
out[6] = high;
|
557
|
+
|
558
|
+
a = ((uint128_t)small1[3]) * small2[2];
|
559
|
+
low = a;
|
560
|
+
high = a >> 64;
|
561
|
+
out[5] += low;
|
562
|
+
out[6] += high;
|
563
|
+
|
564
|
+
a = ((uint128_t)small1[3]) * small2[3];
|
565
|
+
low = a;
|
566
|
+
high = a >> 64;
|
567
|
+
out[6] += low;
|
568
|
+
out[7] = high;
|
569
|
+
}
|
570
|
+
|
571
|
+
/* felem_mul sets |out| = |in1| * |in2|
|
572
|
+
* On entry:
|
573
|
+
* in1[i] < 2^109
|
574
|
+
* in2[i] < 2^109
|
575
|
+
* On exit:
|
576
|
+
* out[i] < 7 * 2^64 < 2^67 */
|
577
|
+
static void felem_mul(longfelem out, const felem in1, const felem in2) {
|
578
|
+
smallfelem small1, small2;
|
579
|
+
felem_shrink(small1, in1);
|
580
|
+
felem_shrink(small2, in2);
|
581
|
+
smallfelem_mul(out, small1, small2);
|
582
|
+
}
|
583
|
+
|
584
|
+
/* felem_small_mul sets |out| = |small1| * |in2|
|
585
|
+
* On entry:
|
586
|
+
* small1[i] < 2^64
|
587
|
+
* in2[i] < 2^109
|
588
|
+
* On exit:
|
589
|
+
* out[i] < 7 * 2^64 < 2^67 */
|
590
|
+
static void felem_small_mul(longfelem out, const smallfelem small1,
|
591
|
+
const felem in2) {
|
592
|
+
smallfelem small2;
|
593
|
+
felem_shrink(small2, in2);
|
594
|
+
smallfelem_mul(out, small1, small2);
|
595
|
+
}
|
596
|
+
|
597
|
+
#define two100m36m4 (((limb)1) << 100) - (((limb)1) << 36) - (((limb)1) << 4)
|
598
|
+
#define two100 (((limb)1) << 100)
|
599
|
+
#define two100m36p4 (((limb)1) << 100) - (((limb)1) << 36) + (((limb)1) << 4)
|
600
|
+
|
601
|
+
/* zero100 is 0 mod p */
|
602
|
+
static const felem zero100 = {two100m36m4, two100, two100m36p4, two100m36p4};
|
603
|
+
|
604
|
+
/* Internal function for the different flavours of felem_reduce.
|
605
|
+
* felem_reduce_ reduces the higher coefficients in[4]-in[7].
|
606
|
+
* On entry:
|
607
|
+
* out[0] >= in[6] + 2^32*in[6] + in[7] + 2^32*in[7]
|
608
|
+
* out[1] >= in[7] + 2^32*in[4]
|
609
|
+
* out[2] >= in[5] + 2^32*in[5]
|
610
|
+
* out[3] >= in[4] + 2^32*in[5] + 2^32*in[6]
|
611
|
+
* On exit:
|
612
|
+
* out[0] <= out[0] + in[4] + 2^32*in[5]
|
613
|
+
* out[1] <= out[1] + in[5] + 2^33*in[6]
|
614
|
+
* out[2] <= out[2] + in[7] + 2*in[6] + 2^33*in[7]
|
615
|
+
* out[3] <= out[3] + 2^32*in[4] + 3*in[7] */
|
616
|
+
static void felem_reduce_(felem out, const longfelem in) {
|
617
|
+
int128_t c;
|
618
|
+
/* combine common terms from below */
|
619
|
+
c = in[4] + (in[5] << 32);
|
620
|
+
out[0] += c;
|
621
|
+
out[3] -= c;
|
622
|
+
|
623
|
+
c = in[5] - in[7];
|
624
|
+
out[1] += c;
|
625
|
+
out[2] -= c;
|
626
|
+
|
627
|
+
/* the remaining terms */
|
628
|
+
/* 256: [(0,1),(96,-1),(192,-1),(224,1)] */
|
629
|
+
out[1] -= (in[4] << 32);
|
630
|
+
out[3] += (in[4] << 32);
|
631
|
+
|
632
|
+
/* 320: [(32,1),(64,1),(128,-1),(160,-1),(224,-1)] */
|
633
|
+
out[2] -= (in[5] << 32);
|
634
|
+
|
635
|
+
/* 384: [(0,-1),(32,-1),(96,2),(128,2),(224,-1)] */
|
636
|
+
out[0] -= in[6];
|
637
|
+
out[0] -= (in[6] << 32);
|
638
|
+
out[1] += (in[6] << 33);
|
639
|
+
out[2] += (in[6] * 2);
|
640
|
+
out[3] -= (in[6] << 32);
|
641
|
+
|
642
|
+
/* 448: [(0,-1),(32,-1),(64,-1),(128,1),(160,2),(192,3)] */
|
643
|
+
out[0] -= in[7];
|
644
|
+
out[0] -= (in[7] << 32);
|
645
|
+
out[2] += (in[7] << 33);
|
646
|
+
out[3] += (in[7] * 3);
|
647
|
+
}
|
648
|
+
|
649
|
+
/* felem_reduce converts a longfelem into an felem.
|
650
|
+
* To be called directly after felem_square or felem_mul.
|
651
|
+
* On entry:
|
652
|
+
* in[0] < 2^64, in[1] < 3*2^64, in[2] < 5*2^64, in[3] < 7*2^64
|
653
|
+
* in[4] < 7*2^64, in[5] < 5*2^64, in[6] < 3*2^64, in[7] < 2*64
|
654
|
+
* On exit:
|
655
|
+
* out[i] < 2^101 */
|
656
|
+
static void felem_reduce(felem out, const longfelem in) {
|
657
|
+
out[0] = zero100[0] + in[0];
|
658
|
+
out[1] = zero100[1] + in[1];
|
659
|
+
out[2] = zero100[2] + in[2];
|
660
|
+
out[3] = zero100[3] + in[3];
|
661
|
+
|
662
|
+
felem_reduce_(out, in);
|
663
|
+
|
664
|
+
/* out[0] > 2^100 - 2^36 - 2^4 - 3*2^64 - 3*2^96 - 2^64 - 2^96 > 0
|
665
|
+
* out[1] > 2^100 - 2^64 - 7*2^96 > 0
|
666
|
+
* out[2] > 2^100 - 2^36 + 2^4 - 5*2^64 - 5*2^96 > 0
|
667
|
+
* out[3] > 2^100 - 2^36 + 2^4 - 7*2^64 - 5*2^96 - 3*2^96 > 0
|
668
|
+
*
|
669
|
+
* out[0] < 2^100 + 2^64 + 7*2^64 + 5*2^96 < 2^101
|
670
|
+
* out[1] < 2^100 + 3*2^64 + 5*2^64 + 3*2^97 < 2^101
|
671
|
+
* out[2] < 2^100 + 5*2^64 + 2^64 + 3*2^65 + 2^97 < 2^101
|
672
|
+
* out[3] < 2^100 + 7*2^64 + 7*2^96 + 3*2^64 < 2^101 */
|
673
|
+
}
|
674
|
+
|
675
|
+
/* felem_reduce_zero105 converts a larger longfelem into an felem.
|
676
|
+
* On entry:
|
677
|
+
* in[0] < 2^71
|
678
|
+
* On exit:
|
679
|
+
* out[i] < 2^106 */
|
680
|
+
static void felem_reduce_zero105(felem out, const longfelem in) {
|
681
|
+
out[0] = zero105[0] + in[0];
|
682
|
+
out[1] = zero105[1] + in[1];
|
683
|
+
out[2] = zero105[2] + in[2];
|
684
|
+
out[3] = zero105[3] + in[3];
|
685
|
+
|
686
|
+
felem_reduce_(out, in);
|
687
|
+
|
688
|
+
/* out[0] > 2^105 - 2^41 - 2^9 - 2^71 - 2^103 - 2^71 - 2^103 > 0
|
689
|
+
* out[1] > 2^105 - 2^71 - 2^103 > 0
|
690
|
+
* out[2] > 2^105 - 2^41 + 2^9 - 2^71 - 2^103 > 0
|
691
|
+
* out[3] > 2^105 - 2^41 + 2^9 - 2^71 - 2^103 - 2^103 > 0
|
692
|
+
*
|
693
|
+
* out[0] < 2^105 + 2^71 + 2^71 + 2^103 < 2^106
|
694
|
+
* out[1] < 2^105 + 2^71 + 2^71 + 2^103 < 2^106
|
695
|
+
* out[2] < 2^105 + 2^71 + 2^71 + 2^71 + 2^103 < 2^106
|
696
|
+
* out[3] < 2^105 + 2^71 + 2^103 + 2^71 < 2^106 */
|
697
|
+
}
|
698
|
+
|
699
|
+
/* subtract_u64 sets *result = *result - v and *carry to one if the
|
700
|
+
* subtraction underflowed. */
|
701
|
+
static void subtract_u64(u64 *result, u64 *carry, u64 v) {
|
702
|
+
uint128_t r = *result;
|
703
|
+
r -= v;
|
704
|
+
*carry = (r >> 64) & 1;
|
705
|
+
*result = (u64)r;
|
706
|
+
}
|
707
|
+
|
708
|
+
/* felem_contract converts |in| to its unique, minimal representation. On
|
709
|
+
* entry: in[i] < 2^109. */
|
710
|
+
static void felem_contract(smallfelem out, const felem in) {
|
711
|
+
u64 all_equal_so_far = 0, result = 0;
|
712
|
+
|
713
|
+
felem_shrink(out, in);
|
714
|
+
/* small is minimal except that the value might be > p */
|
715
|
+
|
716
|
+
all_equal_so_far--;
|
717
|
+
/* We are doing a constant time test if out >= kPrime. We need to compare
|
718
|
+
* each u64, from most-significant to least significant. For each one, if
|
719
|
+
* all words so far have been equal (m is all ones) then a non-equal
|
720
|
+
* result is the answer. Otherwise we continue. */
|
721
|
+
for (size_t i = 3; i < 4; i--) {
|
722
|
+
u64 equal;
|
723
|
+
uint128_t a = ((uint128_t)kPrime[i]) - out[i];
|
724
|
+
/* if out[i] > kPrime[i] then a will underflow and the high 64-bits
|
725
|
+
* will all be set. */
|
726
|
+
result |= all_equal_so_far & ((u64)(a >> 64));
|
727
|
+
|
728
|
+
/* if kPrime[i] == out[i] then |equal| will be all zeros and the
|
729
|
+
* decrement will make it all ones. */
|
730
|
+
equal = kPrime[i] ^ out[i];
|
731
|
+
equal--;
|
732
|
+
equal &= equal << 32;
|
733
|
+
equal &= equal << 16;
|
734
|
+
equal &= equal << 8;
|
735
|
+
equal &= equal << 4;
|
736
|
+
equal &= equal << 2;
|
737
|
+
equal &= equal << 1;
|
738
|
+
equal = ((s64)equal) >> 63;
|
739
|
+
|
740
|
+
all_equal_so_far &= equal;
|
741
|
+
}
|
742
|
+
|
743
|
+
/* if all_equal_so_far is still all ones then the two values are equal
|
744
|
+
* and so out >= kPrime is true. */
|
745
|
+
result |= all_equal_so_far;
|
746
|
+
|
747
|
+
/* if out >= kPrime then we subtract kPrime. */
|
748
|
+
u64 carry;
|
749
|
+
subtract_u64(&out[0], &carry, result & kPrime[0]);
|
750
|
+
subtract_u64(&out[1], &carry, carry);
|
751
|
+
subtract_u64(&out[2], &carry, carry);
|
752
|
+
subtract_u64(&out[3], &carry, carry);
|
753
|
+
|
754
|
+
subtract_u64(&out[1], &carry, result & kPrime[1]);
|
755
|
+
subtract_u64(&out[2], &carry, carry);
|
756
|
+
subtract_u64(&out[3], &carry, carry);
|
757
|
+
|
758
|
+
subtract_u64(&out[2], &carry, result & kPrime[2]);
|
759
|
+
subtract_u64(&out[3], &carry, carry);
|
760
|
+
|
761
|
+
subtract_u64(&out[3], &carry, result & kPrime[3]);
|
762
|
+
}
|
763
|
+
|
764
|
+
/* felem_is_zero returns a limb with all bits set if |in| == 0 (mod p) and 0
|
765
|
+
* otherwise.
|
766
|
+
* On entry:
|
767
|
+
* small[i] < 2^64 */
|
768
|
+
static limb smallfelem_is_zero(const smallfelem small) {
|
769
|
+
limb result;
|
770
|
+
u64 is_p;
|
771
|
+
|
772
|
+
u64 is_zero = small[0] | small[1] | small[2] | small[3];
|
773
|
+
is_zero--;
|
774
|
+
is_zero &= is_zero << 32;
|
775
|
+
is_zero &= is_zero << 16;
|
776
|
+
is_zero &= is_zero << 8;
|
777
|
+
is_zero &= is_zero << 4;
|
778
|
+
is_zero &= is_zero << 2;
|
779
|
+
is_zero &= is_zero << 1;
|
780
|
+
is_zero = ((s64)is_zero) >> 63;
|
781
|
+
|
782
|
+
is_p = (small[0] ^ kPrime[0]) | (small[1] ^ kPrime[1]) |
|
783
|
+
(small[2] ^ kPrime[2]) | (small[3] ^ kPrime[3]);
|
784
|
+
is_p--;
|
785
|
+
is_p &= is_p << 32;
|
786
|
+
is_p &= is_p << 16;
|
787
|
+
is_p &= is_p << 8;
|
788
|
+
is_p &= is_p << 4;
|
789
|
+
is_p &= is_p << 2;
|
790
|
+
is_p &= is_p << 1;
|
791
|
+
is_p = ((s64)is_p) >> 63;
|
792
|
+
|
793
|
+
is_zero |= is_p;
|
794
|
+
|
795
|
+
result = is_zero;
|
796
|
+
result |= ((limb)is_zero) << 64;
|
797
|
+
return result;
|
798
|
+
}
|
799
|
+
|
800
|
+
/* felem_inv calculates |out| = |in|^{-1}
|
801
|
+
*
|
802
|
+
* Based on Fermat's Little Theorem:
|
803
|
+
* a^p = a (mod p)
|
804
|
+
* a^{p-1} = 1 (mod p)
|
805
|
+
* a^{p-2} = a^{-1} (mod p) */
|
806
|
+
static void felem_inv(felem out, const felem in) {
|
807
|
+
felem ftmp, ftmp2;
|
808
|
+
/* each e_I will hold |in|^{2^I - 1} */
|
809
|
+
felem e2, e4, e8, e16, e32, e64;
|
810
|
+
longfelem tmp;
|
811
|
+
|
812
|
+
felem_square(tmp, in);
|
813
|
+
felem_reduce(ftmp, tmp); /* 2^1 */
|
814
|
+
felem_mul(tmp, in, ftmp);
|
815
|
+
felem_reduce(ftmp, tmp); /* 2^2 - 2^0 */
|
816
|
+
felem_assign(e2, ftmp);
|
817
|
+
felem_square(tmp, ftmp);
|
818
|
+
felem_reduce(ftmp, tmp); /* 2^3 - 2^1 */
|
819
|
+
felem_square(tmp, ftmp);
|
820
|
+
felem_reduce(ftmp, tmp); /* 2^4 - 2^2 */
|
821
|
+
felem_mul(tmp, ftmp, e2);
|
822
|
+
felem_reduce(ftmp, tmp); /* 2^4 - 2^0 */
|
823
|
+
felem_assign(e4, ftmp);
|
824
|
+
felem_square(tmp, ftmp);
|
825
|
+
felem_reduce(ftmp, tmp); /* 2^5 - 2^1 */
|
826
|
+
felem_square(tmp, ftmp);
|
827
|
+
felem_reduce(ftmp, tmp); /* 2^6 - 2^2 */
|
828
|
+
felem_square(tmp, ftmp);
|
829
|
+
felem_reduce(ftmp, tmp); /* 2^7 - 2^3 */
|
830
|
+
felem_square(tmp, ftmp);
|
831
|
+
felem_reduce(ftmp, tmp); /* 2^8 - 2^4 */
|
832
|
+
felem_mul(tmp, ftmp, e4);
|
833
|
+
felem_reduce(ftmp, tmp); /* 2^8 - 2^0 */
|
834
|
+
felem_assign(e8, ftmp);
|
835
|
+
for (size_t i = 0; i < 8; i++) {
|
836
|
+
felem_square(tmp, ftmp);
|
837
|
+
felem_reduce(ftmp, tmp);
|
838
|
+
} /* 2^16 - 2^8 */
|
839
|
+
felem_mul(tmp, ftmp, e8);
|
840
|
+
felem_reduce(ftmp, tmp); /* 2^16 - 2^0 */
|
841
|
+
felem_assign(e16, ftmp);
|
842
|
+
for (size_t i = 0; i < 16; i++) {
|
843
|
+
felem_square(tmp, ftmp);
|
844
|
+
felem_reduce(ftmp, tmp);
|
845
|
+
} /* 2^32 - 2^16 */
|
846
|
+
felem_mul(tmp, ftmp, e16);
|
847
|
+
felem_reduce(ftmp, tmp); /* 2^32 - 2^0 */
|
848
|
+
felem_assign(e32, ftmp);
|
849
|
+
for (size_t i = 0; i < 32; i++) {
|
850
|
+
felem_square(tmp, ftmp);
|
851
|
+
felem_reduce(ftmp, tmp);
|
852
|
+
} /* 2^64 - 2^32 */
|
853
|
+
felem_assign(e64, ftmp);
|
854
|
+
felem_mul(tmp, ftmp, in);
|
855
|
+
felem_reduce(ftmp, tmp); /* 2^64 - 2^32 + 2^0 */
|
856
|
+
for (size_t i = 0; i < 192; i++) {
|
857
|
+
felem_square(tmp, ftmp);
|
858
|
+
felem_reduce(ftmp, tmp);
|
859
|
+
} /* 2^256 - 2^224 + 2^192 */
|
860
|
+
|
861
|
+
felem_mul(tmp, e64, e32);
|
862
|
+
felem_reduce(ftmp2, tmp); /* 2^64 - 2^0 */
|
863
|
+
for (size_t i = 0; i < 16; i++) {
|
864
|
+
felem_square(tmp, ftmp2);
|
865
|
+
felem_reduce(ftmp2, tmp);
|
866
|
+
} /* 2^80 - 2^16 */
|
867
|
+
felem_mul(tmp, ftmp2, e16);
|
868
|
+
felem_reduce(ftmp2, tmp); /* 2^80 - 2^0 */
|
869
|
+
for (size_t i = 0; i < 8; i++) {
|
870
|
+
felem_square(tmp, ftmp2);
|
871
|
+
felem_reduce(ftmp2, tmp);
|
872
|
+
} /* 2^88 - 2^8 */
|
873
|
+
felem_mul(tmp, ftmp2, e8);
|
874
|
+
felem_reduce(ftmp2, tmp); /* 2^88 - 2^0 */
|
875
|
+
for (size_t i = 0; i < 4; i++) {
|
876
|
+
felem_square(tmp, ftmp2);
|
877
|
+
felem_reduce(ftmp2, tmp);
|
878
|
+
} /* 2^92 - 2^4 */
|
879
|
+
felem_mul(tmp, ftmp2, e4);
|
880
|
+
felem_reduce(ftmp2, tmp); /* 2^92 - 2^0 */
|
881
|
+
felem_square(tmp, ftmp2);
|
882
|
+
felem_reduce(ftmp2, tmp); /* 2^93 - 2^1 */
|
883
|
+
felem_square(tmp, ftmp2);
|
884
|
+
felem_reduce(ftmp2, tmp); /* 2^94 - 2^2 */
|
885
|
+
felem_mul(tmp, ftmp2, e2);
|
886
|
+
felem_reduce(ftmp2, tmp); /* 2^94 - 2^0 */
|
887
|
+
felem_square(tmp, ftmp2);
|
888
|
+
felem_reduce(ftmp2, tmp); /* 2^95 - 2^1 */
|
889
|
+
felem_square(tmp, ftmp2);
|
890
|
+
felem_reduce(ftmp2, tmp); /* 2^96 - 2^2 */
|
891
|
+
felem_mul(tmp, ftmp2, in);
|
892
|
+
felem_reduce(ftmp2, tmp); /* 2^96 - 3 */
|
893
|
+
|
894
|
+
felem_mul(tmp, ftmp2, ftmp);
|
895
|
+
felem_reduce(out, tmp); /* 2^256 - 2^224 + 2^192 + 2^96 - 3 */
|
896
|
+
}
|
897
|
+
|
898
|
+
/* Group operations
|
899
|
+
* ----------------
|
900
|
+
*
|
901
|
+
* Building on top of the field operations we have the operations on the
|
902
|
+
* elliptic curve group itself. Points on the curve are represented in Jacobian
|
903
|
+
* coordinates. */
|
904
|
+
|
905
|
+
/* point_double calculates 2*(x_in, y_in, z_in)
|
906
|
+
*
|
907
|
+
* The method is taken from:
|
908
|
+
* http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
|
909
|
+
*
|
910
|
+
* Outputs can equal corresponding inputs, i.e., x_out == x_in is allowed.
|
911
|
+
* while x_out == y_in is not (maybe this works, but it's not tested). */
|
912
|
+
static void point_double(felem x_out, felem y_out, felem z_out,
|
913
|
+
const felem x_in, const felem y_in, const felem z_in) {
|
914
|
+
longfelem tmp, tmp2;
|
915
|
+
felem delta, gamma, beta, alpha, ftmp, ftmp2;
|
916
|
+
smallfelem small1, small2;
|
917
|
+
|
918
|
+
felem_assign(ftmp, x_in);
|
919
|
+
/* ftmp[i] < 2^106 */
|
920
|
+
felem_assign(ftmp2, x_in);
|
921
|
+
/* ftmp2[i] < 2^106 */
|
922
|
+
|
923
|
+
/* delta = z^2 */
|
924
|
+
felem_square(tmp, z_in);
|
925
|
+
felem_reduce(delta, tmp);
|
926
|
+
/* delta[i] < 2^101 */
|
927
|
+
|
928
|
+
/* gamma = y^2 */
|
929
|
+
felem_square(tmp, y_in);
|
930
|
+
felem_reduce(gamma, tmp);
|
931
|
+
/* gamma[i] < 2^101 */
|
932
|
+
felem_shrink(small1, gamma);
|
933
|
+
|
934
|
+
/* beta = x*gamma */
|
935
|
+
felem_small_mul(tmp, small1, x_in);
|
936
|
+
felem_reduce(beta, tmp);
|
937
|
+
/* beta[i] < 2^101 */
|
938
|
+
|
939
|
+
/* alpha = 3*(x-delta)*(x+delta) */
|
940
|
+
felem_diff(ftmp, delta);
|
941
|
+
/* ftmp[i] < 2^105 + 2^106 < 2^107 */
|
942
|
+
felem_sum(ftmp2, delta);
|
943
|
+
/* ftmp2[i] < 2^105 + 2^106 < 2^107 */
|
944
|
+
felem_scalar(ftmp2, 3);
|
945
|
+
/* ftmp2[i] < 3 * 2^107 < 2^109 */
|
946
|
+
felem_mul(tmp, ftmp, ftmp2);
|
947
|
+
felem_reduce(alpha, tmp);
|
948
|
+
/* alpha[i] < 2^101 */
|
949
|
+
felem_shrink(small2, alpha);
|
950
|
+
|
951
|
+
/* x' = alpha^2 - 8*beta */
|
952
|
+
smallfelem_square(tmp, small2);
|
953
|
+
felem_reduce(x_out, tmp);
|
954
|
+
felem_assign(ftmp, beta);
|
955
|
+
felem_scalar(ftmp, 8);
|
956
|
+
/* ftmp[i] < 8 * 2^101 = 2^104 */
|
957
|
+
felem_diff(x_out, ftmp);
|
958
|
+
/* x_out[i] < 2^105 + 2^101 < 2^106 */
|
959
|
+
|
960
|
+
/* z' = (y + z)^2 - gamma - delta */
|
961
|
+
felem_sum(delta, gamma);
|
962
|
+
/* delta[i] < 2^101 + 2^101 = 2^102 */
|
963
|
+
felem_assign(ftmp, y_in);
|
964
|
+
felem_sum(ftmp, z_in);
|
965
|
+
/* ftmp[i] < 2^106 + 2^106 = 2^107 */
|
966
|
+
felem_square(tmp, ftmp);
|
967
|
+
felem_reduce(z_out, tmp);
|
968
|
+
felem_diff(z_out, delta);
|
969
|
+
/* z_out[i] < 2^105 + 2^101 < 2^106 */
|
970
|
+
|
971
|
+
/* y' = alpha*(4*beta - x') - 8*gamma^2 */
|
972
|
+
felem_scalar(beta, 4);
|
973
|
+
/* beta[i] < 4 * 2^101 = 2^103 */
|
974
|
+
felem_diff_zero107(beta, x_out);
|
975
|
+
/* beta[i] < 2^107 + 2^103 < 2^108 */
|
976
|
+
felem_small_mul(tmp, small2, beta);
|
977
|
+
/* tmp[i] < 7 * 2^64 < 2^67 */
|
978
|
+
smallfelem_square(tmp2, small1);
|
979
|
+
/* tmp2[i] < 7 * 2^64 */
|
980
|
+
longfelem_scalar(tmp2, 8);
|
981
|
+
/* tmp2[i] < 8 * 7 * 2^64 = 7 * 2^67 */
|
982
|
+
longfelem_diff(tmp, tmp2);
|
983
|
+
/* tmp[i] < 2^67 + 2^70 + 2^40 < 2^71 */
|
984
|
+
felem_reduce_zero105(y_out, tmp);
|
985
|
+
/* y_out[i] < 2^106 */
|
986
|
+
}
|
987
|
+
|
988
|
+
/* point_double_small is the same as point_double, except that it operates on
|
989
|
+
* smallfelems. */
|
990
|
+
static void point_double_small(smallfelem x_out, smallfelem y_out,
|
991
|
+
smallfelem z_out, const smallfelem x_in,
|
992
|
+
const smallfelem y_in, const smallfelem z_in) {
|
993
|
+
felem felem_x_out, felem_y_out, felem_z_out;
|
994
|
+
felem felem_x_in, felem_y_in, felem_z_in;
|
995
|
+
|
996
|
+
smallfelem_expand(felem_x_in, x_in);
|
997
|
+
smallfelem_expand(felem_y_in, y_in);
|
998
|
+
smallfelem_expand(felem_z_in, z_in);
|
999
|
+
point_double(felem_x_out, felem_y_out, felem_z_out, felem_x_in, felem_y_in,
|
1000
|
+
felem_z_in);
|
1001
|
+
felem_shrink(x_out, felem_x_out);
|
1002
|
+
felem_shrink(y_out, felem_y_out);
|
1003
|
+
felem_shrink(z_out, felem_z_out);
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
/* copy_conditional copies in to out iff mask is all ones. */
|
1007
|
+
static void copy_conditional(felem out, const felem in, limb mask) {
|
1008
|
+
for (size_t i = 0; i < NLIMBS; ++i) {
|
1009
|
+
const limb tmp = mask & (in[i] ^ out[i]);
|
1010
|
+
out[i] ^= tmp;
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
/* copy_small_conditional copies in to out iff mask is all ones. */
|
1015
|
+
static void copy_small_conditional(felem out, const smallfelem in, limb mask) {
|
1016
|
+
const u64 mask64 = mask;
|
1017
|
+
for (size_t i = 0; i < NLIMBS; ++i) {
|
1018
|
+
out[i] = ((limb)(in[i] & mask64)) | (out[i] & ~mask);
|
1019
|
+
}
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
/* point_add calcuates (x1, y1, z1) + (x2, y2, z2)
|
1023
|
+
*
|
1024
|
+
* The method is taken from:
|
1025
|
+
* http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-2007-bl,
|
1026
|
+
* adapted for mixed addition (z2 = 1, or z2 = 0 for the point at infinity).
|
1027
|
+
*
|
1028
|
+
* This function includes a branch for checking whether the two input points
|
1029
|
+
* are equal, (while not equal to the point at infinity). This case never
|
1030
|
+
* happens during single point multiplication, so there is no timing leak for
|
1031
|
+
* ECDH or ECDSA signing. */
|
1032
|
+
static void point_add(felem x3, felem y3, felem z3, const felem x1,
|
1033
|
+
const felem y1, const felem z1, const int mixed,
|
1034
|
+
const smallfelem x2, const smallfelem y2,
|
1035
|
+
const smallfelem z2) {
|
1036
|
+
felem ftmp, ftmp2, ftmp3, ftmp4, ftmp5, ftmp6, x_out, y_out, z_out;
|
1037
|
+
longfelem tmp, tmp2;
|
1038
|
+
smallfelem small1, small2, small3, small4, small5;
|
1039
|
+
limb x_equal, y_equal, z1_is_zero, z2_is_zero;
|
1040
|
+
|
1041
|
+
felem_shrink(small3, z1);
|
1042
|
+
|
1043
|
+
z1_is_zero = smallfelem_is_zero(small3);
|
1044
|
+
z2_is_zero = smallfelem_is_zero(z2);
|
1045
|
+
|
1046
|
+
/* ftmp = z1z1 = z1**2 */
|
1047
|
+
smallfelem_square(tmp, small3);
|
1048
|
+
felem_reduce(ftmp, tmp);
|
1049
|
+
/* ftmp[i] < 2^101 */
|
1050
|
+
felem_shrink(small1, ftmp);
|
1051
|
+
|
1052
|
+
if (!mixed) {
|
1053
|
+
/* ftmp2 = z2z2 = z2**2 */
|
1054
|
+
smallfelem_square(tmp, z2);
|
1055
|
+
felem_reduce(ftmp2, tmp);
|
1056
|
+
/* ftmp2[i] < 2^101 */
|
1057
|
+
felem_shrink(small2, ftmp2);
|
1058
|
+
|
1059
|
+
felem_shrink(small5, x1);
|
1060
|
+
|
1061
|
+
/* u1 = ftmp3 = x1*z2z2 */
|
1062
|
+
smallfelem_mul(tmp, small5, small2);
|
1063
|
+
felem_reduce(ftmp3, tmp);
|
1064
|
+
/* ftmp3[i] < 2^101 */
|
1065
|
+
|
1066
|
+
/* ftmp5 = z1 + z2 */
|
1067
|
+
felem_assign(ftmp5, z1);
|
1068
|
+
felem_small_sum(ftmp5, z2);
|
1069
|
+
/* ftmp5[i] < 2^107 */
|
1070
|
+
|
1071
|
+
/* ftmp5 = (z1 + z2)**2 - (z1z1 + z2z2) = 2z1z2 */
|
1072
|
+
felem_square(tmp, ftmp5);
|
1073
|
+
felem_reduce(ftmp5, tmp);
|
1074
|
+
/* ftmp2 = z2z2 + z1z1 */
|
1075
|
+
felem_sum(ftmp2, ftmp);
|
1076
|
+
/* ftmp2[i] < 2^101 + 2^101 = 2^102 */
|
1077
|
+
felem_diff(ftmp5, ftmp2);
|
1078
|
+
/* ftmp5[i] < 2^105 + 2^101 < 2^106 */
|
1079
|
+
|
1080
|
+
/* ftmp2 = z2 * z2z2 */
|
1081
|
+
smallfelem_mul(tmp, small2, z2);
|
1082
|
+
felem_reduce(ftmp2, tmp);
|
1083
|
+
|
1084
|
+
/* s1 = ftmp2 = y1 * z2**3 */
|
1085
|
+
felem_mul(tmp, y1, ftmp2);
|
1086
|
+
felem_reduce(ftmp6, tmp);
|
1087
|
+
/* ftmp6[i] < 2^101 */
|
1088
|
+
} else {
|
1089
|
+
/* We'll assume z2 = 1 (special case z2 = 0 is handled later). */
|
1090
|
+
|
1091
|
+
/* u1 = ftmp3 = x1*z2z2 */
|
1092
|
+
felem_assign(ftmp3, x1);
|
1093
|
+
/* ftmp3[i] < 2^106 */
|
1094
|
+
|
1095
|
+
/* ftmp5 = 2z1z2 */
|
1096
|
+
felem_assign(ftmp5, z1);
|
1097
|
+
felem_scalar(ftmp5, 2);
|
1098
|
+
/* ftmp5[i] < 2*2^106 = 2^107 */
|
1099
|
+
|
1100
|
+
/* s1 = ftmp2 = y1 * z2**3 */
|
1101
|
+
felem_assign(ftmp6, y1);
|
1102
|
+
/* ftmp6[i] < 2^106 */
|
1103
|
+
}
|
1104
|
+
|
1105
|
+
/* u2 = x2*z1z1 */
|
1106
|
+
smallfelem_mul(tmp, x2, small1);
|
1107
|
+
felem_reduce(ftmp4, tmp);
|
1108
|
+
|
1109
|
+
/* h = ftmp4 = u2 - u1 */
|
1110
|
+
felem_diff_zero107(ftmp4, ftmp3);
|
1111
|
+
/* ftmp4[i] < 2^107 + 2^101 < 2^108 */
|
1112
|
+
felem_shrink(small4, ftmp4);
|
1113
|
+
|
1114
|
+
x_equal = smallfelem_is_zero(small4);
|
1115
|
+
|
1116
|
+
/* z_out = ftmp5 * h */
|
1117
|
+
felem_small_mul(tmp, small4, ftmp5);
|
1118
|
+
felem_reduce(z_out, tmp);
|
1119
|
+
/* z_out[i] < 2^101 */
|
1120
|
+
|
1121
|
+
/* ftmp = z1 * z1z1 */
|
1122
|
+
smallfelem_mul(tmp, small1, small3);
|
1123
|
+
felem_reduce(ftmp, tmp);
|
1124
|
+
|
1125
|
+
/* s2 = tmp = y2 * z1**3 */
|
1126
|
+
felem_small_mul(tmp, y2, ftmp);
|
1127
|
+
felem_reduce(ftmp5, tmp);
|
1128
|
+
|
1129
|
+
/* r = ftmp5 = (s2 - s1)*2 */
|
1130
|
+
felem_diff_zero107(ftmp5, ftmp6);
|
1131
|
+
/* ftmp5[i] < 2^107 + 2^107 = 2^108 */
|
1132
|
+
felem_scalar(ftmp5, 2);
|
1133
|
+
/* ftmp5[i] < 2^109 */
|
1134
|
+
felem_shrink(small1, ftmp5);
|
1135
|
+
y_equal = smallfelem_is_zero(small1);
|
1136
|
+
|
1137
|
+
if (x_equal && y_equal && !z1_is_zero && !z2_is_zero) {
|
1138
|
+
point_double(x3, y3, z3, x1, y1, z1);
|
1139
|
+
return;
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
/* I = ftmp = (2h)**2 */
|
1143
|
+
felem_assign(ftmp, ftmp4);
|
1144
|
+
felem_scalar(ftmp, 2);
|
1145
|
+
/* ftmp[i] < 2*2^108 = 2^109 */
|
1146
|
+
felem_square(tmp, ftmp);
|
1147
|
+
felem_reduce(ftmp, tmp);
|
1148
|
+
|
1149
|
+
/* J = ftmp2 = h * I */
|
1150
|
+
felem_mul(tmp, ftmp4, ftmp);
|
1151
|
+
felem_reduce(ftmp2, tmp);
|
1152
|
+
|
1153
|
+
/* V = ftmp4 = U1 * I */
|
1154
|
+
felem_mul(tmp, ftmp3, ftmp);
|
1155
|
+
felem_reduce(ftmp4, tmp);
|
1156
|
+
|
1157
|
+
/* x_out = r**2 - J - 2V */
|
1158
|
+
smallfelem_square(tmp, small1);
|
1159
|
+
felem_reduce(x_out, tmp);
|
1160
|
+
felem_assign(ftmp3, ftmp4);
|
1161
|
+
felem_scalar(ftmp4, 2);
|
1162
|
+
felem_sum(ftmp4, ftmp2);
|
1163
|
+
/* ftmp4[i] < 2*2^101 + 2^101 < 2^103 */
|
1164
|
+
felem_diff(x_out, ftmp4);
|
1165
|
+
/* x_out[i] < 2^105 + 2^101 */
|
1166
|
+
|
1167
|
+
/* y_out = r(V-x_out) - 2 * s1 * J */
|
1168
|
+
felem_diff_zero107(ftmp3, x_out);
|
1169
|
+
/* ftmp3[i] < 2^107 + 2^101 < 2^108 */
|
1170
|
+
felem_small_mul(tmp, small1, ftmp3);
|
1171
|
+
felem_mul(tmp2, ftmp6, ftmp2);
|
1172
|
+
longfelem_scalar(tmp2, 2);
|
1173
|
+
/* tmp2[i] < 2*2^67 = 2^68 */
|
1174
|
+
longfelem_diff(tmp, tmp2);
|
1175
|
+
/* tmp[i] < 2^67 + 2^70 + 2^40 < 2^71 */
|
1176
|
+
felem_reduce_zero105(y_out, tmp);
|
1177
|
+
/* y_out[i] < 2^106 */
|
1178
|
+
|
1179
|
+
copy_small_conditional(x_out, x2, z1_is_zero);
|
1180
|
+
copy_conditional(x_out, x1, z2_is_zero);
|
1181
|
+
copy_small_conditional(y_out, y2, z1_is_zero);
|
1182
|
+
copy_conditional(y_out, y1, z2_is_zero);
|
1183
|
+
copy_small_conditional(z_out, z2, z1_is_zero);
|
1184
|
+
copy_conditional(z_out, z1, z2_is_zero);
|
1185
|
+
felem_assign(x3, x_out);
|
1186
|
+
felem_assign(y3, y_out);
|
1187
|
+
felem_assign(z3, z_out);
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
/* point_add_small is the same as point_add, except that it operates on
|
1191
|
+
* smallfelems. */
|
1192
|
+
static void point_add_small(smallfelem x3, smallfelem y3, smallfelem z3,
|
1193
|
+
smallfelem x1, smallfelem y1, smallfelem z1,
|
1194
|
+
smallfelem x2, smallfelem y2, smallfelem z2) {
|
1195
|
+
felem felem_x3, felem_y3, felem_z3;
|
1196
|
+
felem felem_x1, felem_y1, felem_z1;
|
1197
|
+
smallfelem_expand(felem_x1, x1);
|
1198
|
+
smallfelem_expand(felem_y1, y1);
|
1199
|
+
smallfelem_expand(felem_z1, z1);
|
1200
|
+
point_add(felem_x3, felem_y3, felem_z3, felem_x1, felem_y1, felem_z1, 0, x2,
|
1201
|
+
y2, z2);
|
1202
|
+
felem_shrink(x3, felem_x3);
|
1203
|
+
felem_shrink(y3, felem_y3);
|
1204
|
+
felem_shrink(z3, felem_z3);
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
/* Base point pre computation
|
1208
|
+
* --------------------------
|
1209
|
+
*
|
1210
|
+
* Two different sorts of precomputed tables are used in the following code.
|
1211
|
+
* Each contain various points on the curve, where each point is three field
|
1212
|
+
* elements (x, y, z).
|
1213
|
+
*
|
1214
|
+
* For the base point table, z is usually 1 (0 for the point at infinity).
|
1215
|
+
* This table has 2 * 16 elements, starting with the following:
|
1216
|
+
* index | bits | point
|
1217
|
+
* ------+---------+------------------------------
|
1218
|
+
* 0 | 0 0 0 0 | 0G
|
1219
|
+
* 1 | 0 0 0 1 | 1G
|
1220
|
+
* 2 | 0 0 1 0 | 2^64G
|
1221
|
+
* 3 | 0 0 1 1 | (2^64 + 1)G
|
1222
|
+
* 4 | 0 1 0 0 | 2^128G
|
1223
|
+
* 5 | 0 1 0 1 | (2^128 + 1)G
|
1224
|
+
* 6 | 0 1 1 0 | (2^128 + 2^64)G
|
1225
|
+
* 7 | 0 1 1 1 | (2^128 + 2^64 + 1)G
|
1226
|
+
* 8 | 1 0 0 0 | 2^192G
|
1227
|
+
* 9 | 1 0 0 1 | (2^192 + 1)G
|
1228
|
+
* 10 | 1 0 1 0 | (2^192 + 2^64)G
|
1229
|
+
* 11 | 1 0 1 1 | (2^192 + 2^64 + 1)G
|
1230
|
+
* 12 | 1 1 0 0 | (2^192 + 2^128)G
|
1231
|
+
* 13 | 1 1 0 1 | (2^192 + 2^128 + 1)G
|
1232
|
+
* 14 | 1 1 1 0 | (2^192 + 2^128 + 2^64)G
|
1233
|
+
* 15 | 1 1 1 1 | (2^192 + 2^128 + 2^64 + 1)G
|
1234
|
+
* followed by a copy of this with each element multiplied by 2^32.
|
1235
|
+
*
|
1236
|
+
* The reason for this is so that we can clock bits into four different
|
1237
|
+
* locations when doing simple scalar multiplies against the base point,
|
1238
|
+
* and then another four locations using the second 16 elements.
|
1239
|
+
*
|
1240
|
+
* Tables for other points have table[i] = iG for i in 0 .. 16. */
|
1241
|
+
|
1242
|
+
/* g_pre_comp is the table of precomputed base points */
|
1243
|
+
static const smallfelem g_pre_comp[2][16][3] = {
|
1244
|
+
{{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
|
1245
|
+
{{0xf4a13945d898c296, 0x77037d812deb33a0, 0xf8bce6e563a440f2,
|
1246
|
+
0x6b17d1f2e12c4247},
|
1247
|
+
{0xcbb6406837bf51f5, 0x2bce33576b315ece, 0x8ee7eb4a7c0f9e16,
|
1248
|
+
0x4fe342e2fe1a7f9b},
|
1249
|
+
{1, 0, 0, 0}},
|
1250
|
+
{{0x90e75cb48e14db63, 0x29493baaad651f7e, 0x8492592e326e25de,
|
1251
|
+
0x0fa822bc2811aaa5},
|
1252
|
+
{0xe41124545f462ee7, 0x34b1a65050fe82f5, 0x6f4ad4bcb3df188b,
|
1253
|
+
0xbff44ae8f5dba80d},
|
1254
|
+
{1, 0, 0, 0}},
|
1255
|
+
{{0x93391ce2097992af, 0xe96c98fd0d35f1fa, 0xb257c0de95e02789,
|
1256
|
+
0x300a4bbc89d6726f},
|
1257
|
+
{0xaa54a291c08127a0, 0x5bb1eeada9d806a5, 0x7f1ddb25ff1e3c6f,
|
1258
|
+
0x72aac7e0d09b4644},
|
1259
|
+
{1, 0, 0, 0}},
|
1260
|
+
{{0x57c84fc9d789bd85, 0xfc35ff7dc297eac3, 0xfb982fd588c6766e,
|
1261
|
+
0x447d739beedb5e67},
|
1262
|
+
{0x0c7e33c972e25b32, 0x3d349b95a7fae500, 0xe12e9d953a4aaff7,
|
1263
|
+
0x2d4825ab834131ee},
|
1264
|
+
{1, 0, 0, 0}},
|
1265
|
+
{{0x13949c932a1d367f, 0xef7fbd2b1a0a11b7, 0xddc6068bb91dfc60,
|
1266
|
+
0xef9519328a9c72ff},
|
1267
|
+
{0x196035a77376d8a8, 0x23183b0895ca1740, 0xc1ee9807022c219c,
|
1268
|
+
0x611e9fc37dbb2c9b},
|
1269
|
+
{1, 0, 0, 0}},
|
1270
|
+
{{0xcae2b1920b57f4bc, 0x2936df5ec6c9bc36, 0x7dea6482e11238bf,
|
1271
|
+
0x550663797b51f5d8},
|
1272
|
+
{0x44ffe216348a964c, 0x9fb3d576dbdefbe1, 0x0afa40018d9d50e5,
|
1273
|
+
0x157164848aecb851},
|
1274
|
+
{1, 0, 0, 0}},
|
1275
|
+
{{0xe48ecafffc5cde01, 0x7ccd84e70d715f26, 0xa2e8f483f43e4391,
|
1276
|
+
0xeb5d7745b21141ea},
|
1277
|
+
{0xcac917e2731a3479, 0x85f22cfe2844b645, 0x0990e6a158006cee,
|
1278
|
+
0xeafd72ebdbecc17b},
|
1279
|
+
{1, 0, 0, 0}},
|
1280
|
+
{{0x6cf20ffb313728be, 0x96439591a3c6b94a, 0x2736ff8344315fc5,
|
1281
|
+
0xa6d39677a7849276},
|
1282
|
+
{0xf2bab833c357f5f4, 0x824a920c2284059b, 0x66b8babd2d27ecdf,
|
1283
|
+
0x674f84749b0b8816},
|
1284
|
+
{1, 0, 0, 0}},
|
1285
|
+
{{0x2df48c04677c8a3e, 0x74e02f080203a56b, 0x31855f7db8c7fedb,
|
1286
|
+
0x4e769e7672c9ddad},
|
1287
|
+
{0xa4c36165b824bbb0, 0xfb9ae16f3b9122a5, 0x1ec0057206947281,
|
1288
|
+
0x42b99082de830663},
|
1289
|
+
{1, 0, 0, 0}},
|
1290
|
+
{{0x6ef95150dda868b9, 0xd1f89e799c0ce131, 0x7fdc1ca008a1c478,
|
1291
|
+
0x78878ef61c6ce04d},
|
1292
|
+
{0x9c62b9121fe0d976, 0x6ace570ebde08d4f, 0xde53142c12309def,
|
1293
|
+
0xb6cb3f5d7b72c321},
|
1294
|
+
{1, 0, 0, 0}},
|
1295
|
+
{{0x7f991ed2c31a3573, 0x5b82dd5bd54fb496, 0x595c5220812ffcae,
|
1296
|
+
0x0c88bc4d716b1287},
|
1297
|
+
{0x3a57bf635f48aca8, 0x7c8181f4df2564f3, 0x18d1b5b39c04e6aa,
|
1298
|
+
0xdd5ddea3f3901dc6},
|
1299
|
+
{1, 0, 0, 0}},
|
1300
|
+
{{0xe96a79fb3e72ad0c, 0x43a0a28c42ba792f, 0xefe0a423083e49f3,
|
1301
|
+
0x68f344af6b317466},
|
1302
|
+
{0xcdfe17db3fb24d4a, 0x668bfc2271f5c626, 0x604ed93c24d67ff3,
|
1303
|
+
0x31b9c405f8540a20},
|
1304
|
+
{1, 0, 0, 0}},
|
1305
|
+
{{0xd36b4789a2582e7f, 0x0d1a10144ec39c28, 0x663c62c3edbad7a0,
|
1306
|
+
0x4052bf4b6f461db9},
|
1307
|
+
{0x235a27c3188d25eb, 0xe724f33999bfcc5b, 0x862be6bd71d70cc8,
|
1308
|
+
0xfecf4d5190b0fc61},
|
1309
|
+
{1, 0, 0, 0}},
|
1310
|
+
{{0x74346c10a1d4cfac, 0xafdf5cc08526a7a4, 0x123202a8f62bff7a,
|
1311
|
+
0x1eddbae2c802e41a},
|
1312
|
+
{0x8fa0af2dd603f844, 0x36e06b7e4c701917, 0x0c45f45273db33a0,
|
1313
|
+
0x43104d86560ebcfc},
|
1314
|
+
{1, 0, 0, 0}},
|
1315
|
+
{{0x9615b5110d1d78e5, 0x66b0de3225c4744b, 0x0a4a46fb6aaf363a,
|
1316
|
+
0xb48e26b484f7a21c},
|
1317
|
+
{0x06ebb0f621a01b2d, 0xc004e4048b7b0f98, 0x64131bcdfed6f668,
|
1318
|
+
0xfac015404d4d3dab},
|
1319
|
+
{1, 0, 0, 0}}},
|
1320
|
+
{{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
|
1321
|
+
{{0x3a5a9e22185a5943, 0x1ab919365c65dfb6, 0x21656b32262c71da,
|
1322
|
+
0x7fe36b40af22af89},
|
1323
|
+
{0xd50d152c699ca101, 0x74b3d5867b8af212, 0x9f09f40407dca6f1,
|
1324
|
+
0xe697d45825b63624},
|
1325
|
+
{1, 0, 0, 0}},
|
1326
|
+
{{0xa84aa9397512218e, 0xe9a521b074ca0141, 0x57880b3a18a2e902,
|
1327
|
+
0x4a5b506612a677a6},
|
1328
|
+
{0x0beada7a4c4f3840, 0x626db15419e26d9d, 0xc42604fbe1627d40,
|
1329
|
+
0xeb13461ceac089f1},
|
1330
|
+
{1, 0, 0, 0}},
|
1331
|
+
{{0xf9faed0927a43281, 0x5e52c4144103ecbc, 0xc342967aa815c857,
|
1332
|
+
0x0781b8291c6a220a},
|
1333
|
+
{0x5a8343ceeac55f80, 0x88f80eeee54a05e3, 0x97b2a14f12916434,
|
1334
|
+
0x690cde8df0151593},
|
1335
|
+
{1, 0, 0, 0}},
|
1336
|
+
{{0xaee9c75df7f82f2a, 0x9e4c35874afdf43a, 0xf5622df437371326,
|
1337
|
+
0x8a535f566ec73617},
|
1338
|
+
{0xc5f9a0ac223094b7, 0xcde533864c8c7669, 0x37e02819085a92bf,
|
1339
|
+
0x0455c08468b08bd7},
|
1340
|
+
{1, 0, 0, 0}},
|
1341
|
+
{{0x0c0a6e2c9477b5d9, 0xf9a4bf62876dc444, 0x5050a949b6cdc279,
|
1342
|
+
0x06bada7ab77f8276},
|
1343
|
+
{0xc8b4aed1ea48dac9, 0xdebd8a4b7ea1070f, 0x427d49101366eb70,
|
1344
|
+
0x5b476dfd0e6cb18a},
|
1345
|
+
{1, 0, 0, 0}},
|
1346
|
+
{{0x7c5c3e44278c340a, 0x4d54606812d66f3b, 0x29a751b1ae23c5d8,
|
1347
|
+
0x3e29864e8a2ec908},
|
1348
|
+
{0x142d2a6626dbb850, 0xad1744c4765bd780, 0x1f150e68e322d1ed,
|
1349
|
+
0x239b90ea3dc31e7e},
|
1350
|
+
{1, 0, 0, 0}},
|
1351
|
+
{{0x78c416527a53322a, 0x305dde6709776f8e, 0xdbcab759f8862ed4,
|
1352
|
+
0x820f4dd949f72ff7},
|
1353
|
+
{0x6cc544a62b5debd4, 0x75be5d937b4e8cc4, 0x1b481b1b215c14d3,
|
1354
|
+
0x140406ec783a05ec},
|
1355
|
+
{1, 0, 0, 0}},
|
1356
|
+
{{0x6a703f10e895df07, 0xfd75f3fa01876bd8, 0xeb5b06e70ce08ffe,
|
1357
|
+
0x68f6b8542783dfee},
|
1358
|
+
{0x90c76f8a78712655, 0xcf5293d2f310bf7f, 0xfbc8044dfda45028,
|
1359
|
+
0xcbe1feba92e40ce6},
|
1360
|
+
{1, 0, 0, 0}},
|
1361
|
+
{{0xe998ceea4396e4c1, 0xfc82ef0b6acea274, 0x230f729f2250e927,
|
1362
|
+
0xd0b2f94d2f420109},
|
1363
|
+
{0x4305adddb38d4966, 0x10b838f8624c3b45, 0x7db2636658954e7a,
|
1364
|
+
0x971459828b0719e5},
|
1365
|
+
{1, 0, 0, 0}},
|
1366
|
+
{{0x4bd6b72623369fc9, 0x57f2929e53d0b876, 0xc2d5cba4f2340687,
|
1367
|
+
0x961610004a866aba},
|
1368
|
+
{0x49997bcd2e407a5e, 0x69ab197d92ddcb24, 0x2cf1f2438fe5131c,
|
1369
|
+
0x7acb9fadcee75e44},
|
1370
|
+
{1, 0, 0, 0}},
|
1371
|
+
{{0x254e839423d2d4c0, 0xf57f0c917aea685b, 0xa60d880f6f75aaea,
|
1372
|
+
0x24eb9acca333bf5b},
|
1373
|
+
{0xe3de4ccb1cda5dea, 0xfeef9341c51a6b4f, 0x743125f88bac4c4d,
|
1374
|
+
0x69f891c5acd079cc},
|
1375
|
+
{1, 0, 0, 0}},
|
1376
|
+
{{0xeee44b35702476b5, 0x7ed031a0e45c2258, 0xb422d1e7bd6f8514,
|
1377
|
+
0xe51f547c5972a107},
|
1378
|
+
{0xa25bcd6fc9cf343d, 0x8ca922ee097c184e, 0xa62f98b3a9fe9a06,
|
1379
|
+
0x1c309a2b25bb1387},
|
1380
|
+
{1, 0, 0, 0}},
|
1381
|
+
{{0x9295dbeb1967c459, 0xb00148833472c98e, 0xc504977708011828,
|
1382
|
+
0x20b87b8aa2c4e503},
|
1383
|
+
{0x3063175de057c277, 0x1bd539338fe582dd, 0x0d11adef5f69a044,
|
1384
|
+
0xf5c6fa49919776be},
|
1385
|
+
{1, 0, 0, 0}},
|
1386
|
+
{{0x8c944e760fd59e11, 0x3876cba1102fad5f, 0xa454c3fad83faa56,
|
1387
|
+
0x1ed7d1b9332010b9},
|
1388
|
+
{0xa1011a270024b889, 0x05e4d0dcac0cd344, 0x52b520f0eb6a2a24,
|
1389
|
+
0x3a2b03f03217257a},
|
1390
|
+
{1, 0, 0, 0}},
|
1391
|
+
{{0xf20fc2afdf1d043d, 0xf330240db58d5a62, 0xfc7d229ca0058c3b,
|
1392
|
+
0x15fee545c78dd9f6},
|
1393
|
+
{0x501e82885bc98cda, 0x41ef80e5d046ac04, 0x557d9f49461210fb,
|
1394
|
+
0x4ab5b6b2b8753f81},
|
1395
|
+
{1, 0, 0, 0}}}};
|
1396
|
+
|
1397
|
+
/* select_point selects the |idx|th point from a precomputation table and
|
1398
|
+
* copies it to out. */
|
1399
|
+
static void select_point(const u64 idx, size_t size,
|
1400
|
+
const smallfelem pre_comp[/*size*/][3],
|
1401
|
+
smallfelem out[3]) {
|
1402
|
+
u64 *outlimbs = &out[0][0];
|
1403
|
+
memset(outlimbs, 0, 3 * sizeof(smallfelem));
|
1404
|
+
|
1405
|
+
for (size_t i = 0; i < size; i++) {
|
1406
|
+
const u64 *inlimbs = (const u64 *)&pre_comp[i][0][0];
|
1407
|
+
u64 mask = i ^ idx;
|
1408
|
+
mask |= mask >> 4;
|
1409
|
+
mask |= mask >> 2;
|
1410
|
+
mask |= mask >> 1;
|
1411
|
+
mask &= 1;
|
1412
|
+
mask--;
|
1413
|
+
for (size_t j = 0; j < NLIMBS * 3; j++) {
|
1414
|
+
outlimbs[j] |= inlimbs[j] & mask;
|
1415
|
+
}
|
1416
|
+
}
|
1417
|
+
}
|
1418
|
+
|
1419
|
+
/* get_bit returns the |i|th bit in |in| */
|
1420
|
+
static char get_bit(const felem_bytearray in, int i) {
|
1421
|
+
if (i < 0 || i >= 256) {
|
1422
|
+
return 0;
|
1423
|
+
}
|
1424
|
+
return (in[i >> 3] >> (i & 7)) & 1;
|
1425
|
+
}
|
1426
|
+
|
1427
|
+
/* Interleaved point multiplication using precomputed point multiples: The
|
1428
|
+
* small point multiples 0*P, 1*P, ..., 17*P are in pre_comp[], the scalars
|
1429
|
+
* in scalars[]. If g_scalar is non-NULL, we also add this multiple of the
|
1430
|
+
* generator, using certain (large) precomputed multiples in g_pre_comp.
|
1431
|
+
* Output point (X, Y, Z) is stored in x_out, y_out, z_out. */
|
1432
|
+
static void batch_mul(felem x_out, felem y_out, felem z_out,
|
1433
|
+
const felem_bytearray scalars[],
|
1434
|
+
const size_t num_points, const u8 *g_scalar,
|
1435
|
+
const smallfelem pre_comp[][17][3]) {
|
1436
|
+
felem nq[3], ftmp;
|
1437
|
+
smallfelem tmp[3];
|
1438
|
+
u64 bits;
|
1439
|
+
u8 sign, digit;
|
1440
|
+
|
1441
|
+
/* set nq to the point at infinity */
|
1442
|
+
memset(nq, 0, 3 * sizeof(felem));
|
1443
|
+
|
1444
|
+
/* Loop over all scalars msb-to-lsb, interleaving additions of multiples
|
1445
|
+
* of the generator (two in each of the last 32 rounds) and additions of
|
1446
|
+
* other points multiples (every 5th round). */
|
1447
|
+
|
1448
|
+
int skip = 1; /* save two point operations in the first round */
|
1449
|
+
size_t i = num_points != 0 ? 255 : 31;
|
1450
|
+
for (;;) {
|
1451
|
+
/* double */
|
1452
|
+
if (!skip) {
|
1453
|
+
point_double(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2]);
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
/* add multiples of the generator */
|
1457
|
+
if (g_scalar != NULL && i <= 31) {
|
1458
|
+
/* first, look 32 bits upwards */
|
1459
|
+
bits = get_bit(g_scalar, i + 224) << 3;
|
1460
|
+
bits |= get_bit(g_scalar, i + 160) << 2;
|
1461
|
+
bits |= get_bit(g_scalar, i + 96) << 1;
|
1462
|
+
bits |= get_bit(g_scalar, i + 32);
|
1463
|
+
/* select the point to add, in constant time */
|
1464
|
+
select_point(bits, 16, g_pre_comp[1], tmp);
|
1465
|
+
|
1466
|
+
if (!skip) {
|
1467
|
+
point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 1 /* mixed */,
|
1468
|
+
tmp[0], tmp[1], tmp[2]);
|
1469
|
+
} else {
|
1470
|
+
smallfelem_expand(nq[0], tmp[0]);
|
1471
|
+
smallfelem_expand(nq[1], tmp[1]);
|
1472
|
+
smallfelem_expand(nq[2], tmp[2]);
|
1473
|
+
skip = 0;
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
/* second, look at the current position */
|
1477
|
+
bits = get_bit(g_scalar, i + 192) << 3;
|
1478
|
+
bits |= get_bit(g_scalar, i + 128) << 2;
|
1479
|
+
bits |= get_bit(g_scalar, i + 64) << 1;
|
1480
|
+
bits |= get_bit(g_scalar, i);
|
1481
|
+
/* select the point to add, in constant time */
|
1482
|
+
select_point(bits, 16, g_pre_comp[0], tmp);
|
1483
|
+
point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 1 /* mixed */, tmp[0],
|
1484
|
+
tmp[1], tmp[2]);
|
1485
|
+
}
|
1486
|
+
|
1487
|
+
/* do other additions every 5 doublings */
|
1488
|
+
if (num_points != 0 && i % 5 == 0) {
|
1489
|
+
/* loop over all scalars */
|
1490
|
+
size_t num;
|
1491
|
+
for (num = 0; num < num_points; ++num) {
|
1492
|
+
bits = get_bit(scalars[num], i + 4) << 5;
|
1493
|
+
bits |= get_bit(scalars[num], i + 3) << 4;
|
1494
|
+
bits |= get_bit(scalars[num], i + 2) << 3;
|
1495
|
+
bits |= get_bit(scalars[num], i + 1) << 2;
|
1496
|
+
bits |= get_bit(scalars[num], i) << 1;
|
1497
|
+
bits |= get_bit(scalars[num], i - 1);
|
1498
|
+
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, bits);
|
1499
|
+
|
1500
|
+
/* select the point to add or subtract, in constant time. */
|
1501
|
+
select_point(digit, 17, pre_comp[num], tmp);
|
1502
|
+
smallfelem_neg(ftmp, tmp[1]); /* (X, -Y, Z) is the negative
|
1503
|
+
* point */
|
1504
|
+
copy_small_conditional(ftmp, tmp[1], (((limb)sign) - 1));
|
1505
|
+
felem_contract(tmp[1], ftmp);
|
1506
|
+
|
1507
|
+
if (!skip) {
|
1508
|
+
point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 0 /* mixed */,
|
1509
|
+
tmp[0], tmp[1], tmp[2]);
|
1510
|
+
} else {
|
1511
|
+
smallfelem_expand(nq[0], tmp[0]);
|
1512
|
+
smallfelem_expand(nq[1], tmp[1]);
|
1513
|
+
smallfelem_expand(nq[2], tmp[2]);
|
1514
|
+
skip = 0;
|
1515
|
+
}
|
1516
|
+
}
|
1517
|
+
}
|
1518
|
+
|
1519
|
+
if (i == 0) {
|
1520
|
+
break;
|
1521
|
+
}
|
1522
|
+
--i;
|
1523
|
+
}
|
1524
|
+
felem_assign(x_out, nq[0]);
|
1525
|
+
felem_assign(y_out, nq[1]);
|
1526
|
+
felem_assign(z_out, nq[2]);
|
1527
|
+
}
|
1528
|
+
|
1529
|
+
/******************************************************************************/
|
1530
|
+
/*
|
1531
|
+
* OPENSSL EC_METHOD FUNCTIONS
|
1532
|
+
*/
|
1533
|
+
|
1534
|
+
/* Takes the Jacobian coordinates (X, Y, Z) of a point and returns (X', Y') =
|
1535
|
+
* (X/Z^2, Y/Z^3). */
|
1536
|
+
static int ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP *group,
|
1537
|
+
const EC_POINT *point,
|
1538
|
+
BIGNUM *x, BIGNUM *y,
|
1539
|
+
BN_CTX *ctx) {
|
1540
|
+
felem z1, z2, x_in, y_in;
|
1541
|
+
smallfelem x_out, y_out;
|
1542
|
+
longfelem tmp;
|
1543
|
+
|
1544
|
+
if (EC_POINT_is_at_infinity(group, point)) {
|
1545
|
+
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
1546
|
+
return 0;
|
1547
|
+
}
|
1548
|
+
if (!BN_to_felem(x_in, &point->X) ||
|
1549
|
+
!BN_to_felem(y_in, &point->Y) ||
|
1550
|
+
!BN_to_felem(z1, &point->Z)) {
|
1551
|
+
return 0;
|
1552
|
+
}
|
1553
|
+
felem_inv(z2, z1);
|
1554
|
+
felem_square(tmp, z2);
|
1555
|
+
felem_reduce(z1, tmp);
|
1556
|
+
|
1557
|
+
if (x != NULL) {
|
1558
|
+
felem_mul(tmp, x_in, z1);
|
1559
|
+
felem_reduce(x_in, tmp);
|
1560
|
+
felem_contract(x_out, x_in);
|
1561
|
+
if (!smallfelem_to_BN(x, x_out)) {
|
1562
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
1563
|
+
return 0;
|
1564
|
+
}
|
1565
|
+
}
|
1566
|
+
|
1567
|
+
if (y != NULL) {
|
1568
|
+
felem_mul(tmp, z1, z2);
|
1569
|
+
felem_reduce(z1, tmp);
|
1570
|
+
felem_mul(tmp, y_in, z1);
|
1571
|
+
felem_reduce(y_in, tmp);
|
1572
|
+
felem_contract(y_out, y_in);
|
1573
|
+
if (!smallfelem_to_BN(y, y_out)) {
|
1574
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
1575
|
+
return 0;
|
1576
|
+
}
|
1577
|
+
}
|
1578
|
+
|
1579
|
+
return 1;
|
1580
|
+
}
|
1581
|
+
|
1582
|
+
static int ec_GFp_nistp256_points_mul(const EC_GROUP *group,
|
1583
|
+
EC_POINT *r,
|
1584
|
+
const BIGNUM *g_scalar,
|
1585
|
+
const EC_POINT *p_,
|
1586
|
+
const BIGNUM *p_scalar_,
|
1587
|
+
BN_CTX *ctx) {
|
1588
|
+
/* TODO: This function used to take |points| and |scalars| as arrays of
|
1589
|
+
* |num| elements. The code below should be simplified to work in terms of |p|
|
1590
|
+
* and |p_scalar|. */
|
1591
|
+
size_t num = p_ != NULL ? 1 : 0;
|
1592
|
+
const EC_POINT **points = p_ != NULL ? &p_ : NULL;
|
1593
|
+
BIGNUM const *const *scalars = p_ != NULL ? &p_scalar_ : NULL;
|
1594
|
+
|
1595
|
+
int ret = 0;
|
1596
|
+
BN_CTX *new_ctx = NULL;
|
1597
|
+
BIGNUM *x, *y, *z, *tmp_scalar;
|
1598
|
+
felem_bytearray g_secret;
|
1599
|
+
felem_bytearray *secrets = NULL;
|
1600
|
+
smallfelem(*pre_comp)[17][3] = NULL;
|
1601
|
+
felem_bytearray tmp;
|
1602
|
+
size_t num_points = num;
|
1603
|
+
smallfelem x_in, y_in, z_in;
|
1604
|
+
felem x_out, y_out, z_out;
|
1605
|
+
const EC_POINT *p = NULL;
|
1606
|
+
const BIGNUM *p_scalar = NULL;
|
1607
|
+
|
1608
|
+
if (ctx == NULL) {
|
1609
|
+
ctx = new_ctx = BN_CTX_new();
|
1610
|
+
if (ctx == NULL) {
|
1611
|
+
return 0;
|
1612
|
+
}
|
1613
|
+
}
|
1614
|
+
|
1615
|
+
BN_CTX_start(ctx);
|
1616
|
+
if ((x = BN_CTX_get(ctx)) == NULL ||
|
1617
|
+
(y = BN_CTX_get(ctx)) == NULL ||
|
1618
|
+
(z = BN_CTX_get(ctx)) == NULL ||
|
1619
|
+
(tmp_scalar = BN_CTX_get(ctx)) == NULL) {
|
1620
|
+
goto err;
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
if (num_points > 0) {
|
1624
|
+
secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray));
|
1625
|
+
pre_comp = OPENSSL_malloc(num_points * sizeof(smallfelem[17][3]));
|
1626
|
+
if (secrets == NULL || pre_comp == NULL) {
|
1627
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
|
1628
|
+
goto err;
|
1629
|
+
}
|
1630
|
+
|
1631
|
+
/* we treat NULL scalars as 0, and NULL points as points at infinity,
|
1632
|
+
* i.e., they contribute nothing to the linear combination. */
|
1633
|
+
memset(secrets, 0, num_points * sizeof(felem_bytearray));
|
1634
|
+
memset(pre_comp, 0, num_points * 17 * 3 * sizeof(smallfelem));
|
1635
|
+
for (size_t i = 0; i < num_points; ++i) {
|
1636
|
+
if (i == num) {
|
1637
|
+
/* we didn't have a valid precomputation, so we pick the generator. */
|
1638
|
+
p = EC_GROUP_get0_generator(group);
|
1639
|
+
p_scalar = g_scalar;
|
1640
|
+
} else {
|
1641
|
+
/* the i^th point */
|
1642
|
+
p = points[i];
|
1643
|
+
p_scalar = scalars[i];
|
1644
|
+
}
|
1645
|
+
if (p_scalar != NULL && p != NULL) {
|
1646
|
+
size_t num_bytes;
|
1647
|
+
/* reduce g_scalar to 0 <= g_scalar < 2^256 */
|
1648
|
+
if (BN_num_bits(p_scalar) > 256 || BN_is_negative(p_scalar)) {
|
1649
|
+
/* this is an unusual input, and we don't guarantee
|
1650
|
+
* constant-timeness. */
|
1651
|
+
if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) {
|
1652
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
1653
|
+
goto err;
|
1654
|
+
}
|
1655
|
+
num_bytes = BN_bn2bin(tmp_scalar, tmp);
|
1656
|
+
} else {
|
1657
|
+
num_bytes = BN_bn2bin(p_scalar, tmp);
|
1658
|
+
}
|
1659
|
+
flip_endian(secrets[i], tmp, num_bytes);
|
1660
|
+
/* precompute multiples */
|
1661
|
+
if (!BN_to_felem(x_out, &p->X) ||
|
1662
|
+
!BN_to_felem(y_out, &p->Y) ||
|
1663
|
+
!BN_to_felem(z_out, &p->Z)) {
|
1664
|
+
goto err;
|
1665
|
+
}
|
1666
|
+
felem_shrink(pre_comp[i][1][0], x_out);
|
1667
|
+
felem_shrink(pre_comp[i][1][1], y_out);
|
1668
|
+
felem_shrink(pre_comp[i][1][2], z_out);
|
1669
|
+
for (size_t j = 2; j <= 16; ++j) {
|
1670
|
+
if (j & 1) {
|
1671
|
+
point_add_small(pre_comp[i][j][0], pre_comp[i][j][1],
|
1672
|
+
pre_comp[i][j][2], pre_comp[i][1][0],
|
1673
|
+
pre_comp[i][1][1], pre_comp[i][1][2],
|
1674
|
+
pre_comp[i][j - 1][0], pre_comp[i][j - 1][1],
|
1675
|
+
pre_comp[i][j - 1][2]);
|
1676
|
+
} else {
|
1677
|
+
point_double_small(pre_comp[i][j][0], pre_comp[i][j][1],
|
1678
|
+
pre_comp[i][j][2], pre_comp[i][j / 2][0],
|
1679
|
+
pre_comp[i][j / 2][1], pre_comp[i][j / 2][2]);
|
1680
|
+
}
|
1681
|
+
}
|
1682
|
+
}
|
1683
|
+
}
|
1684
|
+
}
|
1685
|
+
|
1686
|
+
if (g_scalar != NULL) {
|
1687
|
+
size_t num_bytes;
|
1688
|
+
|
1689
|
+
memset(g_secret, 0, sizeof(g_secret));
|
1690
|
+
/* reduce g_scalar to 0 <= g_scalar < 2^256 */
|
1691
|
+
if (BN_num_bits(g_scalar) > 256 || BN_is_negative(g_scalar)) {
|
1692
|
+
/* this is an unusual input, and we don't guarantee
|
1693
|
+
* constant-timeness. */
|
1694
|
+
if (!BN_nnmod(tmp_scalar, g_scalar, &group->order, ctx)) {
|
1695
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
1696
|
+
goto err;
|
1697
|
+
}
|
1698
|
+
num_bytes = BN_bn2bin(tmp_scalar, tmp);
|
1699
|
+
} else {
|
1700
|
+
num_bytes = BN_bn2bin(g_scalar, tmp);
|
1701
|
+
}
|
1702
|
+
flip_endian(g_secret, tmp, num_bytes);
|
1703
|
+
}
|
1704
|
+
batch_mul(x_out, y_out, z_out, (const felem_bytearray(*))secrets,
|
1705
|
+
num_points, g_scalar != NULL ? g_secret : NULL,
|
1706
|
+
(const smallfelem(*)[17][3])pre_comp);
|
1707
|
+
|
1708
|
+
/* reduce the output to its unique minimal representation */
|
1709
|
+
felem_contract(x_in, x_out);
|
1710
|
+
felem_contract(y_in, y_out);
|
1711
|
+
felem_contract(z_in, z_out);
|
1712
|
+
if (!smallfelem_to_BN(x, x_in) ||
|
1713
|
+
!smallfelem_to_BN(y, y_in) ||
|
1714
|
+
!smallfelem_to_BN(z, z_in)) {
|
1715
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
1716
|
+
goto err;
|
1717
|
+
}
|
1718
|
+
ret = ec_point_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
1719
|
+
|
1720
|
+
err:
|
1721
|
+
BN_CTX_end(ctx);
|
1722
|
+
BN_CTX_free(new_ctx);
|
1723
|
+
OPENSSL_free(secrets);
|
1724
|
+
OPENSSL_free(pre_comp);
|
1725
|
+
return ret;
|
1726
|
+
}
|
1727
|
+
|
1728
|
+
const EC_METHOD EC_GFp_nistp256_method = {
|
1729
|
+
ec_GFp_simple_group_init,
|
1730
|
+
ec_GFp_simple_group_finish,
|
1731
|
+
ec_GFp_simple_group_copy,
|
1732
|
+
ec_GFp_simple_group_set_curve,
|
1733
|
+
ec_GFp_nistp256_point_get_affine_coordinates,
|
1734
|
+
ec_GFp_nistp256_points_mul,
|
1735
|
+
ec_GFp_simple_field_mul,
|
1736
|
+
ec_GFp_simple_field_sqr,
|
1737
|
+
NULL /* field_encode */,
|
1738
|
+
NULL /* field_decode */,
|
1739
|
+
};
|
1740
|
+
|
1741
|
+
#endif /* 64_BIT && !WINDOWS */
|