=pod

=head1 NAME

EVP_SIGNATURE-SM2 - The EVP_PKEY SM2 signature implementation.

=head1 DESCRIPTION

Support for computing SM2 signatures.
See L<EVP_PKEY-SM2(7)> for information related to SM2 keys.

This signature algorithm can be explicitly fetched with
L<EVP_PKEY_sign_init_ex2(3)>, and implicitly fetched (through L<SM2
keys|EVP_PKEY-SM2(7)>) with L<EVP_DigestSignInit_ex(3)> and
L<EVP_DigestVerifyInit_ex(3)>.

=head2 SM2 Signature Parameters

The following signature parameters can be set using
L<EVP_PKEY_CTX_set_params(3)>, L<EVP_DigestSignInit_ex(3)> or
L<EVP_DigestVerifyInit_ex(3)>.

=over 4

=item "digest" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <UTF8 string>

This defaults to the C<SM3> digest if not explicitly specified.

=item "digest-size" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <size_t>

This defaults to 32 bytes if not explicitly specified.
Digests of a different size are not supported with B<SM2>.

=item "distid" (B<OSSL_PKEY_PARAM_DIST_ID>) <UTF8 string>

The I<distinguishing identifier> defaults to C<1234567812345678> if not
explicitly specified.

An explicit empty distinguishing identifier value may need to be used to verify
or create signatures that are compatible with versions of OpenSSL prior to 4.0.
With the commandline tools an empty value can be specified with the use of
either the B<-pkeyopt> (L<openssl-pkeyutl(1)>) or B<-sigopt>
(L<openssl-dgst(1)>) option with a value of C<distid:>.

=item "tls-version" (B<OSSL_SIGNATURE_PARAM_TLS_VERSION>) <uint>

The OpenSSL 4.0 or later TLS protocol engine passes this parameter to the
underlying signature algorithm when signing or verifying TLS
B<CertificateVerify> messages.
When the protocol version is TLS 1.3 (0x0304), the SM2 signature algorithm will
use the RFC8998 I<distinguished identifier> instead of the default value noted
above.

=back

The following signature parameters can be retrieved using
EVP_PKEY_CTX_get_params().

=over 4

=item "algorithm-id" (B<OSSL_SIGNATURE_PARAM_ALGORITHM_ID>) <octet string>

This returns the DER encoding of the B<SM2-with-SM3> signature OID.

=item "digest" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <UTF8 string>

=item "digest-size" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <size_t>

=back

=head1 SEE ALSO

L<EVP_PKEY_CTX_set_params(3)>,
L<EVP_PKEY_sign(3)>,
L<EVP_PKEY_verify(3)>,
L<EVP_DigestSignInit_ex(3)>,
L<EVP_DigestVerifyInit_ex(3)>,
L<provider-signature(7)>,

=head1 HISTORY

The default value of the SM2 distinguishing identifier changed from empty to
C<1234567812345678> as of OpenSSL 4.0.

Support for the B<OSSL_SIGNATURE_PARAM_TLS_VERSION> parameter was added in
OpenSSL 4.0.

=head1 COPYRIGHT

Copyright 2020-2026 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License").  You may not use
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.

=cut
