Skip to content

Commit a611b27

Browse files
committed
Update docs.
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 49d8206 commit a611b27

File tree

2 files changed

+82
-82
lines changed

2 files changed

+82
-82
lines changed

doc/crypt.tex

+62-56
Original file line numberDiff line numberDiff line change
@@ -5809,91 +5809,97 @@ \subsection{Signature Generation}
58095809

58105810
\index{ecc\_sign\_hash()}
58115811
\begin{verbatim}
5812-
int ecc_sign_hash(const unsigned char *in,
5813-
unsigned long inlen,
5814-
unsigned char *out,
5815-
unsigned long *outlen,
5816-
prng_state *prng,
5817-
int wprng,
5818-
ecc_key *key);
5812+
int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
5813+
unsigned char *out, unsigned long *outlen,
5814+
prng_state *prng, int wprng, const ecc_key *key);
58195815
\end{verbatim}
58205816

5821-
This function will ECDSA sign the message digest stored in the array pointed to by \textit{in} of length \textit{inlen} octets. The signature
5822-
will be stored in the array pointed to by \textit{out} of length \textit{outlen} octets. The function requires a properly seeded PRNG, and
5823-
the ECC \textit{key} provided must be a private key.
5817+
This function will ECDSA sign the message digest stored in the array pointed to by \texttt{in} of length \texttt{inlen} octets. The signature
5818+
will be stored in the array pointed to by \texttt{out} of length \texttt{outlen} octets. The function requires a properly seeded PRNG, and
5819+
the ECC \texttt{key} provided must be a private key.
58245820

58255821
\index{ecc\_sign\_hash\_rfc7518()}
58265822
\begin{verbatim}
5827-
int ecc_sign_hash_rfc7518(const unsigned char *in,
5828-
unsigned long inlen,
5829-
unsigned char *out,
5830-
unsigned long *outlen,
5831-
prng_state *prng,
5832-
int wprng,
5833-
ecc_key *key);
5823+
int ecc_sign_hash_rfc7518(const unsigned char *in, unsigned long inlen,
5824+
unsigned char *out, unsigned long *outlen,
5825+
prng_state *prng, int wprng, const ecc_key *key);
58345826
\end{verbatim}
58355827

5836-
This function creates the same ECDSA signature as \textit{ecc\_sign\_hash} only the output format is different.
5828+
This function creates the same ECDSA signature as \texttt{ecc\_sign\_hash()} only the output format is different.
58375829
The format follows \url{https://tools.ietf.org/html/rfc7518#section-3.4}, sometimes it is also called plain signature.
58385830

5839-
\index{ecc\_sign\_hash\_ex()}
5831+
\index{ecc\_sign\_hash\_rfc7518\_ex()}
58405832
\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);
5833+
int ecc_sign_hash_rfc7518_ex(const unsigned char *in, unsigned long inlen,
5834+
unsigned char *out, unsigned long *outlen,
5835+
prng_state *prng, int wprng,
5836+
int *recid, const ecc_key *key);
5837+
\end{verbatim}
5838+
5839+
This function is an extended version of the ECDSA signature in \texttt{ecc\_sign\_hash\_rfc7518()}, but with an additional output of the recovery ID
5840+
for use with \texttt{ecc\_recover\_key()}.
5841+
5842+
\index{ecc\_sign\_hash\_rfc5656()}
5843+
\begin{verbatim}
5844+
int ecc_sign_hash_rfc5656(const unsigned char *in, unsigned long inlen,
5845+
unsigned char *out, unsigned long *outlen,
5846+
prng_state *prng, int wprng, const ecc_key *key);
58505847
\end{verbatim}
58515848

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}.
5849+
This function creates an ECDSA signature and the output format is according to RFC5656, i.e. SSH compatible.
5850+
5851+
\index{ecc\_sign\_hash\_eth27()}
5852+
\begin{verbatim}
5853+
int ecc_sign_hash_eth27(const unsigned char *in, unsigned long inlen,
5854+
unsigned char *out, unsigned long *outlen,
5855+
prng_state *prng, int wprng, const ecc_key *key);
5856+
\end{verbatim}
5857+
5858+
This function creates an ECDSA signature and the output format is according to the Ethereum format.
5859+
With this API the curve is limited to secp256k1.
58545860

58555861
\subsection{Signature Verification}
58565862
\index{ecc\_verify\_hash()}
58575863
\begin{verbatim}
5858-
int ecc_verify_hash(const unsigned char *sig,
5859-
unsigned long siglen,
5860-
const unsigned char *hash,
5861-
unsigned long hashlen,
5862-
int *stat,
5863-
ecc_key *key);
5864+
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
5865+
const unsigned char *hash, unsigned long hashlen,
5866+
int *stat, const ecc_key *key);
58645867
\end{verbatim}
58655868

5866-
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:
5869+
This function will verify the ECDSA signature in the array pointed to by \texttt{sig} of length \texttt{siglen} octets, against the message digest
5870+
pointed to by the array \texttt{hash} of length \texttt{hashlen}. It will store a non--zero value in \texttt{stat} if the signature is valid. Note:
58685871
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.
5872+
The ECC \texttt{key} must be the public (or private) ECC key corresponding to the key that performed the signature.
5873+
The function \texttt{ecc\_verify\_hash()} implements signature format according to X9.62 ECDSA, and the output is compliant for GF(p) curves.
58715874

58725875
\index{ecc\_verify\_hash\_rfc7518()}
58735876
\begin{verbatim}
5874-
int ecc_verify_hash_rfc7518(const unsigned char *sig,
5875-
unsigned long siglen,
5876-
const unsigned char *hash,
5877-
unsigned long hashlen,
5878-
int *stat,
5879-
ecc_key *key);
5877+
int ecc_verify_hash_rfc7518(const unsigned char *sig, unsigned long siglen,
5878+
const unsigned char *hash, unsigned long hashlen,
5879+
int *stat, const ecc_key *key);
58805880
\end{verbatim}
58815881

