summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_sqr.c
diff options
context:
space:
mode:
authorbeck <>2002-05-15 02:29:21 +0000
committerbeck <>2002-05-15 02:29:21 +0000
commitb64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch)
treefa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/bn/bn_sqr.c
parente471e1ea98d673597b182ea85f29e30c97cd08b5 (diff)
downloadopenbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2
openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/bn/bn_sqr.c')
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index 75f4f38392..c1d0cca438 100644
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -62,14 +62,14 @@
62 62
63/* r must not be a */ 63/* r must not be a */
64/* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */ 64/* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */
65int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx) 65int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
66 { 66 {
67 int max,al; 67 int max,al;
68 int ret = 0; 68 int ret = 0;
69 BIGNUM *tmp,*rr; 69 BIGNUM *tmp,*rr;
70 70
71#ifdef BN_COUNT 71#ifdef BN_COUNT
72printf("BN_sqr %d * %d\n",a->top,a->top); 72 fprintf(stderr,"BN_sqr %d * %d\n",a->top,a->top);
73#endif 73#endif
74 bn_check_top(a); 74 bn_check_top(a);
75 75
@@ -88,7 +88,6 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
88 max=(al+al); 88 max=(al+al);
89 if (bn_wexpand(rr,max+1) == NULL) goto err; 89 if (bn_wexpand(rr,max+1) == NULL) goto err;
90 90
91 r->neg=0;
92 if (al == 4) 91 if (al == 4)
93 { 92 {
94#ifndef BN_SQR_COMBA 93#ifndef BN_SQR_COMBA
@@ -124,7 +123,6 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
124 k=j+j; 123 k=j+j;
125 if (al == j) 124 if (al == j)
126 { 125 {
127 if (bn_wexpand(a,k*2) == NULL) goto err;
128 if (bn_wexpand(tmp,k*2) == NULL) goto err; 126 if (bn_wexpand(tmp,k*2) == NULL) goto err;
129 bn_sqr_recursive(rr->d,a->d,al,tmp->d); 127 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
130 } 128 }
@@ -141,6 +139,7 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
141 } 139 }
142 140
143 rr->top=max; 141 rr->top=max;
142 rr->neg=0;
144 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; 143 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
145 if (rr != r) BN_copy(r,rr); 144 if (rr != r) BN_copy(r,rr);
146 ret = 1; 145 ret = 1;
@@ -150,10 +149,11 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
150 } 149 }
151 150
152/* tmp must have 2*n words */ 151/* tmp must have 2*n words */
153void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp) 152void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
154 { 153 {
155 int i,j,max; 154 int i,j,max;
156 BN_ULONG *ap,*rp; 155 const BN_ULONG *ap;
156 BN_ULONG *rp;
157 157
158 max=n*2; 158 max=n*2;
159 ap=a; 159 ap=a;
@@ -197,14 +197,14 @@ void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)
197 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) 197 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
198 * a[1]*b[1] 198 * a[1]*b[1]
199 */ 199 */
200void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t) 200void bn_sqr_recursive(BN_ULONG *r, const BN_ULONG *a, int n2, BN_ULONG *t)
201 { 201 {
202 int n=n2/2; 202 int n=n2/2;
203 int zero,c1; 203 int zero,c1;
204 BN_ULONG ln,lo,*p; 204 BN_ULONG ln,lo,*p;
205 205
206#ifdef BN_COUNT 206#ifdef BN_COUNT
207printf(" bn_sqr_recursive %d * %d\n",n2,n2); 207 fprintf(stderr," bn_sqr_recursive %d * %d\n",n2,n2);
208#endif 208#endif
209 if (n2 == 4) 209 if (n2 == 4)
210 { 210 {
@@ -245,7 +245,7 @@ printf(" bn_sqr_recursive %d * %d\n",n2,n2);
245 if (!zero) 245 if (!zero)
246 bn_sqr_recursive(&(t[n2]),t,n,p); 246 bn_sqr_recursive(&(t[n2]),t,n,p);
247 else 247 else
248 memset(&(t[n2]),0,n*sizeof(BN_ULONG)); 248 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
249 bn_sqr_recursive(r,a,n,p); 249 bn_sqr_recursive(r,a,n,p);
250 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p); 250 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p);
251 251