@@ -1265,6 +1265,8 @@ int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
12651265/**
12661266 * \brief This function reads an elliptic curve private key.
12671267 *
1268+ * \note This function does not support Curve448 yet.
1269+ *
12681270 * \param grp_id The ECP group identifier.
12691271 * \param key The destination key.
12701272 * \param buf The buffer containing the binary representation of the
@@ -1286,17 +1288,43 @@ int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
12861288/**
12871289 * \brief This function exports an elliptic curve private key.
12881290 *
1291+ * \note Note that although this function accepts an output
1292+ * buffer that is smaller or larger than the key, most key
1293+ * import interfaces require the output to have exactly
1294+ * key's nominal length. It is generally simplest to
1295+ * pass the key's nominal length as \c buflen, after
1296+ * checking that the output buffer is large enough.
1297+ * See the description of the \p buflen parameter for
1298+ * how to calculate the nominal length.
1299+ *
1300+ * \note If the private key was not set in \p key,
1301+ * the output is unspecified. Future versions
1302+ * may return an error in that case.
1303+ *
1304+ * \note This function does not support Curve448 yet.
1305+ *
12891306 * \param key The private key.
12901307 * \param buf The output buffer for containing the binary representation
1291- * of the key. (Big endian integer for Weierstrass curves, byte
1292- * string for Montgomery curves.)
1308+ * of the key.
1309+ * For Weierstrass curves, this is the big-endian
1310+ * representation, padded with null bytes at the beginning
1311+ * to reach \p buflen bytes.
1312+ * For Montgomery curves, this is the standard byte string
1313+ * representation (which is little-endian), padded with
1314+ * null bytes at the end to reach \p buflen bytes.
12931315 * \param buflen The total length of the buffer in bytes.
1316+ * The length of the output is
1317+ * (`grp->nbits` + 7) / 8 bytes
1318+ * where `grp->nbits` is the private key size in bits.
1319+ * For Weierstrass keys, if the output buffer is smaller,
1320+ * leading zeros are trimmed to fit if possible. For
1321+ * Montgomery keys, the output buffer must always be large
1322+ * enough for the nominal length.
12941323 *
12951324 * \return \c 0 on success.
1296- * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the \p key
1297- representation is larger than the available space in \p buf.
1298- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for
1299- * the group is not implemented.
1325+ * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL or
1326+ * #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the \p key
1327+ * representation is larger than the available space in \p buf.
13001328 * \return Another negative error code on different kinds of failure.
13011329 */
13021330int mbedtls_ecp_write_key (mbedtls_ecp_keypair * key ,
0 commit comments