diff options
author | beck <> | 1999-09-29 04:37:45 +0000 |
---|---|---|
committer | beck <> | 1999-09-29 04:37:45 +0000 |
commit | de8f24ea083384bb66b32ec105dc4743c5663cdf (patch) | |
tree | 1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/bn/bn_gcd.c | |
parent | cb929d29896bcb87c2a97417fbd03e50078fc178 (diff) | |
download | openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2 openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip |
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libcrypto/bn/bn_gcd.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_gcd.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c index 071bba3b4b..64a76f4498 100644 --- a/src/lib/libcrypto/bn/bn_gcd.c +++ b/src/lib/libcrypto/bn/bn_gcd.c | |||
@@ -60,21 +60,17 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn_lcl.h" | 61 | #include "bn_lcl.h" |
62 | 62 | ||
63 | #ifndef NOPROTO | ||
64 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); | 63 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); |
65 | #else | 64 | int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx) |
66 | static BIGNUM *euclid(); | ||
67 | #endif | ||
68 | |||
69 | int BN_gcd(r,in_a,in_b,ctx) | ||
70 | BIGNUM *r,*in_a,*in_b; | ||
71 | BN_CTX *ctx; | ||
72 | { | 65 | { |
73 | BIGNUM *a,*b,*t; | 66 | BIGNUM *a,*b,*t; |
74 | int ret=0; | 67 | int ret=0; |
75 | 68 | ||
76 | a=ctx->bn[ctx->tos]; | 69 | bn_check_top(in_a); |
77 | b=ctx->bn[ctx->tos+1]; | 70 | bn_check_top(in_b); |
71 | |||
72 | a= &(ctx->bn[ctx->tos]); | ||
73 | b= &(ctx->bn[ctx->tos+1]); | ||
78 | 74 | ||
79 | if (BN_copy(a,in_a) == NULL) goto err; | 75 | if (BN_copy(a,in_a) == NULL) goto err; |
80 | if (BN_copy(b,in_b) == NULL) goto err; | 76 | if (BN_copy(b,in_b) == NULL) goto err; |
@@ -89,12 +85,14 @@ err: | |||
89 | return(ret); | 85 | return(ret); |
90 | } | 86 | } |
91 | 87 | ||
92 | static BIGNUM *euclid(a,b) | 88 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b) |
93 | BIGNUM *a,*b; | ||
94 | { | 89 | { |
95 | BIGNUM *t; | 90 | BIGNUM *t; |
96 | int shifts=0; | 91 | int shifts=0; |
97 | 92 | ||
93 | bn_check_top(a); | ||
94 | bn_check_top(b); | ||
95 | |||
98 | for (;;) | 96 | for (;;) |
99 | { | 97 | { |
100 | if (BN_is_zero(b)) | 98 | if (BN_is_zero(b)) |
@@ -142,23 +140,26 @@ err: | |||
142 | } | 140 | } |
143 | 141 | ||
144 | /* solves ax == 1 (mod n) */ | 142 | /* solves ax == 1 (mod n) */ |
145 | BIGNUM *BN_mod_inverse(a, n, ctx) | 143 | BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) |
146 | BIGNUM *a; | ||
147 | BIGNUM *n; | ||
148 | BN_CTX *ctx; | ||
149 | { | 144 | { |
150 | BIGNUM *A,*B,*X,*Y,*M,*D,*R; | 145 | BIGNUM *A,*B,*X,*Y,*M,*D,*R; |
151 | BIGNUM *ret=NULL,*T; | 146 | BIGNUM *T,*ret=NULL; |
152 | int sign; | 147 | int sign; |
153 | 148 | ||
154 | A=ctx->bn[ctx->tos]; | 149 | bn_check_top(a); |
155 | B=ctx->bn[ctx->tos+1]; | 150 | bn_check_top(n); |
156 | X=ctx->bn[ctx->tos+2]; | 151 | |
157 | D=ctx->bn[ctx->tos+3]; | 152 | A= &(ctx->bn[ctx->tos]); |
158 | M=ctx->bn[ctx->tos+4]; | 153 | B= &(ctx->bn[ctx->tos+1]); |
159 | Y=ctx->bn[ctx->tos+5]; | 154 | X= &(ctx->bn[ctx->tos+2]); |
155 | D= &(ctx->bn[ctx->tos+3]); | ||
156 | M= &(ctx->bn[ctx->tos+4]); | ||
157 | Y= &(ctx->bn[ctx->tos+5]); | ||
160 | ctx->tos+=6; | 158 | ctx->tos+=6; |
161 | R=BN_new(); | 159 | if (in == NULL) |
160 | R=BN_new(); | ||
161 | else | ||
162 | R=in; | ||
162 | if (R == NULL) goto err; | 163 | if (R == NULL) goto err; |
163 | 164 | ||
164 | BN_zero(X); | 165 | BN_zero(X); |
@@ -175,7 +176,7 @@ BN_CTX *ctx; | |||
175 | B=M; | 176 | B=M; |
176 | /* T has a struct, M does not */ | 177 | /* T has a struct, M does not */ |
177 | 178 | ||
178 | if (!BN_mul(T,D,X)) goto err; | 179 | if (!BN_mul(T,D,X,ctx)) goto err; |
179 | if (!BN_add(T,T,Y)) goto err; | 180 | if (!BN_add(T,T,Y)) goto err; |
180 | M=Y; | 181 | M=Y; |
181 | Y=X; | 182 | Y=X; |
@@ -196,7 +197,7 @@ BN_CTX *ctx; | |||
196 | } | 197 | } |
197 | ret=R; | 198 | ret=R; |
198 | err: | 199 | err: |
199 | if ((ret == NULL) && (R != NULL)) BN_free(R); | 200 | if ((ret == NULL) && (in == NULL)) BN_free(R); |
200 | ctx->tos-=6; | 201 | ctx->tos-=6; |
201 | return(ret); | 202 | return(ret); |
202 | } | 203 | } |