/home/dko/projects/mobilec/trunk/src/security/xyssl-0.7/library/bignum.c File Reference

#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "xyssl/bignum.h"
#include "xyssl/bn_asm.h"

Go to the source code of this file.

Defines

#define _CRT_SECURE_NO_DEPRECATE   1
#define BITS_TO_LIMBS(i)   (((i) + biL - 1) / biL)
#define CHARS_TO_LIMBS(i)   (((i) + ciL - 1) / ciL)

Functions

void mpi_init (mpi *X,...)
 Initialize one or more mpi.
void mpi_free (mpi *X,...)
 Unallocate one or more mpi.
int mpi_grow (mpi *X, int nblimbs)
 Enlarge X to the specified number of limbs.
int mpi_copy (mpi *X, mpi *Y)
 Copy the contents of Y into X.
void mpi_swap (mpi *X, mpi *Y)
 Swap the contents of X and Y.
int mpi_lset (mpi *X, int z)
 Set value from integer.
static int mpi_get_digit (t_int *d, int radix, char c)
int mpi_read_string (mpi *X, int radix, char *s)
 Import X from an ASCII string.
static int mpi_write_hlp (mpi *X, int radix, char **p)
int mpi_write_string (mpi *X, int radix, char *s, int *slen)
 Export X into an ASCII string.
int mpi_read_file (mpi *X, int radix, FILE *fin)
 Read X from an opened file.
int mpi_write_file (char *p, mpi *X, int radix, FILE *fout)
 Write X into an opened file, or stdout.
int mpi_read_binary (mpi *X, unsigned char *buf, int buflen)
 Import X from unsigned binary data, big endian.
int mpi_write_binary (mpi *X, unsigned char *buf, int *buflen)
 Export X into unsigned binary data, big endian.
int mpi_msb (mpi *X)
 Return the total size in bits, without leading 0s.
int mpi_lsb (mpi *X)
 Return the number of least significant bits.
int mpi_shift_l (mpi *X, int count)
 Left-shift: X <<= count.
int mpi_shift_r (mpi *X, int count)
 Right-shift: X >>= count.
int mpi_cmp_abs (mpi *X, mpi *Y)
 Compare unsigned values.
int mpi_cmp_mpi (mpi *X, mpi *Y)
 Compare signed values.
int mpi_cmp_int (mpi *X, int z)
 Compare signed values.
int mpi_add_abs (mpi *X, mpi *A, mpi *B)
 Unsigned addition: X = |A| + |B|.
static void mpi_sub_hlp (int n, t_int *s, t_int *d)
int mpi_sub_abs (mpi *X, mpi *A, mpi *B)
 Unsigned substraction: X = |A| - |B|.
int mpi_add_mpi (mpi *X, mpi *A, mpi *B)
 Signed addition: X = A + B.
int mpi_sub_mpi (mpi *X, mpi *A, mpi *B)
 Signed substraction: X = A - B.
int mpi_add_int (mpi *X, mpi *A, int b)
 Signed addition: X = A + b.
int mpi_sub_int (mpi *X, mpi *A, int b)
 Signed substraction: X = A - b.
static void mpi_mul_hlp (int i, t_int *s, t_int *d, t_int b)
int mpi_mul_mpi (mpi *X, mpi *A, mpi *B)
 Baseline multiplication: X = A * B.
int mpi_mul_int (mpi *X, mpi *A, t_int b)
 Baseline multiplication: X = A * b.
int mpi_div_mpi (mpi *Q, mpi *R, mpi *A, mpi *B)
 Division by mpi: A = Q * B + R.
int mpi_div_int (mpi *Q, mpi *R, mpi *A, int b)
 Division by int: A = Q * b + R.
int mpi_mod_mpi (mpi *R, mpi *A, mpi *B)
 Modulo: R = A mod B.
int mpi_mod_int (t_int *r, mpi *A, int b)
 Modulo: r = A mod b.
static void mpi_montg_init (t_int *mm, mpi *N)
static void mpi_montmul (mpi *A, mpi *B, mpi *N, t_int mm, mpi *T)
static void mpi_montred (mpi *A, mpi *N, t_int mm, mpi *T)
int mpi_exp_mod (mpi *X, mpi *A, mpi *E, mpi *N, mpi *_RR)
 Sliding-window exponentiation: X = A^E mod N.
