Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:50

0001 /**
0002  * \file ecdh.h
0003  *
0004  * \brief This file contains ECDH definitions and functions.
0005  *
0006  * The Elliptic Curve Diffie-Hellman (ECDH) protocol is an anonymous
0007  * key agreement protocol allowing two parties to establish a shared
0008  * secret over an insecure channel. Each party must have an
0009  * elliptic-curve public–private key pair.
0010  *
0011  * For more information, see <em>NIST SP 800-56A Rev. 2: Recommendation for
0012  * Pair-Wise Key Establishment Schemes Using Discrete Logarithm
0013  * Cryptography</em>.
0014  */
0015 /*
0016  *  Copyright The Mbed TLS Contributors
0017  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
0018  */
0019 
0020 #ifndef MBEDTLS_ECDH_H
0021 #define MBEDTLS_ECDH_H
0022 #include "mbedtls/private_access.h"
0023 
0024 #include "tf-psa-crypto/build_info.h"
0025 
0026 #include "mbedtls/private/ecp.h"
0027 
0028 /*
0029  * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context
0030  * defined in `ecdh.h`). For most applications, the choice of format makes
0031  * no difference, since all library functions can work with either format,
0032  * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE.
0033 
0034  * The new format used when this option is disabled is smaller
0035  * (56 bytes on a 32-bit platform). In future versions of the library, it
0036  * will support alternative implementations of ECDH operations.
0037  * The new format is incompatible with applications that access
0038  * context fields directly and with restartable ECP operations.
0039  */
0040 
0041 #if defined(MBEDTLS_ECP_RESTARTABLE)
0042 #define MBEDTLS_ECDH_LEGACY_CONTEXT
0043 #else
0044 #undef MBEDTLS_ECDH_LEGACY_CONTEXT
0045 #endif
0046 
0047 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
0048 #undef MBEDTLS_ECDH_LEGACY_CONTEXT
0049 #include "tf-psa-crypto/private/everest/x25519.h"
0050 #include "tf-psa-crypto/private/everest/everest.h"
0051 #endif
0052 
0053 #ifdef __cplusplus
0054 extern "C" {
0055 #endif
0056 
0057 #if defined(MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS)
0058 /**
0059  * Defines the source of the imported EC key.
0060  */
0061 typedef enum {
0062     MBEDTLS_ECDH_OURS,   /**< Our key. */
0063     MBEDTLS_ECDH_THEIRS, /**< The key of the peer. */
0064 } mbedtls_ecdh_side;
0065 #endif /* MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS */
0066 
0067 #if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
0068 /**
0069  * Defines the ECDH implementation used.
0070  *
0071  * Later versions of the library may add new variants, therefore users should
0072  * not make any assumptions about them.
0073  */
0074 typedef enum {
0075     MBEDTLS_ECDH_VARIANT_NONE = 0,   /*!< Implementation not defined. */
0076     MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,/*!< The default Mbed TLS implementation */
0077 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
0078     MBEDTLS_ECDH_VARIANT_EVEREST     /*!< Everest implementation */
0079 #endif
0080 } mbedtls_ecdh_variant;
0081 
0082 /**
0083  * The context used by the default ECDH implementation.
0084  *
0085  * Later versions might change the structure of this context, therefore users
0086  * should not make any assumptions about the structure of
0087  * mbedtls_ecdh_context_mbed.
0088  */
0089 typedef struct mbedtls_ecdh_context_mbed {
0090     mbedtls_ecp_group MBEDTLS_PRIVATE(grp);   /*!< The elliptic curve used. */
0091     mbedtls_mpi MBEDTLS_PRIVATE(d);           /*!< The private key. */
0092     mbedtls_ecp_point MBEDTLS_PRIVATE(Q);     /*!< The public key. */
0093     mbedtls_ecp_point MBEDTLS_PRIVATE(Qp);    /*!< The value of the public key of the peer. */
0094     mbedtls_mpi MBEDTLS_PRIVATE(z);           /*!< The shared secret. */
0095 #if defined(MBEDTLS_ECP_RESTARTABLE)
0096     mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(rs); /*!< The restart context for EC computations. */
0097 #endif
0098 } mbedtls_ecdh_context_mbed;
0099 #endif
0100 
0101 #if defined(MBEDTLS_ECP_RESTARTABLE)
0102 #define MBEDTLS_ECDH_CONTEXT_MBED_INIT { MBEDTLS_ECP_GROUP_INIT, MBEDTLS_MPI_INIT, \
0103                                          MBEDTLS_ECP_POINT_INIT, \
0104                                          MBEDTLS_ECP_POINT_INIT, MBEDTLS_MPI_INIT, \
0105                                          MBEDTLS_ECP_RESTART_INIT }
0106 #else
0107 #define MBEDTLS_ECDH_CONTEXT_MBED_INIT { MBEDTLS_ECP_GROUP_INIT, MBEDTLS_MPI_INIT, \
0108                                          MBEDTLS_ECP_POINT_INIT, \
0109                                          MBEDTLS_ECP_POINT_INIT, MBEDTLS_MPI_INIT }
0110 #endif
0111 
0112 /**
0113  *
0114  * \warning         Performing multiple operations concurrently on the same
0115  *                  ECDSA context is not supported; objects of this type
0116  *                  should not be shared between multiple threads.
0117  * \brief           The ECDH context structure.
0118  */
0119 typedef struct mbedtls_ecdh_context {
0120 #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
0121     mbedtls_ecp_group MBEDTLS_PRIVATE(grp);   /*!< The elliptic curve used. */
0122     mbedtls_mpi MBEDTLS_PRIVATE(d);           /*!< The private key. */
0123     mbedtls_ecp_point MBEDTLS_PRIVATE(Q);     /*!< The public key. */
0124     mbedtls_ecp_point MBEDTLS_PRIVATE(Qp);    /*!< The value of the public key of the peer. */
0125     mbedtls_mpi MBEDTLS_PRIVATE(z);           /*!< The shared secret. */
0126     int MBEDTLS_PRIVATE(point_format);        /*!< The format of point export in TLS messages. */
0127     mbedtls_ecp_point MBEDTLS_PRIVATE(Vi);    /*!< The blinding value. */
0128     mbedtls_ecp_point MBEDTLS_PRIVATE(Vf);    /*!< The unblinding value. */
0129     mbedtls_mpi MBEDTLS_PRIVATE(_d);          /*!< The previous \p d. */
0130 #if defined(MBEDTLS_ECP_RESTARTABLE)
0131     int MBEDTLS_PRIVATE(restart_enabled);        /*!< The flag for restartable mode. */
0132     mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(rs); /*!< The restart context for EC computations. */
0133 #endif /* MBEDTLS_ECP_RESTARTABLE */
0134 #else
0135     uint8_t MBEDTLS_PRIVATE(point_format);       /*!< The format of point export in TLS messages
0136                                                     as defined in RFC 4492. */
0137     mbedtls_ecp_group_id MBEDTLS_PRIVATE(grp_id);/*!< The elliptic curve used. */
0138     mbedtls_ecdh_variant MBEDTLS_PRIVATE(var);   /*!< The ECDH implementation/structure used. */
0139     union {
0140         mbedtls_ecdh_context_mbed   MBEDTLS_PRIVATE(mbed_ecdh);
0141 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
0142         mbedtls_ecdh_context_everest MBEDTLS_PRIVATE(everest_ecdh);
0143 #endif
0144     } MBEDTLS_PRIVATE(ctx);                      /*!< Implementation-specific context. The
0145                                                     context in use is specified by the \c var
0146                                                     field. */
0147 #if defined(MBEDTLS_ECP_RESTARTABLE)
0148     uint8_t MBEDTLS_PRIVATE(restart_enabled);    /*!< The flag for restartable mode. Functions of
0149                                                     an alternative implementation not supporting
0150                                                     restartable mode must return
0151                                                     MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error
0152                                                     if this flag is set. */
0153 #endif /* MBEDTLS_ECP_RESTARTABLE */
0154 #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
0155 }
0156 mbedtls_ecdh_context;
0157 
0158 #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
0159 #if defined(MBEDTLS_ECP_RESTARTABLE)
0160 #define MBEDTLS_ECDH_CONTEXT_INIT { MBEDTLS_ECP_GROUP_INIT, MBEDTLS_MPI_INIT, \
0161                                     MBEDTLS_ECP_POINT_INIT, \
0162                                     MBEDTLS_ECP_POINT_INIT, MBEDTLS_MPI_INIT, \
0163                                     MBEDTLS_ECP_PF_UNCOMPRESSED, \
0164                                     MBEDTLS_ECP_POINT_INIT, MBEDTLS_ECP_POINT_INIT, \
0165                                     MBEDTLS_MPI_INIT, 0, \
0166                                     MBEDTLS_ECP_RESTART_INIT }
0167 #else
0168 #define MBEDTLS_ECDH_CONTEXT_INIT { MBEDTLS_ECP_GROUP_INIT, MBEDTLS_MPI_INIT, \
0169                                     MBEDTLS_ECP_POINT_INIT, \
0170                                     MBEDTLS_ECP_POINT_INIT, MBEDTLS_MPI_INIT, \
0171                                     MBEDTLS_ECP_PF_UNCOMPRESSED, \
0172                                     MBEDTLS_ECP_POINT_INIT, MBEDTLS_ECP_POINT_INIT, \
0173                                     MBEDTLS_MPI_INIT }
0174 #endif /* MBEDTLS_ECP_RESTARTABLE */
0175 #else
0176 #if defined(MBEDTLS_ECP_RESTARTABLE)
0177 #define MBEDTLS_ECDH_CONTEXT_INIT { MBEDTLS_ECP_PF_UNCOMPRESSED, MBEDTLS_ECP_DP_NONE, \
0178                                     MBEDTLS_ECDH_VARIANT_NONE, \
0179                                     { MBEDTLS_ECDH_CONTEXT_MBED_INIT }, 0 }
0180 #else
0181 #define MBEDTLS_ECDH_CONTEXT_INIT { MBEDTLS_ECP_PF_UNCOMPRESSED, MBEDTLS_ECP_DP_NONE, \
0182                                     MBEDTLS_ECDH_VARIANT_NONE, \
0183                                     { MBEDTLS_ECDH_CONTEXT_MBED_INIT } }
0184 #endif /* MBEDTLS_ECP_RESTARTABLE */
0185 #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
0186 
0187 #if defined(MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS)
0188 /**
0189  * \brief          Return the ECP group for provided context.
0190  *
0191  * \note           To access group specific fields, users should use
0192  *                 `mbedtls_ecp_curve_info_from_grp_id` or
0193  *                 `mbedtls_ecp_group_load` on the extracted `group_id`.
0194  *
0195  * \param ctx      The ECDH context to parse. This must not be \c NULL.
0196  *
0197  * \return         The \c mbedtls_ecp_group_id of the context.
0198  */
0199 mbedtls_ecp_group_id mbedtls_ecdh_get_grp_id(mbedtls_ecdh_context *ctx);
0200 
0201 /**
0202  * \brief          Check whether a given group can be used for ECDH.
0203  *
0204  * \param gid      The ECP group ID to check.
0205  *
0206  * \return         \c 1 if the group can be used, \c 0 otherwise
0207  */
0208 int mbedtls_ecdh_can_do(mbedtls_ecp_group_id gid);
0209 
0210 /**
0211  * \brief           This function generates an ECDH keypair on an elliptic
0212  *                  curve.
0213  *
0214  *                  This function performs the first of two core computations
0215  *                  implemented during the ECDH key exchange. The second core
0216  *                  computation is performed by mbedtls_ecdh_compute_shared().
0217  *
0218  * \see             ecp.h
0219  *
0220  * \param grp       The ECP group to use. This must be initialized and have
0221  *                  domain parameters loaded, for example through
0222  *                  mbedtls_ecp_load() or mbedtls_ecp_tls_read_group().
0223  * \param d         The destination MPI (private key).
0224  *                  This must be initialized.
0225  * \param Q         The destination point (public key).
0226  *                  This must be initialized.
0227  * \param f_rng     The RNG function to use. This must not be \c NULL.
0228  * \param p_rng     The RNG context to be passed to \p f_rng. This may be
0229  *                  \c NULL in case \p f_rng doesn't need a context argument.
0230  *
0231  * \return          \c 0 on success.
0232  * \return          Another \c MBEDTLS_ERR_ECP_XXX or
0233  *                  \c MBEDTLS_MPI_XXX error code on failure.
0234  */
0235 int mbedtls_ecdh_gen_public(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
0236                             int (*f_rng)(void *, unsigned char *, size_t),
0237                             void *p_rng);
0238 
0239 /**
0240  * \brief           This function computes the shared secret.
0241  *
0242  *                  This function performs the second of two core computations
0243  *                  implemented during the ECDH key exchange. The first core
0244  *                  computation is performed by mbedtls_ecdh_gen_public().
0245  *
0246  * \see             ecp.h
0247  *
0248  * \note            If \p f_rng is not NULL, it is used to implement
0249  *                  countermeasures against side-channel attacks.
0250  *                  For more information, see mbedtls_ecp_mul().
0251  *
0252  * \param grp       The ECP group to use. This must be initialized and have
0253  *                  domain parameters loaded, for example through
0254  *                  mbedtls_ecp_load() or mbedtls_ecp_tls_read_group().
0255  * \param z         The destination MPI (shared secret).
0256  *                  This must be initialized.
0257  * \param Q         The public key from another party.
0258  *                  This must be initialized.
0259  * \param d         Our secret exponent (private key).
0260  *                  This must be initialized.
0261  * \param f_rng     The RNG function to use. This must not be \c NULL.
0262  * \param p_rng     The RNG context to be passed to \p f_rng. This may be
0263  *                  \c NULL if \p f_rng is \c NULL or doesn't need a
0264  *                  context argument.
0265  *
0266  * \return          \c 0 on success.
0267  * \return          Another \c MBEDTLS_ERR_ECP_XXX or
0268  *                  \c MBEDTLS_MPI_XXX error code on failure.
0269  */
0270 int mbedtls_ecdh_compute_shared(mbedtls_ecp_group *grp, mbedtls_mpi *z,
0271                                 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
0272                                 int (*f_rng)(void *, unsigned char *, size_t),
0273                                 void *p_rng);
0274 
0275 /**
0276  * \brief           This function initializes an ECDH context.
0277  *
0278  * \param ctx       The ECDH context to initialize. This must not be \c NULL.
0279  */
0280 void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx);
0281 
0282 /**
0283  * \brief           This function sets up the ECDH context with the information
0284  *                  given.
0285  *
0286  *                  This function should be called after mbedtls_ecdh_init() but
0287  *                  before mbedtls_ecdh_make_params(). There is no need to call
0288  *                  this function before mbedtls_ecdh_read_params().
0289  *
0290  *                  This is the first function used by a TLS server for ECDHE
0291  *                  ciphersuites.
0292  *
0293  * \param ctx       The ECDH context to set up. This must be initialized.
0294  * \param grp_id    The group id of the group to set up the context for.
0295  *
0296  * \return          \c 0 on success.
0297  */
0298 int mbedtls_ecdh_setup(mbedtls_ecdh_context *ctx,
0299                        mbedtls_ecp_group_id grp_id);
0300 
0301 /**
0302  * \brief           This function frees a context.
0303  *
0304  * \param ctx       The context to free. This may be \c NULL, in which
0305  *                  case this function does nothing. If it is not \c NULL,
0306  *                  it must point to an initialized ECDH context.
0307  */
0308 void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx);
0309 
0310 /**
0311  * \brief           This function generates an EC key pair and exports its
0312  *                  in the format used in a TLS ServerKeyExchange handshake
0313  *                  message.
0314  *
0315  *                  This is the second function used by a TLS server for ECDHE
0316  *                  ciphersuites. (It is called after mbedtls_ecdh_setup().)
0317  *
0318  * \see             ecp.h
0319  *
0320  * \param ctx       The ECDH context to use. This must be initialized
0321  *                  and bound to a group, for example via mbedtls_ecdh_setup().
0322  * \param olen      The address at which to store the number of Bytes written.
0323  * \param buf       The destination buffer. This must be a writable buffer of
0324  *                  length \p blen Bytes.
0325  * \param blen      The length of the destination buffer \p buf in Bytes.
0326  * \param f_rng     The RNG function to use. This must not be \c NULL.
0327  * \param p_rng     The RNG context to be passed to \p f_rng. This may be
0328  *                  \c NULL in case \p f_rng doesn't need a context argument.
0329  *
0330  * \return          \c 0 on success.
0331  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
0332  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
0333  * \return          Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
0334  */
0335 int mbedtls_ecdh_make_params(mbedtls_ecdh_context *ctx, size_t *olen,
0336                              unsigned char *buf, size_t blen,
0337                              int (*f_rng)(void *, unsigned char *, size_t),
0338                              void *p_rng);
0339 
0340 /**
0341  * \brief           This function parses the ECDHE parameters in a
0342  *                  TLS ServerKeyExchange handshake message.
0343  *
0344  * \note            In a TLS handshake, this is the how the client
0345  *                  sets up its ECDHE context from the server's public
0346  *                  ECDHE key material.
0347  *
0348  * \see             ecp.h
0349  *
0350  * \param ctx       The ECDHE context to use. This must be initialized.
0351  * \param buf       On input, \c *buf must be the start of the input buffer.
0352  *                  On output, \c *buf is updated to point to the end of the
0353  *                  data that has been read. On success, this is the first byte
0354  *                  past the end of the ServerKeyExchange parameters.
0355  *                  On error, this is the point at which an error has been
0356  *                  detected, which is usually not useful except to debug
0357  *                  failures.
0358  * \param end       The end of the input buffer.
0359  *
0360  * \return          \c 0 on success.
0361  * \return          An \c MBEDTLS_ERR_ECP_XXX error code on failure.
0362  *
0363  */
0364 int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx,
0365                              const unsigned char **buf,
0366                              const unsigned char *end);
0367 
0368 /**
0369  * \brief           This function sets up an ECDH context from an EC key.
0370  *
0371  *                  It is used by clients and servers in place of the
0372  *                  ServerKeyExchange for static ECDH, and imports ECDH
0373  *                  parameters from the EC key information of a certificate.
0374  *
0375  * \see             ecp.h
0376  *
0377  * \param ctx       The ECDH context to set up. This must be initialized.
0378  * \param key       The EC key to use. This must be initialized.
0379  * \param side      Defines the source of the key. Possible values are:
0380  *                  - #MBEDTLS_ECDH_OURS: The key is ours.
0381  *                  - #MBEDTLS_ECDH_THEIRS: The key is that of the peer.
0382  *
0383  * \return          \c 0 on success.
0384  * \return          Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
0385  *
0386  */
0387 int mbedtls_ecdh_get_params(mbedtls_ecdh_context *ctx,
0388                             const mbedtls_ecp_keypair *key,
0389                             mbedtls_ecdh_side side);
0390 
0391 /**
0392  * \brief           This function generates a public key and exports it
0393  *                  as a TLS ClientKeyExchange payload.
0394  *
0395  *                  This is the second function used by a TLS client for ECDH(E)
0396  *                  ciphersuites.
0397  *
0398  * \see             ecp.h
0399  *
0400  * \param ctx       The ECDH context to use. This must be initialized
0401  *                  and bound to a group, the latter usually by
0402  *                  mbedtls_ecdh_read_params().
0403  * \param olen      The address at which to store the number of Bytes written.
0404  *                  This must not be \c NULL.
0405  * \param buf       The destination buffer. This must be a writable buffer
0406  *                  of length \p blen Bytes.
0407  * \param blen      The size of the destination buffer \p buf in Bytes.
0408  * \param f_rng     The RNG function to use. This must not be \c NULL.
0409  * \param p_rng     The RNG context to be passed to \p f_rng. This may be
0410  *                  \c NULL in case \p f_rng doesn't need a context argument.
0411  *
0412  * \return          \c 0 on success.
0413  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
0414  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
0415  * \return          Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
0416  */
0417 int mbedtls_ecdh_make_public(mbedtls_ecdh_context *ctx, size_t *olen,
0418                              unsigned char *buf, size_t blen,
0419                              int (*f_rng)(void *, unsigned char *, size_t),
0420                              void *p_rng);
0421 
0422 /**
0423  * \brief       This function parses and processes the ECDHE payload of a
0424  *              TLS ClientKeyExchange message.
0425  *
0426  *              This is the third function used by a TLS server for ECDH(E)
0427  *              ciphersuites. (It is called after mbedtls_ecdh_setup() and
0428  *              mbedtls_ecdh_make_params().)
0429  *
0430  * \see         ecp.h
0431  *
0432  * \param ctx   The ECDH context to use. This must be initialized
0433  *              and bound to a group, for example via mbedtls_ecdh_setup().
0434  * \param buf   The pointer to the ClientKeyExchange payload. This must
0435  *              be a readable buffer of length \p blen Bytes.
0436  * \param blen  The length of the input buffer \p buf in Bytes.
0437  *
0438  * \return      \c 0 on success.
0439  * \return      An \c MBEDTLS_ERR_ECP_XXX error code on failure.
0440  */
0441 int mbedtls_ecdh_read_public(mbedtls_ecdh_context *ctx,
0442                              const unsigned char *buf, size_t blen);
0443 
0444 /**
0445  * \brief           This function derives and exports the shared secret.
0446  *
0447  *                  This is the last function used by both TLS client
0448  *                  and servers.
0449  *
0450  * \note            If \p f_rng is not NULL, it is used to implement
0451  *                  countermeasures against side-channel attacks.
0452  *                  For more information, see mbedtls_ecp_mul().
0453  *
0454  * \see             ecp.h
0455 
0456  * \param ctx       The ECDH context to use. This must be initialized
0457  *                  and have its own private key generated and the peer's
0458  *                  public key imported.
0459  * \param olen      The address at which to store the total number of
0460  *                  Bytes written on success. This must not be \c NULL.
0461  * \param buf       The buffer to write the generated shared key to. This
0462  *                  must be a writable buffer of size \p blen Bytes.
0463  * \param blen      The length of the destination buffer \p buf in Bytes.
0464  * \param f_rng     The RNG function to use. This must not be \c NULL.
0465  * \param p_rng     The RNG context. This may be \c NULL if \p f_rng
0466  *                  doesn't need a context argument.
0467  *
0468  * \return          \c 0 on success.
0469  * \return          #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
0470  *                  operations was reached: see \c mbedtls_ecp_set_max_ops().
0471  * \return          Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
0472  */
0473 int mbedtls_ecdh_calc_secret(mbedtls_ecdh_context *ctx, size_t *olen,
0474                              unsigned char *buf, size_t blen,
0475                              int (*f_rng)(void *, unsigned char *, size_t),
0476                              void *p_rng);
0477 
0478 #if defined(MBEDTLS_ECP_RESTARTABLE)
0479 /**
0480  * \brief           This function enables restartable EC computations for this
0481  *                  context.  (Default: disabled.)
0482  *
0483  * \see             \c mbedtls_ecp_set_max_ops()
0484  *
0485  * \note            It is not possible to safely disable restartable
0486  *                  computations once enabled, except by free-ing the context,
0487  *                  which cancels possible in-progress operations.
0488  *
0489  * \param ctx       The ECDH context to use. This must be initialized.
0490  */
0491 void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx);
0492 #endif /* MBEDTLS_ECP_RESTARTABLE */
0493 
0494 #endif /* MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS */
0495 
0496 #ifdef __cplusplus
0497 }
0498 #endif
0499 
0500 #endif /* ecdh.h */