You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the option to use \code{LTC\_ECCSIG\_ANSIX962}. Also it is possible to disable \code{LTC\_SSH} which will disable
6093
6094
the option to use \code{LTC\_ECCSIG\_RFC5656}.
6094
6095
6096
+
\mysection{Signatures (SM2)}
6097
+
The library also provides helpers for the \textit{SM2} signature scheme. In contrast to the hash-level \textit{ECDSA} API,
6098
+
these functions operate on the original message and the signer identifier (application-defined user ID bound into ZA). Internally they compute the SM2 message digest
6099
+
\textit{Hash(ZA || M)}, where \textit{ZA} is the SM2 digest of the signer identifier, curve parameters, and public key, and produce or verify a DER-encoded \textit{(r, s)} signature. Standard deployments typically use
6100
+
the built-in curve \texttt{sm2p256v1} together with the \textit{SM3} hash. These SM2 functions accept only keys on the built-in
6101
+
\texttt{sm2p256v1} curve.
6102
+
6103
+
\textbf{NOTE:} These functions require \code{LTC\_DER}.
6104
+
6105
+
\subsection{Signature Generation}
6106
+
\index{ecc\_sign\_sm2()}
6107
+
\begin{verbatim}
6108
+
int ecc_sign_sm2(const unsigned char *id, unsigned long idlen,
6109
+
const unsigned char *msg, unsigned long msglen,
6110
+
unsigned char *out, unsigned long *outlen,
6111
+
prng_state *prng, int wprng, int hash_idx,
6112
+
const ecc_key *key);
6113
+
\end{verbatim}
6114
+
6115
+
This function signs the message in \code{msg} of length \code{msglen} octets using the signer identifier (application-defined user ID bound into ZA) \code{id} of
6116
+
length \code{idlen} octets. The resulting DER-encoded signature is stored in \code{out}. The \code{hash\_idx} parameter
6117
+
selects the hash used for both \code{ZA} and the message digest. If \code{hash\_idx} is \code{-1}, the default \textit{SM3}
6118
+
hash is used. Other hashes are supported for compatibility and testing, but should only rarely be used in practice. The
6119
+
\code{key} must be a private ECC key on the built-in \texttt{sm2p256v1} curve.
6120
+
6121
+
\subsection{Signature Verification}
6122
+
\index{ecc\_verify\_sm2()}
6123
+
\begin{verbatim}
6124
+
int ecc_verify_sm2(const unsigned char *id, unsigned long idlen,
6125
+
const unsigned char *msg, unsigned long msglen,
6126
+
const unsigned char *sig, unsigned long siglen,
6127
+
int hash_idx, int *stat, const ecc_key *key);
6128
+
\end{verbatim}
6129
+
6130
+
This function verifies the DER-encoded signature in \code{sig} against the message in \code{msg} and the signer identifier
6131
+
(application-defined user ID bound into ZA) \code{id}. The same identifier and hash must be used as during signature generation. The result is stored in \code{stat},
6132
+
which is set to a non-zero value if the signature is valid. If \code{hash\_idx} is \code{-1}, the default \textit{SM3}
6133
+
hash is used. Other hashes are supported for compatibility and testing, but should only rarely be used in practice. The
6134
+
\code{key} must contain the corresponding public key (or the private key matching that public key) on the built-in
6135
+
\texttt{sm2p256v1} curve.
6136
+
6095
6137
\mysection{Shared Secret (ECDH)}
6096
6138
To construct a Diffie-Hellman shared secret with a private and public ECC key, use the following function:
0 commit comments