/home/dko/projects/mobilec/trunk/src/security/xyssl-0.7/include/xyssl/bignum.h

Go to the documentation of this file.
00001 /* SVN FILE INFO
00002  * $Revision: 174 $ : Last Committed Revision
00003  * $Date: 2008-06-24 10:50:29 -0700 (Tue, 24 Jun 2008) $ : Last Committed Date */
00007 #ifndef _BIGNUM_H
00008 #define _BIGNUM_H
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 #include <stdio.h>
00015 
00016 #include "ssl_conf.h"
00017 
00018 #define ERR_MPI_FILE_IO_ERROR                   0x0002
00019 #define ERR_MPI_INVALID_CHARACTER               0x0004
00020 #define ERR_MPI_INVALID_PARAMETER               0x0006
00021 #define ERR_MPI_BUFFER_TOO_SMALL                0x0008
00022 #define ERR_MPI_NEGATIVE_VALUE                  0x000A
00023 #define ERR_MPI_DIVISION_BY_ZERO                0x000C
00024 #define ERR_MPI_NOT_ACCEPTABLE                  0x000E
00025 
00026 #define CHK(fc) if( ( ret = fc ) != 0 ) goto cleanup
00027 
00028 /*
00029  * Define the base limb type
00030  */
00031 #if defined(HAVE_INT16) /* 8086 */
00032 typedef unsigned int  t_int;
00033 typedef unsigned long t_dbl;
00034 #else
00035   typedef unsigned long t_int;
00036   #if defined(_MSC_VER) && defined(_M_IX86)
00037     typedef unsigned __int64 t_dbl;
00038   #else
00039     #if defined(__amd64__) || defined(__x86_64__)    || \
00040         defined(__ppc64__) || defined(__powerpc64__) || \
00041         defined(__ia64__)  || defined(__alpha__)
00042       typedef unsigned int t_dbl __attribute__((mode(TI)));
00043     #else
00044       typedef unsigned long long t_dbl;
00045     #endif
00046   #endif
00047 #endif
00048 
00049 #define ciL    (int) sizeof(t_int)      /* chars in limb  */
00050 #define biL    (ciL << 3)               /* bits  in limb  */
00051 #define biH    (ciL << 2)               /* half limb size */
00052 
00056 typedef struct
00057 {
00058     int s;              
00059     int n;              
00060     t_int *p;           
00061 }
00062 mpi;
00063 
00067 void mpi_init( mpi *X, ... );
00068 
00072 void mpi_free( mpi *X, ... );
00073 
00080 int mpi_grow( mpi *X, int nblimbs );
00081 
00088 int mpi_copy( mpi *X, mpi *Y );
00089 
00093 void mpi_swap( mpi *X, mpi *Y );
00094 
00101 int mpi_lset( mpi *X, int z );
00102 
00112 int mpi_read_string( mpi *X, int radix, char *s );
00113 
00127 int mpi_write_string( mpi *X, int radix, char *s, int *slen );
00128 
00138 int mpi_read_file( mpi *X, int radix, FILE *fin );
00139 
00152 int mpi_write_file( char *p, mpi *X, int radix, FILE *fout );
00153 
00164 int mpi_read_binary( mpi *X, unsigned char *buf, int buflen );
00165 
00179 int mpi_write_binary( mpi *X, unsigned char *buf, int *buflen );
00180 
00184 int mpi_msb( mpi *X );
00185 
00189 int mpi_lsb( mpi *X );
00190 
00197 int mpi_shift_l( mpi *X, int count );
00198 
00205 int mpi_shift_r( mpi *X, int count );
00206 
00214 int mpi_cmp_abs( mpi *X, mpi *Y );
00215 
00223 int mpi_cmp_mpi( mpi *X, mpi *Y );
00224 
00232 int mpi_cmp_int( mpi *X, int z );
00233 
00240 int mpi_add_abs( mpi *X, mpi *A, mpi *B );
00241 
00248 int mpi_sub_abs( mpi *X, mpi *A, mpi *B );
00249 
00256 int mpi_add_mpi( mpi *X, mpi *A, mpi *B );
00257 
00264 int mpi_sub_mpi( mpi *X, mpi *A, mpi *B );
00265 
00272 int mpi_add_int( mpi *X, mpi *A, int b );
00273 
00280 int mpi_sub_int( mpi *X, mpi *A, int b );
00281 
00288 int mpi_mul_mpi( mpi *X, mpi *A, mpi *B );
00289 
00296 int mpi_mul_int( mpi *X, mpi *A, t_int b );
00297 
00307 int mpi_div_mpi( mpi *Q, mpi *R, mpi *A, mpi *B );
00308 
00318 int mpi_div_int( mpi *Q, mpi *R, mpi *A, int b );
00319 
00327 int mpi_mod_mpi( mpi *R, mpi *A, mpi *B );
00328 
00336 int mpi_mod_int( t_int *r, mpi *A, int b );
00337 
00349 int mpi_exp_mod( mpi *X, mpi *A, mpi *E, mpi *N, mpi *_RR );
00350 
00357 int mpi_gcd( mpi *G, mpi *A, mpi *B );
00358 
00367 int mpi_inv_mod( mpi *X, mpi *A, mpi *N );
00368 
00376 int mpi_is_prime( mpi *X );
00377 
00391 int mpi_gen_prime( mpi *X, int nbits, int dh_flag,
00392                    int (*rng_f)(void *), void *rng_d );
00393 
00399 int mpi_self_test( int verbose );
00400 
00401 #ifdef __cplusplus
00402 }
00403 #endif
00404 
00405 #endif /* bignum.h */

Generated on Tue Jul 1 15:29:58 2008 for Mobile-C by  doxygen 1.5.4