ecp_invasive.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "common.h"
  17. #include "mbedtls/bignum.h"
  18. #include "mbedtls/ecp.h"
  19. #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_ECP_C)
  20. #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
  21. defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
  22. defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
  23. /* Preconditions:
  24. * - bits is a multiple of 64 or is 224
  25. * - c is -1 or -2
  26. * - 0 <= N < 2^bits
  27. * - N has room for bits plus one limb
  28. *
  29. * Behavior:
  30. * Set N to c * 2^bits + old_value_of_N.
  31. */
  32. void mbedtls_ecp_fix_negative(mbedtls_mpi *N, signed char c, size_t bits);
  33. #endif
  34. #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
  35. /** Generate a private key on a Montgomery curve (Curve25519 or Curve448).
  36. *
  37. * This function implements key generation for the set of secret keys
  38. * specified in [Curve25519] p. 5 and in [Curve448]. The resulting value
  39. * has the lower bits masked but is not necessarily canonical.
  40. *
  41. * \note - [Curve25519] http://cr.yp.to/ecdh/curve25519-20060209.pdf
  42. * - [RFC7748] https://tools.ietf.org/html/rfc7748
  43. *
  44. * \p high_bit The position of the high-order bit of the key to generate.
  45. * This is the bit-size of the key minus 1:
  46. * 254 for Curve25519 or 447 for Curve448.
  47. * \param d The randomly generated key. This is a number of size
  48. * exactly \p high_bit + 1 bits, with the least significant bits
  49. * masked as specified in [Curve25519] and in [RFC7748] §5.
  50. * \param f_rng The RNG function.
  51. * \param p_rng The RNG context to be passed to \p f_rng.
  52. *
  53. * \return \c 0 on success.
  54. * \return \c MBEDTLS_ERR_ECP_xxx or MBEDTLS_ERR_MPI_xxx on failure.
  55. */
  56. int mbedtls_ecp_gen_privkey_mx(size_t high_bit,
  57. mbedtls_mpi *d,
  58. int (*f_rng)(void *, unsigned char *, size_t),
  59. void *p_rng);
  60. #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
  61. #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_ECP_C */
  62. #endif /* MBEDTLS_ECP_INVASIVE_H */