123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- #ifndef POLARSSL_BIGNUM_H
- #define POLARSSL_BIGNUM_H
- #ifdef PRINTF_STDLIB
- #include <stdio.h>
- #endif
- #ifdef PRINTF_CUSTOM
- #include "tinystdio.h"
- #endif
- #include <string.h>
- #define POLARSSL_ERR_MPI_FILE_IO_ERROR -0x0002
- #define POLARSSL_ERR_MPI_BAD_INPUT_DATA -0x0004
- #define POLARSSL_ERR_MPI_INVALID_CHARACTER -0x0006
- #define POLARSSL_ERR_MPI_BUFFER_TOO_SMALL -0x0008
- #define POLARSSL_ERR_MPI_NEGATIVE_VALUE -0x000A
- #define POLARSSL_ERR_MPI_DIVISION_BY_ZERO -0x000C
- #define POLARSSL_ERR_MPI_NOT_ACCEPTABLE -0x000E
- #define MPI_CHK(f) if( ( ret = f ) != 0 ) goto cleanup
- #define POLARSSL_MPI_MAX_LIMBS 10000
- #if defined(POLARSSL_HAVE_INT8)
- typedef signed char t_sint;
- typedef unsigned char t_uint;
- typedef unsigned short t_udbl;
- #else
- #if defined(POLARSSL_HAVE_INT16)
- typedef signed short t_sint;
- typedef unsigned short t_uint;
- typedef unsigned long t_udbl;
- #else
- typedef signed long t_sint;
- typedef unsigned long t_uint;
- #if defined(_MSC_VER) && defined(_M_IX86)
- typedef unsigned __int64 t_udbl;
- #else
- #if defined(__amd64__) || defined(__x86_64__) || \
- defined(__ppc64__) || defined(__powerpc64__) || \
- defined(__ia64__) || defined(__alpha__)
- typedef unsigned int t_udbl __attribute__((mode(TI)));
- #else
- #if defined(POLARSSL_HAVE_LONGLONG)
- typedef unsigned long long t_udbl;
- #endif
- #endif
- #endif
- #endif
- #endif
- typedef struct
- {
- int s;
- size_t n;
- t_uint *p;
- }
- mpi;
- #ifdef __cplusplus
- extern "C" {
- #endif
- void mpi_init( mpi *X );
- void mpi_free( mpi *X );
- int mpi_grow( mpi *X, size_t nblimbs );
- int mpi_copy( mpi *X, const mpi *Y );
- void mpi_swap( mpi *X, mpi *Y );
- int mpi_lset( mpi *X, t_sint z );
- int mpi_get_bit( mpi *X, size_t pos );
- int mpi_set_bit( mpi *X, size_t pos, unsigned char val );
- size_t mpi_lsb( const mpi *X );
- size_t mpi_msb( const mpi *X );
- size_t mpi_size( const mpi *X );
- int mpi_read_string( mpi *X, int radix, const char *s );
- int mpi_write_string( const mpi *X, int radix, char *s, size_t *slen );
- int mpi_read_binary( mpi *X, const unsigned char *buf, size_t buflen );
- int mpi_write_binary( const mpi *X, unsigned char *buf, size_t buflen );
- int mpi_shift_l( mpi *X, size_t count );
- int mpi_shift_r( mpi *X, size_t count );
- int mpi_cmp_abs( const mpi *X, const mpi *Y );
- int mpi_cmp_mpi( const mpi *X, const mpi *Y );
- int mpi_cmp_int( const mpi *X, t_sint z );
- int mpi_add_abs( mpi *X, const mpi *A, const mpi *B );
- int mpi_sub_abs( mpi *X, const mpi *A, const mpi *B );
- int mpi_add_mpi( mpi *X, const mpi *A, const mpi *B );
- int mpi_sub_mpi( mpi *X, const mpi *A, const mpi *B );
- int mpi_add_int( mpi *X, const mpi *A, t_sint b );
- int mpi_sub_int( mpi *X, const mpi *A, t_sint b );
- int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B );
- int mpi_mul_int( mpi *X, const mpi *A, t_sint b );
- int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B );
- int mpi_div_int( mpi *Q, mpi *R, const mpi *A, t_sint b );
- int mpi_mod_mpi( mpi *R, const mpi *A, const mpi *B );
- int mpi_mod_int( t_uint *r, const mpi *A, t_sint b );
- int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR );
- int mpi_fill_random( mpi *X, size_t size, int (*f_rng)(void *), void *p_rng );
- int mpi_gcd( mpi *G, const mpi *A, const mpi *B );
- int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N );
- int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng );
- int mpi_gen_prime( mpi *X, size_t nbits, int dh_flag,
- int (*f_rng)(void *), void *p_rng );
- int mpi_self_test( int verbose );
- #ifdef __cplusplus
- }
- #endif
- #endif
|