int mpi_gcd (mpi *G, mpi *A, mpi *B)
 Greatest common divisor: G = gcd(A, B).
int mpi_inv_mod (mpi *X, mpi *A, mpi *N)
 Modular inverse: X = A^-1 mod N.
int mpi_is_prime (mpi *X)
 Miller-Rabin primality test.
int mpi_gen_prime (mpi *X, int nbits, int dh_flag, int(*rng_f)(void *), void *rng_d)
 Prime number generation.
int mpi_self_test (int verbose)
 Checkup routine.

Variables

static const int small_prime []
static const char _bignum_src [] = "_bignum_src"


Define Documentation

#define _CRT_SECURE_NO_DEPRECATE   1

Definition at line 28 of file bignum.c.

#define BITS_TO_LIMBS (  )     (((i) + biL - 1) / biL)

Definition at line 42 of file bignum.c.

Referenced by mpi_gen_prime(), mpi_read_string(), and mpi_shift_l().

#define CHARS_TO_LIMBS (  )     (((i) + ciL - 1) / ciL)

Definition at line 43 of file bignum.c.

Referenced by mpi_read_binary().


Function Documentation

int mpi_add_abs ( mpi X,
mpi A,
mpi B 
)

Unsigned addition: X = |A| + |B|.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 641 of file bignum.c.

References CHK, mpi_copy(), mpi_grow(), mpi::n, and mpi::p.

Referenced by mpi_add_mpi(), and mpi_sub_mpi().

int mpi_add_int ( mpi X,
mpi A,
int  b 
)

Signed addition: X = A + b.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 806 of file bignum.c.

References mpi_add_mpi(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_gen_prime(), and mpi_read_string().

int mpi_add_mpi ( mpi X,
mpi A,
mpi B 
)

Signed addition: X = A + B.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 744 of file bignum.c.

References CHK, mpi_add_abs(), mpi_cmp_abs(), mpi_sub_abs(), and mpi::s.

Referenced by mpi_add_int(), mpi_div_mpi(), mpi_inv_mod(), mpi_mod_mpi(), and rsa_private().

int mpi_cmp_abs ( mpi X,
mpi Y 
)

Compare unsigned values.

Returns:
1 if |X| is greater than |Y|, -1 if |X| is lesser than |Y| or 0 if |X| is equal to |Y|

Definition at line 562 of file bignum.c.

References mpi::n, and mpi::p.

Referenced by mpi_add_mpi(), mpi_div_mpi(), mpi_montmul(), mpi_sub_abs(), and mpi_sub_mpi().

int mpi_cmp_int ( mpi X,
int  z 
)

Compare signed values.

Returns:
1 if X is greater than z, -1 if X is lesser than z or 0 if X is equal to z

Definition at line 625 of file bignum.c.

References mpi_cmp_mpi(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), mpi_inv_mod(), mpi_is_prime(), mpi_mod_mpi(), mpi_write_hlp(), rsa_check_privkey(), and rsa_gen_key().

int mpi_cmp_mpi ( mpi X,
mpi Y 
)

Compare signed values.

Returns:
1 if X is greater than Y, -1 if X is lesser than Y or 0 if X is equal to Y

Definition at line 592 of file bignum.c.

References mpi::n, mpi::p, and mpi::s.

Referenced by dhm_make_params(), dhm_make_public(), mpi_cmp_int(), mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), mpi_inv_mod(), mpi_is_prime(), mpi_mod_mpi(), rsa_check_privkey(), rsa_gen_key(), rsa_private(), and rsa_public().

int mpi_copy ( mpi X,
mpi Y 
)

Copy the contents of Y into X.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 115 of file bignum.c.

References CHK, ciL, mpi_grow(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_add_abs(), mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), mpi_inv_mod(), mpi_is_prime(), mpi_mul_mpi(), mpi_sub_abs(), and mpi_write_string().

int mpi_div_int ( mpi Q,
mpi R,
mpi A,
int  b 
)

Division by int: A = Q * b + R.

Returns:
0 if successful, 1 if memory allocation failed, ERR_MPI_DIVISION_BY_ZERO if b == 0
Note:
Either Q or R can be NULL.

Definition at line 1117 of file bignum.c.

References mpi_div_mpi(), mpi::n, mpi::p, and mpi::s.

Referenced by main(), and mpi_write_hlp().

int mpi_div_mpi ( mpi Q,
mpi R,
mpi A,
mpi B 
)

