The Great Renaming

A simple execution of tmp/invoke-rename.pl
diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h
index 171d42a..de3b959 100644
--- a/include/mbedtls/bignum.h
+++ b/include/mbedtls/bignum.h
@@ -21,18 +21,18 @@
  *  with this program; if not, write to the Free Software Foundation, Inc.,
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
-#ifndef POLARSSL_BIGNUM_H
-#define POLARSSL_BIGNUM_H
+#ifndef MBEDTLS_BIGNUM_H
+#define MBEDTLS_BIGNUM_H
 
-#if !defined(POLARSSL_CONFIG_FILE)
+#if !defined(MBEDTLS_CONFIG_FILE)
 #include "config.h"
 #else
-#include POLARSSL_CONFIG_FILE
+#include MBEDTLS_CONFIG_FILE
 #endif
 
 #include <stddef.h>
 
-#if defined(POLARSSL_FS_IO)
+#if defined(MBEDTLS_FS_IO)
 #include <stdio.h>
 #endif
 
@@ -53,124 +53,124 @@
 #include <inttypes.h>
 #endif /* _MSC_VER && !EFIX64 && !EFI32 */
 
-#define POLARSSL_ERR_MPI_FILE_IO_ERROR                     -0x0002  /**< An error occurred while reading from or writing to a file. */
-#define POLARSSL_ERR_MPI_BAD_INPUT_DATA                    -0x0004  /**< Bad input parameters to function. */
-#define POLARSSL_ERR_MPI_INVALID_CHARACTER                 -0x0006  /**< There is an invalid character in the digit string. */
-#define POLARSSL_ERR_MPI_BUFFER_TOO_SMALL                  -0x0008  /**< The buffer is too small to write to. */
-#define POLARSSL_ERR_MPI_NEGATIVE_VALUE                    -0x000A  /**< The input arguments are negative or result in illegal output. */
-#define POLARSSL_ERR_MPI_DIVISION_BY_ZERO                  -0x000C  /**< The input argument for division is zero, which is not allowed. */
-#define POLARSSL_ERR_MPI_NOT_ACCEPTABLE                    -0x000E  /**< The input arguments are not acceptable. */
-#define POLARSSL_ERR_MPI_MALLOC_FAILED                     -0x0010  /**< Memory allocation failed. */
+#define MBEDTLS_ERR_MPI_FILE_IO_ERROR                     -0x0002  /**< An error occurred while reading from or writing to a file. */
+#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004  /**< Bad input parameters to function. */
+#define MBEDTLS_ERR_MPI_INVALID_CHARACTER                 -0x0006  /**< There is an invalid character in the digit string. */
+#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL                  -0x0008  /**< The buffer is too small to write to. */
+#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A  /**< The input arguments are negative or result in illegal output. */
+#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO                  -0x000C  /**< The input argument for division is zero, which is not allowed. */
+#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE                    -0x000E  /**< The input arguments are not acceptable. */
+#define MBEDTLS_ERR_MPI_MALLOC_FAILED                     -0x0010  /**< Memory allocation failed. */
 
-#define MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 )
+#define MBEDTLS_MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 )
 
 /*
  * Maximum size MPIs are allowed to grow to in number of limbs.
  */
-#define POLARSSL_MPI_MAX_LIMBS                             10000
+#define MBEDTLS_MPI_MAX_LIMBS                             10000
 
-#if !defined(POLARSSL_MPI_WINDOW_SIZE)
+#if !defined(MBEDTLS_MPI_WINDOW_SIZE)
 /*
  * Maximum window size used for modular exponentiation. Default: 6
  * Minimum value: 1. Maximum value: 6.
  *
- * Result is an array of ( 2 << POLARSSL_MPI_WINDOW_SIZE ) MPIs used
+ * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used
  * for the sliding window calculation. (So 64 by default)
  *
  * Reduction in size, reduces speed.
  */
-#define POLARSSL_MPI_WINDOW_SIZE                           6        /**< Maximum windows size used. */
-#endif /* !POLARSSL_MPI_WINDOW_SIZE */
+#define MBEDTLS_MPI_WINDOW_SIZE                           6        /**< Maximum windows size used. */
+#endif /* !MBEDTLS_MPI_WINDOW_SIZE */
 
