1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

mbedtls_ecp_write_key(): deprecate the old function

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2024-02-19 16:50:39 +01:00
parent 84b9f1b039
commit c0f7a8680f
4 changed files with 19 additions and 4 deletions

View File

@ -2,3 +2,7 @@ Features
* The new function mbedtls_ecp_write_key_ext() is similar to * The new function mbedtls_ecp_write_key_ext() is similar to
mbedtls_ecp_write_key(), but can be used without separately calculating mbedtls_ecp_write_key(), but can be used without separately calculating
the output length. the output length.
New deprecations
* mbedtls_ecp_write_key() is deprecated in favor of
mbedtls_ecp_write_key_ext().

View File

@ -24,6 +24,7 @@
#include "mbedtls/private_access.h" #include "mbedtls/private_access.h"
#include "mbedtls/build_info.h" #include "mbedtls/build_info.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/bignum.h" #include "mbedtls/bignum.h"
@ -1327,10 +1328,11 @@ int mbedtls_ecp_set_public_key(mbedtls_ecp_group_id grp_id,
int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
const unsigned char *buf, size_t buflen); const unsigned char *buf, size_t buflen);
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
/** /**
* \brief This function exports an elliptic curve private key. * \brief This function exports an elliptic curve private key.
* *
* \note Note that although this function accepts an output * \deprecated Note that although this function accepts an output
* buffer that is smaller or larger than the key, most key * buffer that is smaller or larger than the key, most key
* import interfaces require the output to have exactly * import interfaces require the output to have exactly
* key's nominal length. It is generally simplest to * key's nominal length. It is generally simplest to
@ -1340,6 +1342,8 @@ int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
* how to calculate the nominal length. * how to calculate the nominal length.
* To avoid this difficulty, use mbedtls_ecp_write_key_ext() * To avoid this difficulty, use mbedtls_ecp_write_key_ext()
* instead. * instead.
* mbedtls_ecp_write_key() is deprecated and will be
* removed in a future version of the library.
* *
* \note If the private key was not set in \p key, * \note If the private key was not set in \p key,
* the output is unspecified. Future versions * the output is unspecified. Future versions
@ -1369,8 +1373,9 @@ int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
* representation is larger than the available space in \p buf. * representation is larger than the available space in \p buf.
* \return Another negative error code on different kinds of failure. * \return Another negative error code on different kinds of failure.
*/ */
int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key, int MBEDTLS_DEPRECATED mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,
unsigned char *buf, size_t buflen); unsigned char *buf, size_t buflen);
#endif /* MBEDTLS_DEPRECATED_REMOVED */
/** /**
* \brief This function exports an elliptic curve private key. * \brief This function exports an elliptic curve private key.

View File

@ -3302,6 +3302,7 @@ cleanup:
/* /*
* Write a private key. * Write a private key.
*/ */
#if !defined MBEDTLS_DEPRECATED_REMOVED
int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key, int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,
unsigned char *buf, size_t buflen) unsigned char *buf, size_t buflen)
{ {
@ -3332,6 +3333,7 @@ cleanup:
return ret; return ret;
} }
#endif /* MBEDTLS_DEPRECATED_REMOVED */
int mbedtls_ecp_write_key_ext(mbedtls_ecp_keypair *key, int mbedtls_ecp_write_key_ext(mbedtls_ecp_keypair *key,
size_t *olen, unsigned char *buf, size_t buflen) size_t *olen, unsigned char *buf, size_t buflen)

View File

@ -1213,10 +1213,12 @@ void mbedtls_ecp_read_key(int grp_id, data_t *in_key, int expected, int canonica
TEST_MEMORY_COMPARE(in_key->x, in_key->len, TEST_MEMORY_COMPARE(in_key->x, in_key->len,
buf, length); buf, length);
#if defined(MBEDTLS_TEST_DEPRECATED)
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
TEST_EQUAL(mbedtls_ecp_write_key(&key, buf, in_key->len), 0); TEST_EQUAL(mbedtls_ecp_write_key(&key, buf, in_key->len), 0);
TEST_MEMORY_COMPARE(in_key->x, in_key->len, TEST_MEMORY_COMPARE(in_key->x, in_key->len,
buf, in_key->len); buf, in_key->len);
#endif /* MBEDTLS_TEST_DEPRECATED */
} else { } else {
unsigned char export1[MBEDTLS_ECP_MAX_BYTES]; unsigned char export1[MBEDTLS_ECP_MAX_BYTES];
unsigned char export2[MBEDTLS_ECP_MAX_BYTES]; unsigned char export2[MBEDTLS_ECP_MAX_BYTES];
@ -1232,6 +1234,7 @@ void mbedtls_ecp_read_key(int grp_id, data_t *in_key, int expected, int canonica
TEST_MEMORY_COMPARE(export1, length1, TEST_MEMORY_COMPARE(export1, length1,
export2, length2); export2, length2);
#if defined(MBEDTLS_TEST_DEPRECATED)
memset(export1, 0, sizeof(export1)); memset(export1, 0, sizeof(export1));
memset(export2, 0, sizeof(export2)); memset(export2, 0, sizeof(export2));
TEST_EQUAL(mbedtls_ecp_write_key(&key, export1, in_key->len), 0); TEST_EQUAL(mbedtls_ecp_write_key(&key, export1, in_key->len), 0);
@ -1240,6 +1243,7 @@ void mbedtls_ecp_read_key(int grp_id, data_t *in_key, int expected, int canonica
TEST_EQUAL(mbedtls_ecp_write_key(&key2, export2, in_key->len), 0); TEST_EQUAL(mbedtls_ecp_write_key(&key2, export2, in_key->len), 0);
TEST_MEMORY_COMPARE(export1, in_key->len, TEST_MEMORY_COMPARE(export1, in_key->len,
export2, in_key->len); export2, in_key->len);
#endif /* MBEDTLS_TEST_DEPRECATED */
} }
} }
@ -1249,7 +1253,7 @@ exit:
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_TEST_DEPRECATED */
void ecp_write_key(int grp_id, data_t *in_key, void ecp_write_key(int grp_id, data_t *in_key,
int exported_size, int expected_ret) int exported_size, int expected_ret)
{ {