diff --git a/src/generators/.gitignore b/src/generators/.gitignore new file mode 100644 index 0000000..7da1b6a --- /dev/null +++ b/src/generators/.gitignore @@ -0,0 +1,2 @@ +comba_sqr_gen +comba_sqr_smallgen diff --git a/src/generators/comba_sqr_gen.c b/src/generators/comba_sqr_gen.c index 57e0737..a5a8ed1 100644 --- a/src/generators/comba_sqr_gen.c +++ b/src/generators/comba_sqr_gen.c @@ -16,10 +16,16 @@ int main(int argc, char **argv) N = atoi(argv[1]); printf( +"#define TFM_DEFINES\n" +"#include \"fp_sqr_comba.c\"\n" +"\n" "#ifdef TFM_SQR%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" @@ -90,8 +96,9 @@ printf( " B->used = %d;\n" " B->sign = FP_ZPOS;\n" " memcpy(B->dp, b, %d * sizeof(fp_digit));\n" +" memset(B->dp + %d, 0, (FP_SIZE - %d) * sizeof(fp_digit));\n" " fp_clamp(B);\n" -"}\n#endif\n\n\n", N+N, N+N); +"}\n#endif\n\n\n", N+N, N+N, N+N, N+N); return 0; } diff --git a/src/generators/comba_sqr_smallgen.c b/src/generators/comba_sqr_smallgen.c index c6e58c9..f4718f0 100644 --- a/src/generators/comba_sqr_smallgen.c +++ b/src/generators/comba_sqr_smallgen.c @@ -16,9 +16,16 @@ 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"); @@ -95,11 +102,12 @@ printf( " B->used = %d;\n" " B->sign = FP_ZPOS;\n" " memcpy(B->dp, b, %d * sizeof(fp_digit));\n" +" memset(B->dp + %d, 0, (FP_SIZE - %d) * sizeof(fp_digit));\n" " fp_clamp(B);\n" -" break;\n\n", N+N, N+N); +" break;\n\n", N+N, N+N, N+N, N+N); } -printf("}\n\n}\n"); +printf("}\n}\n\n#endif /* TFM_SMALL_SET */\n"); return 0; } diff --git a/src/generators/makefile b/src/generators/makefile new file mode 100644 index 0000000..6af8ea0 --- /dev/null +++ b/src/generators/makefile @@ -0,0 +1,17 @@ +all: comba_sqr_gen comba_sqr_smallgen + +clean: + rm -f comba_sqr_gen + rm -f comba_sqr_smallgen + +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_sqr_gen comba_sqr_smallgen + for i in 3 4 6 7 8 9 12 17 20 24 28 32 48 64; do \ + ./comba_sqr_gen $$i > ../sqr/fp_sqr_comba_$$i.c; \ + done + ./comba_sqr_smallgen > ../sqr/fp_sqr_comba_small_set.c + diff --git a/src/sqr/fp_sqr_comba_12.c b/src/sqr/fp_sqr_comba_12.c index a1ed092..4a2e2d8 100644 --- a/src/sqr/fp_sqr_comba_12.c +++ b/src/sqr/fp_sqr_comba_12.c @@ -134,11 +134,9 @@ void fp_sqr_comba12(fp_int *A, fp_int *B) B->used = 24; B->sign = FP_ZPOS; memcpy(B->dp, b, 24 * sizeof(fp_digit)); + memset(B->dp + 24, 0, (FP_SIZE - 24) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_17.c b/src/sqr/fp_sqr_comba_17.c index 798c190..015298a 100644 --- a/src/sqr/fp_sqr_comba_17.c +++ b/src/sqr/fp_sqr_comba_17.c @@ -184,11 +184,9 @@ void fp_sqr_comba17(fp_int *A, fp_int *B) B->used = 34; B->sign = FP_ZPOS; memcpy(B->dp, b, 34 * sizeof(fp_digit)); + memset(B->dp + 34, 0, (FP_SIZE - 34) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_20.c b/src/sqr/fp_sqr_comba_20.c index 35b80e5..d7cb2b9 100644 --- a/src/sqr/fp_sqr_comba_20.c +++ b/src/sqr/fp_sqr_comba_20.c @@ -214,11 +214,9 @@ void fp_sqr_comba20(fp_int *A, fp_int *B) B->used = 40; B->sign = FP_ZPOS; memcpy(B->dp, b, 40 * sizeof(fp_digit)); + memset(B->dp + 40, 0, (FP_SIZE - 40) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_24.c b/src/sqr/fp_sqr_comba_24.c index 7628c32..81e146c 100644 --- a/src/sqr/fp_sqr_comba_24.c +++ b/src/sqr/fp_sqr_comba_24.c @@ -254,11 +254,9 @@ void fp_sqr_comba24(fp_int *A, fp_int *B) B->used = 48; B->sign = FP_ZPOS; memcpy(B->dp, b, 48 * sizeof(fp_digit)); + memset(B->dp + 48, 0, (FP_SIZE - 48) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_28.c b/src/sqr/fp_sqr_comba_28.c index 043574d..89fd3d6 100644 --- a/src/sqr/fp_sqr_comba_28.c +++ b/src/sqr/fp_sqr_comba_28.c @@ -294,11 +294,9 @@ void fp_sqr_comba28(fp_int *A, fp_int *B) B->used = 56; B->sign = FP_ZPOS; memcpy(B->dp, b, 56 * sizeof(fp_digit)); + memset(B->dp + 56, 0, (FP_SIZE - 56) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_3.c b/src/sqr/fp_sqr_comba_3.c index 7aefa4f..a702fed 100644 --- a/src/sqr/fp_sqr_comba_3.c +++ b/src/sqr/fp_sqr_comba_3.c @@ -44,11 +44,9 @@ void fp_sqr_comba3(fp_int *A, fp_int *B) B->used = 6; B->sign = FP_ZPOS; memcpy(B->dp, b, 6 * sizeof(fp_digit)); + memset(B->dp + 6, 0, (FP_SIZE - 6) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_32.c b/src/sqr/fp_sqr_comba_32.c index 2e8ca55..e2446d8 100644 --- a/src/sqr/fp_sqr_comba_32.c +++ b/src/sqr/fp_sqr_comba_32.c @@ -334,11 +334,9 @@ void fp_sqr_comba32(fp_int *A, fp_int *B) B->used = 64; B->sign = FP_ZPOS; memcpy(B->dp, b, 64 * sizeof(fp_digit)); + memset(B->dp + 64, 0, (FP_SIZE - 64) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_4.c b/src/sqr/fp_sqr_comba_4.c index cd8de7e..568f71e 100644 --- a/src/sqr/fp_sqr_comba_4.c +++ b/src/sqr/fp_sqr_comba_4.c @@ -54,11 +54,9 @@ void fp_sqr_comba4(fp_int *A, fp_int *B) B->used = 8; B->sign = FP_ZPOS; memcpy(B->dp, b, 8 * sizeof(fp_digit)); + memset(B->dp + 8, 0, (FP_SIZE - 8) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_48.c b/src/sqr/fp_sqr_comba_48.c index 256f7b9..c2dc85d 100644 --- a/src/sqr/fp_sqr_comba_48.c +++ b/src/sqr/fp_sqr_comba_48.c @@ -494,11 +494,9 @@ void fp_sqr_comba48(fp_int *A, fp_int *B) B->used = 96; B->sign = FP_ZPOS; memcpy(B->dp, b, 96 * sizeof(fp_digit)); + memset(B->dp + 96, 0, (FP_SIZE - 96) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_6.c b/src/sqr/fp_sqr_comba_6.c index 2537621..951d1e6 100644 --- a/src/sqr/fp_sqr_comba_6.c +++ b/src/sqr/fp_sqr_comba_6.c @@ -74,11 +74,9 @@ void fp_sqr_comba6(fp_int *A, fp_int *B) B->used = 12; B->sign = FP_ZPOS; memcpy(B->dp, b, 12 * sizeof(fp_digit)); + memset(B->dp + 12, 0, (FP_SIZE - 12) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_64.c b/src/sqr/fp_sqr_comba_64.c index 88871ac..49a75c4 100644 --- a/src/sqr/fp_sqr_comba_64.c +++ b/src/sqr/fp_sqr_comba_64.c @@ -654,11 +654,9 @@ void fp_sqr_comba64(fp_int *A, fp_int *B) B->used = 128; B->sign = FP_ZPOS; memcpy(B->dp, b, 128 * sizeof(fp_digit)); + memset(B->dp + 128, 0, (FP_SIZE - 128) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_7.c b/src/sqr/fp_sqr_comba_7.c index 08c520f..48ab6f3 100644 --- a/src/sqr/fp_sqr_comba_7.c +++ b/src/sqr/fp_sqr_comba_7.c @@ -84,11 +84,9 @@ void fp_sqr_comba7(fp_int *A, fp_int *B) B->used = 14; B->sign = FP_ZPOS; memcpy(B->dp, b, 14 * sizeof(fp_digit)); + memset(B->dp + 14, 0, (FP_SIZE - 14) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_8.c b/src/sqr/fp_sqr_comba_8.c index 9300b17..b648d31 100644 --- a/src/sqr/fp_sqr_comba_8.c +++ b/src/sqr/fp_sqr_comba_8.c @@ -94,11 +94,9 @@ void fp_sqr_comba8(fp_int *A, fp_int *B) B->used = 16; B->sign = FP_ZPOS; memcpy(B->dp, b, 16 * sizeof(fp_digit)); + memset(B->dp + 16, 0, (FP_SIZE - 16) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_9.c b/src/sqr/fp_sqr_comba_9.c index 880e29e..97be21d 100644 --- a/src/sqr/fp_sqr_comba_9.c +++ b/src/sqr/fp_sqr_comba_9.c @@ -104,11 +104,9 @@ void fp_sqr_comba9(fp_int *A, fp_int *B) B->used = 18; B->sign = FP_ZPOS; memcpy(B->dp, b, 18 * sizeof(fp_digit)); + memset(B->dp + 18, 0, (FP_SIZE - 18) * sizeof(fp_digit)); fp_clamp(B); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/src/sqr/fp_sqr_comba_small_set.c b/src/sqr/fp_sqr_comba_small_set.c index 1d505ea..3f21b8a 100644 --- a/src/sqr/fp_sqr_comba_small_set.c +++ b/src/sqr/fp_sqr_comba_small_set.c @@ -6,8 +6,8 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) { fp_digit *a, b[32], c0, c1, c2, sc0, sc1, sc2; #ifdef TFM_ISO - fp_word tt; -#endif + fp_word tt; +#endif switch (A->used) { case 1: a = A->dp; @@ -25,6 +25,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 2; B->sign = FP_ZPOS; memcpy(B->dp, b, 2 * sizeof(fp_digit)); + memset(B->dp + 2, 0, (FP_SIZE - 2) * sizeof(fp_digit)); fp_clamp(B); break; @@ -54,6 +55,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 4; B->sign = FP_ZPOS; memcpy(B->dp, b, 4 * sizeof(fp_digit)); + memset(B->dp + 4, 0, (FP_SIZE - 4) * sizeof(fp_digit)); fp_clamp(B); break; @@ -93,6 +95,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 6; B->sign = FP_ZPOS; memcpy(B->dp, b, 6 * sizeof(fp_digit)); + memset(B->dp + 6, 0, (FP_SIZE - 6) * sizeof(fp_digit)); fp_clamp(B); break; @@ -142,6 +145,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 8; B->sign = FP_ZPOS; memcpy(B->dp, b, 8 * sizeof(fp_digit)); + memset(B->dp + 8, 0, (FP_SIZE - 8) * sizeof(fp_digit)); fp_clamp(B); break; @@ -201,6 +205,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 10; B->sign = FP_ZPOS; memcpy(B->dp, b, 10 * sizeof(fp_digit)); + memset(B->dp + 10, 0, (FP_SIZE - 10) * sizeof(fp_digit)); fp_clamp(B); break; @@ -270,6 +275,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 12; B->sign = FP_ZPOS; memcpy(B->dp, b, 12 * sizeof(fp_digit)); + memset(B->dp + 12, 0, (FP_SIZE - 12) * sizeof(fp_digit)); fp_clamp(B); break; @@ -349,6 +355,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 14; B->sign = FP_ZPOS; memcpy(B->dp, b, 14 * sizeof(fp_digit)); + memset(B->dp + 14, 0, (FP_SIZE - 14) * sizeof(fp_digit)); fp_clamp(B); break; @@ -438,6 +445,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 16; B->sign = FP_ZPOS; memcpy(B->dp, b, 16 * sizeof(fp_digit)); + memset(B->dp + 16, 0, (FP_SIZE - 16) * sizeof(fp_digit)); fp_clamp(B); break; @@ -537,6 +545,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 18; B->sign = FP_ZPOS; memcpy(B->dp, b, 18 * sizeof(fp_digit)); + memset(B->dp + 18, 0, (FP_SIZE - 18) * sizeof(fp_digit)); fp_clamp(B); break; @@ -646,6 +655,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 20; B->sign = FP_ZPOS; memcpy(B->dp, b, 20 * sizeof(fp_digit)); + memset(B->dp + 20, 0, (FP_SIZE - 20) * sizeof(fp_digit)); fp_clamp(B); break; @@ -765,6 +775,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 22; B->sign = FP_ZPOS; memcpy(B->dp, b, 22 * sizeof(fp_digit)); + memset(B->dp + 22, 0, (FP_SIZE - 22) * sizeof(fp_digit)); fp_clamp(B); break; @@ -894,6 +905,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 24; B->sign = FP_ZPOS; memcpy(B->dp, b, 24 * sizeof(fp_digit)); + memset(B->dp + 24, 0, (FP_SIZE - 24) * sizeof(fp_digit)); fp_clamp(B); break; @@ -1033,6 +1045,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 26; B->sign = FP_ZPOS; memcpy(B->dp, b, 26 * sizeof(fp_digit)); + memset(B->dp + 26, 0, (FP_SIZE - 26) * sizeof(fp_digit)); fp_clamp(B); break; @@ -1182,6 +1195,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 28; B->sign = FP_ZPOS; memcpy(B->dp, b, 28 * sizeof(fp_digit)); + memset(B->dp + 28, 0, (FP_SIZE - 28) * sizeof(fp_digit)); fp_clamp(B); break; @@ -1341,6 +1355,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 30; B->sign = FP_ZPOS; memcpy(B->dp, b, 30 * sizeof(fp_digit)); + memset(B->dp + 30, 0, (FP_SIZE - 30) * sizeof(fp_digit)); fp_clamp(B); break; @@ -1510,13 +1525,11 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B) B->used = 32; B->sign = FP_ZPOS; memcpy(B->dp, b, 32 * sizeof(fp_digit)); + memset(B->dp + 32, 0, (FP_SIZE - 32) * sizeof(fp_digit)); fp_clamp(B); break; + } } #endif /* TFM_SMALL_SET */ - -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */