Function esp_idf_svc::hal::sys::mbedtls_ecdsa_write_signature
source · pub unsafe extern "C" fn mbedtls_ecdsa_write_signature(
ctx: *mut mbedtls_ecp_keypair,
md_alg: u32,
hash: *const u8,
hlen: usize,
sig: *mut u8,
sig_size: usize,
slen: *mut usize,
f_rng: Option<unsafe extern "C" fn(_: *mut c_void, _: *mut u8, _: usize) -> i32>,
p_rng: *mut c_void,
) -> i32
Expand description
\brief 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.
\note 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).
\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 Standards for Efficient Cryptography Group (SECG): SEC1 Elliptic Curve Cryptography, section 4.1.3, step 5.
\see ecp.h
\param 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(). \param md_alg The message digest that was used to hash the message. \param hash The message hash to be signed. This must be a readable buffer of length \p hlen Bytes. \param hlen The length of the hash \p hash in Bytes. \param 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. \param sig_size The size of the \p sig buffer in bytes. \param slen The address at which to store the actual length of the signature written. Must not be \c NULL. \param f_rng The RNG function. This must not be \c NULL if #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, it is used only for blinding and may be set to \c NULL, but doing so is DEPRECATED. \param 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 \c 0 on success. \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or \c MBEDTLS_ERR_ASN1_XXX error code on failure.