commit
cbc4260314
@ -6789,6 +6789,13 @@ typedef struct {
|
||||
|
||||
/* ---- data movement ---- */
|
||||
|
||||
/** negate
|
||||
@param src The number to negate
|
||||
@param dst The destination
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*neg)(void *src, void *dst);
|
||||
|
||||
/** copy
|
||||
@param src The number to copy from
|
||||
@param dst The number to write to
|
||||
@ -6800,13 +6807,14 @@ typedef struct {
|
||||
|
||||
/** set small constant
|
||||
@param a Number to write to
|
||||
@param n Source upto bits_per_digit (meant for small constants)
|
||||
@param n Source upto bits_per_digit (actually meant for very small constants)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*set_int)(void *a, unsigned long n);
|
||||
|
||||
/** get small constant
|
||||
@param a Small number to read
|
||||
@param a Small number to read,
|
||||
only fetches up to bits_per_digit from the number
|
||||
@return The lower bits_per_digit of the integer (unsigned)
|
||||
*/
|
||||
unsigned long (*get_int)(void *a);
|
||||
@ -6816,7 +6824,7 @@ typedef struct {
|
||||
@param n The number of the digit to fetch
|
||||
@return The bits_per_digit sized n'th digit of a
|
||||
*/
|
||||
unsigned long (*get_digit)(void *a, int n);
|
||||
ltc_mp_digit (*get_digit)(void *a, int n);
|
||||
|
||||
/** Get the number of digits that represent the number
|
||||
@param a The number to count
|
||||
@ -6880,7 +6888,7 @@ typedef struct {
|
||||
int (*write_radix)(void *a, char *str, int radix);
|
||||
|
||||
/** get size as unsigned char string
|
||||
@param a The integer to get the size
|
||||
@param a The integer to get the size (when stored in array of octets)
|
||||
@return The length of the integer in octets
|
||||
*/
|
||||
unsigned long (*unsigned_size)(void *a);
|
||||
@ -6915,7 +6923,7 @@ typedef struct {
|
||||
/** add two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer
|
||||
(single digit of upto bits_per_digit in length)
|
||||
(single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a + b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
@ -6970,7 +6978,7 @@ typedef struct {
|
||||
@param d The remainder (can be NULL to signify don't care)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*div)(void *a, void *b, void *c, void *d);
|
||||
int (*mpdiv)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** divide by two
|
||||
@param a The integer to divide (shift right)
|
||||
@ -7071,10 +7079,11 @@ typedef struct {
|
||||
|
||||
/** Primality testing
|
||||
@param a The integer to test
|
||||
@param b The destination of the result (FP_YES if prime)
|
||||
@param b The number of Miller-Rabin tests that shall be executed
|
||||
@param c The destination of the result (FP_YES if prime)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*isprime)(void *a, int *b);
|
||||
int (*isprime)(void *a, int b, int *c);
|
||||
|
||||
/* ---- (optional) ecc point math ---- */
|
||||
|
||||
@ -7145,7 +7154,6 @@ typedef struct {
|
||||
ecc_point *C,
|
||||
void *modulus);
|
||||
|
||||
|
||||
/* ---- (optional) rsa optimized math (for internal CRT) ---- */
|
||||
|
||||
/** RSA Key Generation
|
||||
@ -7176,6 +7184,35 @@ typedef struct {
|
||||
int (*rsa_me)(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen, int which,
|
||||
rsa_key *key);
|
||||
|
||||
/* ---- basic math continued ---- */
|
||||
|
||||
/** Modular addition
|
||||
@param a The first source
|
||||
@param b The second source
|
||||
@param c The modulus
|
||||
@param d The destination (a + b mod c)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*addmod)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** Modular substraction
|
||||
@param a The first source
|
||||
@param b The second source
|
||||
@param c The modulus
|
||||
@param d The destination (a - b mod c)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*submod)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/* ---- misc stuff ---- */
|
||||
|
||||
/** Make a pseudo-random mpi
|
||||
@param a The mpi to make random
|
||||
@param size The desired length
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*rand)(void *a, int size);
|
||||
} ltc_math_descriptor;
|
||||
\end{verbatim}
|
||||
\end{small}
|
||||
|
12
makefile
12
makefile
@ -13,14 +13,18 @@ silent=@
|
||||
silent_stdout= > /dev/null
|
||||
endif
|
||||
|
||||
PLATFORM := $(shell uname | sed -e 's/_.*//')
|
||||
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifeq ($(PLATFORM), Darwin)
|
||||
$(error Can't build static library on Mac, please use makefile.shared)
|
||||
endif
|
||||
endif
|
||||
|
||||
# ranlib tools
|
||||
ifndef RANLIB
|
||||
ifeq ($(PLATFORM), Darwin)
|
||||
RANLIB:=$(PREFIX)ranlib -c
|
||||
else
|
||||
RANLIB:=$(PREFIX)ranlib
|
||||
endif
|
||||
endif
|
||||
INSTALL_CMD = install
|
||||
|
||||
#Output filenames for various targets.
|
||||
|
@ -7,6 +7,15 @@
|
||||
#
|
||||
# (GNU make only)
|
||||
|
||||
### USAGE:
|
||||
#
|
||||
# CFLAGS="-DUSE_LTM -DLTM_DESC -I/path/to/libtommath" make -f makefile.shared all EXTRALIBS=/path/to/libtommath/libtommath.a
|
||||
# ./test
|
||||
# make -f makefile.shared DESTDIR=/opt/libtom install
|
||||
#
|
||||
|
||||
PLATFORM := $(shell uname | sed -e 's/_.*//')
|
||||
|
||||
ifndef LT
|
||||
ifeq ($(PLATFORM), Darwin)
|
||||
LT:=glibtool
|
||||
|
@ -7,8 +7,6 @@ VERSION=1.17
|
||||
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
||||
VERSION_LT=0:117
|
||||
|
||||
PLATFORM := $(shell uname | sed -e 's/_.*//')
|
||||
|
||||
# Compiler and Linker Names
|
||||
ifndef PREFIX
|
||||
PREFIX:=
|
||||
@ -45,6 +43,11 @@ endif
|
||||
#
|
||||
# Compilation flags. Note the += does not write over the user's CFLAGS!
|
||||
#
|
||||
# Also note that we're extending the environments' CFLAGS.
|
||||
# If you think that our CFLAGS are not nice you can easily override them
|
||||
# by giving them as a parameter to make:
|
||||
# make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ...
|
||||
#
|
||||
CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE
|
||||
|
||||
ifdef OLD_GCC
|
||||
@ -92,6 +95,9 @@ endif # COMPILE_DEBUG
|
||||
ifneq ($(findstring clang,$(CC)),)
|
||||
CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
|
||||
endif
|
||||
ifeq ($(PLATFORM), Darwin)
|
||||
CFLAGS += -Wno-nullability-completeness
|
||||
endif
|
||||
|
||||
|
||||
GIT_VERSION := $(shell [ -e .git ] && { printf git- ; git describe --tags --always --dirty ; } || echo $(VERSION))
|
||||
@ -337,6 +343,8 @@ $(TOBJECTS): $(HEADERS) $(THEADERS)
|
||||
|
||||
bins: $(USEFUL_DEMOS)
|
||||
|
||||
all: all_test
|
||||
|
||||
all_test: test $(UNBROKEN_DEMOS)
|
||||
|
||||
#build the doxy files (requires Doxygen, tetex and patience)
|
||||
|
@ -536,6 +536,10 @@
|
||||
#error LTC_BLAKE2BMAC requires LTC_BLAKE2B
|
||||
#endif
|
||||
|
||||
#if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
|
||||
#error LTC_NO_MATH defined, but also a math descriptor
|
||||
#endif
|
||||
|
||||
/* THREAD management */
|
||||
#ifdef LTC_PTHREAD
|
||||
|
||||
|
@ -65,13 +65,14 @@ typedef struct {
|
||||
/** set small constant
|
||||
@param a Number to write to
|
||||
@param n Source upto bits_per_digit (actually meant for very small constants)
|
||||
@return CRYPT_OK on succcess
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*set_int)(void *a, unsigned long n);
|
||||
int (*set_int)(void *a, ltc_mp_digit n);
|
||||
|
||||
/** get small constant
|
||||
@param a Number to read, only fetches upto bits_per_digit from the number
|
||||
@return The lower bits_per_digit of the integer (unsigned)
|
||||
@param a Small number to read,
|
||||
only fetches up to bits_per_digit from the number
|
||||
@return The lower bits_per_digit of the integer (unsigned)
|
||||
*/
|
||||
unsigned long (*get_int)(void *a);
|
||||
|
||||
@ -91,16 +92,20 @@ typedef struct {
|
||||
/** compare two integers
|
||||
@param a The left side integer
|
||||
@param b The right side integer
|
||||
@return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
|
||||
@return LTC_MP_LT if a < b,
|
||||
LTC_MP_GT if a > b and
|
||||
LTC_MP_EQ otherwise. (signed comparison)
|
||||
*/
|
||||
int (*compare)(void *a, void *b);
|
||||
|
||||
/** compare against int
|
||||
@param a The left side integer
|
||||
@param b The right side integer (upto bits_per_digit)
|
||||
@return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
|
||||
@return LTC_MP_LT if a < b,
|
||||
LTC_MP_GT if a > b and
|
||||
LTC_MP_EQ otherwise. (signed comparison)
|
||||
*/
|
||||
int (*compare_d)(void *a, unsigned long n);
|
||||
int (*compare_d)(void *a, ltc_mp_digit n);
|
||||
|
||||
/** Count the number of bits used to represent the integer
|
||||
@param a The integer to count
|
||||
@ -140,8 +145,8 @@ typedef struct {
|
||||
int (*write_radix)(void *a, char *str, int radix);
|
||||
|
||||
/** get size as unsigned char string
|
||||
@param a The integer to get the size (when stored in array of octets)
|
||||
@return The length of the integer
|
||||
@param a The integer to get the size (when stored in array of octets)
|
||||
@return The length of the integer in octets
|
||||
*/
|
||||
unsigned long (*unsigned_size)(void *a);
|
||||
|
||||
@ -158,7 +163,9 @@ typedef struct {
|
||||
@param len The number of octets
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
|
||||
int (*unsigned_read)( void *dst,
|
||||
unsigned char *src,
|
||||
unsigned long len);
|
||||
|
||||
/* ---- basic math ---- */
|
||||
|
||||
@ -170,14 +177,14 @@ typedef struct {
|
||||
*/
|
||||
int (*add)(void *a, void *b, void *c);
|
||||
|
||||
|
||||
/** add two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param b The second source integer
|
||||
(single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a + b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*addi)(void *a, unsigned long b, void *c);
|
||||
int (*addi)(void *a, ltc_mp_digit b, void *c);
|
||||
|
||||
/** subtract two integers
|
||||
@param a The first source integer
|
||||
@ -189,15 +196,17 @@ typedef struct {
|
||||
|
||||
/** subtract two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param b The second source integer
|
||||
(single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a - b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*subi)(void *a, unsigned long b, void *c);
|
||||
int (*subi)(void *a, ltc_mp_digit b, void *c);
|
||||
|
||||
/** multiply two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param b The second source integer
|
||||
(single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a * b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
@ -205,11 +214,12 @@ typedef struct {
|
||||
|
||||
/** multiply two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param b The second source integer
|
||||
(single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a * b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*muli)(void *a, unsigned long b, void *c);
|
||||
int (*muli)(void *a, ltc_mp_digit b, void *c);
|
||||
|
||||
/** Square an integer
|
||||
@param a The integer to square
|
||||
@ -240,7 +250,7 @@ typedef struct {
|
||||
@param c The destination for the residue
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*modi)(void *a, unsigned long b, unsigned long *c);
|
||||
int (*modi)(void *a, ltc_mp_digit b, ltc_mp_digit *c);
|
||||
|
||||
/** gcd
|
||||
@param a The first integer
|
||||
@ -285,7 +295,7 @@ typedef struct {
|
||||
|
||||
/* ---- reduction ---- */
|
||||
|
||||
/** setup montgomery
|
||||
/** setup Montgomery
|
||||
@param a The modulus
|
||||
@param b The destination for the reduction digit
|
||||
@return CRYPT_OK on success
|
||||
@ -339,10 +349,15 @@ typedef struct {
|
||||
@param G The point to multiply
|
||||
@param R The destination for kG
|
||||
@param modulus The modulus for the field
|
||||
@param map Boolean indicated whether to map back to affine or not (can be ignored if you work in affine only)
|
||||
@param map Boolean indicated whether to map back to affine or not
|
||||
(can be ignored if you work in affine only)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
|
||||
int (*ecc_ptmul)( void *k,
|
||||
ecc_point *G,
|
||||
ecc_point *R,
|
||||
void *modulus,
|
||||
int map);
|
||||
|
||||
/** ECC GF(p) point addition
|
||||
@param P The first point
|
||||
@ -352,7 +367,11 @@ typedef struct {
|
||||
@param mp The "b" value from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
|
||||
int (*ecc_ptadd)(ecc_point *P,
|
||||
ecc_point *Q,
|
||||
ecc_point *R,
|
||||
void *modulus,
|
||||
void *mp);
|
||||
|
||||
/** ECC GF(p) point double
|
||||
@param P The first point
|
||||
@ -361,15 +380,20 @@ typedef struct {
|
||||
@param mp The "b" value from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_ptdbl)(ecc_point *P, ecc_point *R, void *modulus, void *mp);
|
||||
int (*ecc_ptdbl)(ecc_point *P,
|
||||
ecc_point *R,
|
||||
void *modulus,
|
||||
void *mp);
|
||||
|
||||
/** ECC mapping from projective to affine, currently uses (x,y,z) => (x/z^2, y/z^3, 1)
|
||||
/** ECC mapping from projective to affine,
|
||||
currently uses (x,y,z) => (x/z^2, y/z^3, 1)
|
||||
@param P The point to map
|
||||
@param modulus The modulus
|
||||
@param mp The "b" value from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
@remark 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.
|
||||
@remark 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 (*ecc_map)(ecc_point *P, void *modulus, void *mp);
|
||||
|
||||
@ -378,7 +402,7 @@ typedef struct {
|
||||
@param kA What to multiple A by
|
||||
@param B Second point to multiply
|
||||
@param kB What to multiple B by
|
||||
@param C [out] Destination point (can overlap with A or B
|
||||
@param C [out] Destination point (can overlap with A or B)
|
||||
@param modulus Modulus for curve
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
@ -392,19 +416,24 @@ typedef struct {
|
||||
/** RSA Key Generation
|
||||
@param prng An active PRNG state
|
||||
@param wprng The index of the PRNG desired
|
||||
@param size The size of the modulus (key size) desired (octets)
|
||||
@param e The "e" value (public key). e==65537 is a good choice
|
||||
@param size The size of the key in octets
|
||||
@param e The "e" value (public key).
|
||||
e==65537 is a good choice
|
||||
@param key [out] Destination of a newly created private key pair
|
||||
@return CRYPT_OK if successful, upon error all allocated ram is freed
|
||||
*/
|
||||
int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
|
||||
|
||||
int (*rsa_keygen)(prng_state *prng,
|
||||
int wprng,
|
||||
int size,
|
||||
long e,
|
||||
rsa_key *key);
|
||||
|
||||
/** RSA exponentiation
|
||||
@param in The octet array representing the base
|
||||
@param inlen The length of the input
|
||||
@param out The destination (to be stored in an octet array format)
|
||||
@param outlen The length of the output buffer and the resulting size (zero padded to the size of the modulus)
|
||||
@param outlen The length of the output buffer and the resulting size
|
||||
(zero padded to the size of the modulus)
|
||||
@param which PK_PUBLIC for public RSA and PK_PRIVATE for private RSA
|
||||
@param key The RSA key to use
|
||||
@return CRYPT_OK on success
|
||||
|
@ -61,7 +61,7 @@ static int init_copy(void **a, void *b)
|
||||
}
|
||||
|
||||
/* ---- trivial ---- */
|
||||
static int set_int(void *a, unsigned long b)
|
||||
static int set_int(void *a, ltc_mp_digit b)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
mpz_set_ui(((__mpz_struct *)a), b);
|
||||
@ -101,7 +101,7 @@ static int compare(void *a, void *b)
|
||||
}
|
||||
}
|
||||
|
||||
static int compare_d(void *a, unsigned long b)
|
||||
static int compare_d(void *a, ltc_mp_digit b)
|
||||
{
|
||||
int ret;
|
||||
LTC_ARGCHK(a != NULL);
|
||||
@ -235,7 +235,7 @@ static int add(void *a, void *b, void *c)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int addi(void *a, unsigned long b, void *c)
|
||||
static int addi(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -253,7 +253,7 @@ static int sub(void *a, void *b, void *c)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int subi(void *a, unsigned long b, void *c)
|
||||
static int subi(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -271,7 +271,7 @@ static int mul(void *a, void *b, void *c)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int muli(void *a, unsigned long b, void *c)
|
||||
static int muli(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -317,7 +317,7 @@ static int div_2(void *a, void *b)
|
||||
}
|
||||
|
||||
/* modi */
|
||||
static int modi(void *a, unsigned long b, unsigned long *c)
|
||||
static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
|
@ -88,7 +88,7 @@ static int init_copy(void **a, void *b)
|
||||
}
|
||||
|
||||
/* ---- trivial ---- */
|
||||
static int set_int(void *a, unsigned long b)
|
||||
static int set_int(void *a, ltc_mp_digit b)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
return mpi_to_ltc_error(mp_set_int(a, b));
|
||||
@ -130,7 +130,7 @@ static int compare(void *a, void *b)
|
||||
}
|
||||
}
|
||||
|
||||
static int compare_d(void *a, unsigned long b)
|
||||
static int compare_d(void *a, ltc_mp_digit b)
|
||||
{
|
||||
int ret;
|
||||
LTC_ARGCHK(a != NULL);
|
||||
@ -212,7 +212,7 @@ static int add(void *a, void *b, void *c)
|
||||
return mpi_to_ltc_error(mp_add(a, b, c));
|
||||
}
|
||||
|
||||
static int addi(void *a, unsigned long b, void *c)
|
||||
static int addi(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -228,7 +228,7 @@ static int sub(void *a, void *b, void *c)
|
||||
return mpi_to_ltc_error(mp_sub(a, b, c));
|
||||
}
|
||||
|
||||
static int subi(void *a, unsigned long b, void *c)
|
||||
static int subi(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -244,7 +244,7 @@ static int mul(void *a, void *b, void *c)
|
||||
return mpi_to_ltc_error(mp_mul(a, b, c));
|
||||
}
|
||||
|
||||
static int muli(void *a, unsigned long b, void *c)
|
||||
static int muli(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -275,7 +275,7 @@ static int div_2(void *a, void *b)
|
||||
}
|
||||
|
||||
/* modi */
|
||||
static int modi(void *a, unsigned long b, unsigned long *c)
|
||||
static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c)
|
||||
{
|
||||
mp_digit tmp;
|
||||
int err;
|
||||
|
@ -84,7 +84,7 @@ static int init_copy(void **a, void *b)
|
||||
}
|
||||
|
||||
/* ---- trivial ---- */
|
||||
static int set_int(void *a, unsigned long b)
|
||||
static int set_int(void *a, ltc_mp_digit b)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
fp_set(a, b);
|
||||
@ -129,7 +129,7 @@ static int compare(void *a, void *b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compare_d(void *a, unsigned long b)
|
||||
static int compare_d(void *a, ltc_mp_digit b)
|
||||
{
|
||||
int ret;
|
||||
LTC_ARGCHK(a != NULL);
|
||||
@ -214,7 +214,7 @@ static int add(void *a, void *b, void *c)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int addi(void *a, unsigned long b, void *c)
|
||||
static int addi(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -232,7 +232,7 @@ static int sub(void *a, void *b, void *c)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int subi(void *a, unsigned long b, void *c)
|
||||
static int subi(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -250,7 +250,7 @@ static int mul(void *a, void *b, void *c)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int muli(void *a, unsigned long b, void *c)
|
||||
static int muli(void *a, ltc_mp_digit b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
@ -284,7 +284,7 @@ static int div_2(void *a, void *b)
|
||||
}
|
||||
|
||||
/* modi */
|
||||
static int modi(void *a, unsigned long b, unsigned long *c)
|
||||
static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c)
|
||||
{
|
||||
fp_digit tmp;
|
||||
int err;
|
||||
|
@ -332,6 +332,23 @@ const char *crypt_build_settings =
|
||||
" Katja\n"
|
||||
#endif
|
||||
|
||||
"\nMPI (Math):\n"
|
||||
#if defined(LTC_MPI)
|
||||
" LTC_MPI\n"
|
||||
#endif
|
||||
#if defined(LTM_DESC)
|
||||
" LTM_DESC\n"
|
||||
#endif
|
||||
#if defined(TFM_DESC)
|
||||
" TFM_DESC\n"
|
||||
#endif
|
||||
#if defined(GMP_DESC)
|
||||
" GMP_DESC\n"
|
||||
#endif
|
||||
#if defined(LTC_MILLER_RABIN_REPS)
|
||||
" "NAME_VALUE(LTC_MILLER_RABIN_REPS)"\n"
|
||||
#endif
|
||||
|
||||
"\nCompiler:\n"
|
||||
#if defined(_WIN64)
|
||||
" WIN64 platform detected.\n"
|
||||
@ -390,9 +407,6 @@ const char *crypt_build_settings =
|
||||
#if defined(LTC_HKDF)
|
||||
" HKDF "
|
||||
#endif
|
||||
#if defined(MPI)
|
||||
" MPI "
|
||||
#endif
|
||||
#if defined(LTC_DEVRANDOM)
|
||||
" LTC_DEVRANDOM "
|
||||
#endif
|
||||
@ -456,15 +470,6 @@ const char *crypt_build_settings =
|
||||
#if defined(LTC_PTHREAD)
|
||||
" LTC_PTHREAD "
|
||||
#endif
|
||||
#if defined(LTM_DESC)
|
||||
" LTM_DESC "
|
||||
#endif
|
||||
#if defined(TFM_DESC)
|
||||
" TFM_DESC "
|
||||
#endif
|
||||
#if defined(GMP_DESC)
|
||||
" GMP_DESC "
|
||||
#endif
|
||||
#if defined(LTC_EASY)
|
||||
" LTC_EASY "
|
||||
#endif
|
||||
|
@ -80,6 +80,13 @@ static const crypt_constant _crypt_constants[] = {
|
||||
{"LTC_MDSA", 0},
|
||||
#endif
|
||||
|
||||
#ifdef LTC_DER_MAX_PUBKEY_SIZE
|
||||
_C_STRINGIFY(LTC_DER_MAX_PUBKEY_SIZE),
|
||||
#endif
|
||||
#ifdef LTC_MILLER_RABIN_REPS
|
||||
_C_STRINGIFY(LTC_MILLER_RABIN_REPS),
|
||||
#endif
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
{"LTC_CTR_MODE", 1},
|
||||
_C_STRINGIFY(CTR_COUNTER_LITTLE_ENDIAN),
|
||||
|
@ -71,7 +71,7 @@ int chacha20_prng_add_entropy(const unsigned char *in, unsigned long inlen, prng
|
||||
/* iv 8 bytes */
|
||||
if ((err = chacha_ivctr64(&prng->chacha.s, buf + 32, 8, 0)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* clear KEY + IV */
|
||||
XMEMSET(buf, 0, sizeof(buf));
|
||||
zeromem(buf, sizeof(buf));
|
||||
}
|
||||
else {
|
||||
/* chacha20_prng_ready() was not called yet, add entropy to ent buffer */
|
||||
|
@ -72,6 +72,7 @@ int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *pr
|
||||
if ((err = rc4_stream_setup(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* drop first 3072 bytes - https://en.wikipedia.org/wiki/RC4#Fluhrer.2C_Mantin_and_Shamir_attack */
|
||||
for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf));
|
||||
zeromem(buf, sizeof(buf));
|
||||
}
|
||||
else {
|
||||
/* rc4_ready() was not called yet, add entropy to the buffer */
|
||||
|
@ -73,7 +73,7 @@ int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_stat
|
||||
/* iv 8 bytes */
|
||||
if ((err = sober128_stream_setiv(&prng->sober128.s, buf + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* clear KEY + IV */
|
||||
XMEMSET(buf, 0, sizeof(buf));
|
||||
zeromem(buf, sizeof(buf));
|
||||
}
|
||||
else {
|
||||
/* sober128_ready() was not called yet, add entropy to ent buffer */
|
||||
|
Loading…
Reference in New Issue
Block a user