@@ -725,36 +725,85 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B
725725 */
726726int mbedtls_mpi_inv_mod ( mbedtls_mpi * X , const mbedtls_mpi * A , const mbedtls_mpi * N );
727727
728+ #if !defined(MBEDTLS_DEPRECATED_REMOVED )
729+ #if defined(MBEDTLS_DEPRECATED_WARNING )
730+ #define MBEDTLS_DEPRECATED __attribute__((deprecated))
731+ #else
732+ #define MBEDTLS_DEPRECATED
733+ #endif
734+ /**
735+ * \brief Miller-Rabin primality test with error probability of
736+ * 2<sup>-80</sup>
737+ *
738+ * \deprecated Superseded by mbedtls_mpi_is_prime_ext() which allows
739+ * specifying the number of Miller-Rabin rounds.
740+ *
741+ * \param X MPI to check
742+ * \param f_rng RNG function
743+ * \param p_rng RNG parameter
744+ *
745+ * \return 0 if successful (probably prime),
746+ * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
747+ * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime
748+ */
749+ MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime ( const mbedtls_mpi * X ,
750+ int (* f_rng )(void * , unsigned char * , size_t ),
751+ void * p_rng );
752+ #undef MBEDTLS_DEPRECATED
753+ #endif /* !MBEDTLS_DEPRECATED_REMOVED */
754+
728755/**
729- * \brief Miller-Rabin primality test
756+ * \brief Miller-Rabin primality test.
757+ *
758+ * \warning If \p X is potentially generated by an adversary, for example
759+ * when validating cryptographic parameters that you didn't
760+ * generate yourself and that are supposed to be prime, then
761+ * \p rounds should be at least the half of the security
762+ * strength of the cryptographic algorithm. On the other hand,
763+ * if \p X is chosen uniformly or non-adversially (as is the
764+ * case when mbedtls_mpi_gen_prime calls this function), then
765+ * \p rounds can be much lower.
730766 *
731767 * \param X MPI to check
768+ * \param rounds Number of bases to perform Miller-Rabin primality test for.
769+ * The probability of returning 0 on a composite is at most
770+ * 2<sup>-2*\p rounds</sup>.
732771 * \param f_rng RNG function
733772 * \param p_rng RNG parameter
734773 *
735774 * \return 0 if successful (probably prime),
736775 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
737776 * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime
738777 */
739- int mbedtls_mpi_is_prime ( const mbedtls_mpi * X ,
740- int (* f_rng )(void * , unsigned char * , size_t ),
741- void * p_rng );
778+ int mbedtls_mpi_is_prime_ext ( const mbedtls_mpi * X , int rounds ,
779+ int (* f_rng )(void * , unsigned char * , size_t ),
780+ void * p_rng );
781+ /**
782+ * \brief Flags for mbedtls_mpi_gen_prime()
783+ *
784+ * Each of these flags is a constraint on the result X returned by
785+ * mbedtls_mpi_gen_prime().
786+ */
787+ typedef enum {
788+ MBEDTLS_MPI_GEN_PRIME_FLAG_DH = 0x0001 , /**< (X-1)/2 is prime too */
789+ MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR = 0x0002 , /**< lower error rate from 2<sup>-80</sup> to 2<sup>-128</sup> */
790+ } mbedtls_mpi_gen_prime_flag_t ;
742791
743792/**
744793 * \brief Prime number generation
745794 *
746795 * \param X Destination MPI
747796 * \param nbits Required size of X in bits
748797 * ( 3 <= nbits <= MBEDTLS_MPI_MAX_BITS )
749- * \param dh_flag If 1, then (X-1)/2 will be prime too
798+ * \param flags Mask of flags of type #mbedtls_mpi_gen_prime_flag_t
750799 * \param f_rng RNG function
751800 * \param p_rng RNG parameter
752801 *
753802 * \return 0 if successful (probably prime),
754803 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
755804 * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
756805 */
757- int mbedtls_mpi_gen_prime ( mbedtls_mpi * X , size_t nbits , int dh_flag ,
806+ int mbedtls_mpi_gen_prime ( mbedtls_mpi * X , size_t nbits , int flags ,
758807 int (* f_rng )(void * , unsigned char * , size_t ),
759808 void * p_rng );
760809
0 commit comments