Commit d74f3d741a78061d701143628559ca5fd5616a14

Francois Perrad 2018-02-01T22:28:43

static variable & function

diff --git a/demo/demo.c b/demo/demo.c
index a95c768..d69426f 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -32,7 +32,7 @@
 
 #include "tommath.h"
 
-void ndraw(mp_int *a, char *name)
+static void ndraw(mp_int *a, char *name)
 {
    char buf[16000];
 
@@ -50,10 +50,10 @@ static void draw(mp_int *a)
 }
 #endif
 
+#if 0
+static unsigned long lfsr = 0xAAAAAAAAUL;
 
-unsigned long lfsr = 0xAAAAAAAAUL;
-
-int lbit(void)
+static int lbit(void)
 {
    if (lfsr & 0x80000000UL) {
       lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
@@ -63,11 +63,13 @@ int lbit(void)
       return 0;
    }
 }
+#endif
 
 #if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
 static FILE *fd_urandom;
 #endif
-int myrng(unsigned char *dst, int len, void *dat)
+#if LTM_DEMO_TEST_VS_MTEST == 0
+static int myrng(unsigned char *dst, int len, void *dat)
 {
    int x;
    (void)dat;
@@ -89,6 +91,7 @@ int myrng(unsigned char *dst, int len, void *dat)
    }
    return len;
 }
+#endif
 
 #if LTM_DEMO_TEST_VS_MTEST != 0
 static void _panic(int l)
@@ -104,7 +107,7 @@ static void _panic(int l)
       if (!ret) { _panic(__LINE__); } \
    }
 
-mp_int a, b, c, d, e, f;
+static mp_int a, b, c, d, e, f;
 
 static void _cleanup(void)
 {
@@ -116,12 +119,13 @@ static void _cleanup(void)
       fclose(fd_urandom);
 #endif
 }
+#if LTM_DEMO_TEST_VS_MTEST == 0
 struct mp_sqrtmod_prime_st {
    unsigned long p;
    unsigned long n;
    mp_digit r;
 };
