1f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project#include <tommath.h> 2f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project#ifdef BN_MP_TOOM_SQR_C 3f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project/* LibTomMath, multiple-precision integer library -- Tom St Denis 4f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * 5f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * LibTomMath is a library that provides multiple-precision 6f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * integer arithmetic as well as number theoretic functionality. 7f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * 8f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * The library was designed directly after the MPI library by 9f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * Michael Fromberger but has been written from scratch with 10f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * additional optimizations in place. 11f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * 12f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * The library is free for all purposes without any express 13f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * guarantee it works. 14f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * 15f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com 16f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project */ 17f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 18f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project/* squaring using Toom-Cook 3-way algorithm */ 19f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Projectint 20f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Projectmp_toom_sqr(mp_int *a, mp_int *b) 21f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project{ 22f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2; 23f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project int res, B; 24f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 25f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* init temps */ 26f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL)) != MP_OKAY) { 27f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project return res; 28f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 29f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 30f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* B */ 31f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project B = a->used / 3; 32f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 33f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* a = a2 * B**2 + a1 * B + a0 */ 34f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) { 35f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 36f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 37f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 38f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_copy(a, &a1)) != MP_OKAY) { 39f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 40f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 41f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project mp_rshd(&a1, B); 42f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project mp_mod_2d(&a1, DIGIT_BIT * B, &a1); 43f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 44f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_copy(a, &a2)) != MP_OKAY) { 45f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 46f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 47f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project mp_rshd(&a2, B*2); 48f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 49f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* w0 = a0*a0 */ 50f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) { 51f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 52f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 53f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 54f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* w4 = a2 * a2 */ 55f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) { 56f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 57f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 58f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 59f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* w1 = (a2 + 2(a1 + 2a0))**2 */ 60f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { 61f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 62f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 63f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { 64f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 65f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 66f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { 67f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 68f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 69f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { 70f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 71f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 72f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 73f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) { 74f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 75f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 76f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 77f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* w3 = (a0 + 2(a1 + 2a2))**2 */ 78f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { 79f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 80f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 81f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { 82f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 83f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 84f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { 85f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 86f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 87f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { 88f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 89f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 90f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 91f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) { 92f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 93f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 94f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 95f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 96f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* w2 = (a2 + a1 + a0)**2 */ 97f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { 98f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 99f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 100f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { 101f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 102f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 103f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) { 104f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 105f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 106f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 107f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* now solve the matrix 108f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 109f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 0 0 0 0 1 110f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 1 2 4 8 16 111f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 1 1 1 1 1 112f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 16 8 4 2 1 113f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 1 0 0 0 0 114f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 115f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project using 12 subtractions, 4 shifts, 2 small divisions and 1 small multiplication. 116f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project */ 117f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 118f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r1 - r4 */ 119f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { 120f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 121f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 122f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r3 - r0 */ 123f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { 124f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 125f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 126f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r1/2 */ 127f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { 128f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 129f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 130f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r3/2 */ 131f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { 132f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 133f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 134f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r2 - r0 - r4 */ 135f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { 136f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 137f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 138f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { 139f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 140f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 141f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r1 - r2 */ 142f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { 143f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 144f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 145f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r3 - r2 */ 146f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { 147f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 148f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 149f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r1 - 8r0 */ 150f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { 151f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 152f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 153f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { 154f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 155f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 156f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r3 - 8r4 */ 157f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { 158f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 159f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 160f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { 161f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 162f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 163f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* 3r2 - r1 - r3 */ 164f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) { 165f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 166f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 167f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { 168f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 169f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 170f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { 171f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 172f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 173f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r1 - r2 */ 174f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { 175f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 176f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 177f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r3 - r2 */ 178f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { 179f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 180f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 181f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r1/3 */ 182f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { 183f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 184f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 185f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* r3/3 */ 186f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { 187f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 188f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 189f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 190f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project /* at this point shift W[n] by B*n */ 191f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { 192f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 193f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 194f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { 195f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 196f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 197f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { 198f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 199f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 200f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { 201f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 202f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 203f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 204f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) { 205f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 206f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 207f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { 208f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 209f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 210f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { 211f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 212f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 213f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) { 214f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project goto ERR; 215f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project } 216f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 217f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source ProjectERR: 218f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL); 219f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project return res; 220f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project} 221f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 222f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project#endif 223f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project 224f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project/* $Source: /cvs/libtom/libtommath/bn_mp_toom_sqr.c,v $ */ 225f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project/* $Revision: 1.3 $ */ 226f7fc46c63fdc8f39234fea409b8dbe116d73ebf8The Android Open Source Project/* $Date: 2006/03/31 14:18:44 $ */ 227