5882-
This function validate the ECDSA signature as \textit{ecc\_verify\_hash} only the signature input format
5882+
This function validate the ECDSA signature as \texttt{ecc\_verify\_hash()} only the signature input format
58835883
follows \url{https://tools.ietf.org/html/rfc7518#section-3.4}.
58845884

5885-
\index{ecc\_verify\_hash\_ex()}
5885+
\index{ecc\_verify\_hash\_rfc5656()}
58865886
\begin{verbatim}
5887-
int ecc_verify_hash_ex(const unsigned char *sig,
5888-
unsigned long siglen,
5889-
const unsigned char *hash,
5890-
unsigned long hashlen,
5891-
ecc_signature_type sigformat,
5892-
int *stat,
5893-
ecc_key *key);
5887+
int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
5888+
const unsigned char *hash, unsigned long hashlen,
5889+
int *stat, const ecc_key *key);
5890+
\end{verbatim}
5891+
5892+
This function validates the ECDSA signature according to the format defined in RFC5656, i.e. SSH compatible.
5893+
5894+
5895+
\index{ecc\_verify\_hash\_eth27()}
5896+
\begin{verbatim}
5897+
int ecc_verify_hash_eth27(const unsigned char *sig, unsigned long siglen,
5898+
const unsigned char *hash, unsigned long hashlen,
5899+
int *stat, const ecc_key *key);
58945900
\end{verbatim}
58955901

5896-
This function validates an ECDSA signature as \textit{ecc\_verify\_hash} but with a choice of signature formats.
5902+
This function validates the ECDSA signature according to the Ethereum format.
58975903

58985904
{\bf BEWARE:} With ECC if you try to sign a hash that is bigger than your ECC key you can run into problems. The math
58995905
will still work, and in effect the signature will still work. With ECC keys the strength of the signature is limited

src/headers/tomcrypt_pk.h

+20-26
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,17 @@ void ecc_free(ecc_key *key);
316316
int ecc_export(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
317317
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
318318
int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
319-
#endif
320-
321-
int ecc_ansi_x963_export(const ecc_key *key, unsigned char *out, unsigned long *outlen);
322-
int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
323-
int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
324319

325-
#if defined(LTC_DER)
326-
int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
327-
int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *key);
328-
int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, const password_ctx *pw_ctx, ecc_key *key);
329-
int ecc_import_x509(const unsigned char *in, unsigned long inlen, ecc_key *key);
320+
int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
321+
int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *key);
322+
int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, const password_ctx *pw_ctx, ecc_key *key);
323+
int ecc_import_x509(const unsigned char *in, unsigned long inlen, ecc_key *key);
330324
#endif
331325

326+
int ecc_ansi_x963_export(const ecc_key *key, unsigned char *out, unsigned long *outlen);
327+
int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
328+
int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
329+
332330
int ecc_shared_secret(const ecc_key *private_key, const ecc_key *public_key,
333331
unsigned char *out, unsigned long *outlen);
334332

@@ -345,6 +343,10 @@ int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
345343
int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
346344
unsigned char *out, unsigned long *outlen,
347345
prng_state *prng, int wprng, const ecc_key *key);
346+
347+
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
348+
const unsigned char *hash, unsigned long hashlen,
349+
int *stat, const ecc_key *key);
348350
#endif
349351

350352
int ecc_sign_hash_rfc7518(const unsigned char *in, unsigned long inlen,
@@ -356,32 +358,24 @@ int ecc_sign_hash_rfc7518_ex(const unsigned char *in, unsigned long inlen,
356358
prng_state *prng, int wprng,
357359
int *recid, const ecc_key *key);
358360

359-
#if defined(LTC_SSH)
360-
int ecc_sign_hash_rfc5656(const unsigned char *in, unsigned long inlen,
361-
unsigned char *out, unsigned long *outlen,
362-
prng_state *prng, int wprng, const ecc_key *key);
363-
#endif
364-
365-
int ecc_sign_hash_eth27(const unsigned char *in, unsigned long inlen,
366-
unsigned char *out, unsigned long *outlen,
367-
prng_state *prng, int wprng, const ecc_key *key);
368-
369-
#if defined(LTC_DER)
370-
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
371-
const unsigned char *hash, unsigned long hashlen,
372-
int *stat, const ecc_key *key);
373-
#endif
374-
375361
int ecc_verify_hash_rfc7518(const unsigned char *sig, unsigned long siglen,
376362
const unsigned char *hash, unsigned long hashlen,
377363
int *stat, const ecc_key *key);
378364

379365
#if defined(LTC_SSH)
366+
int ecc_sign_hash_rfc5656(const unsigned char *in, unsigned long inlen,
367+
unsigned char *out, unsigned long *outlen,
368+
prng_state *prng, int wprng, const ecc_key *key);
369+
380370
int ecc_verify_hash_rfc5656(const unsigned char *sig, unsigned long siglen,
381371
const unsigned char *hash, unsigned long hashlen,
382372
int *stat, const ecc_key *key);
383373
#endif
384374

375+
int ecc_sign_hash_eth27(const unsigned char *in, unsigned long inlen,
376+
unsigned char *out, unsigned long *outlen,
377+
prng_state *prng, int wprng, const ecc_key *key);
378+
385379
int ecc_verify_hash_eth27(const unsigned char *sig, unsigned long siglen,
386380
const unsigned char *hash, unsigned long hashlen,
387381
int *stat, const ecc_key *key);

0 commit comments

Comments
 (0)