Division by mpi: A = Q * B + R.

Returns:
0 if successful, 1 if memory allocation failed, ERR_MPI_DIVISION_BY_ZERO if B == 0
Note:
Either Q or R can be NULL.

Definition at line 953 of file bignum.c.

References biH, biL, CHK, ERR_MPI_DIVISION_BY_ZERO, mpi_add_mpi(), mpi_cmp_abs(), mpi_cmp_int(), mpi_cmp_mpi(), mpi_copy(), mpi_free(), mpi_grow(), mpi_init(), mpi_lset(), mpi_msb(), mpi_mul_int(), mpi_shift_l(), mpi_shift_r(), mpi_sub_mpi(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_div_int(), and mpi_mod_mpi().

int mpi_exp_mod ( mpi X,
mpi A,
mpi E,
mpi N,
mpi _RR 
)

Sliding-window exponentiation: X = A^E mod N.

Returns:
0 if successful, 1 if memory allocation failed, ERR_MPI_INVALID_PARAMETER if N is negative or even
Note:
_RR is used to avoid re-computing R*R mod N across multiple calls, which speeds up things a bit. It can be set to NULL if the extra performance is unneeded.

Definition at line 1263 of file bignum.c.

References biL, CHK, ERR_MPI_INVALID_PARAMETER, mpi_cmp_int(), mpi_cmp_mpi(), mpi_copy(), mpi_free(), mpi_grow(), mpi_init(), mpi_lset(), mpi_mod_mpi(), mpi_montg_init(), mpi_montmul(), mpi_montred(), mpi_msb(), mpi_shift_l(), mpi::n, and mpi::p.

Referenced by dhm_calc_secret(), dhm_make_params(), dhm_make_public(), main(), mpi_is_prime(), rsa_private(), and rsa_public().

void mpi_free ( mpi X,
  ... 
)

Unallocate one or more mpi.

Definition at line 66 of file bignum.c.

References ciL, mpi::n, and mpi::p.

Referenced by dhm_free(), main(), mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), mpi_gen_prime(), mpi_inv_mod(), mpi_is_prime(), mpi_mul_mpi(), mpi_read_string(), mpi_sub_abs(), mpi_write_string(), rsa_check_privkey(), rsa_free(), rsa_gen_key(), rsa_private(), and rsa_public().

int mpi_gcd ( mpi G,
mpi A,
mpi B 
)

Greatest common divisor: G = gcd(A, B).

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 1440 of file bignum.c.

References CHK, mpi_cmp_int(), mpi_cmp_mpi(), mpi_copy(), mpi_free(), mpi_init(), mpi_lsb(), mpi_lset(), mpi_mul_mpi(), mpi_shift_l(), mpi_shift_r(), mpi_sub_abs(), mpi::p, and mpi::s.

Referenced by mpi_inv_mod(), rsa_check_privkey(), and rsa_gen_key().

int mpi_gen_prime ( mpi X,
int  nbits,
int  dh_flag,
int(*)(void *)  rng_f,
void *  rng_d 
)

Prime number generation.

Parameters:
X destination mpi
nbits required size of X in bits
dh_flag if 1, then (X-1)/2 will be prime too
rng_f points to the RNG function
rng_d points to the RNG data
Returns:
0 if successful (probably prime), 1 if memory allocation failed, ERR_MPI_INVALID_PARAMETER if nbits is < 3

Definition at line 1710 of file bignum.c.

References BITS_TO_LIMBS, CHK, ERR_MPI_INVALID_PARAMETER, ERR_MPI_NOT_ACCEPTABLE, mpi_add_int(), mpi_free(), mpi_grow(), mpi_init(), mpi_is_prime(), mpi_lset(), mpi_msb(), mpi_shift_l(), mpi_shift_r(), mpi_sub_int(), and mpi::p.

Referenced by main(), and rsa_gen_key().

static int mpi_get_digit ( t_int d,
int  radix,
char  c 
) [static]

Definition at line 171 of file bignum.c.

References ERR_MPI_INVALID_CHARACTER.

Referenced by mpi_read_file(), and mpi_read_string().

int mpi_grow ( mpi X,
int  nblimbs 
)

Enlarge X to the specified number of limbs.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 91 of file bignum.c.

References ciL, mpi::n, mpi::p, and mpi::s.