-#if !defined(POLARSSL_MPI_MAX_SIZE)
+#if !defined(MBEDTLS_MPI_MAX_SIZE)
 /*
  * Maximum size of MPIs allowed in bits and bytes for user-MPIs.
  * ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits )
  *
  * Note: Calculations can results temporarily in larger MPIs. So the number
- * of limbs required (POLARSSL_MPI_MAX_LIMBS) is higher.
+ * of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher.
  */
-#define POLARSSL_MPI_MAX_SIZE                              1024     /**< Maximum number of bytes for usable MPIs. */
-#endif /* !POLARSSL_MPI_MAX_SIZE */
+#define MBEDTLS_MPI_MAX_SIZE                              1024     /**< Maximum number of bytes for usable MPIs. */
+#endif /* !MBEDTLS_MPI_MAX_SIZE */
 
-#define POLARSSL_MPI_MAX_BITS                              ( 8 * POLARSSL_MPI_MAX_SIZE )    /**< Maximum number of bits for usable MPIs. */
+#define MBEDTLS_MPI_MAX_BITS                              ( 8 * MBEDTLS_MPI_MAX_SIZE )    /**< Maximum number of bits for usable MPIs. */
 
 /*
- * When reading from files with mpi_read_file() and writing to files with
- * mpi_write_file() the buffer should have space
+ * When reading from files with mbedtls_mpi_read_file() and writing to files with
+ * mbedtls_mpi_write_file() the buffer should have space
  * for a (short) label, the MPI (in the provided radix), the newline
  * characters and the '\0'.
  *
  * By default we assume at least a 10 char label, a minimum radix of 10
  * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars).
  * Autosized at compile time for at least a 10 char label, a minimum radix
- * of 10 (decimal) for a number of POLARSSL_MPI_MAX_BITS size.
+ * of 10 (decimal) for a number of MBEDTLS_MPI_MAX_BITS size.
  *
  * This used to be statically sized to 1250 for a maximum of 4096 bit
  * numbers (1234 decimal chars).
  *
  * Calculate using the formula:
- *  POLARSSL_MPI_RW_BUFFER_SIZE = ceil(POLARSSL_MPI_MAX_BITS / ln(10) * ln(2)) +
+ *  MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) +
  *                                LabelSize + 6
  */
-#define POLARSSL_MPI_MAX_BITS_SCALE100          ( 100 * POLARSSL_MPI_MAX_BITS )
-#define LN_2_DIV_LN_10_SCALE100                 332
-#define POLARSSL_MPI_RW_BUFFER_SIZE             ( ((POLARSSL_MPI_MAX_BITS_SCALE100 + LN_2_DIV_LN_10_SCALE100 - 1) / LN_2_DIV_LN_10_SCALE100) + 10 + 6 )
+#define MBEDTLS_MPI_MAX_BITS_SCALE100          ( 100 * MBEDTLS_MPI_MAX_BITS )
+#define MBEDTLS_LN_2_DIV_LN_10_SCALE100                 332
+#define MBEDTLS_MPI_RW_BUFFER_SIZE             ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 )
 
 /*
  * Define the base integer type, architecture-wise
  */
-#if defined(POLARSSL_HAVE_INT8)
-typedef   signed char  t_sint;
-typedef unsigned char  t_uint;
-typedef uint16_t       t_udbl;
-#define POLARSSL_HAVE_UDBL
+#if defined(MBEDTLS_HAVE_INT8)
+typedef   signed char  mbedtls_mpi_sint;
+typedef unsigned char  mbedtls_mpi_uint;
+typedef uint16_t       mbedtls_t_udbl;
+#define MBEDTLS_HAVE_UDBL
 #else
-#if defined(POLARSSL_HAVE_INT16)
-typedef  int16_t t_sint;
-typedef uint16_t t_uint;
-typedef uint32_t t_udbl;
-#define POLARSSL_HAVE_UDBL
+#if defined(MBEDTLS_HAVE_INT16)
+typedef  int16_t mbedtls_mpi_sint;
+typedef uint16_t mbedtls_mpi_uint;
+typedef uint32_t mbedtls_t_udbl;
+#define MBEDTLS_HAVE_UDBL
 #else
   /*
    * 32-bit integers can be forced on 64-bit arches (eg. for testing purposes)
-   * by defining POLARSSL_HAVE_INT32 and undefining POLARSSL_HAVE_ASM
+   * by defining MBEDTLS_HAVE_INT32 and undefining MBEDTLS_HAVE_ASM
    */
