raw
ch1_mpi                 1 /* mpi.h  -  Multi Precision Integers
ch1_mpi 2 * Modified by No Such Labs. (C) 2015. See README.
eucrypt_ch4_rpng 3 * Modified by S.MG, 2018. Added mpi_get_alloced, function for retrieving currently allocated number of limbs.
ch1_mpi 4 *
ch1_mpi 5 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
ch1_mpi 6 * SHA256(gnupg-1.4.10.tar.gz):
ch1_mpi 7 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
ch1_mpi 8 * (C) 1994-2005 Free Software Foundation, Inc.
ch1_mpi 9 *
ch1_mpi 10 * This program is free software: you can redistribute it and/or modify
ch1_mpi 11 * it under the terms of the GNU General Public License as published by
ch1_mpi 12 * the Free Software Foundation, either version 3 of the License, or
ch1_mpi 13 * (at your option) any later version.
ch1_mpi 14 *
ch1_mpi 15 * This program is distributed in the hope that it will be useful,
ch1_mpi 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ch1_mpi 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ch1_mpi 18 * GNU General Public License for more details.
ch1_mpi 19 *
ch1_mpi 20 * You should have received a copy of the GNU General Public License
ch1_mpi 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ch1_mpi 22 */
ch1_mpi 23
ch1_mpi 24 #ifndef G10_MPI_H
ch1_mpi 25 #define G10_MPI_H
ch1_mpi 26
ch1_mpi 27 #include <stdio.h>
ch1_mpi 28 #include "knobs.h"
ch1_mpi 29 #include "types.h"
ch1_mpi 30 #include "memory.h"
ch1_mpi 31
ch1_mpi 32 #ifndef EXTERN_UNLESS_MAIN_MODULE
ch1_mpi 33 #define EXTERN_UNLESS_MAIN_MODULE
ch1_mpi 34 #endif
ch1_mpi 35
ch1_mpi 36 #define DBG_MPI mpi_debug_mode
ch1_mpi 37 EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode;
ch1_mpi 38
ch1_mpi 39
ch1_mpi 40 struct gcry_mpi;
ch1_mpi 41 typedef struct gcry_mpi *MPI;
ch1_mpi 42
ch1_mpi 43
ch1_mpi 44 /*-- mpiutil.c --*/
ch1_mpi 45
ch1_mpi 46 #ifdef M_DEBUG
ch1_mpi 47 #define mpi_alloc(n) mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
ch1_mpi 48 #define mpi_alloc_secure(n) mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
ch1_mpi 49 #define mpi_alloc_like(n) mpi_debug_alloc_like((n), M_DBGINFO( __LINE__ ) )
ch1_mpi 50 #define mpi_free(a) mpi_debug_free((a), M_DBGINFO(__LINE__) )
ch1_mpi 51 #define mpi_resize(a,b) mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
ch1_mpi 52 #define mpi_copy(a) mpi_debug_copy((a), M_DBGINFO(__LINE__) )
ch1_mpi 53 MPI mpi_debug_alloc( unsigned nlimbs, const char *info );
ch1_mpi 54 MPI mpi_debug_alloc_secure( unsigned nlimbs, const char *info );
ch1_mpi 55 MPI mpi_debug_alloc_like( MPI a, const char *info );
ch1_mpi 56 void mpi_debug_free( MPI a, const char *info );
ch1_mpi 57 void mpi_debug_resize( MPI a, unsigned nlimbs, const char *info );
ch1_mpi 58 MPI mpi_debug_copy( MPI a, const char *info );
ch1_mpi 59 #else
ch1_mpi 60 MPI mpi_alloc( unsigned nlimbs );
ch1_mpi 61 MPI mpi_alloc_secure( unsigned nlimbs );
ch1_mpi 62 MPI mpi_alloc_like( MPI a );
ch1_mpi 63 void mpi_free( MPI a );
ch1_mpi 64 void mpi_resize( MPI a, unsigned nlimbs );
ch1_mpi 65 MPI mpi_copy( MPI a );
ch1_mpi 66 #endif
ch1_mpi 67 #define mpi_is_opaque(a) ((a) && (mpi_get_flags (a)&4))
ch1_mpi 68 MPI mpi_set_opaque( MPI a, void *p, unsigned int len );
ch1_mpi 69 void *mpi_get_opaque( MPI a, unsigned int *len );
ch1_mpi 70 #define mpi_is_secure(a) ((a) && (mpi_get_flags (a)&1))
ch1_mpi 71 void mpi_set_secure( MPI a );
ch1_mpi 72 void mpi_clear( MPI a );
ch1_mpi 73 void mpi_set( MPI w, MPI u);
ch1_mpi 74 void mpi_set_ui( MPI w, ulong u);
ch1_mpi 75 MPI mpi_alloc_set_ui( unsigned long u);
ch1_mpi 76 void mpi_m_check( MPI a );
ch1_mpi 77 void mpi_swap( MPI a, MPI b);
ch1_mpi 78 int mpi_get_nlimbs (MPI a);
eucrypt_ch4_rpng 79 int mpi_get_alloced (MPI a); /* returns the allocated memory space for this MPI, in number of limbs */
ch1_mpi 80 int mpi_is_neg (MPI a);
ch1_mpi 81 unsigned int mpi_nlimb_hint_from_nbytes (unsigned int nbytes);
ch1_mpi 82 unsigned int mpi_nlimb_hint_from_nbits (unsigned int nbits);
ch1_mpi 83 unsigned int mpi_get_flags (MPI a);
ch1_mpi 84
ch1_mpi 85 /*-- mpicoder.c --*/
ch1_mpi 86 MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure);
ch1_mpi 87 int mpi_fromstr(MPI val, const char *str);
ch1_mpi 88 int mpi_print( FILE *fp, MPI a, int mode );
ch1_mpi 89 //void g10_log_mpidump( const char *text, MPI a );
ch1_mpi 90 byte *mpi_get_buffer( MPI a, unsigned *nbytes, int *sign );
ch1_mpi 91 byte *mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign );
ch1_mpi 92 void mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign );
ch1_mpi 93
ch1_mpi 94 #define log_mpidump g10_log_mpidump
ch1_mpi 95
ch1_mpi 96 /*-- mpi-add.c --*/
ch1_mpi 97 void mpi_add_ui(MPI w, MPI u, ulong v );
ch1_mpi 98 void mpi_add(MPI w, MPI u, MPI v);
ch1_mpi 99 void mpi_addm(MPI w, MPI u, MPI v, MPI m);
ch1_mpi 100 void mpi_sub_ui(MPI w, MPI u, ulong v );
ch1_mpi 101 void mpi_sub( MPI w, MPI u, MPI v);
ch1_mpi 102 void mpi_subm( MPI w, MPI u, MPI v, MPI m);
ch1_mpi 103
ch1_mpi 104 /*-- mpi-mul.c --*/
ch1_mpi 105 void mpi_mul_ui(MPI w, MPI u, ulong v );
ch1_mpi 106 void mpi_mul_2exp( MPI w, MPI u, ulong cnt);
ch1_mpi 107 void mpi_mul( MPI w, MPI u, MPI v);
ch1_mpi 108 void mpi_mulm( MPI w, MPI u, MPI v, MPI m);
ch1_mpi 109
ch1_mpi 110 /*-- mpi-div.c --*/
ch1_mpi 111 ulong mpi_fdiv_r_ui( MPI rem, MPI dividend, ulong divisor );
ch1_mpi 112 void mpi_fdiv_r( MPI rem, MPI dividend, MPI divisor );
ch1_mpi 113 void mpi_fdiv_q( MPI quot, MPI dividend, MPI divisor );
ch1_mpi 114 void mpi_fdiv_qr( MPI quot, MPI rem, MPI dividend, MPI divisor );
ch1_mpi 115 void mpi_tdiv_r( MPI rem, MPI num, MPI den);
ch1_mpi 116 void mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den);
ch1_mpi 117 void mpi_tdiv_q_2exp( MPI w, MPI u, unsigned count );
ch1_mpi 118 int mpi_divisible_ui(MPI dividend, ulong divisor );
ch1_mpi 119
ch1_mpi 120 /*-- mpi-gcd.c --*/
ch1_mpi 121 int mpi_gcd( MPI g, MPI a, MPI b );
ch1_mpi 122
ch1_mpi 123 /*-- mpi-pow.c --*/
ch1_mpi 124 void mpi_pow( MPI w, MPI u, MPI v);
ch1_mpi 125 void mpi_powm( MPI res, MPI base, MPI exponent, MPI mod);
ch1_mpi 126
ch1_mpi 127 /*-- mpi-mpow.c --*/
ch1_mpi 128 void mpi_mulpowm( MPI res, MPI *basearray, MPI *exparray, MPI mod);
ch1_mpi 129
ch1_mpi 130 /*-- mpi-cmp.c --*/
ch1_mpi 131 int mpi_cmp_ui( MPI u, ulong v );
ch1_mpi 132 int mpi_cmp( MPI u, MPI v );
ch1_mpi 133
ch1_mpi 134 /*-- mpi-scan.c --*/
ch1_mpi 135 int mpi_getbyte( MPI a, unsigned idx );
ch1_mpi 136 void mpi_putbyte( MPI a, unsigned idx, int value );
ch1_mpi 137 unsigned mpi_trailing_zeros( MPI a );
ch1_mpi 138
ch1_mpi 139 /*-- mpi-bit.c --*/
ch1_mpi 140 void mpi_normalize( MPI a );
ch1_mpi 141 unsigned mpi_get_nbits( MPI a );
ch1_mpi 142 int mpi_test_bit( MPI a, unsigned n );
ch1_mpi 143 void mpi_set_bit( MPI a, unsigned n );
ch1_mpi 144 void mpi_set_highbit( MPI a, unsigned n );
ch1_mpi 145 void mpi_clear_highbit( MPI a, unsigned n );
ch1_mpi 146 void mpi_clear_bit( MPI a, unsigned n );
ch1_mpi 147 void mpi_rshift( MPI x, MPI a, unsigned n );
ch1_mpi 148
ch1_mpi 149 /*-- mpi-inv.c --*/
ch1_mpi 150 void mpi_invm( MPI x, MPI u, MPI v );
ch1_mpi 151
ch1_mpi 152 #endif /*G10_MPI_H*/