-
+ E539EF777487B66317CD23B7D19F883A9BAB67A9CB984DFB5D1A5DF4575A66CB44B7EC199AC0829B1270EDFA68F182D646CE944C14F5C401654E1E0F68271BAFmpi/include/mpi.h(0 . 0)(1 . 169)
2061 /* mpi.h - Multi Precision Integers
2062 * Copyright (C) 1994, 1996, 1998, 1999,
2063 * 2000, 2001 Free Software Foundation, Inc.
2064 *
2065 * This file is part of GNUPG.
2066 *
2067 * GNUPG is free software; you can redistribute it and/or modify
2068 * it under the terms of the GNU General Public License as published by
2069 * the Free Software Foundation; either version 3 of the License, or
2070 * (at your option) any later version.
2071 *
2072 * GNUPG is distributed in the hope that it will be useful,
2073 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2074 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2075 * GNU General Public License for more details.
2076 *
2077 * You should have received a copy of the GNU General Public License
2078 * along with this program; if not, see <http://www.gnu.org/licenses/>.
2079 *
2080 * Note: This code is heavily based on the GNU MP Library.
2081 * Actually it's the same code with only minor changes in the
2082 * way the data is stored; this is to support the abstraction
2083 * of an optional secure memory allocation which may be used
2084 * to avoid revealing of sensitive data due to paging etc.
2085 * The GNU MP Library itself is published under the LGPL;
2086 * however I decided to publish this code under the plain GPL.
2087 */
2088
2089 #ifndef G10_MPI_H
2090 #define G10_MPI_H
2091
2092 #include <config.h>
2093 #include <stdio.h>
2094 #include "iobuf.h"
2095 #include "types.h"
2096 #include "memory.h"
2097
2098 #ifndef EXTERN_UNLESS_MAIN_MODULE
2099 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
2100 #define EXTERN_UNLESS_MAIN_MODULE extern
2101 #else
2102 #define EXTERN_UNLESS_MAIN_MODULE
2103 #endif
2104 #endif
2105
2106 #define DBG_MPI mpi_debug_mode
2107 EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode;
2108
2109
2110 struct gcry_mpi;
2111 typedef struct gcry_mpi *MPI;
2112
2113
2114 /*-- mpiutil.c --*/
2115
2116 #ifdef M_DEBUG
2117 #define mpi_alloc(n) mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
2118 #define mpi_alloc_secure(n) mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
2119 #define mpi_alloc_like(n) mpi_debug_alloc_like((n), M_DBGINFO( __LINE__ ) )
2120 #define mpi_free(a) mpi_debug_free((a), M_DBGINFO(__LINE__) )
2121 #define mpi_resize(a,b) mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
2122 #define mpi_copy(a) mpi_debug_copy((a), M_DBGINFO(__LINE__) )
2123 MPI mpi_debug_alloc( unsigned nlimbs, const char *info );
2124 MPI mpi_debug_alloc_secure( unsigned nlimbs, const char *info );
2125 MPI mpi_debug_alloc_like( MPI a, const char *info );
2126 void mpi_debug_free( MPI a, const char *info );
2127 void mpi_debug_resize( MPI a, unsigned nlimbs, const char *info );
2128 MPI mpi_debug_copy( MPI a, const char *info );
2129 #else
2130 MPI mpi_alloc( unsigned nlimbs );
2131 MPI mpi_alloc_secure( unsigned nlimbs );
2132 MPI mpi_alloc_like( MPI a );
2133 void mpi_free( MPI a );
2134 void mpi_resize( MPI a, unsigned nlimbs );
2135 MPI mpi_copy( MPI a );
2136 #endif
2137 #define mpi_is_opaque(a) ((a) && (mpi_get_flags (a)&4))
2138 MPI mpi_set_opaque( MPI a, void *p, unsigned int len );
2139 void *mpi_get_opaque( MPI a, unsigned int *len );
2140 #define mpi_is_secure(a) ((a) && (mpi_get_flags (a)&1))
2141 void mpi_set_secure( MPI a );
2142 void mpi_clear( MPI a );
2143 void mpi_set( MPI w, MPI u);
2144 void mpi_set_ui( MPI w, ulong u);
2145 MPI mpi_alloc_set_ui( unsigned long u);
2146 void mpi_m_check( MPI a );
2147 void mpi_swap( MPI a, MPI b);
2148 int mpi_get_nlimbs (MPI a);
2149 int mpi_is_neg (MPI a);
2150 unsigned int mpi_nlimb_hint_from_nbytes (unsigned int nbytes);
2151 unsigned int mpi_nlimb_hint_from_nbits (unsigned int nbits);
2152 unsigned int mpi_get_flags (MPI a);
2153
2154 /*-- mpicoder.c --*/
2155 int mpi_write( IOBUF out, MPI a );
2156 #ifdef M_DEBUG
2157 #define mpi_read(a,b,c) mpi_debug_read((a),(b),(c), M_DBGINFO( __LINE__ ) )
2158 MPI mpi_debug_read(IOBUF inp, unsigned *nread, int secure, const char *info);
2159 #else
2160 MPI mpi_read(IOBUF inp, unsigned *nread, int secure);
2161 #endif
2162 MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure);
2163 int mpi_fromstr(MPI val, const char *str);
2164 int mpi_print( FILE *fp, MPI a, int mode );
2165 void g10_log_mpidump( const char *text, MPI a );
2166 u32 mpi_get_keyid( MPI a, u32 *keyid );
2167 byte *mpi_get_buffer( MPI a, unsigned *nbytes, int *sign );
2168 byte *mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign );
2169 void mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign );
2170
2171 #define log_mpidump g10_log_mpidump
2172
2173 /*-- mpi-add.c --*/
2174 void mpi_add_ui(MPI w, MPI u, ulong v );
2175 void mpi_add(MPI w, MPI u, MPI v);
2176 void mpi_addm(MPI w, MPI u, MPI v, MPI m);
2177 void mpi_sub_ui(MPI w, MPI u, ulong v );
2178 void mpi_sub( MPI w, MPI u, MPI v);
2179 void mpi_subm( MPI w, MPI u, MPI v, MPI m);
2180
2181 /*-- mpi-mul.c --*/
2182 void mpi_mul_ui(MPI w, MPI u, ulong v );
2183 void mpi_mul_2exp( MPI w, MPI u, ulong cnt);
2184 void mpi_mul( MPI w, MPI u, MPI v);
2185 void mpi_mulm( MPI w, MPI u, MPI v, MPI m);
2186
2187 /*-- mpi-div.c --*/
2188 ulong mpi_fdiv_r_ui( MPI rem, MPI dividend, ulong divisor );
2189 void mpi_fdiv_r( MPI rem, MPI dividend, MPI divisor );
2190 void mpi_fdiv_q( MPI quot, MPI dividend, MPI divisor );
2191 void mpi_fdiv_qr( MPI quot, MPI rem, MPI dividend, MPI divisor );
2192 void mpi_tdiv_r( MPI rem, MPI num, MPI den);
2193 void mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den);
2194 void mpi_tdiv_q_2exp( MPI w, MPI u, unsigned count );
2195 int mpi_divisible_ui(MPI dividend, ulong divisor );
2196
2197 /*-- mpi-gcd.c --*/
2198 int mpi_gcd( MPI g, MPI a, MPI b );
2199
2200 /*-- mpi-pow.c --*/
2201 void mpi_pow( MPI w, MPI u, MPI v);
2202 void mpi_powm( MPI res, MPI base, MPI exponent, MPI mod);
2203
2204 /*-- mpi-mpow.c --*/
2205 void mpi_mulpowm( MPI res, MPI *basearray, MPI *exparray, MPI mod);
2206
2207 /*-- mpi-cmp.c --*/
2208 int mpi_cmp_ui( MPI u, ulong v );
2209 int mpi_cmp( MPI u, MPI v );
2210
2211 /*-- mpi-scan.c --*/
2212 int mpi_getbyte( MPI a, unsigned idx );
2213 void mpi_putbyte( MPI a, unsigned idx, int value );
2214 unsigned mpi_trailing_zeros( MPI a );
2215
2216 /*-- mpi-bit.c --*/
2217 void mpi_normalize( MPI a );
2218 unsigned mpi_get_nbits( MPI a );
2219 int mpi_test_bit( MPI a, unsigned n );
2220 void mpi_set_bit( MPI a, unsigned n );
2221 void mpi_set_highbit( MPI a, unsigned n );
2222 void mpi_clear_highbit( MPI a, unsigned n );
2223 void mpi_clear_bit( MPI a, unsigned n );
2224 void mpi_rshift( MPI x, MPI a, unsigned n );
2225
2226 /*-- mpi-inv.c --*/
2227 void mpi_invm( MPI x, MPI u, MPI v );
2228
2229 #endif /*G10_MPI_H*/