--- /dev/null
+/**\r
+ * \file ecdsa.h\r
+ *\r
+ * \brief This file contains ECDSA definitions and functions.\r
+ *\r
+ * The Elliptic Curve Digital Signature Algorithm (ECDSA) is defined in\r
+ * <em>Standards for Efficient Cryptography Group (SECG):\r
+ * SEC1 Elliptic Curve Cryptography</em>.\r
+ * The use of ECDSA for TLS is defined in <em>RFC-4492: Elliptic Curve\r
+ * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.\r
+ *\r
+ */\r
+/*\r
+ * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may\r
+ * not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * This file is part of Mbed TLS (https://tls.mbed.org)\r
+ */\r
+\r
+#ifndef MBEDTLS_ECDSA_H\r
+#define MBEDTLS_ECDSA_H\r
+\r
+#if !defined(MBEDTLS_CONFIG_FILE)\r
+#include "config.h"\r
+#else\r
+#include MBEDTLS_CONFIG_FILE\r
+#endif\r
+\r
+#include "ecp.h"\r
+#include "md.h"\r
+\r
+/**\r
+ * \brief Maximum ECDSA signature size for a given curve bit size\r
+ *\r
+ * \param bits Curve size in bits\r
+ * \return Maximum signature size in bytes\r
+ *\r
+ * \note This macro returns a compile-time constant if its argument\r
+ * is one. It may evaluate its argument multiple times.\r
+ */\r
+/*\r
+ * Ecdsa-Sig-Value ::= SEQUENCE {\r
+ * r INTEGER,\r
+ * s INTEGER\r
+ * }\r
+ *\r
+ * For each of r and s, the value (V) may include an extra initial "0" bit.\r
+ */\r
+#define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \\r
+ ( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \\r
+ /*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \\r
+ /*V of r,s*/ ( ( bits ) + 8 ) / 8 ) )\r
+\r
+/** The maximal size of an ECDSA signature in Bytes. */\r
+#define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN( MBEDTLS_ECP_MAX_BITS )\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/**\r
+ * \brief The ECDSA context structure.\r
+ *\r
+ * \warning Performing multiple operations concurrently on the same\r
+ * ECDSA context is not supported; objects of this type\r
+ * should not be shared between multiple threads.\r
+ */\r
+typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;\r
+\r
+#if defined(MBEDTLS_ECP_RESTARTABLE)\r
+\r
+/**\r
+ * \brief Internal restart context for ecdsa_verify()\r
+ *\r
+ * \note Opaque struct, defined in ecdsa.c\r
+ */\r
+typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;\r
+\r
+/**\r
+ * \brief Internal restart context for ecdsa_sign()\r
+ *\r
+ * \note Opaque struct, defined in ecdsa.c\r
+ */\r
+typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;\r
+\r
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC)\r
+/**\r
+ * \brief Internal restart context for ecdsa_sign_det()\r
+ *\r
+ * \note Opaque struct, defined in ecdsa.c\r
+ */\r
+typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;\r
+#endif\r
+\r
+/**\r
+ * \brief General context for resuming ECDSA operations\r
+ */\r
+typedef struct\r
+{\r
+ mbedtls_ecp_restart_ctx ecp; /*!< base context for ECP restart and\r
+ shared administrative info */\r
+ mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */\r
+ mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */\r
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC)\r
+ mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */\r
+#endif\r
+} mbedtls_ecdsa_restart_ctx;\r
+\r
+#else /* MBEDTLS_ECP_RESTARTABLE */\r
+\r
+/* Now we can declare functions that take a pointer to that */\r
+typedef void mbedtls_ecdsa_restart_ctx;\r
+\r
+#endif /* MBEDTLS_ECP_RESTARTABLE */\r
+\r
+/**\r
+ * \brief This function computes the ECDSA signature of a\r
+ * previously-hashed message.\r
+ *\r
+ * \note The deterministic version implemented in\r
+ * mbedtls_ecdsa_sign_det() is usually preferred.\r
+ *\r
+ * \note If the bitlength of the message hash is larger than the\r
+ * bitlength of the group order, then the hash is truncated\r
+ * as defined in <em>Standards for Efficient Cryptography Group\r
+ * (SECG): SEC1 Elliptic Curve Cryptography</em>, section\r
+ * 4.1.3, step 5.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param grp The context for the elliptic curve to use.\r
+ * This must be initialized and have group parameters\r
+ * set, for example through mbedtls_ecp_group_load().\r
+ * \param r The MPI context in which to store the first part\r
+ * the signature. This must be initialized.\r
+ * \param s The MPI context in which to store the second part\r
+ * the signature. This must be initialized.\r
+ * \param d The private signing key. This must be initialized.\r
+ * \param buf The content to be signed. This is usually the hash of\r
+ * the original data to be signed. This must be a readable\r
+ * buffer of length \p blen Bytes. It may be \c NULL if\r
+ * \p blen is zero.\r
+ * \param blen The length of \p buf in Bytes.\r
+ * \param f_rng The RNG function. This must not be \c NULL.\r
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be\r
+ * \c NULL if \p f_rng doesn't need a context parameter.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX\r
+ * or \c MBEDTLS_MPI_XXX error code on failure.\r
+ */\r
+int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,\r
+ const mbedtls_mpi *d, const unsigned char *buf, size_t blen,\r
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );\r
+\r
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC)\r
+/**\r
+ * \brief This function computes the ECDSA signature of a\r
+ * previously-hashed message, deterministic version.\r
+ *\r
+ * For more information, see <em>RFC-6979: Deterministic\r
+ * Usage of the Digital Signature Algorithm (DSA) and Elliptic\r
+ * Curve Digital Signature Algorithm (ECDSA)</em>.\r
+ *\r
+ * \note If the bitlength of the message hash is larger than the\r
+ * bitlength of the group order, then the hash is truncated as\r
+ * defined in <em>Standards for Efficient Cryptography Group\r
+ * (SECG): SEC1 Elliptic Curve Cryptography</em>, section\r
+ * 4.1.3, step 5.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param grp The context for the elliptic curve to use.\r
+ * This must be initialized and have group parameters\r
+ * set, for example through mbedtls_ecp_group_load().\r
+ * \param r The MPI context in which to store the first part\r
+ * the signature. This must be initialized.\r
+ * \param s The MPI context in which to store the second part\r
+ * the signature. This must be initialized.\r
+ * \param d The private signing key. This must be initialized\r
+ * and setup, for example through mbedtls_ecp_gen_privkey().\r
+ * \param buf The hashed content to be signed. This must be a readable\r
+ * buffer of length \p blen Bytes. It may be \c NULL if\r
+ * \p blen is zero.\r
+ * \param blen The length of \p buf in Bytes.\r
+ * \param md_alg The hash algorithm used to hash the original data.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX\r
+ * error code on failure.\r
+ */\r
+int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,\r
+ mbedtls_mpi *s, const mbedtls_mpi *d,\r
+ const unsigned char *buf, size_t blen,\r
+ mbedtls_md_type_t md_alg );\r
+#endif /* MBEDTLS_ECDSA_DETERMINISTIC */\r
+\r
+/**\r
+ * \brief This function verifies the ECDSA signature of a\r
+ * previously-hashed message.\r
+ *\r
+ * \note If the bitlength of the message hash is larger than the\r
+ * bitlength of the group order, then the hash is truncated as\r
+ * defined in <em>Standards for Efficient Cryptography Group\r
+ * (SECG): SEC1 Elliptic Curve Cryptography</em>, section\r
+ * 4.1.4, step 3.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param grp The ECP group to use.\r
+ * This must be initialized and have group parameters\r
+ * set, for example through mbedtls_ecp_group_load().\r
+ * \param buf The hashed content that was signed. This must be a readable\r
+ * buffer of length \p blen Bytes. It may be \c NULL if\r
+ * \p blen is zero.\r
+ * \param blen The length of \p buf in Bytes.\r
+ * \param Q The public key to use for verification. This must be\r
+ * initialized and setup.\r
+ * \param r The first integer of the signature.\r
+ * This must be initialized.\r
+ * \param s The second integer of the signature.\r
+ * This must be initialized.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the signature\r
+ * is invalid.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX\r
+ * error code on failure for any other reason.\r
+ */\r
+int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,\r
+ const unsigned char *buf, size_t blen,\r
+ const mbedtls_ecp_point *Q, const mbedtls_mpi *r,\r
+ const mbedtls_mpi *s);\r
+\r
+/**\r
+ * \brief This function computes the ECDSA signature and writes it\r
+ * to a buffer, serialized as defined in <em>RFC-4492:\r
+ * Elliptic Curve Cryptography (ECC) Cipher Suites for\r
+ * Transport Layer Security (TLS)</em>.\r
+ *\r
+ * \warning It is not thread-safe to use the same context in\r
+ * multiple threads.\r
+ *\r
+ * \note The deterministic version is used if\r
+ * #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more\r
+ * information, see <em>RFC-6979: Deterministic Usage\r
+ * of the Digital Signature Algorithm (DSA) and Elliptic\r
+ * Curve Digital Signature Algorithm (ECDSA)</em>.\r
+ *\r
+ * \note If the bitlength of the message hash is larger than the\r
+ * bitlength of the group order, then the hash is truncated as\r
+ * defined in <em>Standards for Efficient Cryptography Group\r
+ * (SECG): SEC1 Elliptic Curve Cryptography</em>, section\r
+ * 4.1.3, step 5.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param ctx The ECDSA context to use. This must be initialized\r
+ * and have a group and private key bound to it, for example\r
+ * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().\r
+ * \param md_alg The message digest that was used to hash the message.\r
+ * \param hash The message hash to be signed. This must be a readable\r
+ * buffer of length \p blen Bytes.\r
+ * \param hlen The length of the hash \p hash in Bytes.\r
+ * \param sig The buffer to which to write the signature. This must be a\r
+ * writable buffer of length at least twice as large as the\r
+ * size of the curve used, plus 9. For example, 73 Bytes if\r
+ * a 256-bit curve is used. A buffer length of\r
+ * #MBEDTLS_ECDSA_MAX_LEN is always safe.\r
+ * \param slen The address at which to store the actual length of\r
+ * the signature written. Must not be \c NULL.\r
+ * \param f_rng The RNG function. This must not be \c NULL if\r
+ * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise,\r
+ * it is unused and may be set to \c NULL.\r
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be\r
+ * \c NULL if \p f_rng is \c NULL or doesn't use a context.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or\r
+ * \c MBEDTLS_ERR_ASN1_XXX error code on failure.\r
+ */\r
+int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,\r
+ mbedtls_md_type_t md_alg,\r
+ const unsigned char *hash, size_t hlen,\r
+ unsigned char *sig, size_t *slen,\r
+ int (*f_rng)(void *, unsigned char *, size_t),\r
+ void *p_rng );\r
+\r
+/**\r
+ * \brief This function computes the ECDSA signature and writes it\r
+ * to a buffer, in a restartable way.\r
+ *\r
+ * \see \c mbedtls_ecdsa_write_signature()\r
+ *\r
+ * \note This function is like \c mbedtls_ecdsa_write_signature()\r
+ * but it can return early and restart according to the limit\r
+ * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.\r
+ *\r
+ * \param ctx The ECDSA context to use. This must be initialized\r
+ * and have a group and private key bound to it, for example\r
+ * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().\r
+ * \param md_alg The message digest that was used to hash the message.\r
+ * \param hash The message hash to be signed. This must be a readable\r
+ * buffer of length \p blen Bytes.\r
+ * \param hlen The length of the hash \p hash in Bytes.\r
+ * \param sig The buffer to which to write the signature. This must be a\r
+ * writable buffer of length at least twice as large as the\r
+ * size of the curve used, plus 9. For example, 73 Bytes if\r
+ * a 256-bit curve is used. A buffer length of\r
+ * #MBEDTLS_ECDSA_MAX_LEN is always safe.\r
+ * \param slen The address at which to store the actual length of\r
+ * the signature written. Must not be \c NULL.\r
+ * \param f_rng The RNG function. This must not be \c NULL if\r
+ * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise,\r
+ * it is unused and may be set to \c NULL.\r
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be\r
+ * \c NULL if \p f_rng is \c NULL or doesn't use a context.\r
+ * \param rs_ctx The restart context to use. This may be \c NULL to disable\r
+ * restarting. If it is not \c NULL, it must point to an\r
+ * initialized restart context.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of\r
+ * operations was reached: see \c mbedtls_ecp_set_max_ops().\r
+ * \return Another \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or\r
+ * \c MBEDTLS_ERR_ASN1_XXX error code on failure.\r
+ */\r
+int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,\r
+ mbedtls_md_type_t md_alg,\r
+ const unsigned char *hash, size_t hlen,\r
+ unsigned char *sig, size_t *slen,\r
+ int (*f_rng)(void *, unsigned char *, size_t),\r
+ void *p_rng,\r
+ mbedtls_ecdsa_restart_ctx *rs_ctx );\r
+\r
+#if defined(MBEDTLS_ECDSA_DETERMINISTIC)\r
+#if ! defined(MBEDTLS_DEPRECATED_REMOVED)\r
+#if defined(MBEDTLS_DEPRECATED_WARNING)\r
+#define MBEDTLS_DEPRECATED __attribute__((deprecated))\r
+#else\r
+#define MBEDTLS_DEPRECATED\r
+#endif\r
+/**\r
+ * \brief This function computes an ECDSA signature and writes\r
+ * it to a buffer, serialized as defined in <em>RFC-4492:\r
+ * Elliptic Curve Cryptography (ECC) Cipher Suites for\r
+ * Transport Layer Security (TLS)</em>.\r
+ *\r
+ * The deterministic version is defined in <em>RFC-6979:\r
+ * Deterministic Usage of the Digital Signature Algorithm (DSA)\r
+ * and Elliptic Curve Digital Signature Algorithm (ECDSA)</em>.\r
+ *\r
+ * \warning It is not thread-safe to use the same context in\r
+ * multiple threads.\r
+ *\r
+ * \note If the bitlength of the message hash is larger than the\r
+ * bitlength of the group order, then the hash is truncated as\r
+ * defined in <em>Standards for Efficient Cryptography Group\r
+ * (SECG): SEC1 Elliptic Curve Cryptography</em>, section\r
+ * 4.1.3, step 5.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \deprecated Superseded by mbedtls_ecdsa_write_signature() in\r
+ * Mbed TLS version 2.0 and later.\r
+ *\r
+ * \param ctx The ECDSA context to use. This must be initialized\r
+ * and have a group and private key bound to it, for example\r
+ * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().\r
+ * \param hash The message hash to be signed. This must be a readable\r
+ * buffer of length \p blen Bytes.\r
+ * \param hlen The length of the hash \p hash in Bytes.\r
+ * \param sig The buffer to which to write the signature. This must be a\r
+ * writable buffer of length at least twice as large as the\r
+ * size of the curve used, plus 9. For example, 73 Bytes if\r
+ * a 256-bit curve is used. A buffer length of\r
+ * #MBEDTLS_ECDSA_MAX_LEN is always safe.\r
+ * \param slen The address at which to store the actual length of\r
+ * the signature written. Must not be \c NULL.\r
+ * \param md_alg The message digest that was used to hash the message.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or\r
+ * \c MBEDTLS_ERR_ASN1_XXX error code on failure.\r
+ */\r
+int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,\r
+ const unsigned char *hash, size_t hlen,\r
+ unsigned char *sig, size_t *slen,\r
+ mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;\r
+#undef MBEDTLS_DEPRECATED\r
+#endif /* MBEDTLS_DEPRECATED_REMOVED */\r
+#endif /* MBEDTLS_ECDSA_DETERMINISTIC */\r
+\r
+/**\r
+ * \brief This function reads and verifies an ECDSA signature.\r
+ *\r
+ * \note If the bitlength of the message hash is larger than the\r
+ * bitlength of the group order, then the hash is truncated as\r
+ * defined in <em>Standards for Efficient Cryptography Group\r
+ * (SECG): SEC1 Elliptic Curve Cryptography</em>, section\r
+ * 4.1.4, step 3.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param ctx The ECDSA context to use. This must be initialized\r
+ * and have a group and public key bound to it.\r
+ * \param hash The message hash that was signed. This must be a readable\r
+ * buffer of length \p size Bytes.\r
+ * \param hlen The size of the hash \p hash.\r
+ * \param sig The signature to read and verify. This must be a readable\r
+ * buffer of length \p slen Bytes.\r
+ * \param slen The size of \p sig in Bytes.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid.\r
+ * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid\r
+ * signature in \p sig, but its length is less than \p siglen.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX\r
+ * error code on failure for any other reason.\r
+ */\r
+int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,\r
+ const unsigned char *hash, size_t hlen,\r
+ const unsigned char *sig, size_t slen );\r
+\r
+/**\r
+ * \brief This function reads and verifies an ECDSA signature,\r
+ * in a restartable way.\r
+ *\r
+ * \see \c mbedtls_ecdsa_read_signature()\r
+ *\r
+ * \note This function is like \c mbedtls_ecdsa_read_signature()\r
+ * but it can return early and restart according to the limit\r
+ * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.\r
+ *\r
+ * \param ctx The ECDSA context to use. This must be initialized\r
+ * and have a group and public key bound to it.\r
+ * \param hash The message hash that was signed. This must be a readable\r
+ * buffer of length \p size Bytes.\r
+ * \param hlen The size of the hash \p hash.\r
+ * \param sig The signature to read and verify. This must be a readable\r
+ * buffer of length \p slen Bytes.\r
+ * \param slen The size of \p sig in Bytes.\r
+ * \param rs_ctx The restart context to use. This may be \c NULL to disable\r
+ * restarting. If it is not \c NULL, it must point to an\r
+ * initialized restart context.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid.\r
+ * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid\r
+ * signature in \p sig, but its length is less than \p siglen.\r
+ * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of\r
+ * operations was reached: see \c mbedtls_ecp_set_max_ops().\r
+ * \return Another \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX\r
+ * error code on failure for any other reason.\r
+ */\r
+int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,\r
+ const unsigned char *hash, size_t hlen,\r
+ const unsigned char *sig, size_t slen,\r
+ mbedtls_ecdsa_restart_ctx *rs_ctx );\r
+\r
+/**\r
+ * \brief This function generates an ECDSA keypair on the given curve.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param ctx The ECDSA context to store the keypair in.\r
+ * This must be initialized.\r
+ * \param gid The elliptic curve to use. One of the various\r
+ * \c MBEDTLS_ECP_DP_XXX macros depending on configuration.\r
+ * \param f_rng The RNG function to use. This must not be \c NULL.\r
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be\r
+ * \c NULL if \p f_rng doesn't need a context argument.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX code on failure.\r
+ */\r
+int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,\r
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );\r
+\r
+/**\r
+ * \brief This function sets up an ECDSA context from an EC key pair.\r
+ *\r
+ * \see ecp.h\r
+ *\r
+ * \param ctx The ECDSA context to setup. This must be initialized.\r
+ * \param key The EC key to use. This must be initialized and hold\r
+ * a private-public key pair or a public key. In the former\r
+ * case, the ECDSA context may be used for signature creation\r
+ * and verification after this call. In the latter case, it\r
+ * may be used for signature verification.\r
+ *\r
+ * \return \c 0 on success.\r
+ * \return An \c MBEDTLS_ERR_ECP_XXX code on failure.\r
+ */\r
+int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx,\r
+ const mbedtls_ecp_keypair *key );\r
+\r
+/**\r
+ * \brief This function initializes an ECDSA context.\r
+ *\r
+ * \param ctx The ECDSA context to initialize.\r
+ * This must not be \c NULL.\r
+ */\r
+void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );\r
+\r
+/**\r
+ * \brief This function frees an ECDSA context.\r
+ *\r
+ * \param ctx The ECDSA context to free. This may be \c NULL,\r
+ * in which case this function does nothing. If it\r
+ * is not \c NULL, it must be initialized.\r
+ */\r
+void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );\r
+\r
+#if defined(MBEDTLS_ECP_RESTARTABLE)\r
+/**\r
+ * \brief Initialize a restart context.\r
+ *\r
+ * \param ctx The restart context to initialize.\r
+ * This must not be \c NULL.\r
+ */\r
+void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );\r
+\r
+/**\r
+ * \brief Free the components of a restart context.\r
+ *\r
+ * \param ctx The restart context to free. This may be \c NULL,\r
+ * in which case this function does nothing. If it\r
+ * is not \c NULL, it must be initialized.\r
+ */\r
+void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );\r
+#endif /* MBEDTLS_ECP_RESTARTABLE */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* ecdsa.h */\r