-  #if ( ! defined(POLARSSL_HAVE_INT32) && \
+  #if ( ! defined(MBEDTLS_HAVE_INT32) && \
           defined(_MSC_VER) && defined(_M_AMD64) )
-    #define POLARSSL_HAVE_INT64
-    typedef  int64_t t_sint;
-    typedef uint64_t t_uint;
+    #define MBEDTLS_HAVE_INT64
+    typedef  int64_t mbedtls_mpi_sint;
+    typedef uint64_t mbedtls_mpi_uint;
   #else
-    #if ( ! defined(POLARSSL_HAVE_INT32) &&               \
+    #if ( ! defined(MBEDTLS_HAVE_INT32) &&               \
           defined(__GNUC__) && (                          \
           defined(__amd64__) || defined(__x86_64__)    || \
           defined(__ppc64__) || defined(__powerpc64__) || \
           defined(__ia64__)  || defined(__alpha__)     || \
           (defined(__sparc__) && defined(__arch64__))  || \
           defined(__s390x__) || defined(__mips64) ) )
-       #define POLARSSL_HAVE_INT64
-       typedef  int64_t t_sint;
-       typedef uint64_t t_uint;
-       typedef unsigned int t_udbl __attribute__((mode(TI)));
-       #define POLARSSL_HAVE_UDBL
+       #define MBEDTLS_HAVE_INT64
+       typedef  int64_t mbedtls_mpi_sint;
+       typedef uint64_t mbedtls_mpi_uint;
+       typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
+       #define MBEDTLS_HAVE_UDBL
     #else
-       #define POLARSSL_HAVE_INT32
-       typedef  int32_t t_sint;
-       typedef uint32_t t_uint;
+       #define MBEDTLS_HAVE_INT32
+       typedef  int32_t mbedtls_mpi_sint;
+       typedef uint32_t mbedtls_mpi_uint;
        #if ( defined(_MSC_VER) && defined(_M_IX86) )
-         typedef uint64_t t_udbl;
-         #define POLARSSL_HAVE_UDBL
+         typedef uint64_t mbedtls_t_udbl;
+         #define MBEDTLS_HAVE_UDBL
        #else
-         #if defined( POLARSSL_HAVE_LONGLONG )
-           typedef unsigned long long t_udbl;
-           #define POLARSSL_HAVE_UDBL
+         #if defined( MBEDTLS_HAVE_LONGLONG )
+           typedef unsigned long long mbedtls_t_udbl;
+           #define MBEDTLS_HAVE_UDBL
          #endif
        #endif
