diff options
author | beck <> | 2000-03-19 11:13:58 +0000 |
---|---|---|
committer | beck <> | 2000-03-19 11:13:58 +0000 |
commit | 796d609550df3a33fc11468741c5d2f6d3df4c11 (patch) | |
tree | 6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libcrypto/bn/bn_sqr.c | |
parent | 5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff) | |
download | openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2 openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip |
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2
if you are using the ssl26 packages for ssh and other things to work you will
need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libcrypto/bn/bn_sqr.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_sqr.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c index 12cce4d7ce..fe00c5f69a 100644 --- a/src/lib/libcrypto/bn/bn_sqr.c +++ b/src/lib/libcrypto/bn/bn_sqr.c | |||
@@ -65,14 +65,13 @@ | |||
65 | int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx) | 65 | int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx) |
66 | { | 66 | { |
67 | int max,al; | 67 | int max,al; |
68 | int ret = 0; | ||
68 | BIGNUM *tmp,*rr; | 69 | BIGNUM *tmp,*rr; |
69 | 70 | ||
70 | #ifdef BN_COUNT | 71 | #ifdef BN_COUNT |
71 | printf("BN_sqr %d * %d\n",a->top,a->top); | 72 | printf("BN_sqr %d * %d\n",a->top,a->top); |
72 | #endif | 73 | #endif |
73 | bn_check_top(a); | 74 | bn_check_top(a); |
74 | tmp= &(ctx->bn[ctx->tos]); | ||
75 | rr=(a != r)?r: (&ctx->bn[ctx->tos+1]); | ||
76 | 75 | ||
77 | al=a->top; | 76 | al=a->top; |
78 | if (al <= 0) | 77 | if (al <= 0) |
@@ -81,8 +80,13 @@ printf("BN_sqr %d * %d\n",a->top,a->top); | |||
81 | return(1); | 80 | return(1); |
82 | } | 81 | } |
83 | 82 | ||
83 | BN_CTX_start(ctx); | ||
84 | rr=(a != r) ? r : BN_CTX_get(ctx); | ||
85 | tmp=BN_CTX_get(ctx); | ||
86 | if (tmp == NULL) goto err; | ||
87 | |||
84 | max=(al+al); | 88 | max=(al+al); |
85 | if (bn_wexpand(rr,max+1) == NULL) return(0); | 89 | if (bn_wexpand(rr,max+1) == NULL) goto err; |
86 | 90 | ||
87 | r->neg=0; | 91 | r->neg=0; |
88 | if (al == 4) | 92 | if (al == 4) |
@@ -120,18 +124,18 @@ printf("BN_sqr %d * %d\n",a->top,a->top); | |||
120 | k=j+j; | 124 | k=j+j; |
121 | if (al == j) | 125 | if (al == j) |
122 | { | 126 | { |
123 | if (bn_wexpand(a,k*2) == NULL) return(0); | 127 | if (bn_wexpand(a,k*2) == NULL) goto err; |
124 | if (bn_wexpand(tmp,k*2) == NULL) return(0); | 128 | if (bn_wexpand(tmp,k*2) == NULL) goto err; |
125 | bn_sqr_recursive(rr->d,a->d,al,tmp->d); | 129 | bn_sqr_recursive(rr->d,a->d,al,tmp->d); |
126 | } | 130 | } |
127 | else | 131 | else |
128 | { | 132 | { |
129 | if (bn_wexpand(tmp,max) == NULL) return(0); | 133 | if (bn_wexpand(tmp,max) == NULL) goto err; |
130 | bn_sqr_normal(rr->d,a->d,al,tmp->d); | 134 | bn_sqr_normal(rr->d,a->d,al,tmp->d); |
131 | } | 135 | } |
132 | } | 136 | } |
133 | #else | 137 | #else |
134 | if (bn_wexpand(tmp,max) == NULL) return(0); | 138 | if (bn_wexpand(tmp,max) == NULL) goto err; |
135 | bn_sqr_normal(rr->d,a->d,al,tmp->d); | 139 | bn_sqr_normal(rr->d,a->d,al,tmp->d); |
136 | #endif | 140 | #endif |
137 | } | 141 | } |
@@ -139,7 +143,10 @@ printf("BN_sqr %d * %d\n",a->top,a->top); | |||
139 | rr->top=max; | 143 | rr->top=max; |
140 | if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; | 144 | if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; |
141 | if (rr != r) BN_copy(r,rr); | 145 | if (rr != r) BN_copy(r,rr); |
142 | return(1); | 146 | ret = 1; |
147 | err: | ||
148 | BN_CTX_end(ctx); | ||
149 | return(ret); | ||
143 | } | 150 | } |
144 | 151 | ||
145 | /* tmp must have 2*n words */ | 152 | /* tmp must have 2*n words */ |
@@ -185,7 +192,7 @@ void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp) | |||
185 | * n must be a power of 2. | 192 | * n must be a power of 2. |
186 | * We multiply and return the result. | 193 | * We multiply and return the result. |
187 | * t must be 2*n words in size | 194 | * t must be 2*n words in size |
188 | * We calulate | 195 | * We calculate |
189 | * a[0]*b[0] | 196 | * a[0]*b[0] |
190 | * 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]) |
191 | * a[1]*b[1] | 198 | * a[1]*b[1] |