-/******************************************************************************/
-#if OLD_SQUARE
-
-#if DEBUG_SQUARE
-unsigned square_depth = 0;
-#endif
-
-/* square */
-/* (xh*b^n+xl)^2 = xh^2*b^2n + 2*xh*xl*b^n + xl^2 */
-void bigint_square(bigint_t *dest, const bigint_t *a){
- if(a->length_W * sizeof(bigint_word_t) <= 4){
- uint64_t r = 0;
- memcpy(&r, a->wordv, a->length_W * sizeof(bigint_word_t));
- r = r * r;
- memcpy(dest->wordv, &r, 2 * a->length_W * sizeof(bigint_word_t));
- SET_POS(dest);
- dest->length_W = 2 * a->length_W;
- bigint_adjust(dest);
- return;
- }
-
- if(dest->wordv == a->wordv){
- bigint_t d;
- bigint_word_t d_b[a->length_W*2];
- d.wordv = d_b;
- bigint_square(&d, a);
- bigint_copy(dest, &d);
- return;
- }
- bigint_fast_square(dest, a);
- return;
-#if DEBUG_SQUARE
- square_depth += 1;
-#endif
-
- bigint_length_t n;
- n=(a->length_W+1)/2;
- bigint_t xh, xl, tmp; /* x-high, x-low, temp */
- bigint_word_t buffer[2*n+1];
- xl.wordv = a->wordv;
- xl.length_W = n;
- xl.info = 0;
- xh.wordv = &(a->wordv[n]);
- xh.length_W = a->length_W-n;
- xh.info = a->info;
- bigint_adjust(&xl);
- tmp.wordv = buffer;
-/* (xh * b**n + xl)**2 = xh**2 * b**2n + 2 * xh * xl * b**n + xl**2 */
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (a): xl: "); bigint_print_hex(&xl);
- cli_putstr("\r\nDBG (b): xh: "); bigint_print_hex(&xh);
- }
-#endif
- bigint_square(dest, &xl);
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (1): xl**2: "); bigint_print_hex(dest);
- }
-#endif
- bigint_square(&tmp, &xh);
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (2): xh**2: "); bigint_print_hex(&tmp);
- }
-#endif
- bigint_add_scale_u(dest, &tmp, 2 * n * sizeof(bigint_word_t));
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (3): xl**2 + xh**2*n**2: "); bigint_print_hex(dest);
- }
-#endif
- bigint_mul_u(&tmp, &xl, &xh);
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (4): xl*xh: "); bigint_print_hex(&tmp);
- }
-#endif
- bigint_shiftleft(&tmp, 1);
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (5): xl*xh*2: "); bigint_print_hex(&tmp);
- }
-#endif
- bigint_add_scale_u(dest, &tmp, n * sizeof(bigint_word_t));
-#if DEBUG_SQUARE
- if(square_depth == 1){
- cli_putstr("\r\nDBG (6): x**2: "); bigint_print_hex(dest);
- cli_putstr("\r\n");
- }
- square_depth -= 1;
-#endif
-}
-
-#endif
-