-    #endif /* !POLARSSL_HAVE_INT32 && __GNUC__ && 64-bit platform */
-  #endif /* !POLARSSL_HAVE_INT32 && _MSC_VER && _M_AMD64 */
-#endif /* POLARSSL_HAVE_INT16 */
-#endif /* POLARSSL_HAVE_INT8  */
+    #endif /* !MBEDTLS_HAVE_INT32 && __GNUC__ && 64-bit platform */
+  #endif /* !MBEDTLS_HAVE_INT32 && _MSC_VER && _M_AMD64 */
+#endif /* MBEDTLS_HAVE_INT16 */
+#endif /* MBEDTLS_HAVE_INT8  */
 
 #ifdef __cplusplus
 extern "C" {
@@ -183,23 +183,23 @@
 {
     int s;              /*!<  integer sign      */
     size_t n;           /*!<  total # of limbs  */
-    t_uint *p;          /*!<  pointer to limbs  */
+    mbedtls_mpi_uint *p;          /*!<  pointer to limbs  */
 }
-mpi;
+mbedtls_mpi;
 
 /**
  * \brief           Initialize one MPI
  *
  * \param X         One MPI to initialize.
  */
-void mpi_init( mpi *X );
+void mbedtls_mpi_init( mbedtls_mpi *X );
 
 /**
  * \brief          Unallocate one MPI
  *
  * \param X        One MPI to unallocate.
  */
-void mpi_free( mpi *X );
+void mbedtls_mpi_free( mbedtls_mpi *X );
 
 /**
  * \brief          Enlarge to the specified number of limbs
@@ -208,9 +208,9 @@
  * \param nblimbs  The target number of limbs
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_grow( mpi *X, size_t nblimbs );
+int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
 
 /**
  * \brief          Resize down, keeping at least the specified number of limbs
@@ -219,9 +219,9 @@
  * \param nblimbs  The minimum number of limbs to keep
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_shrink( mpi *X, size_t nblimbs );
+int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
 
 /**
  * \brief          Copy the contents of Y into X
@@ -230,9 +230,9 @@
  * \param Y        Source MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_copy( mpi *X, const mpi *Y );
+int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y );
 
 /**
  * \brief          Swap the contents of X and Y
@@ -240,7 +240,7 @@
  * \param X        First MPI value
  * \param Y        Second MPI value
  */
-void mpi_swap( mpi *X, mpi *Y );
+void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
 
 /**
  * \brief          Safe conditional assignement X = Y if assign is 1
@@ -250,35 +250,35 @@
  * \param assign   1: perform the assignment, 0: keep X's original value
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
  *
  * \note           This function is equivalent to
- *                      if( assign ) mpi_copy( X, Y );
+ *                      if( assign ) mbedtls_mpi_copy( X, Y );
  *                 except that it avoids leaking any information about whether
  *                 the assignment was done or not (the above code may leak
  *                 information through branch prediction and/or memory access
  *                 patterns analysis).
  */
-int mpi_safe_cond_assign( mpi *X, const mpi *Y, unsigned char assign );
+int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign );
 
 /**
  * \brief          Safe conditional swap X <-> Y if swap is 1
  *
- * \param X        First mpi value
- * \param Y        Second mpi value
+ * \param X        First mbedtls_mpi value
+ * \param Y        Second mbedtls_mpi value
  * \param assign   1: perform the swap, 0: keep X and Y's original values
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
  *
  * \note           This function is equivalent to
- *                      if( assign ) mpi_swap( X, Y );
+ *                      if( assign ) mbedtls_mpi_swap( X, Y );
  *                 except that it avoids leaking any information about whether
  *                 the assignment was done or not (the above code may leak
  *                 information through branch prediction and/or memory access
  *                 patterns analysis).
  */
-int mpi_safe_cond_swap( mpi *X, mpi *Y, unsigned char assign );
+int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign );
 
 /**
  * \brief          Set value from integer
@@ -287,9 +287,9 @@
  * \param z        Value to use
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_lset( mpi *X, t_sint z );
+int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z );
 
 /**
  * \brief          Get a specific bit from X
@@ -299,7 +299,7 @@
  *
  * \return         Either a 0 or a 1
  */
-int mpi_get_bit( const mpi *X, size_t pos );
+int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
 
 /**
  * \brief          Set a bit of X to a specific value of 0 or 1
@@ -312,10 +312,10 @@
  * \param val      The value to set the bit to (0 or 1)
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1
  */
-int mpi_set_bit( mpi *X, size_t pos, unsigned char val );
+int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
 
 /**
  * \brief          Return the number of zero-bits before the least significant
@@ -325,7 +325,7 @@
  *
  * \param X        MPI to use
  */
-size_t mpi_lsb( const mpi *X );
+size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
 
 /**
  * \brief          Return the number of bits up to and including the most
@@ -335,14 +335,14 @@
  *
  * \param X        MPI to use
  */
-size_t mpi_msb( const mpi *X );
+size_t mbedtls_mpi_msb( const mbedtls_mpi *X );
 
 /**
  * \brief          Return the total size in bytes
  *
  * \param X        MPI to use
  */
-size_t mpi_size( const mpi *X );
+size_t mbedtls_mpi_size( const mbedtls_mpi *X );
 
 /**
  * \brief          Import from an ASCII string
@@ -351,9 +351,9 @@
  * \param radix    Input numeric base
  * \param s        Null-terminated string buffer
  *
- * \return         0 if successful, or a POLARSSL_ERR_MPI_XXX error code
+ * \return         0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
  */
-int mpi_read_string( mpi *X, int radix, const char *s );
+int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
 
 /**
  * \brief          Export into an ASCII string
@@ -363,16 +363,16 @@
  * \param s        String buffer
  * \param slen     String buffer size
  *
- * \return         0 if successful, or a POLARSSL_ERR_MPI_XXX error code.
+ * \return         0 if successful, or a MBEDTLS_ERR_MPI_XXX error code.
  *                 *slen is always updated to reflect the amount
  *                 of data that has (or would have) been written.
  *
  * \note           Call this function with *slen = 0 to obtain the
  *                 minimum required buffer size in *slen.
  */
