static variable & function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
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;