Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file bignum.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief Multi-precision integer library |
| 5 | * |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2010, Brainspark B.V. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 10 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 11 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 12 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 27 | #ifndef POLARSSL_BIGNUM_H |
| 28 | #define POLARSSL_BIGNUM_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 29 | |
| 30 | #include <stdio.h> |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 31 | #include <string.h> |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 32 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 33 | #define POLARSSL_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */ |
| 34 | #define POLARSSL_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */ |
| 35 | #define POLARSSL_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */ |
| 36 | #define POLARSSL_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The output buffer is too small to write too. */ |
| 37 | #define POLARSSL_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */ |
| 38 | #define POLARSSL_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */ |
| 39 | #define POLARSSL_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 40 | |
| 41 | #define MPI_CHK(f) if( ( ret = f ) != 0 ) goto cleanup |
| 42 | |
| 43 | /* |
Paul Bakker | f968857 | 2011-05-05 10:00:45 +0000 | [diff] [blame] | 44 | * Maximum size MPIs are allowed to grow to in number of limbs. |
| 45 | */ |
| 46 | #define POLARSSL_MPI_MAX_LIMBS 10000 |
| 47 | |
| 48 | /* |
Paul Bakker | b6d5f08 | 2011-11-25 11:52:11 +0000 | [diff] [blame] | 49 | * Maximum window size used for modular exponentiation. Default: 6 |
| 50 | * Minimum value: 1. Maximum value: 6. |
| 51 | * |
| 52 | * Result is an array of ( 2 << POLARSSL_MPI_WINDOW_SIZE ) MPIs used |
| 53 | * for the sliding window calculation. (So 64 by default) |
| 54 | * |
| 55 | * Reduction in size, reduces speed. |
| 56 | */ |
| 57 | #define POLARSSL_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */ |
| 58 | |
| 59 | /* |
Paul Bakker | fe3256e | 2011-11-25 12:11:43 +0000 | [diff] [blame^] | 60 | * Maximum size of MPIs allowed in bits and bytes for user-MPIs. |
| 61 | * ( Default: 512 bytes => 4096 bits ) |
| 62 | * |
| 63 | * Note: Calculations can results temporarily in larger MPIs. So the number |
| 64 | * of limbs required (POLARSSL_MPI_MAX_LIMBS) is higher. |
| 65 | */ |
| 66 | #define POLARSSL_MPI_MAX_SIZE 512 /**< Maximum number of bytes for usable MPIs. */ |
| 67 | #define POLARSSL_MPI_MAX_BITS ( 8 * POLARSSL_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */ |
| 68 | |
| 69 | /* |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 70 | * Define the base integer type, architecture-wise |
| 71 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 72 | #if defined(POLARSSL_HAVE_INT8) |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 73 | typedef signed char t_sint; |
| 74 | typedef unsigned char t_uint; |
| 75 | typedef unsigned short t_udbl; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 76 | #else |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 77 | #if defined(POLARSSL_HAVE_INT16) |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 78 | typedef signed short t_sint; |
| 79 | typedef unsigned short t_uint; |
| 80 | typedef unsigned long t_udbl; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 81 | #else |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 82 | typedef signed long t_sint; |
| 83 | typedef unsigned long t_uint; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 84 | #if defined(_MSC_VER) && defined(_M_IX86) |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 85 | typedef unsigned __int64 t_udbl; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 86 | #else |
| 87 | #if defined(__amd64__) || defined(__x86_64__) || \ |
| 88 | defined(__ppc64__) || defined(__powerpc64__) || \ |
| 89 | defined(__ia64__) || defined(__alpha__) |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 90 | typedef unsigned int t_udbl __attribute__((mode(TI))); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | #else |
Paul Bakker | 1a9382e | 2009-07-11 16:35:32 +0000 | [diff] [blame] | 92 | #if defined(POLARSSL_HAVE_LONGLONG) |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 93 | typedef unsigned long long t_udbl; |
Paul Bakker | 1a9382e | 2009-07-11 16:35:32 +0000 | [diff] [blame] | 94 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 95 | #endif |
| 96 | #endif |
| 97 | #endif |
| 98 | #endif |
| 99 | |
| 100 | /** |
| 101 | * \brief MPI structure |
| 102 | */ |
| 103 | typedef struct |
| 104 | { |
| 105 | int s; /*!< integer sign */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 106 | size_t n; /*!< total # of limbs */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 107 | t_uint *p; /*!< pointer to limbs */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 108 | } |
| 109 | mpi; |
| 110 | |
| 111 | #ifdef __cplusplus |
| 112 | extern "C" { |
| 113 | #endif |
| 114 | |
| 115 | /** |
Paul Bakker | 6c591fa | 2011-05-05 11:49:20 +0000 | [diff] [blame] | 116 | * \brief Initialize one MPI |
| 117 | * |
| 118 | * \param X One MPI to initialize. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | */ |
Paul Bakker | 6c591fa | 2011-05-05 11:49:20 +0000 | [diff] [blame] | 120 | void mpi_init( mpi *X ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 121 | |
| 122 | /** |
Paul Bakker | 6c591fa | 2011-05-05 11:49:20 +0000 | [diff] [blame] | 123 | * \brief Unallocate one MPI |
| 124 | * |
| 125 | * \param X One MPI to unallocate. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 126 | */ |
Paul Bakker | 6c591fa | 2011-05-05 11:49:20 +0000 | [diff] [blame] | 127 | void mpi_free( mpi *X ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * \brief Enlarge to the specified number of limbs |
| 131 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 132 | * \param X MPI to grow |
| 133 | * \param nblimbs The target number of limbs |
| 134 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 | * \return 0 if successful, |
| 136 | * 1 if memory allocation failed |
| 137 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 138 | int mpi_grow( mpi *X, size_t nblimbs ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * \brief Copy the contents of Y into X |
| 142 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 143 | * \param X Destination MPI |
| 144 | * \param Y Source MPI |
| 145 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 146 | * \return 0 if successful, |
| 147 | * 1 if memory allocation failed |
| 148 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 149 | int mpi_copy( mpi *X, const mpi *Y ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * \brief Swap the contents of X and Y |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 153 | * |
| 154 | * \param X First MPI value |
| 155 | * \param Y Second MPI value |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 156 | */ |
| 157 | void mpi_swap( mpi *X, mpi *Y ); |
| 158 | |
| 159 | /** |
| 160 | * \brief Set value from integer |
| 161 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 162 | * \param X MPI to set |
| 163 | * \param z Value to use |
| 164 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | * \return 0 if successful, |
| 166 | * 1 if memory allocation failed |
| 167 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 168 | int mpi_lset( mpi *X, t_sint z ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 169 | |
Paul Bakker | 2f5947e | 2011-05-18 15:47:11 +0000 | [diff] [blame] | 170 | /* |
| 171 | * \brief Get a specific bit from X |
| 172 | * |
| 173 | * \param X MPI to use |
| 174 | * \param pos Zero-based index of the bit in X |
| 175 | * |
| 176 | * \return Either a 0 or a 1 |
| 177 | */ |
| 178 | int mpi_get_bit( mpi *X, size_t pos ); |
| 179 | |
| 180 | /* |
| 181 | * \brief Set a bit of X to a specific value of 0 or 1 |
| 182 | * |
| 183 | * \note Will grow X if necessary to set a bit to 1 in a not yet |
| 184 | * existing limb. Will not grow if bit should be set to 0 |
| 185 | * |
| 186 | * \param X MPI to use |
| 187 | * \param pos Zero-based index of the bit in X |
| 188 | * \param val The value to set the bit to (0 or 1) |
| 189 | * |
| 190 | * \return 0 if successful, |
| 191 | * 1 if memory allocation failed, |
| 192 | * POLARSSL_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1 |
| 193 | */ |
| 194 | int mpi_set_bit( mpi *X, size_t pos, unsigned char val ); |
| 195 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 196 | /** |
| 197 | * \brief Return the number of least significant bits |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 198 | * |
| 199 | * \param X MPI to use |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 200 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 201 | size_t mpi_lsb( const mpi *X ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * \brief Return the number of most significant bits |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 205 | * |
| 206 | * \param X MPI to use |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 207 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 208 | size_t mpi_msb( const mpi *X ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * \brief Return the total size in bytes |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 212 | * |
| 213 | * \param X MPI to use |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 214 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 215 | size_t mpi_size( const mpi *X ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * \brief Import from an ASCII string |
| 219 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 220 | * \param X Destination MPI |
| 221 | * \param radix Input numeric base |
| 222 | * \param s Null-terminated string buffer |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 223 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 224 | * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 225 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 226 | int mpi_read_string( mpi *X, int radix, const char *s ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * \brief Export into an ASCII string |
| 230 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 231 | * \param X Source MPI |
| 232 | * \param radix Output numeric base |
| 233 | * \param s String buffer |
| 234 | * \param slen String buffer size |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 235 | * |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 236 | * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code. |
| 237 | * *slen is always updated to reflect the amount |
| 238 | * of data that has (or would have) been written. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 239 | * |
| 240 | * \note Call this function with *slen = 0 to obtain the |
| 241 | * minimum required buffer size in *slen. |
| 242 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 243 | int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * \brief Read X from an opened file |
| 247 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 248 | * \param X Destination MPI |
| 249 | * \param radix Input numeric base |
| 250 | * \param fin Input file handle |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 251 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 252 | * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 253 | */ |
| 254 | int mpi_read_file( mpi *X, int radix, FILE *fin ); |
| 255 | |
| 256 | /** |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 257 | * \brief Write X into an opened file, or stdout if fout is NULL |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 258 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 259 | * \param p Prefix, can be NULL |
| 260 | * \param X Source MPI |
| 261 | * \param radix Output numeric base |
| 262 | * \param fout Output file handle (can be NULL) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 263 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 264 | * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 265 | * |
| 266 | * \note Set fout == NULL to print X on the console. |
| 267 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 268 | int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * \brief Import X from unsigned binary data, big endian |
| 272 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 273 | * \param X Destination MPI |
| 274 | * \param buf Input buffer |
| 275 | * \param buflen Input buffer size |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 276 | * |
| 277 | * \return 0 if successful, |
| 278 | * 1 if memory allocation failed |
| 279 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 280 | int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 281 | |
| 282 | /** |
| 283 | * \brief Export X into unsigned binary data, big endian |
| 284 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 285 | * \param X Source MPI |
| 286 | * \param buf Output buffer |
| 287 | * \param buflen Output buffer size |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 288 | * |
| 289 | * \return 0 if successful, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 290 | * POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 291 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 292 | int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 293 | |
| 294 | /** |
| 295 | * \brief Left-shift: X <<= count |
| 296 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 297 | * \param X MPI to shift |
| 298 | * \param count Amount to shift |
| 299 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 300 | * \return 0 if successful, |
| 301 | * 1 if memory allocation failed |
| 302 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 303 | int mpi_shift_l( mpi *X, size_t count ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * \brief Right-shift: X >>= count |
| 307 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 308 | * \param X MPI to shift |
| 309 | * \param count Amount to shift |
| 310 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 311 | * \return 0 if successful, |
| 312 | * 1 if memory allocation failed |
| 313 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 314 | int mpi_shift_r( mpi *X, size_t count ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * \brief Compare unsigned values |
| 318 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 319 | * \param X Left-hand MPI |
| 320 | * \param Y Right-hand MPI |
| 321 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 322 | * \return 1 if |X| is greater than |Y|, |
| 323 | * -1 if |X| is lesser than |Y| or |
| 324 | * 0 if |X| is equal to |Y| |
| 325 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 326 | int mpi_cmp_abs( const mpi *X, const mpi *Y ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 327 | |
| 328 | /** |
| 329 | * \brief Compare signed values |
| 330 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 331 | * \param X Left-hand MPI |
| 332 | * \param Y Right-hand MPI |
| 333 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 334 | * \return 1 if X is greater than Y, |
| 335 | * -1 if X is lesser than Y or |
| 336 | * 0 if X is equal to Y |
| 337 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 338 | int mpi_cmp_mpi( const mpi *X, const mpi *Y ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * \brief Compare signed values |
| 342 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 343 | * \param X Left-hand MPI |
| 344 | * \param z The integer value to compare to |
| 345 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 346 | * \return 1 if X is greater than z, |
| 347 | * -1 if X is lesser than z or |
| 348 | * 0 if X is equal to z |
| 349 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 350 | int mpi_cmp_int( const mpi *X, t_sint z ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * \brief Unsigned addition: X = |A| + |B| |
| 354 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 355 | * \param X Destination MPI |
| 356 | * \param A Left-hand MPI |
| 357 | * \param B Right-hand MPI |
| 358 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 359 | * \return 0 if successful, |
| 360 | * 1 if memory allocation failed |
| 361 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 362 | int mpi_add_abs( mpi *X, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 363 | |
| 364 | /** |
| 365 | * \brief Unsigned substraction: X = |A| - |B| |
| 366 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 367 | * \param X Destination MPI |
| 368 | * \param A Left-hand MPI |
| 369 | * \param B Right-hand MPI |
| 370 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 371 | * \return 0 if successful, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 372 | * POLARSSL_ERR_MPI_NEGATIVE_VALUE if B is greater than A |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 373 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 374 | int mpi_sub_abs( mpi *X, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * \brief Signed addition: X = A + B |
| 378 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 379 | * \param X Destination MPI |
| 380 | * \param A Left-hand MPI |
| 381 | * \param B Right-hand MPI |
| 382 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 383 | * \return 0 if successful, |
| 384 | * 1 if memory allocation failed |
| 385 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 386 | int mpi_add_mpi( mpi *X, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 387 | |
| 388 | /** |
| 389 | * \brief Signed substraction: X = A - B |
| 390 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 391 | * \param X Destination MPI |
| 392 | * \param A Left-hand MPI |
| 393 | * \param B Right-hand MPI |
| 394 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 395 | * \return 0 if successful, |
| 396 | * 1 if memory allocation failed |
| 397 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 398 | int mpi_sub_mpi( mpi *X, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 399 | |
| 400 | /** |
| 401 | * \brief Signed addition: X = A + b |
| 402 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 403 | * \param X Destination MPI |
| 404 | * \param A Left-hand MPI |
| 405 | * \param b The integer value to add |
| 406 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 407 | * \return 0 if successful, |
| 408 | * 1 if memory allocation failed |
| 409 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 410 | int mpi_add_int( mpi *X, const mpi *A, t_sint b ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 411 | |
| 412 | /** |
| 413 | * \brief Signed substraction: X = A - b |
| 414 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 415 | * \param X Destination MPI |
| 416 | * \param A Left-hand MPI |
| 417 | * \param b The integer value to subtract |
| 418 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 419 | * \return 0 if successful, |
| 420 | * 1 if memory allocation failed |
| 421 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 422 | int mpi_sub_int( mpi *X, const mpi *A, t_sint b ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 423 | |
| 424 | /** |
| 425 | * \brief Baseline multiplication: X = A * B |
| 426 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 427 | * \param X Destination MPI |
| 428 | * \param A Left-hand MPI |
| 429 | * \param B Right-hand MPI |
| 430 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 431 | * \return 0 if successful, |
| 432 | * 1 if memory allocation failed |
| 433 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 434 | int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 435 | |
| 436 | /** |
| 437 | * \brief Baseline multiplication: X = A * b |
Paul Bakker | ce40a6d | 2009-06-23 19:46:08 +0000 | [diff] [blame] | 438 | * Note: b is an unsigned integer type, thus |
| 439 | * Negative values of b are ignored. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 440 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 441 | * \param X Destination MPI |
| 442 | * \param A Left-hand MPI |
| 443 | * \param b The integer value to multiply with |
| 444 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 445 | * \return 0 if successful, |
| 446 | * 1 if memory allocation failed |
| 447 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 448 | int mpi_mul_int( mpi *X, const mpi *A, t_sint b ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 449 | |
| 450 | /** |
| 451 | * \brief Division by mpi: A = Q * B + R |
| 452 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 453 | * \param Q Destination MPI for the quotient |
| 454 | * \param R Destination MPI for the rest value |
| 455 | * \param A Left-hand MPI |
| 456 | * \param B Right-hand MPI |
| 457 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 458 | * \return 0 if successful, |
| 459 | * 1 if memory allocation failed, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 460 | * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 461 | * |
| 462 | * \note Either Q or R can be NULL. |
| 463 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 464 | int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 465 | |
| 466 | /** |
| 467 | * \brief Division by int: A = Q * b + R |
| 468 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 469 | * \param Q Destination MPI for the quotient |
| 470 | * \param R Destination MPI for the rest value |
| 471 | * \param A Left-hand MPI |
| 472 | * \param b Integer to divide by |
| 473 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 474 | * \return 0 if successful, |
| 475 | * 1 if memory allocation failed, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 476 | * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 477 | * |
| 478 | * \note Either Q or R can be NULL. |
| 479 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 480 | int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_sint b ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 481 | |
| 482 | /** |
| 483 | * \brief Modulo: R = A mod B |
| 484 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 485 | * \param R Destination MPI for the rest value |
| 486 | * \param A Left-hand MPI |
| 487 | * \param B Right-hand MPI |
| 488 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 489 | * \return 0 if successful, |
| 490 | * 1 if memory allocation failed, |
Paul Bakker | ce40a6d | 2009-06-23 19:46:08 +0000 | [diff] [blame] | 491 | * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0, |
| 492 | * POLARSSL_ERR_MPI_NEGATIVE_VALUE if B < 0 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 493 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 494 | int mpi_mod_mpi( mpi *R, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * \brief Modulo: r = A mod b |
| 498 | * |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 499 | * \param r Destination t_uint |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 500 | * \param A Left-hand MPI |
| 501 | * \param b Integer to divide by |
| 502 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 503 | * \return 0 if successful, |
| 504 | * 1 if memory allocation failed, |
Paul Bakker | ce40a6d | 2009-06-23 19:46:08 +0000 | [diff] [blame] | 505 | * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0, |
| 506 | * POLARSSL_ERR_MPI_NEGATIVE_VALUE if b < 0 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 507 | */ |
Paul Bakker | a755ca1 | 2011-04-24 09:11:17 +0000 | [diff] [blame] | 508 | int mpi_mod_int( t_uint *r, const mpi *A, t_sint b ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 509 | |
| 510 | /** |
| 511 | * \brief Sliding-window exponentiation: X = A^E mod N |
| 512 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 513 | * \param X Destination MPI |
| 514 | * \param A Left-hand MPI |
| 515 | * \param E Exponent MPI |
| 516 | * \param N Modular MPI |
| 517 | * \param _RR Speed-up MPI used for recalculations |
| 518 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 519 | * \return 0 if successful, |
| 520 | * 1 if memory allocation failed, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 521 | * POLARSSL_ERR_MPI_BAD_INPUT_DATA if N is negative or even |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 522 | * |
| 523 | * \note _RR is used to avoid re-computing R*R mod N across |
| 524 | * multiple calls, which speeds up things a bit. It can |
| 525 | * be set to NULL if the extra performance is unneeded. |
| 526 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 527 | int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 528 | |
| 529 | /** |
Paul Bakker | 287781a | 2011-03-26 13:18:49 +0000 | [diff] [blame] | 530 | * \brief Fill an MPI X with size bytes of random |
| 531 | * |
| 532 | * \param X Destination MPI |
| 533 | * \param size Size in bytes |
| 534 | * \param f_rng RNG function |
| 535 | * \param p_rng RNG parameter |
| 536 | * |
| 537 | * \return 0 if successful, |
| 538 | * 1 if memory allocation failed |
| 539 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 540 | int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng ); |
Paul Bakker | 287781a | 2011-03-26 13:18:49 +0000 | [diff] [blame] | 541 | |
| 542 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 543 | * \brief Greatest common divisor: G = gcd(A, B) |
| 544 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 545 | * \param G Destination MPI |
| 546 | * \param A Left-hand MPI |
| 547 | * \param B Right-hand MPI |
| 548 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 549 | * \return 0 if successful, |
| 550 | * 1 if memory allocation failed |
| 551 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 552 | int mpi_gcd( mpi *G, const mpi *A, const mpi *B ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 553 | |
| 554 | /** |
| 555 | * \brief Modular inverse: X = A^-1 mod N |
| 556 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 557 | * \param X Destination MPI |
| 558 | * \param A Left-hand MPI |
| 559 | * \param N Right-hand MPI |
| 560 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 561 | * \return 0 if successful, |
| 562 | * 1 if memory allocation failed, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 563 | * POLARSSL_ERR_MPI_BAD_INPUT_DATA if N is negative or nil |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 564 | POLARSSL_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 565 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 566 | int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 567 | |
| 568 | /** |
| 569 | * \brief Miller-Rabin primality test |
| 570 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 571 | * \param X MPI to check |
| 572 | * \param f_rng RNG function |
| 573 | * \param p_rng RNG parameter |
| 574 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 575 | * \return 0 if successful (probably prime), |
| 576 | * 1 if memory allocation failed, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 577 | * POLARSSL_ERR_MPI_NOT_ACCEPTABLE if X is not prime |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 578 | */ |
| 579 | int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ); |
| 580 | |
| 581 | /** |
| 582 | * \brief Prime number generation |
| 583 | * |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 584 | * \param X Destination MPI |
Paul Bakker | fe3256e | 2011-11-25 12:11:43 +0000 | [diff] [blame^] | 585 | * \param nbits Required size of X in bits ( 3 <= nbits <= POLARSSL_MPI_MAX_BITS ) |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 586 | * \param dh_flag If 1, then (X-1)/2 will be prime too |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 587 | * \param f_rng RNG function |
| 588 | * \param p_rng RNG parameter |
| 589 | * |
| 590 | * \return 0 if successful (probably prime), |
| 591 | * 1 if memory allocation failed, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 592 | * POLARSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 593 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 594 | int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 595 | int (*f_rng)(void *), void *p_rng ); |
| 596 | |
| 597 | /** |
| 598 | * \brief Checkup routine |
| 599 | * |
| 600 | * \return 0 if successful, or 1 if the test failed |
| 601 | */ |
| 602 | int mpi_self_test( int verbose ); |
| 603 | |
| 604 | #ifdef __cplusplus |
| 605 | } |
| 606 | #endif |
| 607 | |
| 608 | #endif /* bignum.h */ |