-int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen );
+int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, char *s, size_t *slen );
 
-#if defined(POLARSSL_FS_IO)
+#if defined(MBEDTLS_FS_IO)
 /**
  * \brief          Read X from an opened file
  *
@@ -380,11 +380,11 @@
  * \param radix    Input numeric base
  * \param fin      Input file handle
  *
- * \return         0 if successful, POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if
+ * \return         0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
  *                 the file read buffer is too small or a
- *                 POLARSSL_ERR_MPI_XXX error code
+ *                 MBEDTLS_ERR_MPI_XXX error code
  */
-int mpi_read_file( mpi *X, int radix, FILE *fin );
+int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
 
 /**
  * \brief          Write X into an opened file, or stdout if fout is NULL
@@ -394,12 +394,12 @@
  * \param radix    Output numeric base
  * \param fout     Output file handle (can be NULL)
  *
- * \return         0 if successful, or a POLARSSL_ERR_MPI_XXX error code
+ * \return         0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
  *
  * \note           Set fout == NULL to print X on the console.
  */
-int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout );
-#endif /* POLARSSL_FS_IO */
+int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE *fout );
+#endif /* MBEDTLS_FS_IO */
 
 /**
  * \brief          Import X from unsigned binary data, big endian
@@ -409,9 +409,9 @@
  * \param buflen   Input buffer size
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen );
+int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen );
 
 /**
  * \brief          Export X into unsigned binary data, big endian.
@@ -423,9 +423,9 @@
  * \param buflen   Output buffer size
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough
+ *                 MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough
  */
-int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen );
+int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, size_t buflen );
 
 /**
  * \brief          Left-shift: X <<= count
@@ -434,9 +434,9 @@
  * \param count    Amount to shift
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_shift_l( mpi *X, size_t count );
+int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
 
 /**
  * \brief          Right-shift: X >>= count
@@ -445,9 +445,9 @@
  * \param count    Amount to shift
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_shift_r( mpi *X, size_t count );
+int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
 
 /**
  * \brief          Compare unsigned values
@@ -459,7 +459,7 @@
  *                -1 if |X| is lesser  than |Y| or
  *                 0 if |X| is equal to |Y|
  */
-int mpi_cmp_abs( const mpi *X, const mpi *Y );
+int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
 
 /**
  * \brief          Compare signed values
@@ -471,7 +471,7 @@
  *                -1 if X is lesser  than Y or
  *                 0 if X is equal to Y
  */
-int mpi_cmp_mpi( const mpi *X, const mpi *Y );
+int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
 
 /**
  * \brief          Compare signed values
@@ -483,7 +483,7 @@
  *                -1 if X is lesser  than z or
  *                 0 if X is equal to z
  */
-int mpi_cmp_int( const mpi *X, t_sint z );
+int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z );
 
 /**
  * \brief          Unsigned addition: X = |A| + |B|
@@ -493,9 +493,9 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_add_abs( mpi *X, const mpi *A, const mpi *B );
+int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Unsigned subtraction: X = |A| - |B|
@@ -505,9 +505,9 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_NEGATIVE_VALUE if B is greater than A
+ *                 MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B is greater than A
  */
-int mpi_sub_abs( mpi *X, const mpi *A, const mpi *B );
+int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Signed addition: X = A + B
@@ -517,9 +517,9 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_add_mpi( mpi *X, const mpi *A, const mpi *B );
+int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Signed subtraction: X = A - B
@@ -529,9 +529,9 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_sub_mpi( mpi *X, const mpi *A, const mpi *B );
+int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Signed addition: X = A + b
@@ -541,9 +541,9 @@
  * \param b        The integer value to add
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_add_int( mpi *X, const mpi *A, t_sint b );
+int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b );
 
 /**
  * \brief          Signed subtraction: X = A - b
@@ -553,9 +553,9 @@
  * \param b        The integer value to subtract
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_sub_int( mpi *X, const mpi *A, t_sint b );
+int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b );
 
 /**
  * \brief          Baseline multiplication: X = A * B
@@ -565,9 +565,9 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B );
+int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Baseline multiplication: X = A * b
@@ -579,12 +579,12 @@
  * \note           b is unsigned
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_mul_int( mpi *X, const mpi *A, t_uint b );
+int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b );
 
 /**
- * \brief          Division by mpi: A = Q * B + R
+ * \brief          Division by mbedtls_mpi: A = Q * B + R
  *
  * \param Q        Destination MPI for the quotient
  * \param R        Destination MPI for the rest value
@@ -592,12 +592,12 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0
  *
  * \note           Either Q or R can be NULL.
  */
