Use large prime table for faster prime gen. Make prime table "const".

Change functions that use prime table to use const arguments.
This commit is contained in:
nelsonb%netscape.com 2000-07-22 05:36:45 +00:00
Родитель cb60172520
Коммит 7e0654a977
3 изменённых файлов: 16 добавлений и 30 удалений

Просмотреть файл

@ -40,7 +40,7 @@
#include "mpprime.h" #include "mpprime.h"
#include <stdlib.h> #include <stdlib.h>
#define SMALL_TABLE /* determines size of hard-wired prime table */ #define SMALL_TABLE 0 /* determines size of hard-wired prime table */
#define RANDOM() rand() #define RANDOM() rand()
@ -51,7 +51,7 @@
is returned; otherwise, MP_YES is returned and 'which' is set to is returned; otherwise, MP_YES is returned and 'which' is set to
the index of the integer in the vector which divided a. the index of the integer in the vector which divided a.
*/ */
mp_err s_mpp_divp(mp_int *a, mp_digit *vec, int size, int *which); mp_err s_mpp_divp(mp_int *a, const mp_digit *vec, int size, int *which);
extern mp_err s_mp_pad(mp_int *mp, mp_size min); /* left pad with zeroes */ extern mp_err s_mp_pad(mp_int *mp, mp_size min); /* left pad with zeroes */
@ -178,7 +178,7 @@ mp_err mpp_random_size(mp_int *a, mp_size prec)
if it is; returns MP_NO if it is not. if it is; returns MP_NO if it is not.
*/ */
mp_err mpp_divis_vector(mp_int *a, mp_digit *vec, int size, int *which) mp_err mpp_divis_vector(mp_int *a, const mp_digit *vec, int size, int *which)
{ {
ARGCHK(a != NULL && vec != NULL && size > 0, MP_BADARG); ARGCHK(a != NULL && vec != NULL && size > 0, MP_BADARG);
@ -380,7 +380,7 @@ X:
first digit against which a is divisible. first digit against which a is divisible.
*/ */
mp_err s_mpp_divp(mp_int *a, mp_digit *vec, int size, int *which) mp_err s_mpp_divp(mp_int *a, const mp_digit *vec, int size, int *which)
{ {
mp_err res; mp_err res;
mp_digit rem; mp_digit rem;

Просмотреть файл

@ -42,7 +42,8 @@
#include "mpi.h" #include "mpi.h"
extern int prime_tab_size; /* number of primes available */ extern const int prime_tab_size; /* number of primes available */
extern const mp_digit prime_tab[];
/* Tests for divisibility */ /* Tests for divisibility */
mp_err mpp_divis(mp_int *a, mp_int *b); mp_err mpp_divis(mp_int *a, mp_int *b);
@ -53,7 +54,7 @@ mp_err mpp_random(mp_int *a);
mp_err mpp_random_size(mp_int *a, mp_size prec); mp_err mpp_random_size(mp_int *a, mp_size prec);
/* Pseudo-primality testing */ /* Pseudo-primality testing */
mp_err mpp_divis_vector(mp_int *a, mp_digit *vec, int size, int *which); mp_err mpp_divis_vector(mp_int *a, const mp_digit *vec, int size, int *which);
mp_err mpp_divis_primes(mp_int *a, mp_digit *np); mp_err mpp_divis_primes(mp_int *a, mp_digit *np);
mp_err mpp_fermat(mp_int *a, mp_digit w); mp_err mpp_fermat(mp_int *a, mp_digit w);
mp_err mpp_pprime(mp_int *a, int nt); mp_err mpp_pprime(mp_int *a, int nt);

Просмотреть файл

@ -39,30 +39,14 @@
* GPL. * GPL.
*/ */
#ifdef SMALL_TABLE #if SMALL_TABLE
int prime_tab_size = 128; #define MP_PRIME_TAB_SIZE 128
mp_digit prime_tab[] = {
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
0x0061, 0x0065, 0x0067, 0x006B, 0x006D, 0x0071, 0x007F, 0x0083,
0x0089, 0x008B, 0x0095, 0x0097, 0x009D, 0x00A3, 0x00A7, 0x00AD,
0x00B3, 0x00B5, 0x00BF, 0x00C1, 0x00C5, 0x00C7, 0x00D3, 0x00DF,
0x00E3, 0x00E5, 0x00E9, 0x00EF, 0x00F1, 0x00FB, 0x0101, 0x0107,
0x010D, 0x010F, 0x0115, 0x0119, 0x011B, 0x0125, 0x0133, 0x0137,
0x0139, 0x013D, 0x014B, 0x0151, 0x015B, 0x015D, 0x0161, 0x0167,
0x016F, 0x0175, 0x017B, 0x017F, 0x0185, 0x018D, 0x0191, 0x0199,
0x01A3, 0x01A5, 0x01AF, 0x01B1, 0x01B7, 0x01BB, 0x01C1, 0x01C9,
0x01CD, 0x01CF, 0x01D3, 0x01DF, 0x01E7, 0x01EB, 0x01F3, 0x01F7,
0x01FD, 0x0209, 0x020B, 0x021D, 0x0223, 0x022D, 0x0233, 0x0239,
0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265,
0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293,
0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF
};
#else #else
int prime_tab_size = 6542; #define MP_PRIME_TAB_SIZE 6542
mp_digit prime_tab[] = { #endif
const int prime_tab_size = MP_PRIME_TAB_SIZE;
const mp_digit prime_tab[] = {
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013, 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035, 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059, 0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
@ -79,6 +63,7 @@ mp_digit prime_tab[] = {
0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265, 0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265,
0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293, 0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293,
0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF, 0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF,
#if ! SMALL_TABLE
0x02D7, 0x02DD, 0x02E3, 0x02E7, 0x02EF, 0x02F5, 0x02F9, 0x0301, 0x02D7, 0x02DD, 0x02E3, 0x02E7, 0x02EF, 0x02F5, 0x02F9, 0x0301,
0x0305, 0x0313, 0x031D, 0x0329, 0x032B, 0x0335, 0x0337, 0x033B, 0x0305, 0x0313, 0x031D, 0x0329, 0x032B, 0x0335, 0x0337, 0x033B,
0x033D, 0x0347, 0x0355, 0x0359, 0x035B, 0x035F, 0x036D, 0x0371, 0x033D, 0x0347, 0x0355, 0x0359, 0x035B, 0x035F, 0x036D, 0x0371,
@ -881,6 +866,6 @@ mp_digit prime_tab[] = {
0xFEF5, 0xFF07, 0xFF0D, 0xFF1D, 0xFF2B, 0xFF2F, 0xFF49, 0xFF4D, 0xFEF5, 0xFF07, 0xFF0D, 0xFF1D, 0xFF2B, 0xFF2F, 0xFF49, 0xFF4D,
0xFF5B, 0xFF65, 0xFF71, 0xFF7F, 0xFF85, 0xFF8B, 0xFF8F, 0xFF9D, 0xFF5B, 0xFF65, 0xFF71, 0xFF7F, 0xFF85, 0xFF8B, 0xFF8F, 0xFF9D,
0xFFA7, 0xFFA9, 0xFFC7, 0xFFD9, 0xFFEF, 0xFFF1, 0xFFA7, 0xFFA9, 0xFFC7, 0xFFD9, 0xFFEF, 0xFFF1,
#endif
}; };
#endif