change some parameters in the library to meet the needs of the website httpbin.org

Fork of MiniTLS-GPL by Donatien Garnier

Committer:
shiyilei
Date:
Fri Feb 06 06:17:33 2015 +0000
Revision:
5:95f70ebfe61f
Parent:
0:35aa5be3b78d
change some parameters in the library to meet the needs of httpbin.org

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MiniTLS 0:35aa5be3b78d 1 /* TomsFastMath, a fast ISO C bignum library.
MiniTLS 0:35aa5be3b78d 2 *
MiniTLS 0:35aa5be3b78d 3 * This project is meant to fill in where LibTomMath
MiniTLS 0:35aa5be3b78d 4 * falls short. That is speed ;-)
MiniTLS 0:35aa5be3b78d 5 *
MiniTLS 0:35aa5be3b78d 6 * This project is public domain and free for all purposes.
MiniTLS 0:35aa5be3b78d 7 *
MiniTLS 0:35aa5be3b78d 8 * Tom St Denis, tomstdenis@gmail.com
MiniTLS 0:35aa5be3b78d 9 */
MiniTLS 0:35aa5be3b78d 10
MiniTLS 0:35aa5be3b78d 11 #define TFM_DEFINES
MiniTLS 0:35aa5be3b78d 12 #include "fp_sqr_comba.c"
MiniTLS 0:35aa5be3b78d 13
MiniTLS 0:35aa5be3b78d 14 /* generic comba squarer */
MiniTLS 0:35aa5be3b78d 15 void fp_sqr_comba(fp_int *A, fp_int *B)
MiniTLS 0:35aa5be3b78d 16 {
MiniTLS 0:35aa5be3b78d 17 int pa, ix, iz;
MiniTLS 0:35aa5be3b78d 18 fp_digit c0, c1, c2;
MiniTLS 0:35aa5be3b78d 19 fp_int tmp, *dst;
MiniTLS 0:35aa5be3b78d 20 #ifdef TFM_ISO
MiniTLS 0:35aa5be3b78d 21 fp_word tt;
MiniTLS 0:35aa5be3b78d 22 #endif
MiniTLS 0:35aa5be3b78d 23
MiniTLS 0:35aa5be3b78d 24 /* get size of output and trim */
MiniTLS 0:35aa5be3b78d 25 pa = A->used + A->used;
MiniTLS 0:35aa5be3b78d 26 if (pa >= FP_SIZE) {
MiniTLS 0:35aa5be3b78d 27 pa = FP_SIZE-1;
MiniTLS 0:35aa5be3b78d 28 }
MiniTLS 0:35aa5be3b78d 29
MiniTLS 0:35aa5be3b78d 30 /* number of output digits to produce */
MiniTLS 0:35aa5be3b78d 31 COMBA_START;
MiniTLS 0:35aa5be3b78d 32 CLEAR_CARRY;
MiniTLS 0:35aa5be3b78d 33
MiniTLS 0:35aa5be3b78d 34 if (A == B) {
MiniTLS 0:35aa5be3b78d 35 fp_zero(&tmp);
MiniTLS 0:35aa5be3b78d 36 dst = &tmp;
MiniTLS 0:35aa5be3b78d 37 } else {
MiniTLS 0:35aa5be3b78d 38 fp_zero(B);
MiniTLS 0:35aa5be3b78d 39 dst = B;
MiniTLS 0:35aa5be3b78d 40 }
MiniTLS 0:35aa5be3b78d 41
MiniTLS 0:35aa5be3b78d 42 for (ix = 0; ix < pa; ix++) {
MiniTLS 0:35aa5be3b78d 43 int tx, ty, iy;
MiniTLS 0:35aa5be3b78d 44 fp_digit *tmpy, *tmpx;
MiniTLS 0:35aa5be3b78d 45
MiniTLS 0:35aa5be3b78d 46 /* get offsets into the two bignums */
MiniTLS 0:35aa5be3b78d 47 ty = MIN(A->used-1, ix);
MiniTLS 0:35aa5be3b78d 48 tx = ix - ty;
MiniTLS 0:35aa5be3b78d 49
MiniTLS 0:35aa5be3b78d 50 /* setup temp aliases */
MiniTLS 0:35aa5be3b78d 51 tmpx = A->dp + tx;
MiniTLS 0:35aa5be3b78d 52 tmpy = A->dp + ty;
MiniTLS 0:35aa5be3b78d 53
MiniTLS 0:35aa5be3b78d 54 /* this is the number of times the loop will iterrate,
MiniTLS 0:35aa5be3b78d 55 while (tx++ < a->used && ty-- >= 0) { ... }
MiniTLS 0:35aa5be3b78d 56 */
MiniTLS 0:35aa5be3b78d 57 iy = MIN(A->used-tx, ty+1);
MiniTLS 0:35aa5be3b78d 58
MiniTLS 0:35aa5be3b78d 59 /* now for squaring tx can never equal ty
MiniTLS 0:35aa5be3b78d 60 * we halve the distance since they approach
MiniTLS 0:35aa5be3b78d 61 * at a rate of 2x and we have to round because
MiniTLS 0:35aa5be3b78d 62 * odd cases need to be executed
MiniTLS 0:35aa5be3b78d 63 */
MiniTLS 0:35aa5be3b78d 64 iy = MIN(iy, (ty-tx+1)>>1);
MiniTLS 0:35aa5be3b78d 65
MiniTLS 0:35aa5be3b78d 66 /* forward carries */
MiniTLS 0:35aa5be3b78d 67 CARRY_FORWARD;
MiniTLS 0:35aa5be3b78d 68
MiniTLS 0:35aa5be3b78d 69 /* execute loop */
MiniTLS 0:35aa5be3b78d 70 for (iz = 0; iz < iy; iz++) {
MiniTLS 0:35aa5be3b78d 71 SQRADD2(*tmpx++, *tmpy--);
MiniTLS 0:35aa5be3b78d 72 }
MiniTLS 0:35aa5be3b78d 73
MiniTLS 0:35aa5be3b78d 74 /* even columns have the square term in them */
MiniTLS 0:35aa5be3b78d 75 if ((ix&1) == 0) {
MiniTLS 0:35aa5be3b78d 76 SQRADD(A->dp[ix>>1], A->dp[ix>>1]);
MiniTLS 0:35aa5be3b78d 77 }
MiniTLS 0:35aa5be3b78d 78
MiniTLS 0:35aa5be3b78d 79 /* store it */
MiniTLS 0:35aa5be3b78d 80 COMBA_STORE(dst->dp[ix]);
MiniTLS 0:35aa5be3b78d 81 }
MiniTLS 0:35aa5be3b78d 82
MiniTLS 0:35aa5be3b78d 83 COMBA_FINI;
MiniTLS 0:35aa5be3b78d 84
MiniTLS 0:35aa5be3b78d 85 /* setup dest */
MiniTLS 0:35aa5be3b78d 86 dst->used = pa;
MiniTLS 0:35aa5be3b78d 87 fp_clamp (dst);
MiniTLS 0:35aa5be3b78d 88 if (dst != B) {
MiniTLS 0:35aa5be3b78d 89 fp_copy(dst, B);
MiniTLS 0:35aa5be3b78d 90 }
MiniTLS 0:35aa5be3b78d 91 }
MiniTLS 0:35aa5be3b78d 92
MiniTLS 0:35aa5be3b78d 93 /* $Source: /cvs/libtom/tomsfastmath/src/sqr/Attic/fp_sqr_comba_generic.c,v $ */
MiniTLS 0:35aa5be3b78d 94 /* $Revision: 1.3 $ */
MiniTLS 0:35aa5be3b78d 95 /* $Date: 2007/02/15 00:31:32 $ */