grpc 1.69.0 → 1.70.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +251 -249
- data/include/grpc/support/atm.h +0 -13
- data/src/core/call/request_buffer.cc +224 -0
- data/src/core/call/request_buffer.h +192 -0
- data/src/core/client_channel/client_channel.cc +2 -3
- data/src/core/client_channel/client_channel_args.h +21 -0
- data/src/core/client_channel/client_channel_filter.h +1 -3
- data/src/core/client_channel/retry_interceptor.cc +406 -0
- data/src/core/client_channel/retry_interceptor.h +157 -0
- data/src/core/client_channel/retry_service_config.h +13 -0
- data/src/core/client_channel/retry_throttle.cc +33 -18
- data/src/core/client_channel/retry_throttle.h +3 -3
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +596 -94
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +189 -13
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/frame_security.cc +1 -3
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +40 -1
- data/src/core/ext/upb-gen/envoy/admin/v3/config_dump_shared.upb.h +3 -1
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb.h +66 -36
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb_minitable.c +19 -17
- data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb.h +116 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb_minitable.c +31 -5
- data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb.h +67 -6
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb_minitable.c +12 -8
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_cmsg_headers.upb.h +151 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_cmsg_headers.upb_minitable.c +60 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_cmsg_headers.upb_minitable.h +32 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_option.upb.h +228 -21
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_option.upb_minitable.c +65 -17
- data/src/core/ext/upb-gen/envoy/config/core/v3/socket_option.upb_minitable.h +6 -0
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener_components.upb.h +7 -106
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener_components.upb_minitable.c +7 -28
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener_components.upb_minitable.h +0 -2
- data/src/core/ext/upb-gen/envoy/config/listener/v3/quic_config.upb.h +85 -0
- data/src/core/ext/upb-gen/envoy/config/listener/v3/quic_config.upb_minitable.c +25 -3
- data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb.h +2 -1
- data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb.h +152 -0
- data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb_minitable.c +40 -10
- data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb.h +135 -4
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.c +41 -9
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/config/trace/v3/trace.upb.h +0 -2
- data/src/core/ext/upb-gen/envoy/config/trace/v3/trace.upb_minitable.c +0 -1
- data/src/core/ext/upb-gen/envoy/config/trace/v3/trace.upb_minitable.h +0 -1
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +16 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.c +3 -2
- 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 -0
- 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 +13 -2
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upb.h +0 -1
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upb_minitable.c +0 -1
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +102 -24
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls.upb_minitable.c +28 -19
- data/src/core/ext/upb-gen/envoy/service/discovery/v3/discovery.upb.h +251 -18
- data/src/core/ext/upb-gen/envoy/service/discovery/v3/discovery.upb_minitable.c +41 -16
- data/src/core/ext/upb-gen/envoy/service/discovery/v3/discovery.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/service/status/v3/csds.upb.h +2 -1
- data/src/core/ext/upbdefs-gen/envoy/admin/v3/config_dump_shared.upbdefs.c +11 -10
- data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.c +418 -413
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.c +161 -153
- 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/protocol.upbdefs.c +267 -261
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_cmsg_headers.upbdefs.c +46 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_cmsg_headers.upbdefs.h +33 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_option.upbdefs.c +29 -19
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_option.upbdefs.h +15 -0
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener_components.upbdefs.c +58 -65
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener_components.upbdefs.h +0 -5
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/quic_config.upbdefs.c +73 -63
- data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.c +49 -48
- data/src/core/ext/upbdefs-gen/envoy/config/rbac/v3/rbac.upbdefs.c +117 -100
- data/src/core/ext/upbdefs-gen/envoy/config/rbac/v3/rbac.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.c +905 -897
- data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/trace.upbdefs.c +15 -18
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +460 -457
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upbdefs.c +16 -19
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +95 -95
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +202 -191
- data/src/core/ext/upbdefs-gen/envoy/service/discovery/v3/discovery.upbdefs.c +148 -135
- data/src/core/ext/upbdefs-gen/envoy/service/discovery/v3/discovery.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/service/status/v3/csds.upbdefs.c +23 -22
- data/src/core/filter/filter_args.h +112 -0
- data/src/core/handshaker/http_connect/http_connect_handshaker.cc +1 -1
- data/src/core/lib/channel/promise_based_filter.h +5 -79
- 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/posix_engine/posix_endpoint.cc +14 -0
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +7 -2
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +0 -2
- data/src/core/lib/event_engine/windows/windows_engine.cc +1 -0
- data/src/core/lib/experiments/experiments.cc +90 -39
- data/src/core/lib/experiments/experiments.h +43 -24
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +1 -1
- data/src/core/lib/promise/activity.cc +2 -0
- data/src/core/lib/promise/activity.h +29 -8
- data/src/core/lib/promise/map.h +42 -0
- data/src/core/lib/promise/party.cc +36 -1
- data/src/core/lib/promise/party.h +13 -5
- data/src/core/lib/promise/sleep.h +1 -0
- data/src/core/lib/promise/status_flag.h +10 -0
- data/src/core/lib/resource_quota/arena.h +8 -0
- data/src/core/lib/resource_quota/connection_quota.h +4 -0
- data/src/core/lib/surface/call_utils.h +2 -0
- data/src/core/lib/surface/client_call.cc +43 -35
- data/src/core/lib/surface/client_call.h +5 -0
- data/src/core/lib/surface/event_string.cc +7 -1
- data/src/core/lib/surface/init_internally.h +13 -2
- data/src/core/lib/surface/server_call.cc +100 -85
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/call_filters.cc +10 -4
- data/src/core/lib/transport/call_filters.h +8 -0
- data/src/core/lib/transport/call_spine.cc +36 -71
- data/src/core/lib/transport/call_spine.h +131 -7
- data/src/core/lib/transport/call_state.h +132 -39
- data/src/core/lib/transport/interception_chain.cc +8 -0
- data/src/core/lib/transport/interception_chain.h +9 -0
- data/src/core/load_balancing/endpoint_list.cc +10 -0
- data/src/core/load_balancing/endpoint_list.h +13 -6
- data/src/core/load_balancing/lb_policy.h +0 -8
- data/src/core/load_balancing/pick_first/pick_first.cc +89 -56
- data/src/core/load_balancing/ring_hash/ring_hash.cc +158 -70
- data/src/core/load_balancing/ring_hash/ring_hash.h +4 -11
- data/src/core/load_balancing/round_robin/round_robin.cc +9 -14
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +12 -15
- data/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +4 -4
- data/src/core/resolver/xds/xds_dependency_manager.cc +139 -135
- data/src/core/resolver/xds/xds_dependency_manager.h +24 -18
- data/src/core/resolver/xds/xds_resolver.cc +28 -47
- data/src/core/server/server.cc +290 -24
- data/src/core/server/server.h +199 -61
- data/src/core/server/xds_server_config_fetcher.cc +78 -142
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
- data/src/core/util/backoff.cc +15 -4
- data/src/core/util/http_client/httpcli.cc +66 -18
- data/src/core/util/http_client/httpcli.h +14 -4
- data/src/core/util/matchers.h +5 -10
- data/src/core/util/ref_counted.h +1 -0
- data/src/core/util/ref_counted_ptr.h +1 -1
- data/src/core/util/useful.h +9 -11
- data/src/core/xds/grpc/xds_endpoint_parser.cc +54 -23
- data/src/core/xds/grpc/xds_metadata.h +8 -0
- data/src/core/xds/xds_client/xds_api.cc +0 -223
- data/src/core/xds/xds_client/xds_api.h +1 -133
- data/src/core/xds/xds_client/xds_client.cc +599 -466
- data/src/core/xds/xds_client/xds_client.h +107 -26
- data/src/core/xds/xds_client/xds_resource_type_impl.h +10 -5
- data/src/ruby/ext/grpc/extconf.rb +1 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_bitstr.c → a_bitstr.cc} +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_d2i_fp.c → a_d2i_fp.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_dup.c → a_dup.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_i2d_fp.c → a_i2d_fp.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_int.c → a_int.cc} +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_mbstr.c → a_mbstr.cc} +9 -7
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_object.c → a_object.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_strnid.c → a_strnid.cc} +7 -4
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_type.c → a_type.cc} +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{asn1_lib.c → asn1_lib.cc} +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{asn_pack.c → asn_pack.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{posix_time.c → posix_time.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{tasn_dec.c → tasn_dec.cc} +4 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{tasn_enc.c → tasn_enc.cc} +9 -6
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{tasn_fre.c → tasn_fre.cc} +14 -20
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{tasn_new.c → tasn_new.cc} +7 -6
- data/third_party/boringssl-with-bazel/src/crypto/asn1/{tasn_utl.c → tasn_utl.cc} +13 -10
- data/third_party/boringssl-with-bazel/src/crypto/base64/{base64.c → base64.cc} +9 -12
- data/third_party/boringssl-with-bazel/src/crypto/bcm_support.h +7 -1
- data/third_party/boringssl-with-bazel/src/crypto/bio/{bio.c → bio.cc} +32 -58
- data/third_party/boringssl-with-bazel/src/crypto/bio/{bio_mem.c → bio_mem.cc} +8 -7
- data/third_party/boringssl-with-bazel/src/crypto/bio/{connect.c → connect.cc} +24 -16
- data/third_party/boringssl-with-bazel/src/crypto/bio/{file.c → file.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/bio/{pair.c → pair.cc} +22 -20
- data/third_party/boringssl-with-bazel/src/crypto/bio/{printf.c → printf.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/bio/{socket_helper.c → socket_helper.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/blake2/{blake2.c → blake2.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/bn_extra/{bn_asn1.c → bn_asn1.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/bn_extra/{convert.c → convert.cc} +21 -21
- data/third_party/boringssl-with-bazel/src/crypto/buf/{buf.c → buf.cc} +6 -3
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/{asn1_compat.c → asn1_compat.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/{ber.c → ber.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/{cbb.c → cbb.cc} +33 -49
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/{cbs.c → cbs.cc} +20 -27
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/bytestring/{unicode.c → unicode.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/chacha/{chacha.c → chacha.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/chacha/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_aesctrhmac.c → e_aesctrhmac.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_aesgcmsiv.c → e_aesgcmsiv.cc} +23 -26
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_chacha20poly1305.c → e_chacha20poly1305.cc} +1 -8
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_des.c → e_des.cc} +61 -49
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_null.c → e_null.cc} +12 -9
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_rc2.c → e_rc2.cc} +23 -19
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_rc4.c → e_rc4.cc} +10 -8
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{e_tls.c → e_tls.cc} +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/conf/{conf.c → conf.cc} +17 -14
- data/third_party/boringssl-with-bazel/src/crypto/conf/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_apple.c → cpu_aarch64_apple.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_fuchsia.c → cpu_aarch64_fuchsia.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_linux.c → cpu_aarch64_linux.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_openbsd.c → cpu_aarch64_openbsd.cc} +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_sysreg.c → cpu_aarch64_sysreg.cc} +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_aarch64_win.c → cpu_aarch64_win.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_arm_freebsd.c → cpu_arm_freebsd.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_arm_linux.c → cpu_arm_linux.cc} +5 -5
- data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_linux.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/{cpu_intel.c → cpu_intel.cc} +47 -32
- data/third_party/boringssl-with-bazel/src/crypto/{crypto.c → crypto.cc} +6 -11
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/{curve25519.c → curve25519.cc} +28 -31
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/{curve25519_64_adx.c → curve25519_64_adx.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519_tables.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/curve25519/{spake25519.c → spake25519.cc} +20 -16
- data/third_party/boringssl-with-bazel/src/crypto/dh_extra/{dh_asn1.c → dh_asn1.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/digest_extra/{digest_extra.c → digest_extra.cc} +113 -31
- data/third_party/boringssl-with-bazel/src/crypto/dsa/{dsa.c → dsa.cc} +153 -154
- data/third_party/boringssl-with-bazel/src/crypto/dsa/{dsa_asn1.c → dsa_asn1.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +1 -3
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/{ec_asn1.c → ec_asn1.cc} +35 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/{ec_derive.c → ec_derive.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/{hash_to_curve.c → hash_to_curve.cc} +66 -64
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/ecdsa_extra/{ecdsa_asn1.c → ecdsa_asn1.cc} +15 -25
- data/third_party/boringssl-with-bazel/src/crypto/engine/{engine.c → engine.cc} +12 -8
- data/third_party/boringssl-with-bazel/src/crypto/err/{err.c → err.cc} +24 -27
- data/third_party/boringssl-with-bazel/src/crypto/err/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/evp/{evp.c → evp.cc} +8 -9
- data/third_party/boringssl-with-bazel/src/crypto/evp/{evp_ctx.c → evp_ctx.cc} +7 -8
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_dh.c → p_dh.cc} +23 -14
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_dh_asn1.c → p_dh_asn1.cc} +38 -21
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_dsa_asn1.c → p_dsa_asn1.cc} +19 -24
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_ec.c → p_ec.cc} +20 -23
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_ec_asn1.c → p_ec_asn1.cc} +20 -20
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_ed25519.c → p_ed25519.cc} +22 -19
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_ed25519_asn1.c → p_ed25519_asn1.cc} +14 -13
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_hkdf.c → p_hkdf.cc} +18 -14
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_rsa.c → p_rsa.cc} +38 -37
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_rsa_asn1.c → p_rsa_asn1.cc} +16 -18
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_x25519.c → p_x25519.cc} +22 -19
- data/third_party/boringssl-with-bazel/src/crypto/evp/{p_x25519_asn1.c → p_x25519_asn1.cc} +18 -17
- data/third_party/boringssl-with-bazel/src/crypto/evp/{pbkdf.c → pbkdf.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/evp/{print.c → print.cc} +4 -5
- data/third_party/boringssl-with-bazel/src/crypto/evp/{scrypt.c → scrypt.cc} +7 -5
- data/third_party/boringssl-with-bazel/src/crypto/{ex_data.c → ex_data.cc} +3 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/{aes_nohw.c.inc → aes_nohw.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/internal.h +1 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/{key_wrap.c.inc → key_wrap.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/{bcm.c → bcm.cc} +96 -101
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm_interface.h +165 -12
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{add.c.inc → add.cc.inc} +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/asm/{x86_64-gcc.c.inc → x86_64-gcc.cc.inc} +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{bn.c.inc → bn.cc.inc} +12 -24
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{ctx.c.inc → ctx.cc.inc} +5 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{div.c.inc → div.cc.inc} +29 -38
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{div_extra.c.inc → div_extra.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{exponentiation.c.inc → exponentiation.cc.inc} +22 -22
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{gcd.c.inc → gcd.cc.inc} +3 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{gcd_extra.c.inc → gcd_extra.cc.inc} +33 -25
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{montgomery.c.inc → montgomery.cc.inc} +10 -17
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{mul.c.inc → mul.cc.inc} +11 -15
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{prime.c.inc → prime.cc.inc} +31 -34
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{shift.c.inc → shift.cc.inc} +3 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/{aead.c.inc → aead.cc.inc} +18 -10
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/{cipher.c.inc → cipher.cc.inc} +6 -9
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/{e_aes.c.inc → e_aes.cc.inc} +46 -54
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cmac/{cmac.c.inc → cmac.cc.inc} +6 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/delocate.h +14 -10
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/{dh.c.inc → dh.cc.inc} +15 -19
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/internal.h +1 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/{digest.c.inc → digest.cc.inc} +17 -13
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/{digests.c.inc → digests.cc.inc} +29 -113
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digestsign/{digestsign.c.inc → digestsign.cc.inc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/builtin_curves.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{ec.c.inc → ec.cc.inc} +10 -15
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{ec_key.c.inc → ec_key.cc.inc} +12 -14
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{felem.c.inc → felem.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{oct.c.inc → oct.cc.inc} +5 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{p224-64.c.inc → p224-64.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-nistz-table.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{p256-nistz.c.inc → p256-nistz.cc.inc} +15 -13
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{p256.c.inc → p256.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{scalar.c.inc → scalar.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{simple_mul.c.inc → simple_mul.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{util.c.inc → util.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{wnaf.c.inc → wnaf.cc.inc} +24 -15
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/{ecdh.c.inc → ecdh.cc.inc} +14 -5
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/{ecdsa.c.inc → ecdsa.cc.inc} +6 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/{fips_shared_support.c → fips_shared_support.cc} +2 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/hkdf/{hkdf.c.inc → hkdf.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/hmac/{hmac.c.inc → hmac.cc.inc} +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{gcm.c.inc → gcm.cc.inc} +69 -21
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{gcm_nohw.c.inc → gcm_nohw.cc.inc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/internal.h +53 -33
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{polyval.c.inc → polyval.cc.inc} +2 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/{ctrdrbg.c.inc → ctrdrbg.cc.inc} +5 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/{rand.c.inc → rand.cc.inc} +20 -18
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/{blinding.c.inc → blinding.cc.inc} +5 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/{padding.c.inc → padding.cc.inc} +21 -21
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/{rsa.c.inc → rsa.cc.inc} +77 -73
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/{rsa_impl.c.inc → rsa_impl.cc.inc} +50 -53
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/{fips.c.inc → fips.cc.inc} +14 -6
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/{self_check.c.inc → self_check.cc.inc} +56 -52
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/service_indicator/{service_indicator.c.inc → service_indicator.cc.inc} +10 -11
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/internal.h +2 -4
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/{sha1.c.inc → sha1.cc.inc} +26 -33
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/{sha256.c.inc → sha256.cc.inc} +37 -55
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/{sha512.c.inc → sha512.cc.inc} +48 -76
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/tls/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/hpke/{hpke.c → hpke.cc} +7 -4
- data/third_party/boringssl-with-bazel/src/crypto/hrss/{hrss.c → hrss.cc} +53 -110
- data/third_party/boringssl-with-bazel/src/crypto/hrss/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/internal.h +191 -248
- data/third_party/boringssl-with-bazel/src/crypto/keccak/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/keccak/{keccak.c → keccak.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/kyber/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/kyber/{kyber.c → kyber.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/lhash/{lhash.c → lhash.cc} +8 -7
- data/third_party/boringssl-with-bazel/src/crypto/{fipsmodule/md4/md4.c.inc → md4/md4.cc} +8 -12
- data/third_party/boringssl-with-bazel/src/crypto/{fipsmodule/md5 → md5}/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/{fipsmodule/md5/md5.c.inc → md5/md5.cc} +4 -3
- data/third_party/boringssl-with-bazel/src/crypto/{mem.c → mem.cc} +34 -22
- data/third_party/boringssl-with-bazel/src/crypto/mldsa/internal.h +4 -1
- data/third_party/boringssl-with-bazel/src/crypto/mldsa/{mldsa.c → mldsa.cc} +646 -543
- data/third_party/boringssl-with-bazel/src/crypto/mlkem/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/mlkem/mlkem.cc +8 -8
- data/third_party/boringssl-with-bazel/src/crypto/obj/{obj.c → obj.cc} +27 -30
- data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_info.c → pem_info.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_lib.c → pem_lib.cc} +3 -4
- data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_oth.c → pem_oth.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/pkcs7/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/pkcs7/{pkcs7.c → pkcs7.cc} +5 -5
- data/third_party/boringssl-with-bazel/src/crypto/pkcs7/{pkcs7_x509.c → pkcs7_x509.cc} +26 -25
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/{p5_pbev2.c → p5_pbev2.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/{pkcs8.c → pkcs8.cc} +159 -158
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/{pkcs8_x509.c → pkcs8_x509.cc} +90 -97
- data/third_party/boringssl-with-bazel/src/crypto/poly1305/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/poly1305/{poly1305.c → poly1305.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/poly1305/{poly1305_arm.c → poly1305_arm.cc} +4 -2
- data/third_party/boringssl-with-bazel/src/crypto/poly1305/{poly1305_vec.c → poly1305_vec.cc} +14 -11
- data/third_party/boringssl-with-bazel/src/crypto/pool/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/pool/{pool.c → pool.cc} +12 -11
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{deterministic.c → deterministic.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{fork_detect.c → fork_detect.cc} +11 -12
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{forkunsafe.c → forkunsafe.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{getentropy.c → getentropy.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/getrandom_fillin.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{ios.c → ios.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{passive.c → passive.cc} +22 -18
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{rand_extra.c → rand_extra.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/sysrand_internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{trusty.c → trusty.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{urandom.c → urandom.cc} +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/rand_extra/{windows.c → windows.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/{refcount.c → refcount.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/{rsa_asn1.c → rsa_asn1.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/{rsa_crypt.c → rsa_crypt.cc} +81 -78
- data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_extra.cc +17 -0
- data/third_party/boringssl-with-bazel/src/crypto/sha/sha1.cc +52 -0
- data/third_party/boringssl-with-bazel/src/crypto/sha/sha256.cc +87 -0
- data/third_party/boringssl-with-bazel/src/crypto/sha/sha512.cc +104 -0
- data/third_party/boringssl-with-bazel/src/crypto/siphash/{siphash.c → siphash.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/address.h +123 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/fors.cc +169 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/fors.h +58 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/internal.h +63 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/merkle.cc +161 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/merkle.h +70 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/params.h +83 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/slhdsa.cc +307 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/thash.cc +173 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/thash.h +85 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/wots.cc +171 -0
- data/third_party/boringssl-with-bazel/src/crypto/slhdsa/wots.h +50 -0
- data/third_party/boringssl-with-bazel/src/crypto/stack/{stack.c → stack.cc} +10 -6
- data/third_party/boringssl-with-bazel/src/crypto/{thread_none.c → thread_none.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/{thread_pthread.c → thread_pthread.cc} +9 -8
- data/third_party/boringssl-with-bazel/src/crypto/{thread_win.c → thread_win.cc} +21 -17
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/{pmbtoken.c → pmbtoken.cc} +146 -158
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/{trust_token.c → trust_token.cc} +19 -21
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/{voprf.c → voprf.cc} +165 -169
- data/third_party/boringssl-with-bazel/src/crypto/x509/{a_digest.c → a_digest.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{a_sign.c → a_sign.cc} +37 -34
- data/third_party/boringssl-with-bazel/src/crypto/x509/{a_verify.c → a_verify.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{algorithm.c → algorithm.cc} +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{asn1_gen.c → asn1_gen.cc} +5 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/{by_dir.c → by_dir.cc} +7 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/{policy.c → policy.cc} +188 -178
- data/third_party/boringssl-with-bazel/src/crypto/x509/{rsa_pss.c → rsa_pss.cc} +48 -44
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_akey.c → v3_akey.cc} +4 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_alt.c → v3_alt.cc} +5 -5
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_bcons.c → v3_bcons.cc} +3 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_bitst.c → v3_bitst.cc} +6 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_conf.c → v3_conf.cc} +5 -5
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_cpols.c → v3_cpols.cc} +47 -41
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_crld.c → v3_crld.cc} +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_enum.c → v3_enum.cc} +5 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_extku.c → v3_extku.cc} +3 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_genn.c → v3_genn.cc} +7 -7
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_ia5.c → v3_ia5.cc} +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_info.c → v3_info.cc} +4 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_int.c → v3_int.cc} +3 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_lib.c → v3_lib.cc} +9 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_ncons.c → v3_ncons.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_ocsp.c → v3_ocsp.cc} +4 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_pcons.c → v3_pcons.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_pmaps.c → v3_pmaps.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_prn.c → v3_prn.cc} +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_purp.c → v3_purp.cc} +16 -8
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_skey.c → v3_skey.cc} +6 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_utl.c → v3_utl.cc} +15 -10
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_att.c → x509_att.cc} +3 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_lu.c → x509_lu.cc} +6 -5
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_v3.c → x509_v3.cc} +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_vfy.c → x509_vfy.cc} +216 -212
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_vpm.c → x509_vpm.cc} +55 -13
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x509spki.c → x509spki.cc} +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x_all.c → x_all.cc} +10 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x_crl.c → x_crl.cc} +6 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x_name.c → x_name.cc} +39 -32
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x_pubkey.c → x_pubkey.cc} +4 -2
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x_x509.c → x_x509.cc} +48 -44
- data/third_party/boringssl-with-bazel/src/crypto/x509/{x_x509a.c → x_x509a.cc} +4 -2
- data/third_party/boringssl-with-bazel/src/gen/crypto/{err_data.c → err_data.cc} +359 -358
- data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/asm_base.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/asn1_mac.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/asn1t.h +237 -275
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +12 -5
- data/third_party/boringssl-with-bazel/src/include/openssl/bcm_public.h +82 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/blake2.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/buffer.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/cmac.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/cpu.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +13 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/ctrdrbg.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/curve25519.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +6 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/dtls1.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/e_os2.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/ec_key.h +17 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/engine.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/experimental/kyber.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/hkdf.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/hrss.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/is_boringssl.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/kdf.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/mldsa.h +8 -8
- data/third_party/boringssl-with-bazel/src/include/openssl/mlkem.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/obj_mac.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/objects.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/opensslv.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/ossl_typ.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/pkcs12.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +2 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/poly1305.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/pool.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/posix_time.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +10 -5
- data/third_party/boringssl-with-bazel/src/include/openssl/safestack.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +2 -40
- data/third_party/boringssl-with-bazel/src/include/openssl/siphash.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/slhdsa.h +133 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/span.h +6 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/srtp.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +160 -116
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl3.h +1 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/target.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/thread.h +2 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/time.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/x509v3_errors.h +2 -2
- data/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc +2 -6
- data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +667 -322
- data/third_party/boringssl-with-bazel/src/ssl/d1_lib.cc +116 -119
- data/third_party/boringssl-with-bazel/src/ssl/d1_pkt.cc +163 -21
- data/third_party/boringssl-with-bazel/src/ssl/d1_srtp.cc +4 -12
- data/third_party/boringssl-with-bazel/src/ssl/dtls_method.cc +94 -49
- data/third_party/boringssl-with-bazel/src/ssl/dtls_record.cc +296 -198
- data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +23 -14
- data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +363 -343
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +48 -58
- data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +44 -36
- data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +145 -159
- data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +65 -58
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +910 -356
- data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +29 -41
- data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +13 -11
- data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +2 -2
- data/third_party/boringssl-with-bazel/src/ssl/ssl_aead_ctx.cc +90 -183
- data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +38 -64
- data/third_party/boringssl-with-bazel/src/ssl/ssl_buffer.cc +1 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +103 -44
- data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +210 -220
- data/third_party/boringssl-with-bazel/src/ssl/ssl_credential.cc +70 -12
- data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +20 -17
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +146 -169
- data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +15 -16
- data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +79 -95
- data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +3 -9
- data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +91 -16
- data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +30 -16
- data/third_party/boringssl-with-bazel/src/ssl/ssl_x509.cc +51 -56
- data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +22 -25
- data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +43 -27
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +63 -59
- data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +204 -121
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +86 -59
- data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +51 -62
- data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +37 -25
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_32.h +6 -0
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64.h +6 -0
- data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64_adx.h +4 -1
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_32.h +1 -1
- data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64.h +3 -0
- metadata +339 -339
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opencensus.upb.h +0 -426
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opencensus.upb_minitable.c +0 -87
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opencensus.upb_minitable.h +0 -32
- data/src/core/ext/upb-gen/opencensus/proto/trace/v1/trace_config.upb.h +0 -408
- data/src/core/ext/upb-gen/opencensus/proto/trace/v1/trace_config.upb_minitable.c +0 -124
- data/src/core/ext/upb-gen/opencensus/proto/trace/v1/trace_config.upb_minitable.h +0 -38
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opencensus.upbdefs.c +0 -108
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opencensus.upbdefs.h +0 -33
- data/src/core/ext/upbdefs-gen/opencensus/proto/trace/v1/trace_config.upbdefs.c +0 -67
- data/src/core/ext/upbdefs-gen/opencensus/proto/trace/v1/trace_config.upbdefs.h +0 -48
- data/src/core/util/atm.cc +0 -34
- data/third_party/boringssl-with-bazel/src/crypto/dilithium/dilithium.c +0 -1539
- data/third_party/boringssl-with-bazel/src/crypto/dilithium/internal.h +0 -58
- data/third_party/boringssl-with-bazel/src/crypto/spx/address.c +0 -101
- data/third_party/boringssl-with-bazel/src/crypto/spx/address.h +0 -50
- data/third_party/boringssl-with-bazel/src/crypto/spx/fors.c +0 -133
- data/third_party/boringssl-with-bazel/src/crypto/spx/fors.h +0 -54
- data/third_party/boringssl-with-bazel/src/crypto/spx/merkle.c +0 -150
- data/third_party/boringssl-with-bazel/src/crypto/spx/merkle.h +0 -61
- data/third_party/boringssl-with-bazel/src/crypto/spx/params.h +0 -71
- data/third_party/boringssl-with-bazel/src/crypto/spx/spx.c +0 -140
- data/third_party/boringssl-with-bazel/src/crypto/spx/spx_util.c +0 -53
- data/third_party/boringssl-with-bazel/src/crypto/spx/spx_util.h +0 -44
- data/third_party/boringssl-with-bazel/src/crypto/spx/thash.c +0 -136
- data/third_party/boringssl-with-bazel/src/crypto/spx/thash.h +0 -70
- data/third_party/boringssl-with-bazel/src/crypto/spx/wots.c +0 -135
- data/third_party/boringssl-with-bazel/src/crypto/spx/wots.h +0 -45
- data/third_party/boringssl-with-bazel/src/include/openssl/experimental/dilithium.h +0 -129
- data/third_party/boringssl-with-bazel/src/include/openssl/experimental/spx.h +0 -90
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_bool.c → a_bool.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_gentm.c → a_gentm.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_octet.c → a_octet.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_strex.c → a_strex.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_time.c → a_time.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{a_utctm.c → a_utctm.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{asn1_par.c → asn1_par.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{f_int.c → f_int.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{f_string.c → f_string.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/asn1/{tasn_typ.c → tasn_typ.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/bio/{errno.c → errno.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/bio/{fd.c → fd.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/bio/{hexdump.c → hexdump.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/bio/{socket.c → socket.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{cipher_extra.c → cipher_extra.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{derive_key.c → derive_key.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/{tls_cbc.c → tls_cbc.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/des/{des.c → des.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/dh_extra/{params.c → params.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/{ecdh_extra.c → ecdh_extra.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/evp/{evp_asn1.c → evp_asn1.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/evp/{sign.c → sign.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/{aes.c.inc → aes.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/{mode_wrappers.c.inc → mode_wrappers.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{bytes.c.inc → bytes.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{cmp.c.inc → cmp.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{generic.c.inc → generic.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{jacobi.c.inc → jacobi.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{montgomery_inv.c.inc → montgomery_inv.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{random.c.inc → random.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{rsaz_exp.c.inc → rsaz_exp.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/{sqrt.c.inc → sqrt.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/{e_aesccm.c.inc → e_aesccm.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/{check.c.inc → check.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{ec_montgomery.c.inc → ec_montgomery.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/{simple.c.inc → simple.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{cbc.c.inc → cbc.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{cfb.c.inc → cfb.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{ctr.c.inc → ctr.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/{ofb.c.inc → ofb.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/tls/{kdf.c.inc → kdf.cc.inc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/obj/{obj_xref.c → obj_xref.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_all.c → pem_all.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_pk8.c → pem_pk8.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_pkey.c → pem_pkey.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_x509.c → pem_x509.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/pem/{pem_xaux.c → pem_xaux.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/rc4/{rc4.c → rc4.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/{rsa_print.c → rsa_print.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/{thread.c → thread.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{by_file.c → by_file.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{i2d_pr.c → i2d_pr.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{name_print.c → name_print.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{t_crl.c → t_crl.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{t_req.c → t_req.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{t_x509.c → t_x509.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{t_x509a.c → t_x509a.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{v3_akeya.c → v3_akeya.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509.c → x509.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_cmp.c → x509_cmp.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_d2.c → x509_d2.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_def.c → x509_def.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_ext.c → x509_ext.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_obj.c → x509_obj.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_req.c → x509_req.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_set.c → x509_set.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_trs.c → x509_trs.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509_txt.c → x509_txt.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509cset.c → x509cset.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509name.c → x509name.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x509rset.c → x509rset.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_algor.c → x_algor.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_attrib.c → x_attrib.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_exten.c → x_exten.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_req.c → x_req.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_sig.c → x_sig.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_spki.c → x_spki.cc} +0 -0
- /data/third_party/boringssl-with-bazel/src/crypto/x509/{x_val.c → x_val.cc} +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
/* Copyright
|
1
|
+
/* Copyright 2024 The BoringSSL Authors
|
2
2
|
*
|
3
3
|
* Permission to use, copy, modify, and/or distribute this software for any
|
4
4
|
* purpose with or without fee is hereby granted, provided that the above
|
@@ -14,6 +14,8 @@
|
|
14
14
|
|
15
15
|
#include <openssl/mldsa.h>
|
16
16
|
|
17
|
+
#include <memory>
|
18
|
+
|
17
19
|
#include <assert.h>
|
18
20
|
#include <stdlib.h>
|
19
21
|
|
@@ -25,49 +27,121 @@
|
|
25
27
|
#include "../keccak/internal.h"
|
26
28
|
#include "./internal.h"
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#define SIGMA_BYTES 64
|
38
|
-
#define K_BYTES 32
|
39
|
-
#define TR_BYTES 64
|
40
|
-
#define MU_BYTES 64
|
41
|
-
#define RHO_PRIME_BYTES 64
|
42
|
-
#define LAMBDA_BITS 192
|
43
|
-
#define LAMBDA_BYTES (LAMBDA_BITS / 8)
|
30
|
+
namespace {
|
31
|
+
|
32
|
+
constexpr int kDegree = 256;
|
33
|
+
constexpr int kRhoBytes = 32;
|
34
|
+
constexpr int kSigmaBytes = 64;
|
35
|
+
constexpr int kKBytes = 32;
|
36
|
+
constexpr int kTrBytes = 64;
|
37
|
+
constexpr int kMuBytes = 64;
|
38
|
+
constexpr int kRhoPrimeBytes = 64;
|
44
39
|
|
45
40
|
// 2^23 - 2^13 + 1
|
46
|
-
|
41
|
+
constexpr uint32_t kPrime = 8380417;
|
47
42
|
// Inverse of -kPrime modulo 2^32
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
static const uint32_t kGamma2 = (8380417 - 1) / 32;
|
43
|
+
constexpr uint32_t kPrimeNegInverse = 4236238847;
|
44
|
+
constexpr int kDroppedBits = 13;
|
45
|
+
constexpr uint32_t kHalfPrime = (kPrime - 1) / 2;
|
46
|
+
constexpr uint32_t kGamma2 = (kPrime - 1) / 32;
|
53
47
|
// 256^-1 mod kPrime, in Montgomery form.
|
54
|
-
|
48
|
+
constexpr uint32_t kInverseDegreeMontgomery = 41978;
|
49
|
+
|
50
|
+
// Constants that vary depending on ML-DSA size.
|
51
|
+
//
|
52
|
+
// These are implemented as templates which take the K parameter to distinguish
|
53
|
+
// the ML-DSA sizes. (At the time of writing, `if constexpr` was not available.)
|
54
|
+
//
|
55
|
+
// TODO(crbug.com/42290600): Switch this to `if constexpr` when C++17 is
|
56
|
+
// available.
|
57
|
+
|
58
|
+
template <int K>
|
59
|
+
constexpr size_t public_key_bytes();
|
60
|
+
|
61
|
+
template <>
|
62
|
+
constexpr size_t public_key_bytes<6>() {
|
63
|
+
return MLDSA65_PUBLIC_KEY_BYTES;
|
64
|
+
}
|
65
|
+
|
66
|
+
template <int K>
|
67
|
+
constexpr size_t signature_bytes();
|
68
|
+
|
69
|
+
template <>
|
70
|
+
constexpr size_t signature_bytes<6>() {
|
71
|
+
return MLDSA65_SIGNATURE_BYTES;
|
72
|
+
}
|
73
|
+
|
74
|
+
template <int K>
|
75
|
+
constexpr int tau();
|
76
|
+
|
77
|
+
template <>
|
78
|
+
constexpr int tau<6>() {
|
79
|
+
return 49;
|
80
|
+
}
|
81
|
+
|
82
|
+
template <int K>
|
83
|
+
constexpr int lambda_bytes();
|
84
|
+
|
85
|
+
template <>
|
86
|
+
constexpr int lambda_bytes<6>() {
|
87
|
+
return 192 / 8;
|
88
|
+
}
|
89
|
+
|
90
|
+
template <int K>
|
91
|
+
constexpr int gamma1();
|
92
|
+
|
93
|
+
template <>
|
94
|
+
constexpr int gamma1<6>() {
|
95
|
+
return 1 << 19;
|
96
|
+
}
|
97
|
+
|
98
|
+
template <int K>
|
99
|
+
constexpr int beta();
|
100
|
+
|
101
|
+
template <>
|
102
|
+
constexpr int beta<6>() {
|
103
|
+
return 196;
|
104
|
+
}
|
105
|
+
|
106
|
+
template <int K>
|
107
|
+
constexpr int omega();
|
108
|
+
|
109
|
+
template <>
|
110
|
+
constexpr int omega<6>() {
|
111
|
+
return 55;
|
112
|
+
}
|
113
|
+
|
114
|
+
template <int K>
|
115
|
+
constexpr int eta();
|
116
|
+
|
117
|
+
template <>
|
118
|
+
constexpr int eta<6>() {
|
119
|
+
return 4;
|
120
|
+
}
|
121
|
+
|
122
|
+
template <int K>
|
123
|
+
constexpr int plus_minus_eta_bitlen();
|
124
|
+
|
125
|
+
template <>
|
126
|
+
constexpr int plus_minus_eta_bitlen<6>() {
|
127
|
+
return 4;
|
128
|
+
}
|
129
|
+
|
130
|
+
// Fundamental types.
|
55
131
|
|
56
132
|
typedef struct scalar {
|
57
|
-
uint32_t c[
|
133
|
+
uint32_t c[kDegree];
|
58
134
|
} scalar;
|
59
135
|
|
60
|
-
|
136
|
+
template <int K>
|
137
|
+
struct vector {
|
61
138
|
scalar v[K];
|
62
|
-
}
|
63
|
-
|
64
|
-
typedef struct vectorl {
|
65
|
-
scalar v[L];
|
66
|
-
} vectorl;
|
139
|
+
};
|
67
140
|
|
68
|
-
|
141
|
+
template <int K, int L>
|
142
|
+
struct matrix {
|
69
143
|
scalar v[K][L];
|
70
|
-
}
|
144
|
+
};
|
71
145
|
|
72
146
|
/* Arithmetic */
|
73
147
|
|
@@ -173,13 +247,13 @@ static uint32_t mod_sub(uint32_t a, uint32_t b) {
|
|
173
247
|
}
|
174
248
|
|
175
249
|
static void scalar_add(scalar *out, const scalar *lhs, const scalar *rhs) {
|
176
|
-
for (int i = 0; i <
|
250
|
+
for (int i = 0; i < kDegree; i++) {
|
177
251
|
out->c[i] = reduce_once(lhs->c[i] + rhs->c[i]);
|
178
252
|
}
|
179
253
|
}
|
180
254
|
|
181
255
|
static void scalar_sub(scalar *out, const scalar *lhs, const scalar *rhs) {
|
182
|
-
for (int i = 0; i <
|
256
|
+
for (int i = 0; i < kDegree; i++) {
|
183
257
|
out->c[i] = mod_sub(lhs->c[i], rhs->c[i]);
|
184
258
|
}
|
185
259
|
}
|
@@ -195,7 +269,7 @@ static uint32_t reduce_montgomery(uint64_t x) {
|
|
195
269
|
|
196
270
|
// Multiply two scalars in the number theoretically transformed state.
|
197
271
|
static void scalar_mult(scalar *out, const scalar *lhs, const scalar *rhs) {
|
198
|
-
for (int i = 0; i <
|
272
|
+
for (int i = 0; i < kDegree; i++) {
|
199
273
|
out->c[i] = reduce_montgomery((uint64_t)lhs->c[i] * (uint64_t)rhs->c[i]);
|
200
274
|
}
|
201
275
|
}
|
@@ -206,8 +280,8 @@ static void scalar_mult(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
206
280
|
static void scalar_ntt(scalar *s) {
|
207
281
|
// Step: 1, 2, 4, 8, ..., 128
|
208
282
|
// Offset: 128, 64, 32, 16, ..., 1
|
209
|
-
int offset =
|
210
|
-
for (int step = 1; step <
|
283
|
+
int offset = kDegree;
|
284
|
+
for (int step = 1; step < kDegree; step <<= 1) {
|
211
285
|
offset >>= 1;
|
212
286
|
int k = 0;
|
213
287
|
for (int i = 0; i < step; i++) {
|
@@ -234,8 +308,8 @@ static void scalar_ntt(scalar *s) {
|
|
234
308
|
static void scalar_inverse_ntt(scalar *s) {
|
235
309
|
// Step: 128, 64, 32, 16, ..., 1
|
236
310
|
// Offset: 1, 2, 4, 8, ..., 128
|
237
|
-
int step =
|
238
|
-
for (int offset = 1; offset <
|
311
|
+
int step = kDegree;
|
312
|
+
for (int offset = 1; offset < kDegree; offset <<= 1) {
|
239
313
|
step >>= 1;
|
240
314
|
int k = 0;
|
241
315
|
for (int i = 0; i < step; i++) {
|
@@ -258,72 +332,59 @@ static void scalar_inverse_ntt(scalar *s) {
|
|
258
332
|
k += 2 * offset;
|
259
333
|
}
|
260
334
|
}
|
261
|
-
for (int i = 0; i <
|
335
|
+
for (int i = 0; i < kDegree; i++) {
|
262
336
|
s->c[i] = reduce_montgomery((uint64_t)s->c[i] *
|
263
337
|
(uint64_t)kInverseDegreeMontgomery);
|
264
338
|
}
|
265
339
|
}
|
266
340
|
|
267
|
-
|
341
|
+
template <int X>
|
342
|
+
static void vector_zero(vector<X> *out) {
|
343
|
+
OPENSSL_memset(out, 0, sizeof(*out));
|
344
|
+
}
|
268
345
|
|
269
|
-
|
270
|
-
|
346
|
+
template <int X>
|
347
|
+
static void vector_add(vector<X> *out, const vector<X> *lhs,
|
348
|
+
const vector<X> *rhs) {
|
349
|
+
for (int i = 0; i < X; i++) {
|
271
350
|
scalar_add(&out->v[i], &lhs->v[i], &rhs->v[i]);
|
272
351
|
}
|
273
352
|
}
|
274
353
|
|
275
|
-
|
276
|
-
|
354
|
+
template <int X>
|
355
|
+
static void vector_sub(vector<X> *out, const vector<X> *lhs,
|
356
|
+
const vector<X> *rhs) {
|
357
|
+
for (int i = 0; i < X; i++) {
|
277
358
|
scalar_sub(&out->v[i], &lhs->v[i], &rhs->v[i]);
|
278
359
|
}
|
279
360
|
}
|
280
361
|
|
281
|
-
|
282
|
-
|
283
|
-
|
362
|
+
template <int X>
|
363
|
+
static void vector_mult_scalar(vector<X> *out, const vector<X> *lhs,
|
364
|
+
const scalar *rhs) {
|
365
|
+
for (int i = 0; i < X; i++) {
|
284
366
|
scalar_mult(&out->v[i], &lhs->v[i], rhs);
|
285
367
|
}
|
286
368
|
}
|
287
369
|
|
288
|
-
|
289
|
-
|
370
|
+
template <int X>
|
371
|
+
static void vector_ntt(vector<X> *a) {
|
372
|
+
for (int i = 0; i < X; i++) {
|
290
373
|
scalar_ntt(&a->v[i]);
|
291
374
|
}
|
292
375
|
}
|
293
376
|
|
294
|
-
|
295
|
-
|
377
|
+
template <int X>
|
378
|
+
static void vector_inverse_ntt(vector<X> *a) {
|
379
|
+
for (int i = 0; i < X; i++) {
|
296
380
|
scalar_inverse_ntt(&a->v[i]);
|
297
381
|
}
|
298
382
|
}
|
299
383
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
}
|
305
|
-
|
306
|
-
static void vectorl_mult_scalar(vectorl *out, const vectorl *lhs,
|
307
|
-
const scalar *rhs) {
|
308
|
-
for (int i = 0; i < L; i++) {
|
309
|
-
scalar_mult(&out->v[i], &lhs->v[i], rhs);
|
310
|
-
}
|
311
|
-
}
|
312
|
-
|
313
|
-
static void vectorl_ntt(vectorl *a) {
|
314
|
-
for (int i = 0; i < L; i++) {
|
315
|
-
scalar_ntt(&a->v[i]);
|
316
|
-
}
|
317
|
-
}
|
318
|
-
|
319
|
-
static void vectorl_inverse_ntt(vectorl *a) {
|
320
|
-
for (int i = 0; i < L; i++) {
|
321
|
-
scalar_inverse_ntt(&a->v[i]);
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
static void matrix_mult(vectork *out, const matrix *m, const vectorl *a) {
|
326
|
-
vectork_zero(out);
|
384
|
+
template <int K, int L>
|
385
|
+
static void matrix_mult(vector<K> *out, const matrix<K, L> *m,
|
386
|
+
const vector<L> *a) {
|
387
|
+
vector_zero(out);
|
327
388
|
for (int i = 0; i < K; i++) {
|
328
389
|
for (int j = 0; j < L; j++) {
|
329
390
|
scalar product;
|
@@ -435,38 +496,38 @@ static uint32_t use_hint_vartime(uint32_t h, uint32_t r) {
|
|
435
496
|
}
|
436
497
|
|
437
498
|
static void scalar_power2_round(scalar *s1, scalar *s0, const scalar *s) {
|
438
|
-
for (int i = 0; i <
|
499
|
+
for (int i = 0; i < kDegree; i++) {
|
439
500
|
power2_round(&s1->c[i], &s0->c[i], s->c[i]);
|
440
501
|
}
|
441
502
|
}
|
442
503
|
|
443
504
|
static void scalar_scale_power2_round(scalar *out, const scalar *in) {
|
444
|
-
for (int i = 0; i <
|
505
|
+
for (int i = 0; i < kDegree; i++) {
|
445
506
|
scale_power2_round(&out->c[i], in->c[i]);
|
446
507
|
}
|
447
508
|
}
|
448
509
|
|
449
510
|
static void scalar_high_bits(scalar *out, const scalar *in) {
|
450
|
-
for (int i = 0; i <
|
511
|
+
for (int i = 0; i < kDegree; i++) {
|
451
512
|
out->c[i] = high_bits(in->c[i]);
|
452
513
|
}
|
453
514
|
}
|
454
515
|
|
455
516
|
static void scalar_low_bits(scalar *out, const scalar *in) {
|
456
|
-
for (int i = 0; i <
|
517
|
+
for (int i = 0; i < kDegree; i++) {
|
457
518
|
out->c[i] = low_bits(in->c[i]);
|
458
519
|
}
|
459
520
|
}
|
460
521
|
|
461
522
|
static void scalar_max(uint32_t *max, const scalar *s) {
|
462
|
-
for (int i = 0; i <
|
523
|
+
for (int i = 0; i < kDegree; i++) {
|
463
524
|
uint32_t abs = abs_mod_prime(s->c[i]);
|
464
525
|
*max = maximum(*max, abs);
|
465
526
|
}
|
466
527
|
}
|
467
528
|
|
468
529
|
static void scalar_max_signed(uint32_t *max, const scalar *s) {
|
469
|
-
for (int i = 0; i <
|
530
|
+
for (int i = 0; i < kDegree; i++) {
|
470
531
|
uint32_t abs = abs_signed(s->c[i]);
|
471
532
|
*max = maximum(*max, abs);
|
472
533
|
}
|
@@ -474,98 +535,100 @@ static void scalar_max_signed(uint32_t *max, const scalar *s) {
|
|
474
535
|
|
475
536
|
static void scalar_make_hint(scalar *out, const scalar *ct0, const scalar *cs2,
|
476
537
|
const scalar *w) {
|
477
|
-
for (int i = 0; i <
|
538
|
+
for (int i = 0; i < kDegree; i++) {
|
478
539
|
out->c[i] = make_hint(ct0->c[i], cs2->c[i], w->c[i]);
|
479
540
|
}
|
480
541
|
}
|
481
542
|
|
482
543
|
static void scalar_use_hint_vartime(scalar *out, const scalar *h,
|
483
544
|
const scalar *r) {
|
484
|
-
for (int i = 0; i <
|
545
|
+
for (int i = 0; i < kDegree; i++) {
|
485
546
|
out->c[i] = use_hint_vartime(h->c[i], r->c[i]);
|
486
547
|
}
|
487
548
|
}
|
488
549
|
|
489
|
-
|
490
|
-
|
550
|
+
template <int X>
|
551
|
+
static void vector_power2_round(vector<X> *t1, vector<X> *t0,
|
552
|
+
const vector<X> *t) {
|
553
|
+
for (int i = 0; i < X; i++) {
|
491
554
|
scalar_power2_round(&t1->v[i], &t0->v[i], &t->v[i]);
|
492
555
|
}
|
493
556
|
}
|
494
557
|
|
495
|
-
|
496
|
-
|
558
|
+
template <int X>
|
559
|
+
static void vector_scale_power2_round(vector<X> *out, const vector<X> *in) {
|
560
|
+
for (int i = 0; i < X; i++) {
|
497
561
|
scalar_scale_power2_round(&out->v[i], &in->v[i]);
|
498
562
|
}
|
499
563
|
}
|
500
564
|
|
501
|
-
|
502
|
-
|
565
|
+
template <int X>
|
566
|
+
static void vector_high_bits(vector<X> *out, const vector<X> *in) {
|
567
|
+
for (int i = 0; i < X; i++) {
|
503
568
|
scalar_high_bits(&out->v[i], &in->v[i]);
|
504
569
|
}
|
505
570
|
}
|
506
571
|
|
507
|
-
|
508
|
-
|
572
|
+
template <int X>
|
573
|
+
static void vector_low_bits(vector<X> *out, const vector<X> *in) {
|
574
|
+
for (int i = 0; i < X; i++) {
|
509
575
|
scalar_low_bits(&out->v[i], &in->v[i]);
|
510
576
|
}
|
511
577
|
}
|
512
578
|
|
513
|
-
|
579
|
+
template <int X>
|
580
|
+
static uint32_t vector_max(const vector<X> *a) {
|
514
581
|
uint32_t max = 0;
|
515
|
-
for (int i = 0; i <
|
582
|
+
for (int i = 0; i < X; i++) {
|
516
583
|
scalar_max(&max, &a->v[i]);
|
517
584
|
}
|
518
585
|
return max;
|
519
586
|
}
|
520
587
|
|
521
|
-
|
588
|
+
template <int X>
|
589
|
+
static uint32_t vector_max_signed(const vector<X> *a) {
|
522
590
|
uint32_t max = 0;
|
523
|
-
for (int i = 0; i <
|
591
|
+
for (int i = 0; i < X; i++) {
|
524
592
|
scalar_max_signed(&max, &a->v[i]);
|
525
593
|
}
|
526
594
|
return max;
|
527
595
|
}
|
528
596
|
|
529
597
|
// The input vector contains only zeroes and ones.
|
530
|
-
|
598
|
+
template <int X>
|
599
|
+
static size_t vector_count_ones(const vector<X> *a) {
|
531
600
|
size_t count = 0;
|
532
|
-
for (int i = 0; i <
|
533
|
-
for (int j = 0; j <
|
601
|
+
for (int i = 0; i < X; i++) {
|
602
|
+
for (int j = 0; j < kDegree; j++) {
|
534
603
|
count += a->v[i].c[j];
|
535
604
|
}
|
536
605
|
}
|
537
606
|
return count;
|
538
607
|
}
|
539
608
|
|
540
|
-
|
541
|
-
|
542
|
-
|
609
|
+
template <int X>
|
610
|
+
static void vector_make_hint(vector<X> *out, const vector<X> *ct0,
|
611
|
+
const vector<X> *cs2, const vector<X> *w) {
|
612
|
+
for (int i = 0; i < X; i++) {
|
543
613
|
scalar_make_hint(&out->v[i], &ct0->v[i], &cs2->v[i], &w->v[i]);
|
544
614
|
}
|
545
615
|
}
|
546
616
|
|
547
|
-
|
548
|
-
|
549
|
-
|
617
|
+
template <int X>
|
618
|
+
static void vector_use_hint_vartime(vector<X> *out, const vector<X> *h,
|
619
|
+
const vector<X> *r) {
|
620
|
+
for (int i = 0; i < X; i++) {
|
550
621
|
scalar_use_hint_vartime(&out->v[i], &h->v[i], &r->v[i]);
|
551
622
|
}
|
552
623
|
}
|
553
624
|
|
554
|
-
static uint32_t vectorl_max(const vectorl *a) {
|
555
|
-
uint32_t max = 0;
|
556
|
-
for (int i = 0; i < L; i++) {
|
557
|
-
scalar_max(&max, &a->v[i]);
|
558
|
-
}
|
559
|
-
return max;
|
560
|
-
}
|
561
|
-
|
562
625
|
/* Bit packing */
|
563
626
|
|
564
627
|
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 4.
|
565
628
|
static void scalar_encode_4(uint8_t out[128], const scalar *s) {
|
566
629
|
// Every two elements lands on a byte boundary.
|
567
|
-
static_assert(
|
568
|
-
for (int i = 0; i <
|
630
|
+
static_assert(kDegree % 2 == 0, "kDegree must be a multiple of 2");
|
631
|
+
for (int i = 0; i < kDegree / 2; i++) {
|
569
632
|
uint32_t a = s->c[2 * i];
|
570
633
|
uint32_t b = s->c[2 * i + 1];
|
571
634
|
declassify_assert(a < 16);
|
@@ -577,8 +640,8 @@ static void scalar_encode_4(uint8_t out[128], const scalar *s) {
|
|
577
640
|
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 10.
|
578
641
|
static void scalar_encode_10(uint8_t out[320], const scalar *s) {
|
579
642
|
// Every four elements lands on a byte boundary.
|
580
|
-
static_assert(
|
581
|
-
for (int i = 0; i <
|
643
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
644
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
582
645
|
uint32_t a = s->c[4 * i];
|
583
646
|
uint32_t b = s->c[4 * i + 1];
|
584
647
|
uint32_t c = s->c[4 * i + 2];
|
@@ -595,14 +658,13 @@ static void scalar_encode_10(uint8_t out[320], const scalar *s) {
|
|
595
658
|
}
|
596
659
|
}
|
597
660
|
|
598
|
-
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(b) = 4 and b =
|
599
|
-
|
600
|
-
static void scalar_encode_signed_4_eta(uint8_t out[128], const scalar *s) {
|
661
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(b) = 4 and b = 4.
|
662
|
+
static void scalar_encode_signed_4_4(uint8_t out[128], const scalar *s) {
|
601
663
|
// Every two elements lands on a byte boundary.
|
602
|
-
static_assert(
|
603
|
-
for (int i = 0; i <
|
604
|
-
uint32_t a = mod_sub(
|
605
|
-
uint32_t b = mod_sub(
|
664
|
+
static_assert(kDegree % 2 == 0, "kDegree must be a multiple of 2");
|
665
|
+
for (int i = 0; i < kDegree / 2; i++) {
|
666
|
+
uint32_t a = mod_sub(4, s->c[2 * i]);
|
667
|
+
uint32_t b = mod_sub(4, s->c[2 * i + 1]);
|
606
668
|
declassify_assert(a < 16);
|
607
669
|
declassify_assert(b < 16);
|
608
670
|
out[i] = a | (b << 4);
|
@@ -614,8 +676,8 @@ static void scalar_encode_signed_4_eta(uint8_t out[128], const scalar *s) {
|
|
614
676
|
static void scalar_encode_signed_13_12(uint8_t out[416], const scalar *s) {
|
615
677
|
static const uint32_t kMax = 1u << 12;
|
616
678
|
// Every two elements lands on a byte boundary.
|
617
|
-
static_assert(
|
618
|
-
for (int i = 0; i <
|
679
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
680
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
619
681
|
uint32_t a = mod_sub(kMax, s->c[8 * i]);
|
620
682
|
uint32_t b = mod_sub(kMax, s->c[8 * i + 1]);
|
621
683
|
uint32_t c = mod_sub(kMax, s->c[8 * i + 2]);
|
@@ -654,8 +716,8 @@ static void scalar_encode_signed_13_12(uint8_t out[416], const scalar *s) {
|
|
654
716
|
static void scalar_encode_signed_20_19(uint8_t out[640], const scalar *s) {
|
655
717
|
static const uint32_t kMax = 1u << 19;
|
656
718
|
// Every two elements lands on a byte boundary.
|
657
|
-
static_assert(
|
658
|
-
for (int i = 0; i <
|
719
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
720
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
659
721
|
uint32_t a = mod_sub(kMax, s->c[4 * i]);
|
660
722
|
uint32_t b = mod_sub(kMax, s->c[4 * i + 1]);
|
661
723
|
uint32_t c = mod_sub(kMax, s->c[4 * i + 2]);
|
@@ -679,8 +741,8 @@ static void scalar_encode_signed_20_19(uint8_t out[640], const scalar *s) {
|
|
679
741
|
static void scalar_encode_signed(uint8_t *out, const scalar *s, int bits,
|
680
742
|
uint32_t max) {
|
681
743
|
if (bits == 4) {
|
682
|
-
assert(max ==
|
683
|
-
|
744
|
+
assert(max == 4);
|
745
|
+
scalar_encode_signed_4_4(out, s);
|
684
746
|
} else if (bits == 20) {
|
685
747
|
assert(max == 1u << 19);
|
686
748
|
scalar_encode_signed_20_19(out, s);
|
@@ -694,8 +756,8 @@ static void scalar_encode_signed(uint8_t *out, const scalar *s, int bits,
|
|
694
756
|
// FIPS 204, Algorithm 18 (`SimpleBitUnpack`). Specialized for bitlen(b) == 10.
|
695
757
|
static void scalar_decode_10(scalar *out, const uint8_t in[320]) {
|
696
758
|
uint32_t v;
|
697
|
-
static_assert(
|
698
|
-
for (int i = 0; i <
|
759
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
760
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
699
761
|
OPENSSL_memcpy(&v, &in[5 * i], sizeof(v));
|
700
762
|
out->c[4 * i] = v & 0x3ff;
|
701
763
|
out->c[4 * i + 1] = (v >> 10) & 0x3ff;
|
@@ -705,13 +767,12 @@ static void scalar_decode_10(scalar *out, const uint8_t in[320]) {
|
|
705
767
|
}
|
706
768
|
|
707
769
|
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 4 and b =
|
708
|
-
//
|
709
|
-
static int
|
770
|
+
// 4.
|
771
|
+
static int scalar_decode_signed_4_4(scalar *out, const uint8_t in[128]) {
|
710
772
|
uint32_t v;
|
711
|
-
static_assert(
|
712
|
-
for (int i = 0; i <
|
773
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
774
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
713
775
|
OPENSSL_memcpy(&v, &in[4 * i], sizeof(v));
|
714
|
-
static_assert(ETA == 4, "ETA must be 4");
|
715
776
|
// None of the nibbles may be >= 9. So if the MSB of any nibble is set, none
|
716
777
|
// of the other bits may be set. First, select all the MSBs.
|
717
778
|
const uint32_t msbs = v & 0x88888888u;
|
@@ -723,14 +784,14 @@ static int scalar_decode_signed_4_eta(scalar *out, const uint8_t in[128]) {
|
|
723
784
|
return 0;
|
724
785
|
}
|
725
786
|
|
726
|
-
out->c[i * 8] = mod_sub(
|
727
|
-
out->c[i * 8 + 1] = mod_sub(
|
728
|
-
out->c[i * 8 + 2] = mod_sub(
|
729
|
-
out->c[i * 8 + 3] = mod_sub(
|
730
|
-
out->c[i * 8 + 4] = mod_sub(
|
731
|
-
out->c[i * 8 + 5] = mod_sub(
|
732
|
-
out->c[i * 8 + 6] = mod_sub(
|
733
|
-
out->c[i * 8 + 7] = mod_sub(
|
787
|
+
out->c[i * 8] = mod_sub(4, v & 15);
|
788
|
+
out->c[i * 8 + 1] = mod_sub(4, (v >> 4) & 15);
|
789
|
+
out->c[i * 8 + 2] = mod_sub(4, (v >> 8) & 15);
|
790
|
+
out->c[i * 8 + 3] = mod_sub(4, (v >> 12) & 15);
|
791
|
+
out->c[i * 8 + 4] = mod_sub(4, (v >> 16) & 15);
|
792
|
+
out->c[i * 8 + 5] = mod_sub(4, (v >> 20) & 15);
|
793
|
+
out->c[i * 8 + 6] = mod_sub(4, (v >> 24) & 15);
|
794
|
+
out->c[i * 8 + 7] = mod_sub(4, v >> 28);
|
734
795
|
}
|
735
796
|
return 1;
|
736
797
|
}
|
@@ -744,8 +805,8 @@ static void scalar_decode_signed_13_12(scalar *out, const uint8_t in[416]) {
|
|
744
805
|
|
745
806
|
uint32_t a, b, c;
|
746
807
|
uint8_t d;
|
747
|
-
static_assert(
|
748
|
-
for (int i = 0; i <
|
808
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
809
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
749
810
|
OPENSSL_memcpy(&a, &in[13 * i], sizeof(a));
|
750
811
|
OPENSSL_memcpy(&b, &in[13 * i + 4], sizeof(b));
|
751
812
|
OPENSSL_memcpy(&c, &in[13 * i + 8], sizeof(c));
|
@@ -772,8 +833,8 @@ static void scalar_decode_signed_20_19(scalar *out, const uint8_t in[640]) {
|
|
772
833
|
|
773
834
|
uint32_t a, b;
|
774
835
|
uint16_t c;
|
775
|
-
static_assert(
|
776
|
-
for (int i = 0; i <
|
836
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
837
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
777
838
|
OPENSSL_memcpy(&a, &in[10 * i], sizeof(a));
|
778
839
|
OPENSSL_memcpy(&b, &in[10 * i + 4], sizeof(b));
|
779
840
|
OPENSSL_memcpy(&c, &in[10 * i + 8], sizeof(c));
|
@@ -791,8 +852,8 @@ static void scalar_decode_signed_20_19(scalar *out, const uint8_t in[640]) {
|
|
791
852
|
static int scalar_decode_signed(scalar *out, const uint8_t *in, int bits,
|
792
853
|
uint32_t max) {
|
793
854
|
if (bits == 4) {
|
794
|
-
assert(max ==
|
795
|
-
return
|
855
|
+
assert(max == 4);
|
856
|
+
return scalar_decode_signed_4_4(out, in);
|
796
857
|
} else if (bits == 13) {
|
797
858
|
assert(max == (1u << 12));
|
798
859
|
scalar_decode_signed_13_12(out, in);
|
@@ -813,19 +874,19 @@ static int scalar_decode_signed(scalar *out, const uint8_t *in, int bits,
|
|
813
874
|
// Rejection samples a Keccak stream to get uniformly distributed elements. This
|
814
875
|
// is used for matrix expansion and only operates on public inputs.
|
815
876
|
static void scalar_from_keccak_vartime(
|
816
|
-
scalar *out, const uint8_t derived_seed[
|
877
|
+
scalar *out, const uint8_t derived_seed[kRhoBytes + 2]) {
|
817
878
|
struct BORINGSSL_keccak_st keccak_ctx;
|
818
879
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake128);
|
819
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, derived_seed,
|
880
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, derived_seed, kRhoBytes + 2);
|
820
881
|
assert(keccak_ctx.squeeze_offset == 0);
|
821
882
|
assert(keccak_ctx.rate_bytes == 168);
|
822
883
|
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
823
884
|
|
824
885
|
int done = 0;
|
825
|
-
while (done <
|
886
|
+
while (done < kDegree) {
|
826
887
|
uint8_t block[168];
|
827
888
|
BORINGSSL_keccak_squeeze(&keccak_ctx, block, sizeof(block));
|
828
|
-
for (size_t i = 0; i < sizeof(block) && done <
|
889
|
+
for (size_t i = 0; i < sizeof(block) && done < kDegree; i += 3) {
|
829
890
|
// FIPS 204, Algorithm 14 (`CoeffFromThreeBytes`).
|
830
891
|
uint32_t value = (uint32_t)block[i] | ((uint32_t)block[i + 1] << 8) |
|
831
892
|
(((uint32_t)block[i + 2] & 0x7f) << 16);
|
@@ -836,22 +897,33 @@ static void scalar_from_keccak_vartime(
|
|
836
897
|
}
|
837
898
|
}
|
838
899
|
|
839
|
-
|
840
|
-
static
|
841
|
-
const uint8_t derived_seed[SIGMA_BYTES + 2]) {
|
842
|
-
static_assert(ETA == 4, "This implementation is specialized for ETA == 4");
|
900
|
+
template <int ETA>
|
901
|
+
static bool coefficient_from_nibble(uint32_t nibble, uint32_t *result);
|
843
902
|
|
903
|
+
template <>
|
904
|
+
bool coefficient_from_nibble<4>(uint32_t nibble, uint32_t *result) {
|
905
|
+
if (constant_time_declassify_int(nibble < 9)) {
|
906
|
+
*result = mod_sub(4, nibble);
|
907
|
+
return true;
|
908
|
+
}
|
909
|
+
return false;
|
910
|
+
}
|
911
|
+
|
912
|
+
// FIPS 204, Algorithm 31 (`RejBoundedPoly`).
|
913
|
+
template <int ETA>
|
914
|
+
static void scalar_uniform(scalar *out,
|
915
|
+
const uint8_t derived_seed[kSigmaBytes + 2]) {
|
844
916
|
struct BORINGSSL_keccak_st keccak_ctx;
|
845
917
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
846
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, derived_seed,
|
918
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, derived_seed, kSigmaBytes + 2);
|
847
919
|
assert(keccak_ctx.squeeze_offset == 0);
|
848
920
|
assert(keccak_ctx.rate_bytes == 136);
|
849
921
|
|
850
922
|
int done = 0;
|
851
|
-
while (done <
|
923
|
+
while (done < kDegree) {
|
852
924
|
uint8_t block[136];
|
853
925
|
BORINGSSL_keccak_squeeze(&keccak_ctx, block, sizeof(block));
|
854
|
-
for (size_t i = 0; i < sizeof(block) && done <
|
926
|
+
for (size_t i = 0; i < sizeof(block) && done < kDegree; ++i) {
|
855
927
|
uint32_t t0 = block[i] & 0x0F;
|
856
928
|
uint32_t t1 = block[i] >> 4;
|
857
929
|
// FIPS 204, Algorithm 15 (`CoefFromHalfByte`). Although both the input
|
@@ -859,21 +931,22 @@ static void scalar_uniform_eta_4(scalar *out,
|
|
859
931
|
// Individual bytes of the SHAKE-256 stream are (indistiguishable from)
|
860
932
|
// independent of each other and the original seed, so leaking information
|
861
933
|
// about the rejected bytes does not reveal the input or output.
|
862
|
-
|
863
|
-
|
934
|
+
uint32_t v;
|
935
|
+
if (coefficient_from_nibble<ETA>(t0, &v)) {
|
936
|
+
out->c[done++] = v;
|
864
937
|
}
|
865
|
-
if (done <
|
866
|
-
out->c[done++] =
|
938
|
+
if (done < kDegree && coefficient_from_nibble<ETA>(t1, &v)) {
|
939
|
+
out->c[done++] = v;
|
867
940
|
}
|
868
941
|
}
|
869
942
|
}
|
870
943
|
}
|
871
944
|
|
872
945
|
// FIPS 204, Algorithm 34 (`ExpandMask`), but just a single step.
|
873
|
-
static void scalar_sample_mask(
|
874
|
-
|
946
|
+
static void scalar_sample_mask(scalar *out,
|
947
|
+
const uint8_t derived_seed[kRhoPrimeBytes + 2]) {
|
875
948
|
uint8_t buf[640];
|
876
|
-
BORINGSSL_keccak(buf, sizeof(buf), derived_seed,
|
949
|
+
BORINGSSL_keccak(buf, sizeof(buf), derived_seed, kRhoPrimeBytes + 2,
|
877
950
|
boringssl_shake256);
|
878
951
|
|
879
952
|
scalar_decode_signed_20_19(out, buf);
|
@@ -881,9 +954,7 @@ static void scalar_sample_mask(
|
|
881
954
|
|
882
955
|
// FIPS 204, Algorithm 29 (`SampleInBall`).
|
883
956
|
static void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed,
|
884
|
-
int len) {
|
885
|
-
assert(len == 2 * LAMBDA_BYTES);
|
886
|
-
|
957
|
+
int len, int tau) {
|
887
958
|
struct BORINGSSL_keccak_st keccak_ctx;
|
888
959
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
889
960
|
BORINGSSL_keccak_absorb(&keccak_ctx, seed, len);
|
@@ -902,7 +973,7 @@ static void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed,
|
|
902
973
|
CONSTTIME_DECLASSIFY(block + offset, sizeof(block) - offset);
|
903
974
|
|
904
975
|
OPENSSL_memset(out, 0, sizeof(*out));
|
905
|
-
for (size_t i =
|
976
|
+
for (size_t i = kDegree - tau; i < kDegree; i++) {
|
906
977
|
size_t byte;
|
907
978
|
for (;;) {
|
908
979
|
if (offset == 136) {
|
@@ -925,54 +996,57 @@ static void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed,
|
|
925
996
|
}
|
926
997
|
|
927
998
|
// FIPS 204, Algorithm 32 (`ExpandA`).
|
928
|
-
|
999
|
+
template <int K, int L>
|
1000
|
+
static void matrix_expand(matrix<K, L> *out, const uint8_t rho[kRhoBytes]) {
|
929
1001
|
static_assert(K <= 0x100, "K must fit in 8 bits");
|
930
1002
|
static_assert(L <= 0x100, "L must fit in 8 bits");
|
931
1003
|
|
932
|
-
uint8_t derived_seed[
|
933
|
-
OPENSSL_memcpy(derived_seed, rho,
|
1004
|
+
uint8_t derived_seed[kRhoBytes + 2];
|
1005
|
+
OPENSSL_memcpy(derived_seed, rho, kRhoBytes);
|
934
1006
|
for (int i = 0; i < K; i++) {
|
935
1007
|
for (int j = 0; j < L; j++) {
|
936
|
-
derived_seed[
|
937
|
-
derived_seed[
|
1008
|
+
derived_seed[kRhoBytes + 1] = (uint8_t)i;
|
1009
|
+
derived_seed[kRhoBytes] = (uint8_t)j;
|
938
1010
|
scalar_from_keccak_vartime(&out->v[i][j], derived_seed);
|
939
1011
|
}
|
940
1012
|
}
|
941
1013
|
}
|
942
1014
|
|
943
1015
|
// FIPS 204, Algorithm 33 (`ExpandS`).
|
944
|
-
|
945
|
-
|
1016
|
+
template <int K, int L>
|
1017
|
+
static void vector_expand_short(vector<L> *s1, vector<K> *s2,
|
1018
|
+
const uint8_t sigma[kSigmaBytes]) {
|
946
1019
|
static_assert(K <= 0x100, "K must fit in 8 bits");
|
947
1020
|
static_assert(L <= 0x100, "L must fit in 8 bits");
|
948
1021
|
static_assert(K + L <= 0x100, "K+L must fit in 8 bits");
|
949
1022
|
|
950
|
-
uint8_t derived_seed[
|
951
|
-
OPENSSL_memcpy(derived_seed, sigma,
|
952
|
-
derived_seed[
|
953
|
-
derived_seed[
|
1023
|
+
uint8_t derived_seed[kSigmaBytes + 2];
|
1024
|
+
OPENSSL_memcpy(derived_seed, sigma, kSigmaBytes);
|
1025
|
+
derived_seed[kSigmaBytes] = 0;
|
1026
|
+
derived_seed[kSigmaBytes + 1] = 0;
|
954
1027
|
for (int i = 0; i < L; i++) {
|
955
|
-
|
956
|
-
++derived_seed[
|
1028
|
+
scalar_uniform<eta<K>()>(&s1->v[i], derived_seed);
|
1029
|
+
++derived_seed[kSigmaBytes];
|
957
1030
|
}
|
958
1031
|
for (int i = 0; i < K; i++) {
|
959
|
-
|
960
|
-
++derived_seed[
|
1032
|
+
scalar_uniform<eta<K>()>(&s2->v[i], derived_seed);
|
1033
|
+
++derived_seed[kSigmaBytes];
|
961
1034
|
}
|
962
1035
|
}
|
963
1036
|
|
964
1037
|
// FIPS 204, Algorithm 34 (`ExpandMask`).
|
965
|
-
|
966
|
-
|
967
|
-
|
1038
|
+
template <int L>
|
1039
|
+
static void vector_expand_mask(vector<L> *out,
|
1040
|
+
const uint8_t seed[kRhoPrimeBytes],
|
1041
|
+
size_t kappa) {
|
968
1042
|
assert(kappa + L <= 0x10000);
|
969
1043
|
|
970
|
-
uint8_t derived_seed[
|
971
|
-
OPENSSL_memcpy(derived_seed, seed,
|
1044
|
+
uint8_t derived_seed[kRhoPrimeBytes + 2];
|
1045
|
+
OPENSSL_memcpy(derived_seed, seed, kRhoPrimeBytes);
|
972
1046
|
for (int i = 0; i < L; i++) {
|
973
1047
|
size_t index = kappa + i;
|
974
|
-
derived_seed[
|
975
|
-
derived_seed[
|
1048
|
+
derived_seed[kRhoPrimeBytes] = index & 0xFF;
|
1049
|
+
derived_seed[kRhoPrimeBytes + 1] = (index >> 8) & 0xFF;
|
976
1050
|
scalar_sample_mask(&out->v[i], derived_seed);
|
977
1051
|
}
|
978
1052
|
}
|
@@ -981,63 +1055,49 @@ static void vectorl_expand_mask(vectorl *out,
|
|
981
1055
|
|
982
1056
|
// FIPS 204, Algorithm 16 (`SimpleBitPack`).
|
983
1057
|
//
|
984
|
-
// Encodes an entire vector into 32*K*|bits| bytes. Note that since 256
|
985
|
-
// is divisible by 8, the individual vector entries will always fill a
|
986
|
-
// number of bytes, so we do not need to worry about bit packing here.
|
987
|
-
|
1058
|
+
// Encodes an entire vector into 32*K*|bits| bytes. Note that since 256
|
1059
|
+
// (kDegree) is divisible by 8, the individual vector entries will always fill a
|
1060
|
+
// whole number of bytes, so we do not need to worry about bit packing here.
|
1061
|
+
template <int K>
|
1062
|
+
static void vector_encode(uint8_t *out, const vector<K> *a, int bits) {
|
988
1063
|
if (bits == 4) {
|
989
1064
|
for (int i = 0; i < K; i++) {
|
990
|
-
scalar_encode_4(out + i * bits *
|
1065
|
+
scalar_encode_4(out + i * bits * kDegree / 8, &a->v[i]);
|
991
1066
|
}
|
992
1067
|
} else {
|
993
1068
|
assert(bits == 10);
|
994
1069
|
for (int i = 0; i < K; i++) {
|
995
|
-
scalar_encode_10(out + i * bits *
|
1070
|
+
scalar_encode_10(out + i * bits * kDegree / 8, &a->v[i]);
|
996
1071
|
}
|
997
1072
|
}
|
998
1073
|
}
|
999
1074
|
|
1000
1075
|
// FIPS 204, Algorithm 18 (`SimpleBitUnpack`).
|
1001
|
-
|
1002
|
-
|
1003
|
-
scalar_decode_10(&out->v[i], in + i * 10 * DEGREE / 8);
|
1004
|
-
}
|
1005
|
-
}
|
1006
|
-
|
1007
|
-
static void vectork_encode_signed(uint8_t *out, const vectork *a, int bits,
|
1008
|
-
uint32_t max) {
|
1076
|
+
template <int K>
|
1077
|
+
static void vector_decode_10(vector<K> *out, const uint8_t *in) {
|
1009
1078
|
for (int i = 0; i < K; i++) {
|
1010
|
-
|
1079
|
+
scalar_decode_10(&out->v[i], in + i * 10 * kDegree / 8);
|
1011
1080
|
}
|
1012
1081
|
}
|
1013
1082
|
|
1014
|
-
static int vectork_decode_signed(vectork *out, const uint8_t *in, int bits,
|
1015
|
-
uint32_t max) {
|
1016
|
-
for (int i = 0; i < K; i++) {
|
1017
|
-
if (!scalar_decode_signed(&out->v[i], in + i * bits * DEGREE / 8, bits,
|
1018
|
-
max)) {
|
1019
|
-
return 0;
|
1020
|
-
}
|
1021
|
-
}
|
1022
|
-
return 1;
|
1023
|
-
}
|
1024
|
-
|
1025
1083
|
// FIPS 204, Algorithm 17 (`BitPack`).
|
1026
1084
|
//
|
1027
|
-
// Encodes an entire vector into 32*L*|bits| bytes. Note that since 256
|
1028
|
-
// is divisible by 8, the individual vector entries will always fill a
|
1029
|
-
// number of bytes, so we do not need to worry about bit packing here.
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1085
|
+
// Encodes an entire vector into 32*L*|bits| bytes. Note that since 256
|
1086
|
+
// (kDegree) is divisible by 8, the individual vector entries will always fill a
|
1087
|
+
// whole number of bytes, so we do not need to worry about bit packing here.
|
1088
|
+
template <int X>
|
1089
|
+
static void vector_encode_signed(uint8_t *out, const vector<X> *a, int bits,
|
1090
|
+
uint32_t max) {
|
1091
|
+
for (int i = 0; i < X; i++) {
|
1092
|
+
scalar_encode_signed(out + i * bits * kDegree / 8, &a->v[i], bits, max);
|
1034
1093
|
}
|
1035
1094
|
}
|
1036
1095
|
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1096
|
+
template <int X>
|
1097
|
+
static int vector_decode_signed(vector<X> *out, const uint8_t *in, int bits,
|
1098
|
+
uint32_t max) {
|
1099
|
+
for (int i = 0; i < X; i++) {
|
1100
|
+
if (!scalar_decode_signed(&out->v[i], in + i * bits * kDegree / 8, bits,
|
1041
1101
|
max)) {
|
1042
1102
|
return 0;
|
1043
1103
|
}
|
@@ -1046,33 +1106,36 @@ static int vectorl_decode_signed(vectorl *out, const uint8_t *in, int bits,
|
|
1046
1106
|
}
|
1047
1107
|
|
1048
1108
|
// FIPS 204, Algorithm 28 (`w1Encode`).
|
1049
|
-
|
1050
|
-
|
1109
|
+
template <int K>
|
1110
|
+
static void w1_encode(uint8_t out[128 * K], const vector<K> *w1) {
|
1111
|
+
vector_encode(out, w1, 4);
|
1051
1112
|
}
|
1052
1113
|
|
1053
1114
|
// FIPS 204, Algorithm 20 (`HintBitPack`).
|
1054
|
-
|
1055
|
-
|
1115
|
+
template <int K>
|
1116
|
+
static void hint_bit_pack(uint8_t out[omega<K>() + K], const vector<K> *h) {
|
1117
|
+
OPENSSL_memset(out, 0, omega<K>() + K);
|
1056
1118
|
int index = 0;
|
1057
1119
|
for (int i = 0; i < K; i++) {
|
1058
|
-
for (int j = 0; j <
|
1120
|
+
for (int j = 0; j < kDegree; j++) {
|
1059
1121
|
if (h->v[i].c[j]) {
|
1060
|
-
// h must have at most
|
1061
|
-
BSSL_CHECK(index <
|
1122
|
+
// h must have at most omega<K>() non-zero coefficients.
|
1123
|
+
BSSL_CHECK(index < omega<K>());
|
1062
1124
|
out[index++] = j;
|
1063
1125
|
}
|
1064
1126
|
}
|
1065
|
-
out[
|
1127
|
+
out[omega<K>() + i] = index;
|
1066
1128
|
}
|
1067
1129
|
}
|
1068
1130
|
|
1069
1131
|
// FIPS 204, Algorithm 21 (`HintBitUnpack`).
|
1070
|
-
|
1071
|
-
|
1132
|
+
template <int K>
|
1133
|
+
static int hint_bit_unpack(vector<K> *h, const uint8_t in[omega<K>() + K]) {
|
1134
|
+
vector_zero(h);
|
1072
1135
|
int index = 0;
|
1073
1136
|
for (int i = 0; i < K; i++) {
|
1074
|
-
const int limit = in[
|
1075
|
-
if (limit < index || limit >
|
1137
|
+
const int limit = in[omega<K>() + i];
|
1138
|
+
if (limit < index || limit > omega<K>()) {
|
1076
1139
|
return 0;
|
1077
1140
|
}
|
1078
1141
|
|
@@ -1083,12 +1146,12 @@ static int hint_bit_unpack(vectork *h, const uint8_t in[OMEGA + K]) {
|
|
1083
1146
|
return 0;
|
1084
1147
|
}
|
1085
1148
|
last = byte;
|
1086
|
-
static_assert(
|
1087
|
-
"
|
1149
|
+
static_assert(kDegree == 256,
|
1150
|
+
"kDegree must be 256 for this write to be in bounds");
|
1088
1151
|
h->v[i].c[byte] = 1;
|
1089
1152
|
}
|
1090
1153
|
}
|
1091
|
-
for (; index <
|
1154
|
+
for (; index < omega<K>(); index++) {
|
1092
1155
|
if (in[index] != 0) {
|
1093
1156
|
return 0;
|
1094
1157
|
}
|
@@ -1096,30 +1159,34 @@ static int hint_bit_unpack(vectork *h, const uint8_t in[OMEGA + K]) {
|
|
1096
1159
|
return 1;
|
1097
1160
|
}
|
1098
1161
|
|
1162
|
+
template <int K>
|
1099
1163
|
struct public_key {
|
1100
|
-
uint8_t rho[
|
1101
|
-
|
1164
|
+
uint8_t rho[kRhoBytes];
|
1165
|
+
vector<K> t1;
|
1102
1166
|
// Pre-cached value(s).
|
1103
|
-
uint8_t public_key_hash[
|
1167
|
+
uint8_t public_key_hash[kTrBytes];
|
1104
1168
|
};
|
1105
1169
|
|
1170
|
+
template <int K, int L>
|
1106
1171
|
struct private_key {
|
1107
|
-
uint8_t rho[
|
1108
|
-
uint8_t k[
|
1109
|
-
uint8_t public_key_hash[
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1172
|
+
uint8_t rho[kRhoBytes];
|
1173
|
+
uint8_t k[kKBytes];
|
1174
|
+
uint8_t public_key_hash[kTrBytes];
|
1175
|
+
vector<L> s1;
|
1176
|
+
vector<K> s2;
|
1177
|
+
vector<K> t0;
|
1113
1178
|
};
|
1114
1179
|
|
1180
|
+
template <int K, int L>
|
1115
1181
|
struct signature {
|
1116
|
-
uint8_t c_tilde[2 *
|
1117
|
-
|
1118
|
-
|
1182
|
+
uint8_t c_tilde[2 * lambda_bytes<K>()];
|
1183
|
+
vector<L> z;
|
1184
|
+
vector<K> h;
|
1119
1185
|
};
|
1120
1186
|
|
1121
1187
|
// FIPS 204, Algorithm 22 (`pkEncode`).
|
1122
|
-
|
1188
|
+
template <int K>
|
1189
|
+
static int mldsa_marshal_public_key(CBB *out, const struct public_key<K> *pub) {
|
1123
1190
|
if (!CBB_add_bytes(out, pub->rho, sizeof(pub->rho))) {
|
1124
1191
|
return 0;
|
1125
1192
|
}
|
@@ -1128,28 +1195,37 @@ static int mldsa_marshal_public_key(CBB *out, const struct public_key *pub) {
|
|
1128
1195
|
if (!CBB_add_space(out, &vectork_output, 320 * K)) {
|
1129
1196
|
return 0;
|
1130
1197
|
}
|
1131
|
-
|
1198
|
+
vector_encode(vectork_output, &pub->t1, 10);
|
1132
1199
|
|
1133
1200
|
return 1;
|
1134
1201
|
}
|
1135
1202
|
|
1136
1203
|
// FIPS 204, Algorithm 23 (`pkDecode`).
|
1137
|
-
|
1204
|
+
template <int K>
|
1205
|
+
static int mldsa_parse_public_key(struct public_key<K> *pub, CBS *in) {
|
1206
|
+
const CBS orig_in = *in;
|
1207
|
+
|
1138
1208
|
if (!CBS_copy_bytes(in, pub->rho, sizeof(pub->rho))) {
|
1139
1209
|
return 0;
|
1140
1210
|
}
|
1141
1211
|
|
1142
1212
|
CBS t1_bytes;
|
1143
|
-
if (!CBS_get_bytes(in, &t1_bytes, 320 * K)) {
|
1213
|
+
if (!CBS_get_bytes(in, &t1_bytes, 320 * K) || CBS_len(in) != 0) {
|
1144
1214
|
return 0;
|
1145
1215
|
}
|
1146
|
-
|
1216
|
+
vector_decode_10(&pub->t1, CBS_data(&t1_bytes));
|
1217
|
+
|
1218
|
+
// Compute pre-cached values.
|
1219
|
+
BORINGSSL_keccak(pub->public_key_hash, sizeof(pub->public_key_hash),
|
1220
|
+
CBS_data(&orig_in), CBS_len(&orig_in), boringssl_shake256);
|
1147
1221
|
|
1148
1222
|
return 1;
|
1149
1223
|
}
|
1150
1224
|
|
1151
1225
|
// FIPS 204, Algorithm 24 (`skEncode`).
|
1152
|
-
|
1226
|
+
template <int K, int L>
|
1227
|
+
static int mldsa_marshal_private_key(CBB *out,
|
1228
|
+
const struct private_key<K, L> *priv) {
|
1153
1229
|
if (!CBB_add_bytes(out, priv->rho, sizeof(priv->rho)) ||
|
1154
1230
|
!CBB_add_bytes(out, priv->k, sizeof(priv->k)) ||
|
1155
1231
|
!CBB_add_bytes(out, priv->public_key_hash,
|
@@ -1157,42 +1233,52 @@ static int mldsa_marshal_private_key(CBB *out, const struct private_key *priv) {
|
|
1157
1233
|
return 0;
|
1158
1234
|
}
|
1159
1235
|
|
1236
|
+
constexpr size_t scalar_bytes =
|
1237
|
+
(kDegree * plus_minus_eta_bitlen<K>() + 7) / 8;
|
1160
1238
|
uint8_t *vectorl_output;
|
1161
|
-
if (!CBB_add_space(out, &vectorl_output,
|
1239
|
+
if (!CBB_add_space(out, &vectorl_output, scalar_bytes * L)) {
|
1162
1240
|
return 0;
|
1163
1241
|
}
|
1164
|
-
|
1242
|
+
vector_encode_signed(vectorl_output, &priv->s1, plus_minus_eta_bitlen<K>(),
|
1243
|
+
eta<K>());
|
1165
1244
|
|
1166
|
-
uint8_t *
|
1167
|
-
if (!CBB_add_space(out, &
|
1245
|
+
uint8_t *s2_output;
|
1246
|
+
if (!CBB_add_space(out, &s2_output, scalar_bytes * K)) {
|
1168
1247
|
return 0;
|
1169
1248
|
}
|
1170
|
-
|
1249
|
+
vector_encode_signed(s2_output, &priv->s2, plus_minus_eta_bitlen<K>(),
|
1250
|
+
eta<K>());
|
1171
1251
|
|
1172
|
-
|
1252
|
+
uint8_t *t0_output;
|
1253
|
+
if (!CBB_add_space(out, &t0_output, 416 * K)) {
|
1173
1254
|
return 0;
|
1174
1255
|
}
|
1175
|
-
|
1256
|
+
vector_encode_signed(t0_output, &priv->t0, 13, 1 << 12);
|
1176
1257
|
|
1177
1258
|
return 1;
|
1178
1259
|
}
|
1179
1260
|
|
1180
1261
|
// FIPS 204, Algorithm 25 (`skDecode`).
|
1181
|
-
|
1262
|
+
template <int K, int L>
|
1263
|
+
static int mldsa_parse_private_key(struct private_key<K, L> *priv, CBS *in) {
|
1182
1264
|
CBS s1_bytes;
|
1183
1265
|
CBS s2_bytes;
|
1184
1266
|
CBS t0_bytes;
|
1267
|
+
constexpr size_t scalar_bytes =
|
1268
|
+
(kDegree * plus_minus_eta_bitlen<K>() + 7) / 8;
|
1185
1269
|
if (!CBS_copy_bytes(in, priv->rho, sizeof(priv->rho)) ||
|
1186
1270
|
!CBS_copy_bytes(in, priv->k, sizeof(priv->k)) ||
|
1187
1271
|
!CBS_copy_bytes(in, priv->public_key_hash,
|
1188
1272
|
sizeof(priv->public_key_hash)) ||
|
1189
|
-
!CBS_get_bytes(in, &s1_bytes,
|
1190
|
-
!
|
1191
|
-
|
1192
|
-
!
|
1273
|
+
!CBS_get_bytes(in, &s1_bytes, scalar_bytes * L) ||
|
1274
|
+
!vector_decode_signed(&priv->s1, CBS_data(&s1_bytes),
|
1275
|
+
plus_minus_eta_bitlen<K>(), eta<K>()) ||
|
1276
|
+
!CBS_get_bytes(in, &s2_bytes, scalar_bytes * K) ||
|
1277
|
+
!vector_decode_signed(&priv->s2, CBS_data(&s2_bytes),
|
1278
|
+
plus_minus_eta_bitlen<K>(), eta<K>()) ||
|
1193
1279
|
!CBS_get_bytes(in, &t0_bytes, 416 * K) ||
|
1194
1280
|
// Note: Decoding 13 bits into (-2^12, 2^12] cannot fail.
|
1195
|
-
!
|
1281
|
+
!vector_decode_signed(&priv->t0, CBS_data(&t0_bytes), 13, 1 << 12)) {
|
1196
1282
|
return 0;
|
1197
1283
|
}
|
1198
1284
|
|
@@ -1200,7 +1286,9 @@ static int mldsa_parse_private_key(struct private_key *priv, CBS *in) {
|
|
1200
1286
|
}
|
1201
1287
|
|
1202
1288
|
// FIPS 204, Algorithm 26 (`sigEncode`).
|
1203
|
-
|
1289
|
+
template <int K, int L>
|
1290
|
+
static int mldsa_marshal_signature(CBB *out,
|
1291
|
+
const struct signature<K, L> *sign) {
|
1204
1292
|
if (!CBB_add_bytes(out, sign->c_tilde, sizeof(sign->c_tilde))) {
|
1205
1293
|
return 0;
|
1206
1294
|
}
|
@@ -1209,10 +1297,10 @@ static int mldsa_marshal_signature(CBB *out, const struct signature *sign) {
|
|
1209
1297
|
if (!CBB_add_space(out, &vectorl_output, 640 * L)) {
|
1210
1298
|
return 0;
|
1211
1299
|
}
|
1212
|
-
|
1300
|
+
vector_encode_signed(vectorl_output, &sign->z, 20, 1 << 19);
|
1213
1301
|
|
1214
1302
|
uint8_t *hint_output;
|
1215
|
-
if (!CBB_add_space(out, &hint_output,
|
1303
|
+
if (!CBB_add_space(out, &hint_output, omega<K>() + K)) {
|
1216
1304
|
return 0;
|
1217
1305
|
}
|
1218
1306
|
hint_bit_pack(hint_output, &sign->h);
|
@@ -1221,14 +1309,15 @@ static int mldsa_marshal_signature(CBB *out, const struct signature *sign) {
|
|
1221
1309
|
}
|
1222
1310
|
|
1223
1311
|
// FIPS 204, Algorithm 27 (`sigDecode`).
|
1224
|
-
|
1312
|
+
template <int K, int L>
|
1313
|
+
static int mldsa_parse_signature(struct signature<K, L> *sign, CBS *in) {
|
1225
1314
|
CBS z_bytes;
|
1226
1315
|
CBS hint_bytes;
|
1227
1316
|
if (!CBS_copy_bytes(in, sign->c_tilde, sizeof(sign->c_tilde)) ||
|
1228
1317
|
!CBS_get_bytes(in, &z_bytes, 640 * L) ||
|
1229
1318
|
// Note: Decoding 20 bits into (-2^19, 2^19] cannot fail.
|
1230
|
-
!
|
1231
|
-
!CBS_get_bytes(in, &hint_bytes,
|
1319
|
+
!vector_decode_signed(&sign->z, CBS_data(&z_bytes), 20, 1 << 19) ||
|
1320
|
+
!CBS_get_bytes(in, &hint_bytes, omega<K>() + K) ||
|
1232
1321
|
!hint_bit_unpack(&sign->h, CBS_data(&hint_bytes))) {
|
1233
1322
|
return 0;
|
1234
1323
|
};
|
@@ -1236,86 +1325,44 @@ static int mldsa_parse_signature(struct signature *sign, CBS *in) {
|
|
1236
1325
|
return 1;
|
1237
1326
|
}
|
1238
1327
|
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
"Kyber private key size incorrect");
|
1244
|
-
static_assert(
|
1245
|
-
alignof(struct MLDSA65_private_key) == alignof(struct private_key),
|
1246
|
-
"Kyber private key align incorrect");
|
1247
|
-
return (struct private_key *)external;
|
1248
|
-
}
|
1249
|
-
|
1250
|
-
static struct public_key *public_key_from_external(
|
1251
|
-
const struct MLDSA65_public_key *external) {
|
1252
|
-
static_assert(sizeof(struct MLDSA65_public_key) == sizeof(struct public_key),
|
1253
|
-
"mldsa public key size incorrect");
|
1254
|
-
static_assert(
|
1255
|
-
alignof(struct MLDSA65_public_key) == alignof(struct public_key),
|
1256
|
-
"mldsa public key align incorrect");
|
1257
|
-
return (struct public_key *)external;
|
1258
|
-
}
|
1259
|
-
|
1260
|
-
/* API */
|
1261
|
-
|
1262
|
-
// Calls |MLDSA_generate_key_external_entropy| with random bytes from
|
1263
|
-
// |RAND_bytes|. Returns 1 on success and 0 on failure.
|
1264
|
-
int MLDSA65_generate_key(
|
1265
|
-
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
1266
|
-
uint8_t out_seed[MLDSA_SEED_BYTES],
|
1267
|
-
struct MLDSA65_private_key *out_private_key) {
|
1268
|
-
RAND_bytes(out_seed, MLDSA_SEED_BYTES);
|
1269
|
-
return MLDSA65_generate_key_external_entropy(out_encoded_public_key,
|
1270
|
-
out_private_key, out_seed);
|
1271
|
-
}
|
1272
|
-
|
1273
|
-
int MLDSA65_private_key_from_seed(struct MLDSA65_private_key *out_private_key,
|
1274
|
-
const uint8_t *seed, size_t seed_len) {
|
1275
|
-
if (seed_len != MLDSA_SEED_BYTES) {
|
1276
|
-
return 0;
|
1277
|
-
}
|
1278
|
-
uint8_t public_key[MLDSA65_PUBLIC_KEY_BYTES];
|
1279
|
-
return MLDSA65_generate_key_external_entropy(public_key, out_private_key,
|
1280
|
-
seed);
|
1281
|
-
}
|
1328
|
+
template <typename T>
|
1329
|
+
struct DeleterFree {
|
1330
|
+
void operator()(T *ptr) { OPENSSL_free(ptr); }
|
1331
|
+
};
|
1282
1332
|
|
1283
1333
|
// FIPS 204, Algorithm 6 (`ML-DSA.KeyGen_internal`). Returns 1 on success and 0
|
1284
1334
|
// on failure.
|
1285
|
-
int
|
1286
|
-
|
1287
|
-
|
1288
|
-
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
1289
|
-
int ret = 0;
|
1290
|
-
|
1335
|
+
template <int K, int L>
|
1336
|
+
static int mldsa_generate_key_external_entropy(
|
1337
|
+
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
1338
|
+
struct private_key<K, L> *priv, const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
1291
1339
|
// Intermediate values, allocated on the heap to allow use when there is a
|
1292
1340
|
// limited amount of stack.
|
1293
1341
|
struct values_st {
|
1294
|
-
struct public_key pub;
|
1295
|
-
matrix a_ntt;
|
1296
|
-
|
1297
|
-
|
1342
|
+
struct public_key<K> pub;
|
1343
|
+
matrix<K, L> a_ntt;
|
1344
|
+
vector<L> s1_ntt;
|
1345
|
+
vector<K> t;
|
1298
1346
|
};
|
1299
|
-
|
1347
|
+
std::unique_ptr<values_st, DeleterFree<values_st>> values(
|
1348
|
+
reinterpret_cast<struct values_st *>(OPENSSL_malloc(sizeof(values_st))));
|
1300
1349
|
if (values == NULL) {
|
1301
|
-
|
1350
|
+
return 0;
|
1302
1351
|
}
|
1303
1352
|
|
1304
|
-
struct private_key *priv = private_key_from_external(out_private_key);
|
1305
|
-
|
1306
1353
|
uint8_t augmented_entropy[MLDSA_SEED_BYTES + 2];
|
1307
1354
|
OPENSSL_memcpy(augmented_entropy, entropy, MLDSA_SEED_BYTES);
|
1308
1355
|
// The k and l parameters are appended to the seed.
|
1309
1356
|
augmented_entropy[MLDSA_SEED_BYTES] = K;
|
1310
1357
|
augmented_entropy[MLDSA_SEED_BYTES + 1] = L;
|
1311
|
-
uint8_t expanded_seed[
|
1358
|
+
uint8_t expanded_seed[kRhoBytes + kSigmaBytes + kKBytes];
|
1312
1359
|
BORINGSSL_keccak(expanded_seed, sizeof(expanded_seed), augmented_entropy,
|
1313
1360
|
sizeof(augmented_entropy), boringssl_shake256);
|
1314
1361
|
const uint8_t *const rho = expanded_seed;
|
1315
|
-
const uint8_t *const sigma = expanded_seed +
|
1316
|
-
const uint8_t *const k = expanded_seed +
|
1362
|
+
const uint8_t *const sigma = expanded_seed + kRhoBytes;
|
1363
|
+
const uint8_t *const k = expanded_seed + kRhoBytes + kSigmaBytes;
|
1317
1364
|
// rho is public.
|
1318
|
-
CONSTTIME_DECLASSIFY(rho,
|
1365
|
+
CONSTTIME_DECLASSIFY(rho, kRhoBytes);
|
1319
1366
|
OPENSSL_memcpy(values->pub.rho, rho, sizeof(values->pub.rho));
|
1320
1367
|
OPENSSL_memcpy(priv->rho, rho, sizeof(priv->rho));
|
1321
1368
|
OPENSSL_memcpy(priv->k, k, sizeof(priv->k));
|
@@ -1324,52 +1371,47 @@ int MLDSA65_generate_key_external_entropy(
|
|
1324
1371
|
vector_expand_short(&priv->s1, &priv->s2, sigma);
|
1325
1372
|
|
1326
1373
|
OPENSSL_memcpy(&values->s1_ntt, &priv->s1, sizeof(values->s1_ntt));
|
1327
|
-
|
1374
|
+
vector_ntt(&values->s1_ntt);
|
1328
1375
|
|
1329
1376
|
matrix_mult(&values->t, &values->a_ntt, &values->s1_ntt);
|
1330
|
-
|
1331
|
-
|
1377
|
+
vector_inverse_ntt(&values->t);
|
1378
|
+
vector_add(&values->t, &values->t, &priv->s2);
|
1332
1379
|
|
1333
|
-
|
1380
|
+
vector_power2_round(&values->pub.t1, &priv->t0, &values->t);
|
1334
1381
|
// t1 is public.
|
1335
1382
|
CONSTTIME_DECLASSIFY(&values->pub.t1, sizeof(values->pub.t1));
|
1336
1383
|
|
1337
1384
|
CBB cbb;
|
1338
|
-
CBB_init_fixed(&cbb, out_encoded_public_key,
|
1385
|
+
CBB_init_fixed(&cbb, out_encoded_public_key, public_key_bytes<K>());
|
1339
1386
|
if (!mldsa_marshal_public_key(&cbb, &values->pub)) {
|
1340
|
-
|
1387
|
+
return 0;
|
1341
1388
|
}
|
1342
|
-
assert(CBB_len(&cbb) ==
|
1389
|
+
assert(CBB_len(&cbb) == public_key_bytes<K>());
|
1343
1390
|
|
1344
1391
|
BORINGSSL_keccak(priv->public_key_hash, sizeof(priv->public_key_hash),
|
1345
|
-
out_encoded_public_key,
|
1392
|
+
out_encoded_public_key, public_key_bytes<K>(),
|
1346
1393
|
boringssl_shake256);
|
1347
1394
|
|
1348
|
-
|
1349
|
-
err:
|
1350
|
-
OPENSSL_free(values);
|
1351
|
-
return ret;
|
1395
|
+
return 1;
|
1352
1396
|
}
|
1353
1397
|
|
1354
|
-
int
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1398
|
+
template <int K, int L>
|
1399
|
+
static int mldsa_public_from_private(struct public_key<K> *pub,
|
1400
|
+
const struct private_key<K, L> *priv) {
|
1358
1401
|
// Intermediate values, allocated on the heap to allow use when there is a
|
1359
1402
|
// limited amount of stack.
|
1360
1403
|
struct values_st {
|
1361
|
-
matrix a_ntt;
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1404
|
+
matrix<K, L> a_ntt;
|
1405
|
+
vector<L> s1_ntt;
|
1406
|
+
vector<K> t;
|
1407
|
+
vector<K> t0;
|
1365
1408
|
};
|
1366
|
-
|
1409
|
+
std::unique_ptr<values_st, DeleterFree<values_st>> values(
|
1410
|
+
reinterpret_cast<struct values_st *>(OPENSSL_malloc(sizeof(values_st))));
|
1367
1411
|
if (values == NULL) {
|
1368
|
-
|
1412
|
+
return 0;
|
1369
1413
|
}
|
1370
1414
|
|
1371
|
-
const struct private_key *priv = private_key_from_external(private_key);
|
1372
|
-
struct public_key *pub = public_key_from_external(out_public_key);
|
1373
1415
|
|
1374
1416
|
OPENSSL_memcpy(pub->rho, priv->rho, sizeof(pub->rho));
|
1375
1417
|
OPENSSL_memcpy(pub->public_key_hash, priv->public_key_hash,
|
@@ -1378,32 +1420,26 @@ int MLDSA65_public_from_private(struct MLDSA65_public_key *out_public_key,
|
|
1378
1420
|
matrix_expand(&values->a_ntt, priv->rho);
|
1379
1421
|
|
1380
1422
|
OPENSSL_memcpy(&values->s1_ntt, &priv->s1, sizeof(values->s1_ntt));
|
1381
|
-
|
1423
|
+
vector_ntt(&values->s1_ntt);
|
1382
1424
|
|
1383
1425
|
matrix_mult(&values->t, &values->a_ntt, &values->s1_ntt);
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
vectork_power2_round(&pub->t1, &values->t0, &values->t);
|
1426
|
+
vector_inverse_ntt(&values->t);
|
1427
|
+
vector_add(&values->t, &values->t, &priv->s2);
|
1388
1428
|
|
1389
|
-
|
1390
|
-
|
1391
|
-
OPENSSL_free(values);
|
1392
|
-
return ret;
|
1429
|
+
vector_power2_round(&pub->t1, &values->t0, &values->t);
|
1430
|
+
return 1;
|
1393
1431
|
}
|
1394
1432
|
|
1395
|
-
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`). Returns 1 on success and 0
|
1396
|
-
// failure.
|
1397
|
-
int
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1433
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`). Returns 1 on success and 0
|
1434
|
+
// on failure.
|
1435
|
+
template <int K, int L>
|
1436
|
+
static int mldsa_sign_internal(
|
1437
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
1438
|
+
const struct private_key<K, L> *priv, const uint8_t *msg, size_t msg_len,
|
1439
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
1401
1440
|
const uint8_t *context, size_t context_len,
|
1402
1441
|
const uint8_t randomizer[MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
1403
|
-
|
1404
|
-
const struct private_key *priv = private_key_from_external(private_key);
|
1405
|
-
|
1406
|
-
uint8_t mu[MU_BYTES];
|
1442
|
+
uint8_t mu[kMuBytes];
|
1407
1443
|
struct BORINGSSL_keccak_st keccak_ctx;
|
1408
1444
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
1409
1445
|
BORINGSSL_keccak_absorb(&keccak_ctx, priv->public_key_hash,
|
@@ -1411,82 +1447,83 @@ int MLDSA65_sign_internal(
|
|
1411
1447
|
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
1412
1448
|
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
1413
1449
|
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
1414
|
-
BORINGSSL_keccak_squeeze(&keccak_ctx, mu,
|
1450
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
1415
1451
|
|
1416
|
-
uint8_t rho_prime[
|
1452
|
+
uint8_t rho_prime[kRhoPrimeBytes];
|
1417
1453
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
1418
1454
|
BORINGSSL_keccak_absorb(&keccak_ctx, priv->k, sizeof(priv->k));
|
1419
1455
|
BORINGSSL_keccak_absorb(&keccak_ctx, randomizer,
|
1420
1456
|
MLDSA_SIGNATURE_RANDOMIZER_BYTES);
|
1421
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, mu,
|
1422
|
-
BORINGSSL_keccak_squeeze(&keccak_ctx, rho_prime,
|
1457
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
1458
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, rho_prime, kRhoPrimeBytes);
|
1423
1459
|
|
1424
1460
|
// Intermediate values, allocated on the heap to allow use when there is a
|
1425
1461
|
// limited amount of stack.
|
1426
1462
|
struct values_st {
|
1427
|
-
struct signature sign;
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
matrix a_ntt;
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1463
|
+
struct signature<K, L> sign;
|
1464
|
+
vector<L> s1_ntt;
|
1465
|
+
vector<K> s2_ntt;
|
1466
|
+
vector<K> t0_ntt;
|
1467
|
+
matrix<K, L> a_ntt;
|
1468
|
+
vector<L> y;
|
1469
|
+
vector<K> w;
|
1470
|
+
vector<K> w1;
|
1471
|
+
vector<L> cs1;
|
1472
|
+
vector<K> cs2;
|
1437
1473
|
};
|
1438
|
-
|
1474
|
+
std::unique_ptr<values_st, DeleterFree<values_st>> values(
|
1475
|
+
reinterpret_cast<struct values_st *>(OPENSSL_malloc(sizeof(values_st))));
|
1439
1476
|
if (values == NULL) {
|
1440
|
-
|
1477
|
+
return 0;
|
1441
1478
|
}
|
1442
1479
|
OPENSSL_memcpy(&values->s1_ntt, &priv->s1, sizeof(values->s1_ntt));
|
1443
|
-
|
1480
|
+
vector_ntt(&values->s1_ntt);
|
1444
1481
|
|
1445
1482
|
OPENSSL_memcpy(&values->s2_ntt, &priv->s2, sizeof(values->s2_ntt));
|
1446
|
-
|
1483
|
+
vector_ntt(&values->s2_ntt);
|
1447
1484
|
|
1448
1485
|
OPENSSL_memcpy(&values->t0_ntt, &priv->t0, sizeof(values->t0_ntt));
|
1449
|
-
|
1486
|
+
vector_ntt(&values->t0_ntt);
|
1450
1487
|
|
1451
1488
|
matrix_expand(&values->a_ntt, priv->rho);
|
1452
1489
|
|
1453
|
-
// kappa must not exceed 2**16/L = 13107. But the probability of it
|
1454
|
-
// even 1000 iterations is vanishingly small.
|
1490
|
+
// kappa must not exceed 2**16/L = 13107. But the probability of it
|
1491
|
+
// exceeding even 1000 iterations is vanishingly small.
|
1455
1492
|
for (size_t kappa = 0;; kappa += L) {
|
1456
|
-
|
1493
|
+
vector_expand_mask(&values->y, rho_prime, kappa);
|
1457
1494
|
|
1458
|
-
|
1495
|
+
vector<L> *y_ntt = &values->cs1;
|
1459
1496
|
OPENSSL_memcpy(y_ntt, &values->y, sizeof(*y_ntt));
|
1460
|
-
|
1497
|
+
vector_ntt(y_ntt);
|
1461
1498
|
|
1462
1499
|
matrix_mult(&values->w, &values->a_ntt, y_ntt);
|
1463
|
-
|
1500
|
+
vector_inverse_ntt(&values->w);
|
1464
1501
|
|
1465
|
-
|
1502
|
+
vector_high_bits(&values->w1, &values->w);
|
1466
1503
|
uint8_t w1_encoded[128 * K];
|
1467
1504
|
w1_encode(w1_encoded, &values->w1);
|
1468
1505
|
|
1469
1506
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
1470
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, mu,
|
1507
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
1471
1508
|
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded, 128 * K);
|
1472
1509
|
BORINGSSL_keccak_squeeze(&keccak_ctx, values->sign.c_tilde,
|
1473
|
-
2 *
|
1510
|
+
2 * lambda_bytes<K>());
|
1474
1511
|
|
1475
1512
|
scalar c_ntt;
|
1476
1513
|
scalar_sample_in_ball_vartime(&c_ntt, values->sign.c_tilde,
|
1477
|
-
sizeof(values->sign.c_tilde));
|
1514
|
+
sizeof(values->sign.c_tilde), tau<K>());
|
1478
1515
|
scalar_ntt(&c_ntt);
|
1479
1516
|
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1517
|
+
vector_mult_scalar(&values->cs1, &values->s1_ntt, &c_ntt);
|
1518
|
+
vector_inverse_ntt(&values->cs1);
|
1519
|
+
vector_mult_scalar(&values->cs2, &values->s2_ntt, &c_ntt);
|
1520
|
+
vector_inverse_ntt(&values->cs2);
|
1484
1521
|
|
1485
|
-
|
1522
|
+
vector_add(&values->sign.z, &values->y, &values->cs1);
|
1486
1523
|
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1524
|
+
vector<K> *r0 = &values->w1;
|
1525
|
+
vector_sub(r0, &values->w, &values->cs2);
|
1526
|
+
vector_low_bits(r0, r0);
|
1490
1527
|
|
1491
1528
|
// Leaking the fact that a signature was rejected is fine as the next
|
1492
1529
|
// attempt at a signature will be (indistinguishable from) independent of
|
@@ -1494,27 +1531,27 @@ int MLDSA65_sign_internal(
|
|
1494
1531
|
// branches rejected the signature. Section 5.5 of
|
1495
1532
|
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3.pdf
|
1496
1533
|
// describes this leak as OK. Note we leak less than what is described by
|
1497
|
-
// the paper; we do not reveal which coefficient violated the bound, and
|
1498
|
-
// hide which of the |z_max| or |r0_max| bound failed. See also
|
1534
|
+
// the paper; we do not reveal which coefficient violated the bound, and
|
1535
|
+
// we hide which of the |z_max| or |r0_max| bound failed. See also
|
1499
1536
|
// https://boringssl-review.googlesource.com/c/boringssl/+/67747/comment/2bbab0fa_d241d35a/
|
1500
|
-
uint32_t z_max =
|
1501
|
-
uint32_t r0_max =
|
1537
|
+
uint32_t z_max = vector_max(&values->sign.z);
|
1538
|
+
uint32_t r0_max = vector_max_signed(r0);
|
1502
1539
|
if (constant_time_declassify_w(
|
1503
|
-
constant_time_ge_w(z_max,
|
1504
|
-
constant_time_ge_w(r0_max, kGamma2 -
|
1540
|
+
constant_time_ge_w(z_max, gamma1<K>() - beta<K>()) |
|
1541
|
+
constant_time_ge_w(r0_max, kGamma2 - beta<K>()))) {
|
1505
1542
|
continue;
|
1506
1543
|
}
|
1507
1544
|
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1545
|
+
vector<K> *ct0 = &values->w1;
|
1546
|
+
vector_mult_scalar(ct0, &values->t0_ntt, &c_ntt);
|
1547
|
+
vector_inverse_ntt(ct0);
|
1548
|
+
vector_make_hint(&values->sign.h, ct0, &values->cs2, &values->w);
|
1512
1549
|
|
1513
1550
|
// See above.
|
1514
|
-
uint32_t ct0_max =
|
1515
|
-
size_t h_ones =
|
1551
|
+
uint32_t ct0_max = vector_max(ct0);
|
1552
|
+
size_t h_ones = vector_count_ones(&values->sign.h);
|
1516
1553
|
if (constant_time_declassify_w(constant_time_ge_w(ct0_max, kGamma2) |
|
1517
|
-
constant_time_lt_w(
|
1554
|
+
constant_time_lt_w(omega<K>(), h_ones))) {
|
1518
1555
|
continue;
|
1519
1556
|
}
|
1520
1557
|
|
@@ -1524,88 +1561,47 @@ int MLDSA65_sign_internal(
|
|
1524
1561
|
CONSTTIME_DECLASSIFY(&values->sign.h, sizeof(values->sign.h));
|
1525
1562
|
|
1526
1563
|
CBB cbb;
|
1527
|
-
CBB_init_fixed(&cbb, out_encoded_signature,
|
1564
|
+
CBB_init_fixed(&cbb, out_encoded_signature, signature_bytes<K>());
|
1528
1565
|
if (!mldsa_marshal_signature(&cbb, &values->sign)) {
|
1529
|
-
|
1566
|
+
return 0;
|
1530
1567
|
}
|
1531
1568
|
|
1532
|
-
BSSL_CHECK(CBB_len(&cbb) ==
|
1533
|
-
|
1534
|
-
break;
|
1535
|
-
}
|
1536
|
-
|
1537
|
-
err:
|
1538
|
-
OPENSSL_free(values);
|
1539
|
-
return ret;
|
1540
|
-
}
|
1541
|
-
|
1542
|
-
// mldsa signature in randomized mode, filling the random bytes with
|
1543
|
-
// |RAND_bytes|. Returns 1 on success and 0 on failure.
|
1544
|
-
int MLDSA65_sign(uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
1545
|
-
const struct MLDSA65_private_key *private_key,
|
1546
|
-
const uint8_t *msg, size_t msg_len, const uint8_t *context,
|
1547
|
-
size_t context_len) {
|
1548
|
-
if (context_len > 255) {
|
1549
|
-
return 0;
|
1550
|
-
}
|
1551
|
-
|
1552
|
-
uint8_t randomizer[MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
1553
|
-
RAND_bytes(randomizer, sizeof(randomizer));
|
1554
|
-
|
1555
|
-
const uint8_t context_prefix[2] = {0, context_len};
|
1556
|
-
return MLDSA65_sign_internal(out_encoded_signature, private_key, msg, msg_len,
|
1557
|
-
context_prefix, sizeof(context_prefix), context,
|
1558
|
-
context_len, randomizer);
|
1559
|
-
}
|
1560
|
-
|
1561
|
-
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
1562
|
-
int MLDSA65_verify(const struct MLDSA65_public_key *public_key,
|
1563
|
-
const uint8_t *signature, size_t signature_len,
|
1564
|
-
const uint8_t *msg, size_t msg_len, const uint8_t *context,
|
1565
|
-
size_t context_len) {
|
1566
|
-
if (context_len > 255 || signature_len != MLDSA65_SIGNATURE_BYTES) {
|
1567
|
-
return 0;
|
1569
|
+
BSSL_CHECK(CBB_len(&cbb) == signature_bytes<K>());
|
1570
|
+
return 1;
|
1568
1571
|
}
|
1569
|
-
|
1570
|
-
const uint8_t context_prefix[2] = {0, context_len};
|
1571
|
-
return MLDSA65_verify_internal(public_key, signature, msg, msg_len,
|
1572
|
-
context_prefix, sizeof(context_prefix),
|
1573
|
-
context, context_len);
|
1574
1572
|
}
|
1575
1573
|
|
1576
1574
|
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`).
|
1577
|
-
int
|
1578
|
-
|
1579
|
-
const
|
1580
|
-
const uint8_t
|
1581
|
-
size_t
|
1582
|
-
|
1583
|
-
|
1575
|
+
template <int K, int L>
|
1576
|
+
static int mldsa_verify_internal(
|
1577
|
+
const struct public_key<K> *pub,
|
1578
|
+
const uint8_t encoded_signature[signature_bytes<K>()], const uint8_t *msg,
|
1579
|
+
size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len,
|
1580
|
+
const uint8_t *context, size_t context_len) {
|
1584
1581
|
// Intermediate values, allocated on the heap to allow use when there is a
|
1585
1582
|
// limited amount of stack.
|
1586
1583
|
struct values_st {
|
1587
|
-
struct signature sign;
|
1588
|
-
matrix a_ntt;
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1584
|
+
struct signature<K, L> sign;
|
1585
|
+
matrix<K, L> a_ntt;
|
1586
|
+
vector<L> z_ntt;
|
1587
|
+
vector<K> az_ntt;
|
1588
|
+
vector<K> ct1_ntt;
|
1592
1589
|
};
|
1593
|
-
|
1590
|
+
std::unique_ptr<values_st, DeleterFree<values_st>> values(
|
1591
|
+
reinterpret_cast<struct values_st *>(OPENSSL_malloc(sizeof(values_st))));
|
1594
1592
|
if (values == NULL) {
|
1595
|
-
|
1593
|
+
return 0;
|
1596
1594
|
}
|
1597
1595
|
|
1598
|
-
const struct public_key *pub = public_key_from_external(public_key);
|
1599
|
-
|
1600
1596
|
CBS cbs;
|
1601
|
-
CBS_init(&cbs, encoded_signature,
|
1597
|
+
CBS_init(&cbs, encoded_signature, signature_bytes<K>());
|
1602
1598
|
if (!mldsa_parse_signature(&values->sign, &cbs)) {
|
1603
|
-
|
1599
|
+
return 0;
|
1604
1600
|
}
|
1605
1601
|
|
1606
1602
|
matrix_expand(&values->a_ntt, pub->rho);
|
1607
1603
|
|
1608
|
-
uint8_t mu[
|
1604
|
+
uint8_t mu[kMuBytes];
|
1609
1605
|
struct BORINGSSL_keccak_st keccak_ctx;
|
1610
1606
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
1611
1607
|
BORINGSSL_keccak_absorb(&keccak_ctx, pub->public_key_hash,
|
@@ -1613,75 +1609,182 @@ int MLDSA65_verify_internal(
|
|
1613
1609
|
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
1614
1610
|
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
1615
1611
|
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
1616
|
-
BORINGSSL_keccak_squeeze(&keccak_ctx, mu,
|
1612
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
1617
1613
|
|
1618
1614
|
scalar c_ntt;
|
1619
1615
|
scalar_sample_in_ball_vartime(&c_ntt, values->sign.c_tilde,
|
1620
|
-
sizeof(values->sign.c_tilde));
|
1616
|
+
sizeof(values->sign.c_tilde), tau<K>());
|
1621
1617
|
scalar_ntt(&c_ntt);
|
1622
1618
|
|
1623
1619
|
OPENSSL_memcpy(&values->z_ntt, &values->sign.z, sizeof(values->z_ntt));
|
1624
|
-
|
1620
|
+
vector_ntt(&values->z_ntt);
|
1625
1621
|
|
1626
1622
|
matrix_mult(&values->az_ntt, &values->a_ntt, &values->z_ntt);
|
1627
1623
|
|
1628
|
-
|
1629
|
-
|
1624
|
+
vector_scale_power2_round(&values->ct1_ntt, &pub->t1);
|
1625
|
+
vector_ntt(&values->ct1_ntt);
|
1630
1626
|
|
1631
|
-
|
1627
|
+
vector_mult_scalar(&values->ct1_ntt, &values->ct1_ntt, &c_ntt);
|
1632
1628
|
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1629
|
+
vector<K> *const w1 = &values->az_ntt;
|
1630
|
+
vector_sub(w1, &values->az_ntt, &values->ct1_ntt);
|
1631
|
+
vector_inverse_ntt(w1);
|
1636
1632
|
|
1637
|
-
|
1633
|
+
vector_use_hint_vartime(w1, &values->sign.h, w1);
|
1638
1634
|
uint8_t w1_encoded[128 * K];
|
1639
1635
|
w1_encode(w1_encoded, w1);
|
1640
1636
|
|
1641
|
-
uint8_t c_tilde[2 *
|
1637
|
+
uint8_t c_tilde[2 * lambda_bytes<K>()];
|
1642
1638
|
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
1643
|
-
BORINGSSL_keccak_absorb(&keccak_ctx, mu,
|
1639
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
1644
1640
|
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded, 128 * K);
|
1645
|
-
BORINGSSL_keccak_squeeze(&keccak_ctx, c_tilde, 2 *
|
1646
|
-
|
1647
|
-
uint32_t z_max = vectorl_max(&values->sign.z);
|
1648
|
-
if (z_max < kGamma1 - BETA &&
|
1649
|
-
OPENSSL_memcmp(c_tilde, values->sign.c_tilde, 2 * LAMBDA_BYTES) == 0) {
|
1650
|
-
ret = 1;
|
1651
|
-
}
|
1641
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, c_tilde, 2 * lambda_bytes<K>());
|
1652
1642
|
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1643
|
+
uint32_t z_max = vector_max(&values->sign.z);
|
1644
|
+
return z_max < static_cast<uint32_t>(gamma1<K>() - beta<K>()) &&
|
1645
|
+
OPENSSL_memcmp(c_tilde, values->sign.c_tilde, 2 * lambda_bytes<K>()) ==
|
1646
|
+
0;
|
1656
1647
|
}
|
1657
1648
|
|
1658
|
-
|
1649
|
+
} // namespace
|
1659
1650
|
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1651
|
+
// ML-DSA-65 specific wrappers.
|
1652
|
+
|
1653
|
+
static struct private_key<6, 5> *mldsa65_private_key_from_external(
|
1654
|
+
const struct MLDSA65_private_key *external) {
|
1655
|
+
static_assert(sizeof(struct MLDSA65_private_key) ==
|
1656
|
+
sizeof(struct private_key<6, 5>),
|
1657
|
+
"MLDSA65 private key size incorrect");
|
1658
|
+
static_assert(alignof(struct MLDSA65_private_key) ==
|
1659
|
+
alignof(struct private_key<6, 5>),
|
1660
|
+
"MLDSA65 private key align incorrect");
|
1661
|
+
return (struct private_key<6, 5> *)external;
|
1662
|
+
}
|
1663
|
+
|
1664
|
+
static struct public_key<6> *
|
1665
|
+
mldsa65_public_key_from_external(const struct MLDSA65_public_key *external) {
|
1666
|
+
static_assert(sizeof(struct MLDSA65_public_key) ==
|
1667
|
+
sizeof(struct public_key<6>),
|
1668
|
+
"MLDSA65 public key size incorrect");
|
1669
|
+
static_assert(alignof(struct MLDSA65_public_key) ==
|
1670
|
+
alignof(struct public_key<6>),
|
1671
|
+
"MLDSA65 public key align incorrect");
|
1672
|
+
return (struct public_key<6> *)external;
|
1663
1673
|
}
|
1664
1674
|
|
1665
1675
|
int MLDSA65_parse_public_key(struct MLDSA65_public_key *public_key, CBS *in) {
|
1666
|
-
|
1667
|
-
|
1668
|
-
if (!mldsa_parse_public_key(pub, in) || CBS_len(in) != 0) {
|
1669
|
-
return 0;
|
1670
|
-
}
|
1671
|
-
|
1672
|
-
// Compute pre-cached values.
|
1673
|
-
BORINGSSL_keccak(pub->public_key_hash, sizeof(pub->public_key_hash),
|
1674
|
-
CBS_data(&orig_in), CBS_len(&orig_in), boringssl_shake256);
|
1675
|
-
return 1;
|
1676
|
+
return mldsa_parse_public_key(mldsa65_public_key_from_external(public_key),
|
1677
|
+
in);
|
1676
1678
|
}
|
1677
1679
|
|
1678
1680
|
int MLDSA65_marshal_private_key(CBB *out,
|
1679
1681
|
const struct MLDSA65_private_key *private_key) {
|
1680
|
-
return mldsa_marshal_private_key(
|
1682
|
+
return mldsa_marshal_private_key(
|
1683
|
+
out, mldsa65_private_key_from_external(private_key));
|
1681
1684
|
}
|
1682
1685
|
|
1683
1686
|
int MLDSA65_parse_private_key(struct MLDSA65_private_key *private_key,
|
1684
1687
|
CBS *in) {
|
1685
|
-
|
1686
|
-
|
1688
|
+
return mldsa_parse_private_key(mldsa65_private_key_from_external(private_key),
|
1689
|
+
in) &&
|
1690
|
+
CBS_len(in) == 0;
|
1691
|
+
}
|
1692
|
+
|
1693
|
+
// Calls |MLDSA_generate_key_external_entropy| with random bytes from
|
1694
|
+
// |RAND_bytes|. Returns 1 on success and 0 on failure.
|
1695
|
+
int MLDSA65_generate_key(
|
1696
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
1697
|
+
uint8_t out_seed[MLDSA_SEED_BYTES],
|
1698
|
+
struct MLDSA65_private_key *out_private_key) {
|
1699
|
+
RAND_bytes(out_seed, MLDSA_SEED_BYTES);
|
1700
|
+
return MLDSA65_generate_key_external_entropy(out_encoded_public_key,
|
1701
|
+
out_private_key, out_seed);
|
1702
|
+
}
|
1703
|
+
|
1704
|
+
int MLDSA65_private_key_from_seed(struct MLDSA65_private_key *out_private_key,
|
1705
|
+
const uint8_t *seed, size_t seed_len) {
|
1706
|
+
if (seed_len != MLDSA_SEED_BYTES) {
|
1707
|
+
return 0;
|
1708
|
+
}
|
1709
|
+
uint8_t public_key[MLDSA65_PUBLIC_KEY_BYTES];
|
1710
|
+
return MLDSA65_generate_key_external_entropy(public_key, out_private_key,
|
1711
|
+
seed);
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
int MLDSA65_generate_key_external_entropy(
|
1715
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
1716
|
+
struct MLDSA65_private_key *out_private_key,
|
1717
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
1718
|
+
return mldsa_generate_key_external_entropy(
|
1719
|
+
out_encoded_public_key,
|
1720
|
+
mldsa65_private_key_from_external(out_private_key), entropy);
|
1721
|
+
}
|
1722
|
+
|
1723
|
+
int MLDSA65_public_from_private(struct MLDSA65_public_key *out_public_key,
|
1724
|
+
const struct MLDSA65_private_key *private_key) {
|
1725
|
+
return mldsa_public_from_private(
|
1726
|
+
mldsa65_public_key_from_external(out_public_key),
|
1727
|
+
mldsa65_private_key_from_external(private_key));
|
1728
|
+
}
|
1729
|
+
|
1730
|
+
int MLDSA65_sign_internal(
|
1731
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
1732
|
+
const struct MLDSA65_private_key *private_key, const uint8_t *msg,
|
1733
|
+
size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len,
|
1734
|
+
const uint8_t *context, size_t context_len,
|
1735
|
+
const uint8_t randomizer[MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
1736
|
+
return mldsa_sign_internal(out_encoded_signature,
|
1737
|
+
mldsa65_private_key_from_external(private_key),
|
1738
|
+
msg, msg_len, context_prefix, context_prefix_len,
|
1739
|
+
context, context_len, randomizer);
|
1740
|
+
}
|
1741
|
+
|
1742
|
+
// ML-DSA signature in randomized mode, filling the random bytes with
|
1743
|
+
// |RAND_bytes|. Returns 1 on success and 0 on failure.
|
1744
|
+
int MLDSA65_sign(uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
1745
|
+
const struct MLDSA65_private_key *private_key,
|
1746
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context,
|
1747
|
+
size_t context_len) {
|
1748
|
+
if (context_len > 255) {
|
1749
|
+
return 0;
|
1750
|
+
}
|
1751
|
+
|
1752
|
+
uint8_t randomizer[MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
1753
|
+
RAND_bytes(randomizer, sizeof(randomizer));
|
1754
|
+
|
1755
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
1756
|
+
return MLDSA65_sign_internal(out_encoded_signature, private_key, msg, msg_len,
|
1757
|
+
context_prefix, sizeof(context_prefix), context,
|
1758
|
+
context_len, randomizer);
|
1759
|
+
}
|
1760
|
+
|
1761
|
+
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
1762
|
+
int MLDSA65_verify(const struct MLDSA65_public_key *public_key,
|
1763
|
+
const uint8_t *signature, size_t signature_len,
|
1764
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context,
|
1765
|
+
size_t context_len) {
|
1766
|
+
if (context_len > 255 || signature_len != MLDSA65_SIGNATURE_BYTES) {
|
1767
|
+
return 0;
|
1768
|
+
}
|
1769
|
+
|
1770
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
1771
|
+
return MLDSA65_verify_internal(public_key, signature, msg, msg_len,
|
1772
|
+
context_prefix, sizeof(context_prefix),
|
1773
|
+
context, context_len);
|
1774
|
+
}
|
1775
|
+
|
1776
|
+
int MLDSA65_verify_internal(
|
1777
|
+
const struct MLDSA65_public_key *public_key,
|
1778
|
+
const uint8_t encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
1779
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
1780
|
+
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
1781
|
+
return mldsa_verify_internal<6, 5>(
|
1782
|
+
mldsa65_public_key_from_external(public_key), encoded_signature, msg,
|
1783
|
+
msg_len, context_prefix, context_prefix_len, context, context_len);
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
int MLDSA65_marshal_public_key(CBB *out,
|
1787
|
+
const struct MLDSA65_public_key *public_key) {
|
1788
|
+
return mldsa_marshal_public_key(out,
|
1789
|
+
mldsa65_public_key_from_external(public_key));
|
1687
1790
|
}
|