更新libclamav库1.0.0版本
This commit is contained in:
8
clamav/libclamav/tomsfastmath/generators/.gitignore
vendored
Normal file
8
clamav/libclamav/tomsfastmath/generators/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
comba_mult_gen
|
||||
comba_mult_smallgen
|
||||
comba_sqr_gen
|
||||
comba_sqr_smallgen
|
||||
comba_mult_gen.exe
|
||||
comba_mult_smallgen.exe
|
||||
comba_sqr_gen.exe
|
||||
comba_sqr_smallgen.exe
|
||||
132
clamav/libclamav/tomsfastmath/generators/comba_mont_gen.c
Normal file
132
clamav/libclamav/tomsfastmath/generators/comba_mont_gen.c
Normal file
@@ -0,0 +1,132 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
printf(
|
||||
#if 1
|
||||
"#ifdef TFM_SMALL_SET\n"
|
||||
"/* computes x/R == x (mod N) via Montgomery Reduction */\n"
|
||||
"void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)\n"
|
||||
"{\n"
|
||||
" fp_digit c[FP_SIZE], *_c, *tmpm, mu, cy;\n"
|
||||
" int oldused, x, y, pa;\n"
|
||||
"\n"
|
||||
"#if defined(USE_MEMSET)\n"
|
||||
" /* now zero the buff */\n"
|
||||
" memset(c, 0, sizeof c);\n"
|
||||
"#endif\n"
|
||||
" pa = m->used;\n"
|
||||
"\n"
|
||||
" /* copy the input */\n"
|
||||
" oldused = a->used;\n"
|
||||
" for (x = 0; x < oldused; x++) {\n"
|
||||
" c[x] = a->dp[x];\n"
|
||||
" }\n"
|
||||
"#if !defined(USE_MEMSET)\n"
|
||||
" for (; x < 2*pa+3; x++) {\n"
|
||||
" c[x] = 0;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
" MONT_START;\n"
|
||||
#endif
|
||||
"\n"
|
||||
" switch (pa) {\n");
|
||||
|
||||
for (x = 1; x <= 16; x++) {
|
||||
if (x > 16 && (x != 32 && x != 48 && x != 64)) continue;
|
||||
if (x > 16) printf("#ifdef TFM_HUGE\n");
|
||||
|
||||
|
||||
|
||||
printf(" case %d:\n", x);
|
||||
|
||||
for (y = 0; y < x; y++) {
|
||||
|
||||
printf(" x = %d; cy = 0;\n"
|
||||
" LOOP_START;\n"
|
||||
" _c = c + %d;\n"
|
||||
" tmpm = m->dp;\n", y, y);
|
||||
|
||||
printf("#ifdef INNERMUL8\n");
|
||||
for (z = 0; z+8 <= x; z += 8) {
|
||||
printf(" INNERMUL8; _c += 8; tmpm += 8;\n");
|
||||
}
|
||||
for (; z < x; z++) {
|
||||
printf(" INNERMUL; ++_c;\n");
|
||||
}
|
||||
printf("#else\n");
|
||||
for (z = 0; z < x; z++) {
|
||||
printf(" INNERMUL; ++_c;\n");
|
||||
}
|
||||
printf("#endif\n");
|
||||
printf(" LOOP_END;\n"
|
||||
" while (cy) {\n"
|
||||
" PROPCARRY;\n"
|
||||
" ++_c;\n"
|
||||
" }\n");
|
||||
}
|
||||
//printf(" }\n");
|
||||
printf(" break;\n");
|
||||
|
||||
|
||||
|
||||
#define LOOP_MACRO(stride) \
|
||||
for (x = 0; x < stride; x++) { \
|
||||
fp_digit cy = 0; \
|
||||
/* get Mu for this round */ \
|
||||
LOOP_START; \
|
||||
_c = c + x; \
|
||||
tmpm = m->dp; \
|
||||
for (y = 0; y < stride; y++) { \
|
||||
INNERMUL; \
|
||||
++_c; \
|
||||
} \
|
||||
LOOP_END; \
|
||||
while (cy) { \
|
||||
PROPCARRY; \
|
||||
++_c; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (x > 16) printf("#endif /* TFM_HUGE */\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
||||
printf(
|
||||
" }\n"
|
||||
" /* now copy out */\n"
|
||||
" _c = c + pa;\n"
|
||||
" tmpm = a->dp;\n"
|
||||
" for (x = 0; x < pa+1; x++) {\n"
|
||||
" *tmpm++ = *_c++;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" for (; x < oldused; x++) {\n"
|
||||
" *tmpm++ = 0;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" MONT_FINI;\n"
|
||||
"\n"
|
||||
" a->used = pa+1;\n"
|
||||
" fp_clamp(a);\n"
|
||||
"\n"
|
||||
" /* if A >= m then A = A - m */\n"
|
||||
" if (fp_cmp_mag (a, m) != FP_LT) {\n"
|
||||
" s_fp_sub (a, m, a);\n"
|
||||
" }\n"
|
||||
"}\n\n#endif\n");
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
71
clamav/libclamav/tomsfastmath/generators/comba_mult_gen.c
Normal file
71
clamav/libclamav/tomsfastmath/generators/comba_mult_gen.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
|
||||
/* program emits a NxN comba multiplier */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int N, x, y, z;
|
||||
N = atoi(argv[1]);
|
||||
|
||||
/* print out preamble */
|
||||
printf(
|
||||
"#define TFM_DEFINES\n"
|
||||
"#include \"fp_mul_comba.c\"\n"
|
||||
"\n"
|
||||
"#if defined(TFM_MUL%d) && FP_SIZE >= %d\n"
|
||||
"void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\n"
|
||||
"{\n"
|
||||
" fp_digit c0, c1, c2, at[%d];\n"
|
||||
"\n"
|
||||
" memcpy(at, A->dp, %d * sizeof(fp_digit));\n"
|
||||
" memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n"
|
||||
" COMBA_START;\n"
|
||||
"\n"
|
||||
" COMBA_CLEAR;\n", N, N+N, N, N+N, N, N, N);
|
||||
|
||||
/* now do the rows */
|
||||
for (x = 0; x < (N+N-1); x++) {
|
||||
printf(
|
||||
" /* %d */\n", x);
|
||||
if (x > 0) {
|
||||
printf(
|
||||
" COMBA_FORWARD;\n");
|
||||
}
|
||||
for (y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if ((y+z)==x) {
|
||||
printf(" MULADD(at[%d], at[%d]); ", y, z+N);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf(
|
||||
"\n"
|
||||
" COMBA_STORE(C->dp[%d]);\n", x);
|
||||
}
|
||||
printf(
|
||||
" COMBA_STORE2(C->dp[%d]);\n"
|
||||
" C->used = %d;\n"
|
||||
" C->sign = A->sign ^ B->sign;\n"
|
||||
" fp_clamp(C);\n"
|
||||
" COMBA_FINI;\n"
|
||||
"}\n#endif\n\n\n"
|
||||
"/* $Source$ */\n"
|
||||
"/* $Revision$ */\n"
|
||||
"/* $Date$ */\n"
|
||||
, N+N-1, N+N);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
@@ -0,0 +1,68 @@
|
||||
/* program emits a NxN comba multiplier for 1x1 to 16x16 */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int N, x, y, z;
|
||||
|
||||
/* print out preamble */
|
||||
printf(
|
||||
"#define TFM_DEFINES\n"
|
||||
"#include \"fp_mul_comba.c\"\n"
|
||||
"\n"
|
||||
"#if defined(TFM_SMALL_SET)\n"
|
||||
"void fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)\n"
|
||||
"{\n"
|
||||
" fp_digit c0, c1, c2, at[32];\n"
|
||||
" switch (MAX(A->used, B->used)) { \n"
|
||||
);
|
||||
|
||||
for (N = 1; N <= 16; N++) {
|
||||
|
||||
printf(
|
||||
"\n"
|
||||
" case %d:\n"
|
||||
" memcpy(at, A->dp, %d * sizeof(fp_digit));\n"
|
||||
" memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n"
|
||||
" COMBA_START;\n"
|
||||
"\n"
|
||||
" COMBA_CLEAR;\n", N, N, N, N);
|
||||
|
||||
/* now do the rows */
|
||||
for (x = 0; x < (N+N-1); x++) {
|
||||
printf(
|
||||
" /* %d */\n", x);
|
||||
if (x > 0) {
|
||||
printf(
|
||||
" COMBA_FORWARD;\n");
|
||||
}
|
||||
for (y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if ((y+z)==x) {
|
||||
printf(" MULADD(at[%d], at[%d]); ", y, z+N);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf(
|
||||
"\n"
|
||||
" COMBA_STORE(C->dp[%d]);\n", x);
|
||||
}
|
||||
printf(
|
||||
" COMBA_STORE2(C->dp[%d]);\n"
|
||||
" C->used = %d;\n"
|
||||
" C->sign = A->sign ^ B->sign;\n"
|
||||
" fp_clamp(C);\n"
|
||||
" COMBA_FINI;\n"
|
||||
" break;\n", N+N-1, N+N);
|
||||
}
|
||||
printf(" }\n}\n\n#endif\n\n\n"
|
||||
"/* $Source$ */\n"
|
||||
"/* $Revision$ */\n"
|
||||
"/* $Date$ */\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
112
clamav/libclamav/tomsfastmath/generators/comba_sqr_gen.c
Normal file
112
clamav/libclamav/tomsfastmath/generators/comba_sqr_gen.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int x, y, z, N, f;
|
||||
N = atoi(argv[1]);
|
||||
|
||||
printf(
|
||||
"#define TFM_DEFINES\n"
|
||||
"#include \"fp_sqr_comba.c\"\n"
|
||||
"\n"
|
||||
"#if defined(TFM_SQR%d) && FP_SIZE >= %d\n"
|
||||
"void fp_sqr_comba%d(fp_int *A, fp_int *B)\n"
|
||||
"{\n"
|
||||
" fp_digit *a, b[%d], c0, c1, c2, sc0, sc1, sc2;\n"
|
||||
"#ifdef TFM_ISO\n"
|
||||
" fp_word tt;\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" a = A->dp;\n"
|
||||
" COMBA_START;\n"
|
||||
"\n"
|
||||
" /* clear carries */\n"
|
||||
" CLEAR_CARRY;\n"
|
||||
"\n"
|
||||
" /* output 0 */\n"
|
||||
" SQRADD(a[0],a[0]);\n"
|
||||
" COMBA_STORE(b[0]);\n", N, N+N, N, N+N);
|
||||
|
||||
for (x = 1; x < N+N-1; x++) {
|
||||
printf(
|
||||
"\n /* output %d */\n"
|
||||
" CARRY_FORWARD;\n ", x);
|
||||
|
||||
for (f = y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if (z != y && z + y == x && y <= z) {
|
||||
++f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (f <= 2) {
|
||||
for (y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if (y<=z && (y+z)==x) {
|
||||
if (y == z) {
|
||||
printf("SQRADD(a[%d], a[%d]); ", y, y);
|
||||
} else {
|
||||
printf("SQRADD2(a[%d], a[%d]); ", y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// new method
|
||||
/* do evens first */
|
||||
f = 0;
|
||||
for (y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if (z != y && z + y == x && y <= z) {
|
||||
if (f == 0) {
|
||||
// first double
|
||||
printf("SQRADDSC(a[%d], a[%d]); ", y, z);
|
||||
f = 1;
|
||||
} else {
|
||||
printf("SQRADDAC(a[%d], a[%d]); ", y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// forward the carry
|
||||
printf("SQRADDDB; ");
|
||||
if ((x&1) == 0) {
|
||||
// add the square
|
||||
printf("SQRADD(a[%d], a[%d]); ", x/2, x/2);
|
||||
}
|
||||
}
|
||||
printf("\n COMBA_STORE(b[%d]);\n", x);
|
||||
}
|
||||
printf(" COMBA_STORE2(b[%d]);\n", N+N-1);
|
||||
|
||||
printf(
|
||||
" COMBA_FINI;\n"
|
||||
"\n"
|
||||
" B->used = %d;\n"
|
||||
" B->sign = FP_ZPOS;\n"
|
||||
" memcpy(B->dp, b, %d * sizeof(fp_digit));\n"
|
||||
" fp_clamp(B);\n"
|
||||
"}\n#endif\n\n\n"
|
||||
"/* $Source$ */\n"
|
||||
"/* $Revision$ */\n"
|
||||
"/* $Date$ */\n"
|
||||
, N+N, N+N);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
120
clamav/libclamav/tomsfastmath/generators/comba_sqr_smallgen.c
Normal file
120
clamav/libclamav/tomsfastmath/generators/comba_sqr_smallgen.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
|
||||
/* Generates squaring comba code... it learns it knows our secrets! */
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int x, y, z, N, f;
|
||||
|
||||
printf(
|
||||
"#define TFM_DEFINES\n"
|
||||
"#include \"fp_sqr_comba.c\"\n"
|
||||
"\n"
|
||||
"#if defined(TFM_SMALL_SET)\n"
|
||||
"void fp_sqr_comba_small(fp_int *A, fp_int *B)\n"
|
||||
"{\n"
|
||||
" fp_digit *a, b[32], c0, c1, c2, sc0, sc1, sc2;\n"
|
||||
"#ifdef TFM_ISO\n"
|
||||
" fp_word tt;\n"
|
||||
"#endif\n"
|
||||
);
|
||||
|
||||
printf(" switch (A->used) { \n");
|
||||
|
||||
for (N = 1; N <= 16; N++) {
|
||||
printf(
|
||||
" case %d:\n"
|
||||
" a = A->dp;\n"
|
||||
" COMBA_START; \n"
|
||||
"\n"
|
||||
" /* clear carries */\n"
|
||||
" CLEAR_CARRY;\n"
|
||||
"\n"
|
||||
" /* output 0 */\n"
|
||||
" SQRADD(a[0],a[0]);\n"
|
||||
" COMBA_STORE(b[0]);\n", N);
|
||||
|
||||
for (x = 1; x < N+N-1; x++) {
|
||||
printf(
|
||||
"\n /* output %d */\n"
|
||||
" CARRY_FORWARD;\n ", x);
|
||||
|
||||
for (f = y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if (z != y && z + y == x && y <= z) {
|
||||
++f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (f <= 2) {
|
||||
for (y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if (y<=z && (y+z)==x) {
|
||||
if (y == z) {
|
||||
printf(" SQRADD(a[%d], a[%d]); ", y, y);
|
||||
} else {
|
||||
printf(" SQRADD2(a[%d], a[%d]); ", y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// new method
|
||||
/* do evens first */
|
||||
f = 0;
|
||||
for (y = 0; y < N; y++) {
|
||||
for (z = 0; z < N; z++) {
|
||||
if (z != y && z + y == x && y <= z) {
|
||||
if (f == 0) {
|
||||
// first double
|
||||
printf("SQRADDSC(a[%d], a[%d]); ", y, z);
|
||||
f = 1;
|
||||
} else {
|
||||
printf("SQRADDAC(a[%d], a[%d]); ", y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// forward the carry
|
||||
printf("SQRADDDB; ");
|
||||
if ((x&1) == 0) {
|
||||
// add the square
|
||||
printf("SQRADD(a[%d], a[%d]); ", x/2, x/2);
|
||||
}
|
||||
}
|
||||
printf("\n COMBA_STORE(b[%d]);\n", x);
|
||||
}
|
||||
printf(" COMBA_STORE2(b[%d]);\n", N+N-1);
|
||||
|
||||
printf(
|
||||
" COMBA_FINI;\n"
|
||||
"\n"
|
||||
" B->used = %d;\n"
|
||||
" B->sign = FP_ZPOS;\n"
|
||||
" memcpy(B->dp, b, %d * sizeof(fp_digit));\n"
|
||||
" fp_clamp(B);\n"
|
||||
" break;\n\n", N+N, N+N);
|
||||
}
|
||||
|
||||
printf("}\n}\n\n#endif /* TFM_SMALL_SET */\n\n"
|
||||
"/* $Source$ */\n"
|
||||
"/* $Revision$ */\n"
|
||||
"/* $Date$ */\n"
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
31
clamav/libclamav/tomsfastmath/generators/makefile
Normal file
31
clamav/libclamav/tomsfastmath/generators/makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
all: comba_sqr_gen comba_sqr_smallgen
|
||||
|
||||
clean:
|
||||
rm -f comba_mult_gen
|
||||
rm -f comba_mult_gen.exe
|
||||
rm -f comba_mult_smallgen
|
||||
rm -f comba_mult_smallgen.exe
|
||||
rm -f comba_sqr_gen
|
||||
rm -f comba_sqr_gen.exe
|
||||
rm -f comba_sqr_smallgen
|
||||
rm -f comba_sqr_smallgen.exe
|
||||
|
||||
comba_mult_gen: comba_mult_gen.c
|
||||
gcc -o comba_mult_gen comba_mult_gen.c
|
||||
comba_mult_smallgen: comba_mult_smallgen.c
|
||||
gcc -o comba_mult_smallgen comba_mult_smallgen.c
|
||||
comba_sqr_gen: comba_sqr_gen.c
|
||||
gcc -o comba_sqr_gen comba_sqr_gen.c
|
||||
comba_sqr_smallgen: comba_sqr_smallgen.c
|
||||
gcc -o comba_sqr_smallgen comba_sqr_smallgen.c
|
||||
|
||||
regen: comba_mult_gen comba_mult_smallgen comba_sqr_gen comba_sqr_smallgen
|
||||
for i in 3 4 6 7 8 9 12 17 20 24 28 32 48 64; do \
|
||||
./comba_mult_gen $$i | sed -e 's/ *$$//' > ../mul/fp_mul_comba_$$i.c; \
|
||||
done
|
||||
./comba_mult_smallgen > ../mul/fp_mul_comba_small_set.c
|
||||
for i in 3 4 6 7 8 9 12 17 20 24 28 32 48 64; do \
|
||||
./comba_sqr_gen $$i | sed -e 's/ *$$//' > ../sqr/fp_sqr_comba_$$i.c; \
|
||||
done
|
||||
./comba_sqr_smallgen > ../sqr/fp_sqr_comba_small_set.c
|
||||
|
||||
Reference in New Issue
Block a user