/home/dko/projects/mobilec/trunk/src/security/xyssl-0.9/include/xyssl/bignum.h File Reference
#include <stdio.h>
Go to the source code of this file.
Data Structures
Defines
#define
MPI_CHK(
f) if( ( ret =
f ) != 0 ) goto cleanup
Typedefs
typedef unsigned long
t_int
typedef unsigned long long
t_dbl
Functions
Initialize one or more
mpi.
Unallocate one or more
mpi.
Enlarge to the specified number of limbs.
Copy the contents of Y into X.
Swap the contents of X and Y.
Set value from integer.
Return the number of least significant bits.
Return the number of most significant bits.
Return the total size in bytes.
Import from an ASCII string.
Export into an ASCII string.
Read X from an opened file.
Write X into an opened file, or stdout.
Import X from unsigned binary data, big endian.
Export X into unsigned binary data, big endian.
Left-shift: X <<= count.
Right-shift: X >>= count.
Compare unsigned values.
Compare signed values.
Compare signed values.
Unsigned addition: X = |A| + |B|.
Unsigned substraction: X = |A| - |B|.
Signed addition: X = A + B.
Signed substraction: X = A - B.
Signed addition: X = A + b.
Signed substraction: X = A - b.
Baseline multiplication: X = A * B.
Baseline multiplication: X = A * b.
Division by
mpi: A = Q * B + R.
Division by int: A = Q * b + R.
Modulo: R = A mod B.
Modulo: r = A mod b.
Sliding-window exponentiation: X = A^E mod N.
Greatest common divisor: G = gcd(A, B).
Modular inverse: X = A^-1 mod N.
Miller-Rabin primality test.
Prime number generation.
Checkup routine.
Detailed Description
Definition in file bignum.h.
Define Documentation
#define MPI_CHK
(
f
)
if( ( ret =
f ) != 0 ) goto cleanup
#define XYSSL_ERR_MPI_BAD_INPUT_DATA -0x0004
#define XYSSL_ERR_MPI_BUFFER_TOO_SMALL -0x0008
#define XYSSL_ERR_MPI_DIVISION_BY_ZERO -0x000C
#define XYSSL_ERR_MPI_FILE_IO_ERROR -0x0002
#define XYSSL_ERR_MPI_INVALID_CHARACTER -0x0006
#define XYSSL_ERR_MPI_NEGATIVE_VALUE -0x000A
#define XYSSL_ERR_MPI_NOT_ACCEPTABLE -0x000E
Typedef Documentation
typedef unsigned long long
t_dbl
typedef unsigned long
t_int
Function Documentation
Unsigned addition: X = |A| + |B|.
- Returns:
- 0 if successful, 1 if memory allocation failed
Signed addition: X = A + b.
- Returns:
- 0 if successful, 1 if memory allocation failed
Signed addition: X = A + B.
- Returns:
- 0 if successful, 1 if memory allocation failed
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|
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
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
Copy the contents of Y into X.
- Returns:
- 0 if successful, 1 if memory allocation failed
Division by int: A = Q * b + R.
- Returns:
- 0 if successful, 1 if memory allocation failed, XYSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0
- Note:
- Either Q or R can be NULL.
Referenced by main().
Division by mpi: A = Q * B + R.
- Returns:
- 0 if successful, 1 if memory allocation failed, XYSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0
- Note:
- Either Q or R can be NULL.
Sliding-window exponentiation: X = A^E mod N.
- Returns:
- 0 if successful, 1 if memory allocation failed, XYSSL_ERR_MPI_BAD_INPUT_DATA 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.
Referenced by main().
Unallocate one or more mpi.
Referenced by main().
Greatest common divisor: G = gcd(A, B).
- Returns:
- 0 if successful, 1 if memory allocation failed
Prime number generation.
- Parameters:
-
nbits required size of X in bits
dh_flag if 1, then (X-1)/2 will be prime too
f_rng RNG function
p_rng RNG parameter
- Returns:
- 0 if successful (probably prime), 1 if memory allocation failed, XYSSL_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
Referenced by main().
Enlarge to the specified number of limbs.
- Returns:
- 0 if successful, 1 if memory allocation failed
Initialize one or more mpi.
Referenced by main().
Modular inverse: X = A^-1 mod N.
- Returns:
- 0 if successful, 1 if memory allocation failed, XYSSL_ERR_MPI_BAD_INPUT_DATA if N is negative or nil XYSSL_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N
Referenced by main().
Miller-Rabin primality test.
- Returns:
- 0 if successful (probably prime), 1 if memory allocation failed, XYSSL_ERR_MPI_NOT_ACCEPTABLE if X is not prime
Referenced by main().
Return the number of least significant bits.
Set value from integer.
- Returns:
- 0 if successful, 1 if memory allocation failed
Modulo: r = A mod b.
- Returns:
- 0 if successful, 1 if memory allocation failed, XYSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0
Modulo: R = A mod B.
- Returns:
- 0 if successful, 1 if memory allocation failed, XYSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0
Baseline multiplication: X = A * b.
- Returns:
- 0 if successful, 1 if memory allocation failed
Baseline multiplication: X = A * B.
- Returns:
- 0 if successful, 1 if memory allocation failed
Referenced by main().
int mpi_read_binary
(
mpi *
X,
unsigned char *
buf,
)
Import X from unsigned binary data, big endian.
- Parameters:
-
buf input buffer
buflen input buffer size
- Returns:
- 0 if successful, 1 if memory allocation failed
Referenced by d2i_RSA_PUBKEY().
Read X from an opened file.
- Parameters:
-
radix input numeric base
fin input file handle
- Returns:
- 0 if successful, or an XYSSL_ERR_MPI_XXX error code
Referenced by main().
int mpi_read_string
(
mpi *
X,
char *
s
)
Import from an ASCII string.
- Parameters:
-
radix input numeric base
s null-terminated string buffer
- Returns:
- 0 if successful, or an XYSSL_ERR_MPI_XXX error code
Referenced by main().
int mpi_self_test
(
int
verbose
)
Checkup routine.
- Returns:
- 0 if successful, or 1 if the test failed
Referenced by main().
Left-shift: X <<= count.
- Returns:
- 0 if successful, 1 if memory allocation failed
Right-shift: X >>= count.
- Returns:
- 0 if successful, 1 if memory allocation failed
Return the total size in bytes.
Unsigned substraction: X = |A| - |B|.
- Returns:
- 0 if successful, XYSSL_ERR_MPI_NEGATIVE_VALUE if B is greater than A
Signed substraction: X = A - b.
- Returns:
- 0 if successful, 1 if memory allocation failed
Referenced by main().
Signed substraction: X = A - B.
- Returns:
- 0 if successful, 1 if memory allocation failed
Swap the contents of X and Y.
int mpi_write_binary
(
mpi *
X,
unsigned char *
buf,
)
Export X into unsigned binary data, big endian.
- Parameters:
-
buf output buffer
buflen output buffer size
- Returns:
- 0 if successful, XYSSL_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.
int mpi_write_file
(
char *
p,
FILE *
fout
)
Write X into an opened file, or stdout.
- Parameters:
-
p prefix, can be NULL
radix output numeric base
fout output file handle
- Returns:
- 0 if successful, or an XYSSL_ERR_MPI_XXX error code
- Note:
- Set fout == NULL to print X on the console.
Referenced by main().
int mpi_write_string
(
mpi *
X,
char *
s,
)
Export into an ASCII string.
- Parameters:
-
radix output numeric base
s string buffer
slen string buffer size
- Returns:
- 0 if successful, or an XYSSL_ERR_MPI_XXX error code
- Note:
- Call this function with *slen = 0 to obtain the minimum required buffer size in *slen.