TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ltc_math_descriptor Struct Reference

#include <tomcrypt_math.h>

Public Attributes

char * name
 
int bits_per_digit
 
int(* init )(void **a)
 
int(* init_copy )(void **dst, void *src)
 
void(* deinit )(void *a)
 
int(* neg )(void *src, void *dst)
 
int(* copy )(void *src, void *dst)
 
int(* set_int )(void *a, unsigned long n)
 
unsigned long(* get_int )(void *a)
 
unsigned long(* get_digit )(void *a, int n)
 
int(* get_digit_count )(void *a)
 
int(* compare )(void *a, void *b)
 
int(* compare_d )(void *a, unsigned long n)
 
int(* count_bits )(void *a)
 
int(* count_lsb_bits )(void *a)
 
int(* twoexpt )(void *a, int n)
 
int(* read_radix )(void *a, const char *str, int radix)
 
int(* write_radix )(void *a, char *str, int radix)
 
unsigned long(* unsigned_size )(void *a)
 
int(* unsigned_write )(void *src, unsigned char *dst)
 
int(* unsigned_read )(void *dst, unsigned char *src, unsigned long len)
 
int(* add )(void *a, void *b, void *c)
 
int(* addi )(void *a, unsigned long b, void *c)
 
int(* sub )(void *a, void *b, void *c)
 
int(* subi )(void *a, unsigned long b, void *c)
 
int(* mul )(void *a, void *b, void *c)
 
int(* muli )(void *a, unsigned long b, void *c)
 
int(* sqr )(void *a, void *b)
 
int(* mpdiv )(void *a, void *b, void *c, void *d)
 
int(* div_2 )(void *a, void *b)
 
int(* modi )(void *a, unsigned long b, unsigned long *c)
 
int(* gcd )(void *a, void *b, void *c)
 
int(* lcm )(void *a, void *b, void *c)
 
int(* mulmod )(void *a, void *b, void *c, void *d)
 
int(* sqrmod )(void *a, void *b, void *c)
 
int(* invmod )(void *, void *, void *)
 
int(* montgomery_setup )(void *a, void **b)
 
int(* montgomery_normalization )(void *a, void *b)
 
int(* montgomery_reduce )(void *a, void *b, void *c)
 
void(* montgomery_deinit )(void *a)
 
int(* exptmod )(void *a, void *b, void *c, void *d)
 
int(* isprime )(void *a, int *b)
 
int(* ecc_ptmul )(void *k, ecc_point *G, ecc_point *R, void *modulus, int map)
 
int(* ecc_ptadd )(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp)
 
int(* ecc_ptdbl )(ecc_point *P, ecc_point *R, void *modulus, void *mp)
 
int(* ecc_map )(ecc_point *P, void *modulus, void *mp)
 
int(* ecc_mul2add )(ecc_point *A, void *kA, ecc_point *B, void *kB, ecc_point *C, void *modulus)
 
int(* rsa_keygen )(prng_state *prng, int wprng, int size, long e, rsa_key *key)
 
int(* rsa_me )(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, int which, rsa_key *key)
 

Detailed Description

math descriptor

Member Data Documentation

int(* ltc_math_descriptor::add)(void *a, void *b, void *c)

add two integers

Parameters
aThe first source integer
bThe second source integer
cThe destination of "a + b"
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::addi)(void *a, unsigned long b, void *c)

add two integers

Parameters
aThe first source integer
bThe second source integer (single digit of upto bits_per_digit in length)
cThe destination of "a + b"
Returns
CRYPT_OK on success
int ltc_math_descriptor::bits_per_digit

Bits per digit, amount of bits must fit in an unsigned long

int(* ltc_math_descriptor::compare)(void *a, void *b)

compare two integers

Parameters
aThe left side integer
bThe right side integer
Returns
LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
int(* ltc_math_descriptor::compare_d)(void *a, unsigned long n)

compare against int

Parameters
aThe left side integer
bThe right side integer (upto bits_per_digit)
Returns
LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
int(* ltc_math_descriptor::copy)(void *src, void *dst)

copy

Parameters
srcThe number to copy from
dstThe number to write to
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::count_bits)(void *a)

Count the number of bits used to represent the integer

