Skip to content

Commit 43f564f

Browse files
Define MBEDTLS_ECDH_LEGACY_CONTEXT in config.h
Define MBEDTLS_ECDH_LEGACY_CONTEXT in config.h instead of hard-coding this in ecdh.h so that its absence can be tested. Document it as experimental so that we reserve the right to change it in the future.
1 parent ccf8ba0 commit 43f564f

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

include/mbedtls/check_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation"
125125
#endif
126126

127+
#if defined(MBEDTLS_ECP_RESTARTABLE) && \
128+
! defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
129+
#error "MBEDTLS_ECP_RESTARTABLE defined, but not MBEDTLS_ECDH_LEGACY_CONTEXT"
130+
#endif
131+
127132
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
128133
#error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
129134
#endif

include/mbedtls/config.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,39 @@
740740
*
741741
* \note This option only works with the default software implementation of
742742
* elliptic curve functionality. It is incompatible with
743-
* MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT and MBEDTLS_ECDSA_XXX_ALT.
743+
* MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT
744+
* and MBEDTLS_ECDH_LEGACY_CONTEXT.
744745
*/
745746
//#define MBEDTLS_ECP_RESTARTABLE
746747

748+
/**
749+
* \def MBEDTLS_ECDH_LEGACY_CONTEXT
750+
*
751+
* Use a backward compatible ECDH context.
752+
*
753+
* Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context
754+
* defined in `ecdh.h`). For most applications, the choice of format makes
755+
* no difference, since all library functions can work with either format,
756+
* except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE.
757+
758+
* The new format used when this option is disabled is smaller
759+
* (56 bytes on a 32-bit platform). In future versions of the library, it
760+
* will support alternative implementations of ECDH operations.
761+
* The new format is incompatible with applications that access
762+
* context fields directly and with restartable ECP operations.
763+
*
764+
* Define this macro if you enable MBEDTLS_ECP_RESTARTABLE or if you
765+
* want to access ECDH context fields directly. Otherwise you should
766+
* comment out this macro definition.
767+
*
768+
* This option has no effect if #MBEDTLS_ECDH_C is not enabled.
769+
*
770+
* \note This configuration option is experimental. Future versions of the
771+
* library may modify the way the ECDH context layout is configured
772+
* and may modify the layout of the new context type.
773+
*/
774+
#define MBEDTLS_ECDH_LEGACY_CONTEXT
775+
747776
/**
748777
* \def MBEDTLS_ECDSA_DETERMINISTIC
749778
*

include/mbedtls/ecdh.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@
4242

4343
#include "ecp.h"
4444

45-
/*
46-
* Use a backward compatible ECDH context.
47-
*
48-
* This flag is always enabled for now and future versions might add a
49-
* configuration option that conditionally undefines this flag.
50-
* The configuration option in question may have a different name.
51-
*
52-
* Features undefining this flag, must have a warning in their description in
53-
* config.h stating that the feature breaks backward compatibility.
54-
*/
55-
#define MBEDTLS_ECDH_LEGACY_CONTEXT
56-
5745
#ifdef __cplusplus
5846
extern "C" {
5947
#endif

library/version_features.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ static const char *features[] = {
348348
#if defined(MBEDTLS_ECP_RESTARTABLE)
349349
"MBEDTLS_ECP_RESTARTABLE",
350350
#endif /* MBEDTLS_ECP_RESTARTABLE */
351+
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
352+
"MBEDTLS_ECDH_LEGACY_CONTEXT",
353+
#endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
351354
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
352355
"MBEDTLS_ECDSA_DETERMINISTIC",
353356
#endif /* MBEDTLS_ECDSA_DETERMINISTIC */

0 commit comments

Comments
 (0)