Mercurial > dropbear
comparison bn_mp_karatsuba_sqr.c @ 386:97db060d0ef5 libtommath-orig libtommath-0.40
Update to LibTomMath 0.40
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 11 Jan 2007 03:11:15 +0000 |
parents | 91fbc376f010 |
children |
comparison
equal
deleted
inserted
replaced
282:91fbc376f010 | 386:97db060d0ef5 |
---|---|
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 $ */ |