• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file ecp_invasive.h
3  *
4  * \brief ECP module: interfaces for invasive testing only.
5  *
6  * The interfaces in this file are intended for testing purposes only.
7  * They SHOULD NOT be made available in library integrations except when
8  * building the library for testing.
9  */
10 /*
11  *  Copyright The Mbed TLS Contributors
12  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13  */
14 #ifndef MBEDTLS_ECP_INVASIVE_H
15 #define MBEDTLS_ECP_INVASIVE_H
16 
17 #include "common.h"
18 #include "mbedtls/bignum.h"
19 #include "mbedtls/ecp.h"
20 
21 #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_ECP_C)
22 
23 #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) ||   \
24     defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) ||   \
25     defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
26 /* Preconditions:
27  *   - bits is a multiple of 64 or is 224
28  *   - c is -1 or -2
29  *   - 0 <= N < 2^bits
30  *   - N has room for bits plus one limb
31  *
32  * Behavior:
33  * Set N to c * 2^bits + old_value_of_N.
34  */
35 void mbedtls_ecp_fix_negative(mbedtls_mpi *N, signed char c, size_t bits);
36 #endif
37 
38 #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
39 /** Generate a private key on a Montgomery curve (Curve25519 or Curve448).
40  *
41  * This function implements key generation for the set of secret keys
42  * specified in [Curve25519] p. 5 and in [Curve448]. The resulting value
43  * has the lower bits masked but is not necessarily canonical.
44  *
45  * \note            - [Curve25519] http://cr.yp.to/ecdh/curve25519-20060209.pdf
46  *                  - [RFC7748] https://tools.ietf.org/html/rfc7748
47  *
48  * \p high_bit      The position of the high-order bit of the key to generate.
49  *                  This is the bit-size of the key minus 1:
50  *                  254 for Curve25519 or 447 for Curve448.
51  * \param d         The randomly generated key. This is a number of size
52  *                  exactly \p high_bit + 1 bits, with the least significant bits
53  *                  masked as specified in [Curve25519] and in [RFC7748] §5.
54  * \param f_rng     The RNG function.
55  * \param p_rng     The RNG context to be passed to \p f_rng.
56  *
57  * \return          \c 0 on success.
58  * \return          \c MBEDTLS_ERR_ECP_xxx or MBEDTLS_ERR_MPI_xxx on failure.
59  */
60 int mbedtls_ecp_gen_privkey_mx(size_t high_bit,
61                                mbedtls_mpi *d,
62                                int (*f_rng)(void *, unsigned char *, size_t),
63                                void *p_rng);
64 
65 #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
66 
67 #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_ECP_C */
68 
69 #endif /* MBEDTLS_ECP_INVASIVE_H */
70