-struct mp_sqrtmod_prime_st sqrtmod_prime[] = {
+static struct mp_sqrtmod_prime_st sqrtmod_prime[] = {
    { 5, 14, 3 },
    { 7, 9, 4 },
    { 113, 2, 62 }
@@ -130,14 +134,18 @@ struct mp_jacobi_st {
    unsigned long n;
    int c[16];
 };
-struct mp_jacobi_st jacobi[] = {
+static struct mp_jacobi_st jacobi[] = {
    { 3, {  1, -1,  0,  1, -1,  0,  1, -1,  0,  1, -1,  0,  1, -1,  0,  1 } },
    { 5, {  0,  1, -1, -1,  1,  0,  1, -1, -1,  1,  0,  1, -1, -1,  1,  0 } },
    { 7, {  1, -1,  1, -1, -1,  0,  1,  1, -1,  1, -1, -1,  0,  1,  1, -1 } },
    { 9, { -1,  1,  0,  1,  1,  0,  1,  1,  0,  1,  1,  0,  1,  1,  0,  1 } },
 };
+#endif
 
-char cmd[4096], buf[4096];
+#if LTM_DEMO_TEST_VS_MTEST != 0
+static char cmd[4096];
+#endif
+static char buf[4096];
 int main(void)
 {
    unsigned rr;
diff --git a/demo/timing.c b/demo/timing.c
index 41239e3..38561d4 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -17,7 +17,7 @@
 #endif
 
 
-void ndraw(mp_int *a, char *name)
+static void ndraw(mp_int *a, char *name)
 {
    char buf[4096];
 
@@ -32,9 +32,9 @@ static void draw(mp_int *a)
 }
 
 
-unsigned long lfsr = 0xAAAAAAAAUL;
+static unsigned long lfsr = 0xAAAAAAAAUL;
 
-int lbit(void)
+static int lbit(void)
 {
    if (lfsr & 0x80000000UL) {
       lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
diff --git a/etc/2kprime.c b/etc/2kprime.c
index f3f6b74..47c3b88 100644
--- a/etc/2kprime.c
+++ b/etc/2kprime.c
@@ -2,7 +2,7 @@
 #include <tommath.h>
 #include <time.h>
 
-int sizes[] = {256, 512, 768, 1024, 1536, 2048, 3072, 4096};
+static int sizes[] = {256, 512, 768, 1024, 1536, 2048, 3072, 4096};
 
 int main(void)
 {
diff --git a/etc/drprime.c b/etc/drprime.c
index c683a5e..eb51dcc 100644
--- a/etc/drprime.c
+++ b/etc/drprime.c
@@ -1,7 +1,7 @@
 /* Makes safe primes of a DR nature */
 #include <tommath.h>
 
-int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
+static int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
 
 int main(void)
 {
diff --git a/etc/mersenne.c b/etc/mersenne.c
index bdd819b..99babb1 100644
--- a/etc/mersenne.c
+++ b/etc/mersenne.c
@@ -5,7 +5,7 @@
 #include <time.h>
 #include <tommath.h>
 
-int is_mersenne(long s, int *pp)
+static int is_mersenne(long s, int *pp)
 {
    mp_int  n, u;
    int     res, k;
@@ -69,7 +69,7 @@ LBL_N:
 }
 
 /* square root of a long < 65536 */
-long i_sqrt(long x)
+static long i_sqrt(long x)
 {
    long    x1, x2;
 
@@ -87,7 +87,7 @@ long i_sqrt(long x)
 }
 
 /* is the long prime by brute force */
-int isprime(long k)
+static int isprime(long k)
 {
    long    y, z;
 
diff --git a/etc/pprime.c b/etc/pprime.c
index a1681a8..fc2322a 100644
--- a/etc/pprime.c
+++ b/etc/pprime.c
@@ -7,8 +7,8 @@
 #include <time.h>
 #include "tommath.h"
 
-int   n_prime;
-FILE *primes;
+static int   n_prime;
+static FILE *primes;
 
 /* fast square root */
 static mp_digit i_sqrt(mp_word x)
@@ -152,7 +152,7 @@ static void gen_prime(void)
    fclose(out);
 }
 
-void load_tab(void)
+static void load_tab(void)
 {
    primes = fopen("pprime.dat", "rb");
    if (primes == NULL) {
@@ -163,7 +163,7 @@ void load_tab(void)
    n_prime = ftell(primes) / sizeof(mp_digit);
 }
 
-mp_digit prime_digit(void)
+static mp_digit prime_digit(void)
 {
    int n;
    mp_digit d;
@@ -176,7 +176,7 @@ mp_digit prime_digit(void)
 
 
 /* makes a prime of at least k bits */
-int pprime(int k, int li, mp_int *p, mp_int *q)
+static int pprime(int k, int li, mp_int *p, mp_int *q)
 {
    mp_int  a, b, c, n, x, y, z, v;
    int     res, ii;
diff --git a/etc/tune.c b/etc/tune.c
index b9191e0..82e1796 100644
--- a/etc/tune.c
+++ b/etc/tune.c
@@ -49,9 +49,9 @@ static uint64_t TIMFUNC(void)
 
 /* *INDENT-OFF* */
 /* generic ISO C timer */
-uint64_t LBL_T;
-void t_start(void) { LBL_T = TIMFUNC(); }
-uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
+static uint64_t LBL_T;
+static void t_start(void) { LBL_T = TIMFUNC(); }
+static uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
 /* *INDENT-ON* */
 
 #else
@@ -59,7 +59,7 @@ extern void t_start(void);
 extern uint64_t t_read(void);
 #endif
 
-uint64_t time_mult(int size, int s)
+static uint64_t time_mult(int size, int s)
 {
    unsigned long     x;
    mp_int  a, b, c;
@@ -89,7 +89,7 @@ uint64_t time_mult(int size, int s)
    return t1;
 }
 
-uint64_t time_sqr(int size, int s)
+static uint64_t time_sqr(int size, int s)
 {
    unsigned long     x;
    mp_int  a, b;