summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_sqr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_sqr.c')
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index 270d0cd348..c1d0cca438 100644
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -77,16 +77,16 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
77 if (al <= 0) 77 if (al <= 0)
78 { 78 {
79 r->top=0; 79 r->top=0;
80 return 1; 80 return(1);
81 } 81 }
82 82
83 BN_CTX_start(ctx); 83 BN_CTX_start(ctx);
84 rr=(a != r) ? r : BN_CTX_get(ctx); 84 rr=(a != r) ? r : BN_CTX_get(ctx);
85 tmp=BN_CTX_get(ctx); 85 tmp=BN_CTX_get(ctx);
86 if (!rr || !tmp) goto err; 86 if (tmp == NULL) goto err;
87 87
88 max = 2 * al; /* Non-zero (from above) */ 88 max=(al+al);
89 if (bn_wexpand(rr,max) == NULL) goto err; 89 if (bn_wexpand(rr,max+1) == NULL) goto err;
90 90
91 if (al == 4) 91 if (al == 4)
92 { 92 {
@@ -138,18 +138,12 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
138#endif 138#endif
139 } 139 }
140 140
141 rr->top=max;
141 rr->neg=0; 142 rr->neg=0;
142 /* If the most-significant half of the top word of 'a' is zero, then 143 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
143 * the square of 'a' will max-1 words. */
144 if(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))
145 rr->top = max - 1;
146 else
147 rr->top = max;
148 if (rr != r) BN_copy(r,rr); 144 if (rr != r) BN_copy(r,rr);
149 ret = 1; 145 ret = 1;
150 err: 146 err:
151 bn_check_top(rr);
152 bn_check_top(tmp);
153 BN_CTX_end(ctx); 147 BN_CTX_end(ctx);
154 return(ret); 148 return(ret);
155 } 149 }