Module: wine Branch: master Commit: 98dad209253a5c4b870d02bdc8b825bc4dcf00d9 URL: http://source.winehq.org/git/wine.git/?a=commit;h=98dad209253a5c4b870d02bdc8...
Author: Andrew Talbot andrew.talbot@talbotville.com Date: Tue Jan 20 22:33:24 2009 +0000
rsaenh: Declare some functions static.
---
dlls/rsaenh/mpi.c | 267 ++++++++++++++++++++++++------------------------ dlls/rsaenh/tomcrypt.h | 19 ---- 2 files changed, 133 insertions(+), 153 deletions(-)
diff --git a/dlls/rsaenh/mpi.c b/dlls/rsaenh/mpi.c index d6d1072..ff514f7 100644 --- a/dlls/rsaenh/mpi.c +++ b/dlls/rsaenh/mpi.c @@ -52,6 +52,42 @@ static int mp_invmod_slow (const mp_int * a, mp_int * b, mp_int * c); static int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); static int mp_karatsuba_sqr(const mp_int *a, mp_int *b);
+/* grow as required */ +static int mp_grow (mp_int * a, int size) +{ + int i; + mp_digit *tmp; + + /* if the alloc size is smaller alloc more ram */ + if (a->alloc < size) { + /* ensure there are always at least MP_PREC digits extra on top */ + size += (MP_PREC * 2) - (size % MP_PREC); + + /* reallocate the array a->dp + * + * We store the return in a temporary variable + * in case the operation failed we don't want + * to overwrite the dp member of a. + */ + tmp = realloc (a->dp, sizeof (mp_digit) * size); + if (tmp == NULL) { + /* reallocation failed but "a" is still valid [can be freed] */ + return MP_MEM; + } + + /* reallocation succeeded so set a->dp */ + a->dp = tmp; + + /* zero excess digits */ + i = a->alloc; + a->alloc = size; + for (; i < a->alloc; i++) { + a->dp[i] = 0; + } + } + return MP_OKAY; +} + /* b = a/2 */ static int mp_div_2(const mp_int * a, mp_int * b) { @@ -99,6 +135,103 @@ static int mp_div_2(const mp_int * a, mp_int * b) return MP_OKAY; }
+/* swap the elements of two integers, for cases where you can't simply swap the + * mp_int pointers around + */ +static void +mp_exch (mp_int * a, mp_int * b) +{ + mp_int t; + + t = *a; + *a = *b; + *b = t; +} + +/* init a new mp_int */ +static int mp_init (mp_int * a) +{ + int i; + + /* allocate memory required and clear it */ + a->dp = malloc (sizeof (mp_digit) * MP_PREC); + if (a->dp == NULL) { + return MP_MEM; + } + + /* set the digits to zero */ + for (i = 0; i < MP_PREC; i++) { + a->dp[i] = 0; + } + + /* set the used to zero, allocated digits to the default precision + * and sign to positive */ + a->used = 0; + a->alloc = MP_PREC; + a->sign = MP_ZPOS; + + return MP_OKAY; +} + +/* init an mp_init for a given size */ +static int mp_init_size (mp_int * a, int size) +{ + int x; + + /* pad size so there are always extra digits */ + size += (MP_PREC * 2) - (size % MP_PREC); + + /* alloc mem */ + a->dp = malloc (sizeof (mp_digit) * size); + if (a->dp == NULL) { + return MP_MEM; + } + + /* set the members */ + a->used = 0; + a->alloc = size; + a->sign = MP_ZPOS; + + /* zero the digits */ + for (x = 0; x < size; x++) { + a->dp[x] = 0; + } + + return MP_OKAY; +} + +/* clear one (frees) */ +static void +mp_clear (mp_int * a) +{ + int i; + + /* only do anything if a hasn't been freed previously */ + if (a->dp != NULL) { + /* first zero the digits */ + for (i = 0; i < a->used; i++) { + a->dp[i] = 0; + } + + /* free ram */ + free(a->dp); + + /* reset members to make debugging easier */ + a->dp = NULL; + a->alloc = a->used = 0; + a->sign = MP_ZPOS; + } +} + +/* set to zero */ +static void +mp_zero (mp_int * a) +{ + a->sign = MP_ZPOS; + a->used = 0; + memset (a->dp, 0, sizeof (mp_digit) * a->alloc); +} + /* computes the modular inverse via binary extended euclidean algorithm, * that is c = 1/a mod b * @@ -846,30 +979,6 @@ mp_clamp (mp_int * a) } }
-/* clear one (frees) */ -void -mp_clear (mp_int * a) -{ - int i; - - /* only do anything if a hasn't been freed previously */ - if (a->dp != NULL) { - /* first zero the digits */ - for (i = 0; i < a->used; i++) { - a->dp[i] = 0; - } - - /* free ram */ - free(a->dp); - - /* reset members to make debugging easier */ - a->dp = NULL; - a->alloc = a->used = 0; - a->sign = MP_ZPOS; - } -} - - void mp_clear_multi(mp_int *mp, ...) { mp_int* next_mp = mp; @@ -1499,19 +1608,6 @@ static void mp_dr_setup(const mp_int *a, mp_digit *d) ((mp_word)a->dp[0])); }
-/* swap the elements of two integers, for cases where you can't simply swap the - * mp_int pointers around - */ -void -mp_exch (mp_int * a, mp_int * b) -{ - mp_int t; - - t = *a; - *a = *b; - *b = t; -} - /* this is a shell function that calls either the normal or Montgomery * exptmod functions. Originally the call to the montgomery code was * embedded in the normal function but that wasted a lot of stack space @@ -1943,67 +2039,6 @@ unsigned long mp_get_int(const mp_int * a) return res & 0xFFFFFFFFUL; }
-/* grow as required */ -int mp_grow (mp_int * a, int size) -{ - int i; - mp_digit *tmp; - - /* if the alloc size is smaller alloc more ram */ - if (a->alloc < size) { - /* ensure there are always at least MP_PREC digits extra on top */ - size += (MP_PREC * 2) - (size % MP_PREC); - - /* reallocate the array a->dp - * - * We store the return in a temporary variable - * in case the operation failed we don't want - * to overwrite the dp member of a. - */ - tmp = realloc (a->dp, sizeof (mp_digit) * size); - if (tmp == NULL) { - /* reallocation failed but "a" is still valid [can be freed] */ - return MP_MEM; - } - - /* reallocation succeeded so set a->dp */ - a->dp = tmp; - - /* zero excess digits */ - i = a->alloc; - a->alloc = size; - for (; i < a->alloc; i++) { - a->dp[i] = 0; - } - } - return MP_OKAY; -} - -/* init a new mp_int */ -int mp_init (mp_int * a) -{ - int i; - - /* allocate memory required and clear it */ - a->dp = malloc (sizeof (mp_digit) * MP_PREC); - if (a->dp == NULL) { - return MP_MEM; - } - - /* set the digits to zero */ - for (i = 0; i < MP_PREC; i++) { - a->dp[i] = 0; - } - - /* set the used to zero, allocated digits to the default precision - * and sign to positive */ - a->used = 0; - a->alloc = MP_PREC; - a->sign = MP_ZPOS; - - return MP_OKAY; -} - /* creates "a" then copies b into it */ int mp_init_copy (mp_int * a, const mp_int * b) { @@ -2051,33 +2086,6 @@ int mp_init_multi(mp_int *mp, ...) return res; /* Assumed ok, if error flagged above. */ }
-/* init an mp_init for a given size */ -int mp_init_size (mp_int * a, int size) -{ - int x; - - /* pad size so there are always extra digits */ - size += (MP_PREC * 2) - (size % MP_PREC); - - /* alloc mem */ - a->dp = malloc (sizeof (mp_digit) * size); - if (a->dp == NULL) { - return MP_MEM; - } - - /* set the members */ - a->used = 0; - a->alloc = size; - a->sign = MP_ZPOS; - - /* zero the digits */ - for (x = 0; x < size; x++) { - a->dp[x] = 0; - } - - return MP_OKAY; -} - /* hac 14.61, pp608 */ int mp_invmod (const mp_int * a, mp_int * b, mp_int * c) { @@ -3850,15 +3858,6 @@ mp_unsigned_bin_size (const mp_int * a) return (size / 8 + ((size & 7) != 0 ? 1 : 0)); }
-/* set to zero */ -void -mp_zero (mp_int * a) -{ - a->sign = MP_ZPOS; - a->used = 0; - memset (a->dp, 0, sizeof (mp_digit) * a->alloc); -} - /* reverse an array, used for radix code */ static void bn_reverse (unsigned char *s, int len) diff --git a/dlls/rsaenh/tomcrypt.h b/dlls/rsaenh/tomcrypt.h index 4ec2dc2..d52ddb3 100644 --- a/dlls/rsaenh/tomcrypt.h +++ b/dlls/rsaenh/tomcrypt.h @@ -235,39 +235,20 @@ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); /* error code to char* string */ char *mp_error_to_string(int code);
-/* ---> init and deinit bignum functions <--- */ -/* init a bignum */ -int mp_init(mp_int *a); - -/* free a bignum */ -void mp_clear(mp_int *a); - /* init a null terminated series of arguments */ int mp_init_multi(mp_int *mp, ...);
/* clear a null terminated series of arguments */ void mp_clear_multi(mp_int *mp, ...);
-/* exchange two ints */ -void mp_exch(mp_int *a, mp_int *b); - /* shrink ram required for a bignum */ int mp_shrink(mp_int *a);
-/* grow an int to a given size */ -int mp_grow(mp_int *a, int size); - -/* init to a given number of digits */ -int mp_init_size(mp_int *a, int size); - /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) #define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO) #define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
-/* set to zero */ -void mp_zero(mp_int *a); - /* set to a digit */ void mp_set(mp_int *a, mp_digit b);