-int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B );
+int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Division by int: A = Q * b + R
@@ -608,12 +608,12 @@
  * \param b        Integer to divide by
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0
  *
  * \note           Either Q or R can be NULL.
  */
-int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_sint b );
+int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b );
 
 /**
  * \brief          Modulo: R = A mod B
@@ -623,25 +623,25 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0,
- *                 POLARSSL_ERR_MPI_NEGATIVE_VALUE if B < 0
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0,
+ *                 MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B < 0
  */
-int mpi_mod_mpi( mpi *R, const mpi *A, const mpi *B );
+int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Modulo: r = A mod b
  *
- * \param r        Destination t_uint
+ * \param r        Destination mbedtls_mpi_uint
  * \param A        Left-hand MPI
  * \param b        Integer to divide by
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0,
- *                 POLARSSL_ERR_MPI_NEGATIVE_VALUE if b < 0
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0,
+ *                 MBEDTLS_ERR_MPI_NEGATIVE_VALUE if b < 0
  */
-int mpi_mod_int( t_uint *r, const mpi *A, t_sint b );
+int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b );
 
 /**
  * \brief          Sliding-window exponentiation: X = A^E mod N
@@ -653,15 +653,15 @@
  * \param _RR      Speed-up MPI used for recalculations
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_BAD_INPUT_DATA if N is negative or even or
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or even or
  *                 if E is negative
  *
  * \note           _RR is used to avoid re-computing R*R mod N across
  *                 multiple calls, which speeds up things a bit. It can
  *                 be set to NULL if the extra performance is unneeded.
  */
-int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR );
+int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR );
 
 /**
  * \brief          Fill an MPI X with size bytes of random
@@ -672,9 +672,9 @@
  * \param p_rng    RNG parameter
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_fill_random( mpi *X, size_t size,
+int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
                      int (*f_rng)(void *, unsigned char *, size_t),
                      void *p_rng );
 
@@ -686,9 +686,9 @@
  * \param B        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed
  */
-int mpi_gcd( mpi *G, const mpi *A, const mpi *B );
+int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B );
 
 /**
  * \brief          Modular inverse: X = A^-1 mod N
@@ -698,11 +698,11 @@
  * \param N        Right-hand MPI
  *
  * \return         0 if successful,
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_BAD_INPUT_DATA if N is negative or nil
-                   POLARSSL_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or nil
+                   MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N
  */
-int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N );
+int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N );
 
 /**
  * \brief          Miller-Rabin primality test
@@ -712,10 +712,10 @@
  * \param p_rng    RNG parameter
  *
  * \return         0 if successful (probably prime),
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_NOT_ACCEPTABLE if X is not prime
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime
  */
-int mpi_is_prime( const mpi *X,
+int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
                   int (*f_rng)(void *, unsigned char *, size_t),
                   void *p_rng );
 
@@ -724,16 +724,16 @@
  *
  * \param X        Destination MPI
  * \param nbits    Required size of X in bits
- *                 ( 3 <= nbits <= POLARSSL_MPI_MAX_BITS )
+ *                 ( 3 <= nbits <= MBEDTLS_MPI_MAX_BITS )
  * \param dh_flag  If 1, then (X-1)/2 will be prime too
  * \param f_rng    RNG function
  * \param p_rng    RNG parameter
  *
  * \return         0 if successful (probably prime),
- *                 POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed,
- *                 POLARSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
+ *                 MBEDTLS_ERR_MPI_MALLOC_FAILED if memory allocation failed,
+ *                 MBEDTLS_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
  */
-int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag,
+int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
                    int (*f_rng)(void *, unsigned char *, size_t),
                    void *p_rng );
 
@@ -742,7 +742,7 @@
  *
  * \return         0 if successful, or 1 if the test failed
  */
-int mpi_self_test( int verbose );
+int mbedtls_mpi_self_test( int verbose );
 
 #ifdef __cplusplus
 }