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
There are also functions to sign and verify messages. They use the ANSI X9.62 ECDSA algorithm to generate and verify signatures in the
5805
-
ANSI X9.62 format.
5806
+
There are also functions to sign and verify messages. They use the \textit{ANSI X9.62} \textit{ECDSA} algorithm to generate and verify signatures in the
5807
+
\textit{ANSI X9.62} format.
5808
+
5809
+
\textbf{BEWARE:} With \textit{ECC} if you try to sign a hash that is bigger than your \textit{ECC} key you can run into problems. The math
5810
+
will still work, and in effect the signature will still work. With \textit{ECC} keys the strength of the signature is limited
5811
+
by the size of the hash, or the size of the key, whichever is smaller. For example, if you sign with SHA256 and a
5812
+
P--192 key, you have in effect 96--bits of security. The library will not warn you if you make this mistake, so it
5813
+
is important to check yourself before using the signatures.
5806
5814
5807
5815
\subsection{Signature Generation}
5808
5816
To sign a message digest (hash) use the following function:
This function creates the same ECDSA signature as \textit{ecc\_sign\_hash} only the output format is different.
5844
+
This function creates the same \textit{ECDSA} signature as \code{ecc\_sign\_hash()} only the output format is different.
5837
5845
The format follows \url{https://tools.ietf.org/html/rfc7518#section-3.4}, sometimes it is also called plain signature.
5838
5846
5839
-
\index{ecc\_sign\_hash\_ex()}
5847
+
\index{ecc\_sign\_hash\_rfc7518\_ex()}
5840
5848
\begin{verbatim}
5841
-
int ecc_sign_hash_ex(const unsigned char *in,
5842
-
unsigned long inlen,
5843
-
unsigned char *out,
5844
-
unsigned long *outlen,
5845
-
prng_state *prng,
5846
-
int wprng,
5847
-
ecc_signature_type sigformat,
5848
-
int *recid,
5849
-
ecc_key *key);
5849
+
int ecc_sign_hash_rfc7518_ex(const unsigned char *in,
5850
+
unsigned long inlen,
5851
+
unsigned char *out,
5852
+
unsigned long *outlen,
5853
+
prng_state *prng,
5854
+
int wprng,
5855
+
int *recid,
5856
+
const ecc_key *key);
5857
+
\end{verbatim}
5858
+
5859
+
This function is an extended version of the \textit{ECDSA} signature in \code{ecc\_sign\_hash\_rfc7518()}, but with an additional output of the recovery ID
5860
+
for use with \code{ecc\_recover\_key()}.
5861
+
5862
+
\index{ecc\_sign\_hash\_rfc5656()}
5863
+
\begin{verbatim}
5864
+
int ecc_sign_hash_rfc5656(const unsigned char *in,
5865
+
unsigned long inlen,
5866
+
unsigned char *out,
5867
+
unsigned long *outlen,
5868
+
prng_state *prng,
5869
+
int wprng,
5870
+
const ecc_key *key);
5871
+
\end{verbatim}
5872
+
5873
+
This function creates an \textit{ECDSA} signature and the output format is according to \textit{RFC5656}, i.e. \textit{SSH} compatible.
5874
+
5875
+
\index{ecc\_sign\_hash\_eth27()}
5876
+
\begin{verbatim}
5877
+
int ecc_sign_hash_eth27(const unsigned char *in,
5878
+
unsigned long inlen,
5879
+
unsigned char *out,
5880
+
unsigned long *outlen,
5881
+
prng_state *prng,
5882
+
int wprng,
5883
+
const ecc_key *key);
5850
5884
\end{verbatim}
5851
5885
5852
-
This function is an extended version of the ECDSA signature in \textit{ecc\_sign\_hash}, but with a choice of output formats
5853
-
and an optional output of the recovery ID for use with \textit{ecc\_recover\_key}.
5886
+
This function creates an \textit{ECDSA} signature and the output format is according to the Ethereum format.
5887
+
With this API the curve is limited to \textit{secp256k1}.
This function will verify the ECDSA signature in the array pointed to by \textit{sig} of length \textit{siglen} octets, against the message digest
5867
-
pointed to by the array \textit{hash} of length \textit{hashlen}. It will store a non--zero value in \textit{stat} if the signature is valid. Note:
5900
+
This function will verify the \textit{ECDSA} signature in the array pointed to by \code{sig} of length \code{siglen} octets, against the message digest
5901
+
pointed to by the array \code{hash} of length \code{hashlen}. It will store a non--zero value in \code{stat} if the signature is valid. Note:
5868
5902
the function will not return an error if the signature is invalid. It will return an error, if the actual signature payload is an invalid format.
5869
-
The ECC\textit{key} must be the public (or private) ECC key corresponding to the key that performed the signature.
5870
-
The function \textit{ecc\_verify\_hash} implements signature format according to X9.62 ECDSA, and the output is compliant for GF(p) curves.
5903
+
The \textit{ECC} \code{key} must be the public (or private) \textit{ECC} key corresponding to the key that performed the signature.
5904
+
The function \code{ecc\_verify\_hash()} implements signature format according to \textit{ANSI X9.62} EC\textit{DSA}, and the output is compliant for GF(p) curves.
This function will recover (a) public key from the ECDSA signature in the array pointed to by \textit{sig} of length \textit{siglen} octets, the message digest
5917
-
pointed to by the array \textit{hash} of length \textit{hashlen}, and the recovery id \textit{recid}. It will store the recovered
5918
-
key into \textit{key} and return CRYPT\_OK if recovery succeeds, or an error if recovery fails.
5956
+
This function will recover (a) public key from the \textit{ECDSA} signature in the array pointed to by \code{sig} of length \code{siglen} octets, the message digest
5957
+
pointed to by the array \code{hash} of length \code{hashlen}, and the recovery id \code{recid}. It will store the recovered
5958
+
key into \code{key} and return \code{CRYPT\_OK} if recovery succeeds, or an error if recovery fails.
5919
5959
This is for compatibility with the (v,r,s) signatures used in Ethereum, where public keys are not explicitly shared,
5920
-
only the parity of the public key. For curves like secp256k1, recid will take values of 0 or 1, corresponding to the
5921
-
parity of the public key's y coordinate. For curves like secp112r2, with a cofactor of 4, values 0..7 are possible,
5960
+
only the parity of the public key. For curves like \textit{secp256k1}, \code{recid} will take values of 0 or 1, corresponding to the
5961
+
parity of the public key's y coordinate. For curves like \textit{secp112r2}, with a cofactor of 4, values 0..7 are possible,
5922
5962
with the low bit corresponding to the parity and the higher bits specifying the public key's x coordinate's multiple
5923
5963
of the curve's order.
5924
-
If the signature format contains the recovery id (currently only \textit{LTC\_ECCSIG\_ETH27}), \textit{recid} can be -1
5964
+
If the signature format contains the recovery id (currently only \code{LTC\_ECCSIG\_ETH27}), \code{recid} can be -1
5925
5965
which signals that the recovery id from the signature blob should be used. This means an application does not need to
5926
5966
extract the recovery id from such a signature in order to use this function.
5927
-
The function \textit{ecc\_recover\_key} implements multiple signature formats, and the output is compliant for GF(p) curves.
5967
+
The function \code{ecc\_recover\_key()} implements multiple signature formats, and the output is compliant for GF(p) curves.
0 commit comments