Referenced by dhm_make_params(), dhm_make_public(), mpi_add_abs(), mpi_copy(), mpi_div_mpi(), mpi_exp_mod(), mpi_gen_prime(), mpi_is_prime(), mpi_lset(), mpi_mul_mpi(), mpi_read_binary(), mpi_read_string(), and mpi_shift_l().

void mpi_init ( mpi X,
  ... 
)

Initialize one or more mpi.

Definition at line 48 of file bignum.c.

Referenced by main(), mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), mpi_gen_prime(), mpi_inv_mod(), mpi_is_prime(), mpi_mul_mpi(), mpi_read_string(), mpi_sub_abs(), mpi_write_string(), rsa_check_privkey(), rsa_gen_key(), rsa_private(), and rsa_public().

int mpi_inv_mod ( mpi X,
mpi A,
mpi N 
)

Modular inverse: X = A^-1 mod N.

Returns:
0 if successful, 1 if memory allocation failed, ERR_MPI_INVALID_PARAMETER if N is negative or nil ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N

Definition at line 1488 of file bignum.c.

References CHK, ERR_MPI_INVALID_PARAMETER, ERR_MPI_NOT_ACCEPTABLE, mpi_add_mpi(), mpi_cmp_int(), mpi_cmp_mpi(), mpi_copy(), mpi_free(), mpi_gcd(), mpi_init(), mpi_lset(), mpi_mod_mpi(), mpi_shift_r(), mpi_sub_mpi(), and mpi::p.

Referenced by main(), and rsa_gen_key().

int mpi_is_prime ( mpi X  ) 

Miller-Rabin primality test.

Returns:
0 if successful (probably prime), 1 if memory allocation failed, ERR_MPI_NOT_ACCEPTABLE if X is not prime

Definition at line 1614 of file bignum.c.

References CHK, ERR_MPI_NOT_ACCEPTABLE, mpi_cmp_int(), mpi_cmp_mpi(), mpi_copy(), mpi_exp_mod(), mpi_free(), mpi_grow(), mpi_init(), mpi_lsb(), mpi_mod_int(), mpi_mod_mpi(), mpi_msb(), mpi_mul_mpi(), mpi_shift_r(), mpi_sub_int(), mpi::n, mpi::p, R, mpi::s, and small_prime.

Referenced by main(), and mpi_gen_prime().

int mpi_lsb ( mpi X  ) 

Return the number of least significant bits.

Definition at line 458 of file bignum.c.

References biL, int, mpi::n, and mpi::p.

Referenced by mpi_gcd(), and mpi_is_prime().

int mpi_lset ( mpi X,
int  z 
)

Set value from integer.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 154 of file bignum.c.

References CHK, ciL, mpi_grow(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), mpi_gen_prime(), mpi_inv_mod(), mpi_mul_mpi(), mpi_read_binary(), mpi_read_string(), and rsa_gen_key().

int mpi_mod_int ( t_int r,
mpi A,
int  b 
)

Modulo: r = A mod b.

Returns:
0 if successful, 1 if memory allocation failed, ERR_MPI_DIVISION_BY_ZERO if b == 0,

Definition at line 1153 of file bignum.c.

References biH, ERR_MPI_DIVISION_BY_ZERO, mpi::n, and mpi::p.

Referenced by mpi_is_prime(), and mpi_write_hlp().

int mpi_mod_mpi ( mpi R,
mpi A,
mpi B 
)

Modulo: R = A mod B.

Returns:
0 if successful, 1 if memory allocation failed, ERR_MPI_DIVISION_BY_ZERO if B == 0

Definition at line 1133 of file bignum.c.

References CHK, mpi_add_mpi(), mpi_cmp_int(), mpi_cmp_mpi(), mpi_div_mpi(), and mpi_sub_mpi().

Referenced by mpi_exp_mod(), mpi_inv_mod(), mpi_is_prime(), rsa_gen_key(), and rsa_private().

static void mpi_montg_init ( t_int mm,
mpi N 
) [static]

Definition at line 1194 of file bignum.c.

References biL, and mpi::p.

Referenced by mpi_exp_mod().

static void mpi_montmul ( mpi A,
mpi B,
mpi N,
t_int  mm,
mpi T 
) [static]

Definition at line 1212 of file bignum.c.

References ciL, mpi_cmp_abs(), mpi_mul_hlp(), mpi_sub_hlp(), mpi::n, and mpi::p.

