grpc 1.9.1 → 1.10.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +2654 -953
- data/etc/roots.pem +282 -683
- data/include/grpc/compression.h +9 -26
- data/include/grpc/grpc.h +10 -24
- data/include/grpc/grpc_security.h +7 -1
- data/include/grpc/impl/codegen/compression_types.h +5 -62
- data/include/grpc/impl/codegen/grpc_types.h +10 -6
- data/include/grpc/module.modulemap +1 -10
- data/include/grpc/support/alloc.h +3 -2
- data/include/grpc/support/log.h +1 -2
- data/{src/core/lib/gpr/thd_internal.h → include/grpc/support/thd_id.h} +23 -9
- data/src/boringssl/err_data.c +550 -496
- data/src/core/ext/census/grpc_context.cc +2 -1
- data/src/core/ext/filters/client_channel/backup_poller.cc +5 -4
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +7 -7
- data/src/core/ext/filters/client_channel/client_channel.cc +162 -172
- data/src/core/ext/filters/client_channel/client_channel_factory.cc +4 -2
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +10 -10
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +18 -14
- data/src/core/ext/filters/client_channel/http_proxy.cc +3 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +21 -105
- data/src/core/ext/filters/client_channel/lb_policy.h +166 -170
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +41 -36
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +1452 -1459
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +7 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +27 -27
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +279 -304
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +358 -330
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +30 -41
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +7 -14
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +8 -21
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +23 -27
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +58 -33
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +25 -12
- data/src/core/ext/filters/client_channel/parse_address.cc +10 -8
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver.cc +6 -52
- data/src/core/ext/filters/client_channel/resolver.h +98 -55
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +266 -237
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +5 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +31 -27
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +244 -207
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +161 -148
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +47 -31
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +126 -126
- data/src/core/ext/filters/client_channel/resolver_factory.h +33 -32
- data/src/core/ext/filters/client_channel/resolver_registry.cc +110 -90
- data/src/core/ext/filters/client_channel/resolver_registry.h +49 -36
- data/src/core/ext/filters/client_channel/retry_throttle.cc +29 -22
- data/src/core/ext/filters/client_channel/subchannel.cc +173 -173
- data/src/core/ext/filters/client_channel/subchannel.h +38 -45
- data/src/core/ext/filters/client_channel/subchannel_index.cc +44 -40
- data/src/core/ext/filters/client_channel/uri_parser.cc +3 -3
- data/src/core/ext/filters/deadline/deadline_filter.cc +27 -18
- data/src/core/ext/filters/http/client/http_client_filter.cc +26 -23
- data/src/core/ext/filters/http/http_filters_plugin.cc +3 -2
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +78 -110
- data/src/core/ext/filters/http/server/http_server_filter.cc +29 -26
- data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +9 -11
- data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +2 -1
- data/src/core/ext/filters/max_age/max_age_filter.cc +14 -14
- data/src/core/ext/filters/message_size/message_size_filter.cc +20 -18
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +4 -4
- data/src/core/ext/filters/workarounds/workaround_utils.cc +4 -4
- data/src/core/ext/transport/chttp2/alpn/alpn.cc +2 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +10 -10
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +4 -4
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +11 -12
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +16 -13
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +36 -9
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +3 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +17 -14
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +139 -145
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +16 -14
- data/src/core/ext/transport/chttp2/transport/flow_control.h +8 -7
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +35 -33
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +27 -25
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +12 -12
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +16 -15
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +19 -19
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +11 -11
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +23 -22
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +35 -35
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +10 -7
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +1 -1
- data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -39
- data/src/core/ext/transport/chttp2/transport/stream_map.cc +8 -7
- data/src/core/ext/transport/chttp2/transport/varint.cc +5 -5
- data/src/core/ext/transport/chttp2/transport/writing.cc +18 -18
- data/src/core/ext/transport/inproc/inproc_transport.cc +43 -23
- data/src/core/lib/{gpr → avl}/avl.cc +61 -57
- data/{include/grpc/support → src/core/lib/avl}/avl.h +25 -35
- data/src/core/lib/backoff/backoff.cc +6 -5
- data/src/core/lib/channel/channel_args.cc +23 -109
- data/src/core/lib/channel/channel_args.h +5 -31
- data/src/core/lib/channel/channel_stack.cc +11 -8
- data/src/core/lib/channel/channel_stack_builder.cc +10 -7
- data/src/core/lib/channel/connected_channel.cc +18 -17
- data/src/core/lib/channel/handshaker.cc +8 -8
- data/src/core/lib/channel/handshaker_registry.cc +3 -2
- data/src/core/lib/compression/algorithm_metadata.h +13 -6
- data/src/core/lib/compression/compression.cc +72 -183
- data/src/core/lib/compression/compression_internal.cc +274 -0
- data/src/core/lib/compression/compression_internal.h +86 -0
- data/src/core/lib/compression/message_compress.cc +15 -15
- data/src/core/lib/compression/message_compress.h +4 -3
- data/src/core/lib/compression/stream_compression_gzip.cc +8 -8
- data/src/core/lib/compression/stream_compression_identity.cc +1 -1
- data/src/core/lib/debug/stats.cc +10 -8
- data/src/core/lib/debug/stats_data.cc +2 -1
- data/src/core/lib/debug/trace.cc +3 -3
- data/src/core/lib/gpr/alloc.cc +7 -11
- data/src/core/lib/gpr/arena.cc +34 -12
- data/src/core/lib/gpr/atm.cc +2 -1
- data/src/core/lib/gpr/cpu_linux.cc +3 -3
- data/src/core/lib/gpr/cpu_posix.cc +2 -1
- data/src/core/lib/gpr/env.h +1 -1
- data/src/core/lib/gpr/env_linux.cc +1 -1
- data/src/core/lib/gpr/env_windows.cc +4 -4
- data/src/core/lib/gpr/fork.cc +16 -2
- data/src/core/lib/gpr/host_port.cc +5 -4
- data/{include/grpc/support → src/core/lib/gpr}/host_port.h +5 -13
- data/src/core/lib/gpr/log.cc +5 -4
- data/src/core/lib/gpr/log_linux.cc +1 -1
- data/src/core/lib/gpr/mpscq.cc +1 -0
- data/src/core/lib/gpr/murmur_hash.cc +4 -4
- data/src/core/lib/gpr/string.cc +19 -16
- data/src/core/lib/gpr/string_posix.cc +3 -3
- data/src/core/lib/gpr/sync_posix.cc +5 -9
- data/src/core/lib/gpr/thd.cc +3 -3
- data/{include/grpc/support → src/core/lib/gpr}/thd.h +20 -28
- data/src/core/lib/gpr/thd_posix.cc +6 -4
- data/src/core/lib/gpr/thd_windows.cc +3 -1
- data/src/core/lib/gpr/time.cc +6 -4
- data/src/core/lib/gpr/time_posix.cc +2 -2
- data/{include/grpc/support → src/core/lib/gpr}/tls.h +6 -6
- data/{include/grpc/support → src/core/lib/gpr}/tls_gcc.h +3 -3
- data/{include/grpc/support → src/core/lib/gpr}/tls_msvc.h +3 -3
- data/src/core/lib/gpr/tls_pthread.cc +1 -1
- data/{include/grpc/support → src/core/lib/gpr}/tls_pthread.h +3 -3
- data/{include/grpc/support → src/core/lib/gpr}/useful.h +3 -3
- data/src/core/lib/{gpr++ → gprpp}/abstract.h +3 -3
- data/src/core/lib/{gpr++ → gprpp}/atomic.h +5 -5
- data/src/core/lib/{gpr++ → gprpp}/atomic_with_atm.h +3 -3
- data/src/core/lib/{gpr++ → gprpp}/atomic_with_std.h +3 -3
- data/src/core/lib/{gpr++ → gprpp}/debug_location.h +3 -3
- data/src/core/lib/{gpr++ → gprpp}/inlined_vector.h +44 -22
- data/src/core/lib/{gpr++ → gprpp}/manual_constructor.h +2 -2
- data/src/core/lib/{gpr++ → gprpp}/memory.h +14 -5
- data/src/core/lib/{gpr++ → gprpp}/orphanable.h +39 -14
- data/src/core/lib/{gpr++ → gprpp}/ref_counted.h +42 -10
- data/src/core/lib/{gpr++ → gprpp}/ref_counted_ptr.h +18 -8
- data/src/core/lib/http/format_request.cc +3 -3
- data/src/core/lib/http/httpcli.cc +6 -7
- data/src/core/lib/http/httpcli_security_connector.cc +10 -10
- data/src/core/lib/http/parser.cc +16 -12
- data/src/core/lib/iomgr/call_combiner.cc +12 -13
- data/src/core/lib/iomgr/closure.h +4 -6
- data/src/core/lib/iomgr/combiner.cc +10 -21
- data/src/core/lib/iomgr/error.cc +50 -55
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +41 -52
- data/src/core/lib/iomgr/ev_epollex_linux.cc +80 -28
- data/src/core/lib/iomgr/ev_epollsig_linux.cc +23 -30
- data/src/core/lib/iomgr/ev_poll_posix.cc +52 -46
- data/src/core/lib/iomgr/ev_posix.cc +47 -6
- data/src/core/lib/iomgr/exec_ctx.cc +10 -10
- data/src/core/lib/iomgr/exec_ctx.h +1 -1
- data/src/core/lib/iomgr/executor.cc +16 -13
- data/src/core/lib/iomgr/fork_posix.cc +1 -3
- data/src/core/lib/iomgr/gethostname_host_name_max.cc +1 -1
- data/src/core/lib/iomgr/iocp_windows.cc +1 -2
- data/src/core/lib/iomgr/iomgr.cc +2 -2
- data/src/core/lib/iomgr/iomgr_uv.cc +2 -0
- data/src/core/lib/iomgr/iomgr_uv.h +1 -1
- data/src/core/lib/iomgr/is_epollexclusive_available.cc +5 -4
- data/src/core/lib/iomgr/load_file.cc +3 -3
- data/src/core/lib/iomgr/pollset_windows.cc +1 -1
- data/src/core/lib/iomgr/resolve_address_posix.cc +10 -9
- data/src/core/lib/iomgr/resolve_address_uv.cc +2 -2
- data/src/core/lib/iomgr/resolve_address_windows.cc +3 -2
- data/src/core/lib/iomgr/resource_quota.cc +36 -34
- data/src/core/lib/iomgr/sockaddr_utils.cc +39 -23
- data/src/core/lib/iomgr/socket_factory_posix.cc +5 -5
- data/src/core/lib/iomgr/socket_mutator.cc +7 -7
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +7 -4
- data/src/core/lib/iomgr/socket_utils_linux.cc +3 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +7 -6
- data/src/core/lib/iomgr/tcp_client_windows.cc +0 -1
- data/src/core/lib/iomgr/tcp_posix.cc +47 -55
- data/src/core/lib/iomgr/tcp_server_posix.cc +12 -10
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +7 -5
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +4 -3
- data/src/core/lib/iomgr/tcp_windows.cc +1 -1
- data/src/core/lib/iomgr/timer_generic.cc +16 -14
- data/src/core/lib/iomgr/timer_heap.cc +8 -7
- data/src/core/lib/iomgr/timer_manager.cc +4 -3
- data/src/core/lib/iomgr/udp_server.cc +24 -16
- data/src/core/lib/iomgr/unix_sockets_posix.cc +15 -10
- data/src/core/lib/iomgr/wakeup_fd_cv.cc +6 -5
- data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +1 -2
- data/src/core/lib/json/json.cc +1 -1
- data/src/core/lib/json/json_reader.cc +8 -6
- data/src/core/lib/json/json_string.cc +19 -18
- data/src/core/lib/json/json_writer.cc +10 -8
- data/src/core/lib/profiling/basic_timers.cc +1 -1
- data/src/core/lib/profiling/timers.h +3 -20
- data/src/core/lib/security/context/security_context.cc +16 -14
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +17 -14
- data/src/core/lib/security/credentials/credentials.cc +9 -8
- data/src/core/lib/security/credentials/credentials.h +1 -1
- data/src/core/lib/security/credentials/credentials_metadata.cc +2 -2
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +12 -13
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +7 -4
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +5 -3
- data/src/core/lib/security/credentials/jwt/json_token.cc +4 -3
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -7
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +21 -18
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +23 -18
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +11 -7
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +22 -21
- data/src/core/lib/security/{transport → security_connector}/security_connector.cc +46 -43
- data/src/core/lib/security/{transport → security_connector}/security_connector.h +3 -3
- data/src/core/lib/security/transport/client_auth_filter.cc +32 -34
- data/src/core/lib/security/transport/lb_targets_info.cc +7 -5
- data/src/core/lib/security/transport/secure_endpoint.cc +21 -21
- data/src/core/lib/security/transport/security_handshaker.cc +19 -18
- data/src/core/lib/security/transport/security_handshaker.h +1 -1
- data/src/core/lib/security/transport/server_auth_filter.cc +21 -21
- data/src/core/lib/slice/b64.cc +19 -16
- data/src/core/lib/slice/percent_encoding.cc +5 -5
- data/src/core/lib/slice/slice.cc +35 -33
- data/src/core/lib/slice/slice_buffer.cc +16 -14
- data/src/core/lib/slice/slice_hash_table.cc +3 -2
- data/src/core/lib/slice/slice_intern.cc +21 -25
- data/src/core/lib/slice/slice_string_helpers.cc +45 -9
- data/src/core/lib/slice/slice_string_helpers.h +6 -0
- data/src/core/lib/surface/byte_buffer.cc +2 -2
- data/src/core/lib/surface/byte_buffer_reader.cc +6 -3
- data/src/core/lib/surface/call.cc +171 -260
- data/src/core/lib/surface/call_test_only.h +1 -13
- data/src/core/lib/surface/channel.cc +20 -43
- data/src/core/lib/surface/channel_init.cc +7 -7
- data/src/core/lib/surface/channel_ping.cc +2 -2
- data/src/core/lib/surface/completion_queue.cc +69 -75
- data/src/core/lib/surface/init.cc +4 -5
- data/src/core/lib/surface/init_secure.cc +1 -1
- data/src/core/lib/surface/lame_client.cc +1 -1
- data/src/core/lib/surface/server.cc +64 -59
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/bdp_estimator.cc +6 -5
- data/src/core/lib/transport/byte_stream.cc +23 -14
- data/src/core/lib/transport/byte_stream.h +1 -1
- data/src/core/lib/transport/connectivity_state.cc +9 -13
- data/src/core/lib/transport/error_utils.cc +10 -7
- data/src/core/lib/transport/metadata.cc +27 -26
- data/src/core/lib/transport/metadata.h +1 -1
- data/src/core/lib/transport/pid_controller.cc +2 -1
- data/src/core/lib/transport/service_config.cc +5 -5
- data/src/core/lib/transport/static_metadata.cc +225 -222
- data/src/core/lib/transport/static_metadata.h +77 -76
- data/src/core/lib/transport/timeout_encoding.cc +3 -2
- data/src/core/lib/transport/transport.cc +6 -5
- data/src/core/lib/transport/transport_op_string.cc +0 -1
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -4
- data/src/core/tsi/alts_transport_security.cc +61 -0
- data/src/core/tsi/{gts_transport_security.h → alts_transport_security.h} +16 -8
- data/src/core/tsi/fake_transport_security.cc +59 -43
- data/src/core/tsi/ssl_transport_security.cc +122 -107
- data/src/core/tsi/transport_security.cc +3 -3
- data/src/core/tsi/transport_security_adapter.cc +16 -10
- data/src/ruby/bin/apis/pubsub_demo.rb +1 -1
- data/src/ruby/ext/grpc/rb_channel.c +3 -4
- data/src/ruby/ext/grpc/rb_compression_options.c +13 -3
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -76
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +8 -120
- data/src/ruby/ext/grpc/rb_server.c +52 -28
- data/src/ruby/lib/grpc/generic/rpc_server.rb +7 -4
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/test/client.rb +1 -1
- data/src/ruby/pb/test/server.rb +1 -1
- data/src/ruby/spec/client_server_spec.rb +4 -2
- data/src/ruby/spec/generic/active_call_spec.rb +2 -1
- data/src/ruby/spec/generic/client_stub_spec.rb +32 -8
- data/src/ruby/spec/server_spec.rb +26 -7
- data/third_party/boringssl/crypto/asn1/a_bitstr.c +7 -2
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +15 -0
- data/third_party/boringssl/crypto/asn1/a_gentm.c +1 -1
- data/third_party/boringssl/crypto/asn1/a_print.c +0 -28
- data/third_party/boringssl/crypto/asn1/a_strnid.c +3 -0
- data/third_party/boringssl/crypto/asn1/a_time.c +17 -9
- data/third_party/boringssl/crypto/asn1/a_utctm.c +1 -1
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +5 -49
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +1 -1
- data/third_party/boringssl/crypto/asn1/tasn_dec.c +9 -9
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +0 -6
- data/third_party/boringssl/crypto/asn1/time_support.c +5 -5
- data/third_party/boringssl/crypto/base64/base64.c +65 -43
- data/third_party/boringssl/crypto/bio/bio.c +134 -110
- data/third_party/boringssl/crypto/bio/bio_mem.c +9 -9
- data/third_party/boringssl/crypto/bio/connect.c +17 -17
- data/third_party/boringssl/crypto/bio/fd.c +2 -1
- data/third_party/boringssl/crypto/bio/file.c +14 -14
- data/third_party/boringssl/crypto/bio/hexdump.c +15 -16
- data/third_party/boringssl/crypto/bio/internal.h +14 -14
- data/third_party/boringssl/crypto/bio/pair.c +45 -45
- data/third_party/boringssl/crypto/bio/printf.c +6 -10
- data/third_party/boringssl/crypto/{bn → bn_extra}/bn_asn1.c +9 -9
- data/third_party/boringssl/crypto/{bn → bn_extra}/convert.c +18 -223
- data/third_party/boringssl/crypto/buf/buf.c +20 -44
- data/third_party/boringssl/crypto/bytestring/ber.c +35 -35
- data/third_party/boringssl/crypto/bytestring/cbb.c +24 -24
- data/third_party/boringssl/crypto/bytestring/cbs.c +33 -37
- data/third_party/boringssl/crypto/bytestring/internal.h +38 -38
- data/third_party/boringssl/crypto/chacha/chacha.c +7 -7
- data/third_party/boringssl/crypto/{asn1/t_bitst.c → cipher_extra/cipher_extra.c} +49 -38
- data/third_party/boringssl/crypto/{cipher → cipher_extra}/derive_key.c +0 -2
- data/third_party/boringssl/crypto/cipher_extra/e_aesctrhmac.c +281 -0
- data/third_party/boringssl/crypto/cipher_extra/e_aesgcmsiv.c +867 -0
- data/third_party/boringssl/crypto/cipher_extra/e_chacha20poly1305.c +326 -0
- data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_null.c +0 -1
- data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_rc2.c +22 -10
- data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_rc4.c +0 -0
- data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_ssl3.c +120 -64
- data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_tls.c +220 -141
- data/third_party/boringssl/crypto/{asn1/x_bignum.c → cipher_extra/internal.h} +61 -86
- data/third_party/boringssl/crypto/cipher_extra/tls_cbc.c +482 -0
- data/third_party/boringssl/crypto/cmac/cmac.c +20 -20
- data/third_party/boringssl/crypto/conf/conf.c +32 -20
- data/third_party/boringssl/crypto/conf/internal.h +3 -3
- data/third_party/boringssl/crypto/cpu-aarch64-linux.c +5 -5
- data/third_party/boringssl/crypto/cpu-arm-linux.c +44 -41
- data/third_party/boringssl/crypto/cpu-intel.c +68 -43
- data/third_party/boringssl/crypto/cpu-ppc64le.c +5 -7
- data/third_party/boringssl/crypto/crypto.c +54 -32
- data/third_party/boringssl/crypto/curve25519/curve25519.c +269 -269
- data/third_party/boringssl/crypto/curve25519/internal.h +28 -8
- data/third_party/boringssl/crypto/curve25519/spake25519.c +180 -106
- data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +9 -9
- data/third_party/boringssl/crypto/dh/check.c +33 -34
- data/third_party/boringssl/crypto/dh/dh.c +72 -36
- data/third_party/boringssl/crypto/dh/dh_asn1.c +1 -1
- data/third_party/boringssl/crypto/dh/params.c +1 -161
- data/third_party/boringssl/crypto/digest_extra/digest_extra.c +240 -0
- data/third_party/boringssl/crypto/dsa/dsa.c +127 -87
- data/third_party/boringssl/crypto/dsa/dsa_asn1.c +1 -1
- data/third_party/boringssl/crypto/{ec → ec_extra}/ec_asn1.c +83 -70
- data/third_party/boringssl/crypto/ecdh/ecdh.c +1 -1
- data/third_party/boringssl/crypto/{ecdsa → ecdsa_extra}/ecdsa_asn1.c +86 -31
- data/third_party/boringssl/crypto/engine/engine.c +6 -6
- data/third_party/boringssl/crypto/err/err.c +197 -106
- data/third_party/boringssl/crypto/err/internal.h +58 -0
- data/third_party/boringssl/crypto/evp/digestsign.c +86 -14
- data/third_party/boringssl/crypto/evp/evp.c +6 -11
- data/third_party/boringssl/crypto/evp/evp_asn1.c +17 -17
- data/third_party/boringssl/crypto/evp/evp_ctx.c +15 -11
- data/third_party/boringssl/crypto/evp/internal.h +66 -51
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +11 -11
- data/third_party/boringssl/crypto/evp/p_ec.c +10 -8
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +11 -12
- data/third_party/boringssl/crypto/evp/p_ed25519.c +71 -0
- data/third_party/boringssl/crypto/evp/p_ed25519_asn1.c +190 -0
- data/third_party/boringssl/crypto/evp/p_rsa.c +50 -95
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +28 -18
- data/third_party/boringssl/crypto/evp/pbkdf.c +49 -56
- data/third_party/boringssl/crypto/evp/print.c +5 -36
- data/third_party/boringssl/crypto/evp/scrypt.c +209 -0
- data/third_party/boringssl/crypto/ex_data.c +15 -45
- data/third_party/boringssl/crypto/fipsmodule/aes/internal.h +100 -0
- data/third_party/boringssl/crypto/fipsmodule/bcm.c +679 -0
- data/third_party/boringssl/crypto/{bn → fipsmodule/bn}/internal.h +40 -27
- data/third_party/boringssl/crypto/{bn → fipsmodule/bn}/rsaz_exp.h +0 -0
- data/third_party/boringssl/crypto/{cipher → fipsmodule/cipher}/internal.h +34 -67
- data/third_party/boringssl/crypto/fipsmodule/delocate.h +88 -0
- data/third_party/boringssl/crypto/{des → fipsmodule/des}/internal.h +18 -4
- data/third_party/boringssl/crypto/{digest → fipsmodule/digest}/internal.h +18 -18
- data/third_party/boringssl/crypto/{digest → fipsmodule/digest}/md32_common.h +58 -64
- data/third_party/boringssl/crypto/{ec → fipsmodule/ec}/internal.h +58 -52
- data/third_party/boringssl/crypto/{ec → fipsmodule/ec}/p256-x86_64-table.h +11 -11
- data/third_party/boringssl/crypto/{ec → fipsmodule/ec}/p256-x86_64.h +32 -32
- data/third_party/boringssl/crypto/{rand/internal.h → fipsmodule/is_fips.c} +10 -15
- data/third_party/boringssl/crypto/{modes → fipsmodule/modes}/internal.h +112 -119
- data/third_party/boringssl/crypto/fipsmodule/rand/internal.h +92 -0
- data/third_party/boringssl/crypto/{rsa → fipsmodule/rsa}/internal.h +36 -49
- data/third_party/boringssl/crypto/hkdf/hkdf.c +6 -6
- data/third_party/boringssl/crypto/internal.h +301 -233
- data/third_party/boringssl/crypto/lhash/lhash.c +26 -45
- data/third_party/boringssl/crypto/mem.c +76 -33
- data/third_party/boringssl/crypto/obj/obj.c +44 -28
- data/third_party/boringssl/crypto/obj/obj_dat.h +102 -34
- data/third_party/boringssl/crypto/obj/obj_xref.c +6 -6
- data/third_party/boringssl/crypto/pem/pem_info.c +3 -5
- data/third_party/boringssl/crypto/pem/pem_lib.c +1 -6
- data/third_party/boringssl/crypto/pem/pem_pk8.c +1 -0
- data/third_party/boringssl/crypto/pem/pem_pkey.c +1 -1
- data/third_party/boringssl/crypto/pem/pem_xaux.c +0 -2
- data/third_party/boringssl/crypto/pkcs7/internal.h +49 -0
- data/third_party/boringssl/crypto/pkcs7/pkcs7.c +166 -0
- data/third_party/boringssl/crypto/{x509/pkcs7.c → pkcs7/pkcs7_x509.c} +27 -147
- data/third_party/boringssl/crypto/pkcs8/internal.h +34 -16
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +120 -39
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +144 -857
- data/third_party/boringssl/crypto/pkcs8/pkcs8_x509.c +789 -0
- data/third_party/boringssl/crypto/poly1305/internal.h +4 -3
- data/third_party/boringssl/crypto/poly1305/poly1305.c +14 -14
- data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +11 -11
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +41 -41
- data/third_party/boringssl/crypto/pool/internal.h +2 -2
- data/third_party/boringssl/crypto/pool/pool.c +15 -15
- data/third_party/boringssl/crypto/{rand → rand_extra}/deterministic.c +7 -7
- data/third_party/boringssl/crypto/rand_extra/forkunsafe.c +46 -0
- data/third_party/boringssl/crypto/{rand → rand_extra}/fuchsia.c +7 -7
- data/third_party/boringssl/crypto/rand_extra/rand_extra.c +70 -0
- data/third_party/boringssl/crypto/{rand → rand_extra}/windows.c +5 -5
- data/third_party/boringssl/crypto/refcount_c11.c +2 -2
- data/third_party/boringssl/crypto/refcount_lock.c +1 -1
- data/third_party/boringssl/crypto/{rsa → rsa_extra}/rsa_asn1.c +12 -120
- data/third_party/boringssl/crypto/stack/stack.c +13 -13
- data/third_party/boringssl/crypto/thread_none.c +1 -1
- data/third_party/boringssl/crypto/thread_pthread.c +1 -1
- data/third_party/boringssl/crypto/thread_win.c +40 -40
- data/third_party/boringssl/crypto/x509/a_sign.c +5 -12
- data/third_party/boringssl/crypto/x509/a_verify.c +6 -18
- data/third_party/boringssl/crypto/x509/algorithm.c +22 -6
- data/third_party/boringssl/crypto/x509/asn1_gen.c +30 -7
- data/third_party/boringssl/crypto/x509/by_dir.c +2 -2
- data/third_party/boringssl/crypto/x509/by_file.c +2 -2
- data/third_party/boringssl/crypto/x509/rsa_pss.c +5 -5
- data/third_party/boringssl/crypto/x509/t_x509.c +2 -1
- data/third_party/boringssl/crypto/x509/x509_def.c +5 -0
- data/third_party/boringssl/crypto/x509/x509_lu.c +35 -4
- data/third_party/boringssl/crypto/x509/x509_set.c +10 -0
- data/third_party/boringssl/crypto/x509/x509_vfy.c +20 -17
- data/third_party/boringssl/crypto/x509/x_name.c +13 -16
- data/third_party/boringssl/crypto/x509/x_x509.c +3 -3
- data/third_party/boringssl/crypto/x509/x_x509a.c +0 -7
- data/third_party/boringssl/crypto/x509v3/ext_dat.h +8 -0
- data/third_party/boringssl/crypto/x509v3/pcy_int.h +2 -2
- data/third_party/boringssl/crypto/x509v3/pcy_lib.c +0 -9
- data/third_party/boringssl/crypto/x509v3/pcy_node.c +1 -1
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +25 -15
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +21 -11
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +9 -3
- data/third_party/boringssl/crypto/x509v3/v3_info.c +22 -14
- data/third_party/boringssl/crypto/x509v3/v3_ncons.c +27 -11
- data/third_party/boringssl/crypto/x509v3/v3_pci.c +0 -33
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +4 -4
- data/third_party/boringssl/include/openssl/aead.h +280 -191
- data/third_party/boringssl/include/openssl/aes.h +50 -50
- data/third_party/boringssl/include/openssl/arm_arch.h +12 -12
- data/third_party/boringssl/include/openssl/asn1.h +14 -77
- data/third_party/boringssl/include/openssl/asn1t.h +11 -15
- data/third_party/boringssl/include/openssl/base.h +78 -51
- data/third_party/boringssl/include/openssl/base64.h +68 -68
- data/third_party/boringssl/include/openssl/bio.h +472 -406
- data/third_party/boringssl/include/openssl/blowfish.h +1 -1
- data/third_party/boringssl/include/openssl/bn.h +454 -435
- data/third_party/boringssl/include/openssl/buf.h +27 -27
- data/third_party/boringssl/include/openssl/bytestring.h +282 -267
- data/third_party/boringssl/include/openssl/cast.h +2 -2
- data/third_party/boringssl/include/openssl/chacha.h +5 -5
- data/third_party/boringssl/include/openssl/cipher.h +209 -200
- data/third_party/boringssl/include/openssl/cmac.h +27 -27
- data/third_party/boringssl/include/openssl/conf.h +49 -46
- data/third_party/boringssl/include/openssl/cpu.h +60 -45
- data/third_party/boringssl/include/openssl/crypto.h +59 -35
- data/third_party/boringssl/include/openssl/curve25519.h +97 -92
- data/third_party/boringssl/include/openssl/des.h +25 -25
- data/third_party/boringssl/include/openssl/dh.h +98 -97
- data/third_party/boringssl/include/openssl/digest.h +143 -114
- data/third_party/boringssl/include/openssl/dsa.h +217 -202
- data/third_party/boringssl/include/openssl/ec.h +132 -131
- data/third_party/boringssl/include/openssl/ec_key.h +132 -128
- data/third_party/boringssl/include/openssl/ecdh.h +9 -9
- data/third_party/boringssl/include/openssl/ecdsa.h +66 -66
- data/third_party/boringssl/include/openssl/engine.h +38 -38
- data/third_party/boringssl/include/openssl/err.h +189 -219
- data/third_party/boringssl/include/openssl/evp.h +473 -397
- data/third_party/boringssl/include/openssl/ex_data.h +46 -56
- data/third_party/boringssl/include/openssl/hkdf.h +17 -17
- data/third_party/boringssl/include/openssl/hmac.h +55 -43
- data/third_party/boringssl/include/openssl/is_boringssl.h +16 -0
- data/third_party/boringssl/include/openssl/lhash.h +67 -67
- data/third_party/boringssl/include/openssl/lhash_macros.h +4 -4
- data/third_party/boringssl/include/openssl/md4.h +14 -14
- data/third_party/boringssl/include/openssl/md5.h +14 -14
- data/third_party/boringssl/include/openssl/mem.h +39 -33
- data/third_party/boringssl/include/openssl/nid.h +43 -0
- data/third_party/boringssl/include/openssl/obj.h +93 -87
- data/third_party/boringssl/include/openssl/opensslconf.h +8 -1
- data/third_party/boringssl/include/openssl/pem.h +2 -122
- data/third_party/boringssl/include/openssl/pkcs7.h +68 -2
- data/third_party/boringssl/include/openssl/pkcs8.h +81 -66
- data/third_party/boringssl/include/openssl/poly1305.h +11 -11
- data/third_party/boringssl/include/openssl/pool.h +29 -25
- data/third_party/boringssl/include/openssl/rand.h +48 -45
- data/third_party/boringssl/include/openssl/rc4.h +9 -9
- data/third_party/boringssl/include/openssl/ripemd.h +13 -13
- data/third_party/boringssl/include/openssl/rsa.h +371 -340
- data/third_party/boringssl/include/openssl/sha.h +71 -71
- data/third_party/boringssl/include/openssl/span.h +191 -0
- data/third_party/boringssl/include/openssl/ssl.h +2639 -2519
- data/third_party/boringssl/include/openssl/ssl3.h +39 -122
- data/third_party/boringssl/include/openssl/stack.h +355 -164
- data/third_party/boringssl/include/openssl/thread.h +43 -43
- data/third_party/boringssl/include/openssl/tls1.h +60 -63
- data/third_party/boringssl/include/openssl/type_check.h +10 -14
- data/third_party/boringssl/include/openssl/x509.h +41 -116
- data/third_party/boringssl/include/openssl/x509_vfy.h +17 -25
- data/third_party/boringssl/include/openssl/x509v3.h +27 -21
- data/third_party/boringssl/ssl/{bio_ssl.c → bio_ssl.cc} +9 -5
- data/third_party/boringssl/ssl/{custom_extensions.c → custom_extensions.cc} +19 -12
- data/third_party/boringssl/ssl/{d1_both.c → d1_both.cc} +224 -193
- data/third_party/boringssl/ssl/{d1_lib.c → d1_lib.cc} +86 -79
- data/third_party/boringssl/ssl/{d1_pkt.c → d1_pkt.cc} +55 -87
- data/third_party/boringssl/ssl/{d1_srtp.c → d1_srtp.cc} +12 -16
- data/third_party/boringssl/ssl/{dtls_method.c → dtls_method.cc} +33 -50
- data/third_party/boringssl/ssl/{dtls_record.c → dtls_record.cc} +76 -64
- data/third_party/boringssl/ssl/handshake.cc +547 -0
- data/third_party/boringssl/ssl/handshake_client.cc +1828 -0
- data/third_party/boringssl/ssl/handshake_server.cc +1672 -0
- data/third_party/boringssl/ssl/internal.h +2027 -1280
- data/third_party/boringssl/ssl/s3_both.cc +603 -0
- data/third_party/boringssl/ssl/{s3_lib.c → s3_lib.cc} +22 -10
- data/third_party/boringssl/ssl/{s3_pkt.c → s3_pkt.cc} +171 -75
- data/third_party/boringssl/ssl/ssl_aead_ctx.cc +415 -0
- data/third_party/boringssl/ssl/{ssl_asn1.c → ssl_asn1.cc} +257 -261
- data/third_party/boringssl/ssl/{ssl_buffer.c → ssl_buffer.cc} +81 -97
- data/third_party/boringssl/ssl/{ssl_cert.c → ssl_cert.cc} +304 -414
- data/third_party/boringssl/ssl/{ssl_cipher.c → ssl_cipher.cc} +427 -505
- data/third_party/boringssl/ssl/{ssl_file.c → ssl_file.cc} +24 -16
- data/third_party/boringssl/ssl/ssl_key_share.cc +245 -0
- data/third_party/boringssl/ssl/{ssl_lib.c → ssl_lib.cc} +665 -828
- data/third_party/boringssl/ssl/ssl_privkey.cc +518 -0
- data/third_party/boringssl/ssl/{ssl_session.c → ssl_session.cc} +596 -471
- data/third_party/boringssl/ssl/{ssl_stat.c → ssl_stat.cc} +5 -224
- data/third_party/boringssl/ssl/{ssl_transcript.c → ssl_transcript.cc} +117 -140
- data/third_party/boringssl/ssl/ssl_versions.cc +439 -0
- data/third_party/boringssl/ssl/{ssl_x509.c → ssl_x509.cc} +751 -267
- data/third_party/boringssl/ssl/{t1_enc.c → t1_enc.cc} +120 -161
- data/third_party/boringssl/ssl/{t1_lib.c → t1_lib.cc} +859 -966
- data/third_party/boringssl/ssl/{tls13_both.c → tls13_both.cc} +202 -284
- data/third_party/boringssl/ssl/tls13_client.cc +842 -0
- data/third_party/boringssl/ssl/{tls13_enc.c → tls13_enc.cc} +108 -90
- data/third_party/boringssl/ssl/tls13_server.cc +967 -0
- data/third_party/boringssl/ssl/{tls_method.c → tls_method.cc} +94 -73
- data/third_party/boringssl/ssl/tls_record.cc +675 -0
- metadata +117 -168
- data/include/grpc/support/cmdline.h +0 -88
- data/include/grpc/support/subprocess.h +0 -44
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -29
- data/src/core/ext/filters/client_channel/resolver_factory.cc +0 -40
- data/src/core/lib/gpr/cmdline.cc +0 -330
- data/src/core/lib/gpr/subprocess_posix.cc +0 -99
- data/src/core/lib/gpr/subprocess_windows.cc +0 -126
- data/src/core/lib/surface/alarm.cc +0 -137
- data/src/core/lib/surface/alarm_internal.h +0 -40
- data/src/core/tsi/gts_transport_security.cc +0 -40
- data/third_party/boringssl/crypto/aes/aes.c +0 -1142
- data/third_party/boringssl/crypto/aes/internal.h +0 -87
- data/third_party/boringssl/crypto/aes/key_wrap.c +0 -138
- data/third_party/boringssl/crypto/aes/mode_wrappers.c +0 -112
- data/third_party/boringssl/crypto/asn1/x_long.c +0 -200
- data/third_party/boringssl/crypto/bn/add.c +0 -377
- data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +0 -532
- data/third_party/boringssl/crypto/bn/bn.c +0 -365
- data/third_party/boringssl/crypto/bn/cmp.c +0 -239
- data/third_party/boringssl/crypto/bn/ctx.c +0 -313
- data/third_party/boringssl/crypto/bn/div.c +0 -728
- data/third_party/boringssl/crypto/bn/exponentiation.c +0 -1240
- data/third_party/boringssl/crypto/bn/gcd.c +0 -635
- data/third_party/boringssl/crypto/bn/generic.c +0 -707
- data/third_party/boringssl/crypto/bn/kronecker.c +0 -176
- data/third_party/boringssl/crypto/bn/montgomery.c +0 -409
- data/third_party/boringssl/crypto/bn/montgomery_inv.c +0 -207
- data/third_party/boringssl/crypto/bn/mul.c +0 -871
- data/third_party/boringssl/crypto/bn/prime.c +0 -861
- data/third_party/boringssl/crypto/bn/random.c +0 -343
- data/third_party/boringssl/crypto/bn/rsaz_exp.c +0 -254
- data/third_party/boringssl/crypto/bn/shift.c +0 -307
- data/third_party/boringssl/crypto/bn/sqrt.c +0 -506
- data/third_party/boringssl/crypto/cipher/aead.c +0 -156
- data/third_party/boringssl/crypto/cipher/cipher.c +0 -657
- data/third_party/boringssl/crypto/cipher/e_aes.c +0 -1771
- data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +0 -276
- data/third_party/boringssl/crypto/cipher/e_des.c +0 -205
- data/third_party/boringssl/crypto/cipher/tls_cbc.c +0 -482
- data/third_party/boringssl/crypto/des/des.c +0 -771
- data/third_party/boringssl/crypto/digest/digest.c +0 -251
- data/third_party/boringssl/crypto/digest/digests.c +0 -358
- data/third_party/boringssl/crypto/ec/ec.c +0 -847
- data/third_party/boringssl/crypto/ec/ec_key.c +0 -479
- data/third_party/boringssl/crypto/ec/ec_montgomery.c +0 -303
- data/third_party/boringssl/crypto/ec/oct.c +0 -416
- data/third_party/boringssl/crypto/ec/p224-64.c +0 -1143
- data/third_party/boringssl/crypto/ec/p256-64.c +0 -1701
- data/third_party/boringssl/crypto/ec/p256-x86_64.c +0 -561
- data/third_party/boringssl/crypto/ec/simple.c +0 -1118
- data/third_party/boringssl/crypto/ec/util-64.c +0 -109
- data/third_party/boringssl/crypto/ec/wnaf.c +0 -458
- data/third_party/boringssl/crypto/ecdsa/ecdsa.c +0 -479
- data/third_party/boringssl/crypto/hmac/hmac.c +0 -215
- data/third_party/boringssl/crypto/md4/md4.c +0 -236
- data/third_party/boringssl/crypto/md5/md5.c +0 -285
- data/third_party/boringssl/crypto/modes/cbc.c +0 -212
- data/third_party/boringssl/crypto/modes/cfb.c +0 -230
- data/third_party/boringssl/crypto/modes/ctr.c +0 -219
- data/third_party/boringssl/crypto/modes/gcm.c +0 -1071
- data/third_party/boringssl/crypto/modes/ofb.c +0 -95
- data/third_party/boringssl/crypto/modes/polyval.c +0 -94
- data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +0 -85
- data/third_party/boringssl/crypto/rand/rand.c +0 -244
- data/third_party/boringssl/crypto/rand/urandom.c +0 -335
- data/third_party/boringssl/crypto/rsa/blinding.c +0 -265
- data/third_party/boringssl/crypto/rsa/padding.c +0 -708
- data/third_party/boringssl/crypto/rsa/rsa.c +0 -830
- data/third_party/boringssl/crypto/rsa/rsa_impl.c +0 -1100
- data/third_party/boringssl/crypto/sha/sha1-altivec.c +0 -346
- data/third_party/boringssl/crypto/sha/sha1.c +0 -355
- data/third_party/boringssl/crypto/sha/sha256.c +0 -329
- data/third_party/boringssl/crypto/sha/sha512.c +0 -609
- data/third_party/boringssl/crypto/x509/x509type.c +0 -126
- data/third_party/boringssl/include/openssl/stack_macros.h +0 -3987
- data/third_party/boringssl/ssl/handshake_client.c +0 -1883
- data/third_party/boringssl/ssl/handshake_server.c +0 -1950
- data/third_party/boringssl/ssl/s3_both.c +0 -895
- data/third_party/boringssl/ssl/ssl_aead_ctx.c +0 -335
- data/third_party/boringssl/ssl/ssl_ecdh.c +0 -465
- data/third_party/boringssl/ssl/ssl_privkey.c +0 -683
- data/third_party/boringssl/ssl/ssl_privkey_cc.cc +0 -76
- data/third_party/boringssl/ssl/tls13_client.c +0 -712
- data/third_party/boringssl/ssl/tls13_server.c +0 -680
- data/third_party/boringssl/ssl/tls_record.c +0 -556
@@ -1,207 +0,0 @@
|
|
1
|
-
/* Copyright 2016 Brian Smith.
|
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
|
-
#include <openssl/bn.h>
|
16
|
-
|
17
|
-
#include <assert.h>
|
18
|
-
|
19
|
-
#include "internal.h"
|
20
|
-
#include "../internal.h"
|
21
|
-
|
22
|
-
|
23
|
-
static uint64_t bn_neg_inv_mod_r_u64(uint64_t n);
|
24
|
-
|
25
|
-
OPENSSL_COMPILE_ASSERT(BN_MONT_CTX_N0_LIMBS == 1 || BN_MONT_CTX_N0_LIMBS == 2,
|
26
|
-
BN_MONT_CTX_N0_LIMBS_VALUE_INVALID);
|
27
|
-
OPENSSL_COMPILE_ASSERT(sizeof(uint64_t) ==
|
28
|
-
BN_MONT_CTX_N0_LIMBS * sizeof(BN_ULONG),
|
29
|
-
BN_MONT_CTX_N0_LIMBS_DOES_NOT_MATCH_UINT64_T);
|
30
|
-
|
31
|
-
/* LG_LITTLE_R is log_2(r). */
|
32
|
-
#define LG_LITTLE_R (BN_MONT_CTX_N0_LIMBS * BN_BITS2)
|
33
|
-
|
34
|
-
uint64_t bn_mont_n0(const BIGNUM *n) {
|
35
|
-
/* These conditions are checked by the caller, |BN_MONT_CTX_set|. */
|
36
|
-
assert(!BN_is_zero(n));
|
37
|
-
assert(!BN_is_negative(n));
|
38
|
-
assert(BN_is_odd(n));
|
39
|
-
|
40
|
-
/* r == 2**(BN_MONT_CTX_N0_LIMBS * BN_BITS2) and LG_LITTLE_R == lg(r). This
|
41
|
-
* ensures that we can do integer division by |r| by simply ignoring
|
42
|
-
* |BN_MONT_CTX_N0_LIMBS| limbs. Similarly, we can calculate values modulo
|
43
|
-
* |r| by just looking at the lowest |BN_MONT_CTX_N0_LIMBS| limbs. This is
|
44
|
-
* what makes Montgomery multiplication efficient.
|
45
|
-
*
|
46
|
-
* As shown in Algorithm 1 of "Fast Prime Field Elliptic Curve Cryptography
|
47
|
-
* with 256 Bit Primes" by Shay Gueron and Vlad Krasnov, in the loop of a
|
48
|
-
* multi-limb Montgomery multiplication of |a * b (mod n)|, given the
|
49
|
-
* unreduced product |t == a * b|, we repeatedly calculate:
|
50
|
-
*
|
51
|
-
* t1 := t % r |t1| is |t|'s lowest limb (see previous paragraph).
|
52
|
-
* t2 := t1*n0*n
|
53
|
-
* t3 := t + t2
|
54
|
-
* t := t3 / r copy all limbs of |t3| except the lowest to |t|.
|
55
|
-
*
|
56
|
-
* In the last step, it would only make sense to ignore the lowest limb of
|
57
|
-
* |t3| if it were zero. The middle steps ensure that this is the case:
|
58
|
-
*
|
59
|
-
* t3 == 0 (mod r)
|
60
|
-
* t + t2 == 0 (mod r)
|
61
|
-
* t + t1*n0*n == 0 (mod r)
|
62
|
-
* t1*n0*n == -t (mod r)
|
63
|
-
* t*n0*n == -t (mod r)
|
64
|
-
* n0*n == -1 (mod r)
|
65
|
-
* n0 == -1/n (mod r)
|
66
|
-
*
|
67
|
-
* Thus, in each iteration of the loop, we multiply by the constant factor
|
68
|
-
* |n0|, the negative inverse of n (mod r). */
|
69
|
-
|
70
|
-
/* n_mod_r = n % r. As explained above, this is done by taking the lowest
|
71
|
-
* |BN_MONT_CTX_N0_LIMBS| limbs of |n|. */
|
72
|
-
uint64_t n_mod_r = n->d[0];
|
73
|
-
#if BN_MONT_CTX_N0_LIMBS == 2
|
74
|
-
if (n->top > 1) {
|
75
|
-
n_mod_r |= (uint64_t)n->d[1] << BN_BITS2;
|
76
|
-
}
|
77
|
-
#endif
|
78
|
-
|
79
|
-
return bn_neg_inv_mod_r_u64(n_mod_r);
|
80
|
-
}
|
81
|
-
|
82
|
-
/* bn_neg_inv_r_mod_n_u64 calculates the -1/n mod r; i.e. it calculates |v|
|
83
|
-
* such that u*r - v*n == 1. |r| is the constant defined in |bn_mont_n0|. |n|
|
84
|
-
* must be odd.
|
85
|
-
*
|
86
|
-
* This is derived from |xbinGCD| in Henry S. Warren, Jr.'s "Montgomery
|
87
|
-
* Multiplication" (http://www.hackersdelight.org/MontgomeryMultiplication.pdf).
|
88
|
-
* It is very similar to the MODULAR-INVERSE function in Stephen R. Dussé's and
|
89
|
-
* Burton S. Kaliski Jr.'s "A Cryptographic Library for the Motorola DSP56000"
|
90
|
-
* (http://link.springer.com/chapter/10.1007%2F3-540-46877-3_21).
|
91
|
-
*
|
92
|
-
* This is inspired by Joppe W. Bos's "Constant Time Modular Inversion"
|
93
|
-
* (http://www.joppebos.com/files/CTInversion.pdf) so that the inversion is
|
94
|
-
* constant-time with respect to |n|. We assume uint64_t additions,
|
95
|
-
* subtractions, shifts, and bitwise operations are all constant time, which
|
96
|
-
* may be a large leap of faith on 32-bit targets. We avoid division and
|
97
|
-
* multiplication, which tend to be the most problematic in terms of timing
|
98
|
-
* leaks.
|
99
|
-
*
|
100
|
-
* Most GCD implementations return values such that |u*r + v*n == 1|, so the
|
101
|
-
* caller would have to negate the resultant |v| for the purpose of Montgomery
|
102
|
-
* multiplication. This implementation does the negation implicitly by doing
|
103
|
-
* the computations as a difference instead of a sum. */
|
104
|
-
static uint64_t bn_neg_inv_mod_r_u64(uint64_t n) {
|
105
|
-
assert(n % 2 == 1);
|
106
|
-
|
107
|
-
/* alpha == 2**(lg r - 1) == r / 2. */
|
108
|
-
static const uint64_t alpha = UINT64_C(1) << (LG_LITTLE_R - 1);
|
109
|
-
|
110
|
-
const uint64_t beta = n;
|
111
|
-
|
112
|
-
uint64_t u = 1;
|
113
|
-
uint64_t v = 0;
|
114
|
-
|
115
|
-
/* The invariant maintained from here on is:
|
116
|
-
* 2**(lg r - i) == u*2*alpha - v*beta. */
|
117
|
-
for (size_t i = 0; i < LG_LITTLE_R; ++i) {
|
118
|
-
#if BN_BITS2 == 64 && defined(BN_ULLONG)
|
119
|
-
assert((BN_ULLONG)(1) << (LG_LITTLE_R - i) ==
|
120
|
-
((BN_ULLONG)u * 2 * alpha) - ((BN_ULLONG)v * beta));
|
121
|
-
#endif
|
122
|
-
|
123
|
-
/* Delete a common factor of 2 in u and v if |u| is even. Otherwise, set
|
124
|
-
* |u = (u + beta) / 2| and |v = (v / 2) + alpha|. */
|
125
|
-
|
126
|
-
uint64_t u_is_odd = UINT64_C(0) - (u & 1); /* Either 0xff..ff or 0. */
|
127
|
-
|
128
|
-
/* The addition can overflow, so use Dietz's method for it.
|
129
|
-
*
|
130
|
-
* Dietz calculates (x+y)/2 by (x⊕y)>>1 + x&y. This is valid for all
|
131
|
-
* (unsigned) x and y, even when x+y overflows. Evidence for 32-bit values
|
132
|
-
* (embedded in 64 bits to so that overflow can be ignored):
|
133
|
-
*
|
134
|
-
* (declare-fun x () (_ BitVec 64))
|
135
|
-
* (declare-fun y () (_ BitVec 64))
|
136
|
-
* (assert (let (
|
137
|
-
* (one (_ bv1 64))
|
138
|
-
* (thirtyTwo (_ bv32 64)))
|
139
|
-
* (and
|
140
|
-
* (bvult x (bvshl one thirtyTwo))
|
141
|
-
* (bvult y (bvshl one thirtyTwo))
|
142
|
-
* (not (=
|
143
|
-
* (bvadd (bvlshr (bvxor x y) one) (bvand x y))
|
144
|
-
* (bvlshr (bvadd x y) one)))
|
145
|
-
* )))
|
146
|
-
* (check-sat) */
|
147
|
-
uint64_t beta_if_u_is_odd = beta & u_is_odd; /* Either |beta| or 0. */
|
148
|
-
u = ((u ^ beta_if_u_is_odd) >> 1) + (u & beta_if_u_is_odd);
|
149
|
-
|
150
|
-
uint64_t alpha_if_u_is_odd = alpha & u_is_odd; /* Either |alpha| or 0. */
|
151
|
-
v = (v >> 1) + alpha_if_u_is_odd;
|
152
|
-
}
|
153
|
-
|
154
|
-
/* The invariant now shows that u*r - v*n == 1 since r == 2 * alpha. */
|
155
|
-
#if BN_BITS2 == 64 && defined(BN_ULLONG)
|
156
|
-
assert(1 == ((BN_ULLONG)u * 2 * alpha) - ((BN_ULLONG)v * beta));
|
157
|
-
#endif
|
158
|
-
|
159
|
-
return v;
|
160
|
-
}
|
161
|
-
|
162
|
-
/* bn_mod_exp_base_2_vartime calculates r = 2**p (mod n). |p| must be larger
|
163
|
-
* than log_2(n); i.e. 2**p must be larger than |n|. |n| must be positive and
|
164
|
-
* odd. */
|
165
|
-
int bn_mod_exp_base_2_vartime(BIGNUM *r, unsigned p, const BIGNUM *n) {
|
166
|
-
assert(!BN_is_zero(n));
|
167
|
-
assert(!BN_is_negative(n));
|
168
|
-
assert(BN_is_odd(n));
|
169
|
-
|
170
|
-
BN_zero(r);
|
171
|
-
|
172
|
-
unsigned n_bits = BN_num_bits(n);
|
173
|
-
assert(n_bits != 0);
|
174
|
-
if (n_bits == 1) {
|
175
|
-
return 1;
|
176
|
-
}
|
177
|
-
|
178
|
-
/* Set |r| to the smallest power of two larger than |n|. */
|
179
|
-
assert(p > n_bits);
|
180
|
-
if (!BN_set_bit(r, n_bits)) {
|
181
|
-
return 0;
|
182
|
-
}
|
183
|
-
|
184
|
-
/* Unconditionally reduce |r|. */
|
185
|
-
assert(BN_cmp(r, n) > 0);
|
186
|
-
if (!BN_usub(r, r, n)) {
|
187
|
-
return 0;
|
188
|
-
}
|
189
|
-
assert(BN_cmp(r, n) < 0);
|
190
|
-
|
191
|
-
for (unsigned i = n_bits; i < p; ++i) {
|
192
|
-
/* This is like |BN_mod_lshift1_quick| except using |BN_usub|.
|
193
|
-
*
|
194
|
-
* TODO: Replace this with the use of a constant-time variant of
|
195
|
-
* |BN_mod_lshift1_quick|. */
|
196
|
-
if (!BN_lshift1(r, r)) {
|
197
|
-
return 0;
|
198
|
-
}
|
199
|
-
if (BN_cmp(r, n) >= 0) {
|
200
|
-
if (!BN_usub(r, r, n)) {
|
201
|
-
return 0;
|
202
|
-
}
|
203
|
-
}
|
204
|
-
}
|
205
|
-
|
206
|
-
return 1;
|
207
|
-
}
|
@@ -1,871 +0,0 @@
|
|
1
|
-
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
2
|
-
* All rights reserved.
|
3
|
-
*
|
4
|
-
* This package is an SSL implementation written
|
5
|
-
* by Eric Young (eay@cryptsoft.com).
|
6
|
-
* The implementation was written so as to conform with Netscapes SSL.
|
7
|
-
*
|
8
|
-
* This library is free for commercial and non-commercial use as long as
|
9
|
-
* the following conditions are aheared to. The following conditions
|
10
|
-
* apply to all code found in this distribution, be it the RC4, RSA,
|
11
|
-
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
12
|
-
* included with this distribution is covered by the same copyright terms
|
13
|
-
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
14
|
-
*
|
15
|
-
* Copyright remains Eric Young's, and as such any Copyright notices in
|
16
|
-
* the code are not to be removed.
|
17
|
-
* If this package is used in a product, Eric Young should be given attribution
|
18
|
-
* as the author of the parts of the library used.
|
19
|
-
* This can be in the form of a textual message at program startup or
|
20
|
-
* in documentation (online or textual) provided with the package.
|
21
|
-
*
|
22
|
-
* Redistribution and use in source and binary forms, with or without
|
23
|
-
* modification, are permitted provided that the following conditions
|
24
|
-
* are met:
|
25
|
-
* 1. Redistributions of source code must retain the copyright
|
26
|
-
* notice, this list of conditions and the following disclaimer.
|
27
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
28
|
-
* notice, this list of conditions and the following disclaimer in the
|
29
|
-
* documentation and/or other materials provided with the distribution.
|
30
|
-
* 3. All advertising materials mentioning features or use of this software
|
31
|
-
* must display the following acknowledgement:
|
32
|
-
* "This product includes cryptographic software written by
|
33
|
-
* Eric Young (eay@cryptsoft.com)"
|
34
|
-
* The word 'cryptographic' can be left out if the rouines from the library
|
35
|
-
* being used are not cryptographic related :-).
|
36
|
-
* 4. If you include any Windows specific code (or a derivative thereof) from
|
37
|
-
* the apps directory (application code) you must include an acknowledgement:
|
38
|
-
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
39
|
-
*
|
40
|
-
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
41
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
43
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
44
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
46
|
-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
48
|
-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
49
|
-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
50
|
-
* SUCH DAMAGE.
|
51
|
-
*
|
52
|
-
* The licence and distribution terms for any publically available version or
|
53
|
-
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
54
|
-
* copied and put under another distribution licence
|
55
|
-
* [including the GNU Public Licence.] */
|
56
|
-
|
57
|
-
#include <openssl/bn.h>
|
58
|
-
|
59
|
-
#include <assert.h>
|
60
|
-
#include <string.h>
|
61
|
-
|
62
|
-
#include "internal.h"
|
63
|
-
|
64
|
-
|
65
|
-
#define BN_MUL_RECURSIVE_SIZE_NORMAL 16
|
66
|
-
#define BN_SQR_RECURSIVE_SIZE_NORMAL BN_MUL_RECURSIVE_SIZE_NORMAL
|
67
|
-
|
68
|
-
|
69
|
-
static void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b,
|
70
|
-
int nb) {
|
71
|
-
BN_ULONG *rr;
|
72
|
-
|
73
|
-
if (na < nb) {
|
74
|
-
int itmp;
|
75
|
-
BN_ULONG *ltmp;
|
76
|
-
|
77
|
-
itmp = na;
|
78
|
-
na = nb;
|
79
|
-
nb = itmp;
|
80
|
-
ltmp = a;
|
81
|
-
a = b;
|
82
|
-
b = ltmp;
|
83
|
-
}
|
84
|
-
rr = &(r[na]);
|
85
|
-
if (nb <= 0) {
|
86
|
-
(void)bn_mul_words(r, a, na, 0);
|
87
|
-
return;
|
88
|
-
} else {
|
89
|
-
rr[0] = bn_mul_words(r, a, na, b[0]);
|
90
|
-
}
|
91
|
-
|
92
|
-
for (;;) {
|
93
|
-
if (--nb <= 0) {
|
94
|
-
return;
|
95
|
-
}
|
96
|
-
rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);
|
97
|
-
if (--nb <= 0) {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);
|
101
|
-
if (--nb <= 0) {
|
102
|
-
return;
|
103
|
-
}
|
104
|
-
rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);
|
105
|
-
if (--nb <= 0) {
|
106
|
-
return;
|
107
|
-
}
|
108
|
-
rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
|
109
|
-
rr += 4;
|
110
|
-
r += 4;
|
111
|
-
b += 4;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
|
115
|
-
#if !defined(OPENSSL_X86) || defined(OPENSSL_NO_ASM)
|
116
|
-
/* Here follows specialised variants of bn_add_words() and bn_sub_words(). They
|
117
|
-
* have the property performing operations on arrays of different sizes. The
|
118
|
-
* sizes of those arrays is expressed through cl, which is the common length (
|
119
|
-
* basicall, min(len(a),len(b)) ), and dl, which is the delta between the two
|
120
|
-
* lengths, calculated as len(a)-len(b). All lengths are the number of
|
121
|
-
* BN_ULONGs... For the operations that require a result array as parameter,
|
122
|
-
* it must have the length cl+abs(dl). These functions should probably end up
|
123
|
-
* in bn_asm.c as soon as there are assembler counterparts for the systems that
|
124
|
-
* use assembler files. */
|
125
|
-
|
126
|
-
static BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a,
|
127
|
-
const BN_ULONG *b, int cl, int dl) {
|
128
|
-
BN_ULONG c, t;
|
129
|
-
|
130
|
-
assert(cl >= 0);
|
131
|
-
c = bn_sub_words(r, a, b, cl);
|
132
|
-
|
133
|
-
if (dl == 0) {
|
134
|
-
return c;
|
135
|
-
}
|
136
|
-
|
137
|
-
r += cl;
|
138
|
-
a += cl;
|
139
|
-
b += cl;
|
140
|
-
|
141
|
-
if (dl < 0) {
|
142
|
-
for (;;) {
|
143
|
-
t = b[0];
|
144
|
-
r[0] = (0 - t - c) & BN_MASK2;
|
145
|
-
if (t != 0) {
|
146
|
-
c = 1;
|
147
|
-
}
|
148
|
-
if (++dl >= 0) {
|
149
|
-
break;
|
150
|
-
}
|
151
|
-
|
152
|
-
t = b[1];
|
153
|
-
r[1] = (0 - t - c) & BN_MASK2;
|
154
|
-
if (t != 0) {
|
155
|
-
c = 1;
|
156
|
-
}
|
157
|
-
if (++dl >= 0) {
|
158
|
-
break;
|
159
|
-
}
|
160
|
-
|
161
|
-
t = b[2];
|
162
|
-
r[2] = (0 - t - c) & BN_MASK2;
|
163
|
-
if (t != 0) {
|
164
|
-
c = 1;
|
165
|
-
}
|
166
|
-
if (++dl >= 0) {
|
167
|
-
break;
|
168
|
-
}
|
169
|
-
|
170
|
-
t = b[3];
|
171
|
-
r[3] = (0 - t - c) & BN_MASK2;
|
172
|
-
if (t != 0) {
|
173
|
-
c = 1;
|
174
|
-
}
|
175
|
-
if (++dl >= 0) {
|
176
|
-
break;
|
177
|
-
}
|
178
|
-
|
179
|
-
b += 4;
|
180
|
-
r += 4;
|
181
|
-
}
|
182
|
-
} else {
|
183
|
-
int save_dl = dl;
|
184
|
-
while (c) {
|
185
|
-
t = a[0];
|
186
|
-
r[0] = (t - c) & BN_MASK2;
|
187
|
-
if (t != 0) {
|
188
|
-
c = 0;
|
189
|
-
}
|
190
|
-
if (--dl <= 0) {
|
191
|
-
break;
|
192
|
-
}
|
193
|
-
|
194
|
-
t = a[1];
|
195
|
-
r[1] = (t - c) & BN_MASK2;
|
196
|
-
if (t != 0) {
|
197
|
-
c = 0;
|
198
|
-
}
|
199
|
-
if (--dl <= 0) {
|
200
|
-
break;
|
201
|
-
}
|
202
|
-
|
203
|
-
t = a[2];
|
204
|
-
r[2] = (t - c) & BN_MASK2;
|
205
|
-
if (t != 0) {
|
206
|
-
c = 0;
|
207
|
-
}
|
208
|
-
if (--dl <= 0) {
|
209
|
-
break;
|
210
|
-
}
|
211
|
-
|
212
|
-
t = a[3];
|
213
|
-
r[3] = (t - c) & BN_MASK2;
|
214
|
-
if (t != 0) {
|
215
|
-
c = 0;
|
216
|
-
}
|
217
|
-
if (--dl <= 0) {
|
218
|
-
break;
|
219
|
-
}
|
220
|
-
|
221
|
-
save_dl = dl;
|
222
|
-
a += 4;
|
223
|
-
r += 4;
|
224
|
-
}
|
225
|
-
if (dl > 0) {
|
226
|
-
if (save_dl > dl) {
|
227
|
-
switch (save_dl - dl) {
|
228
|
-
case 1:
|
229
|
-
r[1] = a[1];
|
230
|
-
if (--dl <= 0) {
|
231
|
-
break;
|
232
|
-
}
|
233
|
-
case 2:
|
234
|
-
r[2] = a[2];
|
235
|
-
if (--dl <= 0) {
|
236
|
-
break;
|
237
|
-
}
|
238
|
-
case 3:
|
239
|
-
r[3] = a[3];
|
240
|
-
if (--dl <= 0) {
|
241
|
-
break;
|
242
|
-
}
|
243
|
-
}
|
244
|
-
a += 4;
|
245
|
-
r += 4;
|
246
|
-
}
|
247
|
-
}
|
248
|
-
|
249
|
-
if (dl > 0) {
|
250
|
-
for (;;) {
|
251
|
-
r[0] = a[0];
|
252
|
-
if (--dl <= 0) {
|
253
|
-
break;
|
254
|
-
}
|
255
|
-
r[1] = a[1];
|
256
|
-
if (--dl <= 0) {
|
257
|
-
break;
|
258
|
-
}
|
259
|
-
r[2] = a[2];
|
260
|
-
if (--dl <= 0) {
|
261
|
-
break;
|
262
|
-
}
|
263
|
-
r[3] = a[3];
|
264
|
-
if (--dl <= 0) {
|
265
|
-
break;
|
266
|
-
}
|
267
|
-
|
268
|
-
a += 4;
|
269
|
-
r += 4;
|
270
|
-
}
|
271
|
-
}
|
272
|
-
}
|
273
|
-
|
274
|
-
return c;
|
275
|
-
}
|
276
|
-
#else
|
277
|
-
/* On other platforms the function is defined in asm. */
|
278
|
-
BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
279
|
-
int cl, int dl);
|
280
|
-
#endif
|
281
|
-
|
282
|
-
/* Karatsuba recursive multiplication algorithm
|
283
|
-
* (cf. Knuth, The Art of Computer Programming, Vol. 2) */
|
284
|
-
|
285
|
-
/* r is 2*n2 words in size,
|
286
|
-
* a and b are both n2 words in size.
|
287
|
-
* n2 must be a power of 2.
|
288
|
-
* We multiply and return the result.
|
289
|
-
* t must be 2*n2 words in size
|
290
|
-
* We calculate
|
291
|
-
* a[0]*b[0]
|
292
|
-
* a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
|
293
|
-
* a[1]*b[1]
|
294
|
-
*/
|
295
|
-
/* dnX may not be positive, but n2/2+dnX has to be */
|
296
|
-
static void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
|
297
|
-
int dna, int dnb, BN_ULONG *t) {
|
298
|
-
int n = n2 / 2, c1, c2;
|
299
|
-
int tna = n + dna, tnb = n + dnb;
|
300
|
-
unsigned int neg, zero;
|
301
|
-
BN_ULONG ln, lo, *p;
|
302
|
-
|
303
|
-
/* Only call bn_mul_comba 8 if n2 == 8 and the
|
304
|
-
* two arrays are complete [steve]
|
305
|
-
*/
|
306
|
-
if (n2 == 8 && dna == 0 && dnb == 0) {
|
307
|
-
bn_mul_comba8(r, a, b);
|
308
|
-
return;
|
309
|
-
}
|
310
|
-
|
311
|
-
/* Else do normal multiply */
|
312
|
-
if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {
|
313
|
-
bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);
|
314
|
-
if ((dna + dnb) < 0) {
|
315
|
-
OPENSSL_memset(&r[2 * n2 + dna + dnb], 0,
|
316
|
-
sizeof(BN_ULONG) * -(dna + dnb));
|
317
|
-
}
|
318
|
-
return;
|
319
|
-
}
|
320
|
-
|
321
|
-
/* r=(a[0]-a[1])*(b[1]-b[0]) */
|
322
|
-
c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);
|
323
|
-
c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);
|
324
|
-
zero = neg = 0;
|
325
|
-
switch (c1 * 3 + c2) {
|
326
|
-
case -4:
|
327
|
-
bn_sub_part_words(t, &(a[n]), a, tna, tna - n); /* - */
|
328
|
-
bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb); /* - */
|
329
|
-
break;
|
330
|
-
case -3:
|
331
|
-
zero = 1;
|
332
|
-
break;
|
333
|
-
case -2:
|
334
|
-
bn_sub_part_words(t, &(a[n]), a, tna, tna - n); /* - */
|
335
|
-
bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n); /* + */
|
336
|
-
neg = 1;
|
337
|
-
break;
|
338
|
-
case -1:
|
339
|
-
case 0:
|
340
|
-
case 1:
|
341
|
-
zero = 1;
|
342
|
-
break;
|
343
|
-
case 2:
|
344
|
-
bn_sub_part_words(t, a, &(a[n]), tna, n - tna); /* + */
|
345
|
-
bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb); /* - */
|
346
|
-
neg = 1;
|
347
|
-
break;
|
348
|
-
case 3:
|
349
|
-
zero = 1;
|
350
|
-
break;
|
351
|
-
case 4:
|
352
|
-
bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
|
353
|
-
bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
|
354
|
-
break;
|
355
|
-
}
|
356
|
-
|
357
|
-
if (n == 4 && dna == 0 && dnb == 0) {
|
358
|
-
/* XXX: bn_mul_comba4 could take extra args to do this well */
|
359
|
-
if (!zero) {
|
360
|
-
bn_mul_comba4(&(t[n2]), t, &(t[n]));
|
361
|
-
} else {
|
362
|
-
OPENSSL_memset(&(t[n2]), 0, 8 * sizeof(BN_ULONG));
|
363
|
-
}
|
364
|
-
|
365
|
-
bn_mul_comba4(r, a, b);
|
366
|
-
bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));
|
367
|
-
} else if (n == 8 && dna == 0 && dnb == 0) {
|
368
|
-
/* XXX: bn_mul_comba8 could take extra args to do this well */
|
369
|
-
if (!zero) {
|
370
|
-
bn_mul_comba8(&(t[n2]), t, &(t[n]));
|
371
|
-
} else {
|
372
|
-
OPENSSL_memset(&(t[n2]), 0, 16 * sizeof(BN_ULONG));
|
373
|
-
}
|
374
|
-
|
375
|
-
bn_mul_comba8(r, a, b);
|
376
|
-
bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));
|
377
|
-
} else {
|
378
|
-
p = &(t[n2 * 2]);
|
379
|
-
if (!zero) {
|
380
|
-
bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
|
381
|
-
} else {
|
382
|
-
OPENSSL_memset(&(t[n2]), 0, n2 * sizeof(BN_ULONG));
|
383
|
-
}
|
384
|
-
bn_mul_recursive(r, a, b, n, 0, 0, p);
|
385
|
-
bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);
|
386
|
-
}
|
387
|
-
|
388
|
-
/* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
|
389
|
-
* r[10] holds (a[0]*b[0])
|
390
|
-
* r[32] holds (b[1]*b[1]) */
|
391
|
-
|
392
|
-
c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));
|
393
|
-
|
394
|
-
if (neg) {
|
395
|
-
/* if t[32] is negative */
|
396
|
-
c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));
|
397
|
-
} else {
|
398
|
-
/* Might have a carry */
|
399
|
-
c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));
|
400
|
-
}
|
401
|
-
|
402
|
-
/* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
|
403
|
-
* r[10] holds (a[0]*b[0])
|
404
|
-
* r[32] holds (b[1]*b[1])
|
405
|
-
* c1 holds the carry bits */
|
406
|
-
c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));
|
407
|
-
if (c1) {
|
408
|
-
p = &(r[n + n2]);
|
409
|
-
lo = *p;
|
410
|
-
ln = (lo + c1) & BN_MASK2;
|
411
|
-
*p = ln;
|
412
|
-
|
413
|
-
/* The overflow will stop before we over write
|
414
|
-
* words we should not overwrite */
|
415
|
-
if (ln < (BN_ULONG)c1) {
|
416
|
-
do {
|
417
|
-
p++;
|
418
|
-
lo = *p;
|
419
|
-
ln = (lo + 1) & BN_MASK2;
|
420
|
-
*p = ln;
|
421
|
-
} while (ln == 0);
|
422
|
-
}
|
423
|
-
}
|
424
|
-
}
|
425
|
-
|
426
|
-
/* n+tn is the word length
|
427
|
-
* t needs to be n*4 is size, as does r */
|
428
|
-
/* tnX may not be negative but less than n */
|
429
|
-
static void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
|
430
|
-
int tna, int tnb, BN_ULONG *t) {
|
431
|
-
int i, j, n2 = n * 2;
|
432
|
-
int c1, c2, neg;
|
433
|
-
BN_ULONG ln, lo, *p;
|
434
|
-
|
435
|
-
if (n < 8) {
|
436
|
-
bn_mul_normal(r, a, n + tna, b, n + tnb);
|
437
|
-
return;
|
438
|
-
}
|
439
|
-
|
440
|
-
/* r=(a[0]-a[1])*(b[1]-b[0]) */
|
441
|
-
c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);
|
442
|
-
c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);
|
443
|
-
neg = 0;
|
444
|
-
switch (c1 * 3 + c2) {
|
445
|
-
case -4:
|
446
|
-
bn_sub_part_words(t, &(a[n]), a, tna, tna - n); /* - */
|
447
|
-
bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb); /* - */
|
448
|
-
break;
|
449
|
-
case -3:
|
450
|
-
/* break; */
|
451
|
-
case -2:
|
452
|
-
bn_sub_part_words(t, &(a[n]), a, tna, tna - n); /* - */
|
453
|
-
bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n); /* + */
|
454
|
-
neg = 1;
|
455
|
-
break;
|
456
|
-
case -1:
|
457
|
-
case 0:
|
458
|
-
case 1:
|
459
|
-
/* break; */
|
460
|
-
case 2:
|
461
|
-
bn_sub_part_words(t, a, &(a[n]), tna, n - tna); /* + */
|
462
|
-
bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb); /* - */
|
463
|
-
neg = 1;
|
464
|
-
break;
|
465
|
-
case 3:
|
466
|
-
/* break; */
|
467
|
-
case 4:
|
468
|
-
bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
|
469
|
-
bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
|
470
|
-
break;
|
471
|
-
}
|
472
|
-
|
473
|
-
if (n == 8) {
|
474
|
-
bn_mul_comba8(&(t[n2]), t, &(t[n]));
|
475
|
-
bn_mul_comba8(r, a, b);
|
476
|
-
bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);
|
477
|
-
OPENSSL_memset(&(r[n2 + tna + tnb]), 0, sizeof(BN_ULONG) * (n2 - tna - tnb));
|
478
|
-
} else {
|
479
|
-
p = &(t[n2 * 2]);
|
480
|
-
bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
|
481
|
-
bn_mul_recursive(r, a, b, n, 0, 0, p);
|
482
|
-
i = n / 2;
|
483
|
-
/* If there is only a bottom half to the number,
|
484
|
-
* just do it */
|
485
|
-
if (tna > tnb) {
|
486
|
-
j = tna - i;
|
487
|
-
} else {
|
488
|
-
j = tnb - i;
|
489
|
-
}
|
490
|
-
|
491
|
-
if (j == 0) {
|
492
|
-
bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), i, tna - i, tnb - i, p);
|
493
|
-
OPENSSL_memset(&(r[n2 + i * 2]), 0, sizeof(BN_ULONG) * (n2 - i * 2));
|
494
|
-
} else if (j > 0) {
|
495
|
-
/* eg, n == 16, i == 8 and tn == 11 */
|
496
|
-
bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]), i, tna - i, tnb - i, p);
|
497
|
-
OPENSSL_memset(&(r[n2 + tna + tnb]), 0,
|
498
|
-
sizeof(BN_ULONG) * (n2 - tna - tnb));
|
499
|
-
} else {
|
500
|
-
/* (j < 0) eg, n == 16, i == 8 and tn == 5 */
|
501
|
-
OPENSSL_memset(&(r[n2]), 0, sizeof(BN_ULONG) * n2);
|
502
|
-
if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL &&
|
503
|
-
tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {
|
504
|
-
bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);
|
505
|
-
} else {
|
506
|
-
for (;;) {
|
507
|
-
i /= 2;
|
508
|
-
/* these simplified conditions work
|
509
|
-
* exclusively because difference
|
510
|
-
* between tna and tnb is 1 or 0 */
|
511
|
-
if (i < tna || i < tnb) {
|
512
|
-
bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]), i, tna - i,
|
513
|
-
tnb - i, p);
|
514
|
-
break;
|
515
|
-
} else if (i == tna || i == tnb) {
|
516
|
-
bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), i, tna - i, tnb - i,
|
517
|
-
p);
|
518
|
-
break;
|
519
|
-
}
|
520
|
-
}
|
521
|
-
}
|
522
|
-
}
|
523
|
-
}
|
524
|
-
|
525
|
-
/* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
|
526
|
-
* r[10] holds (a[0]*b[0])
|
527
|
-
* r[32] holds (b[1]*b[1])
|
528
|
-
*/
|
529
|
-
|
530
|
-
c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));
|
531
|
-
|
532
|
-
if (neg) {
|
533
|
-
/* if t[32] is negative */
|
534
|
-
c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));
|
535
|
-
} else {
|
536
|
-
/* Might have a carry */
|
537
|
-
c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));
|
538
|
-
}
|
539
|
-
|
540
|
-
/* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
|
541
|
-
* r[10] holds (a[0]*b[0])
|
542
|
-
* r[32] holds (b[1]*b[1])
|
543
|
-
* c1 holds the carry bits */
|
544
|
-
c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));
|
545
|
-
if (c1) {
|
546
|
-
p = &(r[n + n2]);
|
547
|
-
lo = *p;
|
548
|
-
ln = (lo + c1) & BN_MASK2;
|
549
|
-
*p = ln;
|
550
|
-
|
551
|
-
/* The overflow will stop before we over write
|
552
|
-
* words we should not overwrite */
|
553
|
-
if (ln < (BN_ULONG)c1) {
|
554
|
-
do {
|
555
|
-
p++;
|
556
|
-
lo = *p;
|
557
|
-
ln = (lo + 1) & BN_MASK2;
|
558
|
-
*p = ln;
|
559
|
-
} while (ln == 0);
|
560
|
-
}
|
561
|
-
}
|
562
|
-
}
|
563
|
-
|
564
|
-
int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
|
565
|
-
int ret = 0;
|
566
|
-
int top, al, bl;
|
567
|
-
BIGNUM *rr;
|
568
|
-
int i;
|
569
|
-
BIGNUM *t = NULL;
|
570
|
-
int j = 0, k;
|
571
|
-
|
572
|
-
al = a->top;
|
573
|
-
bl = b->top;
|
574
|
-
|
575
|
-
if ((al == 0) || (bl == 0)) {
|
576
|
-
BN_zero(r);
|
577
|
-
return 1;
|
578
|
-
}
|
579
|
-
top = al + bl;
|
580
|
-
|
581
|
-
BN_CTX_start(ctx);
|
582
|
-
if ((r == a) || (r == b)) {
|
583
|
-
if ((rr = BN_CTX_get(ctx)) == NULL) {
|
584
|
-
goto err;
|
585
|
-
}
|
586
|
-
} else {
|
587
|
-
rr = r;
|
588
|
-
}
|
589
|
-
rr->neg = a->neg ^ b->neg;
|
590
|
-
|
591
|
-
i = al - bl;
|
592
|
-
if (i == 0) {
|
593
|
-
if (al == 8) {
|
594
|
-
if (bn_wexpand(rr, 16) == NULL) {
|
595
|
-
goto err;
|
596
|
-
}
|
597
|
-
rr->top = 16;
|
598
|
-
bn_mul_comba8(rr->d, a->d, b->d);
|
599
|
-
goto end;
|
600
|
-
}
|
601
|
-
}
|
602
|
-
|
603
|
-
static const int kMulNormalSize = 16;
|
604
|
-
if (al >= kMulNormalSize && bl >= kMulNormalSize) {
|
605
|
-
if (i >= -1 && i <= 1) {
|
606
|
-
/* Find out the power of two lower or equal
|
607
|
-
to the longest of the two numbers */
|
608
|
-
if (i >= 0) {
|
609
|
-
j = BN_num_bits_word((BN_ULONG)al);
|
610
|
-
}
|
611
|
-
if (i == -1) {
|
612
|
-
j = BN_num_bits_word((BN_ULONG)bl);
|
613
|
-
}
|
614
|
-
j = 1 << (j - 1);
|
615
|
-
assert(j <= al || j <= bl);
|
616
|
-
k = j + j;
|
617
|
-
t = BN_CTX_get(ctx);
|
618
|
-
if (t == NULL) {
|
619
|
-
goto err;
|
620
|
-
}
|
621
|
-
if (al > j || bl > j) {
|
622
|
-
if (bn_wexpand(t, k * 4) == NULL) {
|
623
|
-
goto err;
|
624
|
-
}
|
625
|
-
if (bn_wexpand(rr, k * 4) == NULL) {
|
626
|
-
goto err;
|
627
|
-
}
|
628
|
-
bn_mul_part_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);
|
629
|
-
} else {
|
630
|
-
/* al <= j || bl <= j */
|
631
|
-
if (bn_wexpand(t, k * 2) == NULL) {
|
632
|
-
goto err;
|
633
|
-
}
|
634
|
-
if (bn_wexpand(rr, k * 2) == NULL) {
|
635
|
-
goto err;
|
636
|
-
}
|
637
|
-
bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);
|
638
|
-
}
|
639
|
-
rr->top = top;
|
640
|
-
goto end;
|
641
|
-
}
|
642
|
-
}
|
643
|
-
|
644
|
-
if (bn_wexpand(rr, top) == NULL) {
|
645
|
-
goto err;
|
646
|
-
}
|
647
|
-
rr->top = top;
|
648
|
-
bn_mul_normal(rr->d, a->d, al, b->d, bl);
|
649
|
-
|
650
|
-
end:
|
651
|
-
bn_correct_top(rr);
|
652
|
-
if (r != rr && !BN_copy(r, rr)) {
|
653
|
-
goto err;
|
654
|
-
}
|
655
|
-
ret = 1;
|
656
|
-
|
657
|
-
err:
|
658
|
-
BN_CTX_end(ctx);
|
659
|
-
return ret;
|
660
|
-
}
|
661
|
-
|
662
|
-
/* tmp must have 2*n words */
|
663
|
-
static void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) {
|
664
|
-
int i, j, max;
|
665
|
-
const BN_ULONG *ap;
|
666
|
-
BN_ULONG *rp;
|
667
|
-
|
668
|
-
max = n * 2;
|
669
|
-
ap = a;
|
670
|
-
rp = r;
|
671
|
-
rp[0] = rp[max - 1] = 0;
|
672
|
-
rp++;
|
673
|
-
j = n;
|
674
|
-
|
675
|
-
if (--j > 0) {
|
676
|
-
ap++;
|
677
|
-
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
|
678
|
-
rp += 2;
|
679
|
-
}
|
680
|
-
|
681
|
-
for (i = n - 2; i > 0; i--) {
|
682
|
-
j--;
|
683
|
-
ap++;
|
684
|
-
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
|
685
|
-
rp += 2;
|
686
|
-
}
|
687
|
-
|
688
|
-
bn_add_words(r, r, r, max);
|
689
|
-
|
690
|
-
/* There will not be a carry */
|
691
|
-
|
692
|
-
bn_sqr_words(tmp, a, n);
|
693
|
-
|
694
|
-
bn_add_words(r, r, tmp, max);
|
695
|
-
}
|
696
|
-
|
697
|
-
/* r is 2*n words in size,
|
698
|
-
* a and b are both n words in size. (There's not actually a 'b' here ...)
|
699
|
-
* n must be a power of 2.
|
700
|
-
* We multiply and return the result.
|
701
|
-
* t must be 2*n words in size
|
702
|
-
* We calculate
|
703
|
-
* a[0]*b[0]
|
704
|
-
* a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
|
705
|
-
* a[1]*b[1]
|
706
|
-
*/
|
707
|
-
static void bn_sqr_recursive(BN_ULONG *r, const BN_ULONG *a, int n2, BN_ULONG *t) {
|
708
|
-
int n = n2 / 2;
|
709
|
-
int zero, c1;
|
710
|
-
BN_ULONG ln, lo, *p;
|
711
|
-
|
712
|
-
if (n2 == 4) {
|
713
|
-
bn_sqr_comba4(r, a);
|
714
|
-
return;
|
715
|
-
} else if (n2 == 8) {
|
716
|
-
bn_sqr_comba8(r, a);
|
717
|
-
return;
|
718
|
-
}
|
719
|
-
if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) {
|
720
|
-
bn_sqr_normal(r, a, n2, t);
|
721
|
-
return;
|
722
|
-
}
|
723
|
-
/* r=(a[0]-a[1])*(a[1]-a[0]) */
|
724
|
-
c1 = bn_cmp_words(a, &(a[n]), n);
|
725
|
-
zero = 0;
|
726
|
-
if (c1 > 0) {
|
727
|
-
bn_sub_words(t, a, &(a[n]), n);
|
728
|
-
} else if (c1 < 0) {
|
729
|
-
bn_sub_words(t, &(a[n]), a, n);
|
730
|
-
} else {
|
731
|
-
zero = 1;
|
732
|
-
}
|
733
|
-
|
734
|
-
/* The result will always be negative unless it is zero */
|
735
|
-
p = &(t[n2 * 2]);
|
736
|
-
|
737
|
-
if (!zero) {
|
738
|
-
bn_sqr_recursive(&(t[n2]), t, n, p);
|
739
|
-
} else {
|
740
|
-
OPENSSL_memset(&(t[n2]), 0, n2 * sizeof(BN_ULONG));
|
741
|
-
}
|
742
|
-
bn_sqr_recursive(r, a, n, p);
|
743
|
-
bn_sqr_recursive(&(r[n2]), &(a[n]), n, p);
|
744
|
-
|
745
|
-
/* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero
|
746
|
-
* r[10] holds (a[0]*b[0])
|
747
|
-
* r[32] holds (b[1]*b[1]) */
|
748
|
-
|
749
|
-
c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));
|
750
|
-
|
751
|
-
/* t[32] is negative */
|
752
|
-
c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));
|
753
|
-
|
754
|
-
/* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1])
|
755
|
-
* r[10] holds (a[0]*a[0])
|
756
|
-
* r[32] holds (a[1]*a[1])
|
757
|
-
* c1 holds the carry bits */
|
758
|
-
c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));
|
759
|
-
if (c1) {
|
760
|
-
p = &(r[n + n2]);
|
761
|
-
lo = *p;
|
762
|
-
ln = (lo + c1) & BN_MASK2;
|
763
|
-
*p = ln;
|
764
|
-
|
765
|
-
/* The overflow will stop before we over write
|
766
|
-
* words we should not overwrite */
|
767
|
-
if (ln < (BN_ULONG)c1) {
|
768
|
-
do {
|
769
|
-
p++;
|
770
|
-
lo = *p;
|
771
|
-
ln = (lo + 1) & BN_MASK2;
|
772
|
-
*p = ln;
|
773
|
-
} while (ln == 0);
|
774
|
-
}
|
775
|
-
}
|
776
|
-
}
|
777
|
-
|
778
|
-
int BN_mul_word(BIGNUM *bn, BN_ULONG w) {
|
779
|
-
BN_ULONG ll;
|
780
|
-
|
781
|
-
w &= BN_MASK2;
|
782
|
-
if (!bn->top) {
|
783
|
-
return 1;
|
784
|
-
}
|
785
|
-
|
786
|
-
if (w == 0) {
|
787
|
-
BN_zero(bn);
|
788
|
-
return 1;
|
789
|
-
}
|
790
|
-
|
791
|
-
ll = bn_mul_words(bn->d, bn->d, bn->top, w);
|
792
|
-
if (ll) {
|
793
|
-
if (bn_wexpand(bn, bn->top + 1) == NULL) {
|
794
|
-
return 0;
|
795
|
-
}
|
796
|
-
bn->d[bn->top++] = ll;
|
797
|
-
}
|
798
|
-
|
799
|
-
return 1;
|
800
|
-
}
|
801
|
-
|
802
|
-
int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) {
|
803
|
-
int max, al;
|
804
|
-
int ret = 0;
|
805
|
-
BIGNUM *tmp, *rr;
|
806
|
-
|
807
|
-
al = a->top;
|
808
|
-
if (al <= 0) {
|
809
|
-
r->top = 0;
|
810
|
-
r->neg = 0;
|
811
|
-
return 1;
|
812
|
-
}
|
813
|
-
|
814
|
-
BN_CTX_start(ctx);
|
815
|
-
rr = (a != r) ? r : BN_CTX_get(ctx);
|
816
|
-
tmp = BN_CTX_get(ctx);
|
817
|
-
if (!rr || !tmp) {
|
818
|
-
goto err;
|
819
|
-
}
|
820
|
-
|
821
|
-
max = 2 * al; /* Non-zero (from above) */
|
822
|
-
if (bn_wexpand(rr, max) == NULL) {
|
823
|
-
goto err;
|
824
|
-
}
|
825
|
-
|
826
|
-
if (al == 4) {
|
827
|
-
bn_sqr_comba4(rr->d, a->d);
|
828
|
-
} else if (al == 8) {
|
829
|
-
bn_sqr_comba8(rr->d, a->d);
|
830
|
-
} else {
|
831
|
-
if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {
|
832
|
-
BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];
|
833
|
-
bn_sqr_normal(rr->d, a->d, al, t);
|
834
|
-
} else {
|
835
|
-
int j, k;
|
836
|
-
|
837
|
-
j = BN_num_bits_word((BN_ULONG)al);
|
838
|
-
j = 1 << (j - 1);
|
839
|
-
k = j + j;
|
840
|
-
if (al == j) {
|
841
|
-
if (bn_wexpand(tmp, k * 2) == NULL) {
|
842
|
-
goto err;
|
843
|
-
}
|
844
|
-
bn_sqr_recursive(rr->d, a->d, al, tmp->d);
|
845
|
-
} else {
|
846
|
-
if (bn_wexpand(tmp, max) == NULL) {
|
847
|
-
goto err;
|
848
|
-
}
|
849
|
-
bn_sqr_normal(rr->d, a->d, al, tmp->d);
|
850
|
-
}
|
851
|
-
}
|
852
|
-
}
|
853
|
-
|
854
|
-
rr->neg = 0;
|
855
|
-
/* If the most-significant half of the top word of 'a' is zero, then
|
856
|
-
* the square of 'a' will max-1 words. */
|
857
|
-
if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l)) {
|
858
|
-
rr->top = max - 1;
|
859
|
-
} else {
|
860
|
-
rr->top = max;
|
861
|
-
}
|
862
|
-
|
863
|
-
if (rr != r && !BN_copy(r, rr)) {
|
864
|
-
goto err;
|
865
|
-
}
|
866
|
-
ret = 1;
|
867
|
-
|
868
|
-
err:
|
869
|
-
BN_CTX_end(ctx);
|
870
|
-
return ret;
|
871
|
-
}
|