103
103
/*
104
104
* Define the base integer type, architecture-wise.
105
105
*
106
- * 32-bit integers can be forced on 64-bit arches (eg. for testing purposes)
107
- * by defining MBEDTLS_HAVE_INT32 and undefining MBEDTLS_HAVE_ASM
108
- */
109
- #if ( ! defined(MBEDTLS_HAVE_INT32 ) && \
110
- defined(_MSC_VER ) && defined(_M_AMD64 ) )
111
- #define MBEDTLS_HAVE_INT64
112
- typedef int64_t mbedtls_mpi_sint ;
113
- typedef uint64_t mbedtls_mpi_uint ;
114
- #else
115
- #if ( ! defined(MBEDTLS_HAVE_INT32 ) && \
116
- defined(__GNUC__ ) && ( \
117
- defined(__amd64__ ) || defined(__x86_64__ ) || \
118
- defined(__ppc64__ ) || defined(__powerpc64__ ) || \
119
- defined(__ia64__ ) || defined(__alpha__ ) || \
120
- (defined(__sparc__ ) && defined(__arch64__ )) || \
121
- defined(__s390x__ ) || defined(__mips64 ) ) )
122
- #define MBEDTLS_HAVE_INT64
123
- typedef int64_t mbedtls_mpi_sint ;
124
- typedef uint64_t mbedtls_mpi_uint ;
125
- /* mbedtls_t_udbl defined as 128-bit unsigned int */
126
- typedef unsigned int mbedtls_t_udbl __attribute__((mode (TI )));
127
- #define MBEDTLS_HAVE_UDBL
128
- #else
129
- #define MBEDTLS_HAVE_INT32
130
- typedef int32_t mbedtls_mpi_sint ;
131
- typedef uint32_t mbedtls_mpi_uint ;
132
- typedef uint64_t mbedtls_t_udbl ;
133
- #define MBEDTLS_HAVE_UDBL
134
- #endif /* !MBEDTLS_HAVE_INT32 && __GNUC__ && 64-bit platform */
135
- #endif /* !MBEDTLS_HAVE_INT32 && _MSC_VER && _M_AMD64 */
106
+ * 32 or 64-bit integer types can be forced regardless of the underlying
107
+ * architecture by defining MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64
108
+ * respectively and undefining MBEDTLS_HAVE_ASM.
109
+ *
110
+ * Double-width integers (e.g. 128-bit in 64-bit architectures) can be
111
+ * disabled by defining MBEDTLS_NO_UDBL_DIVISION.
112
+ */
113
+ #if !defined(MBEDTLS_HAVE_INT32 )
114
+ #if defined(_MSC_VER ) && defined(_M_AMD64 )
115
+ /* Always choose 64-bit when using MSC */
116
+ #if !defined(MBEDTLS_HAVE_INT64 )
117
+ #define MBEDTLS_HAVE_INT64
118
+ #endif /* !MBEDTLS_HAVE_INT64 */
119
+ typedef int64_t mbedtls_mpi_sint ;
120
+ typedef uint64_t mbedtls_mpi_uint ;
121
+ #elif defined(__GNUC__ ) && ( \
122
+ defined(__amd64__ ) || defined(__x86_64__ ) || \
123
+ defined(__ppc64__ ) || defined(__powerpc64__ ) || \
124
+ defined(__ia64__ ) || defined(__alpha__ ) || \
125
+ ( defined(__sparc__ ) && defined(__arch64__ ) ) || \
126
+ defined(__s390x__ ) || defined(__mips64 ) )
127
+ #if !defined(MBEDTLS_HAVE_INT64 )
128
+ #define MBEDTLS_HAVE_INT64
129
+ #endif /* MBEDTLS_HAVE_INT64 */
130
+ typedef int64_t mbedtls_mpi_sint ;
131
+ typedef uint64_t mbedtls_mpi_uint ;
132
+ #if !defined(MBEDTLS_NO_UDBL_DIVISION )
133
+ /* mbedtls_t_udbl defined as 128-bit unsigned int */
134
+ typedef unsigned int mbedtls_t_udbl __attribute__((mode (TI )));
135
+ #define MBEDTLS_HAVE_UDBL
136
+ #endif /* !MBEDTLS_NO_UDBL_DIVISION */
137
+ #elif defined(__ARMCC_VERSION ) && defined(__aarch64__ )
138
+ /*
139
+ * __ARMCC_VERSION is defined for both armcc and armclang and
140
+ * __aarch64__ is only defined by armclang when compiling 64-bit code
141
+ */
142
+ #if !defined(MBEDTLS_HAVE_INT64 )
143
+ #define MBEDTLS_HAVE_INT64
144
+ #endif /* !MBEDTLS_HAVE_INT64 */
145
+ typedef int64_t mbedtls_mpi_sint ;
146
+ typedef uint64_t mbedtls_mpi_uint ;
147
+ #if !defined(MBEDTLS_NO_UDBL_DIVISION )
148
+ /* mbedtls_t_udbl defined as 128-bit unsigned int */
149
+ typedef __uint128_t mbedtls_t_udbl ;
150
+ #define MBEDTLS_HAVE_UDBL
151
+ #endif /* !MBEDTLS_NO_UDBL_DIVISION */
152
+ #elif defined(MBEDTLS_HAVE_INT64 )
153
+ /* Force 64-bit integers with unknown compiler */
154
+ typedef int64_t mbedtls_mpi_sint ;
155
+ typedef uint64_t mbedtls_mpi_uint ;
156
+ #endif
157
+ #endif /* !MBEDTLS_HAVE_INT32 */
158
+
159
+ #if !defined(MBEDTLS_HAVE_INT64 )
160
+ /* Default to 32-bit compilation */
161
+ #if !defined(MBEDTLS_HAVE_INT32 )
162
+ #define MBEDTLS_HAVE_INT32
163
+ #endif /* !MBEDTLS_HAVE_INT32 */
164
+ typedef int32_t mbedtls_mpi_sint ;
165
+ typedef uint32_t mbedtls_mpi_uint ;
166
+ #if !defined(MBEDTLS_NO_UDBL_DIVISION )
167
+ typedef uint64_t mbedtls_t_udbl ;
168
+ #define MBEDTLS_HAVE_UDBL
169
+ #endif /* !MBEDTLS_NO_UDBL_DIVISION */
170
+ #endif /* !MBEDTLS_HAVE_INT64 */
136
171
137
172
#ifdef __cplusplus
138
173
extern "C" {
@@ -340,7 +375,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
340
375
341
376
#if defined(MBEDTLS_FS_IO )
342
377
/**
343
- * \brief Read X from an opened file
378
+ * \brief Read MPI from a line in an opened file
344
379
*
345
380
* \param X Destination MPI
346
381
* \param radix Input numeric base
@@ -349,6 +384,15 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
349
384
* \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
350
385
* the file read buffer is too small or a
351
386
* MBEDTLS_ERR_MPI_XXX error code
387
+ *
388
+ * \note On success, this function advances the file stream
389
+ * to the end of the current line or to EOF.
390
+ *
391
+ * The function returns 0 on an empty line.
392
+ *
393
+ * Leading whitespaces are ignored, as is a
394
+ * '0x' prefix for radix 16.
395
+ *
352
396
*/
353
397
int mbedtls_mpi_read_file ( mbedtls_mpi * X , int radix , FILE * fin );
354
398
@@ -665,8 +709,8 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B
665
709
*
666
710
* \return 0 if successful,
667
711
* MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
668
- * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or nil
669
- MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N
712
+ * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is <= 1,
713
+ MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N.
670
714
*/
671
715
int mbedtls_mpi_inv_mod ( mbedtls_mpi * X , const mbedtls_mpi * A , const mbedtls_mpi * N );
672
716
0 commit comments