Parameters
aThe integer to count
Returns
The number of bits required to represent the integer
int(* ltc_math_descriptor::count_lsb_bits)(void *a)

Count the number of LSB bits which are zero

Parameters
aThe integer to count
Returns
The number of contiguous zero LSB bits
void(* ltc_math_descriptor::deinit)(void *a)

deinit

Parameters
aThe number to free
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::div_2)(void *a, void *b)

divide by two

Parameters
aThe integer to divide (shift right)
bThe destination
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::ecc_map)(ecc_point *P, void *modulus, void *mp)

ECC mapping from projective to affine, currently uses (x,y,z) => (x/z^2, y/z^3, 1)

Parameters
PThe point to map
modulusThe modulus
mpThe "b" value from montgomery_setup()
Returns
CRYPT_OK on success
Remarks
The mapping can be different but keep in mind a ecc_point only has three integers (x,y,z) so if you use a different mapping you have to make it fit.
int(* ltc_math_descriptor::ecc_mul2add)(ecc_point *A, void *kA, ecc_point *B, void *kB, ecc_point *C, void *modulus)

Computes kA*A + kB*B = C using Shamir's Trick

Parameters
AFirst point to multiply
kAWhat to multiple A by
BSecond point to multiply
kBWhat to multiple B by
C[out] Destination point (can overlap with A or B
modulusModulus for curve
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp)

ECC GF(p) point addition

Parameters
PThe first point
QThe second point
RThe destination of P + Q
modulusThe modulus
mpThe "b" value from montgomery_setup()
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::ecc_ptdbl)(ecc_point *P, ecc_point *R, void *modulus, void *mp)

ECC GF(p) point double

Parameters
PThe first point
RThe destination of 2P
modulusThe modulus
mpThe "b" value from montgomery_setup()
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map)

ECC GF(p) point multiplication (from the NIST curves)

Parameters
kThe integer to multiply the point by
GThe point to multiply
RThe destination for kG
modulusThe modulus for the field
mapBoolean indicated whether to map back to affine or not (can be ignored if you work in affine only)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::exptmod)(void *a, void *b, void *c, void *d)

Modular exponentiation

Parameters
aThe base integer
bThe power (can be negative) integer
cThe modulus integer
dThe destination
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::gcd)(void *a, void *b, void *c)

gcd

Parameters
aThe first integer
bThe second integer
cThe destination for (a, b)
Returns
CRYPT_OK on success
unsigned long(* ltc_math_descriptor::get_digit)(void *a, int n)

get digit n

Parameters
aThe number to read from
nThe number of the digit to fetch
Returns
The bits_per_digit sized n'th digit of a
int(* ltc_math_descriptor::get_digit_count)(void *a)

Get the number of digits that represent the number

Parameters
aThe number to count
Returns
The number of digits used to represent the number
unsigned long(* ltc_math_descriptor::get_int)(void *a)

get small constant

Parameters
aNumber to read, only fetches upto bits_per_digit from the number
Returns
The lower bits_per_digit of the integer (unsigned)
int(* ltc_math_descriptor::init)(void **a)

initialize a bignum

Parameters
aThe number to initialize
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::init_copy)(void **dst, void *src)

init copy

Parameters
dstThe number to initialize and write to
srcThe number to copy from
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::invmod)(void *, void *, void *)

Modular inversion

Parameters
aThe value to invert
bThe modulus
cThe destination (1/a mod b)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::isprime)(void *a, int *b)

Primality testing

Parameters
aThe integer to test
bThe destination of the result (FP_YES if prime)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::lcm)(void *a, void *b, void *c)

lcm

Parameters
aThe first integer
bThe second integer
cThe destination for [a, b]
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::modi)(void *a, unsigned long b, unsigned long *c)

Get remainder (small value)

Parameters
aThe integer to reduce
bThe modulus (upto bits_per_digit in length)
cThe destination for the residue
Returns
CRYPT_OK on success
void(* ltc_math_descriptor::montgomery_deinit)(void *a)

clean up (frees memory)

Parameters
aThe value "b" from montgomery_setup()
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::montgomery_normalization)(void *a, void *b)

get normalization value

