wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
bignum.c File Reference

Big number math. More...

#include "includes.h"
#include "common.h"
#include "bignum.h"
#include <tommath.h>

Functions

struct bignum * bignum_init (void)
 Allocate memory for bignum. More...
 
void bignum_deinit (struct bignum *n)
 Free bignum. More...
 
size_t bignum_get_unsigned_bin_len (struct bignum *n)
 Get length of bignum as an unsigned binary buffer. More...
 
int bignum_get_unsigned_bin (const struct bignum *n, u8 *buf, size_t *len)
 Set binary buffer to unsigned bignum. More...
 
int bignum_set_unsigned_bin (struct bignum *n, const u8 *buf, size_t len)
 Set bignum based on unsigned binary buffer. More...
 
int bignum_cmp (const struct bignum *a, const struct bignum *b)
 Signed comparison. More...
 
int bignum_cmp_d (const struct bignum *a, unsigned long b)
 Compare bignum to standard integer. More...
 
int bignum_add (const struct bignum *a, const struct bignum *b, struct bignum *c)
 c = a + b More...
 
int bignum_sub (const struct bignum *a, const struct bignum *b, struct bignum *c)
 c = a - b More...
 
int bignum_mul (const struct bignum *a, const struct bignum *b, struct bignum *c)
 c = a * b More...
 
int bignum_mulmod (const struct bignum *a, const struct bignum *b, const struct bignum *c, struct bignum *d)
 d = a * b (mod c) More...
 
int bignum_exptmod (const struct bignum *a, const struct bignum *b, const struct bignum *c, struct bignum *d)
 Modular exponentiation: d = a^b (mod c) More...
 

Detailed Description

Big number math.

Function Documentation

int bignum_add ( const struct bignum *  a,
const struct bignum *  b,
struct bignum *  c 
)

c = a + b

Parameters
aBignum from bignum_init()
bBignum from bignum_init()
cBignum from bignum_init(); used to store the result of a + b
Returns
0 on success, -1 on failure
int bignum_cmp ( const struct bignum *  a,
const struct bignum *  b 
)

Signed comparison.

Parameters
aBignum from bignum_init()
bBignum from bignum_init()
Returns
0 on success, -1 on failure
int bignum_cmp_d ( const struct bignum *  a,
unsigned long  b 
)

Compare bignum to standard integer.

Parameters
aBignum from bignum_init()
bSmall integer
Returns
0 on success, -1 on failure
void bignum_deinit ( struct bignum *  n)

Free bignum.

Parameters
nBignum from bignum_init()
int bignum_exptmod ( const struct bignum *  a,
const struct bignum *  b,
const struct bignum *  c,
struct bignum *  d 
)

Modular exponentiation: d = a^b (mod c)

Parameters
aBignum from bignum_init(); base
bBignum from bignum_init(); exponent
cBignum from bignum_init(); modulus
dBignum from bignum_init(); used to store the result of a^b (mod c)
Returns
0 on success, -1 on failure
int bignum_get_unsigned_bin ( const struct bignum *  n,
u8 *  buf,
size_t *  len 
)

Set binary buffer to unsigned bignum.

Parameters
nBignum from bignum_init()
bufBuffer for the binary number
lenLength of the buffer, can be NULL if buffer is known to be long enough. Set to used buffer length on success if not NULL.
Returns
0 on success, -1 on failure
size_t bignum_get_unsigned_bin_len ( struct bignum *  n)

Get length of bignum as an unsigned binary buffer.

Parameters
nBignum from bignum_init()
Returns
Length of n if written to a binary buffer
struct bignum* bignum_init ( void  )

Allocate memory for bignum.

Returns
Pointer to allocated bignum or NULL on failure
int bignum_mul ( const struct bignum *  a,
const struct bignum *  b,
struct bignum *  c 
)

c = a * b

Parameters
aBignum from bignum_init()
bBignum from bignum_init()
cBignum from bignum_init(); used to store the result of a * b
Returns
0 on success, -1 on failure
int bignum_mulmod ( const struct bignum *  a,
const struct bignum *  b,
const struct bignum *  c,
struct bignum *  d 
)

d = a * b (mod c)

Parameters
aBignum from bignum_init()
bBignum from bignum_init()
cBignum from bignum_init(); modulus
dBignum from bignum_init(); used to store the result of a * b (mod c)
Returns
0 on success, -1 on failure
int bignum_set_unsigned_bin ( struct bignum *  n,
const u8 *  buf,
size_t  len 
)

Set bignum based on unsigned binary buffer.

Parameters
nBignum from bignum_init(); to be set to the given value
bufBuffer with unsigned binary value
lenLength of buf in octets
Returns
0 on success, -1 on failure
int bignum_sub ( const struct bignum *  a,
const struct bignum *  b,
struct bignum *  c 
)

c = a - b

Parameters
aBignum from bignum_init()
bBignum from bignum_init()
cBignum from bignum_init(); used to store the result of a - b
Returns
0 on success, -1 on failure