bignum_internal.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * \file bignum_internal.h
  3. *
  4. * \brief Internal-only bignum public-key cryptosystem API.
  5. *
  6. * This file declares bignum-related functions that are to be used
  7. * only from within the Mbed TLS library itself.
  8. *
  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_BIGNUM_INTERNAL_H
  15. #define MBEDTLS_BIGNUM_INTERNAL_H
  16. /**
  17. * \brief Perform a modular exponentiation: X = A^E mod N
  18. *
  19. * \warning This function is not constant time with respect to \p E (the exponent).
  20. *
  21. * \param X The destination MPI. This must point to an initialized MPI.
  22. * This must not alias E or N.
  23. * \param A The base of the exponentiation.
  24. * This must point to an initialized MPI.
  25. * \param E The exponent MPI. This must point to an initialized MPI.
  26. * \param N The base for the modular reduction. This must point to an
  27. * initialized MPI.
  28. * \param prec_RR A helper MPI depending solely on \p N which can be used to
  29. * speed-up multiple modular exponentiations for the same value
  30. * of \p N. This may be \c NULL. If it is not \c NULL, it must
  31. * point to an initialized MPI. If it hasn't been used after
  32. * the call to mbedtls_mpi_init(), this function will compute
  33. * the helper value and store it in \p prec_RR for reuse on
  34. * subsequent calls to this function. Otherwise, the function
  35. * will assume that \p prec_RR holds the helper value set by a
  36. * previous call to mbedtls_mpi_exp_mod(), and reuse it.
  37. *
  38. * \return \c 0 if successful.
  39. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
  40. * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \c N is negative or
  41. * even, or if \c E is negative.
  42. * \return Another negative error code on different kinds of failures.
  43. *
  44. */
  45. int mbedtls_mpi_exp_mod_unsafe(mbedtls_mpi *X, const mbedtls_mpi *A,
  46. const mbedtls_mpi *E, const mbedtls_mpi *N,
  47. mbedtls_mpi *prec_RR);
  48. #endif /* bignum_internal.h */