Parameters
aThe destination for the normalization value
bThe modulus
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::montgomery_reduce)(void *a, void *b, void *c)

reduce a number

Parameters
aThe number [and dest] to reduce
bThe modulus
cThe value "b" from montgomery_setup()
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::montgomery_setup)(void *a, void **b)

setup montgomery

Parameters
aThe modulus
bThe destination for the reduction digit
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::mpdiv)(void *a, void *b, void *c, void *d)

Divide an integer

Parameters
aThe dividend
bThe divisor
cThe quotient (can be NULL to signify don't care)
dThe remainder (can be NULL to signify don't care)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::mul)(void *a, void *b, void *c)

multiply two integers

Parameters
aThe first source integer
bThe second source integer (single digit of upto bits_per_digit in length)
cThe destination of "a * b"
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::muli)(void *a, unsigned long b, void *c)

multiply two integers

Parameters
aThe first source integer
bThe second source integer (single digit of upto bits_per_digit in length)
cThe destination of "a * b"
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::mulmod)(void *a, void *b, void *c, void *d)

Modular multiplication

Parameters
aThe first source
bThe second source
cThe modulus
dThe destination (a*b mod c)
Returns
CRYPT_OK on success
char* ltc_math_descriptor::name

Name of the math provider

int(* ltc_math_descriptor::neg)(void *src, void *dst)

negate

Parameters
srcThe number to negate
dstThe destination
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::read_radix)(void *a, const char *str, int radix)

read ascii string

Parameters
aThe integer to store into
strThe string to read
radixThe radix the integer has been represented in (2-64)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key)

RSA Key Generation

Parameters
prngAn active PRNG state
wprngThe index of the PRNG desired
sizeThe size of the modulus (key size) desired (octets)
eThe "e" value (public key). e==65537 is a good choice
key[out] Destination of a newly created private key pair
Returns
CRYPT_OK if successful, upon error all allocated ram is freed
int(* ltc_math_descriptor::rsa_me)(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, int which, rsa_key *key)

RSA exponentiation

Parameters
inThe octet array representing the base
inlenThe length of the input
outThe destination (to be stored in an octet array format)
outlenThe length of the output buffer and the resulting size (zero padded to the size of the modulus)
whichPK_PUBLIC for public RSA and PK_PRIVATE for private RSA
keyThe RSA key to use
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::set_int)(void *a, unsigned long n)

set small constant

Parameters
aNumber to write to
nSource upto bits_per_digit (actually meant for very small constants)
Returns
CRYPT_OK on succcess
int(* ltc_math_descriptor::sqr)(void *a, void *b)

Square an integer

Parameters
aThe integer to square
bThe destination
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::sqrmod)(void *a, void *b, void *c)

Modular squaring

Parameters
aThe first source
bThe modulus
cThe destination (a*a mod b)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::sub)(void *a, void *b, void *c)

subtract two integers

Parameters
aThe first source integer
bThe second source integer
cThe destination of "a - b"
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::subi)(void *a, unsigned long b, void *c)

subtract two integers

Parameters
aThe first source integer
bThe second source integer (single digit of upto bits_per_digit in length)
cThe destination of "a - b"
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::twoexpt)(void *a, int n)

Compute a power of two

Parameters
aThe integer to store the power in
nThe power of two you want to store (a = 2^n)
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::unsigned_read)(void *dst, unsigned char *src, unsigned long len)

read an array of octets and store as integer

Parameters
dstThe integer to load
srcThe array of octets
lenThe number of octets
Returns
CRYPT_OK on success
unsigned long(* ltc_math_descriptor::unsigned_size)(void *a)

get size as unsigned char string

Parameters
aThe integer to get the size (when stored in array of octets)
Returns
The length of the integer
int(* ltc_math_descriptor::unsigned_write)(void *src, unsigned char *dst)

store an integer as an array of octets

Parameters
srcThe integer to store
dstThe buffer to store the integer in
Returns
CRYPT_OK on success
int(* ltc_math_descriptor::write_radix)(void *a, char *str, int radix)

write number to string

Parameters
aThe integer to store
strThe destination for the string
radixThe radix the integer is to be represented in (2-64)
Returns
CRYPT_OK on success

The documentation for this struct was generated from the following file: