grpc 1.24.0 → 1.25.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +306 -243
- data/etc/roots.pem +0 -100
- data/include/grpc/grpc_security.h +44 -18
- data/include/grpc/impl/codegen/grpc_types.h +15 -0
- data/include/grpc/impl/codegen/port_platform.h +27 -11
- data/include/grpc/impl/codegen/sync_generic.h +1 -1
- data/src/boringssl/err_data.c +695 -650
- data/src/core/ext/filters/client_channel/client_channel.cc +257 -179
- data/src/core/ext/filters/client_channel/client_channel.h +24 -0
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
- data/src/core/ext/filters/client_channel/client_channel_factory.h +1 -5
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +18 -45
- data/src/core/ext/filters/client_channel/health/health_check_client.h +5 -13
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.h +65 -55
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +14 -14
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +113 -36
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +14 -19
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +36 -13
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +3 -10
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +814 -1589
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +2 -5
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +3 -6
- data/src/core/ext/filters/client_channel/resolver.cc +1 -2
- data/src/core/ext/filters/client_channel/resolver.h +8 -16
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +25 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +46 -12
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +10 -17
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +7 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +111 -44
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +22 -14
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +29 -10
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +27 -36
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +7 -10
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +60 -16
- data/src/core/ext/filters/client_channel/resolver_factory.h +4 -8
- data/src/core/ext/filters/client_channel/resolver_registry.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver_registry.h +1 -1
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -10
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +7 -8
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -1
- data/src/core/ext/filters/client_channel/retry_throttle.cc +5 -5
- data/src/core/ext/filters/client_channel/retry_throttle.h +1 -4
- data/src/core/ext/filters/client_channel/service_config.h +8 -8
- data/src/core/ext/filters/client_channel/subchannel.cc +53 -86
- data/src/core/ext/filters/client_channel/subchannel.h +7 -9
- data/src/core/ext/filters/client_channel/subchannel_interface.h +9 -13
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +3 -6
- data/src/core/ext/filters/client_channel/{lb_policy/xds/xds_load_balancer_api.cc → xds/xds_api.cc} +169 -52
- data/src/core/ext/filters/client_channel/xds/xds_api.h +171 -0
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +450 -0
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +99 -0
- data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_channel.h +8 -6
- data/src/core/ext/filters/client_channel/xds/xds_channel_args.h +26 -0
- data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_channel_secure.cc +28 -11
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +1413 -0
- data/src/core/ext/filters/client_channel/xds/xds_client.h +221 -0
- data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_client_stats.cc +1 -5
- data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_client_stats.h +3 -4
- data/src/core/ext/filters/deadline/deadline_filter.cc +20 -20
- data/src/core/ext/filters/http/client/http_client_filter.cc +15 -15
- data/src/core/ext/filters/http/client_authority_filter.cc +14 -14
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +12 -12
- data/src/core/ext/filters/max_age/max_age_filter.cc +59 -50
- data/src/core/ext/filters/message_size/message_size_filter.cc +18 -18
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +15 -14
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +233 -175
- data/src/core/ext/transport/chttp2/transport/flow_control.h +21 -24
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +253 -163
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +24 -12
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +2 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +13 -15
- data/src/core/ext/transport/chttp2/transport/writing.cc +3 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +20 -13
- data/src/core/lib/channel/channel_args.cc +16 -0
- data/src/core/lib/channel/channel_args.h +22 -0
- data/src/core/lib/channel/channelz.cc +5 -6
- data/src/core/lib/channel/channelz.h +1 -1
- data/src/core/lib/channel/connected_channel.cc +20 -20
- data/src/core/lib/channel/handshaker.h +3 -4
- data/src/core/lib/channel/handshaker_factory.h +1 -3
- data/src/core/lib/debug/trace.h +3 -2
- data/src/core/lib/gprpp/arena.cc +3 -3
- data/src/core/lib/gprpp/arena.h +2 -3
- data/src/core/lib/gprpp/inlined_vector.h +9 -0
- data/src/core/lib/gprpp/map.h +3 -501
- data/src/core/lib/gprpp/memory.h +45 -41
- data/src/core/lib/gprpp/mpscq.cc +108 -0
- data/src/core/lib/gprpp/mpscq.h +98 -0
- data/src/core/lib/gprpp/orphanable.h +6 -11
- data/src/core/lib/gprpp/ref_counted.h +25 -19
- data/src/core/lib/gprpp/set.h +33 -0
- data/src/core/lib/gprpp/thd.h +2 -4
- data/src/core/lib/http/httpcli.cc +1 -1
- data/src/core/lib/http/httpcli_security_connector.cc +15 -11
- data/src/core/lib/http/parser.cc +1 -1
- data/src/core/lib/iomgr/buffer_list.cc +4 -5
- data/src/core/lib/iomgr/buffer_list.h +5 -6
- data/src/core/lib/iomgr/call_combiner.cc +4 -5
- data/src/core/lib/iomgr/call_combiner.h +2 -2
- data/src/core/lib/iomgr/cfstream_handle.h +3 -5
- data/src/core/lib/iomgr/closure.h +8 -3
- data/src/core/lib/iomgr/combiner.cc +45 -82
- data/src/core/lib/iomgr/combiner.h +32 -8
- data/src/core/lib/iomgr/endpoint_cfstream.cc +5 -3
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +19 -15
- data/src/core/lib/iomgr/exec_ctx.h +4 -3
- data/src/core/lib/iomgr/executor.cc +4 -2
- data/src/core/lib/iomgr/executor.h +3 -0
- data/src/core/lib/iomgr/executor/mpmcqueue.h +3 -6
- data/src/core/lib/iomgr/executor/threadpool.cc +1 -2
- data/src/core/lib/iomgr/executor/threadpool.h +7 -11
- data/src/core/lib/iomgr/resource_quota.cc +55 -51
- data/src/core/lib/iomgr/resource_quota.h +13 -9
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +13 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +4 -0
- data/src/core/lib/iomgr/tcp_client_posix.cc +4 -11
- data/src/core/lib/iomgr/tcp_custom.cc +9 -7
- data/src/core/lib/iomgr/tcp_posix.cc +20 -16
- data/src/core/lib/iomgr/tcp_server.h +1 -4
- data/src/core/lib/iomgr/tcp_server_custom.cc +5 -5
- data/src/core/lib/iomgr/tcp_server_posix.cc +1 -1
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +2 -11
- data/src/core/lib/iomgr/timer_custom.cc +2 -2
- data/src/core/lib/iomgr/udp_server.cc +3 -2
- data/src/core/lib/iomgr/udp_server.h +6 -12
- data/src/core/lib/json/json.h +1 -1
- data/src/core/lib/json/json_string.cc +2 -2
- data/src/core/lib/profiling/basic_timers.cc +2 -2
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +2 -2
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +1 -1
- data/src/core/lib/security/credentials/credentials.h +4 -20
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +4 -4
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +1 -3
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +64 -0
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +4 -4
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +9 -7
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -0
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +4 -4
- data/src/core/lib/security/security_connector/security_connector.cc +1 -0
- data/src/core/lib/security/security_connector/security_connector.h +19 -17
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +8 -5
- data/src/core/lib/security/security_connector/ssl_utils.cc +2 -2
- data/src/core/lib/security/security_connector/ssl_utils.h +1 -1
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +14 -6
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -2
- data/src/core/lib/security/transport/client_auth_filter.cc +17 -17
- data/src/core/lib/security/transport/security_handshaker.cc +29 -13
- data/src/core/lib/security/transport/security_handshaker.h +4 -2
- data/src/core/lib/security/transport/server_auth_filter.cc +14 -14
- data/src/core/lib/slice/slice.cc +2 -10
- data/src/core/lib/slice/slice_hash_table.h +4 -6
- data/src/core/lib/slice/slice_intern.cc +42 -39
- data/src/core/lib/slice/slice_internal.h +3 -3
- data/src/core/lib/slice/slice_utils.h +21 -4
- data/src/core/lib/slice/slice_weak_hash_table.h +4 -6
- data/src/core/lib/surface/call.cc +3 -3
- data/src/core/lib/surface/channel.cc +7 -0
- data/src/core/lib/surface/completion_queue.cc +12 -11
- data/src/core/lib/surface/completion_queue.h +4 -2
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/lame_client.cc +33 -18
- data/src/core/lib/surface/server.cc +77 -76
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/byte_stream.h +3 -7
- data/src/core/lib/transport/connectivity_state.cc +112 -98
- data/src/core/lib/transport/connectivity_state.h +100 -50
- data/src/core/lib/transport/static_metadata.cc +276 -288
- data/src/core/lib/transport/static_metadata.h +73 -76
- data/src/core/lib/transport/status_conversion.cc +1 -1
- data/src/core/lib/transport/status_metadata.cc +1 -1
- data/src/core/lib/transport/transport.cc +2 -2
- data/src/core/lib/transport/transport.h +12 -4
- data/src/core/lib/transport/transport_op_string.cc +14 -11
- data/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_shared_resource.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +5 -5
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +12 -2
- data/src/core/tsi/fake_transport_security.cc +7 -5
- data/src/core/tsi/grpc_shadow_boringssl.h +2918 -2627
- data/src/core/tsi/local_transport_security.cc +8 -6
- data/src/core/tsi/ssl/session_cache/ssl_session.h +1 -3
- data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -2
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +7 -5
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -6
- data/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +1 -2
- data/src/core/tsi/ssl_transport_security.cc +12 -12
- data/src/core/tsi/ssl_transport_security.h +2 -2
- data/src/core/tsi/transport_security_grpc.cc +7 -0
- data/src/core/tsi/transport_security_grpc.h +6 -0
- data/src/ruby/ext/grpc/extconf.rb +1 -0
- data/src/ruby/ext/grpc/rb_call.c +1 -1
- data/src/ruby/ext/grpc/rb_channel.c +1 -1
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +2 -2
- data/third_party/boringssl/crypto/asn1/a_bool.c +18 -5
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +17 -221
- data/third_party/boringssl/crypto/asn1/a_dup.c +0 -24
- data/third_party/boringssl/crypto/asn1/a_enum.c +2 -2
- data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +10 -72
- data/third_party/boringssl/crypto/asn1/a_int.c +12 -71
- data/third_party/boringssl/crypto/asn1/a_mbstr.c +110 -216
- data/third_party/boringssl/crypto/asn1/a_object.c +16 -5
- data/third_party/boringssl/crypto/asn1/a_strnid.c +1 -0
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +5 -1
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +3 -1
- data/third_party/boringssl/crypto/base64/base64.c +2 -2
- data/third_party/boringssl/crypto/bio/bio.c +73 -9
- data/third_party/boringssl/crypto/bio/connect.c +4 -0
- data/third_party/boringssl/crypto/bio/fd.c +4 -0
- data/third_party/boringssl/crypto/bio/file.c +5 -2
- data/third_party/boringssl/crypto/bio/socket.c +4 -0
- data/third_party/boringssl/crypto/bio/socket_helper.c +4 -0
- data/third_party/boringssl/crypto/bn_extra/convert.c +11 -7
- data/third_party/boringssl/crypto/bytestring/ber.c +8 -4
- data/third_party/boringssl/crypto/bytestring/cbb.c +19 -7
- data/third_party/boringssl/crypto/bytestring/cbs.c +28 -15
- data/third_party/boringssl/crypto/bytestring/internal.h +28 -7
- data/third_party/boringssl/crypto/bytestring/unicode.c +155 -0
- data/third_party/boringssl/crypto/chacha/chacha.c +36 -19
- data/third_party/boringssl/crypto/chacha/internal.h +45 -0
- data/third_party/boringssl/crypto/cipher_extra/cipher_extra.c +29 -0
- data/third_party/boringssl/crypto/cipher_extra/e_aesccm.c +269 -25
- data/third_party/boringssl/crypto/cipher_extra/e_aesctrhmac.c +16 -14
- data/third_party/boringssl/crypto/cipher_extra/e_aesgcmsiv.c +54 -38
- data/third_party/boringssl/crypto/cipher_extra/e_chacha20poly1305.c +133 -41
- data/third_party/boringssl/crypto/cipher_extra/e_tls.c +23 -15
- data/third_party/boringssl/crypto/cipher_extra/tls_cbc.c +24 -15
- data/third_party/boringssl/crypto/cmac/cmac.c +62 -25
- data/third_party/boringssl/crypto/conf/conf.c +7 -0
- data/third_party/boringssl/crypto/cpu-arm-linux.c +4 -148
- data/third_party/boringssl/crypto/cpu-arm-linux.h +201 -0
- data/third_party/boringssl/crypto/cpu-intel.c +45 -51
- data/third_party/boringssl/crypto/crypto.c +39 -22
- data/third_party/boringssl/crypto/curve25519/spake25519.c +1 -1
- data/third_party/boringssl/crypto/dsa/dsa.c +77 -53
- data/third_party/boringssl/crypto/ec_extra/ec_asn1.c +20 -8
- data/third_party/boringssl/crypto/ec_extra/ec_derive.c +96 -0
- data/third_party/boringssl/crypto/{ecdh/ecdh.c → ecdh_extra/ecdh_extra.c} +20 -58
- data/third_party/boringssl/crypto/ecdsa_extra/ecdsa_asn1.c +1 -9
- data/third_party/boringssl/crypto/engine/engine.c +2 -1
- data/third_party/boringssl/crypto/err/err.c +2 -0
- data/third_party/boringssl/crypto/err/internal.h +2 -2
- data/third_party/boringssl/crypto/evp/evp.c +89 -8
- data/third_party/boringssl/crypto/evp/evp_asn1.c +56 -5
- data/third_party/boringssl/crypto/evp/evp_ctx.c +52 -14
- data/third_party/boringssl/crypto/evp/internal.h +18 -1
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +5 -0
- data/third_party/boringssl/crypto/evp/p_ec.c +51 -3
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +6 -7
- data/third_party/boringssl/crypto/evp/p_ed25519.c +36 -3
- data/third_party/boringssl/crypto/evp/p_ed25519_asn1.c +76 -45
- data/third_party/boringssl/crypto/evp/p_rsa.c +3 -1
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +5 -0
- data/third_party/boringssl/crypto/evp/p_x25519.c +110 -0
- data/third_party/boringssl/crypto/evp/p_x25519_asn1.c +249 -0
- data/third_party/boringssl/crypto/evp/scrypt.c +6 -2
- data/third_party/boringssl/crypto/fipsmodule/aes/aes.c +34 -274
- data/third_party/boringssl/crypto/fipsmodule/aes/internal.h +161 -21
- data/third_party/boringssl/crypto/fipsmodule/aes/key_wrap.c +111 -13
- data/third_party/boringssl/crypto/fipsmodule/aes/mode_wrappers.c +17 -21
- data/third_party/boringssl/crypto/fipsmodule/bcm.c +119 -7
- data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +19 -2
- data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +2 -2
- data/third_party/boringssl/crypto/fipsmodule/bn/ctx.c +93 -160
- data/third_party/boringssl/crypto/fipsmodule/bn/div.c +48 -57
- data/third_party/boringssl/crypto/fipsmodule/bn/div_extra.c +87 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.c +143 -211
- data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +0 -305
- data/third_party/boringssl/crypto/fipsmodule/bn/gcd_extra.c +325 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/internal.h +168 -50
- data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +68 -92
- data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +7 -6
- data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +11 -14
- data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +358 -443
- data/third_party/boringssl/crypto/fipsmodule/bn/random.c +25 -35
- data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.c +20 -25
- data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.h +76 -5
- data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +14 -14
- data/third_party/boringssl/crypto/fipsmodule/cipher/cipher.c +7 -2
- data/third_party/boringssl/crypto/fipsmodule/cipher/e_aes.c +383 -516
- data/third_party/boringssl/crypto/fipsmodule/cipher/e_des.c +4 -0
- data/third_party/boringssl/crypto/fipsmodule/cipher/internal.h +3 -4
- data/third_party/boringssl/crypto/fipsmodule/delocate.h +3 -2
- data/third_party/boringssl/crypto/fipsmodule/digest/digest.c +32 -17
- data/third_party/boringssl/crypto/fipsmodule/digest/md32_common.h +3 -3
- data/third_party/boringssl/crypto/fipsmodule/ec/ec.c +228 -122
- data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +34 -8
- data/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.c +311 -98
- data/third_party/boringssl/crypto/fipsmodule/ec/felem.c +82 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/internal.h +263 -97
- data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +22 -59
- data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +317 -234
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64-table.h +9473 -9475
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.c +313 -109
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.h +36 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/scalar.c +96 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +126 -792
- data/third_party/boringssl/crypto/fipsmodule/ec/simple_mul.c +84 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/util.c +163 -12
- data/third_party/boringssl/crypto/fipsmodule/ec/wnaf.c +84 -211
- data/third_party/boringssl/crypto/fipsmodule/ecdh/ecdh.c +122 -0
- data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +60 -205
- data/third_party/boringssl/crypto/fipsmodule/fips_shared_support.c +32 -0
- data/third_party/boringssl/crypto/fipsmodule/is_fips.c +2 -0
- data/third_party/boringssl/crypto/fipsmodule/md4/md4.c +3 -1
- data/third_party/boringssl/crypto/fipsmodule/md5/internal.h +37 -0
- data/third_party/boringssl/crypto/fipsmodule/md5/md5.c +11 -8
- data/third_party/boringssl/crypto/fipsmodule/modes/cbc.c +35 -79
- data/third_party/boringssl/crypto/fipsmodule/modes/cfb.c +7 -39
- data/third_party/boringssl/crypto/fipsmodule/modes/ctr.c +7 -27
- data/third_party/boringssl/crypto/fipsmodule/modes/gcm.c +123 -309
- data/third_party/boringssl/crypto/fipsmodule/modes/internal.h +189 -126
- data/third_party/boringssl/crypto/fipsmodule/modes/ofb.c +3 -2
- data/third_party/boringssl/crypto/fipsmodule/rand/ctrdrbg.c +2 -2
- data/third_party/boringssl/crypto/fipsmodule/rand/internal.h +35 -0
- data/third_party/boringssl/crypto/fipsmodule/rand/rand.c +24 -19
- data/third_party/boringssl/crypto/fipsmodule/rand/urandom.c +256 -77
- data/third_party/boringssl/crypto/fipsmodule/rsa/padding.c +10 -7
- data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +5 -1
- data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +131 -14
- data/third_party/boringssl/crypto/fipsmodule/self_check/self_check.c +83 -10
- data/third_party/boringssl/crypto/fipsmodule/sha/internal.h +53 -0
- data/third_party/boringssl/crypto/fipsmodule/sha/sha1.c +9 -13
- data/third_party/boringssl/crypto/fipsmodule/sha/sha256.c +18 -12
- data/third_party/boringssl/crypto/fipsmodule/sha/sha512.c +95 -168
- data/third_party/boringssl/crypto/hrss/hrss.c +2201 -0
- data/third_party/boringssl/crypto/hrss/internal.h +62 -0
- data/third_party/boringssl/crypto/internal.h +95 -20
- data/third_party/boringssl/crypto/lhash/lhash.c +45 -33
- data/third_party/boringssl/crypto/mem.c +39 -2
- data/third_party/boringssl/crypto/obj/obj.c +4 -4
- data/third_party/boringssl/crypto/obj/obj_dat.h +6181 -875
- data/third_party/boringssl/crypto/pem/pem_all.c +2 -3
- data/third_party/boringssl/crypto/pem/pem_info.c +144 -162
- data/third_party/boringssl/crypto/pem/pem_lib.c +53 -52
- data/third_party/boringssl/crypto/pem/pem_pkey.c +13 -21
- data/third_party/boringssl/crypto/pkcs7/pkcs7.c +15 -22
- data/third_party/boringssl/crypto/pkcs7/pkcs7_x509.c +168 -16
- data/third_party/boringssl/crypto/pkcs8/internal.h +11 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +24 -15
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +42 -25
- data/third_party/boringssl/crypto/pkcs8/pkcs8_x509.c +559 -43
- data/third_party/boringssl/crypto/pool/internal.h +1 -1
- data/third_party/boringssl/crypto/pool/pool.c +21 -0
- data/third_party/boringssl/crypto/rand_extra/deterministic.c +8 -0
- data/third_party/boringssl/crypto/rand_extra/fuchsia.c +1 -14
- data/third_party/boringssl/crypto/refcount_lock.c +2 -2
- data/third_party/boringssl/crypto/rsa_extra/rsa_print.c +22 -0
- data/third_party/boringssl/crypto/siphash/siphash.c +80 -0
- data/third_party/boringssl/crypto/stack/stack.c +83 -32
- data/third_party/boringssl/crypto/thread_none.c +2 -2
- data/third_party/boringssl/crypto/thread_pthread.c +2 -2
- data/third_party/boringssl/crypto/thread_win.c +38 -19
- data/third_party/boringssl/crypto/x509/a_strex.c +22 -2
- data/third_party/boringssl/crypto/x509/asn1_gen.c +2 -1
- data/third_party/boringssl/crypto/x509/by_dir.c +7 -0
- data/third_party/boringssl/crypto/x509/by_file.c +12 -10
- data/third_party/boringssl/crypto/x509/t_crl.c +5 -8
- data/third_party/boringssl/crypto/x509/t_req.c +1 -3
- data/third_party/boringssl/crypto/x509/t_x509.c +5 -8
- data/third_party/boringssl/crypto/x509/x509_cmp.c +1 -1
- data/third_party/boringssl/crypto/x509/x509_def.c +1 -1
- data/third_party/boringssl/crypto/x509/x509_lu.c +114 -5
- data/third_party/boringssl/crypto/x509/x509_req.c +20 -0
- data/third_party/boringssl/crypto/x509/x509_set.c +5 -0
- data/third_party/boringssl/crypto/x509/x509_trs.c +1 -0
- data/third_party/boringssl/crypto/x509/x509_txt.c +4 -5
- data/third_party/boringssl/crypto/x509/x509_vfy.c +145 -138
- data/third_party/boringssl/crypto/x509/x509_vpm.c +2 -0
- data/third_party/boringssl/crypto/x509/x509cset.c +40 -0
- data/third_party/boringssl/crypto/x509/x509name.c +2 -3
- data/third_party/boringssl/crypto/x509/x_all.c +109 -210
- data/third_party/boringssl/crypto/x509/x_x509.c +6 -0
- data/third_party/boringssl/crypto/x509v3/ext_dat.h +1 -3
- data/third_party/boringssl/crypto/x509v3/internal.h +56 -0
- data/third_party/boringssl/crypto/x509v3/pcy_cache.c +2 -0
- data/third_party/boringssl/crypto/x509v3/pcy_node.c +1 -0
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +4 -2
- data/third_party/boringssl/crypto/x509v3/v3_akey.c +5 -2
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +19 -13
- data/third_party/boringssl/crypto/x509v3/v3_conf.c +2 -1
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +3 -2
- data/third_party/boringssl/crypto/x509v3/v3_genn.c +1 -6
- data/third_party/boringssl/crypto/x509v3/v3_lib.c +1 -0
- data/third_party/boringssl/crypto/x509v3/v3_ocsp.c +68 -0
- data/third_party/boringssl/crypto/x509v3/v3_pci.c +2 -1
- data/third_party/boringssl/crypto/x509v3/v3_purp.c +47 -69
- data/third_party/boringssl/crypto/x509v3/v3_skey.c +5 -2
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +69 -25
- data/third_party/boringssl/include/openssl/aead.h +45 -19
- data/third_party/boringssl/include/openssl/aes.h +32 -7
- data/third_party/boringssl/include/openssl/asn1.h +7 -77
- data/third_party/boringssl/include/openssl/base.h +120 -6
- data/third_party/boringssl/include/openssl/base64.h +4 -1
- data/third_party/boringssl/include/openssl/bio.h +112 -81
- data/third_party/boringssl/include/openssl/blowfish.h +3 -3
- data/third_party/boringssl/include/openssl/bn.h +55 -29
- data/third_party/boringssl/include/openssl/buf.h +2 -2
- data/third_party/boringssl/include/openssl/bytestring.h +54 -32
- data/third_party/boringssl/include/openssl/cast.h +2 -2
- data/third_party/boringssl/include/openssl/cipher.h +46 -16
- data/third_party/boringssl/include/openssl/cmac.h +6 -2
- data/third_party/boringssl/include/openssl/conf.h +3 -6
- data/third_party/boringssl/include/openssl/cpu.h +25 -9
- data/third_party/boringssl/include/openssl/crypto.h +32 -10
- data/third_party/boringssl/include/openssl/curve25519.h +4 -4
- data/third_party/boringssl/include/openssl/dh.h +3 -2
- data/third_party/boringssl/include/openssl/digest.h +21 -7
- data/third_party/boringssl/include/openssl/dsa.h +8 -2
- data/third_party/boringssl/include/openssl/e_os2.h +18 -0
- data/third_party/boringssl/include/openssl/ec.h +25 -21
- data/third_party/boringssl/include/openssl/ec_key.h +36 -8
- data/third_party/boringssl/include/openssl/ecdh.h +17 -0
- data/third_party/boringssl/include/openssl/ecdsa.h +3 -3
- data/third_party/boringssl/include/openssl/engine.h +4 -4
- data/third_party/boringssl/include/openssl/err.h +3 -0
- data/third_party/boringssl/include/openssl/evp.h +199 -42
- data/third_party/boringssl/include/openssl/hmac.h +4 -4
- data/third_party/boringssl/include/openssl/hrss.h +100 -0
- data/third_party/boringssl/include/openssl/lhash.h +131 -23
- data/third_party/boringssl/include/openssl/md4.h +6 -4
- data/third_party/boringssl/include/openssl/md5.h +6 -4
- data/third_party/boringssl/include/openssl/mem.h +6 -2
- data/third_party/boringssl/include/openssl/nid.h +3 -0
- data/third_party/boringssl/include/openssl/obj.h +3 -0
- data/third_party/boringssl/include/openssl/pem.h +102 -64
- data/third_party/boringssl/include/openssl/pkcs7.h +136 -3
- data/third_party/boringssl/include/openssl/pkcs8.h +42 -3
- data/third_party/boringssl/include/openssl/pool.h +13 -2
- data/third_party/boringssl/include/openssl/ripemd.h +5 -4
- data/third_party/boringssl/include/openssl/rsa.h +46 -15
- data/third_party/boringssl/include/openssl/sha.h +40 -28
- data/third_party/boringssl/include/openssl/siphash.h +37 -0
- data/third_party/boringssl/include/openssl/span.h +17 -9
- data/third_party/boringssl/include/openssl/ssl.h +766 -393
- data/third_party/boringssl/include/openssl/ssl3.h +4 -3
- data/third_party/boringssl/include/openssl/stack.h +134 -77
- data/third_party/boringssl/include/openssl/thread.h +1 -1
- data/third_party/boringssl/include/openssl/tls1.h +25 -9
- data/third_party/boringssl/include/openssl/type_check.h +14 -15
- data/third_party/boringssl/include/openssl/x509.h +28 -3
- data/third_party/boringssl/include/openssl/x509_vfy.h +98 -32
- data/third_party/boringssl/include/openssl/x509v3.h +17 -13
- data/third_party/boringssl/ssl/d1_both.cc +9 -18
- data/third_party/boringssl/ssl/d1_lib.cc +4 -3
- data/third_party/boringssl/ssl/d1_pkt.cc +4 -4
- data/third_party/boringssl/ssl/d1_srtp.cc +15 -15
- data/third_party/boringssl/ssl/dtls_method.cc +0 -1
- data/third_party/boringssl/ssl/dtls_record.cc +28 -28
- data/third_party/boringssl/ssl/handoff.cc +295 -91
- data/third_party/boringssl/ssl/handshake.cc +133 -72
- data/third_party/boringssl/ssl/handshake_client.cc +218 -189
- data/third_party/boringssl/ssl/handshake_server.cc +399 -272
- data/third_party/boringssl/ssl/internal.h +1413 -928
- data/third_party/boringssl/ssl/s3_both.cc +175 -36
- data/third_party/boringssl/ssl/s3_lib.cc +9 -13
- data/third_party/boringssl/ssl/s3_pkt.cc +63 -29
- data/third_party/boringssl/ssl/ssl_aead_ctx.cc +55 -35
- data/third_party/boringssl/ssl/ssl_asn1.cc +57 -73
- data/third_party/boringssl/ssl/ssl_buffer.cc +13 -12
- data/third_party/boringssl/ssl/ssl_cert.cc +313 -210
- data/third_party/boringssl/ssl/ssl_cipher.cc +159 -221
- data/third_party/boringssl/ssl/ssl_file.cc +2 -0
- data/third_party/boringssl/ssl/ssl_key_share.cc +164 -19
- data/third_party/boringssl/ssl/ssl_lib.cc +847 -555
- data/third_party/boringssl/ssl/ssl_privkey.cc +441 -111
- data/third_party/boringssl/ssl/ssl_session.cc +230 -178
- data/third_party/boringssl/ssl/ssl_transcript.cc +21 -142
- data/third_party/boringssl/ssl/ssl_versions.cc +88 -93
- data/third_party/boringssl/ssl/ssl_x509.cc +279 -218
- data/third_party/boringssl/ssl/t1_enc.cc +5 -96
- data/third_party/boringssl/ssl/t1_lib.cc +931 -678
- data/third_party/boringssl/ssl/tls13_both.cc +251 -121
- data/third_party/boringssl/ssl/tls13_client.cc +129 -73
- data/third_party/boringssl/ssl/tls13_enc.cc +350 -282
- data/third_party/boringssl/ssl/tls13_server.cc +259 -192
- data/third_party/boringssl/ssl/tls_method.cc +26 -21
- data/third_party/boringssl/ssl/tls_record.cc +42 -47
- data/third_party/boringssl/third_party/fiat/curve25519.c +261 -1324
- data/third_party/boringssl/third_party/fiat/curve25519_32.h +911 -0
- data/third_party/boringssl/third_party/fiat/curve25519_64.h +559 -0
- data/third_party/boringssl/third_party/fiat/p256.c +238 -999
- data/third_party/boringssl/third_party/fiat/p256_32.h +3226 -0
- data/third_party/boringssl/third_party/fiat/p256_64.h +1217 -0
- data/third_party/upb/upb/port_def.inc +1 -1
- data/third_party/upb/upb/table.c +2 -1
- metadata +71 -43
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +0 -127
- data/src/core/lib/gpr/mpscq.cc +0 -117
- data/src/core/lib/gpr/mpscq.h +0 -88
- data/src/core/lib/gprpp/abstract.h +0 -47
- data/src/core/lib/gprpp/pair.h +0 -38
- data/third_party/boringssl/crypto/cipher_extra/e_ssl3.c +0 -460
- data/third_party/boringssl/crypto/fipsmodule/modes/ccm.c +0 -256
- data/third_party/boringssl/include/openssl/lhash_macros.h +0 -174
- data/third_party/boringssl/ssl/custom_extensions.cc +0 -265
@@ -108,10 +108,10 @@
|
|
108
108
|
|
109
109
|
#include <openssl/bn.h>
|
110
110
|
|
111
|
+
#include <limits.h>
|
111
112
|
#include <string.h>
|
112
113
|
|
113
114
|
#include <openssl/err.h>
|
114
|
-
#include <openssl/mem.h>
|
115
115
|
#include <openssl/rand.h>
|
116
116
|
#include <openssl/type_check.h>
|
117
117
|
|
@@ -121,9 +121,6 @@
|
|
121
121
|
|
122
122
|
|
123
123
|
int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) {
|
124
|
-
uint8_t *buf = NULL;
|
125
|
-
int ret = 0, bit, bytes, mask;
|
126
|
-
|
127
124
|
if (rnd == NULL) {
|
128
125
|
return 0;
|
129
126
|
}
|
@@ -144,48 +141,41 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) {
|
|
144
141
|
return 1;
|
145
142
|
}
|
146
143
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
buf = OPENSSL_malloc(bytes);
|
152
|
-
if (buf == NULL) {
|
153
|
-
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
|
154
|
-
goto err;
|
144
|
+
if (bits > INT_MAX - (BN_BITS2 - 1)) {
|
145
|
+
OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
|
146
|
+
return 0;
|
155
147
|
}
|
156
148
|
|
157
|
-
|
158
|
-
|
149
|
+
int words = (bits + BN_BITS2 - 1) / BN_BITS2;
|
150
|
+
int bit = (bits - 1) % BN_BITS2;
|
151
|
+
const BN_ULONG kOne = 1;
|
152
|
+
const BN_ULONG kThree = 3;
|
153
|
+
BN_ULONG mask = bit < BN_BITS2 - 1 ? (kOne << (bit + 1)) - 1 : BN_MASK2;
|
154
|
+
if (!bn_wexpand(rnd, words)) {
|
155
|
+
return 0;
|
156
|
+
}
|
159
157
|
|
158
|
+
RAND_bytes((uint8_t *)rnd->d, words * sizeof(BN_ULONG));
|
159
|
+
rnd->d[words - 1] &= mask;
|
160
160
|
if (top != BN_RAND_TOP_ANY) {
|
161
161
|
if (top == BN_RAND_TOP_TWO && bits > 1) {
|
162
162
|
if (bit == 0) {
|
163
|
-
|
164
|
-
|
163
|
+
rnd->d[words - 1] |= 1;
|
164
|
+
rnd->d[words - 2] |= kOne << (BN_BITS2 - 1);
|
165
165
|
} else {
|
166
|
-
|
166
|
+
rnd->d[words - 1] |= kThree << (bit - 1);
|
167
167
|
}
|
168
168
|
} else {
|
169
|
-
|
169
|
+
rnd->d[words - 1] |= kOne << bit;
|
170
170
|
}
|
171
171
|
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
// Set the bottom bit if requested,
|
176
|
-
if (bottom == BN_RAND_BOTTOM_ODD) {
|
177
|
-
buf[bytes - 1] |= 1;
|
178
|
-
}
|
179
|
-
|
180
|
-
if (!BN_bin2bn(buf, bytes, rnd)) {
|
181
|
-
goto err;
|
172
|
+
if (bottom == BN_RAND_BOTTOM_ODD) {
|
173
|
+
rnd->d[0] |= 1;
|
182
174
|
}
|
183
175
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
OPENSSL_free(buf);
|
188
|
-
return ret;
|
176
|
+
rnd->neg = 0;
|
177
|
+
rnd->width = words;
|
178
|
+
return 1;
|
189
179
|
}
|
190
180
|
|
191
181
|
int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom) {
|
@@ -205,8 +195,8 @@ static crypto_word_t bn_less_than_word_mask(const BN_ULONG *a, size_t len,
|
|
205
195
|
}
|
206
196
|
|
207
197
|
// |a| < |b| iff a[1..len-1] are all zero and a[0] < b.
|
208
|
-
|
209
|
-
|
198
|
+
OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t),
|
199
|
+
"crypto_word_t is too small");
|
210
200
|
crypto_word_t mask = 0;
|
211
201
|
for (size_t i = 1; i < len; i++) {
|
212
202
|
mask |= a[i];
|
@@ -12,27 +12,16 @@
|
|
12
12
|
* (2) University of Haifa, Israel
|
13
13
|
*/
|
14
14
|
|
15
|
-
#include <openssl/base.h>
|
16
|
-
|
17
|
-
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
18
|
-
|
19
15
|
#include "rsaz_exp.h"
|
20
16
|
|
17
|
+
#if defined(RSAZ_ENABLED)
|
18
|
+
|
21
19
|
#include <openssl/mem.h>
|
22
20
|
|
21
|
+
#include "internal.h"
|
23
22
|
#include "../../internal.h"
|
24
23
|
|
25
24
|
|
26
|
-
// See crypto/bn/asm/rsaz-avx2.pl for further details.
|
27
|
-
void rsaz_1024_norm2red_avx2(void *red, const void *norm);
|
28
|
-
void rsaz_1024_mul_avx2(void *ret, const void *a, const void *b, const void *n,
|
29
|
-
BN_ULONG k);
|
30
|
-
void rsaz_1024_sqr_avx2(void *ret, const void *a, const void *n, BN_ULONG k,
|
31
|
-
int cnt);
|
32
|
-
void rsaz_1024_scatter5_avx2(void *tbl, const void *val, int i);
|
33
|
-
void rsaz_1024_gather5_avx2(void *val, const void *tbl, int i);
|
34
|
-
void rsaz_1024_red2norm_avx2(void *norm, const void *red);
|
35
|
-
|
36
25
|
// one is 1 in RSAZ's representation.
|
37
26
|
alignas(64) static const BN_ULONG one[40] = {
|
38
27
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
@@ -44,19 +33,25 @@ alignas(64) static const BN_ULONG two80[40] = {
|
|
44
33
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
45
34
|
|
46
35
|
void RSAZ_1024_mod_exp_avx2(BN_ULONG result_norm[16],
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
36
|
+
const BN_ULONG base_norm[16],
|
37
|
+
const BN_ULONG exponent[16],
|
38
|
+
const BN_ULONG m_norm[16], const BN_ULONG RR[16],
|
39
|
+
BN_ULONG k0,
|
40
|
+
BN_ULONG storage[MOD_EXP_CTIME_STORAGE_LEN]) {
|
41
|
+
OPENSSL_STATIC_ASSERT(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH % 64 == 0,
|
42
|
+
"MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH is too small");
|
43
|
+
assert((uintptr_t)storage % 64 == 0);
|
44
|
+
|
45
|
+
BN_ULONG *a_inv, *m, *result, *table_s = storage + 40 * 3, *R2 = table_s;
|
46
|
+
// Note |R2| aliases |table_s|.
|
52
47
|
if (((((uintptr_t)storage & 4095) + 320) >> 12) != 0) {
|
53
48
|
result = storage;
|
54
|
-
a_inv = storage +
|
55
|
-
m = storage +
|
49
|
+
a_inv = storage + 40;
|
50
|
+
m = storage + 40 * 2; // should not cross page
|
56
51
|
} else {
|
57
52
|
m = storage; // should not cross page
|
58
|
-
result = storage +
|
59
|
-
a_inv = storage +
|
53
|
+
result = storage + 40;
|
54
|
+
a_inv = storage + 40 * 2;
|
60
55
|
}
|
61
56
|
|
62
57
|
rsaz_1024_norm2red_avx2(m, m_norm);
|
@@ -225,7 +220,7 @@ void RSAZ_1024_mod_exp_avx2(BN_ULONG result_norm[16],
|
|
225
220
|
|
226
221
|
rsaz_1024_red2norm_avx2(result_norm, result);
|
227
222
|
|
228
|
-
OPENSSL_cleanse(storage, sizeof(
|
223
|
+
OPENSSL_cleanse(storage, MOD_EXP_CTIME_STORAGE_LEN * sizeof(BN_ULONG));
|
229
224
|
}
|
230
225
|
|
231
|
-
#endif //
|
226
|
+
#endif // RSAZ_ENABLED
|
@@ -16,18 +16,89 @@
|
|
16
16
|
#define OPENSSL_HEADER_BN_RSAZ_EXP_H
|
17
17
|
|
18
18
|
#include <openssl/bn.h>
|
19
|
+
#include <openssl/cpu.h>
|
20
|
+
|
21
|
+
#include "internal.h"
|
22
|
+
|
23
|
+
#if defined(__cplusplus)
|
24
|
+
extern "C" {
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
28
|
+
#define RSAZ_ENABLED
|
29
|
+
|
19
30
|
|
20
31
|
// RSAZ_1024_mod_exp_avx2 sets |result| to |base_norm| raised to |exponent|
|
21
32
|
// modulo |m_norm|. |base_norm| must be fully-reduced and |exponent| must have
|
22
33
|
// the high bit set (it is 1024 bits wide). |RR| and |k0| must be |RR| and |n0|,
|
23
|
-
// respectively, extracted from |m_norm|'s |BN_MONT_CTX|.
|
34
|
+
// respectively, extracted from |m_norm|'s |BN_MONT_CTX|. |storage_words| is a
|
35
|
+
// temporary buffer that must be aligned to |MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH|
|
36
|
+
// bytes.
|
24
37
|
void RSAZ_1024_mod_exp_avx2(BN_ULONG result[16], const BN_ULONG base_norm[16],
|
25
38
|
const BN_ULONG exponent[16],
|
26
39
|
const BN_ULONG m_norm[16], const BN_ULONG RR[16],
|
27
|
-
BN_ULONG k0
|
40
|
+
BN_ULONG k0,
|
41
|
+
BN_ULONG storage_words[MOD_EXP_CTIME_STORAGE_LEN]);
|
42
|
+
|
43
|
+
OPENSSL_INLINE int rsaz_avx2_capable(void) {
|
44
|
+
const uint32_t *cap = OPENSSL_ia32cap_get();
|
45
|
+
return (cap[2] & (1 << 5)) != 0; // AVX2
|
46
|
+
}
|
47
|
+
|
48
|
+
OPENSSL_INLINE int rsaz_avx2_preferred(void) {
|
49
|
+
const uint32_t *cap = OPENSSL_ia32cap_get();
|
50
|
+
static const uint32_t kBMI2AndADX = (1 << 8) | (1 << 19);
|
51
|
+
if ((cap[2] & kBMI2AndADX) == kBMI2AndADX) {
|
52
|
+
// If BMI2 and ADX are available, x86_64-mont5.pl is faster.
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
return (cap[2] & (1 << 5)) != 0; // AVX2
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
// Assembly functions.
|
60
|
+
|
61
|
+
// RSAZ represents 1024-bit integers using unsaturated 29-bit limbs stored in
|
62
|
+
// 64-bit integers. This requires 36 limbs but padded up to 40.
|
63
|
+
//
|
64
|
+
// See crypto/bn/asm/rsaz-avx2.pl for further details.
|
65
|
+
|
66
|
+
// rsaz_1024_norm2red_avx2 converts |norm| from |BIGNUM| to RSAZ representation
|
67
|
+
// and writes the result to |red|.
|
68
|
+
void rsaz_1024_norm2red_avx2(BN_ULONG red[40], const BN_ULONG norm[16]);
|
69
|
+
|
70
|
+
// rsaz_1024_mul_avx2 computes |a| * |b| mod |n| and writes the result to |ret|.
|
71
|
+
// Inputs and outputs are in Montgomery form, using RSAZ's representation. |k|
|
72
|
+
// is -|n|^-1 mod 2^64 or |n0| from |BN_MONT_CTX|.
|
73
|
+
void rsaz_1024_mul_avx2(BN_ULONG ret[40], const BN_ULONG a[40],
|
74
|
+
const BN_ULONG b[40], const BN_ULONG n[40], BN_ULONG k);
|
75
|
+
|
76
|
+
// rsaz_1024_mul_avx2 computes |a|^(2*|count|) mod |n| and writes the result to
|
77
|
+
// |ret|. Inputs and outputs are in Montgomery form, using RSAZ's
|
78
|
+
// representation. |k| is -|n|^-1 mod 2^64 or |n0| from |BN_MONT_CTX|.
|
79
|
+
void rsaz_1024_sqr_avx2(BN_ULONG ret[40], const BN_ULONG a[40],
|
80
|
+
const BN_ULONG n[40], BN_ULONG k, int count);
|
81
|
+
|
82
|
+
// rsaz_1024_scatter5_avx2 stores |val| at index |i| of |tbl|. |i| must be
|
83
|
+
// positive and at most 31. Note the table only uses 18 |BN_ULONG|s per entry
|
84
|
+
// instead of 40. It packs two 29-bit limbs into each |BN_ULONG| and only stores
|
85
|
+
// 36 limbs rather than the padded 40.
|
86
|
+
void rsaz_1024_scatter5_avx2(BN_ULONG tbl[32 * 18], const BN_ULONG val[40],
|
87
|
+
int i);
|
88
|
+
|
89
|
+
// rsaz_1024_gather5_avx2 loads index |i| of |tbl| and writes it to |val|.
|
90
|
+
void rsaz_1024_gather5_avx2(BN_ULONG val[40], const BN_ULONG tbl[32 * 18],
|
91
|
+
int i);
|
92
|
+
|
93
|
+
// rsaz_1024_red2norm_avx2 converts |red| from RSAZ to |BIGNUM| representation
|
94
|
+
// and writes the result to |norm|.
|
95
|
+
void rsaz_1024_red2norm_avx2(BN_ULONG norm[16], const BN_ULONG red[40]);
|
96
|
+
|
97
|
+
|
98
|
+
#endif // !OPENSSL_NO_ASM && OPENSSL_X86_64
|
28
99
|
|
29
|
-
|
30
|
-
//
|
31
|
-
|
100
|
+
#if defined(__cplusplus)
|
101
|
+
} // extern "C"
|
102
|
+
#endif
|
32
103
|
|
33
104
|
#endif // OPENSSL_HEADER_BN_RSAZ_EXP_H
|
@@ -133,8 +133,8 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a) {
|
|
133
133
|
return 1;
|
134
134
|
}
|
135
135
|
|
136
|
-
|
137
|
-
|
136
|
+
void bn_rshift_words(BN_ULONG *r, const BN_ULONG *a, unsigned shift,
|
137
|
+
size_t num) {
|
138
138
|
unsigned shift_bits = shift % BN_BITS2;
|
139
139
|
size_t shift_words = shift / BN_BITS2;
|
140
140
|
if (shift_words >= num) {
|
@@ -296,15 +296,15 @@ int BN_mask_bits(BIGNUM *a, int n) {
|
|
296
296
|
}
|
297
297
|
|
298
298
|
static int bn_count_low_zero_bits_word(BN_ULONG l) {
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
299
|
+
OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t),
|
300
|
+
"crypto_word_t is too small");
|
301
|
+
OPENSSL_STATIC_ASSERT(sizeof(int) <= sizeof(crypto_word_t),
|
302
|
+
"crypto_word_t is too small");
|
303
|
+
OPENSSL_STATIC_ASSERT(BN_BITS2 == sizeof(BN_ULONG) * 8,
|
304
|
+
"BN_ULONG has padding bits");
|
305
305
|
// C has very bizarre rules for types smaller than an int.
|
306
|
-
|
307
|
-
|
306
|
+
OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) >= sizeof(int),
|
307
|
+
"BN_ULONG gets promoted to int");
|
308
308
|
|
309
309
|
crypto_word_t mask;
|
310
310
|
int bits = 0;
|
@@ -342,10 +342,10 @@ static int bn_count_low_zero_bits_word(BN_ULONG l) {
|
|
342
342
|
}
|
343
343
|
|
344
344
|
int BN_count_low_zero_bits(const BIGNUM *bn) {
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
345
|
+
OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t),
|
346
|
+
"crypto_word_t is too small");
|
347
|
+
OPENSSL_STATIC_ASSERT(sizeof(int) <= sizeof(crypto_word_t),
|
348
|
+
"crypto_word_t is too small");
|
349
349
|
|
350
350
|
int ret = 0;
|
351
351
|
crypto_word_t saw_nonzero = 0;
|
@@ -125,9 +125,10 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) {
|
|
125
125
|
return 1;
|
126
126
|
}
|
127
127
|
|
128
|
-
|
128
|
+
int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) {
|
129
129
|
EVP_CIPHER_CTX_cleanup(ctx);
|
130
130
|
EVP_CIPHER_CTX_init(ctx);
|
131
|
+
return 1;
|
131
132
|
}
|
132
133
|
|
133
134
|
int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
@@ -191,7 +192,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
|
191
192
|
|
192
193
|
case EVP_CIPH_CFB_MODE:
|
193
194
|
ctx->num = 0;
|
194
|
-
|
195
|
+
OPENSSL_FALLTHROUGH;
|
195
196
|
|
196
197
|
case EVP_CIPH_CBC_MODE:
|
197
198
|
assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof(ctx->iv));
|
@@ -496,6 +497,10 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) {
|
|
496
497
|
return ctx->cipher->nid;
|
497
498
|
}
|
498
499
|
|
500
|
+
int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx) {
|
501
|
+
return ctx->encrypt;
|
502
|
+
}
|
503
|
+
|
499
504
|
unsigned EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) {
|
500
505
|
return ctx->cipher->block_size;
|
501
506
|
}
|
@@ -46,6 +46,7 @@
|
|
46
46
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
47
47
|
* ==================================================================== */
|
48
48
|
|
49
|
+
#include <assert.h>
|
49
50
|
#include <string.h>
|
50
51
|
|
51
52
|
#include <openssl/aead.h>
|
@@ -63,13 +64,52 @@
|
|
63
64
|
#include "../modes/internal.h"
|
64
65
|
#include "../delocate.h"
|
65
66
|
|
66
|
-
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
67
|
-
#include <openssl/arm_arch.h>
|
68
|
-
#endif
|
69
|
-
|
70
67
|
|
68
|
+
OPENSSL_MSVC_PRAGMA(warning(push))
|
71
69
|
OPENSSL_MSVC_PRAGMA(warning(disable: 4702)) // Unreachable code.
|
72
70
|
|
71
|
+
#if defined(BSAES)
|
72
|
+
static void vpaes_ctr32_encrypt_blocks_with_bsaes(const uint8_t *in,
|
73
|
+
uint8_t *out, size_t blocks,
|
74
|
+
const AES_KEY *key,
|
75
|
+
const uint8_t ivec[16]) {
|
76
|
+
// |bsaes_ctr32_encrypt_blocks| is faster than |vpaes_ctr32_encrypt_blocks|,
|
77
|
+
// but it takes at least one full 8-block batch to amortize the conversion.
|
78
|
+
if (blocks < 8) {
|
79
|
+
vpaes_ctr32_encrypt_blocks(in, out, blocks, key, ivec);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
|
83
|
+
size_t bsaes_blocks = blocks;
|
84
|
+
if (bsaes_blocks % 8 < 6) {
|
85
|
+
// |bsaes_ctr32_encrypt_blocks| internally works in 8-block batches. If the
|
86
|
+
// final batch is too small (under six blocks), it is faster to loop over
|
87
|
+
// |vpaes_encrypt|. Round |bsaes_blocks| down to a multiple of 8.
|
88
|
+
bsaes_blocks -= bsaes_blocks % 8;
|
89
|
+
}
|
90
|
+
|
91
|
+
AES_KEY bsaes;
|
92
|
+
vpaes_encrypt_key_to_bsaes(&bsaes, key);
|
93
|
+
bsaes_ctr32_encrypt_blocks(in, out, bsaes_blocks, &bsaes, ivec);
|
94
|
+
OPENSSL_cleanse(&bsaes, sizeof(bsaes));
|
95
|
+
|
96
|
+
in += 16 * bsaes_blocks;
|
97
|
+
out += 16 * bsaes_blocks;
|
98
|
+
blocks -= bsaes_blocks;
|
99
|
+
|
100
|
+
union {
|
101
|
+
uint32_t u32[4];
|
102
|
+
uint8_t u8[16];
|
103
|
+
} new_ivec;
|
104
|
+
memcpy(new_ivec.u8, ivec, 16);
|
105
|
+
uint32_t ctr = CRYPTO_bswap4(new_ivec.u32[3]) + bsaes_blocks;
|
106
|
+
new_ivec.u32[3] = CRYPTO_bswap4(ctr);
|
107
|
+
|
108
|
+
// Finish any remaining blocks with |vpaes_ctr32_encrypt_blocks|.
|
109
|
+
vpaes_ctr32_encrypt_blocks(in, out, blocks, key, new_ivec.u8);
|
110
|
+
}
|
111
|
+
#endif // BSAES
|
112
|
+
|
73
113
|
typedef struct {
|
74
114
|
union {
|
75
115
|
double align;
|
@@ -83,13 +123,13 @@ typedef struct {
|
|
83
123
|
} EVP_AES_KEY;
|
84
124
|
|
85
125
|
typedef struct {
|
126
|
+
GCM128_CONTEXT gcm;
|
86
127
|
union {
|
87
128
|
double align;
|
88
129
|
AES_KEY ks;
|
89
130
|
} ks; // AES key schedule to use
|
90
131
|
int key_set; // Set if key initialised
|
91
132
|
int iv_set; // Set if an iv is set
|
92
|
-
GCM128_CONTEXT gcm;
|
93
133
|
uint8_t *iv; // Temporary IV store
|
94
134
|
int ivlen; // IV length
|
95
135
|
int taglen;
|
@@ -97,129 +137,6 @@ typedef struct {
|
|
97
137
|
ctr128_f ctr;
|
98
138
|
} EVP_AES_GCM_CTX;
|
99
139
|
|
100
|
-
#if !defined(OPENSSL_NO_ASM) && \
|
101
|
-
(defined(OPENSSL_X86_64) || defined(OPENSSL_X86))
|
102
|
-
#define VPAES
|
103
|
-
static char vpaes_capable(void) {
|
104
|
-
return (OPENSSL_ia32cap_P[1] & (1 << (41 - 32))) != 0;
|
105
|
-
}
|
106
|
-
|
107
|
-
#if defined(OPENSSL_X86_64)
|
108
|
-
#define BSAES
|
109
|
-
static char bsaes_capable(void) {
|
110
|
-
return vpaes_capable();
|
111
|
-
}
|
112
|
-
#endif
|
113
|
-
|
114
|
-
#elif !defined(OPENSSL_NO_ASM) && \
|
115
|
-
(defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
116
|
-
|
117
|
-
#if defined(OPENSSL_ARM) && __ARM_MAX_ARCH__ >= 7
|
118
|
-
#define BSAES
|
119
|
-
static char bsaes_capable(void) {
|
120
|
-
return CRYPTO_is_NEON_capable();
|
121
|
-
}
|
122
|
-
#endif
|
123
|
-
|
124
|
-
#endif
|
125
|
-
|
126
|
-
|
127
|
-
#if defined(BSAES)
|
128
|
-
// On platforms where BSAES gets defined (just above), then these functions are
|
129
|
-
// provided by asm.
|
130
|
-
void bsaes_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
131
|
-
const AES_KEY *key, uint8_t ivec[16], int enc);
|
132
|
-
void bsaes_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len,
|
133
|
-
const AES_KEY *key, const uint8_t ivec[16]);
|
134
|
-
#else
|
135
|
-
static char bsaes_capable(void) {
|
136
|
-
return 0;
|
137
|
-
}
|
138
|
-
|
139
|
-
// On other platforms, bsaes_capable() will always return false and so the
|
140
|
-
// following will never be called.
|
141
|
-
static void bsaes_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
142
|
-
const AES_KEY *key, uint8_t ivec[16], int enc) {
|
143
|
-
abort();
|
144
|
-
}
|
145
|
-
|
146
|
-
static void bsaes_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
|
147
|
-
size_t len, const AES_KEY *key,
|
148
|
-
const uint8_t ivec[16]) {
|
149
|
-
abort();
|
150
|
-
}
|
151
|
-
#endif
|
152
|
-
|
153
|
-
#if defined(VPAES)
|
154
|
-
// On platforms where VPAES gets defined (just above), then these functions are
|
155
|
-
// provided by asm.
|
156
|
-
int vpaes_set_encrypt_key(const uint8_t *userKey, int bits, AES_KEY *key);
|
157
|
-
int vpaes_set_decrypt_key(const uint8_t *userKey, int bits, AES_KEY *key);
|
158
|
-
|
159
|
-
void vpaes_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
|
160
|
-
void vpaes_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
|
161
|
-
|
162
|
-
void vpaes_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
163
|
-
const AES_KEY *key, uint8_t *ivec, int enc);
|
164
|
-
#else
|
165
|
-
static char vpaes_capable(void) {
|
166
|
-
return 0;
|
167
|
-
}
|
168
|
-
|
169
|
-
// On other platforms, vpaes_capable() will always return false and so the
|
170
|
-
// following will never be called.
|
171
|
-
static int vpaes_set_encrypt_key(const uint8_t *userKey, int bits,
|
172
|
-
AES_KEY *key) {
|
173
|
-
abort();
|
174
|
-
}
|
175
|
-
static int vpaes_set_decrypt_key(const uint8_t *userKey, int bits,
|
176
|
-
AES_KEY *key) {
|
177
|
-
abort();
|
178
|
-
}
|
179
|
-
static void vpaes_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
180
|
-
abort();
|
181
|
-
}
|
182
|
-
static void vpaes_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
183
|
-
abort();
|
184
|
-
}
|
185
|
-
static void vpaes_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
186
|
-
const AES_KEY *key, uint8_t *ivec, int enc) {
|
187
|
-
abort();
|
188
|
-
}
|
189
|
-
#endif
|
190
|
-
|
191
|
-
#if !defined(OPENSSL_NO_ASM) && \
|
192
|
-
(defined(OPENSSL_X86_64) || defined(OPENSSL_X86))
|
193
|
-
int aesni_set_encrypt_key(const uint8_t *userKey, int bits, AES_KEY *key);
|
194
|
-
int aesni_set_decrypt_key(const uint8_t *userKey, int bits, AES_KEY *key);
|
195
|
-
|
196
|
-
void aesni_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
|
197
|
-
void aesni_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
|
198
|
-
|
199
|
-
void aesni_ecb_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
200
|
-
const AES_KEY *key, int enc);
|
201
|
-
void aesni_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
202
|
-
const AES_KEY *key, uint8_t *ivec, int enc);
|
203
|
-
|
204
|
-
#else
|
205
|
-
|
206
|
-
// On other platforms, aesni_capable() will always return false and so the
|
207
|
-
// following will never be called.
|
208
|
-
static void aesni_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
209
|
-
abort();
|
210
|
-
}
|
211
|
-
static int aesni_set_encrypt_key(const uint8_t *userKey, int bits,
|
212
|
-
AES_KEY *key) {
|
213
|
-
abort();
|
214
|
-
}
|
215
|
-
static void aesni_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
|
216
|
-
size_t blocks, const void *key,
|
217
|
-
const uint8_t *ivec) {
|
218
|
-
abort();
|
219
|
-
}
|
220
|
-
|
221
|
-
#endif
|
222
|
-
|
223
140
|
static int aes_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
224
141
|
const uint8_t *iv, int enc) {
|
225
142
|
int ret, mode;
|
@@ -229,49 +146,74 @@ static int aes_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
|
229
146
|
if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE) && !enc) {
|
230
147
|
if (hwaes_capable()) {
|
231
148
|
ret = aes_hw_set_decrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
232
|
-
dat->block =
|
149
|
+
dat->block = aes_hw_decrypt;
|
233
150
|
dat->stream.cbc = NULL;
|
234
151
|
if (mode == EVP_CIPH_CBC_MODE) {
|
235
|
-
dat->stream.cbc =
|
152
|
+
dat->stream.cbc = aes_hw_cbc_encrypt;
|
236
153
|
}
|
237
154
|
} else if (bsaes_capable() && mode == EVP_CIPH_CBC_MODE) {
|
238
|
-
|
239
|
-
|
240
|
-
|
155
|
+
assert(vpaes_capable());
|
156
|
+
ret = vpaes_set_decrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
157
|
+
if (ret == 0) {
|
158
|
+
vpaes_decrypt_key_to_bsaes(&dat->ks.ks, &dat->ks.ks);
|
159
|
+
}
|
160
|
+
// If |dat->stream.cbc| is provided, |dat->block| is never used.
|
161
|
+
dat->block = NULL;
|
162
|
+
dat->stream.cbc = bsaes_cbc_encrypt;
|
241
163
|
} else if (vpaes_capable()) {
|
242
164
|
ret = vpaes_set_decrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
243
|
-
dat->block =
|
244
|
-
dat->stream.cbc =
|
245
|
-
|
165
|
+
dat->block = vpaes_decrypt;
|
166
|
+
dat->stream.cbc = NULL;
|
167
|
+
#if defined(VPAES_CBC)
|
168
|
+
if (mode == EVP_CIPH_CBC_MODE) {
|
169
|
+
dat->stream.cbc = vpaes_cbc_encrypt;
|
170
|
+
}
|
171
|
+
#endif
|
246
172
|
} else {
|
247
|
-
ret =
|
248
|
-
dat->block =
|
249
|
-
dat->stream.cbc =
|
250
|
-
|
173
|
+
ret = aes_nohw_set_decrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
174
|
+
dat->block = aes_nohw_decrypt;
|
175
|
+
dat->stream.cbc = NULL;
|
176
|
+
#if defined(AES_NOHW_CBC)
|
177
|
+
if (mode == EVP_CIPH_CBC_MODE) {
|
178
|
+
dat->stream.cbc = aes_nohw_cbc_encrypt;
|
179
|
+
}
|
180
|
+
#endif
|
251
181
|
}
|
252
182
|
} else if (hwaes_capable()) {
|
253
183
|
ret = aes_hw_set_encrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
254
|
-
dat->block =
|
184
|
+
dat->block = aes_hw_encrypt;
|
255
185
|
dat->stream.cbc = NULL;
|
256
186
|
if (mode == EVP_CIPH_CBC_MODE) {
|
257
|
-
dat->stream.cbc =
|
187
|
+
dat->stream.cbc = aes_hw_cbc_encrypt;
|
258
188
|
} else if (mode == EVP_CIPH_CTR_MODE) {
|
259
|
-
dat->stream.ctr =
|
189
|
+
dat->stream.ctr = aes_hw_ctr32_encrypt_blocks;
|
260
190
|
}
|
261
|
-
} else if (bsaes_capable() && mode == EVP_CIPH_CTR_MODE) {
|
262
|
-
ret = AES_set_encrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
263
|
-
dat->block = (block128_f)AES_encrypt;
|
264
|
-
dat->stream.ctr = (ctr128_f)bsaes_ctr32_encrypt_blocks;
|
265
191
|
} else if (vpaes_capable()) {
|
266
192
|
ret = vpaes_set_encrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
267
|
-
dat->block =
|
268
|
-
dat->stream.cbc =
|
269
|
-
|
193
|
+
dat->block = vpaes_encrypt;
|
194
|
+
dat->stream.cbc = NULL;
|
195
|
+
#if defined(VPAES_CBC)
|
196
|
+
if (mode == EVP_CIPH_CBC_MODE) {
|
197
|
+
dat->stream.cbc = vpaes_cbc_encrypt;
|
198
|
+
}
|
199
|
+
#endif
|
200
|
+
if (mode == EVP_CIPH_CTR_MODE) {
|
201
|
+
#if defined(BSAES)
|
202
|
+
assert(bsaes_capable());
|
203
|
+
dat->stream.ctr = vpaes_ctr32_encrypt_blocks_with_bsaes;
|
204
|
+
#elif defined(VPAES_CTR32)
|
205
|
+
dat->stream.ctr = vpaes_ctr32_encrypt_blocks;
|
206
|
+
#endif
|
207
|
+
}
|
270
208
|
} else {
|
271
|
-
ret =
|
272
|
-
dat->block =
|
273
|
-
dat->stream.cbc =
|
274
|
-
|
209
|
+
ret = aes_nohw_set_encrypt_key(key, ctx->key_len * 8, &dat->ks.ks);
|
210
|
+
dat->block = aes_nohw_encrypt;
|
211
|
+
dat->stream.cbc = NULL;
|
212
|
+
#if defined(AES_NOHW_CBC)
|
213
|
+
if (mode == EVP_CIPH_CBC_MODE) {
|
214
|
+
dat->stream.cbc = aes_nohw_cbc_encrypt;
|
215
|
+
}
|
216
|
+
#endif
|
275
217
|
}
|
276
218
|
|
277
219
|
if (ret < 0) {
|
@@ -287,11 +229,11 @@ static int aes_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
|
287
229
|
EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
|
288
230
|
|
289
231
|
if (dat->stream.cbc) {
|
290
|
-
(*dat->stream.cbc)(in, out, len, &dat->ks, ctx->iv, ctx->encrypt);
|
232
|
+
(*dat->stream.cbc)(in, out, len, &dat->ks.ks, ctx->iv, ctx->encrypt);
|
291
233
|
} else if (ctx->encrypt) {
|
292
|
-
CRYPTO_cbc128_encrypt(in, out, len, &dat->ks, ctx->iv, dat->block);
|
234
|
+
CRYPTO_cbc128_encrypt(in, out, len, &dat->ks.ks, ctx->iv, dat->block);
|
293
235
|
} else {
|
294
|
-
CRYPTO_cbc128_decrypt(in, out, len, &dat->ks, ctx->iv, dat->block);
|
236
|
+
CRYPTO_cbc128_decrypt(in, out, len, &dat->ks.ks, ctx->iv, dat->block);
|
295
237
|
}
|
296
238
|
|
297
239
|
return 1;
|
@@ -308,7 +250,7 @@ static int aes_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
|
308
250
|
|
309
251
|
len -= bl;
|
310
252
|
for (size_t i = 0; i <= len; i += bl) {
|
311
|
-
(*dat->block)(in + i, out + i, &dat->ks);
|
253
|
+
(*dat->block)(in + i, out + i, &dat->ks.ks);
|
312
254
|
}
|
313
255
|
|
314
256
|
return 1;
|
@@ -319,11 +261,11 @@ static int aes_ctr_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
|
319
261
|
EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
|
320
262
|
|
321
263
|
if (dat->stream.ctr) {
|
322
|
-
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &dat->ks, ctx->iv, ctx->buf,
|
264
|
+
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &dat->ks.ks, ctx->iv, ctx->buf,
|
323
265
|
&ctx->num, dat->stream.ctr);
|
324
266
|
} else {
|
325
|
-
CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, ctx->iv, ctx->buf,
|
326
|
-
dat->block);
|
267
|
+
CRYPTO_ctr128_encrypt(in, out, len, &dat->ks.ks, ctx->iv, ctx->buf,
|
268
|
+
&ctx->num, dat->block);
|
327
269
|
}
|
328
270
|
return 1;
|
329
271
|
}
|
@@ -332,78 +274,91 @@ static int aes_ofb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
|
332
274
|
size_t len) {
|
333
275
|
EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
|
334
276
|
|
335
|
-
CRYPTO_ofb128_encrypt(in, out, len, &dat->ks, ctx->iv, &ctx->num,
|
277
|
+
CRYPTO_ofb128_encrypt(in, out, len, &dat->ks.ks, ctx->iv, &ctx->num,
|
278
|
+
dat->block);
|
336
279
|
return 1;
|
337
280
|
}
|
338
281
|
|
339
|
-
|
340
|
-
|
341
|
-
ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
|
282
|
+
ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_KEY *gcm_key,
|
342
283
|
block128_f *out_block, const uint8_t *key,
|
343
284
|
size_t key_bytes) {
|
344
|
-
if (aesni_capable()) {
|
345
|
-
aesni_set_encrypt_key(key, key_bytes * 8, aes_key);
|
346
|
-
if (gcm_ctx != NULL) {
|
347
|
-
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aesni_encrypt, 1);
|
348
|
-
}
|
349
|
-
if (out_block) {
|
350
|
-
*out_block = (block128_f) aesni_encrypt;
|
351
|
-
}
|
352
|
-
return (ctr128_f)aesni_ctr32_encrypt_blocks;
|
353
|
-
}
|
354
|
-
|
355
285
|
if (hwaes_capable()) {
|
356
286
|
aes_hw_set_encrypt_key(key, key_bytes * 8, aes_key);
|
357
|
-
if (
|
358
|
-
|
359
|
-
}
|
360
|
-
if (out_block) {
|
361
|
-
*out_block = (block128_f) aes_hw_encrypt;
|
362
|
-
}
|
363
|
-
return (ctr128_f)aes_hw_ctr32_encrypt_blocks;
|
364
|
-
}
|
365
|
-
|
366
|
-
if (bsaes_capable()) {
|
367
|
-
AES_set_encrypt_key(key, key_bytes * 8, aes_key);
|
368
|
-
if (gcm_ctx != NULL) {
|
369
|
-
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt, 0);
|
287
|
+
if (gcm_key != NULL) {
|
288
|
+
CRYPTO_gcm128_init_key(gcm_key, aes_key, aes_hw_encrypt, 1);
|
370
289
|
}
|
371
290
|
if (out_block) {
|
372
|
-
*out_block =
|
291
|
+
*out_block = aes_hw_encrypt;
|
373
292
|
}
|
374
|
-
return
|
293
|
+
return aes_hw_ctr32_encrypt_blocks;
|
375
294
|
}
|
376
295
|
|
377
296
|
if (vpaes_capable()) {
|
378
297
|
vpaes_set_encrypt_key(key, key_bytes * 8, aes_key);
|
379
298
|
if (out_block) {
|
380
|
-
*out_block =
|
299
|
+
*out_block = vpaes_encrypt;
|
381
300
|
}
|
382
|
-
if (
|
383
|
-
|
301
|
+
if (gcm_key != NULL) {
|
302
|
+
CRYPTO_gcm128_init_key(gcm_key, aes_key, vpaes_encrypt, 0);
|
384
303
|
}
|
304
|
+
#if defined(BSAES)
|
305
|
+
assert(bsaes_capable());
|
306
|
+
return vpaes_ctr32_encrypt_blocks_with_bsaes;
|
307
|
+
#elif defined(VPAES_CTR32)
|
308
|
+
return vpaes_ctr32_encrypt_blocks;
|
309
|
+
#else
|
385
310
|
return NULL;
|
311
|
+
#endif
|
386
312
|
}
|
387
313
|
|
388
|
-
|
389
|
-
if (
|
390
|
-
|
314
|
+
aes_nohw_set_encrypt_key(key, key_bytes * 8, aes_key);
|
315
|
+
if (gcm_key != NULL) {
|
316
|
+
CRYPTO_gcm128_init_key(gcm_key, aes_key, aes_nohw_encrypt, 0);
|
391
317
|
}
|
392
318
|
if (out_block) {
|
393
|
-
*out_block =
|
319
|
+
*out_block = aes_nohw_encrypt;
|
394
320
|
}
|
395
321
|
return NULL;
|
396
322
|
}
|
397
323
|
|
324
|
+
#if defined(OPENSSL_32_BIT)
|
325
|
+
#define EVP_AES_GCM_CTX_PADDING (4+8)
|
326
|
+
#else
|
327
|
+
#define EVP_AES_GCM_CTX_PADDING 8
|
328
|
+
#endif
|
329
|
+
|
330
|
+
static EVP_AES_GCM_CTX *aes_gcm_from_cipher_ctx(EVP_CIPHER_CTX *ctx) {
|
331
|
+
#if defined(__GNUC__) || defined(__clang__)
|
332
|
+
OPENSSL_STATIC_ASSERT(
|
333
|
+
alignof(EVP_AES_GCM_CTX) <= 16,
|
334
|
+
"EVP_AES_GCM_CTX needs more alignment than this function provides");
|
335
|
+
#endif
|
336
|
+
|
337
|
+
// |malloc| guarantees up to 4-byte alignment on 32-bit and 8-byte alignment
|
338
|
+
// on 64-bit systems, so we need to adjust to reach 16-byte alignment.
|
339
|
+
assert(ctx->cipher->ctx_size ==
|
340
|
+
sizeof(EVP_AES_GCM_CTX) + EVP_AES_GCM_CTX_PADDING);
|
341
|
+
|
342
|
+
char *ptr = ctx->cipher_data;
|
343
|
+
#if defined(OPENSSL_32_BIT)
|
344
|
+
assert((uintptr_t)ptr % 4 == 0);
|
345
|
+
ptr += (uintptr_t)ptr & 4;
|
346
|
+
#endif
|
347
|
+
assert((uintptr_t)ptr % 8 == 0);
|
348
|
+
ptr += (uintptr_t)ptr & 8;
|
349
|
+
return (EVP_AES_GCM_CTX *)ptr;
|
350
|
+
}
|
351
|
+
|
398
352
|
static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
399
353
|
const uint8_t *iv, int enc) {
|
400
|
-
EVP_AES_GCM_CTX *gctx = ctx
|
354
|
+
EVP_AES_GCM_CTX *gctx = aes_gcm_from_cipher_ctx(ctx);
|
401
355
|
if (!iv && !key) {
|
402
356
|
return 1;
|
403
357
|
}
|
404
358
|
if (key) {
|
405
|
-
gctx->
|
406
|
-
|
359
|
+
OPENSSL_memset(&gctx->gcm, 0, sizeof(gctx->gcm));
|
360
|
+
gctx->ctr = aes_ctr_set_key(&gctx->ks.ks, &gctx->gcm.gcm_key, NULL, key,
|
361
|
+
ctx->key_len);
|
407
362
|
// If we have an iv can set it directly, otherwise use saved IV.
|
408
363
|
if (iv == NULL && gctx->iv_set) {
|
409
364
|
iv = gctx->iv;
|
@@ -427,7 +382,7 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
|
427
382
|
}
|
428
383
|
|
429
384
|
static void aes_gcm_cleanup(EVP_CIPHER_CTX *c) {
|
430
|
-
EVP_AES_GCM_CTX *gctx = c
|
385
|
+
EVP_AES_GCM_CTX *gctx = aes_gcm_from_cipher_ctx(c);
|
431
386
|
OPENSSL_cleanse(&gctx->gcm, sizeof(gctx->gcm));
|
432
387
|
if (gctx->iv != c->iv) {
|
433
388
|
OPENSSL_free(gctx->iv);
|
@@ -451,7 +406,7 @@ static void ctr64_inc(uint8_t *counter) {
|
|
451
406
|
}
|
452
407
|
|
453
408
|
static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
454
|
-
EVP_AES_GCM_CTX *gctx = c
|
409
|
+
EVP_AES_GCM_CTX *gctx = aes_gcm_from_cipher_ctx(c);
|
455
410
|
switch (type) {
|
456
411
|
case EVP_CTRL_INIT:
|
457
412
|
gctx->key_set = 0;
|
@@ -462,7 +417,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
|
462
417
|
gctx->iv_gen = 0;
|
463
418
|
return 1;
|
464
419
|
|
465
|
-
case
|
420
|
+
case EVP_CTRL_AEAD_SET_IVLEN:
|
466
421
|
if (arg <= 0) {
|
467
422
|
return 0;
|
468
423
|
}
|
@@ -480,7 +435,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
|
480
435
|
gctx->ivlen = arg;
|
481
436
|
return 1;
|
482
437
|
|
483
|
-
case
|
438
|
+
case EVP_CTRL_AEAD_SET_TAG:
|
484
439
|
if (arg <= 0 || arg > 16 || c->encrypt) {
|
485
440
|
return 0;
|
486
441
|
}
|
@@ -488,14 +443,14 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
|
488
443
|
gctx->taglen = arg;
|
489
444
|
return 1;
|
490
445
|
|
491
|
-
case
|
446
|
+
case EVP_CTRL_AEAD_GET_TAG:
|
492
447
|
if (arg <= 0 || arg > 16 || !c->encrypt || gctx->taglen < 0) {
|
493
448
|
return 0;
|
494
449
|
}
|
495
450
|
OPENSSL_memcpy(ptr, c->buf, arg);
|
496
451
|
return 1;
|
497
452
|
|
498
|
-
case
|
453
|
+
case EVP_CTRL_AEAD_SET_IV_FIXED:
|
499
454
|
// Special case: -1 length restores whole IV
|
500
455
|
if (arg == -1) {
|
501
456
|
OPENSSL_memcpy(gctx->iv, ptr, gctx->ivlen);
|
@@ -543,7 +498,10 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
|
543
498
|
|
544
499
|
case EVP_CTRL_COPY: {
|
545
500
|
EVP_CIPHER_CTX *out = ptr;
|
546
|
-
EVP_AES_GCM_CTX *gctx_out = out
|
501
|
+
EVP_AES_GCM_CTX *gctx_out = aes_gcm_from_cipher_ctx(out);
|
502
|
+
// |EVP_CIPHER_CTX_copy| copies this generically, but we must redo it in
|
503
|
+
// case |out->cipher_data| and |in->cipher_data| are differently aligned.
|
504
|
+
OPENSSL_memcpy(gctx_out, gctx, sizeof(EVP_AES_GCM_CTX));
|
547
505
|
if (gctx->iv == c->iv) {
|
548
506
|
gctx_out->iv = out->iv;
|
549
507
|
} else {
|
@@ -563,7 +521,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
|
563
521
|
|
564
522
|
static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
565
523
|
size_t len) {
|
566
|
-
EVP_AES_GCM_CTX *gctx = ctx
|
524
|
+
EVP_AES_GCM_CTX *gctx = aes_gcm_from_cipher_ctx(ctx);
|
567
525
|
|
568
526
|
// If not set up, return error
|
569
527
|
if (!gctx->key_set) {
|
@@ -677,8 +635,8 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aes_128_gcm_generic) {
|
|
677
635
|
out->block_size = 1;
|
678
636
|
out->key_len = 16;
|
679
637
|
out->iv_len = 12;
|
680
|
-
out->ctx_size = sizeof(EVP_AES_GCM_CTX);
|
681
|
-
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV |
|
638
|
+
out->ctx_size = sizeof(EVP_AES_GCM_CTX) + EVP_AES_GCM_CTX_PADDING;
|
639
|
+
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_CUSTOM_COPY |
|
682
640
|
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
|
683
641
|
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
|
684
642
|
out->init = aes_gcm_init_key;
|
@@ -725,6 +683,19 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aes_192_ecb_generic) {
|
|
725
683
|
out->cipher = aes_ecb_cipher;
|
726
684
|
}
|
727
685
|
|
686
|
+
DEFINE_LOCAL_DATA(EVP_CIPHER, aes_192_ofb_generic) {
|
687
|
+
memset(out, 0, sizeof(EVP_CIPHER));
|
688
|
+
|
689
|
+
out->nid = NID_aes_192_ofb128;
|
690
|
+
out->block_size = 1;
|
691
|
+
out->key_len = 24;
|
692
|
+
out->iv_len = 16;
|
693
|
+
out->ctx_size = sizeof(EVP_AES_KEY);
|
694
|
+
out->flags = EVP_CIPH_OFB_MODE;
|
695
|
+
out->init = aes_init_key;
|
696
|
+
out->cipher = aes_ofb_cipher;
|
697
|
+
}
|
698
|
+
|
728
699
|
DEFINE_LOCAL_DATA(EVP_CIPHER, aes_192_gcm_generic) {
|
729
700
|
memset(out, 0, sizeof(EVP_CIPHER));
|
730
701
|
|
@@ -732,8 +703,8 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aes_192_gcm_generic) {
|
|
732
703
|
out->block_size = 1;
|
733
704
|
out->key_len = 24;
|
734
705
|
out->iv_len = 12;
|
735
|
-
out->ctx_size = sizeof(EVP_AES_GCM_CTX);
|
736
|
-
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV |
|
706
|
+
out->ctx_size = sizeof(EVP_AES_GCM_CTX) + EVP_AES_GCM_CTX_PADDING;
|
707
|
+
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_CUSTOM_COPY |
|
737
708
|
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
|
738
709
|
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
|
739
710
|
out->init = aes_gcm_init_key;
|
@@ -800,8 +771,8 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aes_256_gcm_generic) {
|
|
800
771
|
out->block_size = 1;
|
801
772
|
out->key_len = 32;
|
802
773
|
out->iv_len = 12;
|
803
|
-
out->ctx_size = sizeof(EVP_AES_GCM_CTX);
|
804
|
-
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV |
|
774
|
+
out->ctx_size = sizeof(EVP_AES_GCM_CTX) + EVP_AES_GCM_CTX_PADDING;
|
775
|
+
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV | EVP_CIPH_CUSTOM_COPY |
|
805
776
|
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
|
806
777
|
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
|
807
778
|
out->init = aes_gcm_init_key;
|
@@ -810,126 +781,22 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aes_256_gcm_generic) {
|
|
810
781
|
out->ctrl = aes_gcm_ctrl;
|
811
782
|
}
|
812
783
|
|
813
|
-
#if
|
814
|
-
(defined(OPENSSL_X86_64) || defined(OPENSSL_X86))
|
815
|
-
|
816
|
-
// AES-NI section.
|
784
|
+
#if defined(HWAES_ECB)
|
817
785
|
|
818
|
-
static
|
819
|
-
|
820
|
-
}
|
821
|
-
|
822
|
-
static int aesni_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
823
|
-
const uint8_t *iv, int enc) {
|
824
|
-
int ret, mode;
|
825
|
-
EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
|
826
|
-
|
827
|
-
mode = ctx->cipher->flags & EVP_CIPH_MODE_MASK;
|
828
|
-
if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE) && !enc) {
|
829
|
-
ret = aesni_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
|
830
|
-
dat->block = (block128_f)aesni_decrypt;
|
831
|
-
dat->stream.cbc =
|
832
|
-
mode == EVP_CIPH_CBC_MODE ? (cbc128_f)aesni_cbc_encrypt : NULL;
|
833
|
-
} else {
|
834
|
-
ret = aesni_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
|
835
|
-
dat->block = (block128_f)aesni_encrypt;
|
836
|
-
if (mode == EVP_CIPH_CBC_MODE) {
|
837
|
-
dat->stream.cbc = (cbc128_f)aesni_cbc_encrypt;
|
838
|
-
} else if (mode == EVP_CIPH_CTR_MODE) {
|
839
|
-
dat->stream.ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;
|
840
|
-
} else {
|
841
|
-
dat->stream.cbc = NULL;
|
842
|
-
}
|
843
|
-
}
|
844
|
-
|
845
|
-
if (ret < 0) {
|
846
|
-
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_AES_KEY_SETUP_FAILED);
|
847
|
-
return 0;
|
848
|
-
}
|
849
|
-
|
850
|
-
return 1;
|
851
|
-
}
|
852
|
-
|
853
|
-
static int aesni_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
854
|
-
const uint8_t *in, size_t len) {
|
855
|
-
aesni_cbc_encrypt(in, out, len, ctx->cipher_data, ctx->iv, ctx->encrypt);
|
856
|
-
|
857
|
-
return 1;
|
858
|
-
}
|
859
|
-
|
860
|
-
static int aesni_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
861
|
-
const uint8_t *in, size_t len) {
|
786
|
+
static int aes_hw_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
787
|
+
const uint8_t *in, size_t len) {
|
862
788
|
size_t bl = ctx->cipher->block_size;
|
863
789
|
|
864
790
|
if (len < bl) {
|
865
791
|
return 1;
|
866
792
|
}
|
867
793
|
|
868
|
-
|
794
|
+
aes_hw_ecb_encrypt(in, out, len, ctx->cipher_data, ctx->encrypt);
|
869
795
|
|
870
796
|
return 1;
|
871
797
|
}
|
872
798
|
|
873
|
-
|
874
|
-
const uint8_t *iv, int enc) {
|
875
|
-
EVP_AES_GCM_CTX *gctx = ctx->cipher_data;
|
876
|
-
if (!iv && !key) {
|
877
|
-
return 1;
|
878
|
-
}
|
879
|
-
if (key) {
|
880
|
-
aesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks.ks);
|
881
|
-
CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)aesni_encrypt, 1);
|
882
|
-
gctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;
|
883
|
-
// If we have an iv can set it directly, otherwise use
|
884
|
-
// saved IV.
|
885
|
-
if (iv == NULL && gctx->iv_set) {
|
886
|
-
iv = gctx->iv;
|
887
|
-
}
|
888
|
-
if (iv) {
|
889
|
-
CRYPTO_gcm128_setiv(&gctx->gcm, &gctx->ks.ks, iv, gctx->ivlen);
|
890
|
-
gctx->iv_set = 1;
|
891
|
-
}
|
892
|
-
gctx->key_set = 1;
|
893
|
-
} else {
|
894
|
-
// If key set use IV, otherwise copy
|
895
|
-
if (gctx->key_set) {
|
896
|
-
CRYPTO_gcm128_setiv(&gctx->gcm, &gctx->ks.ks, iv, gctx->ivlen);
|
897
|
-
} else {
|
898
|
-
OPENSSL_memcpy(gctx->iv, iv, gctx->ivlen);
|
899
|
-
}
|
900
|
-
gctx->iv_set = 1;
|
901
|
-
gctx->iv_gen = 0;
|
902
|
-
}
|
903
|
-
return 1;
|
904
|
-
}
|
905
|
-
|
906
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_128_cbc) {
|
907
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
908
|
-
|
909
|
-
out->nid = NID_aes_128_cbc;
|
910
|
-
out->block_size = 16;
|
911
|
-
out->key_len = 16;
|
912
|
-
out->iv_len = 16;
|
913
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
914
|
-
out->flags = EVP_CIPH_CBC_MODE;
|
915
|
-
out->init = aesni_init_key;
|
916
|
-
out->cipher = aesni_cbc_cipher;
|
917
|
-
}
|
918
|
-
|
919
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_128_ctr) {
|
920
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
921
|
-
|
922
|
-
out->nid = NID_aes_128_ctr;
|
923
|
-
out->block_size = 1;
|
924
|
-
out->key_len = 16;
|
925
|
-
out->iv_len = 16;
|
926
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
927
|
-
out->flags = EVP_CIPH_CTR_MODE;
|
928
|
-
out->init = aesni_init_key;
|
929
|
-
out->cipher = aes_ctr_cipher;
|
930
|
-
}
|
931
|
-
|
932
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_128_ecb) {
|
799
|
+
DEFINE_LOCAL_DATA(EVP_CIPHER, aes_hw_128_ecb) {
|
933
800
|
memset(out, 0, sizeof(EVP_CIPHER));
|
934
801
|
|
935
802
|
out->nid = NID_aes_128_ecb;
|
@@ -937,67 +804,11 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_128_ecb) {
|
|
937
804
|
out->key_len = 16;
|
938
805
|
out->ctx_size = sizeof(EVP_AES_KEY);
|
939
806
|
out->flags = EVP_CIPH_ECB_MODE;
|
940
|
-
out->init =
|
941
|
-
out->cipher =
|
942
|
-
}
|
943
|
-
|
944
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_128_ofb) {
|
945
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
946
|
-
|
947
|
-
out->nid = NID_aes_128_ofb128;
|
948
|
-
out->block_size = 1;
|
949
|
-
out->key_len = 16;
|
950
|
-
out->iv_len = 16;
|
951
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
952
|
-
out->flags = EVP_CIPH_OFB_MODE;
|
953
|
-
out->init = aesni_init_key;
|
954
|
-
out->cipher = aes_ofb_cipher;
|
955
|
-
}
|
956
|
-
|
957
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_128_gcm) {
|
958
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
959
|
-
|
960
|
-
out->nid = NID_aes_128_gcm;
|
961
|
-
out->block_size = 1;
|
962
|
-
out->key_len = 16;
|
963
|
-
out->iv_len = 12;
|
964
|
-
out->ctx_size = sizeof(EVP_AES_GCM_CTX);
|
965
|
-
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV |
|
966
|
-
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
|
967
|
-
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
|
968
|
-
out->init = aesni_gcm_init_key;
|
969
|
-
out->cipher = aes_gcm_cipher;
|
970
|
-
out->cleanup = aes_gcm_cleanup;
|
971
|
-
out->ctrl = aes_gcm_ctrl;
|
972
|
-
}
|
973
|
-
|
974
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_192_cbc) {
|
975
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
976
|
-
|
977
|
-
out->nid = NID_aes_192_cbc;
|
978
|
-
out->block_size = 16;
|
979
|
-
out->key_len = 24;
|
980
|
-
out->iv_len = 16;
|
981
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
982
|
-
out->flags = EVP_CIPH_CBC_MODE;
|
983
|
-
out->init = aesni_init_key;
|
984
|
-
out->cipher = aesni_cbc_cipher;
|
985
|
-
}
|
986
|
-
|
987
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_192_ctr) {
|
988
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
989
|
-
|
990
|
-
out->nid = NID_aes_192_ctr;
|
991
|
-
out->block_size = 1;
|
992
|
-
out->key_len = 24;
|
993
|
-
out->iv_len = 16;
|
994
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
995
|
-
out->flags = EVP_CIPH_CTR_MODE;
|
996
|
-
out->init = aesni_init_key;
|
997
|
-
out->cipher = aes_ctr_cipher;
|
807
|
+
out->init = aes_init_key;
|
808
|
+
out->cipher = aes_hw_ecb_cipher;
|
998
809
|
}
|
999
810
|
|
1000
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER,
|
811
|
+
DEFINE_LOCAL_DATA(EVP_CIPHER, aes_hw_192_ecb) {
|
1001
812
|
memset(out, 0, sizeof(EVP_CIPHER));
|
1002
813
|
|
1003
814
|
out->nid = NID_aes_192_ecb;
|
@@ -1005,54 +816,11 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_192_ecb) {
|
|
1005
816
|
out->key_len = 24;
|
1006
817
|
out->ctx_size = sizeof(EVP_AES_KEY);
|
1007
818
|
out->flags = EVP_CIPH_ECB_MODE;
|
1008
|
-
out->init =
|
1009
|
-
out->cipher =
|
1010
|
-
}
|
1011
|
-
|
1012
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_192_gcm) {
|
1013
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
1014
|
-
|
1015
|
-
out->nid = NID_aes_192_gcm;
|
1016
|
-
out->block_size = 1;
|
1017
|
-
out->key_len = 24;
|
1018
|
-
out->iv_len = 12;
|
1019
|
-
out->ctx_size = sizeof(EVP_AES_GCM_CTX);
|
1020
|
-
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV |
|
1021
|
-
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
|
1022
|
-
EVP_CIPH_CTRL_INIT | EVP_CIPH_FLAG_AEAD_CIPHER;
|
1023
|
-
out->init = aesni_gcm_init_key;
|
1024
|
-
out->cipher = aes_gcm_cipher;
|
1025
|
-
out->cleanup = aes_gcm_cleanup;
|
1026
|
-
out->ctrl = aes_gcm_ctrl;
|
1027
|
-
}
|
1028
|
-
|
1029
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_256_cbc) {
|
1030
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
1031
|
-
|
1032
|
-
out->nid = NID_aes_256_cbc;
|
1033
|
-
out->block_size = 16;
|
1034
|
-
out->key_len = 32;
|
1035
|
-
out->iv_len = 16;
|
1036
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
1037
|
-
out->flags = EVP_CIPH_CBC_MODE;
|
1038
|
-
out->init = aesni_init_key;
|
1039
|
-
out->cipher = aesni_cbc_cipher;
|
1040
|
-
}
|
1041
|
-
|
1042
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_256_ctr) {
|
1043
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
1044
|
-
|
1045
|
-
out->nid = NID_aes_256_ctr;
|
1046
|
-
out->block_size = 1;
|
1047
|
-
out->key_len = 32;
|
1048
|
-
out->iv_len = 16;
|
1049
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
1050
|
-
out->flags = EVP_CIPH_CTR_MODE;
|
1051
|
-
out->init = aesni_init_key;
|
1052
|
-
out->cipher = aes_ctr_cipher;
|
819
|
+
out->init = aes_init_key;
|
820
|
+
out->cipher = aes_hw_ecb_cipher;
|
1053
821
|
}
|
1054
822
|
|
1055
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER,
|
823
|
+
DEFINE_LOCAL_DATA(EVP_CIPHER, aes_hw_256_ecb) {
|
1056
824
|
memset(out, 0, sizeof(EVP_CIPHER));
|
1057
825
|
|
1058
826
|
out->nid = NID_aes_256_ecb;
|
@@ -1060,80 +828,51 @@ DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_256_ecb) {
|
|
1060
828
|
out->key_len = 32;
|
1061
829
|
out->ctx_size = sizeof(EVP_AES_KEY);
|
1062
830
|
out->flags = EVP_CIPH_ECB_MODE;
|
1063
|
-
out->init =
|
1064
|
-
out->cipher =
|
1065
|
-
}
|
1066
|
-
|
1067
|
-
DEFINE_LOCAL_DATA(EVP_CIPHER, aesni_256_ofb) {
|
1068
|
-
memset(out, 0, sizeof(EVP_CIPHER));
|
1069
|
-
|
1070
|
-
out->nid = NID_aes_256_ofb128;
|
1071
|
-
out->block_size = 1;
|
1072
|
-
out->key_len = 32;
|
1073
|
-
out->iv_len = 16;
|
1074
|
-
out->ctx_size = sizeof(EVP_AES_KEY);
|
1075
|
-
out->flags = EVP_CIPH_OFB_MODE;
|
1076
|
-
out->init = aesni_init_key;
|
1077
|
-
out->cipher = aes_ofb_cipher;
|
831
|
+
out->init = aes_init_key;
|
832
|
+
out->cipher = aes_hw_ecb_cipher;
|
1078
833
|
}
|
1079
834
|
|
1080
|
-
|
1081
|
-
|
835
|
+
#define EVP_ECB_CIPHER_FUNCTION(keybits) \
|
836
|
+
const EVP_CIPHER *EVP_aes_##keybits##_ecb(void) { \
|
837
|
+
if (hwaes_capable()) { \
|
838
|
+
return aes_hw_##keybits##_ecb(); \
|
839
|
+
} \
|
840
|
+
return aes_##keybits##_ecb_generic(); \
|
841
|
+
}
|
1082
842
|
|
1083
|
-
|
1084
|
-
out->block_size = 1;
|
1085
|
-
out->key_len = 32;
|
1086
|
-
out->iv_len = 12;
|
1087
|
-
out->ctx_size = sizeof(EVP_AES_GCM_CTX);
|
1088
|
-
out->flags = EVP_CIPH_GCM_MODE | EVP_CIPH_CUSTOM_IV |
|
1089
|
-
EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT |
|
1090
|
-
EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY |
|
1091
|
-
EVP_CIPH_FLAG_AEAD_CIPHER;
|
1092
|
-
out->init = aesni_gcm_init_key;
|
1093
|
-
out->cipher = aes_gcm_cipher;
|
1094
|
-
out->cleanup = aes_gcm_cleanup;
|
1095
|
-
out->ctrl = aes_gcm_ctrl;
|
1096
|
-
}
|
843
|
+
#else
|
1097
844
|
|
1098
|
-
#define
|
1099
|
-
const EVP_CIPHER *EVP_aes_##keybits##
|
1100
|
-
|
1101
|
-
return aesni_##keybits##_##mode(); \
|
1102
|
-
} else { \
|
1103
|
-
return aes_##keybits##_##mode##_generic(); \
|
1104
|
-
} \
|
845
|
+
#define EVP_ECB_CIPHER_FUNCTION(keybits) \
|
846
|
+
const EVP_CIPHER *EVP_aes_##keybits##_ecb(void) { \
|
847
|
+
return aes_##keybits##_ecb_generic(); \
|
1105
848
|
}
|
1106
849
|
|
1107
|
-
#
|
1108
|
-
|
1109
|
-
static char aesni_capable(void) {
|
1110
|
-
return 0;
|
1111
|
-
}
|
850
|
+
#endif // HWAES_ECB
|
1112
851
|
|
1113
852
|
#define EVP_CIPHER_FUNCTION(keybits, mode) \
|
1114
853
|
const EVP_CIPHER *EVP_aes_##keybits##_##mode(void) { \
|
1115
854
|
return aes_##keybits##_##mode##_generic(); \
|
1116
855
|
}
|
1117
856
|
|
1118
|
-
#endif
|
1119
|
-
|
1120
857
|
EVP_CIPHER_FUNCTION(128, cbc)
|
1121
858
|
EVP_CIPHER_FUNCTION(128, ctr)
|
1122
|
-
EVP_CIPHER_FUNCTION(128, ecb)
|
1123
859
|
EVP_CIPHER_FUNCTION(128, ofb)
|
1124
860
|
EVP_CIPHER_FUNCTION(128, gcm)
|
1125
861
|
|
1126
862
|
EVP_CIPHER_FUNCTION(192, cbc)
|
1127
863
|
EVP_CIPHER_FUNCTION(192, ctr)
|
1128
|
-
EVP_CIPHER_FUNCTION(192,
|
864
|
+
EVP_CIPHER_FUNCTION(192, ofb)
|
1129
865
|
EVP_CIPHER_FUNCTION(192, gcm)
|
1130
866
|
|
1131
867
|
EVP_CIPHER_FUNCTION(256, cbc)
|
1132
868
|
EVP_CIPHER_FUNCTION(256, ctr)
|
1133
|
-
EVP_CIPHER_FUNCTION(256, ecb)
|
1134
869
|
EVP_CIPHER_FUNCTION(256, ofb)
|
1135
870
|
EVP_CIPHER_FUNCTION(256, gcm)
|
1136
871
|
|
872
|
+
EVP_ECB_CIPHER_FUNCTION(128)
|
873
|
+
EVP_ECB_CIPHER_FUNCTION(192)
|
874
|
+
EVP_ECB_CIPHER_FUNCTION(256)
|
875
|
+
|
1137
876
|
|
1138
877
|
#define EVP_AEAD_AES_GCM_TAG_LEN 16
|
1139
878
|
|
@@ -1142,21 +881,16 @@ struct aead_aes_gcm_ctx {
|
|
1142
881
|
double align;
|
1143
882
|
AES_KEY ks;
|
1144
883
|
} ks;
|
1145
|
-
|
884
|
+
GCM128_KEY gcm_key;
|
1146
885
|
ctr128_f ctr;
|
1147
886
|
};
|
1148
887
|
|
1149
|
-
struct aead_aes_gcm_tls12_ctx {
|
1150
|
-
struct aead_aes_gcm_ctx gcm_ctx;
|
1151
|
-
uint64_t min_next_nonce;
|
1152
|
-
};
|
1153
|
-
|
1154
888
|
static int aead_aes_gcm_init_impl(struct aead_aes_gcm_ctx *gcm_ctx,
|
1155
889
|
size_t *out_tag_len, const uint8_t *key,
|
1156
890
|
size_t key_len, size_t tag_len) {
|
1157
891
|
const size_t key_bits = key_len * 8;
|
1158
892
|
|
1159
|
-
if (key_bits != 128 && key_bits != 256) {
|
893
|
+
if (key_bits != 128 && key_bits != 192 && key_bits != 256) {
|
1160
894
|
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH);
|
1161
895
|
return 0; // EVP_AEAD_CTX_init should catch this.
|
1162
896
|
}
|
@@ -1171,34 +905,35 @@ static int aead_aes_gcm_init_impl(struct aead_aes_gcm_ctx *gcm_ctx,
|
|
1171
905
|
}
|
1172
906
|
|
1173
907
|
gcm_ctx->ctr =
|
1174
|
-
aes_ctr_set_key(&gcm_ctx->ks.ks, &gcm_ctx->
|
908
|
+
aes_ctr_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm_key, NULL, key, key_len);
|
1175
909
|
*out_tag_len = tag_len;
|
1176
910
|
return 1;
|
1177
911
|
}
|
1178
912
|
|
913
|
+
OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >=
|
914
|
+
sizeof(struct aead_aes_gcm_ctx),
|
915
|
+
"AEAD state is too small");
|
916
|
+
#if defined(__GNUC__) || defined(__clang__)
|
917
|
+
OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >=
|
918
|
+
alignof(struct aead_aes_gcm_ctx),
|
919
|
+
"AEAD state has insufficient alignment");
|
920
|
+
#endif
|
921
|
+
|
1179
922
|
static int aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
1180
923
|
size_t key_len, size_t requested_tag_len) {
|
1181
|
-
struct aead_aes_gcm_ctx *gcm_ctx;
|
1182
|
-
gcm_ctx = OPENSSL_malloc(sizeof(struct aead_aes_gcm_ctx));
|
1183
|
-
if (gcm_ctx == NULL) {
|
1184
|
-
return 0;
|
1185
|
-
}
|
924
|
+
struct aead_aes_gcm_ctx *gcm_ctx = (struct aead_aes_gcm_ctx *) &ctx->state;
|
1186
925
|
|
1187
926
|
size_t actual_tag_len;
|
1188
927
|
if (!aead_aes_gcm_init_impl(gcm_ctx, &actual_tag_len, key, key_len,
|
1189
928
|
requested_tag_len)) {
|
1190
|
-
OPENSSL_free(gcm_ctx);
|
1191
929
|
return 0;
|
1192
930
|
}
|
1193
931
|
|
1194
|
-
ctx->aead_state = gcm_ctx;
|
1195
932
|
ctx->tag_len = actual_tag_len;
|
1196
933
|
return 1;
|
1197
934
|
}
|
1198
935
|
|
1199
|
-
static void aead_aes_gcm_cleanup(EVP_AEAD_CTX *ctx) {
|
1200
|
-
OPENSSL_free(ctx->aead_state);
|
1201
|
-
}
|
936
|
+
static void aead_aes_gcm_cleanup(EVP_AEAD_CTX *ctx) {}
|
1202
937
|
|
1203
938
|
static int aead_aes_gcm_seal_scatter(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
1204
939
|
uint8_t *out_tag, size_t *out_tag_len,
|
@@ -1208,8 +943,7 @@ static int aead_aes_gcm_seal_scatter(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
|
1208
943
|
const uint8_t *extra_in,
|
1209
944
|
size_t extra_in_len,
|
1210
945
|
const uint8_t *ad, size_t ad_len) {
|
1211
|
-
|
1212
|
-
GCM128_CONTEXT gcm;
|
946
|
+
struct aead_aes_gcm_ctx *gcm_ctx = (struct aead_aes_gcm_ctx *) &ctx->state;
|
1213
947
|
|
1214
948
|
if (extra_in_len + ctx->tag_len < ctx->tag_len) {
|
1215
949
|
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
|
@@ -1226,7 +960,9 @@ static int aead_aes_gcm_seal_scatter(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
|
1226
960
|
|
1227
961
|
const AES_KEY *key = &gcm_ctx->ks.ks;
|
1228
962
|
|
1229
|
-
|
963
|
+
GCM128_CONTEXT gcm;
|
964
|
+
OPENSSL_memset(&gcm, 0, sizeof(gcm));
|
965
|
+
OPENSSL_memcpy(&gcm.gcm_key, &gcm_ctx->gcm_key, sizeof(gcm.gcm_key));
|
1230
966
|
CRYPTO_gcm128_setiv(&gcm, key, nonce, nonce_len);
|
1231
967
|
|
1232
968
|
if (ad_len > 0 && !CRYPTO_gcm128_aad(&gcm, ad, ad_len)) {
|
@@ -1268,9 +1004,8 @@ static int aead_aes_gcm_open_gather(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
|
1268
1004
|
const uint8_t *in, size_t in_len,
|
1269
1005
|
const uint8_t *in_tag, size_t in_tag_len,
|
1270
1006
|
const uint8_t *ad, size_t ad_len) {
|
1271
|
-
|
1007
|
+
struct aead_aes_gcm_ctx *gcm_ctx = (struct aead_aes_gcm_ctx *) &ctx->state;
|
1272
1008
|
uint8_t tag[EVP_AEAD_AES_GCM_TAG_LEN];
|
1273
|
-
GCM128_CONTEXT gcm;
|
1274
1009
|
|
1275
1010
|
if (nonce_len == 0) {
|
1276
1011
|
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_NONCE_SIZE);
|
@@ -1284,7 +1019,9 @@ static int aead_aes_gcm_open_gather(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
|
1284
1019
|
|
1285
1020
|
const AES_KEY *key = &gcm_ctx->ks.ks;
|
1286
1021
|
|
1287
|
-
|
1022
|
+
GCM128_CONTEXT gcm;
|
1023
|
+
OPENSSL_memset(&gcm, 0, sizeof(gcm));
|
1024
|
+
OPENSSL_memcpy(&gcm.gcm_key, &gcm_ctx->gcm_key, sizeof(gcm.gcm_key));
|
1288
1025
|
CRYPTO_gcm128_setiv(&gcm, key, nonce, nonce_len);
|
1289
1026
|
|
1290
1027
|
if (!CRYPTO_gcm128_aad(&gcm, ad, ad_len)) {
|
@@ -1326,6 +1063,21 @@ DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_gcm) {
|
|
1326
1063
|
out->open_gather = aead_aes_gcm_open_gather;
|
1327
1064
|
}
|
1328
1065
|
|
1066
|
+
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_192_gcm) {
|
1067
|
+
memset(out, 0, sizeof(EVP_AEAD));
|
1068
|
+
|
1069
|
+
out->key_len = 24;
|
1070
|
+
out->nonce_len = 12;
|
1071
|
+
out->overhead = EVP_AEAD_AES_GCM_TAG_LEN;
|
1072
|
+
out->max_tag_len = EVP_AEAD_AES_GCM_TAG_LEN;
|
1073
|
+
out->seal_scatter_supports_extra_in = 1;
|
1074
|
+
|
1075
|
+
out->init = aead_aes_gcm_init;
|
1076
|
+
out->cleanup = aead_aes_gcm_cleanup;
|
1077
|
+
out->seal_scatter = aead_aes_gcm_seal_scatter;
|
1078
|
+
out->open_gather = aead_aes_gcm_open_gather;
|
1079
|
+
}
|
1080
|
+
|
1329
1081
|
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_256_gcm) {
|
1330
1082
|
memset(out, 0, sizeof(EVP_AEAD));
|
1331
1083
|
|
@@ -1341,38 +1093,45 @@ DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_256_gcm) {
|
|
1341
1093
|
out->open_gather = aead_aes_gcm_open_gather;
|
1342
1094
|
}
|
1343
1095
|
|
1096
|
+
struct aead_aes_gcm_tls12_ctx {
|
1097
|
+
struct aead_aes_gcm_ctx gcm_ctx;
|
1098
|
+
uint64_t min_next_nonce;
|
1099
|
+
};
|
1100
|
+
|
1101
|
+
OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >=
|
1102
|
+
sizeof(struct aead_aes_gcm_tls12_ctx),
|
1103
|
+
"AEAD state is too small");
|
1104
|
+
#if defined(__GNUC__) || defined(__clang__)
|
1105
|
+
OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >=
|
1106
|
+
alignof(struct aead_aes_gcm_tls12_ctx),
|
1107
|
+
"AEAD state has insufficient alignment");
|
1108
|
+
#endif
|
1109
|
+
|
1344
1110
|
static int aead_aes_gcm_tls12_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
1345
1111
|
size_t key_len, size_t requested_tag_len) {
|
1346
|
-
struct aead_aes_gcm_tls12_ctx *gcm_ctx
|
1347
|
-
|
1348
|
-
if (gcm_ctx == NULL) {
|
1349
|
-
return 0;
|
1350
|
-
}
|
1112
|
+
struct aead_aes_gcm_tls12_ctx *gcm_ctx =
|
1113
|
+
(struct aead_aes_gcm_tls12_ctx *) &ctx->state;
|
1351
1114
|
|
1352
1115
|
gcm_ctx->min_next_nonce = 0;
|
1353
1116
|
|
1354
1117
|
size_t actual_tag_len;
|
1355
1118
|
if (!aead_aes_gcm_init_impl(&gcm_ctx->gcm_ctx, &actual_tag_len, key, key_len,
|
1356
1119
|
requested_tag_len)) {
|
1357
|
-
OPENSSL_free(gcm_ctx);
|
1358
1120
|
return 0;
|
1359
1121
|
}
|
1360
1122
|
|
1361
|
-
ctx->aead_state = gcm_ctx;
|
1362
1123
|
ctx->tag_len = actual_tag_len;
|
1363
1124
|
return 1;
|
1364
1125
|
}
|
1365
1126
|
|
1366
|
-
static void aead_aes_gcm_tls12_cleanup(EVP_AEAD_CTX *ctx) {
|
1367
|
-
OPENSSL_free(ctx->aead_state);
|
1368
|
-
}
|
1369
|
-
|
1370
1127
|
static int aead_aes_gcm_tls12_seal_scatter(
|
1371
1128
|
const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
|
1372
1129
|
size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
|
1373
1130
|
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
|
1374
1131
|
size_t extra_in_len, const uint8_t *ad, size_t ad_len) {
|
1375
|
-
struct aead_aes_gcm_tls12_ctx *gcm_ctx =
|
1132
|
+
struct aead_aes_gcm_tls12_ctx *gcm_ctx =
|
1133
|
+
(struct aead_aes_gcm_tls12_ctx *) &ctx->state;
|
1134
|
+
|
1376
1135
|
if (nonce_len != 12) {
|
1377
1136
|
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_UNSUPPORTED_NONCE_SIZE);
|
1378
1137
|
return 0;
|
@@ -1406,7 +1165,7 @@ DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_gcm_tls12) {
|
|
1406
1165
|
out->seal_scatter_supports_extra_in = 1;
|
1407
1166
|
|
1408
1167
|
out->init = aead_aes_gcm_tls12_init;
|
1409
|
-
out->cleanup =
|
1168
|
+
out->cleanup = aead_aes_gcm_cleanup;
|
1410
1169
|
out->seal_scatter = aead_aes_gcm_tls12_seal_scatter;
|
1411
1170
|
out->open_gather = aead_aes_gcm_open_gather;
|
1412
1171
|
}
|
@@ -1421,17 +1180,125 @@ DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_256_gcm_tls12) {
|
|
1421
1180
|
out->seal_scatter_supports_extra_in = 1;
|
1422
1181
|
|
1423
1182
|
out->init = aead_aes_gcm_tls12_init;
|
1424
|
-
out->cleanup =
|
1183
|
+
out->cleanup = aead_aes_gcm_cleanup;
|
1425
1184
|
out->seal_scatter = aead_aes_gcm_tls12_seal_scatter;
|
1426
1185
|
out->open_gather = aead_aes_gcm_open_gather;
|
1427
1186
|
}
|
1428
1187
|
|
1188
|
+
struct aead_aes_gcm_tls13_ctx {
|
1189
|
+
struct aead_aes_gcm_ctx gcm_ctx;
|
1190
|
+
uint64_t min_next_nonce;
|
1191
|
+
uint64_t mask;
|
1192
|
+
uint8_t first;
|
1193
|
+
};
|
1194
|
+
|
1195
|
+
OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >=
|
1196
|
+
sizeof(struct aead_aes_gcm_tls13_ctx),
|
1197
|
+
"AEAD state is too small");
|
1198
|
+
#if defined(__GNUC__) || defined(__clang__)
|
1199
|
+
OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >=
|
1200
|
+
alignof(struct aead_aes_gcm_tls13_ctx),
|
1201
|
+
"AEAD state has insufficient alignment");
|
1202
|
+
#endif
|
1203
|
+
|
1204
|
+
static int aead_aes_gcm_tls13_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
1205
|
+
size_t key_len, size_t requested_tag_len) {
|
1206
|
+
struct aead_aes_gcm_tls13_ctx *gcm_ctx =
|
1207
|
+
(struct aead_aes_gcm_tls13_ctx *) &ctx->state;
|
1208
|
+
|
1209
|
+
gcm_ctx->min_next_nonce = 0;
|
1210
|
+
gcm_ctx->first = 1;
|
1211
|
+
|
1212
|
+
size_t actual_tag_len;
|
1213
|
+
if (!aead_aes_gcm_init_impl(&gcm_ctx->gcm_ctx, &actual_tag_len, key, key_len,
|
1214
|
+
requested_tag_len)) {
|
1215
|
+
return 0;
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
ctx->tag_len = actual_tag_len;
|
1219
|
+
return 1;
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
static int aead_aes_gcm_tls13_seal_scatter(
|
1223
|
+
const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
|
1224
|
+
size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
|
1225
|
+
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
|
1226
|
+
size_t extra_in_len, const uint8_t *ad, size_t ad_len) {
|
1227
|
+
struct aead_aes_gcm_tls13_ctx *gcm_ctx =
|
1228
|
+
(struct aead_aes_gcm_tls13_ctx *) &ctx->state;
|
1229
|
+
|
1230
|
+
if (nonce_len != 12) {
|
1231
|
+
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_UNSUPPORTED_NONCE_SIZE);
|
1232
|
+
return 0;
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
// The given nonces must be strictly monotonically increasing. See
|
1236
|
+
// https://tools.ietf.org/html/rfc8446#section-5.3 for details of the TLS 1.3
|
1237
|
+
// nonce construction.
|
1238
|
+
uint64_t given_counter;
|
1239
|
+
OPENSSL_memcpy(&given_counter, nonce + nonce_len - sizeof(given_counter),
|
1240
|
+
sizeof(given_counter));
|
1241
|
+
given_counter = CRYPTO_bswap8(given_counter);
|
1242
|
+
|
1243
|
+
if (gcm_ctx->first) {
|
1244
|
+
// In the first call the sequence number will be zero and therefore the
|
1245
|
+
// given nonce will be 0 ^ mask = mask.
|
1246
|
+
gcm_ctx->mask = given_counter;
|
1247
|
+
gcm_ctx->first = 0;
|
1248
|
+
}
|
1249
|
+
given_counter ^= gcm_ctx->mask;
|
1250
|
+
|
1251
|
+
if (given_counter == UINT64_MAX ||
|
1252
|
+
given_counter < gcm_ctx->min_next_nonce) {
|
1253
|
+
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_INVALID_NONCE);
|
1254
|
+
return 0;
|
1255
|
+
}
|
1256
|
+
|
1257
|
+
gcm_ctx->min_next_nonce = given_counter + 1;
|
1258
|
+
|
1259
|
+
return aead_aes_gcm_seal_scatter(ctx, out, out_tag, out_tag_len,
|
1260
|
+
max_out_tag_len, nonce, nonce_len, in,
|
1261
|
+
in_len, extra_in, extra_in_len, ad, ad_len);
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_gcm_tls13) {
|
1265
|
+
memset(out, 0, sizeof(EVP_AEAD));
|
1266
|
+
|
1267
|
+
out->key_len = 16;
|
1268
|
+
out->nonce_len = 12;
|
1269
|
+
out->overhead = EVP_AEAD_AES_GCM_TAG_LEN;
|
1270
|
+
out->max_tag_len = EVP_AEAD_AES_GCM_TAG_LEN;
|
1271
|
+
out->seal_scatter_supports_extra_in = 1;
|
1272
|
+
|
1273
|
+
out->init = aead_aes_gcm_tls13_init;
|
1274
|
+
out->cleanup = aead_aes_gcm_cleanup;
|
1275
|
+
out->seal_scatter = aead_aes_gcm_tls13_seal_scatter;
|
1276
|
+
out->open_gather = aead_aes_gcm_open_gather;
|
1277
|
+
}
|
1278
|
+
|
1279
|
+
DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_256_gcm_tls13) {
|
1280
|
+
memset(out, 0, sizeof(EVP_AEAD));
|
1281
|
+
|
1282
|
+
out->key_len = 32;
|
1283
|
+
out->nonce_len = 12;
|
1284
|
+
out->overhead = EVP_AEAD_AES_GCM_TAG_LEN;
|
1285
|
+
out->max_tag_len = EVP_AEAD_AES_GCM_TAG_LEN;
|
1286
|
+
out->seal_scatter_supports_extra_in = 1;
|
1287
|
+
|
1288
|
+
out->init = aead_aes_gcm_tls13_init;
|
1289
|
+
out->cleanup = aead_aes_gcm_cleanup;
|
1290
|
+
out->seal_scatter = aead_aes_gcm_tls13_seal_scatter;
|
1291
|
+
out->open_gather = aead_aes_gcm_open_gather;
|
1292
|
+
}
|
1293
|
+
|
1429
1294
|
int EVP_has_aes_hardware(void) {
|
1430
1295
|
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
1431
|
-
return
|
1296
|
+
return hwaes_capable() && crypto_gcm_clmul_enabled();
|
1432
1297
|
#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
1433
1298
|
return hwaes_capable() && CRYPTO_is_ARMv8_PMULL_capable();
|
1434
1299
|
#else
|
1435
1300
|
return 0;
|
1436
1301
|
#endif
|
1437
1302
|
}
|
1303
|
+
|
1304
|
+
OPENSSL_MSVC_PRAGMA(warning(pop))
|