grpc 1.84.1 → 1.86.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +48 -31
- data/etc/roots.pem +0 -583
- data/include/grpc/channel_factory.h +78 -0
- data/include/grpc/credentials.h +21 -0
- data/include/grpc/event_engine/memory_allocator.h +1 -0
- data/include/grpc/grpc.h +10 -0
- data/include/grpc/grpc_security_constants.h +4 -0
- data/include/grpc/impl/channel_arg_names.h +4 -0
- data/include/grpc/module.modulemap +1 -0
- data/src/core/call/call_filters.cc +4 -1
- data/src/core/call/call_filters.h +13 -11
- data/src/core/call/call_spine.h +12 -6
- data/src/core/call/call_state.h +3 -3
- data/src/core/call/client_call.cc +4 -1
- data/src/core/call/client_call.h +1 -0
- data/src/core/{lib/security/authorization → call}/evaluate_args.cc +34 -12
- data/src/core/{lib/security/authorization → call}/evaluate_args.h +19 -5
- data/src/core/call/filter_fusion.h +17 -30
- data/src/core/call/interception_chain.h +5 -10
- data/src/core/call/metadata_batch.cc +6 -0
- data/src/core/call/metadata_batch.h +79 -36
- data/src/core/call/parsed_metadata.h +3 -3
- data/src/core/call/request_buffer.cc +7 -7
- data/src/core/call/request_buffer.h +1 -1
- data/src/core/call/server_call.cc +3 -3
- data/src/core/call/server_call.h +15 -0
- data/src/core/channelz/channel_trace.cc +5 -5
- data/src/core/channelz/channel_trace.h +1 -1
- data/src/core/channelz/channelz.cc +9 -9
- data/src/core/channelz/channelz.h +12 -12
- data/src/core/channelz/channelz_registry.cc +14 -14
- data/src/core/channelz/ztrace_collector.h +16 -7
- data/src/core/client_channel/backup_poller.cc +1 -2
- data/src/core/client_channel/channel_factory.cc +110 -0
- data/src/core/client_channel/channel_factory.h +45 -0
- data/src/core/client_channel/client_channel.cc +4 -4
- data/src/core/client_channel/client_channel_filter.cc +14 -14
- data/src/core/client_channel/global_subchannel_pool.cc +6 -6
- data/src/core/client_channel/lame_channel.cc +59 -0
- data/src/core/client_channel/lame_channel.h +86 -0
- data/src/core/client_channel/subchannel.cc +24 -23
- data/src/core/client_channel/subchannel_stream_client.cc +5 -5
- data/src/core/credentials/call/external/aws_external_account_credentials.cc +7 -7
- data/src/core/credentials/call/external/aws_request_signer.cc +18 -1
- data/src/core/credentials/call/external/external_account_credentials.cc +4 -4
- data/src/core/credentials/call/external/url_external_account_credentials.cc +6 -17
- data/src/core/credentials/call/external/url_external_account_credentials.h +0 -1
- data/src/core/credentials/call/jwt/jwt_verifier.cc +25 -13
- data/src/core/credentials/call/oauth2/oauth2_credentials.cc +6 -4
- data/src/core/credentials/call/regional_access_boundary_fetcher.cc +25 -9
- data/src/core/credentials/call/regional_access_boundary_fetcher.h +6 -2
- data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.cc +4 -4
- data/src/core/credentials/transport/google_default/google_default_credentials.cc +3 -3
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +1 -1
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +9 -9
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +1 -1
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +6 -6
- data/src/core/credentials/transport/tls/grpc_tls_certificate_verifier.cc +3 -3
- data/src/core/credentials/transport/tls/grpc_tls_credentials_options.cc +14 -0
- data/src/core/credentials/transport/tls/grpc_tls_credentials_options.h +12 -2
- data/src/core/credentials/transport/tls/grpc_tls_crl_provider.cc +4 -4
- data/src/core/credentials/transport/tls/ssl_utils.cc +30 -0
- data/src/core/credentials/transport/tls/ssl_utils.h +4 -0
- data/src/core/credentials/transport/tls/tls_security_connector.cc +16 -12
- data/src/core/credentials/transport/tls/tls_security_connector.h +6 -6
- data/src/core/credentials/transport/tls/tls_utils.h +9 -0
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +1 -1
- data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +1 -1
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.cc +2 -2
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.h +1 -1
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +15 -0
- data/src/core/ext/filters/http/server/http_server_filter.cc +6 -1
- data/src/core/ext/filters/rbac/rbac_filter.cc +3 -41
- data/src/core/ext/filters/rbac/rbac_filter.h +3 -12
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +7 -7
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +61 -45
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +6 -13
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +80 -110
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -1
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +2 -6
- data/src/core/ext/transport/chttp2/transport/flow_control_manager.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame.cc +15 -19
- data/src/core/ext/transport/chttp2/transport/frame.h +10 -1
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +18 -61
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +0 -4
- data/src/core/ext/transport/chttp2/transport/frame_security.cc +1 -2
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +9 -0
- data/src/core/ext/transport/chttp2/transport/goaway.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/goaway.h +0 -5
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +1 -5
- data/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc +3 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +8 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +45 -9
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -2
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +50 -37
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +7 -3
- data/src/core/ext/transport/chttp2/transport/http2_server_transport.cc +407 -267
- data/src/core/ext/transport/chttp2/transport/http2_server_transport.h +70 -32
- data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +4 -3
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +21 -57
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +4 -35
- data/src/core/ext/transport/chttp2/transport/http2_transport_stats.h +60 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +8 -3
- data/src/core/ext/transport/chttp2/transport/keepalive.h +1 -4
- data/src/core/ext/transport/chttp2/transport/parsing.cc +7 -10
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +35 -11
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +52 -47
- data/src/core/ext/transport/chttp2/transport/read_context.h +115 -8
- data/src/core/ext/transport/chttp2/transport/reclaimer.cc +32 -0
- data/src/core/ext/transport/chttp2/transport/reclaimer.h +64 -0
- data/src/core/ext/transport/chttp2/transport/security_frame.h +15 -14
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +24 -14
- data/src/core/ext/transport/chttp2/transport/transport_common.cc +47 -0
- data/src/core/ext/transport/chttp2/transport/transport_common.h +29 -0
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +1 -1
- data/src/core/ext/transport/chttp2/transport/write_cycle.h +23 -3
- data/src/core/ext/transport/inproc/inproc_transport.cc +5 -5
- data/src/core/ext/transport/inproc/legacy_inproc_transport.cc +1 -7
- data/src/core/ext/upb-gen/envoy/admin/v3/clusters.upb.h +16 -0
- data/src/core/ext/upb-gen/envoy/admin/v3/clusters.upb_minitable.c +4 -3
- data/src/core/ext/upb-gen/envoy/admin/v3/server_info.upb.h +129 -81
- data/src/core/ext/upb-gen/envoy/admin/v3/server_info.upb_minitable.c +50 -39
- data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb.h +411 -163
- data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb_minitable.c +95 -44
- data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb_minitable.h +3 -0
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/circuit_breaker.upb.h +41 -8
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/circuit_breaker.upb_minitable.c +8 -5
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb.h +427 -222
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb_minitable.c +97 -66
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb_minitable.h +1 -0
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/outlier_detection.upb.h +130 -99
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/outlier_detection.upb_minitable.c +29 -27
- data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb.h +49 -33
- data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb_minitable.c +19 -8
- data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb.h +95 -3
- data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb_minitable.c +33 -6
- data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb_minitable.h +1 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/http_service.upb.h +93 -11
- data/src/core/ext/upb-gen/envoy/config/core/v3/http_service.upb_minitable.c +8 -5
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb.h +656 -134
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb_minitable.c +117 -51
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_option.upb.h +45 -23
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_option.upb_minitable.c +19 -10
- data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb.h +99 -34
- data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb_minitable.c +12 -7
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb.h +344 -273
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb_minitable.c +62 -69
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb_minitable.h +1 -3
- data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb.h +53 -22
- data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb_minitable.c +9 -7
- data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb.h +108 -0
- data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb_minitable.c +26 -2
- data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb_minitable.h +1 -0
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb.h +809 -231
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.c +183 -77
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.h +3 -0
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb.h +151 -26
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb_minitable.c +17 -9
- data/src/core/ext/upb-gen/envoy/config/trace/v3/zipkin.upb.h +24 -8
- data/src/core/ext/upb-gen/envoy/config/trace/v3/zipkin.upb_minitable.c +6 -5
- data/src/core/ext/upb-gen/envoy/data/accesslog/v3/accesslog.upb.h +2 -1
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/composite/v3/composite.upb.h +224 -16
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/composite/v3/composite.upb_minitable.c +83 -10
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/composite/v3/composite.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb.h +95 -79
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.c +23 -22
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb.h +34 -18
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb_minitable.c +10 -9
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb.h +243 -2
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.c +53 -5
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upb_minitable.h +3 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb.h +53 -22
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb_minitable.c +9 -7
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb.h +23 -7
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb_minitable.c +9 -4
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +516 -215
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.c +99 -60
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.h +1 -0
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb.h +60 -28
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb_minitable.c +12 -10
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb.h +109 -0
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb_minitable.c +32 -2
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb_minitable.h +1 -0
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upb.h +37 -4
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upb_minitable.c +7 -4
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb.h +65 -47
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb_minitable.c +29 -12
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upb.h +20 -4
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upb_minitable.c +6 -3
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb.h +776 -88
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.c +195 -35
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.h +5 -0
- data/src/core/ext/upb-gen/envoy/type/matcher/v3/address.upb.h +23 -7
- data/src/core/ext/upb-gen/envoy/type/matcher/v3/address.upb_minitable.c +10 -3
- data/src/core/ext/upb-gen/envoy/type/matcher/v3/status_code_input.upb.h +44 -0
- data/src/core/ext/upb-gen/envoy/type/matcher/v3/status_code_input.upb_minitable.c +11 -2
- data/src/core/ext/upb-gen/envoy/type/matcher/v3/status_code_input.upb_minitable.h +1 -0
- data/src/core/ext/upb-gen/envoy/type/v3/scope.upb.h +218 -0
- data/src/core/ext/upb-gen/envoy/type/v3/scope.upb_minitable.c +70 -0
- data/src/core/ext/upb-gen/envoy/type/v3/scope.upb_minitable.h +31 -0
- data/src/core/ext/upb-gen/grpc/channelz/v1/channelz.upb.h +137 -73
- data/src/core/ext/upb-gen/grpc/channelz/v1/channelz.upb_minitable.c +45 -25
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/altscontext.upb.h +6 -6
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/altscontext.upb_minitable.c +4 -4
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/altscontext.upb_minitable.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/handshaker.upb.h +46 -26
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/handshaker.upb_minitable.c +17 -14
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/handshaker.upb_minitable.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/transport_security_common.upb.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/transport_security_common.upb_minitable.c +3 -3
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/gcp/transport_security_common.upb_minitable.h +5 -5
- data/src/core/ext/upb-gen/grpc/health/v1/health.upb.h +329 -0
- data/src/core/ext/upb-gen/grpc/health/v1/health.upb_minitable.c +128 -0
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/health/v1/health.upb_minitable.h +8 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lb/v1/load_balancer.upb.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lb/v1/load_balancer.upb_minitable.c +3 -3
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lb/v1/load_balancer.upb_minitable.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lookup/v1/rls.upb.h +185 -23
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lookup/v1/rls.upb_minitable.c +20 -12
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lookup/v1/rls.upb_minitable.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lookup/v1/rls_config.upb.h +58 -42
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lookup/v1/rls_config.upb_minitable.c +17 -12
- data/src/core/ext/upb-gen/{src/proto/grpc → grpc}/lookup/v1/rls_config.upb_minitable.h +5 -5
- data/src/core/ext/upbdefs-gen/envoy/admin/v3/clusters.upbdefs.c +30 -24
- data/src/core/ext/upbdefs-gen/envoy/admin/v3/server_info.upbdefs.c +166 -152
- data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +467 -422
- data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +15 -0
- data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +120 -110
- data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.c +912 -857
- data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/outlier_detection.upbdefs.c +26 -19
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/address.upbdefs.c +59 -54
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.c +356 -346
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_service.upbdefs.c +49 -37
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.c +599 -483
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.h +10 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_option.upbdefs.c +65 -49
- data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +165 -161
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.c +369 -327
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.h +5 -15
- data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/stats.upbdefs.c +129 -121
- data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.c +224 -204
- data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.c +2046 -1932
- data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.h +15 -0
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opentelemetry.upbdefs.c +70 -37
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/zipkin.upbdefs.c +7 -3
- data/src/core/ext/upbdefs-gen/envoy/data/accesslog/v3/accesslog.upbdefs.c +5 -3
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/composite/v3/composite.upbdefs.c +121 -78
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/composite/v3/composite.upbdefs.h +10 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.c +165 -160
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +121 -118
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c +68 -37
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h +15 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.c +48 -40
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.c +44 -37
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +919 -870
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upbdefs.c +26 -14
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +44 -36
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +372 -371
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upbdefs.c +32 -28
- data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/address.upbdefs.c +17 -15
- data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/status_code_input.upbdefs.c +4 -1
- data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/status_code_input.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/type/v3/scope.upbdefs.c +76 -0
- data/src/core/ext/upbdefs-gen/envoy/type/v3/scope.upbdefs.h +37 -0
- data/src/core/ext/upbdefs-gen/envoy/type/v3/token_bucket.upbdefs.c +1 -1
- data/src/core/ext/upbdefs-gen/grpc/channelz/v1/channelz.upbdefs.c +567 -549
- data/src/core/ext/upbdefs-gen/grpc/lookup/v1/rls_config.upbdefs.c +182 -0
- data/src/core/ext/upbdefs-gen/{src/proto/grpc → grpc}/lookup/v1/rls_config.upbdefs.h +14 -14
- data/src/core/filter/ext_proc/ext_proc_filter.cc +1883 -48
- data/src/core/filter/ext_proc/ext_proc_filter.h +88 -22
- data/src/core/filter/ext_proc/ext_proc_messages.cc +141 -65
- data/src/core/filter/ext_proc/ext_proc_messages.h +55 -16
- data/src/core/filter/filter_args.h +5 -60
- data/src/core/handshaker/handshaker.cc +4 -4
- data/src/core/handshaker/http_connect/http_connect_client_handshaker.cc +4 -4
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +33 -32
- data/src/core/handshaker/security/secure_endpoint.cc +29 -29
- data/src/core/handshaker/security/security_handshaker.cc +6 -6
- data/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc +4 -4
- data/src/core/lib/channel/channel_args.cc +20 -0
- data/src/core/lib/channel/channel_args.h +17 -17
- data/src/core/lib/channel/channel_stack.cc +0 -12
- data/src/core/lib/channel/channel_stack.h +0 -8
- data/src/core/lib/channel/promise_based_filter.cc +59 -46
- data/src/core/lib/channel/promise_based_filter.h +94 -67
- data/src/core/lib/debug/trace_flags.cc +2 -0
- data/src/core/lib/debug/trace_flags.h +1 -0
- data/src/core/lib/event_engine/ares_resolver.cc +24 -18
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +7 -7
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +4 -4
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +1 -1
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +3 -3
- data/src/core/lib/event_engine/default_event_engine.cc +5 -5
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +10 -14
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +26 -26
- data/src/core/lib/event_engine/posix_engine/file_descriptor_collection.cc +8 -22
- data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +24 -4
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +6 -6
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +7 -7
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +27 -29
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +3 -3
- data/src/core/lib/event_engine/posix_engine/posix_interface.h +1 -1
- data/src/core/lib/event_engine/posix_engine/timer.cc +7 -7
- data/src/core/lib/event_engine/posix_engine/timer_manager.cc +5 -5
- data/src/core/lib/event_engine/posix_engine/traced_buffer_list.cc +3 -3
- data/src/core/lib/event_engine/posix_engine/traced_buffer_list.h +1 -1
- data/src/core/lib/event_engine/shim.cc +1 -6
- data/src/core/lib/event_engine/shim.h +0 -5
- data/src/core/lib/event_engine/thread_pool/thread_count.cc +1 -1
- data/src/core/lib/event_engine/thread_pool/thread_count.h +3 -3
- data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +50 -21
- data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.cc +3 -3
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +3 -3
- data/src/core/lib/event_engine/windows/windows_engine.cc +19 -19
- data/src/core/lib/event_engine/windows/windows_listener.cc +7 -7
- data/src/core/lib/event_engine/work_queue/basic_work_queue.cc +6 -6
- data/src/core/lib/experiments/experiments.cc +177 -246
- data/src/core/lib/experiments/experiments.h +61 -109
- data/src/core/lib/iomgr/buffer_list.cc +3 -3
- data/src/core/lib/iomgr/buffer_list.h +1 -1
- data/src/core/lib/iomgr/combiner.cc +0 -1
- data/src/core/lib/iomgr/ev_apple.cc +4 -4
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +2 -2
- data/src/core/lib/iomgr/iomgr_windows.cc +1 -6
- data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
- data/src/core/lib/iomgr/tcp_posix.cc +28 -28
- data/src/core/lib/iomgr/tcp_server_posix.cc +64 -242
- data/src/core/lib/iomgr/tcp_server_windows.cc +0 -469
- data/src/core/lib/promise/activity.cc +9 -9
- data/src/core/lib/promise/activity.h +6 -6
- data/src/core/lib/promise/arena_promise.h +7 -7
- data/src/core/lib/promise/detail/promise_factory.h +8 -8
- data/src/core/lib/promise/detail/promise_like.h +4 -4
- data/src/core/lib/promise/inter_activity_latch.h +6 -6
- data/src/core/lib/promise/inter_activity_pipe.h +4 -4
- data/src/core/lib/promise/observable.h +3 -3
- data/src/core/lib/promise/party.cc +6 -6
- data/src/core/lib/promise/status_flag.h +7 -2
- data/src/core/lib/promise/try_seq.h +2 -2
- data/src/core/lib/resource_quota/arena.h +3 -3
- data/src/core/lib/resource_quota/memory_quota.cc +18 -18
- data/src/core/lib/resource_quota/memory_quota.h +1 -1
- data/src/core/lib/resource_quota/thread_quota.cc +3 -3
- data/src/core/lib/security/authorization/audit_logging.cc +5 -5
- data/src/core/lib/security/authorization/authorization_engine.h +1 -1
- data/src/core/lib/security/authorization/grpc_authorization_engine.h +1 -1
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -1
- data/src/core/lib/security/authorization/grpc_server_authz_filter.h +1 -1
- data/src/core/lib/security/authorization/matchers.h +1 -1
- data/src/core/lib/security/authorization/rbac_policy.h +2 -2
- data/src/core/lib/surface/call.cc +20 -9
- data/src/core/lib/surface/call.h +24 -7
- data/src/core/lib/surface/call_utils.h +4 -0
- data/src/core/lib/surface/channel.cc +1 -1
- data/src/core/lib/surface/channel.h +1 -1
- data/src/core/lib/surface/channel_create.cc +7 -1
- data/src/core/lib/surface/channel_init.cc +1 -1
- data/src/core/lib/surface/channel_init.h +1 -8
- data/src/core/lib/surface/filter_stack_call.cc +16 -0
- data/src/core/lib/surface/filter_stack_call.h +1 -0
- data/src/core/lib/surface/init.cc +10 -10
- data/src/core/lib/surface/lame_client.cc +1 -1
- data/src/core/lib/surface/legacy_channel.cc +6 -3
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/transport.cc +15 -8
- data/src/core/lib/transport/transport_framing_endpoint_extension.h +9 -3
- data/src/core/load_balancing/autosharding/autosharding.cc +931 -0
- data/src/core/load_balancing/autosharding/autosharding.h +78 -0
- data/src/core/load_balancing/grpclb/grpclb_client_stats.cc +2 -2
- data/src/core/load_balancing/grpclb/load_balancer_api.cc +1 -1
- data/src/core/load_balancing/grpclb/load_balancer_api.h +3 -1
- data/src/core/load_balancing/health_check_client.cc +7 -7
- data/src/core/load_balancing/lb_policy.cc +1 -1
- data/src/core/load_balancing/oob_backend_metric.cc +5 -5
- data/src/core/load_balancing/outlier_detection/outlier_detection.cc +101 -10
- data/src/core/load_balancing/outlier_detection/outlier_detection_metrics.cc +38 -0
- data/src/core/load_balancing/outlier_detection/outlier_detection_metrics.h +55 -0
- data/src/core/load_balancing/ring_hash/ring_hash.cc +111 -38
- data/src/core/load_balancing/rls/rls.cc +44 -18
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +10 -10
- data/src/core/load_balancing/xds/cds.cc +10 -56
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +2 -2
- data/src/core/load_balancing/xds/xds_override_host.cc +10 -10
- data/src/core/mitigation_engine/mitigation_engine.h +28 -4
- data/src/core/plugin_registry/grpc_plugin_registry.cc +12 -13
- data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +0 -7
- data/src/core/resolver/dns/dns_resolver.cc +7 -7
- data/src/core/resolver/fake/fake_resolver.cc +5 -5
- data/src/core/resolver/google_c2p/google_c2p_resolver.cc +38 -30
- data/src/core/resolver/xds/xds_resolver.cc +1 -1
- data/src/core/server/server.cc +88 -32
- data/src/core/server/server.h +4 -3
- data/src/core/server/server_config_selector.h +4 -18
- data/src/core/server/server_config_selector_filter.cc +20 -146
- data/src/core/server/server_config_selector_filter.h +2 -2
- data/src/core/server/xds_server_config_fetcher.cc +5 -20
- data/src/core/telemetry/default_tcp_tracer.cc +1 -1
- data/src/core/telemetry/instrument.cc +30 -16
- data/src/core/telemetry/instrument.h +3 -3
- data/src/core/transport/auth_context.cc +15 -5
- data/src/core/transport/auth_context.h +5 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +4 -4
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +2 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +1 -1
- data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
- data/src/core/tsi/ssl/key_logging/ssl_key_logging.cc +5 -5
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +3 -3
- data/src/core/tsi/ssl_telemetry_utils.cc +9 -1
- data/src/core/tsi/ssl_transport_security.cc +203 -64
- data/src/core/tsi/ssl_transport_security.h +25 -2
- data/src/core/tsi/ssl_transport_security_utils.cc +139 -18
- data/src/core/tsi/ssl_transport_security_utils.h +19 -0
- data/src/core/util/event_log.cc +3 -3
- data/src/core/util/http_client/httpcli.cc +5 -5
- data/src/core/util/http_client/httpcli.h +1 -1
- data/src/core/util/json/json_object_loader.cc +7 -0
- data/src/core/util/json/json_object_loader.h +17 -2
- data/src/core/util/latent_see.cc +188 -39
- data/src/core/util/latent_see.h +71 -13
- data/src/core/util/linux/cpu.cc +12 -6
- data/src/core/util/mpscq.cc +3 -3
- data/src/core/util/notification.h +4 -4
- data/src/core/util/sync.h +20 -6
- data/src/core/util/sync_abseil.cc +3 -3
- data/src/core/util/table.h +20 -22
- data/src/core/util/trie_lookup.h +5 -1
- data/src/core/util/windows/env.cc +1 -0
- data/src/core/util/work_serializer.cc +3 -3
- data/src/core/xds/grpc/blackboard.cc +4 -3
- data/src/core/xds/grpc/certificate_provider_store.cc +2 -2
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +10 -9
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +3 -3
- data/src/core/xds/grpc/streaming_call_promise_wrapper.cc +184 -0
- data/src/core/xds/grpc/streaming_call_promise_wrapper.h +210 -0
- data/src/core/xds/grpc/xds_audit_logger_registry.cc +0 -54
- data/src/core/xds/grpc/xds_audit_logger_registry.h +0 -8
- data/src/core/xds/grpc/xds_bootstrap_grpc_builder.cc +4 -30
- data/src/core/xds/grpc/xds_bootstrap_grpc_builder.h +0 -20
- data/src/core/xds/grpc/xds_client_grpc.cc +12 -12
- data/src/core/xds/grpc/xds_client_grpc.h +1 -1
- data/src/core/xds/grpc/xds_cluster_parser.cc +5 -1
- data/src/core/xds/grpc/xds_cluster_specifier_plugin.cc +2 -2
- data/src/core/xds/grpc/xds_common_types_parser.cc +12 -0
- data/src/core/xds/grpc/xds_endpoint.cc +1 -1
- data/src/core/xds/grpc/xds_endpoint_parser.cc +14 -3
- data/src/core/xds/grpc/xds_grpc_service_parser.cc +12 -10
- data/src/core/xds/grpc/xds_http_composite_filter.cc +0 -5
- data/src/core/xds/grpc/xds_http_composite_filter.h +1 -27
- data/src/core/xds/grpc/xds_http_ext_proc_filter.cc +18 -19
- data/src/core/xds/grpc/xds_http_ext_proc_filter.h +3 -29
- data/src/core/xds/grpc/xds_http_fault_filter.cc +0 -4
- data/src/core/xds/grpc/xds_http_fault_filter.h +0 -26
- data/src/core/xds/grpc/xds_http_filter.h +1 -63
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +0 -5
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +1 -27
- data/src/core/xds/grpc/xds_http_rbac_filter.cc +0 -527
- data/src/core/xds/grpc/xds_http_rbac_filter.h +0 -15
- data/src/core/xds/grpc/xds_http_stateful_session_filter.cc +0 -5
- data/src/core/xds/grpc/xds_http_stateful_session_filter.h +0 -26
- data/src/core/xds/grpc/xds_listener.cc +0 -2
- data/src/core/xds/grpc/xds_listener.h +0 -2
- data/src/core/xds/grpc/xds_listener_parser.cc +0 -7
- data/src/core/xds/grpc/xds_matcher.cc +17 -11
- data/src/core/xds/grpc/xds_matcher.h +4 -3
- data/src/core/xds/grpc/xds_matcher_context.cc +11 -0
- data/src/core/xds/grpc/xds_matcher_context.h +3 -2
- data/src/core/xds/grpc/xds_matcher_input.cc +19 -1
- data/src/core/xds/grpc/xds_matcher_parse.cc +3 -2
- data/src/core/xds/grpc/xds_route_config.cc +0 -2
- data/src/core/xds/grpc/xds_route_config.h +0 -2
- data/src/core/xds/grpc/xds_route_config_parser.cc +0 -5
- data/src/core/xds/grpc/xds_routing.cc +22 -112
- data/src/core/xds/grpc/xds_routing.h +2 -27
- data/src/core/xds/grpc/xds_transport_factory_grpc.cc +236 -0
- data/src/core/xds/grpc/xds_transport_factory_grpc.h +95 -0
- data/src/core/xds/grpc/xds_transport_grpc.cc +176 -299
- data/src/core/xds/grpc/xds_transport_grpc.h +60 -55
- data/src/core/xds/xds_client/lrs_client.cc +23 -22
- data/src/core/xds/xds_client/lrs_client.h +2 -1
- data/src/core/xds/xds_client/xds_client.cc +53 -37
- data/src/core/xds/xds_client/xds_client.h +6 -5
- data/src/core/xds/xds_client/xds_transport.h +113 -65
- data/src/core/xds/xds_client/xds_transport_factory.h +43 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +9 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/README.md +1 -1
- data/src/ruby/pb/generate_proto_ruby.sh +1 -1
- data/third_party/abseil-cpp/absl/algorithm/algorithm.h +34 -2
- data/third_party/abseil-cpp/absl/algorithm/container.h +345 -147
- data/third_party/abseil-cpp/absl/base/attributes.h +67 -44
- data/third_party/abseil-cpp/absl/base/call_once.h +1 -0
- data/third_party/abseil-cpp/absl/base/casts.cc +61 -0
- data/third_party/abseil-cpp/absl/base/casts.h +135 -2
- data/third_party/abseil-cpp/absl/base/config.h +63 -41
- data/third_party/abseil-cpp/absl/base/fast_type_id.h +30 -2
- data/third_party/abseil-cpp/absl/base/internal/dynamic_annotations.h +1 -1
- data/third_party/abseil-cpp/absl/base/internal/hardening.h +136 -0
- data/third_party/abseil-cpp/absl/base/internal/iterator_traits.h +6 -2
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +39 -4
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +6 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +77 -15
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +3 -4
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +26 -24
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +74 -29
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +1 -11
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +52 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +5 -1
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +5 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock_config.h +1 -1
- data/third_party/abseil-cpp/absl/base/macros.h +76 -37
- data/third_party/abseil-cpp/absl/base/nullability.h +5 -5
- data/third_party/abseil-cpp/absl/base/optimization.h +4 -5
- data/third_party/abseil-cpp/absl/base/options.h +46 -18
- data/third_party/abseil-cpp/absl/base/policy_checks.h +5 -5
- data/third_party/abseil-cpp/absl/base/{internal/throw_delegate.cc → throw_delegate.cc} +9 -7
- data/third_party/abseil-cpp/absl/base/{internal/throw_delegate.h → throw_delegate.h} +4 -14
- data/third_party/abseil-cpp/absl/cleanup/cleanup.h +7 -2
- data/third_party/abseil-cpp/absl/cleanup/internal/cleanup.h +3 -2
- data/third_party/abseil-cpp/absl/container/btree_map.h +60 -10
- data/third_party/abseil-cpp/absl/container/btree_set.h +61 -15
- data/third_party/abseil-cpp/absl/container/fixed_array.h +19 -21
- data/third_party/abseil-cpp/absl/container/flat_hash_map.h +49 -27
- data/third_party/abseil-cpp/absl/container/flat_hash_set.h +50 -26
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +42 -36
- data/third_party/abseil-cpp/absl/container/internal/btree.h +32 -24
- data/third_party/abseil-cpp/absl/container/internal/btree_container.h +30 -22
- data/third_party/abseil-cpp/absl/container/internal/common.h +57 -5
- data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +1 -1
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +40 -36
- data/third_party/abseil-cpp/absl/container/internal/container_memory.h +119 -39
- data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +14 -2
- data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +14 -22
- data/third_party/abseil-cpp/absl/container/internal/hashtable_control_bytes.h +52 -52
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +7 -7
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +7 -7
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +32 -40
- data/third_party/abseil-cpp/absl/container/internal/layout.h +13 -13
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +95 -72
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +633 -365
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1016 -749
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set_resize_impl.h +0 -1
- data/third_party/abseil-cpp/absl/container/node_hash_map.h +58 -35
- data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.cc +23 -6
- data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.h +7 -1
- data/third_party/abseil-cpp/absl/crc/internal/crc.cc +4 -6
- data/third_party/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +41 -0
- data/third_party/abseil-cpp/absl/crc/internal/crc_internal.h +0 -16
- data/third_party/abseil-cpp/absl/crc/internal/crc_memcpy_x86_arm_combined.cc +5 -0
- data/third_party/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +304 -188
- data/third_party/abseil-cpp/absl/crc/internal/non_temporal_arm_intrinsics.h +4 -2
- data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +2 -2
- data/third_party/abseil-cpp/absl/debugging/internal/demangle_rust.h +8 -0
- data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +4 -4
- data/third_party/abseil-cpp/absl/debugging/internal/examine_stack.cc +15 -1
- data/third_party/abseil-cpp/absl/debugging/internal/examine_stack.h +7 -1
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +12 -1
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +6 -5
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_emscripten-inl.inc +13 -11
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +14 -7
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +3 -2
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_riscv-inl.inc +6 -1
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +14 -8
- data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +48 -38
- data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +4 -0
- data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +63 -118
- data/third_party/abseil-cpp/absl/debugging/stacktrace.h +7 -47
- data/third_party/abseil-cpp/absl/debugging/symbolize.cc +20 -2
- data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +83 -149
- data/third_party/abseil-cpp/absl/debugging/symbolize_emscripten.inc +4 -17
- data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +4 -4
- data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +2 -4
- data/third_party/abseil-cpp/absl/flags/commandlineflag.h +8 -6
- data/third_party/abseil-cpp/absl/flags/declare.h +9 -0
- data/third_party/abseil-cpp/absl/flags/flag.h +2 -1
- data/third_party/abseil-cpp/absl/flags/internal/commandlineflag.h +1 -1
- data/third_party/abseil-cpp/absl/flags/internal/flag.cc +19 -18
- data/third_party/abseil-cpp/absl/flags/internal/flag.h +33 -34
- data/third_party/abseil-cpp/absl/flags/internal/program_name.cc +2 -2
- data/third_party/abseil-cpp/absl/flags/marshalling.cc +1 -16
- data/third_party/abseil-cpp/absl/flags/marshalling.h +2 -28
- data/third_party/abseil-cpp/absl/flags/reflection.cc +11 -7
- data/third_party/abseil-cpp/absl/flags/usage_config.cc +2 -2
- data/third_party/abseil-cpp/absl/functional/any_invocable.h +22 -19
- data/third_party/abseil-cpp/absl/functional/bind_front.h +7 -1
- data/third_party/abseil-cpp/absl/functional/function_ref.h +125 -20
- data/third_party/abseil-cpp/absl/functional/internal/any_invocable.h +43 -31
- data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +4 -4
- data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +44 -6
- data/third_party/abseil-cpp/absl/hash/hash.h +1 -1
- data/third_party/abseil-cpp/absl/hash/internal/city.cc +39 -51
- data/third_party/abseil-cpp/absl/hash/internal/hash.cc +379 -14
- data/third_party/abseil-cpp/absl/hash/internal/hash.h +457 -353
- data/third_party/abseil-cpp/absl/log/absl_vlog_is_on.h +0 -2
- data/third_party/abseil-cpp/absl/log/internal/check_impl.h +2 -1
- data/third_party/abseil-cpp/absl/log/internal/check_op.cc +4 -0
- data/third_party/abseil-cpp/absl/log/internal/check_op.h +128 -50
- data/third_party/abseil-cpp/absl/log/internal/conditions.h +38 -35
- data/third_party/abseil-cpp/absl/log/internal/log_impl.h +108 -110
- data/third_party/abseil-cpp/absl/log/internal/log_message.cc +10 -6
- data/third_party/abseil-cpp/absl/log/internal/log_message.h +19 -1
- data/third_party/abseil-cpp/absl/log/internal/log_sink_set.cc +4 -4
- data/third_party/abseil-cpp/absl/log/internal/nullstream.h +1 -1
- data/third_party/abseil-cpp/absl/log/internal/proto.cc +13 -0
- data/third_party/abseil-cpp/absl/log/internal/strip.h +30 -31
- data/third_party/abseil-cpp/absl/log/internal/structured_proto.cc +5 -5
- data/third_party/abseil-cpp/absl/log/internal/structured_proto.h +6 -5
- data/third_party/abseil-cpp/absl/log/internal/vlog_config.cc +30 -30
- data/third_party/abseil-cpp/absl/log/internal/vlog_config.h +0 -1
- data/third_party/abseil-cpp/absl/log/log.h +2 -2
- data/third_party/abseil-cpp/absl/log/log_entry.cc +263 -0
- data/third_party/abseil-cpp/absl/log/log_entry.h +2 -0
- data/third_party/abseil-cpp/absl/log/vlog_is_on.h +0 -2
- data/third_party/abseil-cpp/absl/memory/memory.h +55 -5
- data/third_party/abseil-cpp/absl/meta/type_traits.h +161 -56
- data/third_party/abseil-cpp/absl/numeric/int128.h +41 -21
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +16 -22
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +5 -7
- data/third_party/abseil-cpp/absl/numeric/internal/bits.h +32 -4
- data/third_party/abseil-cpp/absl/profiling/internal/sample_recorder.h +9 -9
- data/third_party/abseil-cpp/absl/random/beta_distribution.h +2 -2
- data/third_party/abseil-cpp/absl/random/bit_gen_ref.h +26 -53
- data/third_party/abseil-cpp/absl/random/discrete_distribution.h +1 -1
- data/third_party/abseil-cpp/absl/random/distributions.h +17 -17
- data/third_party/abseil-cpp/absl/random/exponential_distribution.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +8 -21
- data/third_party/abseil-cpp/absl/random/internal/entropy_pool.cc +2 -2
- data/third_party/abseil-cpp/absl/random/internal/fast_uniform_bits.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/generate_real.h +1 -1
- data/third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h +2 -2
- data/third_party/abseil-cpp/absl/random/internal/nonsecure_base.h +2 -2
- data/third_party/abseil-cpp/absl/random/internal/pcg_engine.h +6 -6
- data/third_party/abseil-cpp/absl/random/internal/platform.h +0 -13
- data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +6 -6
- data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +2 -2
- data/third_party/abseil-cpp/absl/random/internal/salted_seed_seq.h +6 -5
- data/third_party/abseil-cpp/absl/random/internal/seed_material.cc +5 -31
- data/third_party/abseil-cpp/absl/random/internal/seed_material.h +2 -1
- data/third_party/abseil-cpp/absl/random/internal/traits.h +21 -0
- data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +23 -23
- data/third_party/abseil-cpp/absl/random/mocking_access.h +74 -0
- data/third_party/abseil-cpp/absl/random/uniform_real_distribution.h +1 -1
- data/third_party/abseil-cpp/absl/status/internal/status_internal.cc +63 -18
- data/third_party/abseil-cpp/absl/status/internal/status_internal.h +30 -4
- data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +225 -63
- data/third_party/abseil-cpp/absl/status/status.cc +66 -70
- data/third_party/abseil-cpp/absl/status/status.h +254 -23
- data/third_party/abseil-cpp/absl/status/status_payload_printer.h +3 -2
- data/third_party/abseil-cpp/absl/status/statusor.h +117 -137
- data/third_party/abseil-cpp/absl/strings/ascii.h +10 -6
- data/third_party/abseil-cpp/absl/strings/cord.cc +41 -17
- data/third_party/abseil-cpp/absl/strings/cord.h +26 -17
- data/third_party/abseil-cpp/absl/strings/cord_buffer.h +4 -2
- data/third_party/abseil-cpp/absl/strings/escaping.cc +305 -125
- data/third_party/abseil-cpp/absl/strings/escaping.h +12 -2
- data/third_party/abseil-cpp/absl/strings/internal/append_and_overwrite.h +93 -0
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/cordz_handle.cc +6 -6
- data/third_party/abseil-cpp/absl/strings/internal/cordz_info.cc +27 -21
- data/third_party/abseil-cpp/absl/strings/internal/cordz_info.h +11 -19
- data/third_party/abseil-cpp/absl/strings/internal/damerau_levenshtein_distance.cc +6 -0
- data/third_party/abseil-cpp/absl/strings/internal/damerau_levenshtein_distance.h +1 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +0 -141
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +2 -24
- data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +31 -36
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +39 -39
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +14 -22
- data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +2 -4
- data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +921 -231
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +18 -16
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +16 -12
- data/third_party/abseil-cpp/absl/strings/internal/stringify_sink.h +12 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +477 -8
- data/third_party/abseil-cpp/absl/strings/numbers.h +29 -12
- data/third_party/abseil-cpp/absl/strings/resize_and_overwrite.h +198 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +96 -91
- data/third_party/abseil-cpp/absl/strings/str_cat.h +53 -13
- data/third_party/abseil-cpp/absl/strings/str_split.h +14 -9
- data/third_party/abseil-cpp/absl/strings/string_view.h +10 -716
- data/third_party/abseil-cpp/absl/strings/substitute.cc +24 -24
- data/third_party/abseil-cpp/absl/strings/substitute.h +2 -2
- data/third_party/abseil-cpp/absl/synchronization/barrier.cc +1 -1
- data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +2 -2
- data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +24 -3
- data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +30 -33
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +2 -2
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +5 -0
- data/third_party/abseil-cpp/absl/synchronization/mutex.cc +41 -29
- data/third_party/abseil-cpp/absl/synchronization/mutex.h +199 -94
- data/third_party/abseil-cpp/absl/synchronization/notification.cc +5 -5
- data/third_party/abseil-cpp/absl/synchronization/notification.h +1 -1
- data/third_party/abseil-cpp/absl/time/clock.cc +29 -30
- data/third_party/abseil-cpp/absl/time/clock.h +3 -0
- data/third_party/abseil-cpp/absl/time/duration.cc +2 -2
- data/third_party/abseil-cpp/absl/time/format.cc +3 -10
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +12 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +131 -91
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +6 -103
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_name_win.cc +185 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_name_win.h +37 -0
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +10 -15
- data/third_party/abseil-cpp/absl/time/time.cc +4 -4
- data/third_party/abseil-cpp/absl/time/time.h +14 -13
- data/third_party/abseil-cpp/absl/types/compare.h +64 -63
- data/third_party/abseil-cpp/absl/types/internal/span.h +6 -6
- data/third_party/abseil-cpp/absl/types/optional.h +31 -4
- data/third_party/abseil-cpp/absl/types/optional_ref.h +295 -0
- data/third_party/{boringssl-with-bazel/crypto/x509/x_val.cc → abseil-cpp/absl/types/source_location.cc} +4 -14
- data/third_party/abseil-cpp/absl/types/source_location.h +172 -0
- data/third_party/abseil-cpp/absl/types/span.h +67 -38
- data/third_party/abseil-cpp/absl/types/variant.h +75 -18
- data/third_party/abseil-cpp/absl/utility/utility.h +112 -16
- data/third_party/boringssl-with-bazel/crypto/aes/aes.cc +3 -0
- data/third_party/boringssl-with-bazel/crypto/armv8_feature_parsing.h +67 -0
- data/third_party/boringssl-with-bazel/crypto/asn1/a_bitstr.cc +143 -105
- data/third_party/boringssl-with-bazel/crypto/asn1/a_bool.cc +5 -8
- data/third_party/boringssl-with-bazel/crypto/asn1/a_d2i_fp.cc +3 -3
- data/third_party/boringssl-with-bazel/crypto/asn1/a_dup.cc +6 -6
- data/third_party/boringssl-with-bazel/crypto/asn1/a_gentm.cc +33 -12
- data/third_party/boringssl-with-bazel/crypto/asn1/a_i2d_fp.cc +7 -6
- data/third_party/boringssl-with-bazel/crypto/asn1/a_int.cc +80 -52
- data/third_party/boringssl-with-bazel/crypto/asn1/a_mbstr.cc +7 -4
- data/third_party/boringssl-with-bazel/crypto/asn1/a_object.cc +70 -72
- data/third_party/boringssl-with-bazel/crypto/asn1/a_strex.cc +38 -42
- data/third_party/boringssl-with-bazel/crypto/asn1/a_strnid.cc +41 -39
- data/third_party/boringssl-with-bazel/crypto/asn1/a_time.cc +59 -35
- data/third_party/boringssl-with-bazel/crypto/asn1/a_type.cc +325 -30
- data/third_party/boringssl-with-bazel/crypto/asn1/a_utctm.cc +32 -13
- data/third_party/boringssl-with-bazel/crypto/asn1/asn1_lib.cc +129 -31
- data/third_party/boringssl-with-bazel/crypto/asn1/asn_pack.cc +10 -10
- data/third_party/boringssl-with-bazel/crypto/asn1/f_int.cc +1 -1
- data/third_party/boringssl-with-bazel/crypto/asn1/f_string.cc +1 -1
- data/third_party/boringssl-with-bazel/crypto/asn1/internal.h +307 -115
- data/third_party/boringssl-with-bazel/crypto/asn1/posix_time.cc +8 -5
- data/third_party/boringssl-with-bazel/crypto/asn1/tasn_dec.cc +376 -728
- data/third_party/boringssl-with-bazel/crypto/asn1/tasn_enc.cc +215 -528
- data/third_party/boringssl-with-bazel/crypto/asn1/tasn_fre.cc +30 -31
- data/third_party/boringssl-with-bazel/crypto/asn1/tasn_new.cc +50 -52
- data/third_party/boringssl-with-bazel/crypto/asn1/tasn_typ.cc +18 -6
- data/third_party/boringssl-with-bazel/crypto/asn1/tasn_utl.cc +63 -74
- data/third_party/boringssl-with-bazel/crypto/base64/base64.cc +14 -15
- data/third_party/boringssl-with-bazel/crypto/bcm_support.h +7 -29
- data/third_party/boringssl-with-bazel/crypto/bio/bio.cc +234 -177
- data/third_party/boringssl-with-bazel/crypto/bio/bio_mem.cc +78 -86
- data/third_party/boringssl-with-bazel/crypto/bio/connect.cc +154 -200
- data/third_party/boringssl-with-bazel/crypto/bio/errno.cc +3 -1
- data/third_party/boringssl-with-bazel/crypto/bio/fd.cc +55 -55
- data/third_party/boringssl-with-bazel/crypto/bio/file.cc +69 -78
- data/third_party/boringssl-with-bazel/crypto/bio/hexdump.cc +6 -4
- data/third_party/boringssl-with-bazel/crypto/bio/internal.h +69 -18
- data/third_party/boringssl-with-bazel/crypto/bio/pair.cc +116 -136
- data/third_party/boringssl-with-bazel/crypto/bio/printf.cc +1 -1
- data/third_party/boringssl-with-bazel/crypto/bio/socket.cc +116 -50
- data/third_party/boringssl-with-bazel/crypto/bio/socket_helper.cc +53 -5
- data/third_party/boringssl-with-bazel/crypto/blake2/blake2.cc +9 -5
- data/third_party/boringssl-with-bazel/crypto/bn/bn_asn1.cc +2 -2
- data/third_party/boringssl-with-bazel/crypto/bn/convert.cc +56 -70
- data/third_party/boringssl-with-bazel/crypto/bn/div.cc +102 -0
- data/third_party/boringssl-with-bazel/crypto/bn/exponentiation.cc +26 -42
- data/third_party/boringssl-with-bazel/crypto/bn/sqrt.cc +93 -0
- data/third_party/boringssl-with-bazel/crypto/buf/buf.cc +6 -5
- data/third_party/boringssl-with-bazel/crypto/bytestring/asn1_compat.cc +6 -5
- data/third_party/boringssl-with-bazel/crypto/bytestring/ber.cc +22 -20
- data/third_party/boringssl-with-bazel/crypto/bytestring/cbb.cc +182 -97
- data/third_party/boringssl-with-bazel/crypto/bytestring/cbs.cc +114 -49
- data/third_party/boringssl-with-bazel/crypto/bytestring/internal.h +84 -24
- data/third_party/boringssl-with-bazel/crypto/bytestring/unicode.cc +2 -2
- data/third_party/boringssl-with-bazel/crypto/chacha/chacha.cc +5 -3
- data/third_party/boringssl-with-bazel/crypto/chacha/internal.h +23 -22
- data/third_party/boringssl-with-bazel/crypto/cipher/derive_key.cc +14 -18
- data/third_party/boringssl-with-bazel/crypto/cipher/e_aesctrhmac.cc +73 -58
- data/third_party/boringssl-with-bazel/crypto/cipher/e_aeseax.cc +132 -70
- data/third_party/boringssl-with-bazel/crypto/cipher/e_aesgcmsiv.cc +363 -367
- data/third_party/boringssl-with-bazel/crypto/cipher/e_chacha20poly1305.cc +200 -137
- data/third_party/boringssl-with-bazel/crypto/cipher/e_des.cc +45 -29
- data/third_party/boringssl-with-bazel/crypto/cipher/e_null.cc +9 -5
- data/third_party/boringssl-with-bazel/crypto/cipher/e_rc2.cc +43 -28
- data/third_party/boringssl-with-bazel/crypto/cipher/e_rc4.cc +7 -5
- data/third_party/boringssl-with-bazel/crypto/cipher/e_tls.cc +253 -237
- data/third_party/boringssl-with-bazel/crypto/cipher/get_cipher.cc +12 -12
- data/third_party/boringssl-with-bazel/crypto/cipher/internal.h +217 -58
- data/third_party/boringssl-with-bazel/crypto/cipher/tls_cbc.cc +111 -111
- data/third_party/boringssl-with-bazel/crypto/cms/cms.cc +48 -42
- data/third_party/boringssl-with-bazel/crypto/conf/conf.cc +69 -63
- data/third_party/boringssl-with-bazel/crypto/conf/internal.h +11 -12
- data/third_party/boringssl-with-bazel/crypto/cpu_aarch64_apple.cc +8 -5
- data/third_party/boringssl-with-bazel/crypto/cpu_aarch64_fuchsia.cc +6 -1
- data/third_party/boringssl-with-bazel/crypto/cpu_aarch64_linux.cc +7 -1
- data/third_party/boringssl-with-bazel/crypto/cpu_aarch64_openbsd.cc +7 -21
- data/third_party/boringssl-with-bazel/crypto/cpu_aarch64_sysreg.cc +15 -41
- data/third_party/boringssl-with-bazel/crypto/cpu_aarch64_win.cc +16 -3
- data/third_party/boringssl-with-bazel/crypto/cpu_arm_freebsd.cc +4 -2
- data/third_party/boringssl-with-bazel/crypto/cpu_arm_linux.cc +54 -31
- data/third_party/boringssl-with-bazel/crypto/cpu_arm_linux.h +79 -101
- data/third_party/boringssl-with-bazel/crypto/cpu_intel.cc +51 -45
- data/third_party/boringssl-with-bazel/crypto/crypto.cc +26 -55
- data/third_party/boringssl-with-bazel/crypto/curve25519/curve25519.cc +323 -41
- data/third_party/boringssl-with-bazel/crypto/curve25519/curve25519_tables.h +6 -6
- data/third_party/boringssl-with-bazel/crypto/curve25519/internal.h +39 -29
- data/third_party/boringssl-with-bazel/crypto/curve25519/spake25519.cc +23 -20
- data/third_party/boringssl-with-bazel/crypto/des/des.cc +27 -19
- data/third_party/boringssl-with-bazel/crypto/des/internal.h +4 -9
- data/third_party/boringssl-with-bazel/crypto/dh/dh_asn1.cc +34 -49
- data/third_party/boringssl-with-bazel/crypto/dh/params.cc +45 -42
- data/third_party/boringssl-with-bazel/crypto/digest/digest_extra.cc +87 -40
- data/third_party/boringssl-with-bazel/crypto/dsa/dsa.cc +237 -260
- data/third_party/boringssl-with-bazel/crypto/dsa/dsa_asn1.cc +100 -173
- data/third_party/boringssl-with-bazel/crypto/dsa/internal.h +23 -21
- data/third_party/boringssl-with-bazel/crypto/ec/ec_asn1.cc +181 -209
- data/third_party/boringssl-with-bazel/crypto/ec/ec_derive.cc +26 -28
- data/third_party/boringssl-with-bazel/crypto/ec/hash_to_curve.cc +459 -196
- data/third_party/boringssl-with-bazel/crypto/ec/internal.h +54 -18
- data/third_party/boringssl-with-bazel/crypto/ecdh/ecdh.cc +7 -5
- data/third_party/boringssl-with-bazel/crypto/ecdsa/ecdsa_asn1.cc +50 -70
- data/third_party/boringssl-with-bazel/crypto/ecdsa/ecdsa_p1363.cc +54 -0
- data/third_party/boringssl-with-bazel/crypto/engine/engine.cc +7 -7
- data/third_party/boringssl-with-bazel/crypto/err/err.cc +119 -107
- data/third_party/boringssl-with-bazel/crypto/err/internal.h +8 -21
- data/third_party/boringssl-with-bazel/crypto/evp/evp.cc +241 -166
- data/third_party/boringssl-with-bazel/crypto/evp/evp_asn1.cc +202 -234
- data/third_party/boringssl-with-bazel/crypto/evp/evp_ctx.cc +260 -159
- data/third_party/boringssl-with-bazel/crypto/evp/evp_kem.cc +101 -0
- data/third_party/boringssl-with-bazel/crypto/evp/internal.h +296 -137
- data/third_party/boringssl-with-bazel/crypto/evp/p_dh.cc +198 -25
- data/third_party/boringssl-with-bazel/crypto/evp/p_dsa.cc +333 -0
- data/third_party/boringssl-with-bazel/crypto/evp/p_ec.cc +548 -42
- data/third_party/boringssl-with-bazel/crypto/evp/p_ed25519.cc +270 -14
- data/third_party/boringssl-with-bazel/crypto/evp/p_hkdf.cc +70 -102
- data/third_party/boringssl-with-bazel/crypto/evp/p_mldsa.cc +549 -0
- data/third_party/boringssl-with-bazel/crypto/evp/p_mlkem.cc +510 -0
- data/third_party/boringssl-with-bazel/crypto/evp/p_rsa.cc +734 -158
- data/third_party/boringssl-with-bazel/crypto/evp/p_x25519.cc +290 -28
- data/third_party/boringssl-with-bazel/crypto/evp/p_xwing.cc +300 -0
- data/third_party/boringssl-with-bazel/crypto/evp/pbkdf.cc +14 -7
- data/third_party/boringssl-with-bazel/crypto/evp/print.cc +34 -89
- data/third_party/boringssl-with-bazel/crypto/evp/scrypt.cc +23 -21
- data/third_party/boringssl-with-bazel/crypto/evp/sign.cc +23 -42
- data/third_party/boringssl-with-bazel/crypto/ex_data.cc +40 -41
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/aes.cc.inc +34 -28
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/aes_nohw.cc.inc +120 -122
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/cbc.cc.inc +16 -14
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/cfb.cc.inc +12 -10
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/ctr.cc.inc +7 -5
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/gcm.cc.inc +41 -31
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/gcm_nohw.cc.inc +15 -13
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/internal.h +193 -177
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/key_wrap.cc.inc +5 -3
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/mode_wrappers.cc.inc +7 -3
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/aes/ofb.cc.inc +7 -5
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bcm.cc +24 -18
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bcm_interface.h +512 -384
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/add.cc.inc +16 -9
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/asm/x86_64-gcc.cc.inc +64 -45
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/bn.cc.inc +40 -37
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/bytes.cc.inc +27 -22
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/cmp.cc.inc +9 -7
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/ctx.cc.inc +62 -126
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/div.cc.inc +92 -167
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/div_extra.cc.inc +15 -12
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/exponentiation.cc.inc +98 -95
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/gcd.cc.inc +73 -92
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/gcd_extra.cc.inc +59 -71
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/generic.cc.inc +54 -57
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/internal.h +339 -255
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/jacobi.cc.inc +13 -20
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/montgomery.cc.inc +80 -95
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/montgomery_inv.cc.inc +55 -98
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/mul.cc.inc +58 -419
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/prime.cc.inc +167 -216
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/random.cc.inc +27 -26
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/rsaz_exp.cc.inc +18 -16
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/rsaz_exp.h +47 -49
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/shift.cc.inc +14 -17
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/bn/sqrt.cc.inc +40 -129
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/cipher/aead.cc.inc +429 -105
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/cipher/cipher.cc.inc +381 -216
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/cipher/e_aes.cc.inc +230 -225
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/cipher/e_aesccm.cc.inc +115 -84
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/cipher/internal.h +375 -27
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/cmac/cmac.cc.inc +28 -23
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/delocate.h +36 -40
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/dh/check.cc.inc +68 -78
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/dh/dh.cc.inc +157 -199
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/dh/internal.h +24 -24
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/digest/digest.cc.inc +40 -69
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/digest/digests.cc.inc +13 -7
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/digest/internal.h +13 -11
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/digest/md32_common.h +86 -81
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/digestsign/digestsign.cc.inc +38 -34
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/ec.cc.inc +254 -203
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/ec_key.cc.inc +196 -154
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/ec_montgomery.cc.inc +78 -138
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/felem.cc.inc +151 -5
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/internal.h +332 -289
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/oct.cc.inc +45 -166
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/p256-nistz.cc.inc +44 -45
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/p256-nistz.h +18 -18
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/p256.cc.inc +75 -246
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/scalar.cc.inc +44 -39
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/simple.cc.inc +73 -106
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/simple_mul.cc.inc +39 -34
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/util.cc.inc +6 -3
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/wnaf.cc.inc +23 -20
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ecdh/ecdh.cc.inc +6 -3
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ecdsa/ecdsa.cc.inc +48 -38
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ecdsa/internal.h +5 -10
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/entropy/internal.h +38 -0
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/entropy/jitter.cc.inc +463 -0
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/entropy/sha512.cc.inc +329 -0
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/fips_shared_support.cc +4 -4
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/hkdf/hkdf.cc.inc +8 -6
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/hmac/hmac.cc.inc +19 -16
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/keccak/internal.h +109 -14
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/keccak/keccak.cc.inc +424 -56
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/mldsa/fips_known_values.inc +5 -5
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/mldsa/mldsa.cc.inc +1796 -773
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/mlkem/fips_known_values.inc +5 -5
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/mlkem/mlkem.cc.inc +902 -443
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rand/android_entropy_client.cc.inc +82 -0
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rand/ctrdrbg.cc.inc +240 -53
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rand/internal.h +41 -26
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rand/rand.cc.inc +221 -218
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rsa/internal.h +64 -67
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rsa/padding.cc.inc +49 -57
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rsa/rsa.cc.inc +247 -234
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rsa/rsa_impl.cc.inc +395 -695
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/self_check/fips.cc.inc +10 -10
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/self_check/self_check.cc.inc +479 -449
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/service_indicator/internal.h +34 -11
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/service_indicator/service_indicator.cc.inc +46 -43
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/sha/internal.h +61 -70
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/sha/sha1.cc.inc +29 -15
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/sha/sha256.cc.inc +46 -30
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/sha/sha512.cc.inc +47 -47
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/address.h +98 -73
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/fors.cc.inc +108 -98
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/fors.h +14 -24
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/merkle.cc.inc +94 -91
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/merkle.h +19 -31
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/params.h +156 -56
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/slhdsa.cc.inc +318 -132
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/thash.cc.inc +234 -81
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/thash.h +20 -34
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/wots.cc.inc +97 -96
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/slhdsa/wots.h +10 -20
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/tls/internal.h +2 -16
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/tls/kdf.cc.inc +26 -26
- data/third_party/boringssl-with-bazel/crypto/fuzzer_mode.cc +5 -5
- data/third_party/boringssl-with-bazel/crypto/hpke/hpke.cc +531 -112
- data/third_party/boringssl-with-bazel/crypto/hrss/hrss.cc +165 -161
- data/third_party/boringssl-with-bazel/crypto/hrss/internal.h +9 -13
- data/third_party/boringssl-with-bazel/crypto/internal.h +594 -394
- data/third_party/boringssl-with-bazel/crypto/lhash/internal.h +38 -37
- data/third_party/boringssl-with-bazel/crypto/lhash/lhash.cc +68 -65
- data/third_party/boringssl-with-bazel/crypto/md4/md4.cc +19 -6
- data/third_party/boringssl-with-bazel/crypto/md5/internal.h +6 -9
- data/third_party/boringssl-with-bazel/crypto/md5/md5.cc +18 -6
- data/third_party/boringssl-with-bazel/crypto/mem.cc +61 -65
- data/third_party/boringssl-with-bazel/crypto/mem_internal.h +706 -0
- data/third_party/boringssl-with-bazel/crypto/mldsa/mldsa.cc +238 -32
- data/third_party/boringssl-with-bazel/crypto/mlkem/mlkem.cc +21 -65
- data/third_party/boringssl-with-bazel/crypto/obj/obj.cc +132 -157
- data/third_party/boringssl-with-bazel/crypto/obj/obj_dat.h +175 -1
- data/third_party/boringssl-with-bazel/crypto/obj/obj_xref.cc +14 -11
- data/third_party/boringssl-with-bazel/crypto/params_internal.h +30 -0
- data/third_party/boringssl-with-bazel/crypto/pem/internal.h +106 -15
- data/third_party/boringssl-with-bazel/crypto/pem/pem_all.cc +28 -24
- data/third_party/boringssl-with-bazel/crypto/pem/pem_info.cc +72 -76
- data/third_party/boringssl-with-bazel/crypto/pem/pem_lib.cc +239 -273
- data/third_party/boringssl-with-bazel/crypto/pem/pem_oth.cc +6 -6
- data/third_party/boringssl-with-bazel/crypto/pem/pem_pk8.cc +16 -13
- data/third_party/boringssl-with-bazel/crypto/pem/pem_pkey.cc +21 -15
- data/third_party/boringssl-with-bazel/crypto/pem/pem_x509.cc +3 -0
- data/third_party/boringssl-with-bazel/crypto/pem/pem_xaux.cc +3 -0
- data/third_party/boringssl-with-bazel/crypto/pkcs7/internal.h +12 -17
- data/third_party/boringssl-with-bazel/crypto/pkcs7/pkcs7.cc +29 -27
- data/third_party/boringssl-with-bazel/crypto/pkcs7/pkcs7_x509.cc +55 -49
- data/third_party/boringssl-with-bazel/crypto/pkcs8/internal.h +21 -26
- data/third_party/boringssl-with-bazel/crypto/pkcs8/p5_pbev2.cc +33 -31
- data/third_party/boringssl-with-bazel/crypto/pkcs8/pkcs8.cc +73 -81
- data/third_party/boringssl-with-bazel/crypto/pkcs8/pkcs8_x509.cc +140 -139
- data/third_party/boringssl-with-bazel/crypto/poly1305/internal.h +20 -7
- data/third_party/boringssl-with-bazel/crypto/poly1305/poly1305.cc +5 -4
- data/third_party/boringssl-with-bazel/crypto/poly1305/poly1305_arm.cc +43 -59
- data/third_party/boringssl-with-bazel/crypto/poly1305/poly1305_vec.cc +32 -29
- data/third_party/boringssl-with-bazel/crypto/pool/internal.h +64 -20
- data/third_party/boringssl-with-bazel/crypto/pool/pool.cc +177 -157
- data/third_party/boringssl-with-bazel/crypto/rand/deterministic.cc +9 -16
- data/third_party/boringssl-with-bazel/crypto/rand/fork_detect.cc +70 -42
- data/third_party/boringssl-with-bazel/crypto/rand/forkunsafe.cc +7 -7
- data/third_party/boringssl-with-bazel/crypto/rand/getentropy.cc +6 -13
- data/third_party/boringssl-with-bazel/crypto/rand/internal.h +16 -4
- data/third_party/boringssl-with-bazel/crypto/rand/ios.cc +4 -11
- data/third_party/boringssl-with-bazel/crypto/rand/rand.cc +11 -9
- data/third_party/boringssl-with-bazel/crypto/rand/trusty.cc +4 -11
- data/third_party/boringssl-with-bazel/crypto/rand/urandom.cc +16 -195
- data/third_party/boringssl-with-bazel/crypto/rand/windows.cc +12 -19
- data/third_party/boringssl-with-bazel/crypto/refcount.cc +7 -17
- data/third_party/boringssl-with-bazel/crypto/rsa/internal.h +22 -7
- data/third_party/boringssl-with-bazel/crypto/rsa/rsa_asn1.cc +199 -78
- data/third_party/boringssl-with-bazel/crypto/rsa/rsa_crypt.cc +49 -50
- data/third_party/boringssl-with-bazel/crypto/rsa/rsa_extra.cc +11 -0
- data/third_party/boringssl-with-bazel/crypto/rsa/rsa_print.cc +4 -6
- data/third_party/boringssl-with-bazel/crypto/sha/sha1.cc +3 -0
- data/third_party/boringssl-with-bazel/crypto/sha/sha256.cc +3 -1
- data/third_party/boringssl-with-bazel/crypto/sha/sha512.cc +6 -4
- data/third_party/boringssl-with-bazel/crypto/siphash/siphash.cc +2 -0
- data/third_party/boringssl-with-bazel/crypto/slhdsa/slhdsa.cc +60 -6
- data/third_party/boringssl-with-bazel/crypto/spake2plus/internal.h +31 -31
- data/third_party/boringssl-with-bazel/crypto/spake2plus/spake2plus.cc +1 -1
- data/third_party/boringssl-with-bazel/crypto/stack/stack.cc +96 -130
- data/third_party/boringssl-with-bazel/crypto/thread.cc +14 -14
- data/third_party/boringssl-with-bazel/crypto/thread_none.cc +10 -13
- data/third_party/boringssl-with-bazel/crypto/thread_pthread.cc +22 -35
- data/third_party/boringssl-with-bazel/crypto/thread_win.cc +29 -40
- data/third_party/boringssl-with-bazel/crypto/trust_token/internal.h +81 -88
- data/third_party/boringssl-with-bazel/crypto/trust_token/pmbtoken.cc +160 -144
- data/third_party/boringssl-with-bazel/crypto/trust_token/trust_token.cc +96 -80
- data/third_party/boringssl-with-bazel/crypto/trust_token/voprf.cc +90 -87
- data/third_party/boringssl-with-bazel/crypto/x509/a_digest.cc +5 -5
- data/third_party/boringssl-with-bazel/crypto/x509/a_sign.cc +51 -48
- data/third_party/boringssl-with-bazel/crypto/x509/a_verify.cc +39 -36
- data/third_party/boringssl-with-bazel/crypto/x509/algorithm.cc +47 -16
- data/third_party/boringssl-with-bazel/crypto/x509/asn1_gen.cc +41 -43
- data/third_party/boringssl-with-bazel/crypto/x509/by_dir.cc +183 -237
- data/third_party/boringssl-with-bazel/crypto/x509/by_file.cc +29 -30
- data/third_party/boringssl-with-bazel/crypto/x509/internal.h +346 -216
- data/third_party/boringssl-with-bazel/crypto/x509/name_print.cc +15 -13
- data/third_party/boringssl-with-bazel/crypto/x509/policy.cc +415 -525
- data/third_party/boringssl-with-bazel/crypto/x509/rsa_pss.cc +95 -272
- data/third_party/boringssl-with-bazel/crypto/x509/t_crl.cc +11 -8
- data/third_party/boringssl-with-bazel/crypto/x509/t_req.cc +26 -23
- data/third_party/boringssl-with-bazel/crypto/x509/t_x509.cc +27 -22
- data/third_party/boringssl-with-bazel/crypto/x509/t_x509a.cc +3 -1
- data/third_party/boringssl-with-bazel/crypto/x509/v3_akey.cc +69 -76
- data/third_party/boringssl-with-bazel/crypto/x509/v3_akeya.cc +2 -2
- data/third_party/boringssl-with-bazel/crypto/x509/v3_alt.cc +112 -69
- data/third_party/boringssl-with-bazel/crypto/x509/v3_bcons.cc +15 -14
- data/third_party/boringssl-with-bazel/crypto/x509/v3_bitst.cc +16 -18
- data/third_party/boringssl-with-bazel/crypto/x509/v3_conf.cc +62 -67
- data/third_party/boringssl-with-bazel/crypto/x509/v3_cpols.cc +143 -170
- data/third_party/boringssl-with-bazel/crypto/x509/v3_crld.cc +123 -209
- data/third_party/boringssl-with-bazel/crypto/x509/v3_enum.cc +13 -12
- data/third_party/boringssl-with-bazel/crypto/x509/v3_extku.cc +17 -34
- data/third_party/boringssl-with-bazel/crypto/x509/v3_genn.cc +20 -10
- data/third_party/boringssl-with-bazel/crypto/x509/v3_ia5.cc +22 -18
- data/third_party/boringssl-with-bazel/crypto/x509/v3_info.cc +45 -47
- data/third_party/boringssl-with-bazel/crypto/x509/v3_int.cc +35 -33
- data/third_party/boringssl-with-bazel/crypto/x509/v3_lib.cc +106 -61
- data/third_party/boringssl-with-bazel/crypto/x509/v3_ncons.cc +642 -358
- data/third_party/boringssl-with-bazel/crypto/x509/v3_ocsp.cc +25 -22
- data/third_party/boringssl-with-bazel/crypto/x509/v3_pcons.cc +15 -14
- data/third_party/boringssl-with-bazel/crypto/x509/v3_pmaps.cc +16 -15
- data/third_party/boringssl-with-bazel/crypto/x509/v3_prn.cc +6 -6
- data/third_party/boringssl-with-bazel/crypto/x509/v3_purp.cc +149 -159
- data/third_party/boringssl-with-bazel/crypto/x509/v3_skey.cc +23 -26
- data/third_party/boringssl-with-bazel/crypto/x509/v3_utl.cc +161 -192
- data/third_party/boringssl-with-bazel/crypto/x509/x509.cc +1 -1
- data/third_party/boringssl-with-bazel/crypto/x509/x509_att.cc +32 -30
- data/third_party/boringssl-with-bazel/crypto/x509/x509_cmp.cc +95 -90
- data/third_party/boringssl-with-bazel/crypto/x509/x509_d2.cc +9 -9
- data/third_party/boringssl-with-bazel/crypto/x509/x509_def.cc +6 -8
- data/third_party/boringssl-with-bazel/crypto/x509/x509_ext.cc +46 -24
- data/third_party/boringssl-with-bazel/crypto/x509/x509_lu.cc +211 -195
- data/third_party/boringssl-with-bazel/crypto/x509/x509_mtc.cc +598 -0
- data/third_party/boringssl-with-bazel/crypto/x509/x509_obj.cc +23 -18
- data/third_party/boringssl-with-bazel/crypto/x509/x509_req.cc +37 -46
- data/third_party/boringssl-with-bazel/crypto/x509/x509_set.cc +58 -90
- data/third_party/boringssl-with-bazel/crypto/x509/x509_trs.cc +18 -13
- data/third_party/boringssl-with-bazel/crypto/x509/x509_v3.cc +33 -33
- data/third_party/boringssl-with-bazel/crypto/x509/x509_vfy.cc +398 -474
- data/third_party/boringssl-with-bazel/crypto/x509/x509_vpm.cc +57 -48
- data/third_party/boringssl-with-bazel/crypto/x509/x509cset.cc +27 -40
- data/third_party/boringssl-with-bazel/crypto/x509/x509name.cc +91 -79
- data/third_party/boringssl-with-bazel/crypto/x509/x509rset.cc +5 -17
- data/third_party/boringssl-with-bazel/crypto/x509/x509spki.cc +13 -13
- data/third_party/boringssl-with-bazel/crypto/x509/x_algor.cc +131 -24
- data/third_party/boringssl-with-bazel/crypto/x509/x_all.cc +73 -39
- data/third_party/boringssl-with-bazel/crypto/x509/x_attrib.cc +10 -4
- data/third_party/boringssl-with-bazel/crypto/x509/x_crl.cc +76 -93
- data/third_party/boringssl-with-bazel/crypto/x509/x_exten.cc +6 -0
- data/third_party/boringssl-with-bazel/crypto/x509/x_name.cc +294 -388
- data/third_party/boringssl-with-bazel/crypto/x509/x_pubkey.cc +113 -84
- data/third_party/boringssl-with-bazel/crypto/x509/x_req.cc +12 -6
- data/third_party/boringssl-with-bazel/crypto/x509/x_sig.cc +4 -4
- data/third_party/boringssl-with-bazel/crypto/x509/x_spki.cc +11 -1
- data/third_party/boringssl-with-bazel/crypto/x509/x_x509.cc +282 -277
- data/third_party/boringssl-with-bazel/crypto/x509/x_x509a.cc +60 -60
- data/third_party/boringssl-with-bazel/crypto/xwing/xwing.cc +257 -0
- data/third_party/boringssl-with-bazel/gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc +325 -0
- data/third_party/boringssl-with-bazel/gen/boringssl_prefix_symbols_internal_x86_win_asm.inc +325 -0
- data/third_party/boringssl-with-bazel/gen/crypto/err_data.cc +538 -500
- data/third_party/boringssl-with-bazel/include/openssl/aead.h +279 -119
- data/third_party/boringssl-with-bazel/include/openssl/aes.h +43 -43
- data/third_party/boringssl-with-bazel/include/openssl/asm_base.h +30 -17
- data/third_party/boringssl-with-bazel/include/openssl/asn1.h +641 -635
- data/third_party/boringssl-with-bazel/include/openssl/asn1t.h +7 -9
- data/third_party/boringssl-with-bazel/include/openssl/base.h +76 -69
- data/third_party/boringssl-with-bazel/include/openssl/base64.h +30 -30
- data/third_party/boringssl-with-bazel/include/openssl/bio.h +394 -322
- data/third_party/boringssl-with-bazel/include/openssl/blake2.h +15 -11
- data/third_party/boringssl-with-bazel/include/openssl/blowfish.h +10 -3
- data/third_party/boringssl-with-bazel/include/openssl/bn.h +298 -306
- data/third_party/boringssl-with-bazel/include/openssl/buf.h +14 -14
- data/third_party/boringssl-with-bazel/include/openssl/bytestring.h +305 -208
- data/third_party/boringssl-with-bazel/include/openssl/cast.h +45 -8
- data/third_party/boringssl-with-bazel/include/openssl/chacha.h +3 -3
- data/third_party/boringssl-with-bazel/include/openssl/cipher.h +345 -161
- data/third_party/boringssl-with-bazel/include/openssl/cmac.h +13 -13
- data/third_party/boringssl-with-bazel/include/openssl/cms.h +35 -34
- data/third_party/boringssl-with-bazel/include/openssl/conf.h +15 -14
- data/third_party/boringssl-with-bazel/include/openssl/configuration.h +18 -0
- data/third_party/boringssl-with-bazel/include/openssl/crypto.h +15 -13
- data/third_party/boringssl-with-bazel/include/openssl/ctrdrbg.h +49 -15
- data/third_party/boringssl-with-bazel/include/openssl/curve25519.h +60 -24
- data/third_party/boringssl-with-bazel/include/openssl/des.h +22 -16
- data/third_party/boringssl-with-bazel/include/openssl/dh.h +95 -95
- data/third_party/boringssl-with-bazel/include/openssl/digest.h +144 -75
- data/third_party/boringssl-with-bazel/include/openssl/dsa.h +101 -101
- data/third_party/boringssl-with-bazel/include/openssl/ec.h +178 -120
- data/third_party/boringssl-with-bazel/include/openssl/ec_key.h +99 -99
- data/third_party/boringssl-with-bazel/include/openssl/ecdh.h +9 -9
- data/third_party/boringssl-with-bazel/include/openssl/ecdsa.h +89 -46
- data/third_party/boringssl-with-bazel/include/openssl/engine.h +5 -5
- data/third_party/boringssl-with-bazel/include/openssl/err.h +73 -71
- data/third_party/boringssl-with-bazel/include/openssl/evp.h +941 -344
- data/third_party/boringssl-with-bazel/include/openssl/evp_errors.h +10 -2
- data/third_party/boringssl-with-bazel/include/openssl/ex_data.h +27 -32
- data/third_party/boringssl-with-bazel/include/openssl/hkdf.h +6 -6
- data/third_party/boringssl-with-bazel/include/openssl/hmac.h +33 -33
- data/third_party/boringssl-with-bazel/include/openssl/hpke.h +170 -123
- data/third_party/boringssl-with-bazel/include/openssl/hrss.h +14 -8
- data/third_party/boringssl-with-bazel/include/openssl/kdf.h +20 -19
- data/third_party/boringssl-with-bazel/include/openssl/lhash.h +4 -25
- data/third_party/boringssl-with-bazel/include/openssl/md4.h +14 -7
- data/third_party/boringssl-with-bazel/include/openssl/md5.h +7 -7
- data/third_party/boringssl-with-bazel/include/openssl/mem.h +42 -42
- data/third_party/boringssl-with-bazel/include/openssl/mldsa.h +380 -24
- data/third_party/boringssl-with-bazel/include/openssl/mlkem.h +43 -43
- data/third_party/boringssl-with-bazel/include/openssl/nid.h +1339 -2
- data/third_party/boringssl-with-bazel/include/openssl/obj.h +49 -49
- data/third_party/boringssl-with-bazel/include/openssl/opensslconf.h +30 -0
- data/third_party/boringssl-with-bazel/include/openssl/params.h +42 -0
- data/third_party/boringssl-with-bazel/include/openssl/pem.h +669 -361
- data/third_party/boringssl-with-bazel/include/openssl/pkcs7.h +40 -40
- data/third_party/boringssl-with-bazel/include/openssl/pkcs8.h +69 -63
- data/third_party/boringssl-with-bazel/include/openssl/poly1305.h +8 -5
- data/third_party/boringssl-with-bazel/include/openssl/pool.h +54 -25
- data/third_party/boringssl-with-bazel/include/openssl/posix_time.h +8 -8
- data/third_party/boringssl-with-bazel/include/openssl/prefix_symbols.h +7992 -0
- data/third_party/boringssl-with-bazel/include/openssl/prefix_symbols_internal_S.h +633 -0
- data/third_party/boringssl-with-bazel/include/openssl/prefix_symbols_internal_c.h +329 -0
- data/third_party/boringssl-with-bazel/include/openssl/rand.h +18 -18
- data/third_party/boringssl-with-bazel/include/openssl/rc4.h +4 -4
- data/third_party/boringssl-with-bazel/include/openssl/ripemd.h +15 -10
- data/third_party/boringssl-with-bazel/include/openssl/rsa.h +272 -235
- data/third_party/boringssl-with-bazel/include/openssl/service_indicator.h +4 -81
- data/third_party/boringssl-with-bazel/include/openssl/sha.h +43 -166
- data/third_party/boringssl-with-bazel/include/openssl/sha2.h +201 -0
- data/third_party/boringssl-with-bazel/include/openssl/slhdsa.h +125 -49
- data/third_party/boringssl-with-bazel/include/openssl/span.h +190 -75
- data/third_party/boringssl-with-bazel/include/openssl/ssl.h +2403 -1633
- data/third_party/boringssl-with-bazel/include/openssl/ssl3.h +11 -69
- data/third_party/boringssl-with-bazel/include/openssl/stack.h +144 -80
- data/third_party/boringssl-with-bazel/include/openssl/target.h +13 -1
- data/third_party/boringssl-with-bazel/include/openssl/thread.h +0 -10
- data/third_party/boringssl-with-bazel/include/openssl/tls1.h +31 -310
- data/third_party/boringssl-with-bazel/include/openssl/tls_prf.h +47 -0
- data/third_party/boringssl-with-bazel/include/openssl/trust_token.h +97 -92
- data/third_party/boringssl-with-bazel/include/openssl/type_check.h +1 -1
- data/third_party/boringssl-with-bazel/include/openssl/types.h +18 -0
- data/third_party/boringssl-with-bazel/include/openssl/x509.h +1839 -1872
- data/third_party/boringssl-with-bazel/include/openssl/x509v3.h +1 -1
- data/third_party/boringssl-with-bazel/include/openssl/xwing.h +115 -0
- data/third_party/boringssl-with-bazel/ssl/bio_ssl.cc +22 -19
- data/third_party/boringssl-with-bazel/ssl/d1_both.cc +202 -135
- data/third_party/boringssl-with-bazel/ssl/d1_lib.cc +84 -68
- data/third_party/boringssl-with-bazel/ssl/d1_pkt.cc +10 -10
- data/third_party/boringssl-with-bazel/ssl/d1_srtp.cc +12 -10
- data/third_party/boringssl-with-bazel/ssl/dtls_method.cc +14 -14
- data/third_party/boringssl-with-bazel/ssl/dtls_record.cc +21 -20
- data/third_party/boringssl-with-bazel/ssl/encrypted_client_hello.cc +102 -96
- data/third_party/boringssl-with-bazel/ssl/extensions.cc +1083 -500
- data/third_party/boringssl-with-bazel/ssl/handoff.cc +154 -100
- data/third_party/boringssl-with-bazel/ssl/handshake.cc +76 -44
- data/third_party/boringssl-with-bazel/ssl/handshake_client.cc +153 -152
- data/third_party/boringssl-with-bazel/ssl/handshake_server.cc +180 -212
- data/third_party/boringssl-with-bazel/ssl/internal.h +1368 -1481
- data/third_party/boringssl-with-bazel/ssl/s3_both.cc +40 -168
- data/third_party/boringssl-with-bazel/ssl/s3_lib.cc +5 -5
- data/third_party/boringssl-with-bazel/ssl/s3_pkt.cc +22 -21
- data/third_party/boringssl-with-bazel/ssl/ssl_aead_ctx.cc +5 -5
- data/third_party/boringssl-with-bazel/ssl/ssl_asn1.cc +123 -68
- data/third_party/boringssl-with-bazel/ssl/ssl_buffer.cc +25 -26
- data/third_party/boringssl-with-bazel/ssl/ssl_cert.cc +156 -84
- data/third_party/boringssl-with-bazel/ssl/ssl_cipher.cc +341 -160
- data/third_party/boringssl-with-bazel/ssl/ssl_credential.cc +349 -124
- data/third_party/boringssl-with-bazel/ssl/ssl_file.cc +134 -225
- data/third_party/boringssl-with-bazel/ssl/ssl_key_share.cc +80 -101
- data/third_party/boringssl-with-bazel/ssl/ssl_lib.cc +1403 -694
- data/third_party/boringssl-with-bazel/ssl/ssl_privkey.cc +173 -105
- data/third_party/boringssl-with-bazel/ssl/ssl_session.cc +287 -235
- data/third_party/boringssl-with-bazel/ssl/ssl_stat.cc +6 -3
- data/third_party/boringssl-with-bazel/ssl/ssl_transcript.cc +4 -4
- data/third_party/boringssl-with-bazel/ssl/ssl_versions.cc +47 -41
- data/third_party/boringssl-with-bazel/ssl/ssl_x509.cc +321 -273
- data/third_party/boringssl-with-bazel/ssl/t1_enc.cc +40 -29
- data/third_party/boringssl-with-bazel/ssl/tls13_both.cc +109 -75
- data/third_party/boringssl-with-bazel/ssl/tls13_client.cc +201 -115
- data/third_party/boringssl-with-bazel/ssl/tls13_enc.cc +179 -124
- data/third_party/boringssl-with-bazel/ssl/tls13_server.cc +241 -158
- data/third_party/boringssl-with-bazel/ssl/tls_method.cc +35 -35
- data/third_party/boringssl-with-bazel/ssl/tls_record.cc +40 -34
- data/third_party/boringssl-with-bazel/third_party/fiat/bedrock_unverified_bareminimum.c.inc +47 -0
- data/third_party/boringssl-with-bazel/third_party/fiat/bedrock_unverified_platform.c.inc +137 -0
- data/third_party/boringssl-with-bazel/third_party/fiat/curve25519_64_adx.h +37 -33
- data/third_party/boringssl-with-bazel/third_party/fiat/p256_64.h +29 -80
- data/third_party/boringssl-with-bazel/third_party/fiat/p256_64_msvc.h +6 -69
- data/third_party/boringssl-with-bazel/third_party/fiat/p256_field.c.inc +26 -0
- data/third_party/boringssl-with-bazel/third_party/fiat/p256_field_32.br.c.inc +71 -0
- data/third_party/boringssl-with-bazel/third_party/fiat/p256_field_64.br.c.inc +84 -0
- data/third_party/boringssl-with-bazel/third_party/fiat/p256_point.br.c.inc +112 -0
- data/third_party/cares/cares/include/ares.h +8 -0
- data/third_party/cares/cares/include/ares_dns_record.h +3 -2
- data/third_party/cares/cares/include/ares_version.h +3 -3
- data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +20 -20
- data/third_party/cares/cares/src/lib/ares_cancel.c +17 -8
- data/third_party/cares/cares/src/lib/ares_close_sockets.c +81 -16
- data/third_party/cares/cares/src/lib/ares_conn.c +256 -10
- data/third_party/cares/cares/src/lib/ares_conn.h +40 -3
- data/third_party/cares/cares/src/lib/ares_cookie.c +2 -2
- data/third_party/cares/cares/src/lib/ares_destroy.c +75 -10
- data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +85 -10
- data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +5 -0
- data/third_party/cares/cares/src/lib/ares_gethostbyname.c +4 -0
- data/third_party/cares/cares/src/lib/ares_getnameinfo.c +10 -2
- data/third_party/cares/cares/src/lib/ares_hosts_file.c +8 -0
- data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +28 -0
- data/third_party/cares/cares/src/lib/ares_init.c +55 -10
- data/third_party/cares/cares/src/lib/ares_library_init.c +25 -7
- data/third_party/cares/cares/src/lib/ares_options.c +38 -10
- data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +1 -1
- data/third_party/cares/cares/src/lib/ares_private.h +186 -27
- data/third_party/cares/cares/src/lib/ares_process.c +604 -112
- data/third_party/cares/cares/src/lib/ares_qcache.c +200 -36
- data/third_party/cares/cares/src/lib/ares_query.c +5 -0
- data/third_party/cares/cares/src/lib/ares_search.c +10 -0
- data/third_party/cares/cares/src/lib/ares_send.c +81 -10
- data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +3 -1
- data/third_party/cares/cares/src/lib/ares_socket.c +28 -0
- data/third_party/cares/cares/src/lib/ares_socket.h +23 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig.c +6 -3
- data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +33 -11
- data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +132 -80
- data/third_party/cares/cares/src/lib/ares_timeout.c +11 -0
- data/third_party/cares/cares/src/lib/ares_update_servers.c +55 -11
- data/third_party/cares/cares/src/lib/dsa/ares_array.c +20 -5
- data/third_party/cares/cares/src/lib/dsa/ares_htable.c +8 -4
- data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +2 -0
- data/third_party/cares/cares/src/lib/dsa/ares_llist.c +4 -1
- data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +5 -2
- data/third_party/cares/cares/src/lib/event/ares_event_select.c +14 -1
- data/third_party/cares/cares/src/lib/event/ares_event_thread.c +8 -0
- data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +7 -1
- data/third_party/cares/cares/src/lib/event/ares_event_win32.c +3 -0
- data/third_party/cares/cares/src/lib/include/ares_mem.h +3 -0
- data/third_party/cares/cares/src/lib/include/ares_str.h +17 -0
- data/third_party/cares/cares/src/lib/inet_net_pton.c +37 -28
- data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +1 -1
- data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +5 -2
- data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +5 -2
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +2 -2
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +2 -2
- data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +1 -1
- data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +19 -4
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +3 -1
- data/third_party/cares/cares/src/lib/record/ares_dns_name.c +67 -4
- data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +62 -34
- data/third_party/cares/cares/src/lib/record/ares_dns_private.h +4 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_record.c +47 -7
- data/third_party/cares/cares/src/lib/record/ares_dns_write.c +13 -5
- data/third_party/cares/cares/src/lib/str/ares_buf.c +33 -16
- data/third_party/cares/cares/src/lib/str/ares_str.c +54 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +22 -10
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +1 -0
- data/third_party/cares/cares/src/lib/util/ares_math.c +17 -2
- data/third_party/cares/cares/src/lib/util/ares_math.h +32 -7
- data/third_party/cares/cares/src/lib/util/ares_rand.c +4 -4
- data/third_party/cares/cares/src/lib/util/ares_threads.c +1 -2
- data/third_party/cares/cares/src/lib/util/ares_time.h +1 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.c +9 -3
- data/third_party/zlib/compress.c +34 -10
- data/third_party/zlib/crc32.c +49 -115
- data/third_party/zlib/deflate.c +107 -61
- data/third_party/zlib/deflate.h +7 -1
- data/third_party/zlib/gzguts.h +33 -31
- data/third_party/zlib/infback.c +20 -67
- data/third_party/zlib/inffast.c +7 -6
- data/third_party/zlib/inffixed.h +91 -91
- data/third_party/zlib/inflate.c +38 -151
- data/third_party/zlib/inflate.h +1 -1
- data/third_party/zlib/inftrees.c +134 -9
- data/third_party/zlib/inftrees.h +3 -1
- data/third_party/zlib/trees.c +14 -12
- data/third_party/zlib/uncompr.c +39 -23
- data/third_party/zlib/zconf.h +27 -19
- data/third_party/zlib/zlib.h +215 -96
- data/third_party/zlib/zutil.c +49 -35
- data/third_party/zlib/zutil.h +87 -10
- metadata +4095 -4024
- data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +0 -916
- data/src/core/ext/filters/rbac/rbac_service_config_parser.h +0 -84
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +0 -240
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +0 -56
- data/src/core/ext/upb-gen/src/proto/grpc/health/v1/health.upb.h +0 -157
- data/src/core/ext/upb-gen/src/proto/grpc/health/v1/health.upb_minitable.c +0 -72
- data/src/core/ext/upbdefs-gen/src/proto/grpc/lookup/v1/rls_config.upbdefs.c +0 -181
- data/src/core/server/xds_channel_stack_modifier.cc +0 -108
- data/src/core/server/xds_channel_stack_modifier.h +0 -62
- data/src/core/server/xds_server_config_fetcher_legacy.cc +0 -1340
- data/third_party/abseil-cpp/absl/base/internal/identity.h +0 -39
- data/third_party/abseil-cpp/absl/base/internal/nullability_deprecated.h +0 -106
- data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.cc +0 -105
- data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.h +0 -50
- data/third_party/abseil-cpp/absl/strings/string_view.cc +0 -257
- data/third_party/boringssl-with-bazel/crypto/evp/p_dh_asn1.cc +0 -142
- data/third_party/boringssl-with-bazel/crypto/evp/p_dsa_asn1.cc +0 -279
- data/third_party/boringssl-with-bazel/crypto/evp/p_ec_asn1.cc +0 -286
- data/third_party/boringssl-with-bazel/crypto/evp/p_ed25519_asn1.cc +0 -225
- data/third_party/boringssl-with-bazel/crypto/evp/p_rsa_asn1.cc +0 -198
- data/third_party/boringssl-with-bazel/crypto/evp/p_x25519_asn1.cc +0 -237
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/ec/p224-64.cc.inc +0 -1163
- data/third_party/boringssl-with-bazel/crypto/fipsmodule/rsa/blinding.cc.inc +0 -147
- data/third_party/boringssl-with-bazel/crypto/kyber/internal.h +0 -60
- data/third_party/boringssl-with-bazel/crypto/kyber/kyber.cc +0 -869
- data/third_party/boringssl-with-bazel/crypto/rand/getrandom_fillin.h +0 -64
- data/third_party/boringssl-with-bazel/crypto/rand/passive.cc +0 -178
- data/third_party/boringssl-with-bazel/crypto/x509/ext_dat.h +0 -92
- data/third_party/boringssl-with-bazel/include/openssl/bcm_public.h +0 -82
- data/third_party/boringssl-with-bazel/include/openssl/experimental/kyber.h +0 -146
|
@@ -24,9 +24,21 @@
|
|
|
24
24
|
#include <openssl/rand.h>
|
|
25
25
|
|
|
26
26
|
#include "../../internal.h"
|
|
27
|
+
#include "../../mem_internal.h"
|
|
27
28
|
#include "../bcm_interface.h"
|
|
28
29
|
#include "../keccak/internal.h"
|
|
29
30
|
|
|
31
|
+
|
|
32
|
+
using namespace bssl;
|
|
33
|
+
|
|
34
|
+
#if defined(BORINGSSL_FIPS)
|
|
35
|
+
|
|
36
|
+
DEFINE_STATIC_ONCE(g_mldsa_keygen_self_test_once)
|
|
37
|
+
DEFINE_STATIC_ONCE(g_mldsa_sign_self_test_once)
|
|
38
|
+
DEFINE_STATIC_ONCE(g_mldsa_verify_self_test_once)
|
|
39
|
+
|
|
40
|
+
#endif
|
|
41
|
+
|
|
30
42
|
namespace mldsa {
|
|
31
43
|
namespace {
|
|
32
44
|
|
|
@@ -50,9 +62,9 @@ constexpr uint32_t kPrime = 8380417;
|
|
|
50
62
|
constexpr uint32_t kPrimeNegInverse = 4236238847;
|
|
51
63
|
constexpr int kDroppedBits = 13;
|
|
52
64
|
constexpr uint32_t kHalfPrime = (kPrime - 1) / 2;
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
constexpr uint32_t
|
|
65
|
+
// 256^-1 ⋅ R² mod kPrime. This is not 256^-1 in Montgomery form, but 256^-1
|
|
66
|
+
// doubly-converted to Montgomery form.
|
|
67
|
+
constexpr uint32_t kInverseDegreeDoubleMontgomery = 41978;
|
|
56
68
|
|
|
57
69
|
// Constants that vary depending on ML-DSA size.
|
|
58
70
|
//
|
|
@@ -62,18 +74,22 @@ constexpr uint32_t kInverseDegreeMontgomery = 41978;
|
|
|
62
74
|
template <int K>
|
|
63
75
|
constexpr size_t public_key_bytes() {
|
|
64
76
|
if constexpr (K == 6) {
|
|
65
|
-
return
|
|
77
|
+
return MLDSA65_PUBLIC_KEY_BYTES;
|
|
66
78
|
} else if constexpr (K == 8) {
|
|
67
|
-
return
|
|
79
|
+
return MLDSA87_PUBLIC_KEY_BYTES;
|
|
80
|
+
} else if constexpr (K == 4) {
|
|
81
|
+
return MLDSA44_PUBLIC_KEY_BYTES;
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
template <int K>
|
|
72
86
|
constexpr size_t signature_bytes() {
|
|
73
87
|
if constexpr (K == 6) {
|
|
74
|
-
return
|
|
88
|
+
return MLDSA65_SIGNATURE_BYTES;
|
|
75
89
|
} else if constexpr (K == 8) {
|
|
76
|
-
return
|
|
90
|
+
return MLDSA87_SIGNATURE_BYTES;
|
|
91
|
+
} else if constexpr (K == 4) {
|
|
92
|
+
return MLDSA44_SIGNATURE_BYTES;
|
|
77
93
|
}
|
|
78
94
|
}
|
|
79
95
|
|
|
@@ -83,6 +99,8 @@ constexpr int tau() {
|
|
|
83
99
|
return 49;
|
|
84
100
|
} else if constexpr (K == 8) {
|
|
85
101
|
return 60;
|
|
102
|
+
} else if constexpr (K == 4) {
|
|
103
|
+
return 39;
|
|
86
104
|
}
|
|
87
105
|
}
|
|
88
106
|
|
|
@@ -92,22 +110,71 @@ constexpr int lambda_bytes() {
|
|
|
92
110
|
return 192 / 8;
|
|
93
111
|
} else if constexpr (K == 8) {
|
|
94
112
|
return 256 / 8;
|
|
113
|
+
} else if constexpr (K == 4) {
|
|
114
|
+
return 128 / 8;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
template <int K>
|
|
119
|
+
constexpr int gamma1_bits() {
|
|
120
|
+
if constexpr (K == 6 || K == 8) {
|
|
121
|
+
return 19;
|
|
122
|
+
} else if constexpr (K == 4) {
|
|
123
|
+
return 17;
|
|
95
124
|
}
|
|
96
125
|
}
|
|
97
126
|
|
|
98
127
|
template <int K>
|
|
99
128
|
constexpr int gamma1() {
|
|
129
|
+
return 1 << gamma1_bits<K>();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
template <int K>
|
|
133
|
+
constexpr int scalar_le_gamma1_bytes() {
|
|
134
|
+
return ((gamma1_bits<K>() + 1) * kDegree) / 8;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
template <int K>
|
|
138
|
+
constexpr uint32_t w1_coeffs_bits() {
|
|
139
|
+
if constexpr (K == 6 || K == 8) {
|
|
140
|
+
return 4;
|
|
141
|
+
} else if constexpr (K == 4) {
|
|
142
|
+
return 6;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
template <int K>
|
|
147
|
+
constexpr uint32_t w1_scalar_bytes() {
|
|
148
|
+
return (w1_coeffs_bits<K>() * kDegree) / 8;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
template <int K>
|
|
152
|
+
constexpr uint32_t w1_bytes() {
|
|
153
|
+
return w1_scalar_bytes<K>() * K;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
template <int K>
|
|
157
|
+
constexpr uint32_t prime_minus_one_over_gamma2() {
|
|
100
158
|
if constexpr (K == 6 || K == 8) {
|
|
101
|
-
return
|
|
159
|
+
return 32;
|
|
160
|
+
} else if constexpr (K == 4) {
|
|
161
|
+
return 88;
|
|
102
162
|
}
|
|
103
163
|
}
|
|
104
164
|
|
|
165
|
+
template <int K>
|
|
166
|
+
constexpr uint32_t gamma2() {
|
|
167
|
+
return (kPrime - 1) / prime_minus_one_over_gamma2<K>();
|
|
168
|
+
}
|
|
169
|
+
|
|
105
170
|
template <int K>
|
|
106
171
|
constexpr int beta() {
|
|
107
172
|
if constexpr (K == 6) {
|
|
108
173
|
return 196;
|
|
109
174
|
} else if constexpr (K == 8) {
|
|
110
175
|
return 120;
|
|
176
|
+
} else if constexpr (K == 4) {
|
|
177
|
+
return 78;
|
|
111
178
|
}
|
|
112
179
|
}
|
|
113
180
|
|
|
@@ -117,6 +184,8 @@ constexpr int omega() {
|
|
|
117
184
|
return 55;
|
|
118
185
|
} else if constexpr (K == 8) {
|
|
119
186
|
return 75;
|
|
187
|
+
} else if constexpr (K == 4) {
|
|
188
|
+
return 80;
|
|
120
189
|
}
|
|
121
190
|
}
|
|
122
191
|
|
|
@@ -124,7 +193,7 @@ template <int K>
|
|
|
124
193
|
constexpr int eta() {
|
|
125
194
|
if constexpr (K == 6) {
|
|
126
195
|
return 4;
|
|
127
|
-
} else if constexpr (K == 8) {
|
|
196
|
+
} else if constexpr (K == 8 || K == 4) {
|
|
128
197
|
return 2;
|
|
129
198
|
}
|
|
130
199
|
}
|
|
@@ -133,16 +202,16 @@ template <int K>
|
|
|
133
202
|
constexpr int plus_minus_eta_bitlen() {
|
|
134
203
|
if constexpr (K == 6) {
|
|
135
204
|
return 4;
|
|
136
|
-
} else if constexpr (K == 8) {
|
|
205
|
+
} else if constexpr (K == 8 || K == 4) {
|
|
137
206
|
return 3;
|
|
138
207
|
}
|
|
139
208
|
}
|
|
140
209
|
|
|
141
210
|
// Fundamental types.
|
|
142
211
|
|
|
143
|
-
|
|
212
|
+
struct scalar {
|
|
144
213
|
uint32_t c[kDegree];
|
|
145
|
-
}
|
|
214
|
+
};
|
|
146
215
|
|
|
147
216
|
template <int K>
|
|
148
217
|
struct vector {
|
|
@@ -222,64 +291,110 @@ static const uint32_t kNTTRootsMontgomery[256] = {
|
|
|
222
291
|
7826001, 3919660, 8332111, 7018208, 3937738, 1400424, 7534263, 1976782};
|
|
223
292
|
|
|
224
293
|
// Reduces x mod kPrime in constant time, where 0 <= x < 2*kPrime.
|
|
225
|
-
uint32_t reduce_once(uint32_t x) {
|
|
294
|
+
inline uint32_t reduce_once(uint32_t x) {
|
|
226
295
|
declassify_assert(x < 2 * kPrime);
|
|
227
296
|
// return x < kPrime ? x : x - kPrime;
|
|
228
|
-
|
|
297
|
+
const uint32_t subtracted = x - kPrime;
|
|
298
|
+
uint32_t mask = 0u - (subtracted >> 31);
|
|
299
|
+
// Although this is a constant-time select, we omit a value barrier here.
|
|
300
|
+
// Value barriers impede auto-vectorization (likely because it forces the
|
|
301
|
+
// value to transit through a general-purpose register). This is a difference
|
|
302
|
+
// of 1.4x to 1.5x in signing performance.
|
|
303
|
+
//
|
|
304
|
+
// We usually add value barriers to selects because Clang turns consecutive
|
|
305
|
+
// selects with the same condition into a branch instead of CMOV/CSEL. This
|
|
306
|
+
// condition does not occur in ML-DSA, so omitting it seems to be generally
|
|
307
|
+
// safe. However, see `coefficient_from_nibble`.
|
|
308
|
+
return (mask & x) | (~mask & subtracted);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// reduce_from_u32 returns `x mod kPrime`. `x` can be any `uint32_t`.
|
|
312
|
+
inline uint32_t reduce_from_u32(uint32_t x) {
|
|
313
|
+
// kPrime is 2^23 - 2^13 + 1. We first split `x` into the upper 9 bits and the
|
|
314
|
+
// lower 23 bits:
|
|
315
|
+
uint32_t hi = x >> 23, lo = x & ((uint32_t{1} << 23) - 1);
|
|
316
|
+
// 2^23 = 2^13 - 1 mod kPrime
|
|
317
|
+
// x = hi * 2^23 + lo
|
|
318
|
+
// = hi * 2^13 - hi + lo mod kPrime
|
|
319
|
+
//
|
|
320
|
+
// This value does not overflow and is below 2 * kPrime. We can `reduce_once`.
|
|
321
|
+
static constexpr uint32_t kMaxHi = UINT32_MAX >> 23;
|
|
322
|
+
static constexpr uint32_t kMaxLo = (uint32_t{1} << 23) - 1;
|
|
323
|
+
static_assert((kMaxHi << 13) - kMaxHi + kMaxLo < 2 * kPrime);
|
|
324
|
+
return reduce_once((hi << 13) - hi + lo);
|
|
229
325
|
}
|
|
230
326
|
|
|
231
|
-
// Returns the absolute value in constant time
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
//
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return constant_time_select_int(constant_time_lt_w(x, 0x80000000), x, 0u - x);
|
|
327
|
+
// Returns the absolute value in constant time, interpreting the high bit as a
|
|
328
|
+
// sign bit.
|
|
329
|
+
inline uint32_t abs_signed(uint32_t x) {
|
|
330
|
+
// return is_negative(x) ? -x : x;
|
|
331
|
+
uint32_t mask = 0u - (x >> 31);
|
|
332
|
+
return constant_time_select_32(mask, 0u - x, x);
|
|
238
333
|
}
|
|
239
334
|
|
|
240
335
|
// Returns the absolute value modulo kPrime.
|
|
241
|
-
uint32_t abs_mod_prime(uint32_t x) {
|
|
336
|
+
inline uint32_t abs_mod_prime(uint32_t x) {
|
|
242
337
|
declassify_assert(x < kPrime);
|
|
243
|
-
// return x
|
|
244
|
-
|
|
245
|
-
|
|
338
|
+
// return x <= kHalfPrime ? x : kPrime - x;
|
|
339
|
+
uint32_t mask = x - kHalfPrime - 1;
|
|
340
|
+
mask = 0u - (mask >> 31);
|
|
341
|
+
return constant_time_select_32(mask, x, kPrime - x);
|
|
246
342
|
}
|
|
247
343
|
|
|
248
|
-
// Returns the maximum of two values in constant time.
|
|
249
|
-
|
|
344
|
+
// Returns the maximum of two values in constant time. Each value must be less
|
|
345
|
+
// than kPrime.
|
|
346
|
+
inline uint32_t maximum_reduced(uint32_t x, uint32_t y) {
|
|
347
|
+
declassify_assert(x < kPrime);
|
|
348
|
+
declassify_assert(y < kPrime);
|
|
250
349
|
// return x < y ? y : x;
|
|
251
|
-
|
|
350
|
+
uint32_t mask = x - y;
|
|
351
|
+
mask = 0u - (mask >> 31);
|
|
352
|
+
return constant_time_select_32(mask, y, x);
|
|
252
353
|
}
|
|
253
354
|
|
|
254
|
-
uint32_t mod_sub(uint32_t a, uint32_t b) {
|
|
355
|
+
inline uint32_t mod_sub(uint32_t a, uint32_t b) {
|
|
255
356
|
declassify_assert(a < kPrime);
|
|
256
357
|
declassify_assert(b < kPrime);
|
|
257
|
-
|
|
358
|
+
uint32_t r = a - b;
|
|
359
|
+
// return r < 0 ? r + kPrime : r;
|
|
360
|
+
uint32_t mask = 0u - (r >> 31);
|
|
361
|
+
// See `reduce_once` for why this does not have a value barrier.
|
|
362
|
+
return (mask & (r + kPrime)) | (~mask & r);
|
|
258
363
|
}
|
|
259
364
|
|
|
260
|
-
void scalar_add(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
365
|
+
inline void scalar_add(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
261
366
|
for (int i = 0; i < kDegree; i++) {
|
|
262
367
|
out->c[i] = reduce_once(lhs->c[i] + rhs->c[i]);
|
|
263
368
|
}
|
|
264
369
|
}
|
|
265
370
|
|
|
266
|
-
void scalar_sub(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
371
|
+
inline void scalar_sub(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
267
372
|
for (int i = 0; i < kDegree; i++) {
|
|
268
373
|
out->c[i] = mod_sub(lhs->c[i], rhs->c[i]);
|
|
269
374
|
}
|
|
270
375
|
}
|
|
271
376
|
|
|
272
|
-
|
|
377
|
+
// reduce_montgomery_partial returns a number equivalent to x * R^-1 mod kPrime.
|
|
378
|
+
// The output is less than 2 * kPrime. `x` must be at most kPrime * 2^32.
|
|
379
|
+
inline uint32_t reduce_montgomery_partial(uint64_t x) {
|
|
273
380
|
declassify_assert(x <= ((uint64_t)kPrime << 32));
|
|
274
381
|
uint64_t a = (uint32_t)x * kPrimeNegInverse;
|
|
275
382
|
uint64_t b = x + a * kPrime;
|
|
276
383
|
declassify_assert((b & 0xffffffff) == 0);
|
|
277
|
-
|
|
278
|
-
|
|
384
|
+
return b >> 32;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// reduce_montgomery returns x * R^-1 mod kPrime, fully reduced. `x` must be at
|
|
388
|
+
// most kPrime * 2^32.
|
|
389
|
+
inline uint32_t reduce_montgomery(uint64_t x) {
|
|
390
|
+
return reduce_once(reduce_montgomery_partial(x));
|
|
279
391
|
}
|
|
280
392
|
|
|
281
|
-
//
|
|
282
|
-
|
|
393
|
+
// Montgomery-multiply two scalars in the number theoretically transformed
|
|
394
|
+
// state. Each term gains an extra R^-1 term, which is expected to be canceled
|
|
395
|
+
// by `scalar_inverse_ntt_montgomery`.
|
|
396
|
+
inline void scalar_mult_montgomery(scalar *out, const scalar *lhs,
|
|
397
|
+
const scalar *rhs) {
|
|
283
398
|
for (int i = 0; i < kDegree; i++) {
|
|
284
399
|
out->c[i] = reduce_montgomery((uint64_t)lhs->c[i] * (uint64_t)rhs->c[i]);
|
|
285
400
|
}
|
|
@@ -288,115 +403,155 @@ void scalar_mult(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
|
288
403
|
// In place number theoretic transform of a given scalar.
|
|
289
404
|
//
|
|
290
405
|
// FIPS 204, Algorithm 41 (`NTT`).
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
406
|
+
inline void scalar_ntt(scalar *s) {
|
|
407
|
+
// Manually unrolled loop to maximize vectorization.
|
|
408
|
+
//
|
|
409
|
+
// Intermediate values of `s` are not fully reduced. `ITER` writes to every
|
|
410
|
+
// element of `s` exactly once. Each write adds less than 2*kPrime to some
|
|
411
|
+
// value from the previous iteration. After eight iterations, each element
|
|
412
|
+
// will be less than 17*kPrime. This fits in `uint32_t`, so we never overflow.
|
|
413
|
+
#define ITER(step, offset) \
|
|
414
|
+
{ \
|
|
415
|
+
int k = 0; \
|
|
416
|
+
for (int i = 0; i < step; i++) { \
|
|
417
|
+
const uint32_t step_root = kNTTRootsMontgomery[step + i]; \
|
|
418
|
+
for (int j = k; j < k + offset; j++) { \
|
|
419
|
+
uint32_t even = s->c[j]; \
|
|
420
|
+
/* `reduce_montgomery_partial` works on values up to kPrime*R. \
|
|
421
|
+
* `step_root < kPrime` because it's static data. `s->c[...] < R` \
|
|
422
|
+
* because it's 32-bit. */ \
|
|
423
|
+
uint32_t odd = reduce_montgomery_partial(uint64_t{step_root} * \
|
|
424
|
+
uint64_t{s->c[j + offset]}); \
|
|
425
|
+
s->c[j] = even + odd; \
|
|
426
|
+
s->c[j + offset] = even + 2 * kPrime - odd; \
|
|
427
|
+
} \
|
|
428
|
+
k += 2 * offset; \
|
|
429
|
+
} \
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
ITER(1, 128)
|
|
433
|
+
ITER(2, 64)
|
|
434
|
+
ITER(4, 32)
|
|
435
|
+
ITER(8, 16)
|
|
436
|
+
ITER(16, 8)
|
|
437
|
+
ITER(32, 4)
|
|
438
|
+
ITER(64, 2)
|
|
439
|
+
ITER(128, 1)
|
|
440
|
+
static_assert(kDegree == 256);
|
|
441
|
+
#undef ITER
|
|
442
|
+
|
|
443
|
+
// Now `s` is correct but the elements are not fully reduced. Reduce them.
|
|
444
|
+
for (int i = 0; i < kDegree; i++) {
|
|
445
|
+
s->c[i] = reduce_from_u32(s->c[i]);
|
|
313
446
|
}
|
|
314
447
|
}
|
|
315
448
|
|
|
316
|
-
// In place inverse number theoretic transform of a given scalar
|
|
449
|
+
// In place inverse number theoretic transform of a given scalar, but with each
|
|
450
|
+
// term multiplied by an extra factor of R. This is function is intended to be
|
|
451
|
+
// used with products that have gone through `reduce_montgomery` one extra time,
|
|
452
|
+
// so the extra R^-1 term is canceled out.
|
|
317
453
|
//
|
|
318
454
|
// FIPS 204, Algorithm 42 (`NTT^-1`).
|
|
319
|
-
void
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
455
|
+
inline void scalar_inverse_ntt_montgomery(scalar *s) {
|
|
456
|
+
// Manually unrolled loop to maximize vectorization.
|
|
457
|
+
//
|
|
458
|
+
// Intermediate values of `s` are not fully reduced. `ITER` writes
|
|
459
|
+
// to every element of `s` exactly once. Each write either adds two values
|
|
460
|
+
// from the previous iteration, or is at most 2 * kPrime. After eight
|
|
461
|
+
// iterations, each element will be less than 2⁸ * kPrime = 256 * kPrime.
|
|
462
|
+
// This fits in `uint32_t`, so we never overflow.
|
|
463
|
+
#define ITER(step, offset) \
|
|
464
|
+
{ \
|
|
465
|
+
int k = 0; \
|
|
466
|
+
for (int i = 0; i < step; i++) { \
|
|
467
|
+
const uint32_t step_root = \
|
|
468
|
+
kPrime - kNTTRootsMontgomery[step + (step - 1 - i)]; \
|
|
469
|
+
for (int j = k; j < k + offset; j++) { \
|
|
470
|
+
uint32_t even = s->c[j]; \
|
|
471
|
+
uint32_t odd = s->c[j + offset]; \
|
|
472
|
+
s->c[j] = odd + even; \
|
|
473
|
+
/* `reduce_montgomery_partial` works on values up to kPrime*R. \
|
|
474
|
+
* `step_root < kPrime` because it's static data. The other term is \
|
|
475
|
+
* less than R because it's 32-bit, and does not overflow because \
|
|
476
|
+
* `odd` is at most 128 * kPrime per the above. */ \
|
|
477
|
+
s->c[j + offset] = reduce_montgomery_partial( \
|
|
478
|
+
uint64_t{step_root} * uint64_t{128 * kPrime + even - odd}); \
|
|
479
|
+
} \
|
|
480
|
+
k += 2 * offset; \
|
|
481
|
+
} \
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
ITER(128, 1)
|
|
485
|
+
ITER(64, 2)
|
|
486
|
+
ITER(32, 4)
|
|
487
|
+
ITER(16, 8)
|
|
488
|
+
ITER(8, 16)
|
|
489
|
+
ITER(4, 32)
|
|
490
|
+
ITER(2, 64)
|
|
491
|
+
ITER(1, 128)
|
|
492
|
+
static_assert(kDegree == 256);
|
|
493
|
+
#undef ITER
|
|
494
|
+
|
|
495
|
+
// `kInverseDegreeDoubleMontgomery` has been double-converted to Montgomery
|
|
496
|
+
// form, so the result is an extra R term in the final result. This also fully
|
|
497
|
+
// reduces the partially-reduced values above.
|
|
346
498
|
for (int i = 0; i < kDegree; i++) {
|
|
347
|
-
s->c[i] = reduce_montgomery(
|
|
348
|
-
|
|
499
|
+
s->c[i] = reduce_montgomery(uint64_t{s->c[i]} *
|
|
500
|
+
uint64_t{kInverseDegreeDoubleMontgomery});
|
|
349
501
|
}
|
|
350
502
|
}
|
|
351
503
|
|
|
352
504
|
template <int X>
|
|
353
|
-
void vector_zero(vector<X> *out) {
|
|
505
|
+
inline void vector_zero(vector<X> *out) {
|
|
354
506
|
OPENSSL_memset(out, 0, sizeof(*out));
|
|
355
507
|
}
|
|
356
508
|
|
|
357
509
|
template <int X>
|
|
358
|
-
void vector_add(vector<X> *out, const vector<X> *lhs,
|
|
510
|
+
inline void vector_add(vector<X> *out, const vector<X> *lhs,
|
|
511
|
+
const vector<X> *rhs) {
|
|
359
512
|
for (int i = 0; i < X; i++) {
|
|
360
513
|
scalar_add(&out->v[i], &lhs->v[i], &rhs->v[i]);
|
|
361
514
|
}
|
|
362
515
|
}
|
|
363
516
|
|
|
364
517
|
template <int X>
|
|
365
|
-
void vector_sub(vector<X> *out, const vector<X> *lhs,
|
|
518
|
+
inline void vector_sub(vector<X> *out, const vector<X> *lhs,
|
|
519
|
+
const vector<X> *rhs) {
|
|
366
520
|
for (int i = 0; i < X; i++) {
|
|
367
521
|
scalar_sub(&out->v[i], &lhs->v[i], &rhs->v[i]);
|
|
368
522
|
}
|
|
369
523
|
}
|
|
370
524
|
|
|
371
525
|
template <int X>
|
|
372
|
-
void
|
|
373
|
-
|
|
526
|
+
inline void vector_mult_scalar_montgomery(vector<X> *out, const vector<X> *lhs,
|
|
527
|
+
const scalar *rhs) {
|
|
374
528
|
for (int i = 0; i < X; i++) {
|
|
375
|
-
|
|
529
|
+
scalar_mult_montgomery(&out->v[i], &lhs->v[i], rhs);
|
|
376
530
|
}
|
|
377
531
|
}
|
|
378
532
|
|
|
379
533
|
template <int X>
|
|
380
|
-
void vector_ntt(vector<X> *a) {
|
|
534
|
+
inline void vector_ntt(vector<X> *a) {
|
|
381
535
|
for (int i = 0; i < X; i++) {
|
|
382
536
|
scalar_ntt(&a->v[i]);
|
|
383
537
|
}
|
|
384
538
|
}
|
|
385
539
|
|
|
386
540
|
template <int X>
|
|
387
|
-
void
|
|
541
|
+
inline void vector_inverse_ntt_montgomery(vector<X> *a) {
|
|
388
542
|
for (int i = 0; i < X; i++) {
|
|
389
|
-
|
|
543
|
+
scalar_inverse_ntt_montgomery(&a->v[i]);
|
|
390
544
|
}
|
|
391
545
|
}
|
|
392
546
|
|
|
393
547
|
template <int K, int L>
|
|
394
|
-
void
|
|
548
|
+
inline void matrix_mult_montgomery(vector<K> *out, const matrix<K, L> *m,
|
|
549
|
+
const vector<L> *a) {
|
|
395
550
|
vector_zero(out);
|
|
396
551
|
for (int i = 0; i < K; i++) {
|
|
397
552
|
for (int j = 0; j < L; j++) {
|
|
398
553
|
scalar product;
|
|
399
|
-
|
|
554
|
+
scalar_mult_montgomery(&product, &m->v[i][j], &a->v[j]);
|
|
400
555
|
scalar_add(&out->v[i], &out->v[i], &product);
|
|
401
556
|
}
|
|
402
557
|
}
|
|
@@ -405,7 +560,7 @@ void matrix_mult(vector<K> *out, const matrix<K, L> *m, const vector<L> *a) {
|
|
|
405
560
|
/* Rounding & hints */
|
|
406
561
|
|
|
407
562
|
// FIPS 204, Algorithm 35 (`Power2Round`).
|
|
408
|
-
void power2_round(uint32_t *r1, uint32_t *r0, uint32_t r) {
|
|
563
|
+
inline void power2_round(uint32_t *r1, uint32_t *r0, uint32_t r) {
|
|
409
564
|
*r1 = r >> kDroppedBits;
|
|
410
565
|
*r0 = r - (*r1 << kDroppedBits);
|
|
411
566
|
|
|
@@ -416,59 +571,71 @@ void power2_round(uint32_t *r1, uint32_t *r0, uint32_t r) {
|
|
|
416
571
|
crypto_word_t mask =
|
|
417
572
|
constant_time_lt_w((uint32_t)(1 << (kDroppedBits - 1)), *r0);
|
|
418
573
|
// r0 = mask ? r0_adjusted : r0
|
|
419
|
-
*r0 =
|
|
574
|
+
*r0 = constant_time_select_32(mask, r0_adjusted, *r0);
|
|
420
575
|
// r1 = mask ? r1_adjusted : r1
|
|
421
|
-
*r1 =
|
|
576
|
+
*r1 = constant_time_select_32(mask, r1_adjusted, *r1);
|
|
422
577
|
}
|
|
423
578
|
|
|
424
579
|
// Scale back previously rounded value.
|
|
425
|
-
void scale_power2_round(uint32_t *out, uint32_t r1) {
|
|
426
|
-
// Pre-condition: 0
|
|
580
|
+
inline void scale_power2_round(uint32_t *out, uint32_t r1) {
|
|
581
|
+
// Pre-condition: 0 ≤ r1 ≤ 2^10 - 1
|
|
427
582
|
assert(r1 < (1u << 10));
|
|
428
583
|
|
|
429
584
|
*out = r1 << kDroppedBits;
|
|
430
585
|
|
|
431
|
-
// Post-condition: 0
|
|
586
|
+
// Post-condition: 0 ≤ out ≤ 2^23 - 2^13 = kPrime - 1
|
|
432
587
|
assert(*out < kPrime);
|
|
433
588
|
}
|
|
434
589
|
|
|
435
590
|
// FIPS 204, Algorithm 37 (`HighBits`).
|
|
436
|
-
|
|
591
|
+
template <int K>
|
|
592
|
+
inline uint32_t high_bits(uint32_t x) {
|
|
437
593
|
// Reference description (given 0 <= x < q):
|
|
438
594
|
//
|
|
439
595
|
// ```
|
|
440
|
-
// int32_t r0 = x mod+- (2 *
|
|
596
|
+
// int32_t r0 = x mod+- (2 * gamma2);
|
|
441
597
|
// if (x - r0 == q - 1) {
|
|
442
598
|
// return 0;
|
|
443
599
|
// } else {
|
|
444
|
-
// return (x - r0) / (2 *
|
|
600
|
+
// return (x - r0) / (2 * gamma2);
|
|
445
601
|
// }
|
|
446
602
|
// ```
|
|
447
603
|
//
|
|
448
|
-
// Below is the formula taken from the reference implementation.
|
|
449
|
-
//
|
|
450
|
-
// Here, kGamma2 == 2^18 - 2^8
|
|
451
|
-
// This returns ((ceil(x / 2^7) * (2^10 + 1) + 2^21) / 2^22) mod 2^4
|
|
452
604
|
uint32_t r1 = (x + 127) >> 7;
|
|
453
|
-
|
|
454
|
-
|
|
605
|
+
if constexpr (prime_minus_one_over_gamma2<K>() == 32) {
|
|
606
|
+
// Below is the formula taken from the reference implementation.
|
|
607
|
+
//
|
|
608
|
+
// Here, Gamma2 == 2^18 - 2^8
|
|
609
|
+
// This returns ((ceil(x / 2^7) ⋅ (2^10 + 1) + 2^21) / 2^22) mod 2^4
|
|
610
|
+
r1 = (r1 * 1025 + (1 << 21)) >> 22;
|
|
611
|
+
r1 &= 15;
|
|
612
|
+
} else if constexpr (prime_minus_one_over_gamma2<K>() == 88) {
|
|
613
|
+
// 1488/2^24 is close enough to 1/1488 so that r1 becomes x/(2 gamma2)
|
|
614
|
+
// rounded down.
|
|
615
|
+
r1 = (r1 * 11275 + (1 << 23)) >> 24;
|
|
616
|
+
|
|
617
|
+
// For corner-case r1 = (Q-1)/(2 gamma2) = 44, we have to set r1=0.
|
|
618
|
+
r1 ^= ((uint32_t)(((int32_t)(43 - r1)) >> 31)) & r1;
|
|
619
|
+
}
|
|
455
620
|
return r1;
|
|
456
621
|
}
|
|
457
622
|
|
|
458
623
|
// FIPS 204, Algorithm 36 (`Decompose`).
|
|
459
|
-
|
|
460
|
-
|
|
624
|
+
template <int K>
|
|
625
|
+
inline void decompose(uint32_t *r1, int32_t *r0, uint32_t r) {
|
|
626
|
+
*r1 = high_bits<K>(r);
|
|
461
627
|
|
|
462
628
|
*r0 = r;
|
|
463
|
-
*r0 -= *r1 * 2 * (int32_t)
|
|
629
|
+
*r0 -= *r1 * 2 * (int32_t)gamma2<K>();
|
|
464
630
|
*r0 -= (((int32_t)kHalfPrime - *r0) >> 31) & (int32_t)kPrime;
|
|
465
631
|
}
|
|
466
632
|
|
|
467
633
|
// FIPS 204, Algorithm 38 (`LowBits`).
|
|
468
|
-
|
|
634
|
+
template <int K>
|
|
635
|
+
inline int32_t low_bits(uint32_t x) {
|
|
469
636
|
uint32_t r1;
|
|
470
637
|
int32_t r0;
|
|
471
|
-
decompose(&r1, &r0, x);
|
|
638
|
+
decompose<K>(&r1, &r0, x);
|
|
472
639
|
return r0;
|
|
473
640
|
}
|
|
474
641
|
|
|
@@ -480,110 +647,137 @@ int32_t low_bits(uint32_t x) {
|
|
|
480
647
|
//
|
|
481
648
|
// It then computes HighBits (algorithm 37) of z and z+r. But z+r is just w -
|
|
482
649
|
// cs2, so this takes three arguments and saves an addition.
|
|
483
|
-
|
|
650
|
+
template <int K>
|
|
651
|
+
inline int32_t make_hint(uint32_t ct0, uint32_t cs2, uint32_t w) {
|
|
484
652
|
uint32_t r_plus_z = mod_sub(w, cs2);
|
|
485
653
|
uint32_t r = reduce_once(r_plus_z + ct0);
|
|
486
|
-
return high_bits(r) != high_bits(r_plus_z);
|
|
654
|
+
return high_bits<K>(r) != high_bits<K>(r_plus_z);
|
|
487
655
|
}
|
|
488
656
|
|
|
489
657
|
// FIPS 204, Algorithm 40 (`UseHint`).
|
|
490
|
-
|
|
658
|
+
template <int K>
|
|
659
|
+
inline uint32_t use_hint_vartime(uint32_t h, uint32_t r) {
|
|
491
660
|
uint32_t r1;
|
|
492
661
|
int32_t r0;
|
|
493
|
-
decompose(&r1, &r0, r);
|
|
662
|
+
decompose<K>(&r1, &r0, r);
|
|
494
663
|
|
|
495
664
|
if (h) {
|
|
496
|
-
if (
|
|
497
|
-
|
|
498
|
-
|
|
665
|
+
if constexpr (prime_minus_one_over_gamma2<K>() == 32) {
|
|
666
|
+
if (r0 > 0) {
|
|
667
|
+
// (Q-1)/(2 gamma2) = m = 16, thus `mod m` in the spec turns into
|
|
668
|
+
// `& 15`.
|
|
669
|
+
return (r1 + 1) & 15;
|
|
670
|
+
} else {
|
|
671
|
+
return (r1 - 1) & 15;
|
|
672
|
+
}
|
|
499
673
|
} else {
|
|
500
|
-
|
|
674
|
+
// m = 44
|
|
675
|
+
static_assert(prime_minus_one_over_gamma2<K>() == 88);
|
|
676
|
+
if (r0 > 0) {
|
|
677
|
+
if (r1 == 43) {
|
|
678
|
+
return 0;
|
|
679
|
+
} else {
|
|
680
|
+
return r1 + 1;
|
|
681
|
+
}
|
|
682
|
+
} else {
|
|
683
|
+
if (r1 == 0) {
|
|
684
|
+
return 43;
|
|
685
|
+
} else {
|
|
686
|
+
return r1 - 1;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
501
689
|
}
|
|
502
690
|
}
|
|
503
691
|
return r1;
|
|
504
692
|
}
|
|
505
693
|
|
|
506
|
-
void scalar_power2_round(scalar *s1, scalar *s0, const scalar *s) {
|
|
694
|
+
inline void scalar_power2_round(scalar *s1, scalar *s0, const scalar *s) {
|
|
507
695
|
for (int i = 0; i < kDegree; i++) {
|
|
508
696
|
power2_round(&s1->c[i], &s0->c[i], s->c[i]);
|
|
509
697
|
}
|
|
510
698
|
}
|
|
511
699
|
|
|
512
|
-
void scalar_scale_power2_round(scalar *out, const scalar *in) {
|
|
700
|
+
inline void scalar_scale_power2_round(scalar *out, const scalar *in) {
|
|
513
701
|
for (int i = 0; i < kDegree; i++) {
|
|
514
702
|
scale_power2_round(&out->c[i], in->c[i]);
|
|
515
703
|
}
|
|
516
704
|
}
|
|
517
705
|
|
|
518
|
-
|
|
706
|
+
template <int K>
|
|
707
|
+
inline void scalar_high_bits(scalar *out, const scalar *in) {
|
|
519
708
|
for (int i = 0; i < kDegree; i++) {
|
|
520
|
-
out->c[i] = high_bits(in->c[i]);
|
|
709
|
+
out->c[i] = high_bits<K>(in->c[i]);
|
|
521
710
|
}
|
|
522
711
|
}
|
|
523
712
|
|
|
524
|
-
|
|
713
|
+
template <int K>
|
|
714
|
+
inline void scalar_low_bits(scalar *out, const scalar *in) {
|
|
525
715
|
for (int i = 0; i < kDegree; i++) {
|
|
526
|
-
out->c[i] = low_bits(in->c[i]);
|
|
716
|
+
out->c[i] = low_bits<K>(in->c[i]);
|
|
527
717
|
}
|
|
528
718
|
}
|
|
529
719
|
|
|
530
|
-
void scalar_max(uint32_t *max, const scalar *s) {
|
|
720
|
+
inline void scalar_max(uint32_t *max, const scalar *s) {
|
|
531
721
|
for (int i = 0; i < kDegree; i++) {
|
|
532
722
|
uint32_t abs = abs_mod_prime(s->c[i]);
|
|
533
|
-
*max =
|
|
723
|
+
*max = maximum_reduced(*max, abs);
|
|
534
724
|
}
|
|
535
725
|
}
|
|
536
726
|
|
|
537
|
-
void scalar_max_signed(uint32_t *max, const scalar *s) {
|
|
727
|
+
inline void scalar_max_signed(uint32_t *max, const scalar *s) {
|
|
538
728
|
for (int i = 0; i < kDegree; i++) {
|
|
539
729
|
uint32_t abs = abs_signed(s->c[i]);
|
|
540
|
-
*max =
|
|
730
|
+
*max = maximum_reduced(*max, abs);
|
|
541
731
|
}
|
|
542
732
|
}
|
|
543
733
|
|
|
544
|
-
|
|
545
|
-
|
|
734
|
+
template <int K>
|
|
735
|
+
inline void scalar_make_hint(scalar *out, const scalar *ct0, const scalar *cs2,
|
|
736
|
+
const scalar *w) {
|
|
546
737
|
for (int i = 0; i < kDegree; i++) {
|
|
547
|
-
out->c[i] = make_hint(ct0->c[i], cs2->c[i], w->c[i]);
|
|
738
|
+
out->c[i] = make_hint<K>(ct0->c[i], cs2->c[i], w->c[i]);
|
|
548
739
|
}
|
|
549
740
|
}
|
|
550
741
|
|
|
551
|
-
|
|
742
|
+
template <int K>
|
|
743
|
+
inline void scalar_use_hint_vartime(scalar *out, const scalar *h,
|
|
744
|
+
const scalar *r) {
|
|
552
745
|
for (int i = 0; i < kDegree; i++) {
|
|
553
|
-
out->c[i] = use_hint_vartime(h->c[i], r->c[i]);
|
|
746
|
+
out->c[i] = use_hint_vartime<K>(h->c[i], r->c[i]);
|
|
554
747
|
}
|
|
555
748
|
}
|
|
556
749
|
|
|
557
750
|
template <int X>
|
|
558
|
-
void vector_power2_round(vector<X> *t1, vector<X> *t0,
|
|
751
|
+
inline void vector_power2_round(vector<X> *t1, vector<X> *t0,
|
|
752
|
+
const vector<X> *t) {
|
|
559
753
|
for (int i = 0; i < X; i++) {
|
|
560
754
|
scalar_power2_round(&t1->v[i], &t0->v[i], &t->v[i]);
|
|
561
755
|
}
|
|
562
756
|
}
|
|
563
757
|
|
|
564
758
|
template <int X>
|
|
565
|
-
void vector_scale_power2_round(vector<X> *out, const vector<X> *in) {
|
|
759
|
+
inline void vector_scale_power2_round(vector<X> *out, const vector<X> *in) {
|
|
566
760
|
for (int i = 0; i < X; i++) {
|
|
567
761
|
scalar_scale_power2_round(&out->v[i], &in->v[i]);
|
|
568
762
|
}
|
|
569
763
|
}
|
|
570
764
|
|
|
571
|
-
template <int
|
|
572
|
-
void vector_high_bits(vector<
|
|
573
|
-
for (int i = 0; i <
|
|
574
|
-
scalar_high_bits(&out->v[i], &in->v[i]);
|
|
765
|
+
template <int K>
|
|
766
|
+
inline void vector_high_bits(vector<K> *out, const vector<K> *in) {
|
|
767
|
+
for (int i = 0; i < K; i++) {
|
|
768
|
+
scalar_high_bits<K>(&out->v[i], &in->v[i]);
|
|
575
769
|
}
|
|
576
770
|
}
|
|
577
771
|
|
|
578
|
-
template <int
|
|
579
|
-
void vector_low_bits(vector<
|
|
580
|
-
for (int i = 0; i <
|
|
581
|
-
scalar_low_bits(&out->v[i], &in->v[i]);
|
|
772
|
+
template <int K>
|
|
773
|
+
inline void vector_low_bits(vector<K> *out, const vector<K> *in) {
|
|
774
|
+
for (int i = 0; i < K; i++) {
|
|
775
|
+
scalar_low_bits<K>(&out->v[i], &in->v[i]);
|
|
582
776
|
}
|
|
583
777
|
}
|
|
584
778
|
|
|
585
779
|
template <int X>
|
|
586
|
-
uint32_t vector_max(const vector<X> *a) {
|
|
780
|
+
inline uint32_t vector_max(const vector<X> *a) {
|
|
587
781
|
uint32_t max = 0;
|
|
588
782
|
for (int i = 0; i < X; i++) {
|
|
589
783
|
scalar_max(&max, &a->v[i]);
|
|
@@ -592,7 +786,7 @@ uint32_t vector_max(const vector<X> *a) {
|
|
|
592
786
|
}
|
|
593
787
|
|
|
594
788
|
template <int X>
|
|
595
|
-
uint32_t vector_max_signed(const vector<X> *a) {
|
|
789
|
+
inline uint32_t vector_max_signed(const vector<X> *a) {
|
|
596
790
|
uint32_t max = 0;
|
|
597
791
|
for (int i = 0; i < X; i++) {
|
|
598
792
|
scalar_max_signed(&max, &a->v[i]);
|
|
@@ -602,7 +796,7 @@ uint32_t vector_max_signed(const vector<X> *a) {
|
|
|
602
796
|
|
|
603
797
|
// The input vector contains only zeroes and ones.
|
|
604
798
|
template <int X>
|
|
605
|
-
size_t vector_count_ones(const vector<X> *a) {
|
|
799
|
+
inline size_t vector_count_ones(const vector<X> *a) {
|
|
606
800
|
size_t count = 0;
|
|
607
801
|
for (int i = 0; i < X; i++) {
|
|
608
802
|
for (int j = 0; j < kDegree; j++) {
|
|
@@ -612,26 +806,30 @@ size_t vector_count_ones(const vector<X> *a) {
|
|
|
612
806
|
return count;
|
|
613
807
|
}
|
|
614
808
|
|
|
615
|
-
template <int
|
|
616
|
-
void vector_make_hint(vector<
|
|
617
|
-
|
|
618
|
-
for (int i = 0; i <
|
|
619
|
-
scalar_make_hint(&out->v[i], &ct0->v[i], &cs2->v[i], &w->v[i]);
|
|
809
|
+
template <int K>
|
|
810
|
+
inline void vector_make_hint(vector<K> *out, const vector<K> *ct0,
|
|
811
|
+
const vector<K> *cs2, const vector<K> *w) {
|
|
812
|
+
for (int i = 0; i < K; i++) {
|
|
813
|
+
scalar_make_hint<K>(&out->v[i], &ct0->v[i], &cs2->v[i], &w->v[i]);
|
|
620
814
|
}
|
|
621
815
|
}
|
|
622
816
|
|
|
623
|
-
template <int
|
|
624
|
-
void vector_use_hint_vartime(vector<
|
|
625
|
-
|
|
626
|
-
for (int i = 0; i <
|
|
627
|
-
scalar_use_hint_vartime(&out->v[i], &h->v[i], &r->v[i]);
|
|
817
|
+
template <int K>
|
|
818
|
+
inline void vector_use_hint_vartime(vector<K> *out, const vector<K> *h,
|
|
819
|
+
const vector<K> *r) {
|
|
820
|
+
for (int i = 0; i < K; i++) {
|
|
821
|
+
scalar_use_hint_vartime<K>(&out->v[i], &h->v[i], &r->v[i]);
|
|
628
822
|
}
|
|
629
823
|
}
|
|
630
824
|
|
|
631
825
|
/* Bit packing */
|
|
632
826
|
|
|
827
|
+
template <int bits>
|
|
828
|
+
inline void scalar_encode(uint8_t *out, const scalar *s);
|
|
829
|
+
|
|
633
830
|
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 4.
|
|
634
|
-
|
|
831
|
+
template <>
|
|
832
|
+
inline void scalar_encode<4>(uint8_t out[128], const scalar *s) {
|
|
635
833
|
// Every two elements lands on a byte boundary.
|
|
636
834
|
static_assert(kDegree % 2 == 0, "kDegree must be a multiple of 2");
|
|
637
835
|
for (int i = 0; i < kDegree / 2; i++) {
|
|
@@ -643,8 +841,29 @@ static void scalar_encode_4(uint8_t out[128], const scalar *s) {
|
|
|
643
841
|
}
|
|
644
842
|
}
|
|
645
843
|
|
|
844
|
+
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 6.
|
|
845
|
+
template <>
|
|
846
|
+
inline void scalar_encode<6>(uint8_t out[192], const scalar *s) {
|
|
847
|
+
// Every four elements lands on a byte boundary.
|
|
848
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
849
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
850
|
+
uint32_t a = s->c[4 * i];
|
|
851
|
+
uint32_t b = s->c[4 * i + 1];
|
|
852
|
+
uint32_t c = s->c[4 * i + 2];
|
|
853
|
+
uint32_t d = s->c[4 * i + 3];
|
|
854
|
+
declassify_assert(a < 64);
|
|
855
|
+
declassify_assert(b < 64);
|
|
856
|
+
declassify_assert(c < 64);
|
|
857
|
+
declassify_assert(d < 64);
|
|
858
|
+
out[3 * i] = a | (b << 6);
|
|
859
|
+
out[3 * i + 1] = (b >> 2) | (c << 4);
|
|
860
|
+
out[3 * i + 2] = (c >> 4) | (d << 2);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
646
864
|
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 10.
|
|
647
|
-
|
|
865
|
+
template <>
|
|
866
|
+
inline void scalar_encode<10>(uint8_t out[320], const scalar *s) {
|
|
648
867
|
// Every four elements lands on a byte boundary.
|
|
649
868
|
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
650
869
|
for (int i = 0; i < kDegree / 4; i++) {
|
|
@@ -664,8 +883,12 @@ void scalar_encode_10(uint8_t out[320], const scalar *s) {
|
|
|
664
883
|
}
|
|
665
884
|
}
|
|
666
885
|
|
|
886
|
+
template <int bits, uint32_t max>
|
|
887
|
+
inline void scalar_encode_signed(uint8_t *out, const scalar *s);
|
|
888
|
+
|
|
667
889
|
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 4 and b = 4.
|
|
668
|
-
|
|
890
|
+
template <>
|
|
891
|
+
inline void scalar_encode_signed<4, 4>(uint8_t out[128], const scalar *s) {
|
|
669
892
|
// Every two elements lands on a byte boundary.
|
|
670
893
|
static_assert(kDegree % 2 == 0, "kDegree must be a multiple of 2");
|
|
671
894
|
for (int i = 0; i < kDegree / 2; i++) {
|
|
@@ -678,7 +901,8 @@ void scalar_encode_signed_4_4(uint8_t out[128], const scalar *s) {
|
|
|
678
901
|
}
|
|
679
902
|
|
|
680
903
|
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 3 and b = 2.
|
|
681
|
-
|
|
904
|
+
template <>
|
|
905
|
+
inline void scalar_encode_signed<3, 2>(uint8_t out[96], const scalar *s) {
|
|
682
906
|
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
683
907
|
for (int i = 0; i < kDegree / 8; i++) {
|
|
684
908
|
uint32_t a = mod_sub(2, s->c[8 * i]);
|
|
@@ -699,7 +923,9 @@ static void scalar_encode_signed_3_2(uint8_t out[96], const scalar *s) {
|
|
|
699
923
|
|
|
700
924
|
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 13 and b =
|
|
701
925
|
// 2^12.
|
|
702
|
-
|
|
926
|
+
template <>
|
|
927
|
+
inline void scalar_encode_signed<13, (1u << 12)>(uint8_t out[416],
|
|
928
|
+
const scalar *s) {
|
|
703
929
|
static const uint32_t kMax = 1u << 12;
|
|
704
930
|
// Every two elements lands on a byte boundary.
|
|
705
931
|
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
@@ -730,16 +956,18 @@ void scalar_encode_signed_13_12(uint8_t out[416], const scalar *s) {
|
|
|
730
956
|
e |= g << 14;
|
|
731
957
|
e |= h << 27;
|
|
732
958
|
h >>= 5;
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
959
|
+
CRYPTO_store_u32_le(&out[13 * i], a);
|
|
960
|
+
CRYPTO_store_u32_le(&out[13 * i + 4], c);
|
|
961
|
+
CRYPTO_store_u32_le(&out[13 * i + 8], e);
|
|
962
|
+
out[13 * i + 12] = static_cast<uint8_t>(h);
|
|
737
963
|
}
|
|
738
964
|
}
|
|
739
965
|
|
|
740
966
|
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 20 and b =
|
|
741
967
|
// 2^19.
|
|
742
|
-
|
|
968
|
+
template <>
|
|
969
|
+
inline void scalar_encode_signed<20, (1u << 19)>(uint8_t out[640],
|
|
970
|
+
const scalar *s) {
|
|
743
971
|
static const uint32_t kMax = 1u << 19;
|
|
744
972
|
// Every two elements lands on a byte boundary.
|
|
745
973
|
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
@@ -757,37 +985,49 @@ void scalar_encode_signed_20_19(uint8_t out[640], const scalar *s) {
|
|
|
757
985
|
b |= c << 8;
|
|
758
986
|
b |= d << 28;
|
|
759
987
|
d >>= 4;
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
988
|
+
CRYPTO_store_u32_le(&out[10 * i], a);
|
|
989
|
+
CRYPTO_store_u32_le(&out[10 * i + 4], b);
|
|
990
|
+
CRYPTO_store_u16_le(&out[10 * i + 8], static_cast<uint16_t>(d));
|
|
763
991
|
}
|
|
764
992
|
}
|
|
765
993
|
|
|
766
|
-
// FIPS 204, Algorithm 17 (`BitPack`).
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
994
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 18 and b =
|
|
995
|
+
// 2^17.
|
|
996
|
+
template <>
|
|
997
|
+
inline void scalar_encode_signed<18, (1u << 17)>(uint8_t out[576],
|
|
998
|
+
const scalar *s) {
|
|
999
|
+
static const uint32_t kMax = 1u << 17;
|
|
1000
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
1001
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
1002
|
+
uint32_t a = mod_sub(kMax, s->c[4 * i]);
|
|
1003
|
+
uint32_t b = mod_sub(kMax, s->c[4 * i + 1]);
|
|
1004
|
+
uint32_t c = mod_sub(kMax, s->c[4 * i + 2]);
|
|
1005
|
+
uint32_t d = mod_sub(kMax, s->c[4 * i + 3]);
|
|
1006
|
+
declassify_assert(a < (1u << 18));
|
|
1007
|
+
declassify_assert(b < (1u << 18));
|
|
1008
|
+
declassify_assert(c < (1u << 18));
|
|
1009
|
+
declassify_assert(d < (1u << 18));
|
|
1010
|
+
out[9 * i] = (uint8_t)a;
|
|
1011
|
+
out[9 * i + 1] = (uint8_t)(a >> 8);
|
|
1012
|
+
out[9 * i + 2] = (uint8_t)(a >> 16) | (uint8_t)(b << 2);
|
|
1013
|
+
out[9 * i + 3] = (uint8_t)(b >> 6);
|
|
1014
|
+
out[9 * i + 4] = (uint8_t)(b >> 14) | (uint8_t)(c << 4);
|
|
1015
|
+
out[9 * i + 5] = (uint8_t)(c >> 4);
|
|
1016
|
+
out[9 * i + 6] = (uint8_t)(c >> 12) | (uint8_t)(d << 6);
|
|
1017
|
+
out[9 * i + 7] = (uint8_t)(d >> 2);
|
|
1018
|
+
out[9 * i + 8] = (uint8_t)(d >> 10);
|
|
782
1019
|
}
|
|
783
1020
|
}
|
|
784
1021
|
|
|
1022
|
+
template <int bits>
|
|
1023
|
+
inline void scalar_decode(scalar *out, const uint8_t *in);
|
|
1024
|
+
|
|
785
1025
|
// FIPS 204, Algorithm 18 (`SimpleBitUnpack`). Specialized for bitlen(b) == 10.
|
|
786
|
-
|
|
787
|
-
|
|
1026
|
+
template <>
|
|
1027
|
+
inline void scalar_decode<10>(scalar *out, const uint8_t in[320]) {
|
|
788
1028
|
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
789
1029
|
for (int i = 0; i < kDegree / 4; i++) {
|
|
790
|
-
|
|
1030
|
+
uint32_t v = CRYPTO_load_u32_le(&in[5 * i]);
|
|
791
1031
|
out->c[4 * i] = v & 0x3ff;
|
|
792
1032
|
out->c[4 * i + 1] = (v >> 10) & 0x3ff;
|
|
793
1033
|
out->c[4 * i + 2] = (v >> 20) & 0x3ff;
|
|
@@ -795,13 +1035,16 @@ void scalar_decode_10(scalar *out, const uint8_t in[320]) {
|
|
|
795
1035
|
}
|
|
796
1036
|
}
|
|
797
1037
|
|
|
1038
|
+
template <int bits, uint32_t max>
|
|
1039
|
+
inline int scalar_decode_signed(scalar *out, const uint8_t *in);
|
|
1040
|
+
|
|
798
1041
|
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 4 and b =
|
|
799
1042
|
// 4.
|
|
800
|
-
|
|
801
|
-
|
|
1043
|
+
template <>
|
|
1044
|
+
inline int scalar_decode_signed<4, 4>(scalar *out, const uint8_t in[128]) {
|
|
802
1045
|
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
803
1046
|
for (int i = 0; i < kDegree / 8; i++) {
|
|
804
|
-
|
|
1047
|
+
uint32_t v = CRYPTO_load_u32_le(&in[4 * i]);
|
|
805
1048
|
// None of the nibbles may be >= 9. So if the MSB of any nibble is set, none
|
|
806
1049
|
// of the other bits may be set. First, select all the MSBs.
|
|
807
1050
|
const uint32_t msbs = v & 0x88888888u;
|
|
@@ -827,7 +1070,8 @@ int scalar_decode_signed_4_4(scalar *out, const uint8_t in[128]) {
|
|
|
827
1070
|
|
|
828
1071
|
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 3 and b =
|
|
829
1072
|
// 2.
|
|
830
|
-
|
|
1073
|
+
template <>
|
|
1074
|
+
inline int scalar_decode_signed<3, 2>(scalar *out, const uint8_t in[96]) {
|
|
831
1075
|
uint32_t v;
|
|
832
1076
|
uint8_t v_bytes[sizeof(v)] = {0};
|
|
833
1077
|
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
@@ -860,19 +1104,19 @@ static int scalar_decode_signed_3_2(scalar *out, const uint8_t in[96]) {
|
|
|
860
1104
|
|
|
861
1105
|
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 13 and b =
|
|
862
1106
|
// 2^12.
|
|
863
|
-
|
|
1107
|
+
template <>
|
|
1108
|
+
inline int scalar_decode_signed<13, (1u << 12)>(scalar *out,
|
|
1109
|
+
const uint8_t in[416]) {
|
|
864
1110
|
static const uint32_t kMax = 1u << 12;
|
|
865
1111
|
static const uint32_t k13Bits = (1u << 13) - 1;
|
|
866
1112
|
static const uint32_t k7Bits = (1u << 7) - 1;
|
|
867
1113
|
|
|
868
|
-
uint32_t a, b, c;
|
|
869
|
-
uint8_t d;
|
|
870
1114
|
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
871
1115
|
for (int i = 0; i < kDegree / 8; i++) {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
d = in[13 * i + 12];
|
|
1116
|
+
uint32_t a = CRYPTO_load_u32_le(&in[13 * i]);
|
|
1117
|
+
uint32_t b = CRYPTO_load_u32_le(&in[13 * i + 4]);
|
|
1118
|
+
uint32_t c = CRYPTO_load_u32_le(&in[13 * i + 8]);
|
|
1119
|
+
uint8_t d = in[13 * i + 12];
|
|
876
1120
|
|
|
877
1121
|
// It's not possible for a 13-bit number to be out of range when the max is
|
|
878
1122
|
// 2^12.
|
|
@@ -885,21 +1129,51 @@ void scalar_decode_signed_13_12(scalar *out, const uint8_t in[416]) {
|
|
|
885
1129
|
out->c[i * 8 + 6] = mod_sub(kMax, (c >> 14) & k13Bits);
|
|
886
1130
|
out->c[i * 8 + 7] = mod_sub(kMax, (c >> 27) | ((uint32_t)d) << 5);
|
|
887
1131
|
}
|
|
1132
|
+
return 1;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 18 and b =
|
|
1136
|
+
// 2^17.
|
|
1137
|
+
template <>
|
|
1138
|
+
inline int scalar_decode_signed<18, (1u << 17)>(scalar *out,
|
|
1139
|
+
const uint8_t in[576]) {
|
|
1140
|
+
static const uint32_t kMax = 1u << 17;
|
|
1141
|
+
|
|
1142
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
1143
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
1144
|
+
uint32_t a = uint32_t{in[9 * i]} | (uint32_t{in[9 * i + 1]} << 8) |
|
|
1145
|
+
((uint32_t{in[9 * i + 2]} & 0x3) << 16);
|
|
1146
|
+
uint32_t b = (uint32_t{in[9 * i + 2]} >> 2) |
|
|
1147
|
+
(uint32_t{in[9 * i + 3]} << 6) |
|
|
1148
|
+
((uint32_t{in[9 * i + 4]} & 0xf) << 14);
|
|
1149
|
+
uint32_t c = (uint32_t{in[9 * i + 4]} >> 4) |
|
|
1150
|
+
(uint32_t{in[9 * i + 5]} << 4) |
|
|
1151
|
+
((uint32_t{in[9 * i + 6]} & 0x3f) << 12);
|
|
1152
|
+
uint32_t d = (uint32_t{in[9 * i + 6]} >> 6) |
|
|
1153
|
+
(uint32_t{in[9 * i + 7]} << 2) |
|
|
1154
|
+
(uint32_t{in[9 * i + 8]} << 10);
|
|
1155
|
+
|
|
1156
|
+
out->c[i * 4] = mod_sub(kMax, a);
|
|
1157
|
+
out->c[i * 4 + 1] = mod_sub(kMax, b);
|
|
1158
|
+
out->c[i * 4 + 2] = mod_sub(kMax, c);
|
|
1159
|
+
out->c[i * 4 + 3] = mod_sub(kMax, d);
|
|
1160
|
+
}
|
|
1161
|
+
return 1;
|
|
888
1162
|
}
|
|
889
1163
|
|
|
890
1164
|
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 20 and b =
|
|
891
1165
|
// 2^19.
|
|
892
|
-
|
|
1166
|
+
template <>
|
|
1167
|
+
inline int scalar_decode_signed<20, (1u << 19)>(scalar *out,
|
|
1168
|
+
const uint8_t in[640]) {
|
|
893
1169
|
static const uint32_t kMax = 1u << 19;
|
|
894
1170
|
static const uint32_t k20Bits = (1u << 20) - 1;
|
|
895
1171
|
|
|
896
|
-
uint32_t a, b;
|
|
897
|
-
uint16_t c;
|
|
898
1172
|
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
899
1173
|
for (int i = 0; i < kDegree / 4; i++) {
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1174
|
+
uint32_t a = CRYPTO_load_u32_le(&in[10 * i]);
|
|
1175
|
+
uint32_t b = CRYPTO_load_u32_le(&in[10 * i + 4]);
|
|
1176
|
+
uint16_t c = CRYPTO_load_u16_le(&in[10 * i + 8]);
|
|
903
1177
|
|
|
904
1178
|
// It's not possible for a 20-bit number to be out of range when the max is
|
|
905
1179
|
// 2^19.
|
|
@@ -908,29 +1182,10 @@ void scalar_decode_signed_20_19(scalar *out, const uint8_t in[640]) {
|
|
|
908
1182
|
out->c[i * 4 + 2] = mod_sub(kMax, (b >> 8) & k20Bits);
|
|
909
1183
|
out->c[i * 4 + 3] = mod_sub(kMax, (b >> 28) | ((uint32_t)c) << 4);
|
|
910
1184
|
}
|
|
1185
|
+
return 1;
|
|
911
1186
|
}
|
|
912
1187
|
|
|
913
|
-
|
|
914
|
-
int scalar_decode_signed(scalar *out, const uint8_t *in, int bits,
|
|
915
|
-
uint32_t max) {
|
|
916
|
-
if (bits == 3) {
|
|
917
|
-
assert(max == 2);
|
|
918
|
-
return scalar_decode_signed_3_2(out, in);
|
|
919
|
-
} else if (bits == 4) {
|
|
920
|
-
assert(max == 4);
|
|
921
|
-
return scalar_decode_signed_4_4(out, in);
|
|
922
|
-
} else if (bits == 13) {
|
|
923
|
-
assert(max == (1u << 12));
|
|
924
|
-
scalar_decode_signed_13_12(out, in);
|
|
925
|
-
return 1;
|
|
926
|
-
} else if (bits == 20) {
|
|
927
|
-
assert(max == (1u << 19));
|
|
928
|
-
scalar_decode_signed_20_19(out, in);
|
|
929
|
-
return 1;
|
|
930
|
-
} else {
|
|
931
|
-
abort();
|
|
932
|
-
}
|
|
933
|
-
}
|
|
1188
|
+
|
|
934
1189
|
|
|
935
1190
|
/* Expansion functions */
|
|
936
1191
|
|
|
@@ -938,97 +1193,219 @@ int scalar_decode_signed(scalar *out, const uint8_t *in, int bits,
|
|
|
938
1193
|
//
|
|
939
1194
|
// Rejection samples a Keccak stream to get uniformly distributed elements. This
|
|
940
1195
|
// is used for matrix expansion and only operates on public inputs.
|
|
941
|
-
void
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1196
|
+
inline void scalar_from_keccak_block_vartime(scalar *out, int *done,
|
|
1197
|
+
const uint8_t block[168]) {
|
|
1198
|
+
// kStep is the number of loop iterations to do at once. May need to become
|
|
1199
|
+
// platform dependent at some point. Must be a compile-time constant - if we
|
|
1200
|
+
// ever need to runtime dispatch on it, it has to be made a template argument.
|
|
1201
|
+
const size_t kStep = 2;
|
|
1202
|
+
|
|
1203
|
+
// Branchless sampling as long as there is enough space in the output buffer
|
|
1204
|
+
// even if all sampled numbers are < `kPrime`.
|
|
1205
|
+
size_t i = 0;
|
|
1206
|
+
for (; i <= size_t{168 - 3 * kStep} && *done <= int{kDegree - kStep};
|
|
1207
|
+
i += 3 * kStep) {
|
|
1208
|
+
uint32_t d[kStep];
|
|
1209
|
+
for (size_t k = 0; k < kStep; ++k) {
|
|
1210
|
+
size_t bi = i + 3 * k;
|
|
1211
|
+
d[k] = (uint32_t)block[bi] | ((uint32_t)block[bi + 1] << 8) |
|
|
1212
|
+
(((uint32_t)block[bi + 2] & 0x7f) << 16);
|
|
1213
|
+
}
|
|
1214
|
+
for (size_t k = 0; k < kStep; ++k) {
|
|
1215
|
+
out->c[*done] = d[k];
|
|
1216
|
+
*done += d[k] < kPrime;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// Branchful "tail".
|
|
1221
|
+
for (; i < 168 && *done < kDegree; i += 3) {
|
|
1222
|
+
// FIPS 204, Algorithm 14 (`CoeffFromThreeBytes`).
|
|
1223
|
+
uint32_t value = (uint32_t)block[i] | ((uint32_t)block[i + 1] << 8) |
|
|
1224
|
+
(((uint32_t)block[i + 2] & 0x7f) << 16);
|
|
1225
|
+
if (value < kPrime) {
|
|
1226
|
+
out->c[(*done)++] = value;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// FIPS 204, Algorithm 30 (`RejNTTPoly`).
|
|
1232
|
+
//
|
|
1233
|
+
// Rejection samples a Keccak stream to get uniformly distributed elements. This
|
|
1234
|
+
// is used for matrix expansion and only operates on public inputs.
|
|
1235
|
+
inline void scalar_from_keccak_vartime(scalar *out,
|
|
1236
|
+
BORINGSSL_keccak_st *keccak_ctx) {
|
|
1237
|
+
assert(keccak_ctx->squeeze_offset == 0);
|
|
1238
|
+
assert(keccak_ctx->rate_bytes == 168);
|
|
948
1239
|
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
|
949
1240
|
|
|
950
1241
|
int done = 0;
|
|
951
1242
|
while (done < kDegree) {
|
|
952
1243
|
uint8_t block[168];
|
|
953
|
-
BORINGSSL_keccak_squeeze(
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1244
|
+
BORINGSSL_keccak_squeeze(keccak_ctx, block, sizeof(block));
|
|
1245
|
+
scalar_from_keccak_block_vartime(out, &done, block);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1250
|
+
inline void scalar_from_keccak_vartime_x2(scalar *out[2],
|
|
1251
|
+
BORINGSSL_keccak_st keccak_ctx[2]) {
|
|
1252
|
+
assert(keccak_ctx[0].squeeze_offset == 0);
|
|
1253
|
+
assert(keccak_ctx[0].rate_bytes == 168);
|
|
1254
|
+
assert(keccak_ctx[1].squeeze_offset == 0);
|
|
1255
|
+
assert(keccak_ctx[1].rate_bytes == 168);
|
|
1256
|
+
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
|
1257
|
+
|
|
1258
|
+
int done[2] = {0, 0};
|
|
1259
|
+
while (done[0] < kDegree || done[1] < kDegree) {
|
|
1260
|
+
uint8_t block[2][168];
|
|
1261
|
+
uint8_t *blocks[] = {block[0], block[1]};
|
|
1262
|
+
BORINGSSL_keccak_squeeze_x2(keccak_ctx, blocks, sizeof(block[0]));
|
|
1263
|
+
scalar_from_keccak_block_vartime(out[0], &done[0], block[0]);
|
|
1264
|
+
scalar_from_keccak_block_vartime(out[1], &done[1], block[1]);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
#endif
|
|
1268
|
+
|
|
1269
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1270
|
+
inline void scalar_from_keccak_vartime_x4(scalar *out[4],
|
|
1271
|
+
BORINGSSL_keccak_st keccak_ctx[]) {
|
|
1272
|
+
for (int i = 0; i < 4; i++) {
|
|
1273
|
+
assert(keccak_ctx[i].squeeze_offset == 0);
|
|
1274
|
+
assert(keccak_ctx[i].rate_bytes == 168);
|
|
1275
|
+
}
|
|
1276
|
+
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
|
1277
|
+
|
|
1278
|
+
int done[4] = {0, 0, 0, 0};
|
|
1279
|
+
while (done[0] < kDegree || done[1] < kDegree || done[2] < kDegree ||
|
|
1280
|
+
done[3] < kDegree) {
|
|
1281
|
+
uint8_t block[4][168];
|
|
1282
|
+
uint8_t *blocks[] = {block[0], block[1], block[2], block[3]};
|
|
1283
|
+
BORINGSSL_keccak_squeeze_x4(keccak_ctx, blocks, sizeof(block[0]));
|
|
1284
|
+
scalar_from_keccak_block_vartime(out[0], &done[0], block[0]);
|
|
1285
|
+
scalar_from_keccak_block_vartime(out[1], &done[1], block[1]);
|
|
1286
|
+
scalar_from_keccak_block_vartime(out[2], &done[2], block[2]);
|
|
1287
|
+
scalar_from_keccak_block_vartime(out[3], &done[3], block[3]);
|
|
962
1288
|
}
|
|
963
1289
|
}
|
|
1290
|
+
#endif
|
|
964
1291
|
|
|
965
1292
|
template <int ETA>
|
|
966
|
-
|
|
1293
|
+
inline bool coefficient_from_nibble(uint32_t nibble, uint32_t *result);
|
|
967
1294
|
|
|
968
1295
|
template <>
|
|
969
|
-
bool coefficient_from_nibble<4>(uint32_t nibble, uint32_t *result) {
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return false;
|
|
1296
|
+
inline bool coefficient_from_nibble<4>(uint32_t nibble, uint32_t *result) {
|
|
1297
|
+
// Knowing bounds on `nibble` seems to tempt some versions of Clang to emit
|
|
1298
|
+
// a branch, if we don't have a barrier in `mod_sub`.
|
|
1299
|
+
*result = mod_sub(4, value_barrier_u32(nibble));
|
|
1300
|
+
return constant_time_declassify_int(nibble < 9);
|
|
975
1301
|
}
|
|
976
1302
|
|
|
977
1303
|
template <>
|
|
978
|
-
bool coefficient_from_nibble<2>(uint32_t nibble, uint32_t *result) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1304
|
+
inline bool coefficient_from_nibble<2>(uint32_t nibble, uint32_t *result) {
|
|
1305
|
+
// Knowing bounds on `nibble` seems to tempt some versions of Clang to emit
|
|
1306
|
+
// a branch, if we don't have a barrier in `mod_sub`.
|
|
1307
|
+
// Constant time "nibble % 5".
|
|
1308
|
+
uint32_t rem = nibble - 5 * ((205 * nibble) >> 10);
|
|
1309
|
+
*result = mod_sub(2, value_barrier_u32(rem));
|
|
1310
|
+
return constant_time_declassify_int(nibble < 15);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
template <int ETA>
|
|
1314
|
+
inline void scalar_uniform_block(scalar *out, int *done,
|
|
1315
|
+
const uint8_t block[136]) {
|
|
1316
|
+
for (size_t i = 0; i < 136 && *done < kDegree; ++i) {
|
|
1317
|
+
uint32_t t0 = block[i] & 0x0F;
|
|
1318
|
+
uint32_t t1 = block[i] >> 4;
|
|
1319
|
+
// FIPS 204, Algorithm 15 (`CoefFromHalfByte`). Although both the input
|
|
1320
|
+
// and output here are secret, it is OK to leak when we rejected a byte.
|
|
1321
|
+
// Individual bytes of the SHAKE-256 stream are (indistinguishable from)
|
|
1322
|
+
// independent of each other and the original seed, so leaking information
|
|
1323
|
+
// about the rejected bytes does not reveal the input or output.
|
|
1324
|
+
*done += coefficient_from_nibble<ETA>(t0, &out->c[*done]);
|
|
1325
|
+
if (*done < kDegree) {
|
|
1326
|
+
*done += coefficient_from_nibble<ETA>(t1, &out->c[*done]);
|
|
1327
|
+
}
|
|
982
1328
|
}
|
|
983
|
-
return false;
|
|
984
1329
|
}
|
|
985
1330
|
|
|
986
1331
|
// FIPS 204, Algorithm 31 (`RejBoundedPoly`).
|
|
987
1332
|
template <int ETA>
|
|
988
|
-
void scalar_uniform(scalar *out,
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, derived_seed, kSigmaBytes + 2);
|
|
992
|
-
assert(keccak_ctx.squeeze_offset == 0);
|
|
993
|
-
assert(keccak_ctx.rate_bytes == 136);
|
|
1333
|
+
inline void scalar_uniform(scalar *out, BORINGSSL_keccak_st *keccak_ctx) {
|
|
1334
|
+
assert(keccak_ctx->squeeze_offset == 0);
|
|
1335
|
+
assert(keccak_ctx->rate_bytes == 136);
|
|
994
1336
|
|
|
995
1337
|
int done = 0;
|
|
996
1338
|
while (done < kDegree) {
|
|
997
1339
|
uint8_t block[136];
|
|
998
|
-
BORINGSSL_keccak_squeeze(
|
|
999
|
-
|
|
1000
|
-
uint32_t t0 = block[i] & 0x0F;
|
|
1001
|
-
uint32_t t1 = block[i] >> 4;
|
|
1002
|
-
// FIPS 204, Algorithm 15 (`CoefFromHalfByte`). Although both the input
|
|
1003
|
-
// and output here are secret, it is OK to leak when we rejected a byte.
|
|
1004
|
-
// Individual bytes of the SHAKE-256 stream are (indistiguishable from)
|
|
1005
|
-
// independent of each other and the original seed, so leaking information
|
|
1006
|
-
// about the rejected bytes does not reveal the input or output.
|
|
1007
|
-
uint32_t v;
|
|
1008
|
-
if (coefficient_from_nibble<ETA>(t0, &v)) {
|
|
1009
|
-
out->c[done++] = v;
|
|
1010
|
-
}
|
|
1011
|
-
if (done < kDegree && coefficient_from_nibble<ETA>(t1, &v)) {
|
|
1012
|
-
out->c[done++] = v;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1340
|
+
BORINGSSL_keccak_squeeze(keccak_ctx, block, sizeof(block));
|
|
1341
|
+
scalar_uniform_block<ETA>(out, &done, block);
|
|
1015
1342
|
}
|
|
1016
1343
|
}
|
|
1017
1344
|
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1345
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1346
|
+
template <int ETA>
|
|
1347
|
+
inline void scalar_uniform_x2(scalar *out[2],
|
|
1348
|
+
BORINGSSL_keccak_st keccak_ctx[2]) {
|
|
1349
|
+
assert(keccak_ctx[0].squeeze_offset == 0);
|
|
1350
|
+
assert(keccak_ctx[0].rate_bytes == 136);
|
|
1351
|
+
assert(keccak_ctx[1].squeeze_offset == 0);
|
|
1352
|
+
assert(keccak_ctx[1].rate_bytes == 136);
|
|
1353
|
+
|
|
1354
|
+
int done[2] = {0, 0};
|
|
1355
|
+
while (done[0] < kDegree || done[1] < kDegree) {
|
|
1356
|
+
uint8_t block[2][136];
|
|
1357
|
+
uint8_t *blocks[] = {block[0], block[1]};
|
|
1358
|
+
BORINGSSL_keccak_squeeze_x2(keccak_ctx, blocks, sizeof(block[0]));
|
|
1359
|
+
scalar_uniform_block<ETA>(out[0], &done[0], block[0]);
|
|
1360
|
+
scalar_uniform_block<ETA>(out[1], &done[1], block[1]);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
#endif
|
|
1364
|
+
|
|
1365
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1366
|
+
template <int ETA>
|
|
1367
|
+
inline void scalar_uniform_x4(scalar *out[4],
|
|
1368
|
+
BORINGSSL_keccak_st keccak_ctx[]) {
|
|
1369
|
+
for (int i = 0; i < 4; i++) {
|
|
1370
|
+
assert(keccak_ctx[i].squeeze_offset == 0);
|
|
1371
|
+
assert(keccak_ctx[i].rate_bytes == 136);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
int done[4] = {0, 0, 0, 0};
|
|
1375
|
+
while (done[0] < kDegree || done[1] < kDegree || done[2] < kDegree ||
|
|
1376
|
+
done[3] < kDegree) {
|
|
1377
|
+
uint8_t block[4][136];
|
|
1378
|
+
uint8_t *blocks[] = {block[0], block[1], block[2], block[3]};
|
|
1379
|
+
BORINGSSL_keccak_squeeze_x4(keccak_ctx, blocks, sizeof(block[0]));
|
|
1380
|
+
scalar_uniform_block<ETA>(out[0], &done[0], block[0]);
|
|
1381
|
+
scalar_uniform_block<ETA>(out[1], &done[1], block[1]);
|
|
1382
|
+
scalar_uniform_block<ETA>(out[2], &done[2], block[2]);
|
|
1383
|
+
scalar_uniform_block<ETA>(out[3], &done[3], block[3]);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
#endif
|
|
1024
1387
|
|
|
1025
|
-
|
|
1388
|
+
// FIPS 204, Algorithm 34 (`ExpandMask`), but just a single step.
|
|
1389
|
+
template <int K>
|
|
1390
|
+
inline void scalar_sample_mask(scalar *out,
|
|
1391
|
+
const uint8_t rho_prime[kRhoPrimeBytes],
|
|
1392
|
+
size_t index) {
|
|
1393
|
+
uint8_t buf[scalar_le_gamma1_bytes<K>()];
|
|
1394
|
+
struct BORINGSSL_keccak_st ctx;
|
|
1395
|
+
BORINGSSL_keccak_init(&ctx, boringssl_shake256);
|
|
1396
|
+
BORINGSSL_keccak_absorb(&ctx, rho_prime, kRhoPrimeBytes);
|
|
1397
|
+
uint8_t index_buf[2];
|
|
1398
|
+
index_buf[0] = static_cast<uint8_t>(index);
|
|
1399
|
+
index_buf[1] = static_cast<uint8_t>(index >> 8);
|
|
1400
|
+
BORINGSSL_keccak_absorb(&ctx, index_buf, 2);
|
|
1401
|
+
BORINGSSL_keccak_squeeze(&ctx, buf, sizeof(buf));
|
|
1402
|
+
scalar_decode_signed<gamma1_bits<K>() + 1, gamma1<K>()>(out, buf);
|
|
1026
1403
|
}
|
|
1027
1404
|
|
|
1028
1405
|
// FIPS 204, Algorithm 29 (`SampleInBall`).
|
|
1029
|
-
void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed,
|
|
1030
|
-
|
|
1031
|
-
|
|
1406
|
+
inline void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed,
|
|
1407
|
+
int len, int tau) {
|
|
1408
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1032
1409
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1033
1410
|
BORINGSSL_keccak_absorb(&keccak_ctx, seed, len);
|
|
1034
1411
|
assert(keccak_ctx.squeeze_offset == 0);
|
|
@@ -1068,58 +1445,194 @@ void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed, int len,
|
|
|
1068
1445
|
}
|
|
1069
1446
|
}
|
|
1070
1447
|
|
|
1071
|
-
// FIPS 204, Algorithm 32 (`ExpandA`).
|
|
1072
1448
|
template <int K, int L>
|
|
1073
|
-
void
|
|
1449
|
+
inline void matrix_expand_step(scalar *out, const uint8_t rho[kRhoBytes],
|
|
1450
|
+
int index) {
|
|
1451
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1452
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake128);
|
|
1453
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, rho, kRhoBytes);
|
|
1454
|
+
uint8_t index_buf[2];
|
|
1455
|
+
index_buf[0] = static_cast<uint8_t>(index % L);
|
|
1456
|
+
index_buf[1] = static_cast<uint8_t>(index / L);
|
|
1457
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, index_buf, 2);
|
|
1458
|
+
scalar_from_keccak_vartime(out, &keccak_ctx);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1462
|
+
template <int K, int L>
|
|
1463
|
+
inline void matrix_expand_step_x2(matrix<K, L> *out,
|
|
1464
|
+
const uint8_t rho[kRhoBytes], int index) {
|
|
1465
|
+
BORINGSSL_keccak_st keccak_ctx[2];
|
|
1466
|
+
BORINGSSL_keccak_init(&keccak_ctx[0], boringssl_shake128);
|
|
1467
|
+
BORINGSSL_keccak_init(&keccak_ctx[1], boringssl_shake128);
|
|
1468
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], rho, kRhoBytes);
|
|
1469
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], rho, kRhoBytes);
|
|
1470
|
+
uint8_t index_buf[2];
|
|
1471
|
+
index_buf[0] = static_cast<uint8_t>(index % L);
|
|
1472
|
+
index_buf[1] = static_cast<uint8_t>(index / L);
|
|
1473
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], index_buf, 2);
|
|
1474
|
+
index_buf[0] = static_cast<uint8_t>((index + 1) % L);
|
|
1475
|
+
index_buf[1] = static_cast<uint8_t>((index + 1) / L);
|
|
1476
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], index_buf, 2);
|
|
1477
|
+
|
|
1478
|
+
scalar *outs[] = {&out->v[index / L][index % L],
|
|
1479
|
+
&out->v[(index + 1) / L][(index + 1) % L]};
|
|
1480
|
+
scalar_from_keccak_vartime_x2(outs, keccak_ctx);
|
|
1481
|
+
}
|
|
1482
|
+
#endif
|
|
1483
|
+
|
|
1484
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1485
|
+
template <int K, int L>
|
|
1486
|
+
inline void matrix_expand_step_x4(matrix<K, L> *out,
|
|
1487
|
+
const uint8_t rho[kRhoBytes], int index) {
|
|
1488
|
+
BORINGSSL_keccak_st keccak_ctx[4];
|
|
1489
|
+
for (int k = 0; k < 4; k++) {
|
|
1490
|
+
BORINGSSL_keccak_init(&keccak_ctx[k], boringssl_shake128);
|
|
1491
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], rho, kRhoBytes);
|
|
1492
|
+
uint8_t index_buf[2];
|
|
1493
|
+
index_buf[0] = static_cast<uint8_t>((index + k) % L);
|
|
1494
|
+
index_buf[1] = static_cast<uint8_t>((index + k) / L);
|
|
1495
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], index_buf, 2);
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
scalar *outs[] = {&out->v[index / L][index % L],
|
|
1499
|
+
&out->v[(index + 1) / L][(index + 1) % L],
|
|
1500
|
+
&out->v[(index + 2) / L][(index + 2) % L],
|
|
1501
|
+
&out->v[(index + 3) / L][(index + 3) % L]};
|
|
1502
|
+
scalar_from_keccak_vartime_x4(outs, keccak_ctx);
|
|
1503
|
+
}
|
|
1504
|
+
#endif
|
|
1505
|
+
|
|
1506
|
+
template <int K, int L>
|
|
1507
|
+
inline void matrix_expand(matrix<K, L> *out, const uint8_t rho[kRhoBytes]) {
|
|
1074
1508
|
static_assert(K <= 0x100, "K must fit in 8 bits");
|
|
1075
1509
|
static_assert(L <= 0x100, "L must fit in 8 bits");
|
|
1076
1510
|
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
for (
|
|
1081
|
-
|
|
1082
|
-
derived_seed[kRhoBytes] = (uint8_t)j;
|
|
1083
|
-
scalar_from_keccak_vartime(&out->v[i][j], derived_seed);
|
|
1511
|
+
int index = 0;
|
|
1512
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1513
|
+
if (BORINGSSL_have_keccak_x4()) {
|
|
1514
|
+
for (; index + 4 <= K * L; index += 4) {
|
|
1515
|
+
matrix_expand_step_x4<K, L>(out, rho, index);
|
|
1084
1516
|
}
|
|
1085
1517
|
}
|
|
1518
|
+
#endif
|
|
1519
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1520
|
+
for (; index + 2 <= K * L; index += 2) {
|
|
1521
|
+
matrix_expand_step_x2(out, rho, index);
|
|
1522
|
+
}
|
|
1523
|
+
#endif
|
|
1524
|
+
|
|
1525
|
+
for (; index < K * L; index++) {
|
|
1526
|
+
matrix_expand_step<K, L>(&out->v[index / L][index % L], rho, index);
|
|
1527
|
+
}
|
|
1086
1528
|
}
|
|
1087
1529
|
|
|
1530
|
+
template <int K>
|
|
1531
|
+
inline void vector_expand_short_step(scalar *out,
|
|
1532
|
+
const uint8_t sigma[kSigmaBytes],
|
|
1533
|
+
int index) {
|
|
1534
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1535
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1536
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, sigma, kSigmaBytes);
|
|
1537
|
+
uint8_t index_buf[2];
|
|
1538
|
+
index_buf[0] = static_cast<uint8_t>(index);
|
|
1539
|
+
index_buf[1] = 0;
|
|
1540
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, index_buf, 2);
|
|
1541
|
+
scalar_uniform<eta<K>()>(out, &keccak_ctx);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1545
|
+
template <int K>
|
|
1546
|
+
inline void vector_expand_short_step_x2(scalar *out0, scalar *out1,
|
|
1547
|
+
const uint8_t sigma[kSigmaBytes],
|
|
1548
|
+
int index) {
|
|
1549
|
+
BORINGSSL_keccak_st keccak_ctx[2];
|
|
1550
|
+
BORINGSSL_keccak_init(&keccak_ctx[0], boringssl_shake256);
|
|
1551
|
+
BORINGSSL_keccak_init(&keccak_ctx[1], boringssl_shake256);
|
|
1552
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], sigma, kSigmaBytes);
|
|
1553
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], sigma, kSigmaBytes);
|
|
1554
|
+
uint8_t index_buf[2];
|
|
1555
|
+
index_buf[0] = static_cast<uint8_t>(index);
|
|
1556
|
+
index_buf[1] = 0;
|
|
1557
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], index_buf, 2);
|
|
1558
|
+
index_buf[0] = static_cast<uint8_t>(index + 1);
|
|
1559
|
+
index_buf[1] = 0;
|
|
1560
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], index_buf, 2);
|
|
1561
|
+
|
|
1562
|
+
scalar *outs[] = {out0, out1};
|
|
1563
|
+
scalar_uniform_x2<eta<K>()>(outs, keccak_ctx);
|
|
1564
|
+
}
|
|
1565
|
+
#endif
|
|
1566
|
+
|
|
1567
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1568
|
+
template <int K>
|
|
1569
|
+
inline void vector_expand_short_step_x4(scalar *out0, scalar *out1,
|
|
1570
|
+
scalar *out2, scalar *out3,
|
|
1571
|
+
const uint8_t sigma[kSigmaBytes],
|
|
1572
|
+
int index) {
|
|
1573
|
+
BORINGSSL_keccak_st keccak_ctx[4];
|
|
1574
|
+
for (int k = 0; k < 4; k++) {
|
|
1575
|
+
BORINGSSL_keccak_init(&keccak_ctx[k], boringssl_shake256);
|
|
1576
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], sigma, kSigmaBytes);
|
|
1577
|
+
uint8_t index_buf[2];
|
|
1578
|
+
index_buf[0] = static_cast<uint8_t>(index + k);
|
|
1579
|
+
index_buf[1] = 0;
|
|
1580
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], index_buf, 2);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
scalar *outs[] = {out0, out1, out2, out3};
|
|
1584
|
+
scalar_uniform_x4<eta<K>()>(outs, keccak_ctx);
|
|
1585
|
+
}
|
|
1586
|
+
#endif
|
|
1587
|
+
|
|
1088
1588
|
// FIPS 204, Algorithm 33 (`ExpandS`).
|
|
1089
1589
|
template <int K, int L>
|
|
1090
|
-
void vector_expand_short(vector<L> *s1, vector<K> *s2,
|
|
1091
|
-
|
|
1590
|
+
inline void vector_expand_short(vector<L> *s1, vector<K> *s2,
|
|
1591
|
+
const uint8_t sigma[kSigmaBytes]) {
|
|
1092
1592
|
static_assert(K <= 0x100, "K must fit in 8 bits");
|
|
1093
1593
|
static_assert(L <= 0x100, "L must fit in 8 bits");
|
|
1094
1594
|
static_assert(K + L <= 0x100, "K+L must fit in 8 bits");
|
|
1095
1595
|
|
|
1096
|
-
|
|
1097
|
-
OPENSSL_memcpy(derived_seed, sigma, kSigmaBytes);
|
|
1098
|
-
derived_seed[kSigmaBytes] = 0;
|
|
1099
|
-
derived_seed[kSigmaBytes + 1] = 0;
|
|
1596
|
+
scalar *all_scalars[K + L];
|
|
1100
1597
|
for (int i = 0; i < L; i++) {
|
|
1101
|
-
|
|
1102
|
-
++derived_seed[kSigmaBytes];
|
|
1598
|
+
all_scalars[i] = &s1->v[i];
|
|
1103
1599
|
}
|
|
1104
1600
|
for (int i = 0; i < K; i++) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1601
|
+
all_scalars[L + i] = &s2->v[i];
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
int index = 0;
|
|
1605
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1606
|
+
if (BORINGSSL_have_keccak_x4()) {
|
|
1607
|
+
for (; index + 4 <= K + L; index += 4) {
|
|
1608
|
+
vector_expand_short_step_x4<K>(all_scalars[index], all_scalars[index + 1],
|
|
1609
|
+
all_scalars[index + 2],
|
|
1610
|
+
all_scalars[index + 3], sigma, index);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
#endif
|
|
1614
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1615
|
+
for (; index + 2 <= K + L; index += 2) {
|
|
1616
|
+
vector_expand_short_step_x2<K>(all_scalars[index], all_scalars[index + 1],
|
|
1617
|
+
sigma, index);
|
|
1618
|
+
}
|
|
1619
|
+
#endif
|
|
1620
|
+
|
|
1621
|
+
for (; index < K + L; index++) {
|
|
1622
|
+
vector_expand_short_step<K>(all_scalars[index], sigma, index);
|
|
1107
1623
|
}
|
|
1108
1624
|
}
|
|
1109
1625
|
|
|
1110
1626
|
// FIPS 204, Algorithm 34 (`ExpandMask`).
|
|
1111
|
-
template <int L>
|
|
1112
|
-
void vector_expand_mask(vector<L> *out,
|
|
1113
|
-
|
|
1627
|
+
template <int K, int L>
|
|
1628
|
+
inline void vector_expand_mask(vector<L> *out,
|
|
1629
|
+
const uint8_t rho_prime[kRhoPrimeBytes],
|
|
1630
|
+
size_t kappa) {
|
|
1114
1631
|
assert(kappa + L <= 0x10000);
|
|
1115
1632
|
|
|
1116
|
-
uint8_t derived_seed[kRhoPrimeBytes + 2];
|
|
1117
|
-
OPENSSL_memcpy(derived_seed, seed, kRhoPrimeBytes);
|
|
1118
1633
|
for (int i = 0; i < L; i++) {
|
|
1119
1634
|
size_t index = kappa + i;
|
|
1120
|
-
|
|
1121
|
-
derived_seed[kRhoPrimeBytes + 1] = (index >> 8) & 0xFF;
|
|
1122
|
-
scalar_sample_mask(&out->v[i], derived_seed);
|
|
1635
|
+
scalar_sample_mask<K>(&out->v[i], rho_prime, index);
|
|
1123
1636
|
}
|
|
1124
1637
|
}
|
|
1125
1638
|
|
|
@@ -1127,50 +1640,60 @@ void vector_expand_mask(vector<L> *out, const uint8_t seed[kRhoPrimeBytes],
|
|
|
1127
1640
|
|
|
1128
1641
|
// FIPS 204, Algorithm 16 (`SimpleBitPack`).
|
|
1129
1642
|
//
|
|
1130
|
-
// Encodes an entire vector into 32*K
|
|
1643
|
+
// Encodes an entire vector into 32*K*`bits` bytes. Note that since 256
|
|
1131
1644
|
// (kDegree) is divisible by 8, the individual vector entries will always fill a
|
|
1132
1645
|
// whole number of bytes, so we do not need to worry about bit packing here.
|
|
1133
|
-
template <int K>
|
|
1134
|
-
void vector_encode(uint8_t *out, const vector<K> *a
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
scalar_encode_4(out + i * bits * kDegree / 8, &a->v[i]);
|
|
1138
|
-
}
|
|
1139
|
-
} else {
|
|
1140
|
-
assert(bits == 10);
|
|
1141
|
-
for (int i = 0; i < K; i++) {
|
|
1142
|
-
scalar_encode_10(out + i * bits * kDegree / 8, &a->v[i]);
|
|
1143
|
-
}
|
|
1646
|
+
template <int bits, int K>
|
|
1647
|
+
inline void vector_encode(uint8_t *out, const vector<K> *a) {
|
|
1648
|
+
for (int i = 0; i < K; i++) {
|
|
1649
|
+
scalar_encode<bits>(out + i * bits * kDegree / 8, &a->v[i]);
|
|
1144
1650
|
}
|
|
1145
1651
|
}
|
|
1146
1652
|
|
|
1147
1653
|
// FIPS 204, Algorithm 18 (`SimpleBitUnpack`).
|
|
1148
|
-
template <int K>
|
|
1149
|
-
void
|
|
1654
|
+
template <int bits, int K>
|
|
1655
|
+
inline void vector_decode(vector<K> *out, const uint8_t *in) {
|
|
1150
1656
|
for (int i = 0; i < K; i++) {
|
|
1151
|
-
|
|
1657
|
+
scalar_decode<bits>(&out->v[i], in + i * bits * kDegree / 8);
|
|
1152
1658
|
}
|
|
1153
1659
|
}
|
|
1154
1660
|
|
|
1155
1661
|
// FIPS 204, Algorithm 17 (`BitPack`).
|
|
1156
1662
|
//
|
|
1157
|
-
// Encodes an entire vector into 32*L
|
|
1663
|
+
// Encodes an entire vector into 32*L*`bits` bytes. Note that since 256
|
|
1158
1664
|
// (kDegree) is divisible by 8, the individual vector entries will always fill a
|
|
1159
1665
|
// whole number of bytes, so we do not need to worry about bit packing here.
|
|
1160
|
-
template <int X>
|
|
1161
|
-
void vector_encode_signed(uint8_t *out, const vector<X> *a
|
|
1162
|
-
uint32_t max) {
|
|
1666
|
+
template <int bits, uint32_t max, int X>
|
|
1667
|
+
inline void vector_encode_signed(uint8_t *out, const vector<X> *a) {
|
|
1163
1668
|
for (int i = 0; i < X; i++) {
|
|
1164
|
-
scalar_encode_signed(out + i * bits * kDegree / 8, &a->v[i]
|
|
1669
|
+
scalar_encode_signed<bits, max>(out + i * bits * kDegree / 8, &a->v[i]);
|
|
1165
1670
|
}
|
|
1166
1671
|
}
|
|
1167
1672
|
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1673
|
+
// `vector_encode_signed_ntt` behaves like `vector_encode_signed` but takes its
|
|
1674
|
+
// input in NTT form. This is only used by the testing-only `skEncode` and
|
|
1675
|
+
// `skDecode` functions and is not performance-sensitive.
|
|
1676
|
+
template <int bits, uint32_t max, int X>
|
|
1677
|
+
inline void vector_encode_signed_ntt(uint8_t *out, const vector<X> *a_ntt) {
|
|
1678
|
+
vector<X> a = *a_ntt;
|
|
1679
|
+
vector_inverse_ntt_montgomery(&a);
|
|
1680
|
+
// `vector_inverse_ntt_montgomery` adds an extra factor of R, which we must
|
|
1681
|
+
// cancel with a Montgomery reduction.
|
|
1682
|
+
for (int i = 0; i < X; i++) {
|
|
1683
|
+
for (int j = 0; j < kDegree; j++) {
|
|
1684
|
+
a.v[i].c[j] = reduce_montgomery(a.v[i].c[j]);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
vector_encode_signed<bits, max>(out, &a);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`).
|
|
1692
|
+
template <int bits, uint32_t max, int X>
|
|
1693
|
+
inline int vector_decode_signed(vector<X> *out, const uint8_t *in) {
|
|
1171
1694
|
for (int i = 0; i < X; i++) {
|
|
1172
|
-
if (!scalar_decode_signed(&out->v[i],
|
|
1173
|
-
|
|
1695
|
+
if (!scalar_decode_signed<bits, max>(&out->v[i],
|
|
1696
|
+
in + i * bits * kDegree / 8)) {
|
|
1174
1697
|
return 0;
|
|
1175
1698
|
}
|
|
1176
1699
|
}
|
|
@@ -1179,13 +1702,13 @@ int vector_decode_signed(vector<X> *out, const uint8_t *in, int bits,
|
|
|
1179
1702
|
|
|
1180
1703
|
// FIPS 204, Algorithm 28 (`w1Encode`).
|
|
1181
1704
|
template <int K>
|
|
1182
|
-
void w1_encode(uint8_t out[
|
|
1183
|
-
vector_encode(out, w1
|
|
1705
|
+
inline void w1_encode(uint8_t out[w1_bytes<K>()], const vector<K> *w1) {
|
|
1706
|
+
vector_encode<w1_coeffs_bits<K>()>(out, w1);
|
|
1184
1707
|
}
|
|
1185
1708
|
|
|
1186
1709
|
// FIPS 204, Algorithm 20 (`HintBitPack`).
|
|
1187
1710
|
template <int K>
|
|
1188
|
-
void hint_bit_pack(uint8_t out[omega<K>() + K], const vector<K> *h) {
|
|
1711
|
+
inline void hint_bit_pack(uint8_t out[omega<K>() + K], const vector<K> *h) {
|
|
1189
1712
|
OPENSSL_memset(out, 0, omega<K>() + K);
|
|
1190
1713
|
int index = 0;
|
|
1191
1714
|
for (int i = 0; i < K; i++) {
|
|
@@ -1202,7 +1725,7 @@ void hint_bit_pack(uint8_t out[omega<K>() + K], const vector<K> *h) {
|
|
|
1202
1725
|
|
|
1203
1726
|
// FIPS 204, Algorithm 21 (`HintBitUnpack`).
|
|
1204
1727
|
template <int K>
|
|
1205
|
-
int hint_bit_unpack(vector<K> *h, const uint8_t in[omega<K>() + K]) {
|
|
1728
|
+
inline int hint_bit_unpack(vector<K> *h, const uint8_t in[omega<K>() + K]) {
|
|
1206
1729
|
vector_zero(h);
|
|
1207
1730
|
int index = 0;
|
|
1208
1731
|
for (int i = 0; i < K; i++) {
|
|
@@ -1241,12 +1764,11 @@ struct public_key {
|
|
|
1241
1764
|
|
|
1242
1765
|
template <int K, int L>
|
|
1243
1766
|
struct private_key {
|
|
1244
|
-
|
|
1767
|
+
public_key<K> pub;
|
|
1245
1768
|
uint8_t k[kKBytes];
|
|
1246
|
-
|
|
1247
|
-
vector<
|
|
1248
|
-
vector<K>
|
|
1249
|
-
vector<K> t0;
|
|
1769
|
+
vector<L> s1_ntt;
|
|
1770
|
+
vector<K> s2_ntt;
|
|
1771
|
+
vector<K> t0_ntt;
|
|
1250
1772
|
};
|
|
1251
1773
|
|
|
1252
1774
|
template <int K, int L>
|
|
@@ -1258,7 +1780,7 @@ struct signature {
|
|
|
1258
1780
|
|
|
1259
1781
|
// FIPS 204, Algorithm 22 (`pkEncode`).
|
|
1260
1782
|
template <int K>
|
|
1261
|
-
int mldsa_marshal_public_key(CBB *out, const
|
|
1783
|
+
inline int mldsa_marshal_public_key(CBB *out, const public_key<K> *pub) {
|
|
1262
1784
|
if (!CBB_add_bytes(out, pub->rho, sizeof(pub->rho))) {
|
|
1263
1785
|
return 0;
|
|
1264
1786
|
}
|
|
@@ -1267,14 +1789,14 @@ int mldsa_marshal_public_key(CBB *out, const struct public_key<K> *pub) {
|
|
|
1267
1789
|
if (!CBB_add_space(out, &vectork_output, 320 * K)) {
|
|
1268
1790
|
return 0;
|
|
1269
1791
|
}
|
|
1270
|
-
vector_encode(vectork_output, &pub->t1
|
|
1792
|
+
vector_encode<10>(vectork_output, &pub->t1);
|
|
1271
1793
|
|
|
1272
1794
|
return 1;
|
|
1273
1795
|
}
|
|
1274
1796
|
|
|
1275
1797
|
// FIPS 204, Algorithm 23 (`pkDecode`).
|
|
1276
1798
|
template <int K>
|
|
1277
|
-
int mldsa_parse_public_key(
|
|
1799
|
+
inline int mldsa_parse_public_key(public_key<K> *pub, CBS *in) {
|
|
1278
1800
|
const CBS orig_in = *in;
|
|
1279
1801
|
|
|
1280
1802
|
if (!CBS_copy_bytes(in, pub->rho, sizeof(pub->rho))) {
|
|
@@ -1285,7 +1807,7 @@ int mldsa_parse_public_key(struct public_key<K> *pub, CBS *in) {
|
|
|
1285
1807
|
if (!CBS_get_bytes(in, &t1_bytes, 320 * K) || CBS_len(in) != 0) {
|
|
1286
1808
|
return 0;
|
|
1287
1809
|
}
|
|
1288
|
-
|
|
1810
|
+
vector_decode<10>(&pub->t1, CBS_data(&t1_bytes));
|
|
1289
1811
|
|
|
1290
1812
|
// Compute pre-cached values.
|
|
1291
1813
|
BORINGSSL_keccak(pub->public_key_hash, sizeof(pub->public_key_hash),
|
|
@@ -1296,11 +1818,11 @@ int mldsa_parse_public_key(struct public_key<K> *pub, CBS *in) {
|
|
|
1296
1818
|
|
|
1297
1819
|
// FIPS 204, Algorithm 24 (`skEncode`).
|
|
1298
1820
|
template <int K, int L>
|
|
1299
|
-
int mldsa_marshal_private_key(CBB *out, const
|
|
1300
|
-
if (!CBB_add_bytes(out, priv->rho, sizeof(priv->rho)) ||
|
|
1821
|
+
inline int mldsa_marshal_private_key(CBB *out, const private_key<K, L> *priv) {
|
|
1822
|
+
if (!CBB_add_bytes(out, priv->pub.rho, sizeof(priv->pub.rho)) ||
|
|
1301
1823
|
!CBB_add_bytes(out, priv->k, sizeof(priv->k)) ||
|
|
1302
|
-
!CBB_add_bytes(out, priv->public_key_hash,
|
|
1303
|
-
sizeof(priv->public_key_hash))) {
|
|
1824
|
+
!CBB_add_bytes(out, priv->pub.public_key_hash,
|
|
1825
|
+
sizeof(priv->pub.public_key_hash))) {
|
|
1304
1826
|
return 0;
|
|
1305
1827
|
}
|
|
1306
1828
|
|
|
@@ -1310,46 +1832,59 @@ int mldsa_marshal_private_key(CBB *out, const struct private_key<K, L> *priv) {
|
|
|
1310
1832
|
if (!CBB_add_space(out, &vectorl_output, scalar_bytes * L)) {
|
|
1311
1833
|
return 0;
|
|
1312
1834
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1835
|
+
vector_encode_signed_ntt<plus_minus_eta_bitlen<K>(), eta<K>()>(vectorl_output,
|
|
1836
|
+
&priv->s1_ntt);
|
|
1315
1837
|
|
|
1316
1838
|
uint8_t *s2_output;
|
|
1317
1839
|
if (!CBB_add_space(out, &s2_output, scalar_bytes * K)) {
|
|
1318
1840
|
return 0;
|
|
1319
1841
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1842
|
+
vector_encode_signed_ntt<plus_minus_eta_bitlen<K>(), eta<K>()>(s2_output,
|
|
1843
|
+
&priv->s2_ntt);
|
|
1322
1844
|
|
|
1323
1845
|
uint8_t *t0_output;
|
|
1324
1846
|
if (!CBB_add_space(out, &t0_output, 416 * K)) {
|
|
1325
1847
|
return 0;
|
|
1326
1848
|
}
|
|
1327
|
-
|
|
1849
|
+
vector_encode_signed_ntt<13, (1 << 12)>(t0_output, &priv->t0_ntt);
|
|
1328
1850
|
|
|
1329
1851
|
return 1;
|
|
1330
1852
|
}
|
|
1331
1853
|
|
|
1332
|
-
// FIPS 204, Algorithm 25 (`skDecode`).
|
|
1854
|
+
// FIPS 204, Algorithm 25 (`skDecode`). This is only used for testing. The
|
|
1855
|
+
// supported external way to construct ML-DSA keys is to use the input seed.
|
|
1333
1856
|
template <int K, int L>
|
|
1334
|
-
int mldsa_parse_private_key(
|
|
1335
|
-
CBS s1_bytes;
|
|
1336
|
-
CBS s2_bytes;
|
|
1337
|
-
CBS t0_bytes;
|
|
1857
|
+
inline int mldsa_parse_private_key(private_key<K, L> *priv, CBS *in) {
|
|
1858
|
+
CBS public_key_hash, s1_bytes, s2_bytes, t0_bytes;
|
|
1338
1859
|
constexpr size_t scalar_bytes =
|
|
1339
1860
|
(kDegree * plus_minus_eta_bitlen<K>() + 7) / 8;
|
|
1340
|
-
if (!CBS_copy_bytes(in, priv->rho, sizeof(priv->rho)) ||
|
|
1861
|
+
if (!CBS_copy_bytes(in, priv->pub.rho, sizeof(priv->pub.rho)) ||
|
|
1341
1862
|
!CBS_copy_bytes(in, priv->k, sizeof(priv->k)) ||
|
|
1342
|
-
!
|
|
1343
|
-
sizeof(priv->public_key_hash)) ||
|
|
1863
|
+
!CBS_get_bytes(in, &public_key_hash, kTrBytes) ||
|
|
1344
1864
|
!CBS_get_bytes(in, &s1_bytes, scalar_bytes * L) ||
|
|
1345
|
-
!vector_decode_signed(
|
|
1346
|
-
|
|
1865
|
+
!vector_decode_signed<plus_minus_eta_bitlen<K>(), eta<K>()>(
|
|
1866
|
+
&priv->s1_ntt, CBS_data(&s1_bytes)) ||
|
|
1347
1867
|
!CBS_get_bytes(in, &s2_bytes, scalar_bytes * K) ||
|
|
1348
|
-
!vector_decode_signed(
|
|
1349
|
-
|
|
1350
|
-
!CBS_get_bytes(in, &t0_bytes, 416 * K)
|
|
1351
|
-
|
|
1352
|
-
|
|
1868
|
+
!vector_decode_signed<plus_minus_eta_bitlen<K>(), eta<K>()>(
|
|
1869
|
+
&priv->s2_ntt, CBS_data(&s2_bytes)) ||
|
|
1870
|
+
!CBS_get_bytes(in, &t0_bytes, 416 * K)) {
|
|
1871
|
+
return 0;
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// Compute `t1`, which is not in the `skDecode` input. This also computes
|
|
1875
|
+
// `t0_ntt` and converts `s1_ntt` and `s2_ntt` to NTT form.
|
|
1876
|
+
uint8_t unused[public_key_bytes<K>()];
|
|
1877
|
+
if (!mldsa_finish_keygen(unused, priv)) {
|
|
1878
|
+
return 0;
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// As a side effect of computing `t1`, we also compute `t0` and
|
|
1882
|
+
// `public_key_hash`. Check they match the received bytes.
|
|
1883
|
+
uint8_t t0_computed[416 * K];
|
|
1884
|
+
vector_encode_signed_ntt<13, (1 << 12)>(t0_computed, &priv->t0_ntt);
|
|
1885
|
+
if (!CBS_mem_equal(&public_key_hash, priv->pub.public_key_hash,
|
|
1886
|
+
sizeof(priv->pub.public_key_hash)) ||
|
|
1887
|
+
!CBS_mem_equal(&t0_bytes, t0_computed, sizeof(t0_computed))) {
|
|
1353
1888
|
return 0;
|
|
1354
1889
|
}
|
|
1355
1890
|
|
|
@@ -1358,16 +1893,17 @@ int mldsa_parse_private_key(struct private_key<K, L> *priv, CBS *in) {
|
|
|
1358
1893
|
|
|
1359
1894
|
// FIPS 204, Algorithm 26 (`sigEncode`).
|
|
1360
1895
|
template <int K, int L>
|
|
1361
|
-
int mldsa_marshal_signature(CBB *out, const
|
|
1896
|
+
inline int mldsa_marshal_signature(CBB *out, const signature<K, L> *sign) {
|
|
1362
1897
|
if (!CBB_add_bytes(out, sign->c_tilde, sizeof(sign->c_tilde))) {
|
|
1363
1898
|
return 0;
|
|
1364
1899
|
}
|
|
1365
1900
|
|
|
1366
1901
|
uint8_t *vectorl_output;
|
|
1367
|
-
if (!CBB_add_space(out, &vectorl_output,
|
|
1902
|
+
if (!CBB_add_space(out, &vectorl_output, scalar_le_gamma1_bytes<K>() * L)) {
|
|
1368
1903
|
return 0;
|
|
1369
1904
|
}
|
|
1370
|
-
vector_encode_signed(
|
|
1905
|
+
vector_encode_signed<gamma1_bits<K>() + 1, gamma1<K>()>(vectorl_output,
|
|
1906
|
+
&sign->z);
|
|
1371
1907
|
|
|
1372
1908
|
uint8_t *hint_output;
|
|
1373
1909
|
if (!CBB_add_space(out, &hint_output, omega<K>() + K)) {
|
|
@@ -1380,13 +1916,14 @@ int mldsa_marshal_signature(CBB *out, const struct signature<K, L> *sign) {
|
|
|
1380
1916
|
|
|
1381
1917
|
// FIPS 204, Algorithm 27 (`sigDecode`).
|
|
1382
1918
|
template <int K, int L>
|
|
1383
|
-
int mldsa_parse_signature(
|
|
1919
|
+
inline int mldsa_parse_signature(signature<K, L> *sign, CBS *in) {
|
|
1384
1920
|
CBS z_bytes;
|
|
1385
1921
|
CBS hint_bytes;
|
|
1386
1922
|
if (!CBS_copy_bytes(in, sign->c_tilde, sizeof(sign->c_tilde)) ||
|
|
1387
|
-
!CBS_get_bytes(in, &z_bytes,
|
|
1388
|
-
// Note: Decoding
|
|
1389
|
-
!vector_decode_signed(
|
|
1923
|
+
!CBS_get_bytes(in, &z_bytes, scalar_le_gamma1_bytes<K>() * L) ||
|
|
1924
|
+
// Note: Decoding b+1 bits into (-2^b, 2^b] cannot fail.
|
|
1925
|
+
!vector_decode_signed<gamma1_bits<K>() + 1, gamma1<K>()>(
|
|
1926
|
+
&sign->z, CBS_data(&z_bytes)) ||
|
|
1390
1927
|
!CBS_get_bytes(in, &hint_bytes, omega<K>() + K) ||
|
|
1391
1928
|
!hint_bit_unpack(&sign->h, CBS_data(&hint_bytes))) {
|
|
1392
1929
|
return 0;
|
|
@@ -1395,143 +1932,107 @@ int mldsa_parse_signature(struct signature<K, L> *sign, CBS *in) {
|
|
|
1395
1932
|
return 1;
|
|
1396
1933
|
}
|
|
1397
1934
|
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
// FIPS 204, Algorithm 6 (`ML-DSA.KeyGen_internal`). Returns 1 on success and 0
|
|
1404
|
-
// on failure.
|
|
1935
|
+
// FIPS 204, Algorithm 6 (`ML-DSA.KeyGen_internal`), steps 3 and 5–11.
|
|
1936
|
+
// Returns 1 on success and 0 on failure.
|
|
1937
|
+
//
|
|
1938
|
+
// On input, `priv->s1_ntt` and `priv->s2_ntt` are not yet in NTT form. They are
|
|
1939
|
+
// converted to NTT form by this function.
|
|
1405
1940
|
template <int K, int L>
|
|
1406
|
-
int
|
|
1941
|
+
inline int mldsa_finish_keygen(
|
|
1407
1942
|
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
|
1408
|
-
|
|
1409
|
-
const uint8_t entropy[BCM_MLDSA_SEED_BYTES]) {
|
|
1943
|
+
private_key<K, L> *priv) {
|
|
1410
1944
|
// Intermediate values, allocated on the heap to allow use when there is a
|
|
1411
1945
|
// limited amount of stack.
|
|
1412
|
-
struct
|
|
1413
|
-
|
|
1946
|
+
struct Values {
|
|
1947
|
+
enum { kAllowUniquePtr = true };
|
|
1414
1948
|
matrix<K, L> a_ntt;
|
|
1415
|
-
vector<L> s1_ntt;
|
|
1416
1949
|
vector<K> t;
|
|
1417
1950
|
};
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (values == NULL) {
|
|
1951
|
+
auto values = MakeUnique<Values>();
|
|
1952
|
+
if (values == nullptr) {
|
|
1421
1953
|
return 0;
|
|
1422
1954
|
}
|
|
1423
1955
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
// The k and l parameters are appended to the seed.
|
|
1427
|
-
augmented_entropy[BCM_MLDSA_SEED_BYTES] = K;
|
|
1428
|
-
augmented_entropy[BCM_MLDSA_SEED_BYTES + 1] = L;
|
|
1429
|
-
uint8_t expanded_seed[kRhoBytes + kSigmaBytes + kKBytes];
|
|
1430
|
-
BORINGSSL_keccak(expanded_seed, sizeof(expanded_seed), augmented_entropy,
|
|
1431
|
-
sizeof(augmented_entropy), boringssl_shake256);
|
|
1432
|
-
const uint8_t *const rho = expanded_seed;
|
|
1433
|
-
const uint8_t *const sigma = expanded_seed + kRhoBytes;
|
|
1434
|
-
const uint8_t *const k = expanded_seed + kRhoBytes + kSigmaBytes;
|
|
1435
|
-
// rho is public.
|
|
1436
|
-
CONSTTIME_DECLASSIFY(rho, kRhoBytes);
|
|
1437
|
-
OPENSSL_memcpy(values->pub.rho, rho, sizeof(values->pub.rho));
|
|
1438
|
-
OPENSSL_memcpy(priv->rho, rho, sizeof(priv->rho));
|
|
1439
|
-
OPENSSL_memcpy(priv->k, k, sizeof(priv->k));
|
|
1440
|
-
|
|
1441
|
-
matrix_expand(&values->a_ntt, rho);
|
|
1442
|
-
vector_expand_short(&priv->s1, &priv->s2, sigma);
|
|
1443
|
-
|
|
1444
|
-
OPENSSL_memcpy(&values->s1_ntt, &priv->s1, sizeof(values->s1_ntt));
|
|
1445
|
-
vector_ntt(&values->s1_ntt);
|
|
1956
|
+
// Step 3.
|
|
1957
|
+
matrix_expand(&values->a_ntt, priv->pub.rho);
|
|
1446
1958
|
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1959
|
+
// Step 5. Note that, on input, `s1_ntt` and `s2_ntt` are not yet in NTT form,
|
|
1960
|
+
// but this function is responsible for converting them to NTT.
|
|
1961
|
+
vector_ntt(&priv->s1_ntt);
|
|
1962
|
+
matrix_mult_montgomery(&values->t, &values->a_ntt, &priv->s1_ntt);
|
|
1963
|
+
vector_inverse_ntt_montgomery(&values->t);
|
|
1964
|
+
vector_add(&values->t, &values->t, &priv->s2_ntt);
|
|
1965
|
+
vector_ntt(&priv->s2_ntt);
|
|
1450
1966
|
|
|
1451
|
-
|
|
1967
|
+
// Step 6-7. We store t0 in NTT form.
|
|
1968
|
+
vector_power2_round(&priv->pub.t1, &priv->t0_ntt, &values->t);
|
|
1969
|
+
vector_ntt(&priv->t0_ntt);
|
|
1452
1970
|
// t1 is public.
|
|
1453
|
-
CONSTTIME_DECLASSIFY(&
|
|
1971
|
+
CONSTTIME_DECLASSIFY(&priv->pub.t1, sizeof(priv->pub.t1));
|
|
1454
1972
|
|
|
1973
|
+
// Step 8.
|
|
1455
1974
|
CBB cbb;
|
|
1456
1975
|
CBB_init_fixed(&cbb, out_encoded_public_key, public_key_bytes<K>());
|
|
1457
|
-
if (!mldsa_marshal_public_key(&cbb, &
|
|
1976
|
+
if (!mldsa_marshal_public_key(&cbb, &priv->pub)) {
|
|
1458
1977
|
return 0;
|
|
1459
1978
|
}
|
|
1460
1979
|
assert(CBB_len(&cbb) == public_key_bytes<K>());
|
|
1461
1980
|
|
|
1462
|
-
|
|
1981
|
+
// Step 9-11.
|
|
1982
|
+
BORINGSSL_keccak(priv->pub.public_key_hash, sizeof(priv->pub.public_key_hash),
|
|
1463
1983
|
out_encoded_public_key, public_key_bytes<K>(),
|
|
1464
1984
|
boringssl_shake256);
|
|
1465
1985
|
|
|
1466
1986
|
return 1;
|
|
1467
1987
|
}
|
|
1468
1988
|
|
|
1989
|
+
// FIPS 204, Algorithm 6 (`ML-DSA.KeyGen_internal`). Returns 1 on success and 0
|
|
1990
|
+
// on failure.
|
|
1469
1991
|
template <int K, int L>
|
|
1470
|
-
int
|
|
1992
|
+
inline int mldsa_generate_key_external_entropy_no_self_test(
|
|
1471
1993
|
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1994
|
+
private_key<K, L> *priv, const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
1995
|
+
// Step 1-2.
|
|
1996
|
+
uint8_t augmented_entropy[MLDSA_SEED_BYTES + 2];
|
|
1997
|
+
OPENSSL_memcpy(augmented_entropy, entropy, MLDSA_SEED_BYTES);
|
|
1998
|
+
// The k and l parameters are appended to the seed.
|
|
1999
|
+
augmented_entropy[MLDSA_SEED_BYTES] = K;
|
|
2000
|
+
augmented_entropy[MLDSA_SEED_BYTES + 1] = L;
|
|
2001
|
+
uint8_t expanded_seed[kRhoBytes + kSigmaBytes + kKBytes];
|
|
2002
|
+
BORINGSSL_keccak(expanded_seed, sizeof(expanded_seed), augmented_entropy,
|
|
2003
|
+
sizeof(augmented_entropy), boringssl_shake256);
|
|
2004
|
+
const uint8_t *const rho = expanded_seed;
|
|
2005
|
+
const uint8_t *const sigma = expanded_seed + kRhoBytes;
|
|
2006
|
+
const uint8_t *const k = expanded_seed + kRhoBytes + kSigmaBytes;
|
|
2007
|
+
// rho is public.
|
|
2008
|
+
CONSTTIME_DECLASSIFY(rho, kRhoBytes);
|
|
2009
|
+
OPENSSL_memcpy(priv->pub.rho, rho, sizeof(priv->pub.rho));
|
|
2010
|
+
OPENSSL_memcpy(priv->k, k, sizeof(priv->k));
|
|
2011
|
+
// Steps 4. This is independent of A (step 3) and can be done first.
|
|
2012
|
+
// `mldsa_finish_keygen` will convert `s1_ntt` and `s2_ntt` into NTT from.
|
|
2013
|
+
vector_expand_short(&priv->s1_ntt, &priv->s2_ntt, sigma);
|
|
2014
|
+
// Steps 3 and 5-11.
|
|
2015
|
+
return mldsa_finish_keygen(out_encoded_public_key, priv);
|
|
1477
2016
|
}
|
|
1478
2017
|
|
|
1479
2018
|
template <int K, int L>
|
|
1480
|
-
int
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
vector<L> s1_ntt;
|
|
1487
|
-
vector<K> t;
|
|
1488
|
-
vector<K> t0;
|
|
1489
|
-
};
|
|
1490
|
-
std::unique_ptr<values_st, DeleterFree<values_st>> values(
|
|
1491
|
-
reinterpret_cast<struct values_st *>(OPENSSL_malloc(sizeof(values_st))));
|
|
1492
|
-
if (values == NULL) {
|
|
1493
|
-
return 0;
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
OPENSSL_memcpy(pub->rho, priv->rho, sizeof(pub->rho));
|
|
1497
|
-
OPENSSL_memcpy(pub->public_key_hash, priv->public_key_hash,
|
|
1498
|
-
sizeof(pub->public_key_hash));
|
|
1499
|
-
|
|
1500
|
-
matrix_expand(&values->a_ntt, priv->rho);
|
|
1501
|
-
|
|
1502
|
-
OPENSSL_memcpy(&values->s1_ntt, &priv->s1, sizeof(values->s1_ntt));
|
|
1503
|
-
vector_ntt(&values->s1_ntt);
|
|
1504
|
-
|
|
1505
|
-
matrix_mult(&values->t, &values->a_ntt, &values->s1_ntt);
|
|
1506
|
-
vector_inverse_ntt(&values->t);
|
|
1507
|
-
vector_add(&values->t, &values->t, &priv->s2);
|
|
1508
|
-
|
|
1509
|
-
vector_power2_round(&pub->t1, &values->t0, &values->t);
|
|
1510
|
-
// t1 is part of the public key and thus is public.
|
|
1511
|
-
CONSTTIME_DECLASSIFY(&pub->t1, sizeof(pub->t1));
|
|
1512
|
-
return 1;
|
|
2019
|
+
inline int mldsa_generate_key_external_entropy(
|
|
2020
|
+
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
|
2021
|
+
private_key<K, L> *priv, const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2022
|
+
fips::ensure_keygen_self_test();
|
|
2023
|
+
return mldsa_generate_key_external_entropy_no_self_test(
|
|
2024
|
+
out_encoded_public_key, priv, entropy);
|
|
1513
2025
|
}
|
|
1514
2026
|
|
|
1515
|
-
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`)
|
|
1516
|
-
// on failure.
|
|
2027
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`), using a pre-computed mu.
|
|
2028
|
+
// Returns 1 on success and 0 on failure.
|
|
1517
2029
|
template <int K, int L>
|
|
1518
|
-
int
|
|
2030
|
+
inline int mldsa_sign_mu_no_self_test(
|
|
1519
2031
|
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
1520
|
-
const
|
|
1521
|
-
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
1522
|
-
const uint8_t *context, size_t context_len,
|
|
2032
|
+
const private_key<K, L> *priv, const uint8_t mu[kMuBytes],
|
|
1523
2033
|
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
1524
|
-
uint8_t mu[kMuBytes];
|
|
1525
|
-
struct BORINGSSL_keccak_st keccak_ctx;
|
|
1526
|
-
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1527
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, priv->public_key_hash,
|
|
1528
|
-
sizeof(priv->public_key_hash));
|
|
1529
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
|
1530
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
|
1531
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
|
1532
|
-
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
|
1533
|
-
|
|
1534
2034
|
uint8_t rho_prime[kRhoPrimeBytes];
|
|
2035
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1535
2036
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1536
2037
|
BORINGSSL_keccak_absorb(&keccak_ctx, priv->k, sizeof(priv->k));
|
|
1537
2038
|
BORINGSSL_keccak_absorb(&keccak_ctx, randomizer,
|
|
@@ -1541,11 +2042,9 @@ int mldsa_sign_internal_no_self_test(
|
|
|
1541
2042
|
|
|
1542
2043
|
// Intermediate values, allocated on the heap to allow use when there is a
|
|
1543
2044
|
// limited amount of stack.
|
|
1544
|
-
struct
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
vector<K> s2_ntt;
|
|
1548
|
-
vector<K> t0_ntt;
|
|
2045
|
+
struct Values {
|
|
2046
|
+
enum { kAllowUniquePtr = true };
|
|
2047
|
+
signature<K, L> sign;
|
|
1549
2048
|
matrix<K, L> a_ntt;
|
|
1550
2049
|
vector<L> y;
|
|
1551
2050
|
vector<K> w;
|
|
@@ -1553,41 +2052,31 @@ int mldsa_sign_internal_no_self_test(
|
|
|
1553
2052
|
vector<L> cs1;
|
|
1554
2053
|
vector<K> cs2;
|
|
1555
2054
|
};
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
if (values == NULL) {
|
|
2055
|
+
auto values = MakeUnique<Values>();
|
|
2056
|
+
if (values == nullptr) {
|
|
1559
2057
|
return 0;
|
|
1560
2058
|
}
|
|
1561
|
-
|
|
1562
|
-
vector_ntt(&values->s1_ntt);
|
|
1563
|
-
|
|
1564
|
-
OPENSSL_memcpy(&values->s2_ntt, &priv->s2, sizeof(values->s2_ntt));
|
|
1565
|
-
vector_ntt(&values->s2_ntt);
|
|
1566
|
-
|
|
1567
|
-
OPENSSL_memcpy(&values->t0_ntt, &priv->t0, sizeof(values->t0_ntt));
|
|
1568
|
-
vector_ntt(&values->t0_ntt);
|
|
1569
|
-
|
|
1570
|
-
matrix_expand(&values->a_ntt, priv->rho);
|
|
2059
|
+
matrix_expand(&values->a_ntt, priv->pub.rho);
|
|
1571
2060
|
|
|
1572
2061
|
// kappa must not exceed 2**16/L = 13107. But the probability of it
|
|
1573
2062
|
// exceeding even 1000 iterations is vanishingly small.
|
|
1574
2063
|
for (size_t kappa = 0;; kappa += L) {
|
|
1575
|
-
vector_expand_mask(&values->y, rho_prime, kappa);
|
|
2064
|
+
vector_expand_mask<K, L>(&values->y, rho_prime, kappa);
|
|
1576
2065
|
|
|
1577
2066
|
vector<L> *y_ntt = &values->cs1;
|
|
1578
2067
|
OPENSSL_memcpy(y_ntt, &values->y, sizeof(*y_ntt));
|
|
1579
2068
|
vector_ntt(y_ntt);
|
|
1580
2069
|
|
|
1581
|
-
|
|
1582
|
-
|
|
2070
|
+
matrix_mult_montgomery(&values->w, &values->a_ntt, y_ntt);
|
|
2071
|
+
vector_inverse_ntt_montgomery(&values->w);
|
|
1583
2072
|
|
|
1584
2073
|
vector_high_bits(&values->w1, &values->w);
|
|
1585
|
-
uint8_t w1_encoded[
|
|
2074
|
+
uint8_t w1_encoded[w1_bytes<K>()];
|
|
1586
2075
|
w1_encode(w1_encoded, &values->w1);
|
|
1587
2076
|
|
|
1588
2077
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1589
2078
|
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
|
1590
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded,
|
|
2079
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded, w1_bytes<K>());
|
|
1591
2080
|
BORINGSSL_keccak_squeeze(&keccak_ctx, values->sign.c_tilde,
|
|
1592
2081
|
2 * lambda_bytes<K>());
|
|
1593
2082
|
|
|
@@ -1596,10 +2085,10 @@ int mldsa_sign_internal_no_self_test(
|
|
|
1596
2085
|
sizeof(values->sign.c_tilde), tau<K>());
|
|
1597
2086
|
scalar_ntt(&c_ntt);
|
|
1598
2087
|
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
2088
|
+
vector_mult_scalar_montgomery(&values->cs1, &priv->s1_ntt, &c_ntt);
|
|
2089
|
+
vector_inverse_ntt_montgomery(&values->cs1);
|
|
2090
|
+
vector_mult_scalar_montgomery(&values->cs2, &priv->s2_ntt, &c_ntt);
|
|
2091
|
+
vector_inverse_ntt_montgomery(&values->cs2);
|
|
1603
2092
|
|
|
1604
2093
|
vector_add(&values->sign.z, &values->y, &values->cs1);
|
|
1605
2094
|
|
|
@@ -1614,13 +2103,13 @@ int mldsa_sign_internal_no_self_test(
|
|
|
1614
2103
|
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3.pdf
|
|
1615
2104
|
// describes this leak as OK. Note we leak less than what is described by
|
|
1616
2105
|
// the paper; we do not reveal which coefficient violated the bound, and
|
|
1617
|
-
// we hide which of the
|
|
2106
|
+
// we hide which of the `z_max` or `r0_max` bound failed. See also
|
|
1618
2107
|
// https://boringssl-review.googlesource.com/c/boringssl/+/67747/comment/2bbab0fa_d241d35a/
|
|
1619
2108
|
uint32_t z_max = vector_max(&values->sign.z);
|
|
1620
2109
|
uint32_t r0_max = vector_max_signed(r0);
|
|
1621
2110
|
if (constant_time_declassify_w(
|
|
1622
2111
|
constant_time_ge_w(z_max, gamma1<K>() - beta<K>()) |
|
|
1623
|
-
constant_time_ge_w(r0_max,
|
|
2112
|
+
constant_time_ge_w(r0_max, gamma2<K>() - beta<K>()))) {
|
|
1624
2113
|
#if defined(BORINGSSL_FIPS_BREAK_TESTS)
|
|
1625
2114
|
// In order to show that our self-tests trigger both restart cases in
|
|
1626
2115
|
// this loop, printf-logging is added when built in break-test mode.
|
|
@@ -1630,14 +2119,14 @@ int mldsa_sign_internal_no_self_test(
|
|
|
1630
2119
|
}
|
|
1631
2120
|
|
|
1632
2121
|
vector<K> *ct0 = &values->w1;
|
|
1633
|
-
|
|
1634
|
-
|
|
2122
|
+
vector_mult_scalar_montgomery(ct0, &priv->t0_ntt, &c_ntt);
|
|
2123
|
+
vector_inverse_ntt_montgomery(ct0);
|
|
1635
2124
|
vector_make_hint(&values->sign.h, ct0, &values->cs2, &values->w);
|
|
1636
2125
|
|
|
1637
2126
|
// See above.
|
|
1638
2127
|
uint32_t ct0_max = vector_max(ct0);
|
|
1639
2128
|
size_t h_ones = vector_count_ones(&values->sign.h);
|
|
1640
|
-
if (constant_time_declassify_w(constant_time_ge_w(ct0_max,
|
|
2129
|
+
if (constant_time_declassify_w(constant_time_ge_w(ct0_max, gamma2<K>()) |
|
|
1641
2130
|
constant_time_lt_w(omega<K>(), h_ones))) {
|
|
1642
2131
|
#if defined(BORINGSSL_FIPS_BREAK_TESTS)
|
|
1643
2132
|
// In order to show that our self-tests trigger both restart cases in
|
|
@@ -1663,10 +2152,47 @@ int mldsa_sign_internal_no_self_test(
|
|
|
1663
2152
|
}
|
|
1664
2153
|
}
|
|
1665
2154
|
|
|
2155
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`), using a pre-computed mu.
|
|
2156
|
+
// Returns 1 on success and 0 on failure.
|
|
2157
|
+
template <int K, int L>
|
|
2158
|
+
inline int mldsa_sign_mu(
|
|
2159
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
2160
|
+
const private_key<K, L> *priv, const uint8_t mu[kMuBytes],
|
|
2161
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2162
|
+
fips::ensure_sign_self_test();
|
|
2163
|
+
return mldsa_sign_mu_no_self_test(out_encoded_signature, priv, mu,
|
|
2164
|
+
randomizer);
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`). Returns 1 on success and 0
|
|
2168
|
+
// on failure.
|
|
1666
2169
|
template <int K, int L>
|
|
1667
|
-
int
|
|
2170
|
+
inline int mldsa_sign_internal_no_self_test(
|
|
1668
2171
|
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
1669
|
-
const
|
|
2172
|
+
const private_key<K, L> *priv, const uint8_t *msg, size_t msg_len,
|
|
2173
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2174
|
+
const uint8_t *context, size_t context_len,
|
|
2175
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2176
|
+
uint8_t mu[kMuBytes];
|
|
2177
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2178
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2179
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, priv->pub.public_key_hash,
|
|
2180
|
+
sizeof(priv->pub.public_key_hash));
|
|
2181
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
|
2182
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
|
2183
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
|
2184
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
|
2185
|
+
|
|
2186
|
+
return mldsa_sign_mu_no_self_test(out_encoded_signature, priv, mu,
|
|
2187
|
+
randomizer);
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`). Returns 1 on success and 0
|
|
2191
|
+
// on failure.
|
|
2192
|
+
template <int K, int L>
|
|
2193
|
+
inline int mldsa_sign_internal(
|
|
2194
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
2195
|
+
const private_key<K, L> *priv, const uint8_t *msg, size_t msg_len,
|
|
1670
2196
|
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
1671
2197
|
const uint8_t *context, size_t context_len,
|
|
1672
2198
|
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
@@ -1676,25 +2202,54 @@ int mldsa_sign_internal(
|
|
|
1676
2202
|
context_prefix_len, context, context_len, randomizer);
|
|
1677
2203
|
}
|
|
1678
2204
|
|
|
1679
|
-
|
|
2205
|
+
struct prehash_context {
|
|
2206
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2209
|
+
template <int K>
|
|
2210
|
+
inline void mldsa_prehash_init(prehash_context *out_prehash_ctx,
|
|
2211
|
+
const public_key<K> *pub,
|
|
2212
|
+
const uint8_t *context_prefix,
|
|
2213
|
+
size_t context_prefix_len,
|
|
2214
|
+
const uint8_t *context, size_t context_len) {
|
|
2215
|
+
BORINGSSL_keccak_init(&out_prehash_ctx->keccak_ctx, boringssl_shake256);
|
|
2216
|
+
BORINGSSL_keccak_absorb(&out_prehash_ctx->keccak_ctx, pub->public_key_hash,
|
|
2217
|
+
sizeof(pub->public_key_hash));
|
|
2218
|
+
BORINGSSL_keccak_absorb(&out_prehash_ctx->keccak_ctx, context_prefix,
|
|
2219
|
+
context_prefix_len);
|
|
2220
|
+
BORINGSSL_keccak_absorb(&out_prehash_ctx->keccak_ctx, context, context_len);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
inline void mldsa_prehash_update(prehash_context *inout_prehash_ctx,
|
|
2224
|
+
const uint8_t *msg, size_t msg_len) {
|
|
2225
|
+
BORINGSSL_keccak_absorb(&inout_prehash_ctx->keccak_ctx, msg, msg_len);
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
inline void mldsa_prehash_finalize(uint8_t out_msg_rep[kMuBytes],
|
|
2229
|
+
prehash_context *inout_prehash_ctx) {
|
|
2230
|
+
BORINGSSL_keccak_squeeze(&inout_prehash_ctx->keccak_ctx, out_msg_rep,
|
|
2231
|
+
kMuBytes);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`), using a pre-computed mu.
|
|
2235
|
+
// Returns 1 on success and 0 on failure.
|
|
1680
2236
|
template <int K, int L>
|
|
1681
|
-
int
|
|
1682
|
-
const
|
|
1683
|
-
const uint8_t encoded_signature[signature_bytes<K>()],
|
|
1684
|
-
|
|
1685
|
-
const uint8_t *context, size_t context_len) {
|
|
2237
|
+
inline int mldsa_verify_mu_no_self_test(
|
|
2238
|
+
const public_key<K> *pub,
|
|
2239
|
+
const uint8_t encoded_signature[signature_bytes<K>()],
|
|
2240
|
+
const uint8_t mu[kMuBytes]) {
|
|
1686
2241
|
// Intermediate values, allocated on the heap to allow use when there is a
|
|
1687
2242
|
// limited amount of stack.
|
|
1688
|
-
struct
|
|
1689
|
-
|
|
2243
|
+
struct Values {
|
|
2244
|
+
enum { kAllowUniquePtr = true };
|
|
2245
|
+
signature<K, L> sign;
|
|
1690
2246
|
matrix<K, L> a_ntt;
|
|
1691
2247
|
vector<L> z_ntt;
|
|
1692
2248
|
vector<K> az_ntt;
|
|
1693
2249
|
vector<K> ct1_ntt;
|
|
1694
2250
|
};
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
if (values == NULL) {
|
|
2251
|
+
auto values = MakeUnique<Values>();
|
|
2252
|
+
if (values == nullptr) {
|
|
1698
2253
|
return 0;
|
|
1699
2254
|
}
|
|
1700
2255
|
|
|
@@ -1706,16 +2261,6 @@ int mldsa_verify_internal_no_self_test(
|
|
|
1706
2261
|
|
|
1707
2262
|
matrix_expand(&values->a_ntt, pub->rho);
|
|
1708
2263
|
|
|
1709
|
-
uint8_t mu[kMuBytes];
|
|
1710
|
-
struct BORINGSSL_keccak_st keccak_ctx;
|
|
1711
|
-
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1712
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, pub->public_key_hash,
|
|
1713
|
-
sizeof(pub->public_key_hash));
|
|
1714
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
|
1715
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
|
1716
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
|
1717
|
-
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
|
1718
|
-
|
|
1719
2264
|
scalar c_ntt;
|
|
1720
2265
|
scalar_sample_in_ball_vartime(&c_ntt, values->sign.c_tilde,
|
|
1721
2266
|
sizeof(values->sign.c_tilde), tau<K>());
|
|
@@ -1724,25 +2269,26 @@ int mldsa_verify_internal_no_self_test(
|
|
|
1724
2269
|
OPENSSL_memcpy(&values->z_ntt, &values->sign.z, sizeof(values->z_ntt));
|
|
1725
2270
|
vector_ntt(&values->z_ntt);
|
|
1726
2271
|
|
|
1727
|
-
|
|
2272
|
+
matrix_mult_montgomery(&values->az_ntt, &values->a_ntt, &values->z_ntt);
|
|
1728
2273
|
|
|
1729
2274
|
vector_scale_power2_round(&values->ct1_ntt, &pub->t1);
|
|
1730
2275
|
vector_ntt(&values->ct1_ntt);
|
|
1731
2276
|
|
|
1732
|
-
|
|
2277
|
+
vector_mult_scalar_montgomery(&values->ct1_ntt, &values->ct1_ntt, &c_ntt);
|
|
1733
2278
|
|
|
1734
2279
|
vector<K> *const w1 = &values->az_ntt;
|
|
1735
2280
|
vector_sub(w1, &values->az_ntt, &values->ct1_ntt);
|
|
1736
|
-
|
|
2281
|
+
vector_inverse_ntt_montgomery(w1);
|
|
1737
2282
|
|
|
1738
2283
|
vector_use_hint_vartime(w1, &values->sign.h, w1);
|
|
1739
|
-
uint8_t w1_encoded[
|
|
2284
|
+
uint8_t w1_encoded[w1_bytes<K>()];
|
|
1740
2285
|
w1_encode(w1_encoded, w1);
|
|
1741
2286
|
|
|
1742
2287
|
uint8_t c_tilde[2 * lambda_bytes<K>()];
|
|
2288
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1743
2289
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1744
2290
|
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
|
1745
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded,
|
|
2291
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded, w1_bytes<K>());
|
|
1746
2292
|
BORINGSSL_keccak_squeeze(&keccak_ctx, c_tilde, 2 * lambda_bytes<K>());
|
|
1747
2293
|
|
|
1748
2294
|
uint32_t z_max = vector_max(&values->sign.z);
|
|
@@ -1750,87 +2296,170 @@ int mldsa_verify_internal_no_self_test(
|
|
|
1750
2296
|
OPENSSL_memcmp(c_tilde, values->sign.c_tilde, 2 * lambda_bytes<K>()) ==
|
|
1751
2297
|
0;
|
|
1752
2298
|
}
|
|
2299
|
+
|
|
2300
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`), using a pre-computed mu.
|
|
2301
|
+
// Returns 1 on success and 0 on failure.
|
|
1753
2302
|
template <int K, int L>
|
|
1754
|
-
int
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
2303
|
+
inline int mldsa_verify_mu(
|
|
2304
|
+
const public_key<K> *pub,
|
|
2305
|
+
const uint8_t encoded_signature[signature_bytes<K>()],
|
|
2306
|
+
const uint8_t mu[kMuBytes]) {
|
|
2307
|
+
fips::ensure_verify_self_test();
|
|
2308
|
+
return mldsa_verify_mu_no_self_test<K, L>(pub, encoded_signature, mu);
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`).
|
|
2312
|
+
template <int K, int L>
|
|
2313
|
+
inline int mldsa_verify_internal_no_self_test(
|
|
2314
|
+
const public_key<K> *pub,
|
|
2315
|
+
const uint8_t encoded_signature[signature_bytes<K>()], const uint8_t *msg,
|
|
2316
|
+
size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2317
|
+
const uint8_t *context, size_t context_len) {
|
|
2318
|
+
uint8_t mu[kMuBytes];
|
|
2319
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2320
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2321
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, pub->public_key_hash,
|
|
2322
|
+
sizeof(pub->public_key_hash));
|
|
2323
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
|
2324
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
|
2325
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
|
2326
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
|
2327
|
+
|
|
2328
|
+
return mldsa_verify_mu_no_self_test<K, L>(pub, encoded_signature, mu);
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`).
|
|
2332
|
+
template <int K, int L>
|
|
2333
|
+
inline int mldsa_verify_internal(
|
|
2334
|
+
const public_key<K> *pub,
|
|
2335
|
+
const uint8_t encoded_signature[signature_bytes<K>()], const uint8_t *msg,
|
|
2336
|
+
size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2337
|
+
const uint8_t *context, size_t context_len) {
|
|
1760
2338
|
fips::ensure_verify_self_test();
|
|
1761
2339
|
return mldsa_verify_internal_no_self_test<K, L>(
|
|
1762
2340
|
pub, encoded_signature, msg, msg_len, context_prefix, context_prefix_len,
|
|
1763
2341
|
context, context_len);
|
|
1764
2342
|
}
|
|
1765
2343
|
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
static_assert(alignof(
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
const
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
2344
|
+
static_assert(sizeof(MLDSA65_private_key) == sizeof(private_key<6, 5>));
|
|
2345
|
+
static_assert(alignof(MLDSA65_private_key) == alignof(private_key<6, 5>));
|
|
2346
|
+
|
|
2347
|
+
inline const private_key<6, 5> *private_key_from_external_65(
|
|
2348
|
+
const MLDSA65_private_key *external) {
|
|
2349
|
+
return reinterpret_cast<const private_key<6, 5> *>(external);
|
|
2350
|
+
}
|
|
2351
|
+
inline private_key<6, 5> *private_key_from_external_65(
|
|
2352
|
+
MLDSA65_private_key *external) {
|
|
2353
|
+
return reinterpret_cast<private_key<6, 5> *>(external);
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
static_assert(sizeof(MLDSA65_public_key) == sizeof(public_key<6>));
|
|
2357
|
+
static_assert(alignof(MLDSA65_public_key) == alignof(public_key<6>));
|
|
2358
|
+
|
|
2359
|
+
inline const public_key<6> *public_key_from_external_65(
|
|
2360
|
+
const MLDSA65_public_key *external) {
|
|
2361
|
+
return reinterpret_cast<const public_key<6> *>(external);
|
|
2362
|
+
}
|
|
2363
|
+
inline public_key<6> *public_key_from_external_65(
|
|
2364
|
+
MLDSA65_public_key *external) {
|
|
2365
|
+
return reinterpret_cast<public_key<6> *>(external);
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
inline prehash_context *prehash_context_from_external_65(
|
|
2369
|
+
MLDSA65_prehash *external) {
|
|
2370
|
+
static_assert(sizeof(MLDSA65_prehash) == sizeof(prehash_context));
|
|
2371
|
+
static_assert(alignof(MLDSA65_prehash) == alignof(prehash_context));
|
|
2372
|
+
return reinterpret_cast<prehash_context *>(external);
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
static_assert(sizeof(MLDSA87_private_key) == sizeof(private_key<8, 7>));
|
|
2376
|
+
static_assert(alignof(MLDSA87_private_key) == alignof(private_key<8, 7>));
|
|
2377
|
+
inline const private_key<8, 7> *private_key_from_external_87(
|
|
2378
|
+
const MLDSA87_private_key *external) {
|
|
2379
|
+
return reinterpret_cast<const private_key<8, 7> *>(external);
|
|
2380
|
+
}
|
|
2381
|
+
inline private_key<8, 7> *private_key_from_external_87(
|
|
2382
|
+
MLDSA87_private_key *external) {
|
|
2383
|
+
return reinterpret_cast<private_key<8, 7> *>(external);
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
static_assert(sizeof(MLDSA87_public_key) == sizeof(public_key<8>));
|
|
2387
|
+
static_assert(alignof(MLDSA87_public_key) == alignof(public_key<8>));
|
|
2388
|
+
|
|
2389
|
+
inline const public_key<8> *public_key_from_external_87(
|
|
2390
|
+
const MLDSA87_public_key *external) {
|
|
2391
|
+
return reinterpret_cast<const public_key<8> *>(external);
|
|
2392
|
+
}
|
|
2393
|
+
inline public_key<8> *public_key_from_external_87(
|
|
2394
|
+
MLDSA87_public_key *external) {
|
|
2395
|
+
return reinterpret_cast<public_key<8> *>(external);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
inline prehash_context *prehash_context_from_external_87(
|
|
2399
|
+
MLDSA87_prehash *external) {
|
|
2400
|
+
static_assert(sizeof(MLDSA87_prehash) == sizeof(prehash_context));
|
|
2401
|
+
static_assert(alignof(MLDSA87_prehash) == alignof(prehash_context));
|
|
2402
|
+
return reinterpret_cast<prehash_context *>(external);
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
static_assert(sizeof(MLDSA44_private_key) == sizeof(private_key<4, 4>));
|
|
2406
|
+
static_assert(alignof(MLDSA44_private_key) == alignof(private_key<4, 4>));
|
|
2407
|
+
|
|
2408
|
+
inline const private_key<4, 4> *private_key_from_external_44(
|
|
2409
|
+
const MLDSA44_private_key *external) {
|
|
2410
|
+
return reinterpret_cast<const private_key<4, 4> *>(external);
|
|
2411
|
+
}
|
|
2412
|
+
inline private_key<4, 4> *private_key_from_external_44(
|
|
2413
|
+
MLDSA44_private_key *external) {
|
|
2414
|
+
return reinterpret_cast<private_key<4, 4> *>(external);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
static_assert(sizeof(MLDSA44_public_key) == sizeof(public_key<4>));
|
|
2418
|
+
static_assert(alignof(MLDSA44_public_key) == alignof(public_key<4>));
|
|
2419
|
+
|
|
2420
|
+
inline const public_key<4> *public_key_from_external_44(
|
|
2421
|
+
const MLDSA44_public_key *external) {
|
|
2422
|
+
return reinterpret_cast<const public_key<4> *>(external);
|
|
2423
|
+
}
|
|
2424
|
+
inline public_key<4> *public_key_from_external_44(
|
|
2425
|
+
MLDSA44_public_key *external) {
|
|
2426
|
+
return reinterpret_cast<public_key<4> *>(external);
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
inline prehash_context *prehash_context_from_external_44(
|
|
2430
|
+
MLDSA44_prehash *external) {
|
|
2431
|
+
static_assert(sizeof(MLDSA44_prehash) == sizeof(prehash_context));
|
|
2432
|
+
static_assert(alignof(MLDSA44_prehash) == alignof(prehash_context));
|
|
2433
|
+
return reinterpret_cast<prehash_context *>(external);
|
|
1808
2434
|
}
|
|
1809
2435
|
|
|
1810
2436
|
namespace fips {
|
|
1811
2437
|
|
|
1812
2438
|
#include "fips_known_values.inc"
|
|
1813
2439
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
2440
|
+
inline int keygen_self_test() {
|
|
2441
|
+
struct Values {
|
|
2442
|
+
enum { kAllowUniquePtr = true };
|
|
2443
|
+
private_key<6, 5> priv;
|
|
2444
|
+
uint8_t pub_bytes[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2445
|
+
uint8_t priv_bytes[BCM_MLDSA65_PRIVATE_KEY_BYTES];
|
|
2446
|
+
};
|
|
2447
|
+
auto values = MakeUnique<Values>();
|
|
2448
|
+
if (values == nullptr ||
|
|
2449
|
+
!mldsa_generate_key_external_entropy_no_self_test(
|
|
2450
|
+
values->pub_bytes, &values->priv, kGenerateKeyEntropy)) {
|
|
1819
2451
|
return 0;
|
|
1820
2452
|
}
|
|
1821
2453
|
|
|
1822
|
-
uint8_t priv_bytes[BCM_MLDSA65_PRIVATE_KEY_BYTES];
|
|
1823
2454
|
CBB cbb;
|
|
1824
|
-
CBB_init_fixed(&cbb, priv_bytes, sizeof(priv_bytes));
|
|
1825
|
-
if (!mldsa_marshal_private_key(&cbb, &priv)) {
|
|
2455
|
+
CBB_init_fixed(&cbb, values->priv_bytes, sizeof(values->priv_bytes));
|
|
2456
|
+
if (!mldsa_marshal_private_key(&cbb, &values->priv)) {
|
|
1826
2457
|
return 0;
|
|
1827
2458
|
}
|
|
1828
2459
|
|
|
1829
|
-
|
|
1830
|
-
static_assert(sizeof(priv_bytes) == sizeof(kExpectedPrivateKey));
|
|
1831
|
-
if (!BORINGSSL_check_test(kExpectedPublicKey, pub_bytes, sizeof(pub_bytes),
|
|
2460
|
+
if (!BORINGSSL_check_test(kExpectedPublicKey, values->pub_bytes,
|
|
1832
2461
|
"ML-DSA keygen public key") ||
|
|
1833
|
-
!BORINGSSL_check_test(kExpectedPrivateKey, priv_bytes,
|
|
2462
|
+
!BORINGSSL_check_test(kExpectedPrivateKey, values->priv_bytes,
|
|
1834
2463
|
"ML-DSA keygen private key")) {
|
|
1835
2464
|
return 0;
|
|
1836
2465
|
}
|
|
@@ -1838,36 +2467,42 @@ static int keygen_self_test() {
|
|
|
1838
2467
|
return 1;
|
|
1839
2468
|
}
|
|
1840
2469
|
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
2470
|
+
inline int sign_self_test() {
|
|
2471
|
+
struct Values {
|
|
2472
|
+
enum { kAllowUniquePtr = true };
|
|
2473
|
+
private_key<6, 5> priv;
|
|
2474
|
+
uint8_t pub_bytes[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2475
|
+
uint8_t sig[MLDSA65_SIGNATURE_BYTES];
|
|
2476
|
+
};
|
|
2477
|
+
auto values = MakeUnique<Values>();
|
|
2478
|
+
if (values == nullptr ||
|
|
2479
|
+
!mldsa_generate_key_external_entropy(values->pub_bytes, &values->priv,
|
|
2480
|
+
kSignEntropy)) {
|
|
1845
2481
|
return 0;
|
|
1846
2482
|
}
|
|
1847
2483
|
|
|
1848
2484
|
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES] = {};
|
|
1849
|
-
uint8_t sig[BCM_MLDSA65_SIGNATURE_BYTES];
|
|
1850
2485
|
|
|
1851
2486
|
// This message triggers the first restart case for signing.
|
|
1852
2487
|
uint8_t message[4] = {0};
|
|
1853
|
-
if (!mldsa_sign_internal_no_self_test(sig, &priv, message,
|
|
1854
|
-
nullptr, 0, nullptr, 0,
|
|
2488
|
+
if (!mldsa_sign_internal_no_self_test(values->sig, &values->priv, message,
|
|
2489
|
+
sizeof(message), nullptr, 0, nullptr, 0,
|
|
2490
|
+
randomizer)) {
|
|
1855
2491
|
return 0;
|
|
1856
2492
|
}
|
|
1857
|
-
|
|
1858
|
-
if (!BORINGSSL_check_test(kExpectedCase1Signature, sig, sizeof(sig),
|
|
2493
|
+
if (!BORINGSSL_check_test(kExpectedCase1Signature, values->sig,
|
|
1859
2494
|
"ML-DSA sign case 1")) {
|
|
1860
2495
|
return 0;
|
|
1861
2496
|
}
|
|
1862
2497
|
|
|
1863
2498
|
// This message triggers the second restart case for signing.
|
|
1864
2499
|
message[0] = 123;
|
|
1865
|
-
if (!mldsa_sign_internal_no_self_test(sig, &priv, message,
|
|
1866
|
-
nullptr, 0, nullptr, 0,
|
|
2500
|
+
if (!mldsa_sign_internal_no_self_test(values->sig, &values->priv, message,
|
|
2501
|
+
sizeof(message), nullptr, 0, nullptr, 0,
|
|
2502
|
+
randomizer)) {
|
|
1867
2503
|
return 0;
|
|
1868
2504
|
}
|
|
1869
|
-
|
|
1870
|
-
if (!BORINGSSL_check_test(kExpectedCase2Signature, sig, sizeof(sig),
|
|
2505
|
+
if (!BORINGSSL_check_test(kExpectedCase2Signature, values->sig,
|
|
1871
2506
|
"ML-DSA sign case 2")) {
|
|
1872
2507
|
return 0;
|
|
1873
2508
|
}
|
|
@@ -1875,15 +2510,14 @@ static int sign_self_test() {
|
|
|
1875
2510
|
return 1;
|
|
1876
2511
|
}
|
|
1877
2512
|
|
|
1878
|
-
|
|
1879
|
-
struct
|
|
2513
|
+
inline int verify_self_test() {
|
|
2514
|
+
struct Values {
|
|
2515
|
+
enum { kAllowUniquePtr = true };
|
|
1880
2516
|
private_key<6, 5> priv;
|
|
1881
|
-
|
|
1882
|
-
uint8_t pub_bytes[BCM_MLDSA65_PUBLIC_KEY_BYTES];
|
|
2517
|
+
uint8_t pub_bytes[MLDSA65_PUBLIC_KEY_BYTES];
|
|
1883
2518
|
};
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
if (!values) {
|
|
2519
|
+
auto values = MakeUnique<Values>();
|
|
2520
|
+
if (values == nullptr) {
|
|
1887
2521
|
return 0;
|
|
1888
2522
|
}
|
|
1889
2523
|
|
|
@@ -1893,9 +2527,8 @@ static int verify_self_test() {
|
|
|
1893
2527
|
}
|
|
1894
2528
|
|
|
1895
2529
|
const uint8_t message[4] = {1, 0};
|
|
1896
|
-
if (!
|
|
1897
|
-
|
|
1898
|
-
&values->pub, kExpectedVerifySignature, message, sizeof(message),
|
|
2530
|
+
if (!mldsa_verify_internal_no_self_test<6, 5>(
|
|
2531
|
+
&values->priv.pub, kExpectedVerifySignature, message, sizeof(message),
|
|
1899
2532
|
nullptr, 0, nullptr, 0)) {
|
|
1900
2533
|
return 0;
|
|
1901
2534
|
}
|
|
@@ -1904,12 +2537,10 @@ static int verify_self_test() {
|
|
|
1904
2537
|
}
|
|
1905
2538
|
|
|
1906
2539
|
template <int K, int L>
|
|
1907
|
-
int check_key(private_key<K, L> *priv) {
|
|
2540
|
+
inline int check_key(const private_key<K, L> *priv) {
|
|
1908
2541
|
uint8_t sig[signature_bytes<K>()];
|
|
1909
2542
|
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES] = {};
|
|
1910
|
-
|
|
1911
|
-
if (!mldsa_public_from_private(&pub, priv) ||
|
|
1912
|
-
!mldsa_sign_internal_no_self_test(sig, priv, nullptr, 0, nullptr, 0,
|
|
2543
|
+
if (!mldsa_sign_internal_no_self_test(sig, priv, nullptr, 0, nullptr, 0,
|
|
1913
2544
|
nullptr, 0, randomizer)) {
|
|
1914
2545
|
return 0;
|
|
1915
2546
|
}
|
|
@@ -1918,8 +2549,8 @@ int check_key(private_key<K, L> *priv) {
|
|
|
1918
2549
|
sig[0] ^= 1;
|
|
1919
2550
|
}
|
|
1920
2551
|
|
|
1921
|
-
if (!mldsa_verify_internal_no_self_test<K, L>(&pub, sig, nullptr, 0,
|
|
1922
|
-
0, nullptr, 0)) {
|
|
2552
|
+
if (!mldsa_verify_internal_no_self_test<K, L>(&priv->pub, sig, nullptr, 0,
|
|
2553
|
+
nullptr, 0, nullptr, 0)) {
|
|
1923
2554
|
return 0;
|
|
1924
2555
|
}
|
|
1925
2556
|
return 1;
|
|
@@ -1927,9 +2558,7 @@ int check_key(private_key<K, L> *priv) {
|
|
|
1927
2558
|
|
|
1928
2559
|
#if defined(BORINGSSL_FIPS)
|
|
1929
2560
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
void ensure_keygen_self_test(void) {
|
|
2561
|
+
void ensure_keygen_self_test() {
|
|
1933
2562
|
CRYPTO_once(g_mldsa_keygen_self_test_once_bss_get(), []() {
|
|
1934
2563
|
if (!keygen_self_test()) {
|
|
1935
2564
|
BORINGSSL_FIPS_abort();
|
|
@@ -1937,9 +2566,7 @@ void ensure_keygen_self_test(void) {
|
|
|
1937
2566
|
});
|
|
1938
2567
|
}
|
|
1939
2568
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
void ensure_sign_self_test(void) {
|
|
2569
|
+
void ensure_sign_self_test() {
|
|
1943
2570
|
CRYPTO_once(g_mldsa_sign_self_test_once_bss_get(), []() {
|
|
1944
2571
|
if (!sign_self_test()) {
|
|
1945
2572
|
BORINGSSL_FIPS_abort();
|
|
@@ -1947,9 +2574,7 @@ void ensure_sign_self_test(void) {
|
|
|
1947
2574
|
});
|
|
1948
2575
|
}
|
|
1949
2576
|
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
void ensure_verify_self_test(void) {
|
|
2577
|
+
void ensure_verify_self_test() {
|
|
1953
2578
|
CRYPTO_once(g_mldsa_verify_self_test_once_bss_get(), []() {
|
|
1954
2579
|
if (!verify_self_test()) {
|
|
1955
2580
|
BORINGSSL_FIPS_abort();
|
|
@@ -1959,9 +2584,9 @@ void ensure_verify_self_test(void) {
|
|
|
1959
2584
|
|
|
1960
2585
|
#else
|
|
1961
2586
|
|
|
1962
|
-
void ensure_keygen_self_test(
|
|
1963
|
-
void ensure_sign_self_test(
|
|
1964
|
-
void ensure_verify_self_test(
|
|
2587
|
+
void ensure_keygen_self_test() {}
|
|
2588
|
+
void ensure_sign_self_test() {}
|
|
2589
|
+
void ensure_verify_self_test() {}
|
|
1965
2590
|
|
|
1966
2591
|
#endif
|
|
1967
2592
|
|
|
@@ -1973,65 +2598,62 @@ void ensure_verify_self_test(void) {}
|
|
|
1973
2598
|
|
|
1974
2599
|
// ML-DSA-65 specific wrappers.
|
|
1975
2600
|
|
|
1976
|
-
bcm_status BCM_mldsa65_parse_public_key(
|
|
1977
|
-
|
|
2601
|
+
bcm_status bssl::BCM_mldsa65_parse_public_key(MLDSA65_public_key *public_key,
|
|
2602
|
+
CBS *in) {
|
|
1978
2603
|
return bcm_as_approved_status(mldsa_parse_public_key(
|
|
1979
2604
|
mldsa::public_key_from_external_65(public_key), in));
|
|
1980
2605
|
}
|
|
1981
2606
|
|
|
1982
|
-
bcm_status BCM_mldsa65_marshal_private_key(
|
|
1983
|
-
CBB *out, const
|
|
2607
|
+
bcm_status bssl::BCM_mldsa65_marshal_private_key(
|
|
2608
|
+
CBB *out, const MLDSA65_private_key *private_key) {
|
|
1984
2609
|
return bcm_as_approved_status(mldsa_marshal_private_key(
|
|
1985
2610
|
out, mldsa::private_key_from_external_65(private_key)));
|
|
1986
2611
|
}
|
|
1987
2612
|
|
|
1988
|
-
bcm_status BCM_mldsa65_parse_private_key(
|
|
1989
|
-
|
|
2613
|
+
bcm_status bssl::BCM_mldsa65_parse_private_key(MLDSA65_private_key *private_key,
|
|
2614
|
+
CBS *in) {
|
|
1990
2615
|
return bcm_as_approved_status(
|
|
1991
2616
|
mldsa_parse_private_key(mldsa::private_key_from_external_65(private_key),
|
|
1992
2617
|
in) &&
|
|
1993
2618
|
CBS_len(in) == 0);
|
|
1994
2619
|
}
|
|
1995
2620
|
|
|
1996
|
-
bcm_status BCM_mldsa65_check_key_fips(
|
|
1997
|
-
struct BCM_mldsa65_private_key *private_key) {
|
|
2621
|
+
bcm_status bssl::BCM_mldsa65_check_key_fips(MLDSA65_private_key *private_key) {
|
|
1998
2622
|
return bcm_as_approved_status(
|
|
1999
2623
|
mldsa::fips::check_key(mldsa::private_key_from_external_65(private_key)));
|
|
2000
2624
|
}
|
|
2001
2625
|
|
|
2002
|
-
// Calls
|
|
2003
|
-
//
|
|
2004
|
-
bcm_status BCM_mldsa65_generate_key(
|
|
2005
|
-
uint8_t out_encoded_public_key[
|
|
2006
|
-
uint8_t out_seed[
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
CONSTTIME_SECRET(out_seed, BCM_MLDSA_SEED_BYTES);
|
|
2626
|
+
// Calls `MLDSA_generate_key_external_entropy` with random bytes from
|
|
2627
|
+
// `BCM_rand_bytes`.
|
|
2628
|
+
bcm_status bssl::BCM_mldsa65_generate_key(
|
|
2629
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2630
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA65_private_key *out_private_key) {
|
|
2631
|
+
BCM_rand_bytes(out_seed, MLDSA_SEED_BYTES);
|
|
2632
|
+
CONSTTIME_SECRET(out_seed, MLDSA_SEED_BYTES);
|
|
2010
2633
|
return BCM_mldsa65_generate_key_external_entropy(out_encoded_public_key,
|
|
2011
2634
|
out_private_key, out_seed);
|
|
2012
2635
|
}
|
|
2013
2636
|
|
|
2014
|
-
bcm_status BCM_mldsa65_private_key_from_seed(
|
|
2015
|
-
|
|
2016
|
-
const uint8_t seed[
|
|
2017
|
-
uint8_t public_key[
|
|
2637
|
+
bcm_status bssl::BCM_mldsa65_private_key_from_seed(
|
|
2638
|
+
MLDSA65_private_key *out_private_key,
|
|
2639
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2640
|
+
uint8_t public_key[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2018
2641
|
return BCM_mldsa65_generate_key_external_entropy(public_key, out_private_key,
|
|
2019
2642
|
seed);
|
|
2020
2643
|
}
|
|
2021
2644
|
|
|
2022
|
-
bcm_status BCM_mldsa65_generate_key_external_entropy(
|
|
2023
|
-
uint8_t out_encoded_public_key[
|
|
2024
|
-
|
|
2025
|
-
const uint8_t entropy[
|
|
2645
|
+
bcm_status bssl::BCM_mldsa65_generate_key_external_entropy(
|
|
2646
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2647
|
+
MLDSA65_private_key *out_private_key,
|
|
2648
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2026
2649
|
return bcm_as_not_approved_status(mldsa_generate_key_external_entropy(
|
|
2027
2650
|
out_encoded_public_key,
|
|
2028
2651
|
mldsa::private_key_from_external_65(out_private_key), entropy));
|
|
2029
2652
|
}
|
|
2030
2653
|
|
|
2031
|
-
bcm_status BCM_mldsa65_generate_key_fips(
|
|
2032
|
-
uint8_t out_encoded_public_key[
|
|
2033
|
-
uint8_t out_seed[
|
|
2034
|
-
struct BCM_mldsa65_private_key *out_private_key) {
|
|
2654
|
+
bcm_status bssl::BCM_mldsa65_generate_key_fips(
|
|
2655
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2656
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA65_private_key *out_private_key) {
|
|
2035
2657
|
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2036
2658
|
return bcm_status::failure;
|
|
2037
2659
|
}
|
|
@@ -2042,10 +2664,10 @@ bcm_status BCM_mldsa65_generate_key_fips(
|
|
|
2042
2664
|
return BCM_mldsa65_check_key_fips(out_private_key);
|
|
2043
2665
|
}
|
|
2044
2666
|
|
|
2045
|
-
bcm_status BCM_mldsa65_generate_key_external_entropy_fips(
|
|
2046
|
-
uint8_t out_encoded_public_key[
|
|
2047
|
-
|
|
2048
|
-
const uint8_t entropy[
|
|
2667
|
+
bcm_status bssl::BCM_mldsa65_generate_key_external_entropy_fips(
|
|
2668
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2669
|
+
MLDSA65_private_key *out_private_key,
|
|
2670
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2049
2671
|
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2050
2672
|
return bcm_status::failure;
|
|
2051
2673
|
}
|
|
@@ -2057,10 +2679,10 @@ bcm_status BCM_mldsa65_generate_key_external_entropy_fips(
|
|
|
2057
2679
|
return BCM_mldsa65_check_key_fips(out_private_key);
|
|
2058
2680
|
}
|
|
2059
2681
|
|
|
2060
|
-
bcm_status BCM_mldsa65_private_key_from_seed_fips(
|
|
2061
|
-
|
|
2062
|
-
const uint8_t seed[
|
|
2063
|
-
uint8_t public_key[
|
|
2682
|
+
bcm_status bssl::BCM_mldsa65_private_key_from_seed_fips(
|
|
2683
|
+
MLDSA65_private_key *out_private_key,
|
|
2684
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2685
|
+
uint8_t public_key[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2064
2686
|
if (BCM_mldsa65_generate_key_external_entropy(public_key, out_private_key,
|
|
2065
2687
|
seed) == bcm_status::failure) {
|
|
2066
2688
|
return bcm_status::failure;
|
|
@@ -2068,18 +2690,25 @@ bcm_status BCM_mldsa65_private_key_from_seed_fips(
|
|
|
2068
2690
|
return BCM_mldsa65_check_key_fips(out_private_key);
|
|
2069
2691
|
}
|
|
2070
2692
|
|
|
2071
|
-
bcm_status BCM_mldsa65_public_from_private(
|
|
2072
|
-
|
|
2073
|
-
const
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2693
|
+
bcm_status bssl::BCM_mldsa65_public_from_private(
|
|
2694
|
+
MLDSA65_public_key *out_public_key,
|
|
2695
|
+
const MLDSA65_private_key *private_key) {
|
|
2696
|
+
const auto *priv = mldsa::private_key_from_external_65(private_key);
|
|
2697
|
+
auto *out_pub = mldsa::public_key_from_external_65(out_public_key);
|
|
2698
|
+
*out_pub = priv->pub;
|
|
2699
|
+
return bcm_status::approved;
|
|
2077
2700
|
}
|
|
2078
2701
|
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2702
|
+
const MLDSA65_public_key *bssl::BCM_mldsa65_public_of_private(
|
|
2703
|
+
const MLDSA65_private_key *private_key) {
|
|
2704
|
+
return reinterpret_cast<const MLDSA65_public_key *>(
|
|
2705
|
+
&mldsa::private_key_from_external_65(private_key)->pub);
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
bcm_status bssl::BCM_mldsa65_sign_internal(
|
|
2709
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2710
|
+
const MLDSA65_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2711
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2083
2712
|
const uint8_t *context, size_t context_len,
|
|
2084
2713
|
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2085
2714
|
return bcm_as_approved_status(mldsa_sign_internal(
|
|
@@ -2088,12 +2717,22 @@ bcm_status BCM_mldsa65_sign_internal(
|
|
|
2088
2717
|
randomizer));
|
|
2089
2718
|
}
|
|
2090
2719
|
|
|
2720
|
+
bcm_status bssl::BCM_mldsa65_sign_mu_internal(
|
|
2721
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2722
|
+
const MLDSA65_private_key *private_key,
|
|
2723
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES],
|
|
2724
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2725
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
2726
|
+
out_encoded_signature, mldsa::private_key_from_external_65(private_key),
|
|
2727
|
+
msg_rep, randomizer));
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2091
2730
|
// ML-DSA signature in randomized mode, filling the random bytes with
|
|
2092
|
-
//
|
|
2093
|
-
bcm_status BCM_mldsa65_sign(
|
|
2094
|
-
uint8_t out_encoded_signature[
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2731
|
+
// `BCM_rand_bytes`.
|
|
2732
|
+
bcm_status bssl::BCM_mldsa65_sign(
|
|
2733
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2734
|
+
const MLDSA65_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2735
|
+
const uint8_t *context, size_t context_len) {
|
|
2097
2736
|
BSSL_CHECK(context_len <= 255);
|
|
2098
2737
|
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
2099
2738
|
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
@@ -2105,10 +2744,61 @@ bcm_status BCM_mldsa65_sign(
|
|
|
2105
2744
|
sizeof(context_prefix), context, context_len, randomizer);
|
|
2106
2745
|
}
|
|
2107
2746
|
|
|
2747
|
+
// ML-DSA pre-hashed API: initializing a pre-hashing context.
|
|
2748
|
+
void bssl::BCM_mldsa65_prehash_init(MLDSA65_prehash *out_prehash_ctx,
|
|
2749
|
+
const MLDSA65_public_key *public_key,
|
|
2750
|
+
const uint8_t *context,
|
|
2751
|
+
size_t context_len) {
|
|
2752
|
+
BSSL_CHECK(context_len <= 255);
|
|
2753
|
+
|
|
2754
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2755
|
+
mldsa_prehash_init(mldsa::prehash_context_from_external_65(out_prehash_ctx),
|
|
2756
|
+
mldsa::public_key_from_external_65(public_key),
|
|
2757
|
+
context_prefix, sizeof(context_prefix), context,
|
|
2758
|
+
context_len);
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
// ML-DSA pre-hashed API: updating a pre-hashing context with a message chunk.
|
|
2762
|
+
void bssl::BCM_mldsa65_prehash_update(MLDSA65_prehash *inout_prehash_ctx,
|
|
2763
|
+
const uint8_t *msg, size_t msg_len) {
|
|
2764
|
+
mldsa_prehash_update(
|
|
2765
|
+
mldsa::prehash_context_from_external_65(inout_prehash_ctx), msg, msg_len);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
// ML-DSA pre-hashed API: obtaining a message representative to sign.
|
|
2769
|
+
void bssl::BCM_mldsa65_prehash_finalize(uint8_t out_msg_rep[MLDSA_MU_BYTES],
|
|
2770
|
+
MLDSA65_prehash *inout_prehash_ctx) {
|
|
2771
|
+
mldsa_prehash_finalize(
|
|
2772
|
+
out_msg_rep, mldsa::prehash_context_from_external_65(inout_prehash_ctx));
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
// ML-DSA pre-hashed API: signing a message representative.
|
|
2776
|
+
bcm_status bssl::BCM_mldsa65_sign_message_representative(
|
|
2777
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2778
|
+
const MLDSA65_private_key *private_key,
|
|
2779
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
2780
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
2781
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
2782
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
2783
|
+
|
|
2784
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
2785
|
+
out_encoded_signature, mldsa::private_key_from_external_65(private_key),
|
|
2786
|
+
msg_rep, randomizer));
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
// ML-DSA pre-hashed API: verifying a message representative.
|
|
2790
|
+
bcm_status bssl::BCM_mldsa65_verify_message_representative(
|
|
2791
|
+
const MLDSA65_public_key *public_key,
|
|
2792
|
+
const uint8_t signature[MLDSA65_SIGNATURE_BYTES],
|
|
2793
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
2794
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_mu<6, 5>(
|
|
2795
|
+
mldsa::public_key_from_external_65(public_key), signature, msg_rep));
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2108
2798
|
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
|
2109
|
-
bcm_status BCM_mldsa65_verify(
|
|
2110
|
-
const
|
|
2111
|
-
const uint8_t signature[
|
|
2799
|
+
bcm_status bssl::BCM_mldsa65_verify(
|
|
2800
|
+
const MLDSA65_public_key *public_key,
|
|
2801
|
+
const uint8_t signature[MLDSA65_SIGNATURE_BYTES], const uint8_t *msg,
|
|
2112
2802
|
size_t msg_len, const uint8_t *context, size_t context_len) {
|
|
2113
2803
|
BSSL_CHECK(context_len <= 255);
|
|
2114
2804
|
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
@@ -2117,9 +2807,9 @@ bcm_status BCM_mldsa65_verify(
|
|
|
2117
2807
|
context, context_len);
|
|
2118
2808
|
}
|
|
2119
2809
|
|
|
2120
|
-
bcm_status BCM_mldsa65_verify_internal(
|
|
2121
|
-
const
|
|
2122
|
-
const uint8_t encoded_signature[
|
|
2810
|
+
bcm_status bssl::BCM_mldsa65_verify_internal(
|
|
2811
|
+
const MLDSA65_public_key *public_key,
|
|
2812
|
+
const uint8_t encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2123
2813
|
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
|
2124
2814
|
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
|
2125
2815
|
return bcm_as_approved_status(mldsa::mldsa_verify_internal<6, 5>(
|
|
@@ -2127,73 +2817,83 @@ bcm_status BCM_mldsa65_verify_internal(
|
|
|
2127
2817
|
msg_len, context_prefix, context_prefix_len, context, context_len));
|
|
2128
2818
|
}
|
|
2129
2819
|
|
|
2130
|
-
bcm_status BCM_mldsa65_marshal_public_key(
|
|
2131
|
-
CBB *out, const
|
|
2820
|
+
bcm_status bssl::BCM_mldsa65_marshal_public_key(
|
|
2821
|
+
CBB *out, const MLDSA65_public_key *public_key) {
|
|
2132
2822
|
return bcm_as_approved_status(mldsa_marshal_public_key(
|
|
2133
2823
|
out, mldsa::public_key_from_external_65(public_key)));
|
|
2134
2824
|
}
|
|
2135
2825
|
|
|
2826
|
+
int bssl::BCM_mldsa65_public_keys_equal(const MLDSA65_public_key *a,
|
|
2827
|
+
const MLDSA65_public_key *b) {
|
|
2828
|
+
auto *a_pub = mldsa::public_key_from_external_65(a);
|
|
2829
|
+
auto *b_pub = mldsa::public_key_from_external_65(b);
|
|
2830
|
+
// It is sufficient to compare `public_key_hash`. When importing a public key,
|
|
2831
|
+
// the hash must be computed. When importing a private key in expanded form
|
|
2832
|
+
// (an internal testing-only API), the hash is provided, but we recompute it
|
|
2833
|
+
// and check for correctness.
|
|
2834
|
+
return OPENSSL_memcmp(a_pub->public_key_hash, b_pub->public_key_hash,
|
|
2835
|
+
sizeof(a_pub->public_key_hash)) == 0;
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2136
2838
|
|
|
2137
2839
|
// ML-DSA-87 specific wrappers.
|
|
2138
2840
|
|
|
2139
|
-
bcm_status BCM_mldsa87_parse_public_key(
|
|
2140
|
-
|
|
2841
|
+
bcm_status bssl::BCM_mldsa87_parse_public_key(MLDSA87_public_key *public_key,
|
|
2842
|
+
CBS *in) {
|
|
2141
2843
|
return bcm_as_approved_status(mldsa_parse_public_key(
|
|
2142
2844
|
mldsa::public_key_from_external_87(public_key), in));
|
|
2143
2845
|
}
|
|
2144
2846
|
|
|
2145
|
-
bcm_status BCM_mldsa87_marshal_private_key(
|
|
2146
|
-
CBB *out, const
|
|
2847
|
+
bcm_status bssl::BCM_mldsa87_marshal_private_key(
|
|
2848
|
+
CBB *out, const MLDSA87_private_key *private_key) {
|
|
2147
2849
|
return bcm_as_approved_status(mldsa_marshal_private_key(
|
|
2148
2850
|
out, mldsa::private_key_from_external_87(private_key)));
|
|
2149
2851
|
}
|
|
2150
2852
|
|
|
2151
|
-
bcm_status BCM_mldsa87_parse_private_key(
|
|
2152
|
-
|
|
2853
|
+
bcm_status bssl::BCM_mldsa87_parse_private_key(MLDSA87_private_key *private_key,
|
|
2854
|
+
CBS *in) {
|
|
2153
2855
|
return bcm_as_approved_status(
|
|
2154
2856
|
mldsa_parse_private_key(mldsa::private_key_from_external_87(private_key),
|
|
2155
2857
|
in) &&
|
|
2156
2858
|
CBS_len(in) == 0);
|
|
2157
2859
|
}
|
|
2158
2860
|
|
|
2159
|
-
bcm_status BCM_mldsa87_check_key_fips(
|
|
2160
|
-
struct BCM_mldsa87_private_key *private_key) {
|
|
2861
|
+
bcm_status bssl::BCM_mldsa87_check_key_fips(MLDSA87_private_key *private_key) {
|
|
2161
2862
|
return bcm_as_approved_status(
|
|
2162
2863
|
mldsa::fips::check_key(mldsa::private_key_from_external_87(private_key)));
|
|
2163
2864
|
}
|
|
2164
2865
|
|
|
2165
|
-
// Calls
|
|
2166
|
-
//
|
|
2167
|
-
bcm_status BCM_mldsa87_generate_key(
|
|
2168
|
-
uint8_t out_encoded_public_key[
|
|
2169
|
-
uint8_t out_seed[
|
|
2170
|
-
|
|
2171
|
-
|
|
2866
|
+
// Calls `MLDSA_generate_key_external_entropy` with random bytes from
|
|
2867
|
+
// `BCM_rand_bytes`.
|
|
2868
|
+
bcm_status bssl::BCM_mldsa87_generate_key(
|
|
2869
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2870
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA87_private_key *out_private_key) {
|
|
2871
|
+
BCM_rand_bytes(out_seed, MLDSA_SEED_BYTES);
|
|
2872
|
+
CONSTTIME_SECRET(out_seed, MLDSA_SEED_BYTES);
|
|
2172
2873
|
return BCM_mldsa87_generate_key_external_entropy(out_encoded_public_key,
|
|
2173
2874
|
out_private_key, out_seed);
|
|
2174
2875
|
}
|
|
2175
2876
|
|
|
2176
|
-
bcm_status BCM_mldsa87_private_key_from_seed(
|
|
2177
|
-
|
|
2178
|
-
const uint8_t seed[
|
|
2179
|
-
uint8_t public_key[
|
|
2877
|
+
bcm_status bssl::BCM_mldsa87_private_key_from_seed(
|
|
2878
|
+
MLDSA87_private_key *out_private_key,
|
|
2879
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2880
|
+
uint8_t public_key[MLDSA87_PUBLIC_KEY_BYTES];
|
|
2180
2881
|
return BCM_mldsa87_generate_key_external_entropy(public_key, out_private_key,
|
|
2181
2882
|
seed);
|
|
2182
2883
|
}
|
|
2183
2884
|
|
|
2184
|
-
bcm_status BCM_mldsa87_generate_key_external_entropy(
|
|
2185
|
-
uint8_t out_encoded_public_key[
|
|
2186
|
-
|
|
2187
|
-
const uint8_t entropy[
|
|
2885
|
+
bcm_status bssl::BCM_mldsa87_generate_key_external_entropy(
|
|
2886
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2887
|
+
MLDSA87_private_key *out_private_key,
|
|
2888
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2188
2889
|
return bcm_as_not_approved_status(mldsa_generate_key_external_entropy(
|
|
2189
2890
|
out_encoded_public_key,
|
|
2190
2891
|
mldsa::private_key_from_external_87(out_private_key), entropy));
|
|
2191
2892
|
}
|
|
2192
2893
|
|
|
2193
|
-
bcm_status BCM_mldsa87_generate_key_fips(
|
|
2194
|
-
uint8_t out_encoded_public_key[
|
|
2195
|
-
uint8_t out_seed[
|
|
2196
|
-
struct BCM_mldsa87_private_key *out_private_key) {
|
|
2894
|
+
bcm_status bssl::BCM_mldsa87_generate_key_fips(
|
|
2895
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2896
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA87_private_key *out_private_key) {
|
|
2197
2897
|
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2198
2898
|
return bcm_status::failure;
|
|
2199
2899
|
}
|
|
@@ -2204,10 +2904,10 @@ bcm_status BCM_mldsa87_generate_key_fips(
|
|
|
2204
2904
|
return BCM_mldsa87_check_key_fips(out_private_key);
|
|
2205
2905
|
}
|
|
2206
2906
|
|
|
2207
|
-
bcm_status BCM_mldsa87_generate_key_external_entropy_fips(
|
|
2208
|
-
uint8_t out_encoded_public_key[
|
|
2209
|
-
|
|
2210
|
-
const uint8_t entropy[
|
|
2907
|
+
bcm_status bssl::BCM_mldsa87_generate_key_external_entropy_fips(
|
|
2908
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2909
|
+
MLDSA87_private_key *out_private_key,
|
|
2910
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2211
2911
|
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2212
2912
|
return bcm_status::failure;
|
|
2213
2913
|
}
|
|
@@ -2219,10 +2919,10 @@ bcm_status BCM_mldsa87_generate_key_external_entropy_fips(
|
|
|
2219
2919
|
return BCM_mldsa87_check_key_fips(out_private_key);
|
|
2220
2920
|
}
|
|
2221
2921
|
|
|
2222
|
-
bcm_status BCM_mldsa87_private_key_from_seed_fips(
|
|
2223
|
-
|
|
2224
|
-
const uint8_t seed[
|
|
2225
|
-
uint8_t public_key[
|
|
2922
|
+
bcm_status bssl::BCM_mldsa87_private_key_from_seed_fips(
|
|
2923
|
+
MLDSA87_private_key *out_private_key,
|
|
2924
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2925
|
+
uint8_t public_key[MLDSA87_PUBLIC_KEY_BYTES];
|
|
2226
2926
|
if (BCM_mldsa87_generate_key_external_entropy(public_key, out_private_key,
|
|
2227
2927
|
seed) == bcm_status::failure) {
|
|
2228
2928
|
return bcm_status::failure;
|
|
@@ -2230,18 +2930,25 @@ bcm_status BCM_mldsa87_private_key_from_seed_fips(
|
|
|
2230
2930
|
return BCM_mldsa87_check_key_fips(out_private_key);
|
|
2231
2931
|
}
|
|
2232
2932
|
|
|
2233
|
-
bcm_status BCM_mldsa87_public_from_private(
|
|
2234
|
-
|
|
2235
|
-
const
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2933
|
+
bcm_status bssl::BCM_mldsa87_public_from_private(
|
|
2934
|
+
MLDSA87_public_key *out_public_key,
|
|
2935
|
+
const MLDSA87_private_key *private_key) {
|
|
2936
|
+
const auto *priv = mldsa::private_key_from_external_87(private_key);
|
|
2937
|
+
auto *out_pub = mldsa::public_key_from_external_87(out_public_key);
|
|
2938
|
+
*out_pub = priv->pub;
|
|
2939
|
+
return bcm_status::approved;
|
|
2239
2940
|
}
|
|
2240
2941
|
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2942
|
+
const MLDSA87_public_key *bssl::BCM_mldsa87_public_of_private(
|
|
2943
|
+
const MLDSA87_private_key *private_key) {
|
|
2944
|
+
return reinterpret_cast<const MLDSA87_public_key *>(
|
|
2945
|
+
&mldsa::private_key_from_external_87(private_key)->pub);
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
bcm_status bssl::BCM_mldsa87_sign_internal(
|
|
2949
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2950
|
+
const MLDSA87_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2951
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2245
2952
|
const uint8_t *context, size_t context_len,
|
|
2246
2953
|
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2247
2954
|
return bcm_as_approved_status(mldsa_sign_internal(
|
|
@@ -2250,15 +2957,26 @@ bcm_status BCM_mldsa87_sign_internal(
|
|
|
2250
2957
|
randomizer));
|
|
2251
2958
|
}
|
|
2252
2959
|
|
|
2960
|
+
bcm_status bssl::BCM_mldsa87_sign_mu_internal(
|
|
2961
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2962
|
+
const MLDSA87_private_key *private_key,
|
|
2963
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES],
|
|
2964
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2965
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
2966
|
+
out_encoded_signature, mldsa::private_key_from_external_87(private_key),
|
|
2967
|
+
msg_rep, randomizer));
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2253
2970
|
// ML-DSA signature in randomized mode, filling the random bytes with
|
|
2254
|
-
//
|
|
2255
|
-
bcm_status BCM_mldsa87_sign(
|
|
2256
|
-
uint8_t out_encoded_signature[
|
|
2257
|
-
const
|
|
2258
|
-
|
|
2971
|
+
// `BCM_rand_bytes`.
|
|
2972
|
+
bcm_status bssl::BCM_mldsa87_sign(
|
|
2973
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2974
|
+
const MLDSA87_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2975
|
+
const uint8_t *context, size_t context_len) {
|
|
2259
2976
|
BSSL_CHECK(context_len <= 255);
|
|
2260
2977
|
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
2261
2978
|
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
2979
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
2262
2980
|
|
|
2263
2981
|
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2264
2982
|
return BCM_mldsa87_sign_internal(
|
|
@@ -2266,11 +2984,63 @@ bcm_status BCM_mldsa87_sign(
|
|
|
2266
2984
|
sizeof(context_prefix), context, context_len, randomizer);
|
|
2267
2985
|
}
|
|
2268
2986
|
|
|
2987
|
+
// ML-DSA pre-hashed API: initializing a pre-hashing context.
|
|
2988
|
+
void bssl::BCM_mldsa87_prehash_init(MLDSA87_prehash *out_prehash_ctx,
|
|
2989
|
+
const MLDSA87_public_key *public_key,
|
|
2990
|
+
const uint8_t *context,
|
|
2991
|
+
size_t context_len) {
|
|
2992
|
+
BSSL_CHECK(context_len <= 255);
|
|
2993
|
+
|
|
2994
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2995
|
+
mldsa_prehash_init(mldsa::prehash_context_from_external_87(out_prehash_ctx),
|
|
2996
|
+
mldsa::public_key_from_external_87(public_key),
|
|
2997
|
+
context_prefix, sizeof(context_prefix), context,
|
|
2998
|
+
context_len);
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
// ML-DSA pre-hashed API: updating a pre-hashing context with a message chunk.
|
|
3002
|
+
void bssl::BCM_mldsa87_prehash_update(MLDSA87_prehash *inout_prehash_ctx,
|
|
3003
|
+
const uint8_t *msg, size_t msg_len) {
|
|
3004
|
+
mldsa_prehash_update(
|
|
3005
|
+
mldsa::prehash_context_from_external_87(inout_prehash_ctx), msg, msg_len);
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
// ML-DSA pre-hashed API: obtaining a message representative to sign.
|
|
3009
|
+
void bssl::BCM_mldsa87_prehash_finalize(uint8_t out_msg_rep[MLDSA_MU_BYTES],
|
|
3010
|
+
MLDSA87_prehash *inout_prehash_ctx) {
|
|
3011
|
+
mldsa_prehash_finalize(
|
|
3012
|
+
out_msg_rep, mldsa::prehash_context_from_external_87(inout_prehash_ctx));
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
// ML-DSA pre-hashed API: signing a message representative.
|
|
3016
|
+
bcm_status bssl::BCM_mldsa87_sign_message_representative(
|
|
3017
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
3018
|
+
const MLDSA87_private_key *private_key,
|
|
3019
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3020
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
3021
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
3022
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
3023
|
+
|
|
3024
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
3025
|
+
out_encoded_signature, mldsa::private_key_from_external_87(private_key),
|
|
3026
|
+
msg_rep, randomizer));
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
// ML-DSA pre-hashed API: verifying a message representative.
|
|
3030
|
+
bcm_status bssl::BCM_mldsa87_verify_message_representative(
|
|
3031
|
+
const MLDSA87_public_key *public_key,
|
|
3032
|
+
const uint8_t signature[MLDSA87_SIGNATURE_BYTES],
|
|
3033
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3034
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_mu<8, 7>(
|
|
3035
|
+
mldsa::public_key_from_external_87(public_key), signature, msg_rep));
|
|
3036
|
+
}
|
|
3037
|
+
|
|
2269
3038
|
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
|
2270
|
-
bcm_status BCM_mldsa87_verify(const
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
3039
|
+
bcm_status bssl::BCM_mldsa87_verify(const MLDSA87_public_key *public_key,
|
|
3040
|
+
const uint8_t *signature,
|
|
3041
|
+
const uint8_t *msg, size_t msg_len,
|
|
3042
|
+
const uint8_t *context,
|
|
3043
|
+
size_t context_len) {
|
|
2274
3044
|
BSSL_CHECK(context_len <= 255);
|
|
2275
3045
|
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2276
3046
|
return BCM_mldsa87_verify_internal(public_key, signature, msg, msg_len,
|
|
@@ -2278,9 +3048,9 @@ bcm_status BCM_mldsa87_verify(const struct BCM_mldsa87_public_key *public_key,
|
|
|
2278
3048
|
context, context_len);
|
|
2279
3049
|
}
|
|
2280
3050
|
|
|
2281
|
-
bcm_status BCM_mldsa87_verify_internal(
|
|
2282
|
-
const
|
|
2283
|
-
const uint8_t encoded_signature[
|
|
3051
|
+
bcm_status bssl::BCM_mldsa87_verify_internal(
|
|
3052
|
+
const MLDSA87_public_key *public_key,
|
|
3053
|
+
const uint8_t encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2284
3054
|
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
|
2285
3055
|
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
|
2286
3056
|
return bcm_as_approved_status(mldsa::mldsa_verify_internal<8, 7>(
|
|
@@ -2288,13 +3058,266 @@ bcm_status BCM_mldsa87_verify_internal(
|
|
|
2288
3058
|
msg_len, context_prefix, context_prefix_len, context, context_len));
|
|
2289
3059
|
}
|
|
2290
3060
|
|
|
2291
|
-
bcm_status BCM_mldsa87_marshal_public_key(
|
|
2292
|
-
CBB *out, const
|
|
3061
|
+
bcm_status bssl::BCM_mldsa87_marshal_public_key(
|
|
3062
|
+
CBB *out, const MLDSA87_public_key *public_key) {
|
|
2293
3063
|
return bcm_as_approved_status(mldsa_marshal_public_key(
|
|
2294
3064
|
out, mldsa::public_key_from_external_87(public_key)));
|
|
2295
3065
|
}
|
|
2296
3066
|
|
|
2297
|
-
int
|
|
3067
|
+
int bssl::BCM_mldsa87_public_keys_equal(const MLDSA87_public_key *a,
|
|
3068
|
+
const MLDSA87_public_key *b) {
|
|
3069
|
+
auto *a_pub = mldsa::public_key_from_external_87(a);
|
|
3070
|
+
auto *b_pub = mldsa::public_key_from_external_87(b);
|
|
3071
|
+
// It is sufficient to compare `public_key_hash`. When importing a public key,
|
|
3072
|
+
// the hash must be computed. When importing a private key in expanded form
|
|
3073
|
+
// (an internal testing-only API), the hash is provided, but we recompute it
|
|
3074
|
+
// and check for correctness.
|
|
3075
|
+
return OPENSSL_memcmp(a_pub->public_key_hash, b_pub->public_key_hash,
|
|
3076
|
+
sizeof(a_pub->public_key_hash)) == 0;
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
|
|
3080
|
+
// ML-DSA-44 specific wrappers.
|
|
3081
|
+
|
|
3082
|
+
bcm_status bssl::BCM_mldsa44_parse_public_key(MLDSA44_public_key *public_key,
|
|
3083
|
+
CBS *in) {
|
|
3084
|
+
return bcm_as_approved_status(mldsa_parse_public_key(
|
|
3085
|
+
mldsa::public_key_from_external_44(public_key), in));
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
bcm_status bssl::BCM_mldsa44_marshal_private_key(
|
|
3089
|
+
CBB *out, const MLDSA44_private_key *private_key) {
|
|
3090
|
+
return bcm_as_approved_status(mldsa_marshal_private_key(
|
|
3091
|
+
out, mldsa::private_key_from_external_44(private_key)));
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
bcm_status bssl::BCM_mldsa44_parse_private_key(MLDSA44_private_key *private_key,
|
|
3095
|
+
CBS *in) {
|
|
3096
|
+
return bcm_as_approved_status(
|
|
3097
|
+
mldsa_parse_private_key(mldsa::private_key_from_external_44(private_key),
|
|
3098
|
+
in) &&
|
|
3099
|
+
CBS_len(in) == 0);
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
bcm_status bssl::BCM_mldsa44_check_key_fips(MLDSA44_private_key *private_key) {
|
|
3103
|
+
return bcm_as_approved_status(
|
|
3104
|
+
mldsa::fips::check_key(mldsa::private_key_from_external_44(private_key)));
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
// Calls `MLDSA_generate_key_external_entropy` with random bytes from
|
|
3108
|
+
// `BCM_rand_bytes`.
|
|
3109
|
+
bcm_status bssl::BCM_mldsa44_generate_key(
|
|
3110
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3111
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA44_private_key *out_private_key) {
|
|
3112
|
+
BCM_rand_bytes(out_seed, MLDSA_SEED_BYTES);
|
|
3113
|
+
CONSTTIME_SECRET(out_seed, MLDSA_SEED_BYTES);
|
|
3114
|
+
return BCM_mldsa44_generate_key_external_entropy(out_encoded_public_key,
|
|
3115
|
+
out_private_key, out_seed);
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
bcm_status bssl::BCM_mldsa44_private_key_from_seed(
|
|
3119
|
+
MLDSA44_private_key *out_private_key,
|
|
3120
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
3121
|
+
uint8_t public_key[MLDSA44_PUBLIC_KEY_BYTES];
|
|
3122
|
+
return BCM_mldsa44_generate_key_external_entropy(public_key, out_private_key,
|
|
3123
|
+
seed);
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
bcm_status bssl::BCM_mldsa44_generate_key_external_entropy(
|
|
3127
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3128
|
+
MLDSA44_private_key *out_private_key,
|
|
3129
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
3130
|
+
return bcm_as_not_approved_status(mldsa_generate_key_external_entropy(
|
|
3131
|
+
out_encoded_public_key,
|
|
3132
|
+
mldsa::private_key_from_external_44(out_private_key), entropy));
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
bcm_status bssl::BCM_mldsa44_generate_key_fips(
|
|
3136
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3137
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA44_private_key *out_private_key) {
|
|
3138
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
3139
|
+
return bcm_status::failure;
|
|
3140
|
+
}
|
|
3141
|
+
if (BCM_mldsa44_generate_key(out_encoded_public_key, out_seed,
|
|
3142
|
+
out_private_key) == bcm_status::failure) {
|
|
3143
|
+
return bcm_status::failure;
|
|
3144
|
+
}
|
|
3145
|
+
return BCM_mldsa44_check_key_fips(out_private_key);
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
bcm_status bssl::BCM_mldsa44_generate_key_external_entropy_fips(
|
|
3149
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3150
|
+
MLDSA44_private_key *out_private_key,
|
|
3151
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
3152
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
3153
|
+
return bcm_status::failure;
|
|
3154
|
+
}
|
|
3155
|
+
if (BCM_mldsa44_generate_key_external_entropy(out_encoded_public_key,
|
|
3156
|
+
out_private_key, entropy) ==
|
|
3157
|
+
bcm_status::failure) {
|
|
3158
|
+
return bcm_status::failure;
|
|
3159
|
+
}
|
|
3160
|
+
return BCM_mldsa44_check_key_fips(out_private_key);
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
bcm_status bssl::BCM_mldsa44_private_key_from_seed_fips(
|
|
3164
|
+
MLDSA44_private_key *out_private_key,
|
|
3165
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
3166
|
+
uint8_t public_key[MLDSA44_PUBLIC_KEY_BYTES];
|
|
3167
|
+
if (BCM_mldsa44_generate_key_external_entropy(public_key, out_private_key,
|
|
3168
|
+
seed) == bcm_status::failure) {
|
|
3169
|
+
return bcm_status::failure;
|
|
3170
|
+
}
|
|
3171
|
+
return BCM_mldsa44_check_key_fips(out_private_key);
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
bcm_status bssl::BCM_mldsa44_public_from_private(
|
|
3175
|
+
MLDSA44_public_key *out_public_key,
|
|
3176
|
+
const MLDSA44_private_key *private_key) {
|
|
3177
|
+
const auto *priv = mldsa::private_key_from_external_44(private_key);
|
|
3178
|
+
auto *out_pub = mldsa::public_key_from_external_44(out_public_key);
|
|
3179
|
+
*out_pub = priv->pub;
|
|
3180
|
+
return bcm_status::approved;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
const MLDSA44_public_key *bssl::BCM_mldsa44_public_of_private(
|
|
3184
|
+
const MLDSA44_private_key *private_key) {
|
|
3185
|
+
return reinterpret_cast<const MLDSA44_public_key *>(
|
|
3186
|
+
&mldsa::private_key_from_external_44(private_key)->pub);
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3189
|
+
bcm_status bssl::BCM_mldsa44_sign_internal(
|
|
3190
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3191
|
+
const MLDSA44_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
3192
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
3193
|
+
const uint8_t *context, size_t context_len,
|
|
3194
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
3195
|
+
return bcm_as_approved_status(mldsa_sign_internal(
|
|
3196
|
+
out_encoded_signature, mldsa::private_key_from_external_44(private_key),
|
|
3197
|
+
msg, msg_len, context_prefix, context_prefix_len, context, context_len,
|
|
3198
|
+
randomizer));
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
bcm_status bssl::BCM_mldsa44_sign_mu_internal(
|
|
3202
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3203
|
+
const MLDSA44_private_key *private_key,
|
|
3204
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES],
|
|
3205
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
3206
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
3207
|
+
out_encoded_signature, mldsa::private_key_from_external_44(private_key),
|
|
3208
|
+
msg_rep, randomizer));
|
|
3209
|
+
}
|
|
3210
|
+
|
|
3211
|
+
// ML-DSA signature in randomized mode, filling the random bytes with
|
|
3212
|
+
// `BCM_rand_bytes`.
|
|
3213
|
+
bcm_status bssl::BCM_mldsa44_sign(
|
|
3214
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3215
|
+
const MLDSA44_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
3216
|
+
const uint8_t *context, size_t context_len) {
|
|
3217
|
+
BSSL_CHECK(context_len <= 255);
|
|
3218
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
3219
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
3220
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
3221
|
+
|
|
3222
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3223
|
+
return BCM_mldsa44_sign_internal(
|
|
3224
|
+
out_encoded_signature, private_key, msg, msg_len, context_prefix,
|
|
3225
|
+
sizeof(context_prefix), context, context_len, randomizer);
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
// ML-DSA pre-hashed API: initializing a pre-hashing context.
|
|
3229
|
+
void bssl::BCM_mldsa44_prehash_init(MLDSA44_prehash *out_prehash_ctx,
|
|
3230
|
+
const MLDSA44_public_key *public_key,
|
|
3231
|
+
const uint8_t *context,
|
|
3232
|
+
size_t context_len) {
|
|
3233
|
+
BSSL_CHECK(context_len <= 255);
|
|
3234
|
+
|
|
3235
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3236
|
+
mldsa_prehash_init(mldsa::prehash_context_from_external_44(out_prehash_ctx),
|
|
3237
|
+
mldsa::public_key_from_external_44(public_key),
|
|
3238
|
+
context_prefix, sizeof(context_prefix), context,
|
|
3239
|
+
context_len);
|
|
3240
|
+
}
|
|
3241
|
+
|
|
3242
|
+
// ML-DSA pre-hashed API: updating a pre-hashing context with a message chunk.
|
|
3243
|
+
void bssl::BCM_mldsa44_prehash_update(MLDSA44_prehash *inout_prehash_ctx,
|
|
3244
|
+
const uint8_t *msg, size_t msg_len) {
|
|
3245
|
+
mldsa_prehash_update(
|
|
3246
|
+
mldsa::prehash_context_from_external_44(inout_prehash_ctx), msg, msg_len);
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
// ML-DSA pre-hashed API: obtaining a message representative to sign.
|
|
3250
|
+
void bssl::BCM_mldsa44_prehash_finalize(uint8_t out_msg_rep[MLDSA_MU_BYTES],
|
|
3251
|
+
MLDSA44_prehash *inout_prehash_ctx) {
|
|
3252
|
+
mldsa_prehash_finalize(
|
|
3253
|
+
out_msg_rep, mldsa::prehash_context_from_external_44(inout_prehash_ctx));
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
// ML-DSA pre-hashed API: signing a message representative.
|
|
3257
|
+
bcm_status bssl::BCM_mldsa44_sign_message_representative(
|
|
3258
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3259
|
+
const MLDSA44_private_key *private_key,
|
|
3260
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3261
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
3262
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
3263
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
3264
|
+
|
|
3265
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
3266
|
+
out_encoded_signature, mldsa::private_key_from_external_44(private_key),
|
|
3267
|
+
msg_rep, randomizer));
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
// ML-DSA pre-hashed API: verifying a message representative.
|
|
3271
|
+
bcm_status bssl::BCM_mldsa44_verify_message_representative(
|
|
3272
|
+
const MLDSA44_public_key *public_key,
|
|
3273
|
+
const uint8_t signature[MLDSA44_SIGNATURE_BYTES],
|
|
3274
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3275
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_mu<4, 4>(
|
|
3276
|
+
mldsa::public_key_from_external_44(public_key), signature, msg_rep));
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3279
|
+
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
|
3280
|
+
bcm_status bssl::BCM_mldsa44_verify(const MLDSA44_public_key *public_key,
|
|
3281
|
+
const uint8_t *signature,
|
|
3282
|
+
const uint8_t *msg, size_t msg_len,
|
|
3283
|
+
const uint8_t *context,
|
|
3284
|
+
size_t context_len) {
|
|
3285
|
+
BSSL_CHECK(context_len <= 255);
|
|
3286
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3287
|
+
return BCM_mldsa44_verify_internal(public_key, signature, msg, msg_len,
|
|
3288
|
+
context_prefix, sizeof(context_prefix),
|
|
3289
|
+
context, context_len);
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
bcm_status bssl::BCM_mldsa44_verify_internal(
|
|
3293
|
+
const MLDSA44_public_key *public_key,
|
|
3294
|
+
const uint8_t encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3295
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
|
3296
|
+
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
|
3297
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_internal<4, 4>(
|
|
3298
|
+
mldsa::public_key_from_external_44(public_key), encoded_signature, msg,
|
|
3299
|
+
msg_len, context_prefix, context_prefix_len, context, context_len));
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
bcm_status bssl::BCM_mldsa44_marshal_public_key(
|
|
3303
|
+
CBB *out, const MLDSA44_public_key *public_key) {
|
|
3304
|
+
return bcm_as_approved_status(mldsa_marshal_public_key(
|
|
3305
|
+
out, mldsa::public_key_from_external_44(public_key)));
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
int bssl::BCM_mldsa44_public_keys_equal(const MLDSA44_public_key *a,
|
|
3309
|
+
const MLDSA44_public_key *b) {
|
|
3310
|
+
auto *a_pub = mldsa::public_key_from_external_44(a);
|
|
3311
|
+
auto *b_pub = mldsa::public_key_from_external_44(b);
|
|
3312
|
+
// It is sufficient to compare `public_key_hash`. When importing a public key,
|
|
3313
|
+
// the hash must be computed. When importing a private key in expanded form
|
|
3314
|
+
// (an internal testing-only API), the hash is provided, but we recompute it
|
|
3315
|
+
// and check for correctness.
|
|
3316
|
+
return OPENSSL_memcmp(a_pub->public_key_hash, b_pub->public_key_hash,
|
|
3317
|
+
sizeof(a_pub->public_key_hash)) == 0;
|
|
3318
|
+
}
|
|
3319
|
+
|
|
3320
|
+
int bssl::boringssl_self_test_mldsa() {
|
|
2298
3321
|
return mldsa::fips::keygen_self_test() && mldsa::fips::sign_self_test() &&
|
|
2299
3322
|
mldsa::fips::verify_self_test();
|
|
2300
3323
|
}
|