static variable & function
This commit is contained in:
parent
8a8659f283
commit
d74f3d741a
26
demo/demo.c
26
demo/demo.c
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include "tommath.h"
|
#include "tommath.h"
|
||||||
|
|
||||||
void ndraw(mp_int *a, char *name)
|
static void ndraw(mp_int *a, char *name)
|
||||||
{
|
{
|
||||||
char buf[16000];
|
char buf[16000];
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ static void draw(mp_int *a)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static unsigned long lfsr = 0xAAAAAAAAUL;
|
||||||
|
|
||||||
unsigned long lfsr = 0xAAAAAAAAUL;
|
static int lbit(void)
|
||||||
|
|
||||||
int lbit(void)
|
|
||||||
{
|
{
|
||||||
if (lfsr & 0x80000000UL) {
|
if (lfsr & 0x80000000UL) {
|
||||||
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
||||||
|
@ -63,11 +63,13 @@ int lbit(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
|
#if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
|
||||||
static FILE *fd_urandom;
|
static FILE *fd_urandom;
|
||||||
#endif
|
#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;
|
int x;
|
||||||
(void)dat;
|
(void)dat;
|
||||||
|
@ -89,6 +91,7 @@ int myrng(unsigned char *dst, int len, void *dat)
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LTM_DEMO_TEST_VS_MTEST != 0
|
#if LTM_DEMO_TEST_VS_MTEST != 0
|
||||||
static void _panic(int l)
|
static void _panic(int l)
|
||||||
|
@ -104,7 +107,7 @@ static void _panic(int l)
|
||||||
if (!ret) { _panic(__LINE__); } \
|
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)
|
static void _cleanup(void)
|
||||||
{
|
{
|
||||||
|
@ -116,12 +119,13 @@ static void _cleanup(void)
|
||||||
fclose(fd_urandom);
|
fclose(fd_urandom);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#if LTM_DEMO_TEST_VS_MTEST == 0
|
||||||
struct mp_sqrtmod_prime_st {
|
struct mp_sqrtmod_prime_st {
|
||||||
unsigned long p;
|
unsigned long p;
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
mp_digit r;
|
mp_digit r;
|
||||||
};
|
};
|
||||||
struct mp_sqrtmod_prime_st sqrtmod_prime[] = {
|
static struct mp_sqrtmod_prime_st sqrtmod_prime[] = {
|
||||||
{ 5, 14, 3 },
|
{ 5, 14, 3 },
|
||||||
{ 7, 9, 4 },
|
{ 7, 9, 4 },
|
||||||
{ 113, 2, 62 }
|
{ 113, 2, 62 }
|
||||||
|
@ -130,14 +134,18 @@ struct mp_jacobi_st {
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
int c[16];
|
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 } },
|
{ 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 } },
|
{ 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 } },
|
{ 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 } },
|
{ 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)
|
int main(void)
|
||||||
{
|
{
|
||||||
unsigned rr;
|
unsigned rr;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ndraw(mp_int *a, char *name)
|
static void ndraw(mp_int *a, char *name)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
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) {
|
if (lfsr & 0x80000000UL) {
|
||||||
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
#include <time.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)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* Makes safe primes of a DR nature */
|
/* Makes safe primes of a DR nature */
|
||||||
#include <tommath.h>
|
#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)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
|
|
||||||
int is_mersenne(long s, int *pp)
|
static int is_mersenne(long s, int *pp)
|
||||||
{
|
{
|
||||||
mp_int n, u;
|
mp_int n, u;
|
||||||
int res, k;
|
int res, k;
|
||||||
|
@ -69,7 +69,7 @@ LBL_N:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* square root of a long < 65536 */
|
/* square root of a long < 65536 */
|
||||||
long i_sqrt(long x)
|
static long i_sqrt(long x)
|
||||||
{
|
{
|
||||||
long x1, x2;
|
long x1, x2;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ long i_sqrt(long x)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is the long prime by brute force */
|
/* is the long prime by brute force */
|
||||||
int isprime(long k)
|
static int isprime(long k)
|
||||||
{
|
{
|
||||||
long y, z;
|
long y, z;
|
||||||
|
|
||||||
|
|
10
etc/pprime.c
10
etc/pprime.c
|
@ -7,8 +7,8 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "tommath.h"
|
#include "tommath.h"
|
||||||
|
|
||||||
int n_prime;
|
static int n_prime;
|
||||||
FILE *primes;
|
static FILE *primes;
|
||||||
|
|
||||||
/* fast square root */
|
/* fast square root */
|
||||||
static mp_digit i_sqrt(mp_word x)
|
static mp_digit i_sqrt(mp_word x)
|
||||||
|
@ -152,7 +152,7 @@ static void gen_prime(void)
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_tab(void)
|
static void load_tab(void)
|
||||||
{
|
{
|
||||||
primes = fopen("pprime.dat", "rb");
|
primes = fopen("pprime.dat", "rb");
|
||||||
if (primes == NULL) {
|
if (primes == NULL) {
|
||||||
|
@ -163,7 +163,7 @@ void load_tab(void)
|
||||||
n_prime = ftell(primes) / sizeof(mp_digit);
|
n_prime = ftell(primes) / sizeof(mp_digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_digit prime_digit(void)
|
static mp_digit prime_digit(void)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
mp_digit d;
|
mp_digit d;
|
||||||
|
@ -176,7 +176,7 @@ mp_digit prime_digit(void)
|
||||||
|
|
||||||
|
|
||||||
/* makes a prime of at least k bits */
|
/* 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;
|
mp_int a, b, c, n, x, y, z, v;
|
||||||
int res, ii;
|
int res, ii;
|
||||||
|
|
10
etc/tune.c
10
etc/tune.c
|
@ -49,9 +49,9 @@ static uint64_t TIMFUNC(void)
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
/* generic ISO C timer */
|
/* generic ISO C timer */
|
||||||
uint64_t LBL_T;
|
static uint64_t LBL_T;
|
||||||
void t_start(void) { LBL_T = TIMFUNC(); }
|
static void t_start(void) { LBL_T = TIMFUNC(); }
|
||||||
uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
|
static uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -59,7 +59,7 @@ extern void t_start(void);
|
||||||
extern uint64_t t_read(void);
|
extern uint64_t t_read(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint64_t time_mult(int size, int s)
|
static uint64_t time_mult(int size, int s)
|
||||||
{
|
{
|
||||||
unsigned long x;
|
unsigned long x;
|
||||||
mp_int a, b, c;
|
mp_int a, b, c;
|
||||||
|
@ -89,7 +89,7 @@ uint64_t time_mult(int size, int s)
|
||||||
return t1;
|
return t1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t time_sqr(int size, int s)
|
static uint64_t time_sqr(int size, int s)
|
||||||
{
|
{
|
||||||
unsigned long x;
|
unsigned long x;
|
||||||
mp_int a, b;
|
mp_int a, b;
|
||||||
|
|
Loading…
Reference in New Issue