comparison libtommath/bn_mp_karatsuba_sqr.c @ 511:582cb38e4eb5 insecure-nocrypto

propagate from branch 'au.asn.ucc.matt.dropbear' (head cdcc3c729e29544e8b98a408e2dc60e4483dfd2a) to branch 'au.asn.ucc.matt.dropbear.insecure-nocrypto' (head 0ca38a1cf349f7426ac9de34ebe4c3e3735effab)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 06 Nov 2008 13:16:55 +0000
parents 5ff8218bcee9
children 60fc6476e044
comparison
equal deleted inserted replaced
361:461c4b1fb35f 511:582cb38e4eb5
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * The library is free for all purposes without any express
13 * guarantee it works. 13 * guarantee it works.
14 * 14 *
15 * Tom St Denis, [email protected], http://math.libtomcrypt.org 15 * Tom St Denis, [email protected], http://math.libtomcrypt.com
16 */ 16 */
17 17
18 /* Karatsuba squaring, computes b = a*a using three 18 /* Karatsuba squaring, computes b = a*a using three
19 * half size squarings 19 * half size squarings
20 * 20 *
78 if (mp_sqr (&x0, &x0x0) != MP_OKAY) 78 if (mp_sqr (&x0, &x0x0) != MP_OKAY)
79 goto X1X1; /* x0x0 = x0*x0 */ 79 goto X1X1; /* x0x0 = x0*x0 */
80 if (mp_sqr (&x1, &x1x1) != MP_OKAY) 80 if (mp_sqr (&x1, &x1x1) != MP_OKAY)
81 goto X1X1; /* x1x1 = x1*x1 */ 81 goto X1X1; /* x1x1 = x1*x1 */
82 82
83 /* now calc (x1-x0)**2 */ 83 /* now calc (x1+x0)**2 */
84 if (mp_sub (&x1, &x0, &t1) != MP_OKAY) 84 if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
85 goto X1X1; /* t1 = x1 - x0 */ 85 goto X1X1; /* t1 = x1 - x0 */
86 if (mp_sqr (&t1, &t1) != MP_OKAY) 86 if (mp_sqr (&t1, &t1) != MP_OKAY)
87 goto X1X1; /* t1 = (x1 - x0) * (x1 - x0) */ 87 goto X1X1; /* t1 = (x1 - x0) * (x1 - x0) */
88 88
89 /* add x0y0 */ 89 /* add x0y0 */
90 if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY) 90 if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
91 goto X1X1; /* t2 = x0x0 + x1x1 */ 91 goto X1X1; /* t2 = x0x0 + x1x1 */
92 if (mp_sub (&t2, &t1, &t1) != MP_OKAY) 92 if (s_mp_sub (&t1, &t2, &t1) != MP_OKAY)
93 goto X1X1; /* t1 = x0x0 + x1x1 - (x1-x0)*(x1-x0) */ 93 goto X1X1; /* t1 = (x1+x0)**2 - (x0x0 + x1x1) */
94 94
95 /* shift by B */ 95 /* shift by B */
96 if (mp_lshd (&t1, B) != MP_OKAY) 96 if (mp_lshd (&t1, B) != MP_OKAY)
97 goto X1X1; /* t1 = (x0x0 + x1x1 - (x1-x0)*(x1-x0))<<B */ 97 goto X1X1; /* t1 = (x0x0 + x1x1 - (x1-x0)*(x1-x0))<<B */
98 if (mp_lshd (&x1x1, B * 2) != MP_OKAY) 98 if (mp_lshd (&x1x1, B * 2) != MP_OKAY)
113 X0:mp_clear (&x0); 113 X0:mp_clear (&x0);
114 ERR: 114 ERR:
115 return err; 115 return err;
116 } 116 }
117 #endif 117 #endif
118
119 /* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_sqr.c,v $ */
120 /* $Revision: 1.5 $ */
121 /* $Date: 2006/03/31 14:18:44 $ */