Referenced by mpi_exp_mod(), and mpi_montred().

static void mpi_montred ( mpi A,
mpi N,
t_int  mm,
mpi T 
) [static]

Definition at line 1249 of file bignum.c.

References mpi_montmul(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_exp_mod().

int mpi_msb ( mpi X  ) 

Return the total size in bits, without leading 0s.

Definition at line 440 of file bignum.c.

References biL, mpi::n, and mpi::p.

Referenced by dhm_calc_secret(), dhm_make_params(), dhm_read_params(), mpi_div_mpi(), mpi_exp_mod(), mpi_gen_prime(), mpi_is_prime(), mpi_shift_l(), mpi_write_binary(), mpi_write_string(), rsa_check_pubkey(), rsa_gen_key(), rsa_read_private(), rsa_read_public(), x509_add_certs(), and x509_parse_key().

static void mpi_mul_hlp ( int  i,
t_int s,
t_int d,
t_int  b 
) [static]

Definition at line 838 of file bignum.c.

References MULADDC_CORE, MULADDC_INIT, and MULADDC_STOP.

Referenced by mpi_montmul(), and mpi_mul_mpi().

int mpi_mul_int ( mpi X,
mpi A,
t_int  b 
)

Baseline multiplication: X = A * b.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 937 of file bignum.c.

References mpi_mul_mpi(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_div_mpi(), and mpi_read_string().

int mpi_mul_mpi ( mpi X,
mpi A,
mpi B 
)

Baseline multiplication: X = A * B.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 902 of file bignum.c.

References CHK, mpi_copy(), mpi_free(), mpi_grow(), mpi_init(), mpi_lset(), mpi_mul_hlp(), mpi::n, mpi::p, and mpi::s.

Referenced by main(), mpi_gcd(), mpi_is_prime(), mpi_mul_int(), rsa_check_privkey(), rsa_gen_key(), and rsa_private().

int mpi_read_binary ( mpi X,
unsigned char *  buf,
int  buflen 
)

Import X from unsigned binary data, big endian.

Parameters:
X destination mpi
buf input buffer
buflen input buffer size
Returns:
0 if successful, 1 if memory allocation failed

Definition at line 395 of file bignum.c.

References CHARS_TO_LIMBS, CHK, ciL, mpi_grow(), mpi_lset(), and mpi::p.

Referenced by asn1_get_mpi(), dhm_read_bignum(), dhm_read_public(), rsa_private(), and rsa_public().

int mpi_read_file ( mpi X,
int  radix,
FILE *  fin 
)

Read X from an opened file.

Parameters:
X destination mpi
radix input numeric base
fin input file handle
Returns:
0 if successful, or an ERR_MPI_XXX error code

Definition at line 332 of file bignum.c.

References ERR_MPI_FILE_IO_ERROR, mpi_get_digit(), and mpi_read_string().

Referenced by main(), rsa_read_private(), and rsa_read_public().

int mpi_read_string ( mpi X,
int  radix,
char *  s 
)

Import X from an ASCII string.

Parameters:
X destination mpi
radix input numeric base
s null-terminated string buffer
Returns:
0 if successful, or an ERR_MPI_XXX error code

Definition at line 188 of file bignum.c.

References BITS_TO_LIMBS, CHK, ciL, ERR_MPI_INVALID_PARAMETER, int, mpi_add_int(), mpi_free(), mpi_get_digit(), mpi_grow(), mpi_init(), mpi_lset(), mpi_mul_int(), mpi::p, and mpi::s.

Referenced by main(), and mpi_read_file().

int mpi_self_test ( int  verbose  ) 

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Definition at line 1912 of file bignum.c.

Referenced by main().

int mpi_shift_l ( mpi X,
int  count 
)

Left-shift: X <<= count.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 473 of file bignum.c.

References biL, BITS_TO_LIMBS, CHK, mpi_grow(), mpi_msb(), mpi::n, and mpi::p.

Referenced by mpi_div_mpi(), mpi_exp_mod(), mpi_gcd(), and mpi_gen_prime().

int mpi_shift_r ( mpi X,
int  count 
)

Right-shift: X >>= count.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 522 of file bignum.c.

References biL, mpi::n, and mpi::p.

Referenced by dhm_make_params(), dhm_make_public(), mpi_div_mpi(), mpi_gcd(), mpi_gen_prime(), mpi_inv_mod(), and mpi_is_prime().

int mpi_sub_abs ( mpi X,
mpi A,
mpi B 
)

Unsigned substraction: X = |A| - |B|.

Returns:
0 if successful, ERR_MPI_NEGATIVE_VALUE if B is greater than A

Definition at line 708 of file bignum.c.

References CHK, ERR_MPI_NEGATIVE_VALUE, mpi_cmp_abs(), mpi_copy(), mpi_free(), mpi_init(), mpi_sub_hlp(), mpi::n, and mpi::p.

Referenced by mpi_add_mpi(), mpi_gcd(), and mpi_sub_mpi().

static void mpi_sub_hlp ( int  n,
t_int s,
t_int d 
) [static]

Definition at line 687 of file bignum.c.

Referenced by mpi_montmul(), and mpi_sub_abs().

int mpi_sub_int ( mpi X,
mpi A,
int  b 
)

Signed substraction: X = A - b.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 822 of file bignum.c.

References mpi_sub_mpi(), mpi::n, mpi::p, and mpi::s.

Referenced by main(), mpi_gen_prime(), mpi_is_prime(), rsa_check_privkey(), and rsa_gen_key().

int mpi_sub_mpi ( mpi X,
mpi A,
mpi B 
)

Signed substraction: X = A - B.

Returns:
0 if successful, 1 if memory allocation failed

Definition at line 775 of file bignum.c.

References CHK, mpi_add_abs(), mpi_cmp_abs(), mpi_sub_abs(), and mpi::s.

Referenced by mpi_div_mpi(), mpi_inv_mod(), mpi_mod_mpi(), mpi_sub_int(), and rsa_private().

void mpi_swap ( mpi X,
mpi Y 
)

Swap the contents of X and Y.

Definition at line 142 of file bignum.c.

Referenced by rsa_gen_key().

int mpi_write_binary ( mpi X,
unsigned char *  buf,
int buflen 
)

Export X into unsigned binary data, big endian.

Parameters:
X source mpi
buf output buffer
buflen output buffer size
Returns:
0 if successful, ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough
Note:
Call this function with *buflen = 0 to obtain the minimum required buffer size in *buflen.

Definition at line 417 of file bignum.c.

References ciL, ERR_MPI_BUFFER_TOO_SMALL, mpi_msb(), and mpi::p.

Referenced by dhm_calc_secret(), dhm_make_public(), rsa_private(), and rsa_public().

int mpi_write_file ( char *  p,
mpi X,
int  radix,
FILE *  fout 
)

Write X into an opened file, or stdout.

Parameters:
p prefix, can be NULL
X source mpi
radix output numeric base
fout output file handle
Returns:
0 if successful, or an ERR_MPI_XXX error code
Note:
Set fout == NULL to print X on the console.

Definition at line 357 of file bignum.c.

References CHK, ERR_MPI_FILE_IO_ERROR, and mpi_write_string().

Referenced by main(), rsa_write_private(), and rsa_write_public().

static int mpi_write_hlp ( mpi X,
int  radix,
char **  p 
) [static]

Definition at line 245 of file bignum.c.

References CHK, ERR_MPI_INVALID_PARAMETER, mpi_cmp_int(), mpi_div_int(), and mpi_mod_int().

Referenced by mpi_write_string().

int mpi_write_string ( mpi X,
int  radix,
char *  s,
int slen 
)

Export X into an ASCII string.

Parameters:
X source mpi
radix output numeric base
s string buffer
slen string buffer size
Returns:
0 if successful, or an ERR_MPI_XXX error code
Note:
Call this function with *slen = 0 to obtain the minimum required buffer size in *slen.

Definition at line 270 of file bignum.c.

References CHK, ciL, ERR_MPI_BUFFER_TOO_SMALL, ERR_MPI_INVALID_PARAMETER, mpi_copy(), mpi_free(), mpi_init(), mpi_msb(), mpi_write_hlp(), mpi::n, mpi::p, and mpi::s.

Referenced by mpi_write_file().


Variable Documentation

const char _bignum_src[] = "_bignum_src" [static]

Definition at line 1778 of file bignum.c.

const int small_prime[] [static]

Definition at line 1579 of file bignum.c.

Referenced by mpi_is_prime().


Generated on Fri May 16 14:49:56 2008 for Mobile-C by  doxygen 1.5.4