title: How to use ECDSA function in the medtls library
body: <p>I am using the mbedtls library (<a href="https://github.com/ARMmbed/mbedtls" rel="nofollow noreferrer">https://github.com/ARMmbed/mbedtls</a>) on an ARM micro-controller (Ambiq).</p>
  
  <p>I need to use the function mbedtls_ecdsa_sign_det() to sign a bitcoin transaction.</p>
  
  <p>Actually, I am not sure if this is the right function.</p>
  
  <p>Here is the documentation of the function:</p>
  
  <pre><code>Compute ECDSA signature of a previously hashed message, deterministic version (RFC 6979).
  
  Parameters:
  grp ECP group
  r   First output integer
  s   Second output integer
  d   Private signing key
  buf Message hash
  blen    Length of buf
  md_alg  MD algorithm used to hash the message
  Returns:
  0 if successful, or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
  
  The header file includes the following description:
  /**
   * \brief           This function computes the ECDSA signature of a
   *                  previously-hashed message, deterministic version.
   *
   *                  For more information, see &lt;em&gt;RFC-6979: Deterministic
   *                  Usage of the Digital Signature Algorithm (DSA) and Elliptic
   *                  Curve Digital Signature Algorithm (ECDSA)&lt;/em&gt;.
   *
   * \note            If the bitlength of the message hash is larger than the
   *                  bitlength of the group order, then the hash is truncated as
   *                  defined in &lt;em&gt;Standards for Efficient Cryptography Group
   *                  (SECG): SEC1 Elliptic Curve Cryptography&lt;/em&gt;, section
   *                  4.1.3, step 5.
   *
   * \see             ecp.h
   *
   * \param grp       The context for the elliptic curve to use.
   *                  This must be initialized and have group parameters
   *                  set, for example through mbedtls_ecp_group_load().
   * \param r         The MPI context in which to store the first part
   *                  the signature. This must be initialized.
   * \param s         The MPI context in which to store the second part
   *                  the signature. This must be initialized.
   * \param d         The private signing key. This must be initialized
   *                  and setup, for example through mbedtls_ecp_gen_privkey().
   * \param buf       The hashed content to be signed. This must be a readable
   *                  buffer of length \p blen Bytes. It may be \c NULL if
   *                  \p blen is zero.
   * \param blen      The length of \p buf in Bytes.
   * \param md_alg    The hash algorithm used to hash the original data.
   *
   * \return          \c 0 on success.
   * \return          An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
   *                  error code on failure.
   */
  int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
                              mbedtls_mpi *s, const mbedtls_mpi *d,
                              const unsigned char *buf, size_t blen,
                              mbedtls_md_type_t md_alg );
  </code></pre>
  
  <p>Besides, I do not find any example how to use this function.</p>
  
  <p>I do not know how to initialize the passed pointers, grp, r, s and d.</p>