awesome-grpc-that-works 0.12.2 → 0.14.0.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/Makefile +5783 -22121
- data/include/grpc/byte_buffer.h +2 -83
- data/include/grpc/census.h +173 -121
- data/include/grpc/compression.h +14 -38
- data/include/grpc/grpc.h +85 -434
- data/include/grpc/grpc_security.h +76 -46
- data/include/grpc/grpc_zookeeper.h +1 -1
- data/include/grpc/impl/codegen/alloc.h +74 -0
- data/include/grpc/impl/codegen/atm.h +92 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +72 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +87 -0
- data/include/grpc/impl/codegen/atm_win32.h +125 -0
- data/include/grpc/impl/codegen/byte_buffer.h +121 -0
- data/include/grpc/impl/codegen/compression_types.h +73 -0
- data/include/grpc/impl/codegen/connectivity_state.h +59 -0
- data/include/grpc/impl/codegen/grpc_types.h +378 -0
- data/include/grpc/impl/codegen/log.h +110 -0
- data/include/grpc/impl/codegen/port_platform.h +370 -0
- data/include/grpc/impl/codegen/propagation_bits.h +67 -0
- data/include/grpc/impl/codegen/slice.h +182 -0
- data/include/grpc/impl/codegen/slice_buffer.h +105 -0
- data/include/grpc/impl/codegen/status.h +163 -0
- data/include/grpc/impl/codegen/sync.h +316 -0
- data/include/grpc/impl/codegen/sync_generic.h +55 -0
- data/{src/core/census/context.h → include/grpc/impl/codegen/sync_posix.h} +11 -11
- data/include/grpc/impl/codegen/sync_win32.h +49 -0
- data/include/grpc/impl/codegen/time.h +130 -0
- data/include/grpc/status.h +2 -126
- data/include/grpc/support/alloc.h +2 -35
- data/include/grpc/support/atm.h +2 -55
- data/include/grpc/support/atm_gcc_atomic.h +5 -38
- data/include/grpc/support/atm_gcc_sync.h +2 -50
- data/include/grpc/support/atm_win32.h +2 -88
- data/include/grpc/support/avl.h +10 -9
- data/include/grpc/support/cmdline.h +15 -13
- data/include/grpc/support/cpu.h +5 -3
- data/include/grpc/support/histogram.h +23 -20
- data/include/grpc/support/host_port.h +5 -3
- data/include/grpc/support/log.h +2 -71
- data/include/grpc/support/log_win32.h +2 -2
- data/include/grpc/support/port_platform.h +2 -319
- data/include/grpc/support/slice.h +2 -145
- data/include/grpc/support/slice_buffer.h +2 -65
- data/include/grpc/support/string_util.h +3 -3
- data/include/grpc/support/subprocess.h +8 -6
- data/include/grpc/support/sync.h +2 -278
- data/include/grpc/support/sync_generic.h +2 -18
- data/include/grpc/support/sync_posix.h +2 -10
- data/include/grpc/support/sync_win32.h +2 -12
- data/include/grpc/support/thd.h +11 -11
- data/include/grpc/support/time.h +2 -91
- data/include/grpc/support/tls.h +1 -1
- data/include/grpc/support/tls_gcc.h +1 -1
- data/include/grpc/support/tls_msvc.h +1 -1
- data/include/grpc/support/tls_pthread.h +2 -2
- data/include/grpc/support/useful.h +3 -1
- data/src/boringssl/err_data.c +1252 -0
- data/src/core/census/context.c +471 -8
- data/src/core/census/grpc_filter.c +5 -5
- data/src/core/census/initialize.c +4 -7
- data/src/core/census/mlog.c +600 -0
- data/src/core/census/mlog.h +95 -0
- data/src/core/census/operation.c +2 -2
- data/src/core/census/placeholders.c +109 -0
- data/src/core/census/rpc_metric_id.h +6 -6
- data/src/core/census/tracing.c +1 -1
- data/src/core/channel/channel_args.c +71 -9
- data/src/core/channel/channel_args.h +7 -1
- data/src/core/channel/channel_stack.c +1 -1
- data/src/core/channel/client_channel.c +33 -30
- data/src/core/channel/client_uchannel.c +3 -3
- data/src/core/channel/compress_filter.c +8 -8
- data/src/core/channel/http_client_filter.c +4 -4
- data/src/core/channel/http_server_filter.c +11 -11
- data/src/core/channel/subchannel_call_holder.c +11 -11
- data/src/core/client_config/connector.c +3 -2
- data/src/core/client_config/connector.h +2 -2
- data/src/core/client_config/lb_policies/load_balancer_api.c +163 -0
- data/src/core/client_config/lb_policies/load_balancer_api.h +85 -0
- data/src/core/client_config/lb_policies/pick_first.c +57 -40
- data/src/core/client_config/lb_policies/round_robin.c +14 -15
- data/src/core/client_config/lb_policy.c +3 -3
- data/src/core/client_config/lb_policy.h +3 -2
- data/src/core/client_config/resolvers/dns_resolver.c +3 -3
- data/src/core/client_config/resolvers/sockaddr_resolver.c +5 -5
- data/src/core/client_config/subchannel.c +84 -39
- data/src/core/client_config/subchannel.h +15 -6
- data/src/core/client_config/subchannel_index.c +261 -0
- data/src/core/client_config/subchannel_index.h +77 -0
- data/src/core/compression/{algorithm.c → compression_algorithm.c} +3 -3
- data/src/core/httpcli/format_request.c +1 -1
- data/src/core/httpcli/httpcli.c +18 -16
- data/src/core/httpcli/httpcli.h +3 -2
- data/src/core/httpcli/httpcli_security_connector.c +9 -10
- data/src/core/httpcli/parser.c +7 -7
- data/src/core/httpcli/parser.h +1 -1
- data/src/core/iomgr/closure.c +7 -7
- data/src/core/iomgr/closure.h +6 -5
- data/src/core/iomgr/exec_ctx.c +12 -8
- data/src/core/iomgr/exec_ctx.h +12 -5
- data/src/core/iomgr/executor.c +4 -4
- data/src/core/iomgr/executor.h +2 -2
- data/src/core/iomgr/fd_posix.c +32 -19
- data/src/core/iomgr/fd_posix.h +7 -4
- data/src/core/iomgr/iocp_windows.c +7 -9
- data/src/core/iomgr/iomgr.c +2 -2
- data/src/core/iomgr/pollset.h +9 -10
- data/src/core/iomgr/pollset_multipoller_with_epoll.c +71 -5
- data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +9 -5
- data/src/core/iomgr/pollset_posix.c +44 -49
- data/src/core/iomgr/pollset_posix.h +14 -8
- data/src/core/iomgr/pollset_set.h +3 -9
- data/src/core/iomgr/pollset_set_posix.c +23 -3
- data/src/core/iomgr/pollset_set_posix.h +2 -18
- data/src/core/iomgr/pollset_set_windows.c +3 -3
- data/src/core/iomgr/pollset_set_windows.h +2 -2
- data/src/core/iomgr/pollset_windows.c +29 -37
- data/src/core/iomgr/pollset_windows.h +1 -5
- data/src/core/iomgr/resolve_address_posix.c +2 -2
- data/src/core/iomgr/resolve_address_windows.c +2 -2
- data/src/core/iomgr/sockaddr_utils.c +6 -6
- data/src/core/iomgr/sockaddr_win32.h +1 -6
- data/src/core/iomgr/tcp_client_posix.c +14 -12
- data/src/core/iomgr/tcp_client_windows.c +4 -4
- data/src/core/iomgr/tcp_posix.c +18 -10
- data/src/core/iomgr/tcp_posix.h +7 -1
- data/src/core/iomgr/tcp_server.h +40 -20
- data/src/core/iomgr/tcp_server_posix.c +106 -49
- data/src/core/iomgr/tcp_server_windows.c +98 -49
- data/src/core/iomgr/tcp_windows.c +11 -15
- data/src/core/iomgr/timer.c +10 -11
- data/src/core/iomgr/timer.h +22 -2
- data/src/core/iomgr/timer_heap.c +10 -10
- data/src/core/iomgr/timer_heap.h +2 -2
- data/src/core/iomgr/udp_server.c +7 -16
- data/src/core/iomgr/udp_server.h +2 -9
- data/src/core/iomgr/workqueue.h +2 -4
- data/src/core/iomgr/workqueue_posix.c +4 -3
- data/src/core/iomgr/workqueue_posix.h +3 -1
- data/src/core/json/json_reader.c +11 -12
- data/src/core/json/json_reader.h +4 -4
- data/src/core/json/json_string.c +19 -19
- data/src/core/json/json_writer.c +7 -9
- data/src/core/profiling/basic_timers.c +1 -1
- data/src/core/proto/grpc/lb/v0/load_balancer.pb.c +119 -0
- data/src/core/proto/grpc/lb/v0/load_balancer.pb.h +182 -0
- data/src/core/security/{base64.c → b64.c} +10 -10
- data/src/core/security/{base64.h → b64.h} +1 -1
- data/src/core/security/client_auth_filter.c +4 -5
- data/src/core/security/credentials.c +17 -10
- data/src/core/security/credentials.h +3 -3
- data/src/core/security/google_default_credentials.c +27 -22
- data/src/core/security/handshake.c +21 -12
- data/src/core/security/handshake.h +2 -1
- data/src/core/security/json_token.c +14 -8
- data/src/core/security/jwt_verifier.c +4 -3
- data/src/core/security/secure_endpoint.c +16 -16
- data/src/core/security/security_connector.c +131 -81
- data/src/core/security/security_connector.h +47 -27
- data/src/core/security/security_context.c +8 -3
- data/src/core/security/server_auth_filter.c +5 -5
- data/src/core/security/server_secure_chttp2.c +36 -37
- data/src/core/statistics/census_interface.h +2 -2
- data/src/core/statistics/census_rpc_stats.h +3 -3
- data/src/core/support/alloc.c +1 -1
- data/src/core/support/avl.c +2 -2
- data/src/core/support/cpu_posix.c +2 -2
- data/src/core/support/env_linux.c +28 -1
- data/src/core/support/env_win32.c +15 -7
- data/src/core/support/histogram.c +5 -5
- data/src/core/support/{file.c → load_file.c} +2 -2
- data/src/core/support/{file.h → load_file.h} +4 -12
- data/src/core/support/log_posix.c +1 -1
- data/src/core/support/log_win32.c +4 -3
- data/src/core/support/murmur_hash.c +11 -11
- data/src/core/support/murmur_hash.h +1 -1
- data/src/core/support/slice.c +11 -11
- data/src/core/support/slice_buffer.c +6 -6
- data/src/core/support/stack_lockfree.c +20 -10
- data/src/core/support/string.c +15 -15
- data/src/core/support/string.h +5 -5
- data/src/core/support/string_win32.c +5 -5
- data/src/core/support/subprocess_windows.c +141 -0
- data/src/core/support/sync.c +4 -4
- data/src/core/support/sync_posix.c +2 -2
- data/src/core/support/sync_win32.c +10 -5
- data/src/core/support/time.c +29 -29
- data/src/core/support/time_posix.c +15 -6
- data/src/core/support/time_precise.c +2 -2
- data/src/core/support/time_win32.c +18 -9
- data/src/core/support/tls_pthread.c +1 -1
- data/src/core/support/tmpfile.h +55 -0
- data/src/core/support/{file_posix.c → tmpfile_posix.c} +2 -2
- data/src/core/support/{file_win32.c → tmpfile_win32.c} +2 -2
- data/src/core/support/wrap_memcpy.c +53 -0
- data/src/core/surface/alarm.c +84 -0
- data/src/core/surface/byte_buffer_reader.c +1 -1
- data/src/core/surface/call.c +175 -116
- data/src/core/surface/call.h +2 -2
- data/src/core/surface/call_test_only.h +2 -2
- data/src/core/surface/channel.c +9 -9
- data/src/core/surface/channel.h +1 -1
- data/src/core/surface/channel_connectivity.c +3 -3
- data/src/core/surface/channel_create.c +4 -4
- data/src/core/surface/channel_ping.c +2 -2
- data/src/core/surface/completion_queue.c +84 -53
- data/src/core/surface/completion_queue.h +1 -1
- data/src/core/surface/init.c +11 -5
- data/src/core/surface/lame_client.c +2 -3
- data/src/core/surface/secure_channel_create.c +9 -10
- data/src/core/surface/server.c +30 -30
- data/src/core/surface/server_chttp2.c +8 -8
- data/src/core/surface/server_create.c +1 -4
- data/src/core/surface/validate_metadata.c +4 -4
- data/src/core/surface/version.c +2 -2
- data/src/core/transport/byte_stream.c +8 -6
- data/src/core/transport/byte_stream.h +6 -5
- data/src/core/transport/chttp2/bin_encoder.c +29 -29
- data/src/core/transport/chttp2/frame_data.c +29 -26
- data/src/core/transport/chttp2/frame_data.h +6 -6
- data/src/core/transport/chttp2/frame_goaway.c +30 -30
- data/src/core/transport/chttp2/frame_goaway.h +6 -6
- data/src/core/transport/chttp2/frame_ping.c +6 -6
- data/src/core/transport/chttp2/frame_ping.h +5 -5
- data/src/core/transport/chttp2/frame_rst_stream.c +18 -19
- data/src/core/transport/chttp2/frame_rst_stream.h +4 -4
- data/src/core/transport/chttp2/frame_settings.c +30 -30
- data/src/core/transport/chttp2/frame_settings.h +13 -13
- data/src/core/transport/chttp2/frame_window_update.c +17 -18
- data/src/core/transport/chttp2/frame_window_update.h +5 -7
- data/src/core/transport/chttp2/hpack_encoder.c +69 -73
- data/src/core/transport/chttp2/hpack_encoder.h +16 -16
- data/src/core/transport/chttp2/hpack_parser.c +167 -167
- data/src/core/transport/chttp2/hpack_parser.h +16 -16
- data/src/core/transport/chttp2/hpack_table.c +13 -13
- data/src/core/transport/chttp2/hpack_table.h +11 -11
- data/src/core/transport/chttp2/internal.h +103 -87
- data/src/core/transport/chttp2/parsing.c +25 -25
- data/src/core/transport/chttp2/stream_lists.c +38 -1
- data/src/core/transport/chttp2/stream_map.c +13 -14
- data/src/core/transport/chttp2/stream_map.h +6 -7
- data/src/core/transport/chttp2/timeout_encoding.c +19 -16
- data/src/core/transport/chttp2/varint.c +8 -9
- data/src/core/transport/chttp2/varint.h +7 -8
- data/src/core/transport/chttp2/writing.c +25 -22
- data/src/core/transport/chttp2_transport.c +147 -100
- data/src/core/transport/connectivity_state.c +6 -6
- data/src/core/transport/metadata.c +18 -18
- data/src/core/transport/metadata.h +5 -5
- data/src/core/transport/static_metadata.c +32 -33
- data/src/core/transport/static_metadata.h +8 -8
- data/src/core/transport/transport.c +6 -5
- data/src/core/transport/transport.h +17 -1
- data/src/core/tsi/fake_transport_security.c +7 -7
- data/src/core/tsi/ssl_transport_security.c +6 -4
- data/src/core/{iomgr/timer_internal.h → tsi/ssl_types.h} +19 -25
- data/src/ruby/ext/grpc/extconf.rb +52 -14
- data/src/ruby/ext/grpc/rb_byte_buffer.c +3 -1
- data/src/ruby/ext/grpc/rb_call.c +7 -3
- data/src/ruby/ext/grpc/rb_call_credentials.c +4 -0
- data/src/ruby/ext/grpc/rb_channel.c +4 -2
- data/src/ruby/ext/grpc/rb_channel_args.c +3 -1
- data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -1
- data/src/ruby/ext/grpc/rb_completion_queue.c +3 -1
- data/src/ruby/ext/grpc/rb_event_thread.c +5 -0
- data/src/ruby/ext/grpc/rb_grpc.c +28 -19
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +562 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +846 -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 +3 -1
- data/src/ruby/ext/grpc/rb_server_credentials.c +4 -2
- data/src/ruby/lib/grpc/core/time_consts.rb +2 -2
- data/src/ruby/lib/grpc/errors.rb +2 -2
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/grpc.rb +34 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/README.md +2 -2
- data/src/ruby/pb/generate_proto_ruby.sh +2 -2
- data/src/ruby/pb/grpc/health/checker.rb +11 -11
- data/src/ruby/pb/grpc/health/v1/health.rb +28 -0
- data/src/ruby/pb/grpc/health/{v1alpha → v1}/health_services.rb +4 -4
- data/src/ruby/spec/client_server_spec.rb +2 -1
- data/src/ruby/spec/pb/health/checker_spec.rb +23 -37
- 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 +108 -0
- data/third_party/boringssl/crypto/asn1/a_bitstr.c +255 -0
- data/third_party/boringssl/crypto/asn1/a_bool.c +112 -0
- data/third_party/boringssl/crypto/asn1/a_bytes.c +317 -0
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +286 -0
- data/third_party/boringssl/crypto/asn1/a_dup.c +103 -0
- data/third_party/boringssl/crypto/asn1/a_enum.c +183 -0
- data/third_party/boringssl/crypto/asn1/a_gentm.c +255 -0
- data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +154 -0
- data/third_party/boringssl/crypto/asn1/a_int.c +456 -0
- data/third_party/boringssl/crypto/asn1/a_mbstr.c +390 -0
- data/third_party/boringssl/crypto/asn1/a_object.c +412 -0
- data/third_party/boringssl/crypto/asn1/a_octet.c +70 -0
- data/third_party/boringssl/crypto/asn1/a_print.c +119 -0
- data/third_party/boringssl/crypto/asn1/a_strnid.c +286 -0
- data/third_party/boringssl/crypto/asn1/a_time.c +221 -0
- data/third_party/boringssl/crypto/asn1/a_type.c +160 -0
- data/third_party/boringssl/crypto/asn1/a_utctm.c +342 -0
- data/third_party/boringssl/crypto/asn1/a_utf8.c +210 -0
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +510 -0
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +73 -0
- data/third_party/boringssl/crypto/asn1/asn1_par.c +444 -0
- data/third_party/boringssl/crypto/asn1/asn_pack.c +104 -0
- data/third_party/boringssl/crypto/asn1/bio_asn1.c +496 -0
- data/third_party/boringssl/crypto/asn1/bio_ndef.c +254 -0
- data/third_party/boringssl/crypto/asn1/f_enum.c +206 -0
- data/third_party/boringssl/crypto/asn1/f_int.c +210 -0
- data/third_party/boringssl/crypto/asn1/f_string.c +204 -0
- data/third_party/boringssl/crypto/asn1/t_bitst.c +102 -0
- data/third_party/boringssl/crypto/asn1/t_pkey.c +112 -0
- data/third_party/boringssl/crypto/asn1/tasn_dec.c +1342 -0
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +695 -0
- data/third_party/boringssl/crypto/asn1/tasn_fre.c +264 -0
- data/third_party/boringssl/crypto/asn1/tasn_new.c +398 -0
- data/third_party/boringssl/crypto/asn1/tasn_prn.c +642 -0
- data/third_party/boringssl/crypto/asn1/tasn_typ.c +137 -0
- data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
- data/third_party/boringssl/crypto/asn1/x_bignum.c +143 -0
- data/third_party/boringssl/crypto/asn1/x_long.c +182 -0
- data/third_party/boringssl/crypto/base64/base64.c +478 -0
- data/third_party/boringssl/crypto/bio/bio.c +608 -0
- data/third_party/boringssl/crypto/bio/bio_mem.c +327 -0
- data/third_party/boringssl/crypto/bio/buffer.c +496 -0
- data/third_party/boringssl/crypto/bio/connect.c +544 -0
- data/third_party/boringssl/crypto/bio/fd.c +270 -0
- data/third_party/boringssl/crypto/bio/file.c +349 -0
- data/third_party/boringssl/crypto/bio/hexdump.c +192 -0
- data/third_party/boringssl/crypto/bio/internal.h +108 -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 +195 -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 +599 -0
- data/third_party/boringssl/crypto/bn/bn.c +341 -0
- data/third_party/boringssl/crypto/bn/bn_asn1.c +93 -0
- data/third_party/boringssl/crypto/bn/cmp.c +200 -0
- data/third_party/boringssl/crypto/bn/convert.c +597 -0
- data/third_party/boringssl/crypto/bn/ctx.c +311 -0
- data/third_party/boringssl/crypto/bn/div.c +625 -0
- data/third_party/boringssl/crypto/bn/exponentiation.c +1544 -0
- data/third_party/boringssl/crypto/bn/gcd.c +711 -0
- data/third_party/boringssl/crypto/bn/generic.c +1019 -0
- data/third_party/boringssl/crypto/bn/internal.h +294 -0
- data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
- data/third_party/boringssl/crypto/bn/montgomery.c +561 -0
- data/third_party/boringssl/crypto/bn/mul.c +888 -0
- data/third_party/boringssl/crypto/bn/prime.c +845 -0
- data/third_party/boringssl/crypto/bn/random.c +326 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.c +326 -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 +505 -0
- data/third_party/boringssl/crypto/buf/buf.c +235 -0
- data/third_party/boringssl/crypto/bytestring/ber.c +221 -0
- data/third_party/boringssl/crypto/bytestring/cbb.c +411 -0
- data/third_party/boringssl/crypto/bytestring/cbs.c +415 -0
- data/third_party/boringssl/crypto/bytestring/internal.h +46 -0
- data/third_party/boringssl/crypto/chacha/chacha_generic.c +140 -0
- data/third_party/boringssl/crypto/chacha/chacha_vec.c +323 -0
- data/third_party/boringssl/crypto/cipher/aead.c +167 -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 +1767 -0
- data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +311 -0
- data/third_party/boringssl/crypto/cipher/e_des.c +207 -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 +463 -0
- data/third_party/boringssl/crypto/cipher/e_tls.c +673 -0
- data/third_party/boringssl/crypto/cipher/internal.h +164 -0
- data/third_party/boringssl/crypto/cipher/tls_cbc.c +495 -0
- data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
- data/third_party/boringssl/crypto/conf/conf.c +778 -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-arm.c +199 -0
- data/third_party/boringssl/crypto/cpu-intel.c +261 -0
- data/third_party/boringssl/crypto/crypto.c +140 -0
- data/third_party/boringssl/crypto/curve25519/curve25519.c +4897 -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 +180 -0
- data/third_party/boringssl/crypto/dh/dh.c +463 -0
- data/third_party/boringssl/crypto/dh/dh_asn1.c +84 -0
- data/third_party/boringssl/crypto/dh/internal.h +80 -0
- data/third_party/boringssl/crypto/dh/params.c +301 -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 +322 -0
- data/third_party/boringssl/crypto/directory.h +66 -0
- data/third_party/boringssl/crypto/directory_posix.c +108 -0
- data/third_party/boringssl/crypto/directory_win.c +144 -0
- data/third_party/boringssl/crypto/dsa/dsa.c +908 -0
- data/third_party/boringssl/crypto/dsa/dsa_asn1.c +150 -0
- data/third_party/boringssl/crypto/dsa/internal.h +78 -0
- data/third_party/boringssl/crypto/ec/ec.c +889 -0
- data/third_party/boringssl/crypto/ec/ec_asn1.c +586 -0
- data/third_party/boringssl/crypto/ec/ec_key.c +482 -0
- data/third_party/boringssl/crypto/ec/ec_montgomery.c +280 -0
- data/third_party/boringssl/crypto/ec/internal.h +318 -0
- data/third_party/boringssl/crypto/ec/oct.c +416 -0
- data/third_party/boringssl/crypto/ec/p224-64.c +1305 -0
- data/third_party/boringssl/crypto/ec/p256-64.c +1878 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9548 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64.c +596 -0
- data/third_party/boringssl/crypto/ec/simple.c +1313 -0
- data/third_party/boringssl/crypto/ec/util-64.c +183 -0
- data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
- data/third_party/boringssl/crypto/ecdh/ecdh.c +153 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa.c +496 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +240 -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/algorithm.c +153 -0
- data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
- data/third_party/boringssl/crypto/evp/evp.c +411 -0
- data/third_party/boringssl/crypto/evp/evp_asn1.c +179 -0
- data/third_party/boringssl/crypto/evp/evp_ctx.c +477 -0
- data/third_party/boringssl/crypto/evp/internal.h +278 -0
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +588 -0
- data/third_party/boringssl/crypto/evp/p_ec.c +283 -0
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +562 -0
- data/third_party/boringssl/crypto/evp/p_rsa.c +596 -0
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +737 -0
- data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
- data/third_party/boringssl/crypto/evp/sign.c +151 -0
- data/third_party/boringssl/crypto/ex_data.c +294 -0
- data/third_party/boringssl/crypto/hkdf/hkdf.c +89 -0
- data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
- data/third_party/boringssl/crypto/internal.h +532 -0
- data/third_party/boringssl/crypto/lhash/lhash.c +346 -0
- data/third_party/boringssl/crypto/md4/md4.c +225 -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 +231 -0
- data/third_party/boringssl/crypto/modes/ctr.c +226 -0
- data/third_party/boringssl/crypto/modes/gcm.c +1252 -0
- data/third_party/boringssl/crypto/modes/internal.h +370 -0
- data/third_party/boringssl/crypto/modes/ofb.c +108 -0
- data/third_party/boringssl/crypto/obj/obj.c +664 -0
- data/third_party/boringssl/crypto/obj/obj_dat.h +5257 -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 +281 -0
- data/third_party/boringssl/crypto/pem/pem_info.c +404 -0
- data/third_party/boringssl/crypto/pem/pem_lib.c +835 -0
- data/third_party/boringssl/crypto/pem/pem_oth.c +89 -0
- data/third_party/boringssl/crypto/pem/pem_pk8.c +244 -0
- data/third_party/boringssl/crypto/pem/pem_pkey.c +312 -0
- data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
- data/third_party/boringssl/crypto/pem/pem_xaux.c +66 -0
- data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +150 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +440 -0
- data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1217 -0
- data/third_party/boringssl/crypto/poly1305/poly1305.c +331 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +301 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +892 -0
- data/third_party/boringssl/crypto/rand/internal.h +32 -0
- data/third_party/boringssl/crypto/rand/rand.c +239 -0
- data/third_party/boringssl/crypto/rand/urandom.c +223 -0
- data/third_party/boringssl/crypto/rand/windows.c +56 -0
- data/third_party/boringssl/crypto/rc4/rc4.c +283 -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 +462 -0
- data/third_party/boringssl/crypto/rsa/internal.h +164 -0
- data/third_party/boringssl/crypto/rsa/padding.c +711 -0
- data/third_party/boringssl/crypto/rsa/rsa.c +808 -0
- data/third_party/boringssl/crypto/rsa/rsa_asn1.c +473 -0
- data/third_party/boringssl/crypto/rsa/rsa_impl.c +1138 -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 +386 -0
- data/third_party/boringssl/crypto/test/scoped_types.h +137 -0
- data/third_party/boringssl/crypto/test/test_util.h +35 -0
- data/third_party/boringssl/crypto/thread.c +101 -0
- data/third_party/boringssl/crypto/thread_none.c +55 -0
- data/third_party/boringssl/crypto/thread_pthread.c +167 -0
- data/third_party/boringssl/crypto/thread_win.c +282 -0
- data/third_party/boringssl/crypto/time_support.c +212 -0
- data/third_party/boringssl/crypto/x509/a_digest.c +97 -0
- data/third_party/boringssl/crypto/x509/a_sign.c +136 -0
- data/third_party/boringssl/crypto/x509/a_strex.c +564 -0
- data/third_party/boringssl/crypto/x509/a_verify.c +133 -0
- data/third_party/boringssl/crypto/x509/asn1_gen.c +873 -0
- data/third_party/boringssl/crypto/x509/by_dir.c +491 -0
- data/third_party/boringssl/crypto/x509/by_file.c +295 -0
- data/third_party/boringssl/crypto/x509/charmap.h +15 -0
- data/third_party/boringssl/crypto/x509/i2d_pr.c +84 -0
- data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
- data/third_party/boringssl/crypto/x509/t_crl.c +129 -0
- data/third_party/boringssl/crypto/x509/t_req.c +246 -0
- data/third_party/boringssl/crypto/x509/t_x509.c +500 -0
- data/third_party/boringssl/crypto/x509/t_x509a.c +109 -0
- data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
- data/third_party/boringssl/crypto/x509/x509.c +152 -0
- data/third_party/boringssl/crypto/x509/x509_att.c +353 -0
- data/third_party/boringssl/crypto/x509/x509_cmp.c +490 -0
- data/third_party/boringssl/crypto/x509/x509_d2.c +105 -0
- data/third_party/boringssl/crypto/x509/x509_def.c +88 -0
- data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
- data/third_party/boringssl/crypto/x509/x509_lu.c +738 -0
- data/third_party/boringssl/crypto/x509/x509_obj.c +191 -0
- data/third_party/boringssl/crypto/x509/x509_r2x.c +113 -0
- data/third_party/boringssl/crypto/x509/x509_req.c +315 -0
- data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
- data/third_party/boringssl/crypto/x509/x509_trs.c +304 -0
- data/third_party/boringssl/crypto/x509/x509_txt.c +209 -0
- data/third_party/boringssl/crypto/x509/x509_v3.c +271 -0
- data/third_party/boringssl/crypto/x509/x509_vfy.c +2456 -0
- data/third_party/boringssl/crypto/x509/x509_vpm.c +672 -0
- data/third_party/boringssl/crypto/x509/x509cset.c +172 -0
- data/third_party/boringssl/crypto/x509/x509name.c +381 -0
- data/third_party/boringssl/crypto/x509/x509rset.c +80 -0
- data/third_party/boringssl/crypto/x509/x509spki.c +135 -0
- data/third_party/boringssl/crypto/x509/x509type.c +128 -0
- data/third_party/boringssl/crypto/x509/x_algor.c +154 -0
- data/third_party/boringssl/crypto/x509/x_all.c +547 -0
- data/third_party/boringssl/crypto/x509/x_attrib.c +117 -0
- data/third_party/boringssl/crypto/x509/x_crl.c +560 -0
- data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
- data/third_party/boringssl/crypto/x509/x_info.c +95 -0
- data/third_party/boringssl/crypto/x509/x_name.c +538 -0
- data/third_party/boringssl/crypto/x509/x_pkey.c +100 -0
- data/third_party/boringssl/crypto/x509/x_pubkey.c +384 -0
- data/third_party/boringssl/crypto/x509/x_req.c +112 -0
- data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
- data/third_party/boringssl/crypto/x509/x_spki.c +78 -0
- data/third_party/boringssl/crypto/x509/x_val.c +69 -0
- data/third_party/boringssl/crypto/x509/x_x509.c +227 -0
- data/third_party/boringssl/crypto/x509/x_x509a.c +197 -0
- data/third_party/boringssl/crypto/x509v3/ext_dat.h +129 -0
- data/third_party/boringssl/crypto/x509v3/pcy_cache.c +299 -0
- data/third_party/boringssl/crypto/x509v3/pcy_data.c +137 -0
- data/third_party/boringssl/crypto/x509v3/pcy_int.h +212 -0
- data/third_party/boringssl/crypto/x509v3/pcy_lib.c +165 -0
- data/third_party/boringssl/crypto/x509v3/pcy_map.c +133 -0
- data/third_party/boringssl/crypto/x509v3/pcy_node.c +197 -0
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +876 -0
- data/third_party/boringssl/crypto/x509v3/v3_akey.c +212 -0
- data/third_party/boringssl/crypto/x509v3/v3_akeya.c +71 -0
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +622 -0
- data/third_party/boringssl/crypto/x509v3/v3_bcons.c +126 -0
- data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
- data/third_party/boringssl/crypto/x509v3/v3_conf.c +459 -0
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +475 -0
- data/third_party/boringssl/crypto/x509v3/v3_crld.c +616 -0
- data/third_party/boringssl/crypto/x509v3/v3_enum.c +98 -0
- data/third_party/boringssl/crypto/x509v3/v3_extku.c +145 -0
- data/third_party/boringssl/crypto/x509v3/v3_genn.c +252 -0
- data/third_party/boringssl/crypto/x509v3/v3_ia5.c +117 -0
- data/third_party/boringssl/crypto/x509v3/v3_info.c +200 -0
- data/third_party/boringssl/crypto/x509v3/v3_int.c +87 -0
- data/third_party/boringssl/crypto/x509v3/v3_lib.c +335 -0
- data/third_party/boringssl/crypto/x509v3/v3_ncons.c +510 -0
- data/third_party/boringssl/crypto/x509v3/v3_pci.c +335 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcia.c +56 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcons.c +142 -0
- data/third_party/boringssl/crypto/x509v3/v3_pku.c +109 -0
- data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +156 -0
- data/third_party/boringssl/crypto/x509v3/v3_prn.c +207 -0
- data/third_party/boringssl/crypto/x509v3/v3_purp.c +805 -0
- data/third_party/boringssl/crypto/x509v3/v3_skey.c +148 -0
- data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +266 -0
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +1322 -0
- data/third_party/boringssl/include/openssl/aead.h +346 -0
- data/third_party/boringssl/include/openssl/aes.h +158 -0
- data/third_party/boringssl/include/openssl/arm_arch.h +127 -0
- data/third_party/boringssl/include/openssl/asn1.h +1168 -0
- data/third_party/boringssl/include/openssl/asn1_mac.h +75 -0
- data/third_party/boringssl/include/openssl/asn1t.h +906 -0
- data/third_party/boringssl/include/openssl/base.h +261 -0
- data/third_party/boringssl/include/openssl/base64.h +184 -0
- data/third_party/boringssl/include/openssl/bio.h +902 -0
- data/third_party/boringssl/include/openssl/blowfish.h +93 -0
- data/third_party/boringssl/include/openssl/bn.h +885 -0
- data/third_party/boringssl/include/openssl/buf.h +118 -0
- data/third_party/boringssl/include/openssl/buffer.h +18 -0
- data/third_party/boringssl/include/openssl/bytestring.h +360 -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 +571 -0
- data/third_party/boringssl/include/openssl/cmac.h +76 -0
- data/third_party/boringssl/include/openssl/conf.h +145 -0
- data/third_party/boringssl/include/openssl/cpu.h +184 -0
- data/third_party/boringssl/include/openssl/crypto.h +68 -0
- data/third_party/boringssl/include/openssl/curve25519.h +88 -0
- data/third_party/boringssl/include/openssl/des.h +177 -0
- data/third_party/boringssl/include/openssl/dh.h +238 -0
- data/third_party/boringssl/include/openssl/digest.h +258 -0
- data/third_party/boringssl/include/openssl/dsa.h +343 -0
- data/third_party/boringssl/include/openssl/dtls1.h +16 -0
- data/third_party/boringssl/include/openssl/ec.h +355 -0
- data/third_party/boringssl/include/openssl/ec_key.h +280 -0
- data/third_party/boringssl/include/openssl/ecdh.h +102 -0
- data/third_party/boringssl/include/openssl/ecdsa.h +206 -0
- data/third_party/boringssl/include/openssl/engine.h +98 -0
- data/third_party/boringssl/include/openssl/err.h +487 -0
- data/third_party/boringssl/include/openssl/evp.h +750 -0
- data/third_party/boringssl/include/openssl/ex_data.h +213 -0
- data/third_party/boringssl/include/openssl/hkdf.h +44 -0
- data/third_party/boringssl/include/openssl/hmac.h +160 -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 +102 -0
- data/third_party/boringssl/include/openssl/md5.h +107 -0
- data/third_party/boringssl/include/openssl/mem.h +140 -0
- data/third_party/boringssl/include/openssl/obj.h +198 -0
- data/third_party/boringssl/include/openssl/obj_mac.h +4140 -0
- data/third_party/boringssl/include/openssl/objects.h +18 -0
- data/third_party/boringssl/include/openssl/opensslfeatures.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 +521 -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 +220 -0
- data/third_party/boringssl/include/openssl/poly1305.h +51 -0
- data/third_party/boringssl/include/openssl/pqueue.h +146 -0
- data/third_party/boringssl/include/openssl/rand.h +113 -0
- data/third_party/boringssl/include/openssl/rc4.h +90 -0
- data/third_party/boringssl/include/openssl/rsa.h +637 -0
- data/third_party/boringssl/include/openssl/safestack.h +16 -0
- data/third_party/boringssl/include/openssl/sha.h +256 -0
- data/third_party/boringssl/include/openssl/srtp.h +18 -0
- data/third_party/boringssl/include/openssl/ssl.h +4466 -0
- data/third_party/boringssl/include/openssl/ssl3.h +441 -0
- data/third_party/boringssl/include/openssl/stack.h +298 -0
- data/third_party/boringssl/include/openssl/stack_macros.h +4190 -0
- data/third_party/boringssl/include/openssl/thread.h +173 -0
- data/third_party/boringssl/include/openssl/time_support.h +90 -0
- data/third_party/boringssl/include/openssl/tls1.h +653 -0
- data/third_party/boringssl/include/openssl/type_check.h +91 -0
- data/third_party/boringssl/include/openssl/x509.h +1258 -0
- data/third_party/boringssl/include/openssl/x509_vfy.h +611 -0
- data/third_party/boringssl/include/openssl/x509v3.h +798 -0
- data/third_party/boringssl/ssl/custom_extensions.c +257 -0
- data/third_party/boringssl/ssl/d1_both.c +880 -0
- data/third_party/boringssl/ssl/d1_clnt.c +566 -0
- data/third_party/boringssl/ssl/d1_lib.c +340 -0
- data/third_party/boringssl/ssl/d1_meth.c +130 -0
- data/third_party/boringssl/ssl/d1_pkt.c +578 -0
- data/third_party/boringssl/ssl/d1_srtp.c +234 -0
- data/third_party/boringssl/ssl/d1_srvr.c +485 -0
- data/third_party/boringssl/ssl/dtls_record.c +308 -0
- data/third_party/boringssl/ssl/internal.h +1276 -0
- data/third_party/boringssl/ssl/pqueue/pqueue.c +197 -0
- data/third_party/boringssl/ssl/s3_both.c +571 -0
- data/third_party/boringssl/ssl/s3_clnt.c +2241 -0
- data/third_party/boringssl/ssl/s3_enc.c +494 -0
- data/third_party/boringssl/ssl/s3_lib.c +587 -0
- data/third_party/boringssl/ssl/s3_meth.c +166 -0
- data/third_party/boringssl/ssl/s3_pkt.c +732 -0
- data/third_party/boringssl/ssl/s3_srvr.c +2536 -0
- data/third_party/boringssl/ssl/ssl_aead_ctx.c +300 -0
- data/third_party/boringssl/ssl/ssl_asn1.c +718 -0
- data/third_party/boringssl/ssl/ssl_buffer.c +319 -0
- data/third_party/boringssl/ssl/ssl_cert.c +539 -0
- data/third_party/boringssl/ssl/ssl_cipher.c +2003 -0
- data/third_party/boringssl/ssl/ssl_file.c +633 -0
- data/third_party/boringssl/ssl/ssl_lib.c +2653 -0
- data/third_party/boringssl/ssl/ssl_rsa.c +423 -0
- data/third_party/boringssl/ssl/ssl_session.c +764 -0
- data/third_party/boringssl/ssl/ssl_stat.c +591 -0
- data/third_party/boringssl/ssl/t1_enc.c +708 -0
- data/third_party/boringssl/ssl/t1_lib.c +2905 -0
- data/third_party/boringssl/ssl/test/async_bio.h +45 -0
- data/third_party/boringssl/ssl/test/packeted_bio.h +44 -0
- data/third_party/boringssl/ssl/test/scoped_types.h +28 -0
- data/third_party/boringssl/ssl/test/test_config.h +108 -0
- data/third_party/boringssl/ssl/tls_record.c +342 -0
- data/third_party/nanopb/pb.h +547 -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 +1319 -0
- data/third_party/nanopb/pb_decode.h +149 -0
- data/third_party/nanopb/pb_encode.c +690 -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 +504 -20
- data/Rakefile +0 -63
- data/src/ruby/pb/grpc/health/v1alpha/health.rb +0 -29
@@ -0,0 +1,1544 @@
|
|
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
|
+
/* ====================================================================
|
58
|
+
* Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
|
59
|
+
*
|
60
|
+
* Redistribution and use in source and binary forms, with or without
|
61
|
+
* modification, are permitted provided that the following conditions
|
62
|
+
* are met:
|
63
|
+
*
|
64
|
+
* 1. Redistributions of source code must retain the above copyright
|
65
|
+
* notice, this list of conditions and the following disclaimer.
|
66
|
+
*
|
67
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
68
|
+
* notice, this list of conditions and the following disclaimer in
|
69
|
+
* the documentation and/or other materials provided with the
|
70
|
+
* distribution.
|
71
|
+
*
|
72
|
+
* 3. All advertising materials mentioning features or use of this
|
73
|
+
* software must display the following acknowledgment:
|
74
|
+
* "This product includes software developed by the OpenSSL Project
|
75
|
+
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
76
|
+
*
|
77
|
+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
78
|
+
* endorse or promote products derived from this software without
|
79
|
+
* prior written permission. For written permission, please contact
|
80
|
+
* openssl-core@openssl.org.
|
81
|
+
*
|
82
|
+
* 5. Products derived from this software may not be called "OpenSSL"
|
83
|
+
* nor may "OpenSSL" appear in their names without prior written
|
84
|
+
* permission of the OpenSSL Project.
|
85
|
+
*
|
86
|
+
* 6. Redistributions of any form whatsoever must retain the following
|
87
|
+
* acknowledgment:
|
88
|
+
* "This product includes software developed by the OpenSSL Project
|
89
|
+
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
90
|
+
*
|
91
|
+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
92
|
+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
93
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
94
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
95
|
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
96
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
97
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
98
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
99
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
100
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
101
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
102
|
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
103
|
+
* ====================================================================
|
104
|
+
*
|
105
|
+
* This product includes cryptographic software written by Eric Young
|
106
|
+
* (eay@cryptsoft.com). This product includes software written by Tim
|
107
|
+
* Hudson (tjh@cryptsoft.com). */
|
108
|
+
|
109
|
+
#include <openssl/bn.h>
|
110
|
+
|
111
|
+
#include <assert.h>
|
112
|
+
#include <string.h>
|
113
|
+
|
114
|
+
#include <openssl/cpu.h>
|
115
|
+
#include <openssl/err.h>
|
116
|
+
#include <openssl/mem.h>
|
117
|
+
|
118
|
+
#include "internal.h"
|
119
|
+
|
120
|
+
|
121
|
+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
122
|
+
#define OPENSSL_BN_ASM_MONT5
|
123
|
+
#define RSAZ_ENABLED
|
124
|
+
|
125
|
+
#include "rsaz_exp.h"
|
126
|
+
|
127
|
+
void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap, const void *table,
|
128
|
+
const BN_ULONG *np, const BN_ULONG *n0, int num,
|
129
|
+
int power);
|
130
|
+
void bn_scatter5(const BN_ULONG *inp, size_t num, void *table, size_t power);
|
131
|
+
void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);
|
132
|
+
void bn_power5(BN_ULONG *rp, const BN_ULONG *ap, const void *table,
|
133
|
+
const BN_ULONG *np, const BN_ULONG *n0, int num, int power);
|
134
|
+
int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,
|
135
|
+
const BN_ULONG *not_used, const BN_ULONG *np,
|
136
|
+
const BN_ULONG *n0, int num);
|
137
|
+
#endif
|
138
|
+
|
139
|
+
int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
140
|
+
int i, bits, ret = 0;
|
141
|
+
BIGNUM *v, *rr;
|
142
|
+
|
143
|
+
if ((p->flags & BN_FLG_CONSTTIME) != 0) {
|
144
|
+
/* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
|
145
|
+
OPENSSL_PUT_ERROR(BN, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
146
|
+
return 0;
|
147
|
+
}
|
148
|
+
|
149
|
+
BN_CTX_start(ctx);
|
150
|
+
if (r == a || r == p) {
|
151
|
+
rr = BN_CTX_get(ctx);
|
152
|
+
} else {
|
153
|
+
rr = r;
|
154
|
+
}
|
155
|
+
|
156
|
+
v = BN_CTX_get(ctx);
|
157
|
+
if (rr == NULL || v == NULL) {
|
158
|
+
goto err;
|
159
|
+
}
|
160
|
+
|
161
|
+
if (BN_copy(v, a) == NULL) {
|
162
|
+
goto err;
|
163
|
+
}
|
164
|
+
bits = BN_num_bits(p);
|
165
|
+
|
166
|
+
if (BN_is_odd(p)) {
|
167
|
+
if (BN_copy(rr, a) == NULL) {
|
168
|
+
goto err;
|
169
|
+
}
|
170
|
+
} else {
|
171
|
+
if (!BN_one(rr)) {
|
172
|
+
goto err;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
for (i = 1; i < bits; i++) {
|
177
|
+
if (!BN_sqr(v, v, ctx)) {
|
178
|
+
goto err;
|
179
|
+
}
|
180
|
+
if (BN_is_bit_set(p, i)) {
|
181
|
+
if (!BN_mul(rr, rr, v, ctx)) {
|
182
|
+
goto err;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
if (r != rr && !BN_copy(r, rr)) {
|
188
|
+
goto err;
|
189
|
+
}
|
190
|
+
ret = 1;
|
191
|
+
|
192
|
+
err:
|
193
|
+
BN_CTX_end(ctx);
|
194
|
+
return ret;
|
195
|
+
}
|
196
|
+
|
197
|
+
/* maximum precomputation table size for *variable* sliding windows */
|
198
|
+
#define TABLE_SIZE 32
|
199
|
+
|
200
|
+
typedef struct bn_recp_ctx_st {
|
201
|
+
BIGNUM N; /* the divisor */
|
202
|
+
BIGNUM Nr; /* the reciprocal */
|
203
|
+
int num_bits;
|
204
|
+
int shift;
|
205
|
+
int flags;
|
206
|
+
} BN_RECP_CTX;
|
207
|
+
|
208
|
+
static void BN_RECP_CTX_init(BN_RECP_CTX *recp) {
|
209
|
+
BN_init(&recp->N);
|
210
|
+
BN_init(&recp->Nr);
|
211
|
+
recp->num_bits = 0;
|
212
|
+
recp->flags = 0;
|
213
|
+
}
|
214
|
+
|
215
|
+
static void BN_RECP_CTX_free(BN_RECP_CTX *recp) {
|
216
|
+
if (recp == NULL) {
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
|
220
|
+
BN_free(&recp->N);
|
221
|
+
BN_free(&recp->Nr);
|
222
|
+
}
|
223
|
+
|
224
|
+
static int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) {
|
225
|
+
if (!BN_copy(&(recp->N), d)) {
|
226
|
+
return 0;
|
227
|
+
}
|
228
|
+
BN_zero(&recp->Nr);
|
229
|
+
recp->num_bits = BN_num_bits(d);
|
230
|
+
recp->shift = 0;
|
231
|
+
|
232
|
+
return 1;
|
233
|
+
}
|
234
|
+
|
235
|
+
/* len is the expected size of the result We actually calculate with an extra
|
236
|
+
* word of precision, so we can do faster division if the remainder is not
|
237
|
+
* required.
|
238
|
+
* r := 2^len / m */
|
239
|
+
static int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) {
|
240
|
+
int ret = -1;
|
241
|
+
BIGNUM *t;
|
242
|
+
|
243
|
+
BN_CTX_start(ctx);
|
244
|
+
t = BN_CTX_get(ctx);
|
245
|
+
if (t == NULL) {
|
246
|
+
goto err;
|
247
|
+
}
|
248
|
+
|
249
|
+
if (!BN_set_bit(t, len)) {
|
250
|
+
goto err;
|
251
|
+
}
|
252
|
+
|
253
|
+
if (!BN_div(r, NULL, t, m, ctx)) {
|
254
|
+
goto err;
|
255
|
+
}
|
256
|
+
|
257
|
+
ret = len;
|
258
|
+
|
259
|
+
err:
|
260
|
+
BN_CTX_end(ctx);
|
261
|
+
return ret;
|
262
|
+
}
|
263
|
+
|
264
|
+
static int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
|
265
|
+
BN_RECP_CTX *recp, BN_CTX *ctx) {
|
266
|
+
int i, j, ret = 0;
|
267
|
+
BIGNUM *a, *b, *d, *r;
|
268
|
+
|
269
|
+
BN_CTX_start(ctx);
|
270
|
+
a = BN_CTX_get(ctx);
|
271
|
+
b = BN_CTX_get(ctx);
|
272
|
+
if (dv != NULL) {
|
273
|
+
d = dv;
|
274
|
+
} else {
|
275
|
+
d = BN_CTX_get(ctx);
|
276
|
+
}
|
277
|
+
|
278
|
+
if (rem != NULL) {
|
279
|
+
r = rem;
|
280
|
+
} else {
|
281
|
+
r = BN_CTX_get(ctx);
|
282
|
+
}
|
283
|
+
|
284
|
+
if (a == NULL || b == NULL || d == NULL || r == NULL) {
|
285
|
+
goto err;
|
286
|
+
}
|
287
|
+
|
288
|
+
if (BN_ucmp(m, &recp->N) < 0) {
|
289
|
+
BN_zero(d);
|
290
|
+
if (!BN_copy(r, m)) {
|
291
|
+
goto err;
|
292
|
+
}
|
293
|
+
BN_CTX_end(ctx);
|
294
|
+
return 1;
|
295
|
+
}
|
296
|
+
|
297
|
+
/* We want the remainder
|
298
|
+
* Given input of ABCDEF / ab
|
299
|
+
* we need multiply ABCDEF by 3 digests of the reciprocal of ab */
|
300
|
+
|
301
|
+
/* i := max(BN_num_bits(m), 2*BN_num_bits(N)) */
|
302
|
+
i = BN_num_bits(m);
|
303
|
+
j = recp->num_bits << 1;
|
304
|
+
if (j > i) {
|
305
|
+
i = j;
|
306
|
+
}
|
307
|
+
|
308
|
+
/* Nr := round(2^i / N) */
|
309
|
+
if (i != recp->shift) {
|
310
|
+
recp->shift =
|
311
|
+
BN_reciprocal(&(recp->Nr), &(recp->N), i,
|
312
|
+
ctx); /* BN_reciprocal returns i, or -1 for an error */
|
313
|
+
}
|
314
|
+
|
315
|
+
if (recp->shift == -1) {
|
316
|
+
goto err;
|
317
|
+
}
|
318
|
+
|
319
|
+
/* d := |round(round(m / 2^BN_num_bits(N)) * recp->Nr / 2^(i -
|
320
|
+
* BN_num_bits(N)))|
|
321
|
+
* = |round(round(m / 2^BN_num_bits(N)) * round(2^i / N) / 2^(i -
|
322
|
+
* BN_num_bits(N)))|
|
323
|
+
* <= |(m / 2^BN_num_bits(N)) * (2^i / N) * (2^BN_num_bits(N) / 2^i)|
|
324
|
+
* = |m/N| */
|
325
|
+
if (!BN_rshift(a, m, recp->num_bits)) {
|
326
|
+
goto err;
|
327
|
+
}
|
328
|
+
if (!BN_mul(b, a, &(recp->Nr), ctx)) {
|
329
|
+
goto err;
|
330
|
+
}
|
331
|
+
if (!BN_rshift(d, b, i - recp->num_bits)) {
|
332
|
+
goto err;
|
333
|
+
}
|
334
|
+
d->neg = 0;
|
335
|
+
|
336
|
+
if (!BN_mul(b, &(recp->N), d, ctx)) {
|
337
|
+
goto err;
|
338
|
+
}
|
339
|
+
if (!BN_usub(r, m, b)) {
|
340
|
+
goto err;
|
341
|
+
}
|
342
|
+
r->neg = 0;
|
343
|
+
|
344
|
+
j = 0;
|
345
|
+
while (BN_ucmp(r, &(recp->N)) >= 0) {
|
346
|
+
if (j++ > 2) {
|
347
|
+
OPENSSL_PUT_ERROR(BN, BN_R_BAD_RECIPROCAL);
|
348
|
+
goto err;
|
349
|
+
}
|
350
|
+
if (!BN_usub(r, r, &(recp->N))) {
|
351
|
+
goto err;
|
352
|
+
}
|
353
|
+
if (!BN_add_word(d, 1)) {
|
354
|
+
goto err;
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
r->neg = BN_is_zero(r) ? 0 : m->neg;
|
359
|
+
d->neg = m->neg ^ recp->N.neg;
|
360
|
+
ret = 1;
|
361
|
+
|
362
|
+
err:
|
363
|
+
BN_CTX_end(ctx);
|
364
|
+
return ret;
|
365
|
+
}
|
366
|
+
|
367
|
+
static int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
|
368
|
+
BN_RECP_CTX *recp, BN_CTX *ctx) {
|
369
|
+
int ret = 0;
|
370
|
+
BIGNUM *a;
|
371
|
+
const BIGNUM *ca;
|
372
|
+
|
373
|
+
BN_CTX_start(ctx);
|
374
|
+
a = BN_CTX_get(ctx);
|
375
|
+
if (a == NULL) {
|
376
|
+
goto err;
|
377
|
+
}
|
378
|
+
|
379
|
+
if (y != NULL) {
|
380
|
+
if (x == y) {
|
381
|
+
if (!BN_sqr(a, x, ctx)) {
|
382
|
+
goto err;
|
383
|
+
}
|
384
|
+
} else {
|
385
|
+
if (!BN_mul(a, x, y, ctx)) {
|
386
|
+
goto err;
|
387
|
+
}
|
388
|
+
}
|
389
|
+
ca = a;
|
390
|
+
} else {
|
391
|
+
ca = x; /* Just do the mod */
|
392
|
+
}
|
393
|
+
|
394
|
+
ret = BN_div_recp(NULL, r, ca, recp, ctx);
|
395
|
+
|
396
|
+
err:
|
397
|
+
BN_CTX_end(ctx);
|
398
|
+
return ret;
|
399
|
+
}
|
400
|
+
|
401
|
+
/* BN_window_bits_for_exponent_size -- macro for sliding window mod_exp
|
402
|
+
* functions
|
403
|
+
*
|
404
|
+
* For window size 'w' (w >= 2) and a random 'b' bits exponent, the number of
|
405
|
+
* multiplications is a constant plus on average
|
406
|
+
*
|
407
|
+
* 2^(w-1) + (b-w)/(w+1);
|
408
|
+
*
|
409
|
+
* here 2^(w-1) is for precomputing the table (we actually need entries only
|
410
|
+
* for windows that have the lowest bit set), and (b-w)/(w+1) is an
|
411
|
+
* approximation for the expected number of w-bit windows, not counting the
|
412
|
+
* first one.
|
413
|
+
*
|
414
|
+
* Thus we should use
|
415
|
+
*
|
416
|
+
* w >= 6 if b > 671
|
417
|
+
* w = 5 if 671 > b > 239
|
418
|
+
* w = 4 if 239 > b > 79
|
419
|
+
* w = 3 if 79 > b > 23
|
420
|
+
* w <= 2 if 23 > b
|
421
|
+
*
|
422
|
+
* (with draws in between). Very small exponents are often selected
|
423
|
+
* with low Hamming weight, so we use w = 1 for b <= 23. */
|
424
|
+
#define BN_window_bits_for_exponent_size(b) \
|
425
|
+
((b) > 671 ? 6 : \
|
426
|
+
(b) > 239 ? 5 : \
|
427
|
+
(b) > 79 ? 4 : \
|
428
|
+
(b) > 23 ? 3 : 1)
|
429
|
+
|
430
|
+
static int mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
431
|
+
const BIGNUM *m, BN_CTX *ctx) {
|
432
|
+
int i, j, bits, ret = 0, wstart, window;
|
433
|
+
int start = 1;
|
434
|
+
BIGNUM *aa;
|
435
|
+
/* Table of variables obtained from 'ctx' */
|
436
|
+
BIGNUM *val[TABLE_SIZE];
|
437
|
+
BN_RECP_CTX recp;
|
438
|
+
|
439
|
+
if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
|
440
|
+
/* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
|
441
|
+
OPENSSL_PUT_ERROR(BN, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
442
|
+
return 0;
|
443
|
+
}
|
444
|
+
|
445
|
+
bits = BN_num_bits(p);
|
446
|
+
|
447
|
+
if (bits == 0) {
|
448
|
+
ret = BN_one(r);
|
449
|
+
return ret;
|
450
|
+
}
|
451
|
+
|
452
|
+
BN_CTX_start(ctx);
|
453
|
+
aa = BN_CTX_get(ctx);
|
454
|
+
val[0] = BN_CTX_get(ctx);
|
455
|
+
if (!aa || !val[0]) {
|
456
|
+
goto err;
|
457
|
+
}
|
458
|
+
|
459
|
+
BN_RECP_CTX_init(&recp);
|
460
|
+
if (m->neg) {
|
461
|
+
/* ignore sign of 'm' */
|
462
|
+
if (!BN_copy(aa, m)) {
|
463
|
+
goto err;
|
464
|
+
}
|
465
|
+
aa->neg = 0;
|
466
|
+
if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0) {
|
467
|
+
goto err;
|
468
|
+
}
|
469
|
+
} else {
|
470
|
+
if (BN_RECP_CTX_set(&recp, m, ctx) <= 0) {
|
471
|
+
goto err;
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
475
|
+
if (!BN_nnmod(val[0], a, m, ctx)) {
|
476
|
+
goto err; /* 1 */
|
477
|
+
}
|
478
|
+
if (BN_is_zero(val[0])) {
|
479
|
+
BN_zero(r);
|
480
|
+
ret = 1;
|
481
|
+
goto err;
|
482
|
+
}
|
483
|
+
|
484
|
+
window = BN_window_bits_for_exponent_size(bits);
|
485
|
+
if (window > 1) {
|
486
|
+
if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx)) {
|
487
|
+
goto err; /* 2 */
|
488
|
+
}
|
489
|
+
j = 1 << (window - 1);
|
490
|
+
for (i = 1; i < j; i++) {
|
491
|
+
if (((val[i] = BN_CTX_get(ctx)) == NULL) ||
|
492
|
+
!BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx)) {
|
493
|
+
goto err;
|
494
|
+
}
|
495
|
+
}
|
496
|
+
}
|
497
|
+
|
498
|
+
start = 1; /* This is used to avoid multiplication etc
|
499
|
+
* when there is only the value '1' in the
|
500
|
+
* buffer. */
|
501
|
+
wstart = bits - 1; /* The top bit of the window */
|
502
|
+
|
503
|
+
if (!BN_one(r)) {
|
504
|
+
goto err;
|
505
|
+
}
|
506
|
+
|
507
|
+
for (;;) {
|
508
|
+
int wvalue; /* The 'value' of the window */
|
509
|
+
int wend; /* The bottom bit of the window */
|
510
|
+
|
511
|
+
if (BN_is_bit_set(p, wstart) == 0) {
|
512
|
+
if (!start) {
|
513
|
+
if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx)) {
|
514
|
+
goto err;
|
515
|
+
}
|
516
|
+
}
|
517
|
+
if (wstart == 0) {
|
518
|
+
break;
|
519
|
+
}
|
520
|
+
wstart--;
|
521
|
+
continue;
|
522
|
+
}
|
523
|
+
|
524
|
+
/* We now have wstart on a 'set' bit, we now need to work out
|
525
|
+
* how bit a window to do. To do this we need to scan
|
526
|
+
* forward until the last set bit before the end of the
|
527
|
+
* window */
|
528
|
+
wvalue = 1;
|
529
|
+
wend = 0;
|
530
|
+
for (i = 1; i < window; i++) {
|
531
|
+
if (wstart - i < 0) {
|
532
|
+
break;
|
533
|
+
}
|
534
|
+
if (BN_is_bit_set(p, wstart - i)) {
|
535
|
+
wvalue <<= (i - wend);
|
536
|
+
wvalue |= 1;
|
537
|
+
wend = i;
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
541
|
+
/* wend is the size of the current window */
|
542
|
+
j = wend + 1;
|
543
|
+
/* add the 'bytes above' */
|
544
|
+
if (!start) {
|
545
|
+
for (i = 0; i < j; i++) {
|
546
|
+
if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx)) {
|
547
|
+
goto err;
|
548
|
+
}
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
/* wvalue will be an odd number < 2^window */
|
553
|
+
if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx)) {
|
554
|
+
goto err;
|
555
|
+
}
|
556
|
+
|
557
|
+
/* move the 'window' down further */
|
558
|
+
wstart -= wend + 1;
|
559
|
+
start = 0;
|
560
|
+
if (wstart < 0) {
|
561
|
+
break;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
ret = 1;
|
565
|
+
|
566
|
+
err:
|
567
|
+
BN_CTX_end(ctx);
|
568
|
+
BN_RECP_CTX_free(&recp);
|
569
|
+
return ret;
|
570
|
+
}
|
571
|
+
|
572
|
+
int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
|
573
|
+
BN_CTX *ctx) {
|
574
|
+
/* For even modulus m = 2^k*m_odd, it might make sense to compute
|
575
|
+
* a^p mod m_odd and a^p mod 2^k separately (with Montgomery
|
576
|
+
* exponentiation for the odd part), using appropriate exponent
|
577
|
+
* reductions, and combine the results using the CRT.
|
578
|
+
*
|
579
|
+
* For now, we use Montgomery only if the modulus is odd; otherwise,
|
580
|
+
* exponentiation using the reciprocal-based quick remaindering
|
581
|
+
* algorithm is used.
|
582
|
+
*
|
583
|
+
* (Timing obtained with expspeed.c [computations a^p mod m
|
584
|
+
* where a, p, m are of the same length: 256, 512, 1024, 2048,
|
585
|
+
* 4096, 8192 bits], compared to the running time of the
|
586
|
+
* standard algorithm:
|
587
|
+
*
|
588
|
+
* BN_mod_exp_mont 33 .. 40 % [AMD K6-2, Linux, debug configuration]
|
589
|
+
* 55 .. 77 % [UltraSparc processor, but
|
590
|
+
* debug-solaris-sparcv8-gcc conf.]
|
591
|
+
*
|
592
|
+
* BN_mod_exp_recp 50 .. 70 % [AMD K6-2, Linux, debug configuration]
|
593
|
+
* 62 .. 118 % [UltraSparc, debug-solaris-sparcv8-gcc]
|
594
|
+
*
|
595
|
+
* On the Sparc, BN_mod_exp_recp was faster than BN_mod_exp_mont
|
596
|
+
* at 2048 and more bits, but at 512 and 1024 bits, it was
|
597
|
+
* slower even than the standard algorithm!
|
598
|
+
*
|
599
|
+
* "Real" timings [linux-elf, solaris-sparcv9-gcc configurations]
|
600
|
+
* should be obtained when the new Montgomery reduction code
|
601
|
+
* has been integrated into OpenSSL.) */
|
602
|
+
|
603
|
+
if (BN_is_odd(m)) {
|
604
|
+
if (a->top == 1 && !a->neg && BN_get_flags(p, BN_FLG_CONSTTIME) == 0) {
|
605
|
+
BN_ULONG A = a->d[0];
|
606
|
+
return BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);
|
607
|
+
}
|
608
|
+
|
609
|
+
return BN_mod_exp_mont(r, a, p, m, ctx, NULL);
|
610
|
+
}
|
611
|
+
|
612
|
+
return mod_exp_recp(r, a, p, m, ctx);
|
613
|
+
}
|
614
|
+
|
615
|
+
int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
616
|
+
const BIGNUM *m, BN_CTX *ctx, const BN_MONT_CTX *mont) {
|
617
|
+
int i, j, bits, ret = 0, wstart, window;
|
618
|
+
int start = 1;
|
619
|
+
BIGNUM *d, *r;
|
620
|
+
const BIGNUM *aa;
|
621
|
+
/* Table of variables obtained from 'ctx' */
|
622
|
+
BIGNUM *val[TABLE_SIZE];
|
623
|
+
BN_MONT_CTX *new_mont = NULL;
|
624
|
+
|
625
|
+
if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
|
626
|
+
return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, mont);
|
627
|
+
}
|
628
|
+
|
629
|
+
if (!BN_is_odd(m)) {
|
630
|
+
OPENSSL_PUT_ERROR(BN, BN_R_CALLED_WITH_EVEN_MODULUS);
|
631
|
+
return 0;
|
632
|
+
}
|
633
|
+
bits = BN_num_bits(p);
|
634
|
+
if (bits == 0) {
|
635
|
+
ret = BN_one(rr);
|
636
|
+
return ret;
|
637
|
+
}
|
638
|
+
|
639
|
+
BN_CTX_start(ctx);
|
640
|
+
d = BN_CTX_get(ctx);
|
641
|
+
r = BN_CTX_get(ctx);
|
642
|
+
val[0] = BN_CTX_get(ctx);
|
643
|
+
if (!d || !r || !val[0]) {
|
644
|
+
goto err;
|
645
|
+
}
|
646
|
+
|
647
|
+
/* Allocate a montgomery context if it was not supplied by the caller. */
|
648
|
+
if (mont == NULL) {
|
649
|
+
new_mont = BN_MONT_CTX_new();
|
650
|
+
if (new_mont == NULL || !BN_MONT_CTX_set(new_mont, m, ctx)) {
|
651
|
+
goto err;
|
652
|
+
}
|
653
|
+
mont = new_mont;
|
654
|
+
}
|
655
|
+
|
656
|
+
if (a->neg || BN_ucmp(a, m) >= 0) {
|
657
|
+
if (!BN_nnmod(val[0], a, m, ctx)) {
|
658
|
+
goto err;
|
659
|
+
}
|
660
|
+
aa = val[0];
|
661
|
+
} else {
|
662
|
+
aa = a;
|
663
|
+
}
|
664
|
+
|
665
|
+
if (BN_is_zero(aa)) {
|
666
|
+
BN_zero(rr);
|
667
|
+
ret = 1;
|
668
|
+
goto err;
|
669
|
+
}
|
670
|
+
if (!BN_to_montgomery(val[0], aa, mont, ctx)) {
|
671
|
+
goto err; /* 1 */
|
672
|
+
}
|
673
|
+
|
674
|
+
window = BN_window_bits_for_exponent_size(bits);
|
675
|
+
if (window > 1) {
|
676
|
+
if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx)) {
|
677
|
+
goto err; /* 2 */
|
678
|
+
}
|
679
|
+
j = 1 << (window - 1);
|
680
|
+
for (i = 1; i < j; i++) {
|
681
|
+
if (((val[i] = BN_CTX_get(ctx)) == NULL) ||
|
682
|
+
!BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx)) {
|
683
|
+
goto err;
|
684
|
+
}
|
685
|
+
}
|
686
|
+
}
|
687
|
+
|
688
|
+
start = 1; /* This is used to avoid multiplication etc
|
689
|
+
* when there is only the value '1' in the
|
690
|
+
* buffer. */
|
691
|
+
wstart = bits - 1; /* The top bit of the window */
|
692
|
+
|
693
|
+
j = m->top; /* borrow j */
|
694
|
+
if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {
|
695
|
+
if (bn_wexpand(r, j) == NULL) {
|
696
|
+
goto err;
|
697
|
+
}
|
698
|
+
/* 2^(top*BN_BITS2) - m */
|
699
|
+
r->d[0] = (0 - m->d[0]) & BN_MASK2;
|
700
|
+
for (i = 1; i < j; i++) {
|
701
|
+
r->d[i] = (~m->d[i]) & BN_MASK2;
|
702
|
+
}
|
703
|
+
r->top = j;
|
704
|
+
/* Upper words will be zero if the corresponding words of 'm'
|
705
|
+
* were 0xfff[...], so decrement r->top accordingly. */
|
706
|
+
bn_correct_top(r);
|
707
|
+
} else if (!BN_to_montgomery(r, BN_value_one(), mont, ctx)) {
|
708
|
+
goto err;
|
709
|
+
}
|
710
|
+
|
711
|
+
for (;;) {
|
712
|
+
int wvalue; /* The 'value' of the window */
|
713
|
+
int wend; /* The bottom bit of the window */
|
714
|
+
|
715
|
+
if (BN_is_bit_set(p, wstart) == 0) {
|
716
|
+
if (!start && !BN_mod_mul_montgomery(r, r, r, mont, ctx)) {
|
717
|
+
goto err;
|
718
|
+
}
|
719
|
+
if (wstart == 0) {
|
720
|
+
break;
|
721
|
+
}
|
722
|
+
wstart--;
|
723
|
+
continue;
|
724
|
+
}
|
725
|
+
|
726
|
+
/* We now have wstart on a 'set' bit, we now need to work out how bit a
|
727
|
+
* window to do. To do this we need to scan forward until the last set bit
|
728
|
+
* before the end of the window */
|
729
|
+
wvalue = 1;
|
730
|
+
wend = 0;
|
731
|
+
for (i = 1; i < window; i++) {
|
732
|
+
if (wstart - i < 0) {
|
733
|
+
break;
|
734
|
+
}
|
735
|
+
if (BN_is_bit_set(p, wstart - i)) {
|
736
|
+
wvalue <<= (i - wend);
|
737
|
+
wvalue |= 1;
|
738
|
+
wend = i;
|
739
|
+
}
|
740
|
+
}
|
741
|
+
|
742
|
+
/* wend is the size of the current window */
|
743
|
+
j = wend + 1;
|
744
|
+
/* add the 'bytes above' */
|
745
|
+
if (!start) {
|
746
|
+
for (i = 0; i < j; i++) {
|
747
|
+
if (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) {
|
748
|
+
goto err;
|
749
|
+
}
|
750
|
+
}
|
751
|
+
}
|
752
|
+
|
753
|
+
/* wvalue will be an odd number < 2^window */
|
754
|
+
if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx)) {
|
755
|
+
goto err;
|
756
|
+
}
|
757
|
+
|
758
|
+
/* move the 'window' down further */
|
759
|
+
wstart -= wend + 1;
|
760
|
+
start = 0;
|
761
|
+
if (wstart < 0) {
|
762
|
+
break;
|
763
|
+
}
|
764
|
+
}
|
765
|
+
|
766
|
+
if (!BN_from_montgomery(rr, r, mont, ctx)) {
|
767
|
+
goto err;
|
768
|
+
}
|
769
|
+
ret = 1;
|
770
|
+
|
771
|
+
err:
|
772
|
+
BN_MONT_CTX_free(new_mont);
|
773
|
+
BN_CTX_end(ctx);
|
774
|
+
return ret;
|
775
|
+
}
|
776
|
+
|
777
|
+
/* BN_mod_exp_mont_consttime() stores the precomputed powers in a specific
|
778
|
+
* layout so that accessing any of these table values shows the same access
|
779
|
+
* pattern as far as cache lines are concerned. The following functions are
|
780
|
+
* used to transfer a BIGNUM from/to that table. */
|
781
|
+
static int copy_to_prebuf(const BIGNUM *b, int top, unsigned char *buf, int idx,
|
782
|
+
int width) {
|
783
|
+
size_t i, j;
|
784
|
+
|
785
|
+
if (top > b->top) {
|
786
|
+
top = b->top; /* this works because 'buf' is explicitly zeroed */
|
787
|
+
}
|
788
|
+
for (i = 0, j = idx; i < top * sizeof b->d[0]; i++, j += width) {
|
789
|
+
buf[j] = ((unsigned char *)b->d)[i];
|
790
|
+
}
|
791
|
+
|
792
|
+
return 1;
|
793
|
+
}
|
794
|
+
|
795
|
+
static int copy_from_prebuf(BIGNUM *b, int top, unsigned char *buf, int idx,
|
796
|
+
int width) {
|
797
|
+
size_t i, j;
|
798
|
+
|
799
|
+
if (bn_wexpand(b, top) == NULL) {
|
800
|
+
return 0;
|
801
|
+
}
|
802
|
+
|
803
|
+
for (i = 0, j = idx; i < top * sizeof b->d[0]; i++, j += width) {
|
804
|
+
((unsigned char *)b->d)[i] = buf[j];
|
805
|
+
}
|
806
|
+
|
807
|
+
b->top = top;
|
808
|
+
bn_correct_top(b);
|
809
|
+
return 1;
|
810
|
+
}
|
811
|
+
|
812
|
+
/* BN_mod_exp_mont_conttime is based on the assumption that the L1 data cache
|
813
|
+
* line width of the target processor is at least the following value. */
|
814
|
+
#define MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH (64)
|
815
|
+
#define MOD_EXP_CTIME_MIN_CACHE_LINE_MASK \
|
816
|
+
(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH - 1)
|
817
|
+
|
818
|
+
/* Window sizes optimized for fixed window size modular exponentiation
|
819
|
+
* algorithm (BN_mod_exp_mont_consttime).
|
820
|
+
*
|
821
|
+
* To achieve the security goals of BN_mode_exp_mont_consttime, the maximum
|
822
|
+
* size of the window must not exceed
|
823
|
+
* log_2(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH).
|
824
|
+
*
|
825
|
+
* Window size thresholds are defined for cache line sizes of 32 and 64, cache
|
826
|
+
* line sizes where log_2(32)=5 and log_2(64)=6 respectively. A window size of
|
827
|
+
* 7 should only be used on processors that have a 128 byte or greater cache
|
828
|
+
* line size. */
|
829
|
+
#if MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH == 64
|
830
|
+
|
831
|
+
#define BN_window_bits_for_ctime_exponent_size(b) \
|
832
|
+
((b) > 937 ? 6 : (b) > 306 ? 5 : (b) > 89 ? 4 : (b) > 22 ? 3 : 1)
|
833
|
+
#define BN_MAX_WINDOW_BITS_FOR_CTIME_EXPONENT_SIZE (6)
|
834
|
+
|
835
|
+
#elif MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH == 32
|
836
|
+
|
837
|
+
#define BN_window_bits_for_ctime_exponent_size(b) \
|
838
|
+
((b) > 306 ? 5 : (b) > 89 ? 4 : (b) > 22 ? 3 : 1)
|
839
|
+
#define BN_MAX_WINDOW_BITS_FOR_CTIME_EXPONENT_SIZE (5)
|
840
|
+
|
841
|
+
#endif
|
842
|
+
|
843
|
+
/* Given a pointer value, compute the next address that is a cache line
|
844
|
+
* multiple. */
|
845
|
+
#define MOD_EXP_CTIME_ALIGN(x_) \
|
846
|
+
((unsigned char *)(x_) + \
|
847
|
+
(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH - \
|
848
|
+
(((size_t)(x_)) & (MOD_EXP_CTIME_MIN_CACHE_LINE_MASK))))
|
849
|
+
|
850
|
+
/* This variant of BN_mod_exp_mont() uses fixed windows and the special
|
851
|
+
* precomputation memory layout to limit data-dependency to a minimum
|
852
|
+
* to protect secret exponents (cf. the hyper-threading timing attacks
|
853
|
+
* pointed out by Colin Percival,
|
854
|
+
* http://www.daemonology.net/hyperthreading-considered-harmful/)
|
855
|
+
*/
|
856
|
+
int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
857
|
+
const BIGNUM *m, BN_CTX *ctx,
|
858
|
+
const BN_MONT_CTX *mont) {
|
859
|
+
int i, bits, ret = 0, window, wvalue;
|
860
|
+
int top;
|
861
|
+
BN_MONT_CTX *new_mont = NULL;
|
862
|
+
|
863
|
+
int numPowers;
|
864
|
+
unsigned char *powerbufFree = NULL;
|
865
|
+
int powerbufLen = 0;
|
866
|
+
unsigned char *powerbuf = NULL;
|
867
|
+
BIGNUM tmp, am;
|
868
|
+
|
869
|
+
if (!BN_is_odd(m)) {
|
870
|
+
OPENSSL_PUT_ERROR(BN, BN_R_CALLED_WITH_EVEN_MODULUS);
|
871
|
+
return 0;
|
872
|
+
}
|
873
|
+
|
874
|
+
top = m->top;
|
875
|
+
|
876
|
+
bits = BN_num_bits(p);
|
877
|
+
if (bits == 0) {
|
878
|
+
ret = BN_one(rr);
|
879
|
+
return ret;
|
880
|
+
}
|
881
|
+
|
882
|
+
BN_CTX_start(ctx);
|
883
|
+
|
884
|
+
/* Allocate a montgomery context if it was not supplied by the caller. */
|
885
|
+
if (mont == NULL) {
|
886
|
+
new_mont = BN_MONT_CTX_new();
|
887
|
+
if (new_mont == NULL || !BN_MONT_CTX_set(new_mont, m, ctx)) {
|
888
|
+
goto err;
|
889
|
+
}
|
890
|
+
mont = new_mont;
|
891
|
+
}
|
892
|
+
|
893
|
+
#ifdef RSAZ_ENABLED
|
894
|
+
/* If the size of the operands allow it, perform the optimized
|
895
|
+
* RSAZ exponentiation. For further information see
|
896
|
+
* crypto/bn/rsaz_exp.c and accompanying assembly modules. */
|
897
|
+
if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024) &&
|
898
|
+
rsaz_avx2_eligible()) {
|
899
|
+
if (NULL == bn_wexpand(rr, 16)) {
|
900
|
+
goto err;
|
901
|
+
}
|
902
|
+
RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d, mont->n0[0]);
|
903
|
+
rr->top = 16;
|
904
|
+
rr->neg = 0;
|
905
|
+
bn_correct_top(rr);
|
906
|
+
ret = 1;
|
907
|
+
goto err;
|
908
|
+
} else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {
|
909
|
+
if (NULL == bn_wexpand(rr, 8)) {
|
910
|
+
goto err;
|
911
|
+
}
|
912
|
+
RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);
|
913
|
+
rr->top = 8;
|
914
|
+
rr->neg = 0;
|
915
|
+
bn_correct_top(rr);
|
916
|
+
ret = 1;
|
917
|
+
goto err;
|
918
|
+
}
|
919
|
+
#endif
|
920
|
+
|
921
|
+
/* Get the window size to use with size of p. */
|
922
|
+
window = BN_window_bits_for_ctime_exponent_size(bits);
|
923
|
+
#if defined(OPENSSL_BN_ASM_MONT5)
|
924
|
+
if (window >= 5) {
|
925
|
+
window = 5; /* ~5% improvement for RSA2048 sign, and even for RSA4096 */
|
926
|
+
if ((top & 7) == 0) {
|
927
|
+
powerbufLen += 2 * top * sizeof(m->d[0]);
|
928
|
+
}
|
929
|
+
}
|
930
|
+
#endif
|
931
|
+
|
932
|
+
/* Allocate a buffer large enough to hold all of the pre-computed
|
933
|
+
* powers of am, am itself and tmp.
|
934
|
+
*/
|
935
|
+
numPowers = 1 << window;
|
936
|
+
powerbufLen +=
|
937
|
+
sizeof(m->d[0]) *
|
938
|
+
(top * numPowers + ((2 * top) > numPowers ? (2 * top) : numPowers));
|
939
|
+
#ifdef alloca
|
940
|
+
if (powerbufLen < 3072) {
|
941
|
+
powerbufFree = alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);
|
942
|
+
} else
|
943
|
+
#endif
|
944
|
+
{
|
945
|
+
if ((powerbufFree = (unsigned char *)OPENSSL_malloc(
|
946
|
+
powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL) {
|
947
|
+
goto err;
|
948
|
+
}
|
949
|
+
}
|
950
|
+
|
951
|
+
powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);
|
952
|
+
memset(powerbuf, 0, powerbufLen);
|
953
|
+
|
954
|
+
#ifdef alloca
|
955
|
+
if (powerbufLen < 3072) {
|
956
|
+
powerbufFree = NULL;
|
957
|
+
}
|
958
|
+
#endif
|
959
|
+
|
960
|
+
/* lay down tmp and am right after powers table */
|
961
|
+
tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);
|
962
|
+
am.d = tmp.d + top;
|
963
|
+
tmp.top = am.top = 0;
|
964
|
+
tmp.dmax = am.dmax = top;
|
965
|
+
tmp.neg = am.neg = 0;
|
966
|
+
tmp.flags = am.flags = BN_FLG_STATIC_DATA;
|
967
|
+
|
968
|
+
/* prepare a^0 in Montgomery domain */
|
969
|
+
/* by Shay Gueron's suggestion */
|
970
|
+
if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {
|
971
|
+
/* 2^(top*BN_BITS2) - m */
|
972
|
+
tmp.d[0] = (0 - m->d[0]) & BN_MASK2;
|
973
|
+
for (i = 1; i < top; i++) {
|
974
|
+
tmp.d[i] = (~m->d[i]) & BN_MASK2;
|
975
|
+
}
|
976
|
+
tmp.top = top;
|
977
|
+
} else if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx)) {
|
978
|
+
goto err;
|
979
|
+
}
|
980
|
+
|
981
|
+
/* prepare a^1 in Montgomery domain */
|
982
|
+
if (a->neg || BN_ucmp(a, m) >= 0) {
|
983
|
+
if (!BN_mod(&am, a, m, ctx) ||
|
984
|
+
!BN_to_montgomery(&am, &am, mont, ctx)) {
|
985
|
+
goto err;
|
986
|
+
}
|
987
|
+
} else if (!BN_to_montgomery(&am, a, mont, ctx)) {
|
988
|
+
goto err;
|
989
|
+
}
|
990
|
+
|
991
|
+
#if defined(OPENSSL_BN_ASM_MONT5)
|
992
|
+
/* This optimization uses ideas from http://eprint.iacr.org/2011/239,
|
993
|
+
* specifically optimization of cache-timing attack countermeasures
|
994
|
+
* and pre-computation optimization. */
|
995
|
+
|
996
|
+
/* Dedicated window==4 case improves 512-bit RSA sign by ~15%, but as
|
997
|
+
* 512-bit RSA is hardly relevant, we omit it to spare size... */
|
998
|
+
if (window == 5 && top > 1) {
|
999
|
+
const BN_ULONG *np = mont->N.d, *n0 = mont->n0, *np2;
|
1000
|
+
|
1001
|
+
/* BN_to_montgomery can contaminate words above .top
|
1002
|
+
* [in BN_DEBUG[_DEBUG] build]... */
|
1003
|
+
for (i = am.top; i < top; i++) {
|
1004
|
+
am.d[i] = 0;
|
1005
|
+
}
|
1006
|
+
for (i = tmp.top; i < top; i++) {
|
1007
|
+
tmp.d[i] = 0;
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
if (top & 7) {
|
1011
|
+
np2 = np;
|
1012
|
+
} else {
|
1013
|
+
BN_ULONG *np_double = am.d + top;
|
1014
|
+
for (i = 0; i < top; i++) {
|
1015
|
+
np_double[2 * i] = np[i];
|
1016
|
+
}
|
1017
|
+
np2 = np_double;
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
bn_scatter5(tmp.d, top, powerbuf, 0);
|
1021
|
+
bn_scatter5(am.d, am.top, powerbuf, 1);
|
1022
|
+
bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);
|
1023
|
+
bn_scatter5(tmp.d, top, powerbuf, 2);
|
1024
|
+
|
1025
|
+
/* same as above, but uses squaring for 1/2 of operations */
|
1026
|
+
for (i = 4; i < 32; i *= 2) {
|
1027
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1028
|
+
bn_scatter5(tmp.d, top, powerbuf, i);
|
1029
|
+
}
|
1030
|
+
for (i = 3; i < 8; i += 2) {
|
1031
|
+
int j;
|
1032
|
+
bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np2, n0, top, i - 1);
|
1033
|
+
bn_scatter5(tmp.d, top, powerbuf, i);
|
1034
|
+
for (j = 2 * i; j < 32; j *= 2) {
|
1035
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1036
|
+
bn_scatter5(tmp.d, top, powerbuf, j);
|
1037
|
+
}
|
1038
|
+
}
|
1039
|
+
for (; i < 16; i += 2) {
|
1040
|
+
bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np2, n0, top, i - 1);
|
1041
|
+
bn_scatter5(tmp.d, top, powerbuf, i);
|
1042
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1043
|
+
bn_scatter5(tmp.d, top, powerbuf, 2 * i);
|
1044
|
+
}
|
1045
|
+
for (; i < 32; i += 2) {
|
1046
|
+
bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np2, n0, top, i - 1);
|
1047
|
+
bn_scatter5(tmp.d, top, powerbuf, i);
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
bits--;
|
1051
|
+
for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--) {
|
1052
|
+
wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);
|
1053
|
+
}
|
1054
|
+
bn_gather5(tmp.d, top, powerbuf, wvalue);
|
1055
|
+
|
1056
|
+
/* At this point |bits| is 4 mod 5 and at least -1. (|bits| is the first bit
|
1057
|
+
* that has not been read yet.) */
|
1058
|
+
assert(bits >= -1 && (bits == -1 || bits % 5 == 4));
|
1059
|
+
|
1060
|
+
/* Scan the exponent one window at a time starting from the most
|
1061
|
+
* significant bits.
|
1062
|
+
*/
|
1063
|
+
if (top & 7) {
|
1064
|
+
while (bits >= 0) {
|
1065
|
+
for (wvalue = 0, i = 0; i < 5; i++, bits--) {
|
1066
|
+
wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);
|
1067
|
+
}
|
1068
|
+
|
1069
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1070
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1071
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1072
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1073
|
+
bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);
|
1074
|
+
bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);
|
1075
|
+
}
|
1076
|
+
} else {
|
1077
|
+
const uint8_t *p_bytes = (const uint8_t *)p->d;
|
1078
|
+
int max_bits = p->top * BN_BITS2;
|
1079
|
+
assert(bits < max_bits);
|
1080
|
+
/* |p = 0| has been handled as a special case, so |max_bits| is at least
|
1081
|
+
* one word. */
|
1082
|
+
assert(max_bits >= 64);
|
1083
|
+
|
1084
|
+
/* If the first bit to be read lands in the last byte, unroll the first
|
1085
|
+
* iteration to avoid reading past the bounds of |p->d|. (After the first
|
1086
|
+
* iteration, we are guaranteed to be past the last byte.) Note |bits|
|
1087
|
+
* here is the top bit, inclusive. */
|
1088
|
+
if (bits - 4 >= max_bits - 8) {
|
1089
|
+
/* Read five bits from |bits-4| through |bits|, inclusive. */
|
1090
|
+
wvalue = p_bytes[p->top * BN_BYTES - 1];
|
1091
|
+
wvalue >>= (bits - 4) & 7;
|
1092
|
+
wvalue &= 0x1f;
|
1093
|
+
bits -= 5;
|
1094
|
+
bn_power5(tmp.d, tmp.d, powerbuf, np2, n0, top, wvalue);
|
1095
|
+
}
|
1096
|
+
while (bits >= 0) {
|
1097
|
+
/* Read five bits from |bits-4| through |bits|, inclusive. */
|
1098
|
+
int first_bit = bits - 4;
|
1099
|
+
wvalue = *(const uint16_t *) (p_bytes + (first_bit >> 3));
|
1100
|
+
wvalue >>= first_bit & 7;
|
1101
|
+
wvalue &= 0x1f;
|
1102
|
+
bits -= 5;
|
1103
|
+
bn_power5(tmp.d, tmp.d, powerbuf, np2, n0, top, wvalue);
|
1104
|
+
}
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np2, n0, top);
|
1108
|
+
tmp.top = top;
|
1109
|
+
bn_correct_top(&tmp);
|
1110
|
+
if (ret) {
|
1111
|
+
if (!BN_copy(rr, &tmp)) {
|
1112
|
+
ret = 0;
|
1113
|
+
}
|
1114
|
+
goto err; /* non-zero ret means it's not error */
|
1115
|
+
}
|
1116
|
+
} else
|
1117
|
+
#endif
|
1118
|
+
{
|
1119
|
+
if (!copy_to_prebuf(&tmp, top, powerbuf, 0, numPowers) ||
|
1120
|
+
!copy_to_prebuf(&am, top, powerbuf, 1, numPowers)) {
|
1121
|
+
goto err;
|
1122
|
+
}
|
1123
|
+
|
1124
|
+
/* If the window size is greater than 1, then calculate
|
1125
|
+
* val[i=2..2^winsize-1]. Powers are computed as a*a^(i-1)
|
1126
|
+
* (even powers could instead be computed as (a^(i/2))^2
|
1127
|
+
* to use the slight performance advantage of sqr over mul).
|
1128
|
+
*/
|
1129
|
+
if (window > 1) {
|
1130
|
+
if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx) ||
|
1131
|
+
!copy_to_prebuf(&tmp, top, powerbuf, 2, numPowers)) {
|
1132
|
+
goto err;
|
1133
|
+
}
|
1134
|
+
for (i = 3; i < numPowers; i++) {
|
1135
|
+
/* Calculate a^i = a^(i-1) * a */
|
1136
|
+
if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx) ||
|
1137
|
+
!copy_to_prebuf(&tmp, top, powerbuf, i, numPowers)) {
|
1138
|
+
goto err;
|
1139
|
+
}
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
bits--;
|
1144
|
+
for (wvalue = 0, i = bits % window; i >= 0; i--, bits--) {
|
1145
|
+
wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);
|
1146
|
+
}
|
1147
|
+
if (!copy_from_prebuf(&tmp, top, powerbuf, wvalue, numPowers)) {
|
1148
|
+
goto err;
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
/* Scan the exponent one window at a time starting from the most
|
1152
|
+
* significant bits.
|
1153
|
+
*/
|
1154
|
+
while (bits >= 0) {
|
1155
|
+
wvalue = 0; /* The 'value' of the window */
|
1156
|
+
|
1157
|
+
/* Scan the window, squaring the result as we go */
|
1158
|
+
for (i = 0; i < window; i++, bits--) {
|
1159
|
+
if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx)) {
|
1160
|
+
goto err;
|
1161
|
+
}
|
1162
|
+
wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
/* Fetch the appropriate pre-computed value from the pre-buf */
|
1166
|
+
if (!copy_from_prebuf(&am, top, powerbuf, wvalue, numPowers)) {
|
1167
|
+
goto err;
|
1168
|
+
}
|
1169
|
+
|
1170
|
+
/* Multiply the result into the intermediate result */
|
1171
|
+
if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx)) {
|
1172
|
+
goto err;
|
1173
|
+
}
|
1174
|
+
}
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
/* Convert the final result from montgomery to standard format */
|
1178
|
+
if (!BN_from_montgomery(rr, &tmp, mont, ctx)) {
|
1179
|
+
goto err;
|
1180
|
+
}
|
1181
|
+
ret = 1;
|
1182
|
+
|
1183
|
+
err:
|
1184
|
+
BN_MONT_CTX_free(new_mont);
|
1185
|
+
if (powerbuf != NULL) {
|
1186
|
+
OPENSSL_cleanse(powerbuf, powerbufLen);
|
1187
|
+
OPENSSL_free(powerbufFree);
|
1188
|
+
}
|
1189
|
+
BN_CTX_end(ctx);
|
1190
|
+
return (ret);
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
|
1194
|
+
const BIGNUM *m, BN_CTX *ctx,
|
1195
|
+
const BN_MONT_CTX *mont) {
|
1196
|
+
BN_MONT_CTX *new_mont = NULL;
|
1197
|
+
int b, bits, ret = 0;
|
1198
|
+
int r_is_one;
|
1199
|
+
BN_ULONG w, next_w;
|
1200
|
+
BIGNUM *d, *r, *t;
|
1201
|
+
BIGNUM *swap_tmp;
|
1202
|
+
#define BN_MOD_MUL_WORD(r, w, m) \
|
1203
|
+
(BN_mul_word(r, (w)) && \
|
1204
|
+
(/* BN_ucmp(r, (m)) < 0 ? 1 :*/ \
|
1205
|
+
(BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))
|
1206
|
+
/* BN_MOD_MUL_WORD is only used with 'w' large, so the BN_ucmp test is
|
1207
|
+
* probably more overhead than always using BN_mod (which uses BN_copy if a
|
1208
|
+
* similar test returns true). We can use BN_mod and do not need BN_nnmod
|
1209
|
+
* because our accumulator is never negative (the result of BN_mod does not
|
1210
|
+
* depend on the sign of the modulus). */
|
1211
|
+
#define BN_TO_MONTGOMERY_WORD(r, w, mont) \
|
1212
|
+
(BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))
|
1213
|
+
|
1214
|
+
if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
|
1215
|
+
/* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
|
1216
|
+
OPENSSL_PUT_ERROR(BN, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
1217
|
+
return 0;
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
if (!BN_is_odd(m)) {
|
1221
|
+
OPENSSL_PUT_ERROR(BN, BN_R_CALLED_WITH_EVEN_MODULUS);
|
1222
|
+
return 0;
|
1223
|
+
}
|
1224
|
+
|
1225
|
+
if (m->top == 1) {
|
1226
|
+
a %= m->d[0]; /* make sure that 'a' is reduced */
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
bits = BN_num_bits(p);
|
1230
|
+
if (bits == 0) {
|
1231
|
+
/* x**0 mod 1 is still zero. */
|
1232
|
+
if (BN_is_one(m)) {
|
1233
|
+
ret = 1;
|
1234
|
+
BN_zero(rr);
|
1235
|
+
} else {
|
1236
|
+
ret = BN_one(rr);
|
1237
|
+
}
|
1238
|
+
return ret;
|
1239
|
+
}
|
1240
|
+
if (a == 0) {
|
1241
|
+
BN_zero(rr);
|
1242
|
+
ret = 1;
|
1243
|
+
return ret;
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
BN_CTX_start(ctx);
|
1247
|
+
d = BN_CTX_get(ctx);
|
1248
|
+
r = BN_CTX_get(ctx);
|
1249
|
+
t = BN_CTX_get(ctx);
|
1250
|
+
if (d == NULL || r == NULL || t == NULL) {
|
1251
|
+
goto err;
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
/* Allocate a montgomery context if it was not supplied by the caller. */
|
1255
|
+
if (mont == NULL) {
|
1256
|
+
new_mont = BN_MONT_CTX_new();
|
1257
|
+
if (new_mont == NULL || !BN_MONT_CTX_set(new_mont, m, ctx)) {
|
1258
|
+
goto err;
|
1259
|
+
}
|
1260
|
+
mont = new_mont;
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
r_is_one = 1; /* except for Montgomery factor */
|
1264
|
+
|
1265
|
+
/* bits-1 >= 0 */
|
1266
|
+
|
1267
|
+
/* The result is accumulated in the product r*w. */
|
1268
|
+
w = a; /* bit 'bits-1' of 'p' is always set */
|
1269
|
+
for (b = bits - 2; b >= 0; b--) {
|
1270
|
+
/* First, square r*w. */
|
1271
|
+
next_w = w * w;
|
1272
|
+
if ((next_w / w) != w) {
|
1273
|
+
/* overflow */
|
1274
|
+
if (r_is_one) {
|
1275
|
+
if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) {
|
1276
|
+
goto err;
|
1277
|
+
}
|
1278
|
+
r_is_one = 0;
|
1279
|
+
} else {
|
1280
|
+
if (!BN_MOD_MUL_WORD(r, w, m)) {
|
1281
|
+
goto err;
|
1282
|
+
}
|
1283
|
+
}
|
1284
|
+
next_w = 1;
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
w = next_w;
|
1288
|
+
if (!r_is_one) {
|
1289
|
+
if (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) {
|
1290
|
+
goto err;
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
/* Second, multiply r*w by 'a' if exponent bit is set. */
|
1295
|
+
if (BN_is_bit_set(p, b)) {
|
1296
|
+
next_w = w * a;
|
1297
|
+
if ((next_w / a) != w) {
|
1298
|
+
/* overflow */
|
1299
|
+
if (r_is_one) {
|
1300
|
+
if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) {
|
1301
|
+
goto err;
|
1302
|
+
}
|
1303
|
+
r_is_one = 0;
|
1304
|
+
} else {
|
1305
|
+
if (!BN_MOD_MUL_WORD(r, w, m)) {
|
1306
|
+
goto err;
|
1307
|
+
}
|
1308
|
+
}
|
1309
|
+
next_w = a;
|
1310
|
+
}
|
1311
|
+
w = next_w;
|
1312
|
+
}
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
/* Finally, set r:=r*w. */
|
1316
|
+
if (w != 1) {
|
1317
|
+
if (r_is_one) {
|
1318
|
+
if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) {
|
1319
|
+
goto err;
|
1320
|
+
}
|
1321
|
+
r_is_one = 0;
|
1322
|
+
} else {
|
1323
|
+
if (!BN_MOD_MUL_WORD(r, w, m)) {
|
1324
|
+
goto err;
|
1325
|
+
}
|
1326
|
+
}
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
if (r_is_one) {
|
1330
|
+
/* can happen only if a == 1*/
|
1331
|
+
if (!BN_one(rr)) {
|
1332
|
+
goto err;
|
1333
|
+
}
|
1334
|
+
} else {
|
1335
|
+
if (!BN_from_montgomery(rr, r, mont, ctx)) {
|
1336
|
+
goto err;
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
ret = 1;
|
1340
|
+
|
1341
|
+
err:
|
1342
|
+
BN_MONT_CTX_free(new_mont);
|
1343
|
+
BN_CTX_end(ctx);
|
1344
|
+
return ret;
|
1345
|
+
}
|
1346
|
+
|
1347
|
+
#define TABLE_SIZE 32
|
1348
|
+
|
1349
|
+
int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
|
1350
|
+
const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
|
1351
|
+
BN_CTX *ctx, const BN_MONT_CTX *mont) {
|
1352
|
+
int i, j, bits, b, bits1, bits2, ret = 0, wpos1, wpos2, window1, window2,
|
1353
|
+
wvalue1, wvalue2;
|
1354
|
+
int r_is_one = 1;
|
1355
|
+
BIGNUM *d, *r;
|
1356
|
+
const BIGNUM *a_mod_m;
|
1357
|
+
/* Tables of variables obtained from 'ctx' */
|
1358
|
+
BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];
|
1359
|
+
BN_MONT_CTX *new_mont = NULL;
|
1360
|
+
|
1361
|
+
if (!(m->d[0] & 1)) {
|
1362
|
+
OPENSSL_PUT_ERROR(BN, BN_R_CALLED_WITH_EVEN_MODULUS);
|
1363
|
+
return 0;
|
1364
|
+
}
|
1365
|
+
bits1 = BN_num_bits(p1);
|
1366
|
+
bits2 = BN_num_bits(p2);
|
1367
|
+
if (bits1 == 0 && bits2 == 0) {
|
1368
|
+
ret = BN_one(rr);
|
1369
|
+
return ret;
|
1370
|
+
}
|
1371
|
+
|
1372
|
+
bits = (bits1 > bits2) ? bits1 : bits2;
|
1373
|
+
|
1374
|
+
BN_CTX_start(ctx);
|
1375
|
+
d = BN_CTX_get(ctx);
|
1376
|
+
r = BN_CTX_get(ctx);
|
1377
|
+
val1[0] = BN_CTX_get(ctx);
|
1378
|
+
val2[0] = BN_CTX_get(ctx);
|
1379
|
+
if (!d || !r || !val1[0] || !val2[0]) {
|
1380
|
+
goto err;
|
1381
|
+
}
|
1382
|
+
|
1383
|
+
/* Allocate a montgomery context if it was not supplied by the caller. */
|
1384
|
+
if (mont == NULL) {
|
1385
|
+
new_mont = BN_MONT_CTX_new();
|
1386
|
+
if (new_mont == NULL || !BN_MONT_CTX_set(new_mont, m, ctx)) {
|
1387
|
+
goto err;
|
1388
|
+
}
|
1389
|
+
mont = new_mont;
|
1390
|
+
}
|
1391
|
+
|
1392
|
+
window1 = BN_window_bits_for_exponent_size(bits1);
|
1393
|
+
window2 = BN_window_bits_for_exponent_size(bits2);
|
1394
|
+
|
1395
|
+
/* Build table for a1: val1[i] := a1^(2*i + 1) mod m for i = 0 ..
|
1396
|
+
* 2^(window1-1) */
|
1397
|
+
if (a1->neg || BN_ucmp(a1, m) >= 0) {
|
1398
|
+
if (!BN_mod(val1[0], a1, m, ctx)) {
|
1399
|
+
goto err;
|
1400
|
+
}
|
1401
|
+
a_mod_m = val1[0];
|
1402
|
+
} else {
|
1403
|
+
a_mod_m = a1;
|
1404
|
+
}
|
1405
|
+
|
1406
|
+
if (BN_is_zero(a_mod_m)) {
|
1407
|
+
BN_zero(rr);
|
1408
|
+
ret = 1;
|
1409
|
+
goto err;
|
1410
|
+
}
|
1411
|
+
|
1412
|
+
if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx)) {
|
1413
|
+
goto err;
|
1414
|
+
}
|
1415
|
+
|
1416
|
+
if (window1 > 1) {
|
1417
|
+
if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx)) {
|
1418
|
+
goto err;
|
1419
|
+
}
|
1420
|
+
|
1421
|
+
j = 1 << (window1 - 1);
|
1422
|
+
for (i = 1; i < j; i++) {
|
1423
|
+
if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||
|
1424
|
+
!BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx)) {
|
1425
|
+
goto err;
|
1426
|
+
}
|
1427
|
+
}
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
/* Build table for a2: val2[i] := a2^(2*i + 1) mod m for i = 0 ..
|
1431
|
+
* 2^(window2-1) */
|
1432
|
+
if (a2->neg || BN_ucmp(a2, m) >= 0) {
|
1433
|
+
if (!BN_mod(val2[0], a2, m, ctx)) {
|
1434
|
+
goto err;
|
1435
|
+
}
|
1436
|
+
a_mod_m = val2[0];
|
1437
|
+
} else {
|
1438
|
+
a_mod_m = a2;
|
1439
|
+
}
|
1440
|
+
|
1441
|
+
if (BN_is_zero(a_mod_m)) {
|
1442
|
+
BN_zero(rr);
|
1443
|
+
ret = 1;
|
1444
|
+
goto err;
|
1445
|
+
}
|
1446
|
+
|
1447
|
+
if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx)) {
|
1448
|
+
goto err;
|
1449
|
+
}
|
1450
|
+
|
1451
|
+
if (window2 > 1) {
|
1452
|
+
if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx)) {
|
1453
|
+
goto err;
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
j = 1 << (window2 - 1);
|
1457
|
+
for (i = 1; i < j; i++) {
|
1458
|
+
if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||
|
1459
|
+
!BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx)) {
|
1460
|
+
goto err;
|
1461
|
+
}
|
1462
|
+
}
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
/* Now compute the power product, using independent windows. */
|
1466
|
+
r_is_one = 1;
|
1467
|
+
wvalue1 = 0; /* The 'value' of the first window */
|
1468
|
+
wvalue2 = 0; /* The 'value' of the second window */
|
1469
|
+
wpos1 = 0; /* If wvalue1 > 0, the bottom bit of the first window */
|
1470
|
+
wpos2 = 0; /* If wvalue2 > 0, the bottom bit of the second window */
|
1471
|
+
|
1472
|
+
if (!BN_to_montgomery(r, BN_value_one(), mont, ctx)) {
|
1473
|
+
goto err;
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
for (b = bits - 1; b >= 0; b--) {
|
1477
|
+
if (!r_is_one) {
|
1478
|
+
if (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) {
|
1479
|
+
goto err;
|
1480
|
+
}
|
1481
|
+
}
|
1482
|
+
|
1483
|
+
if (!wvalue1 && BN_is_bit_set(p1, b)) {
|
1484
|
+
/* consider bits b-window1+1 .. b for this window */
|
1485
|
+
i = b - window1 + 1;
|
1486
|
+
/* works for i<0 */
|
1487
|
+
while (!BN_is_bit_set(p1, i)) {
|
1488
|
+
i++;
|
1489
|
+
}
|
1490
|
+
wpos1 = i;
|
1491
|
+
wvalue1 = 1;
|
1492
|
+
for (i = b - 1; i >= wpos1; i--) {
|
1493
|
+
wvalue1 <<= 1;
|
1494
|
+
if (BN_is_bit_set(p1, i)) {
|
1495
|
+
wvalue1++;
|
1496
|
+
}
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
if (!wvalue2 && BN_is_bit_set(p2, b)) {
|
1501
|
+
/* consider bits b-window2+1 .. b for this window */
|
1502
|
+
i = b - window2 + 1;
|
1503
|
+
while (!BN_is_bit_set(p2, i)) {
|
1504
|
+
i++;
|
1505
|
+
}
|
1506
|
+
wpos2 = i;
|
1507
|
+
wvalue2 = 1;
|
1508
|
+
for (i = b - 1; i >= wpos2; i--) {
|
1509
|
+
wvalue2 <<= 1;
|
1510
|
+
if (BN_is_bit_set(p2, i)) {
|
1511
|
+
wvalue2++;
|
1512
|
+
}
|
1513
|
+
}
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
if (wvalue1 && b == wpos1) {
|
1517
|
+
/* wvalue1 is odd and < 2^window1 */
|
1518
|
+
if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx)) {
|
1519
|
+
goto err;
|
1520
|
+
}
|
1521
|
+
wvalue1 = 0;
|
1522
|
+
r_is_one = 0;
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
if (wvalue2 && b == wpos2) {
|
1526
|
+
/* wvalue2 is odd and < 2^window2 */
|
1527
|
+
if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx)) {
|
1528
|
+
goto err;
|
1529
|
+
}
|
1530
|
+
wvalue2 = 0;
|
1531
|
+
r_is_one = 0;
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
|
1535
|
+
if (!BN_from_montgomery(rr, r, mont, ctx)) {
|
1536
|
+
goto err;
|
1537
|
+
}
|
1538
|
+
ret = 1;
|
1539
|
+
|
1540
|
+
err:
|
1541
|
+
BN_MONT_CTX_free(new_mont);
|
1542
|
+
BN_CTX_end(ctx);
|
1543
|
+
return ret;
|
1544
|
+
}
|