mbedtls_ecdsa_write_signature() function
This function computes the ECDSA signature and writes it to a buffer, serialized as defined in RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS). \warning It is not thread-safe to use the same context in multiple threads. \see ecp.h
Arguments
ctx
The ECDSA context to use. This must be initialized and have a group and private key bound to it, for example via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
md_alg
The message digest that was used to hash the message.
hash
The message hash to be signed. This must be a readable buffer of length \p blen Bytes.
hlen
The length of the hash \p hash in Bytes.
sig
The buffer to which to write the signature. This must be a writable buffer of length at least twice as large as the size of the curve used, plus 9. For example, 73 Bytes if a 256-bit curve is used. A buffer length of #MBEDTLS_ECDSA_MAX_LEN is always safe.
slen
The address at which to store the actual length of the signature written. Must not be \c NULL.
f_rng
The RNG function. This must not be \c NULL if #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, it is unused and may be set to \c NULL.
p_rng
The RNG context to be passed to \p f_rng. This may be \c NULL if \p f_rng is \c NULL or doesn't use a context.
Return value
\c 0 on success. An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or \c MBEDTLS_ERR_ASN1_XXX error code on failure.
Notes
The deterministic version is used if #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more information, see RFC-6979: Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA). If the bitlength of the message hash is larger than the bitlength of the group order, then the hash is truncated as defined in Standards for Efficient Cryptography Group (SECG): SEC1 Elliptic Curve Cryptography, section 4.1.3, step 5.