diff options
author | djm <> | 2010-03-04 11:02:42 +0000 |
---|---|---|
committer | djm <> | 2010-03-04 11:02:42 +0000 |
commit | c87e2fef950513f29035f0902cde1cae8fbaf456 (patch) | |
tree | f4e593c3e9705b2454c89af66d536e4f5e716173 /src | |
parent | eb98df51d4533bcb55eec48a0547d0a3fd3780bc (diff) | |
download | openbsd-c87e2fef950513f29035f0902cde1cae8fbaf456.tar.gz openbsd-c87e2fef950513f29035f0902cde1cae8fbaf456.tar.bz2 openbsd-c87e2fef950513f29035f0902cde1cae8fbaf456.zip |
cherrypick patch from OpenSSL 0.9.8m:
*) Always check bn_wexpend() return values for failure. (CVE-2009-3245)
[Martin Olsson, Neel Mehta]
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_div.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_gf2m.c | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec2_smpl.c | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_div.c | 2 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_gf2m.c | 3 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ec/ec2_smpl.c | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/engines/e_ubsec.c | 4 |
7 files changed, 20 insertions, 14 deletions
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c index 1e8e57626b..d6ddc9cbe3 100644 --- a/src/lib/libcrypto/bn/bn_div.c +++ b/src/lib/libcrypto/bn/bn_div.c | |||
@@ -102,7 +102,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | |||
102 | /* The next 2 are needed so we can do a dv->d[0]|=1 later | 102 | /* The next 2 are needed so we can do a dv->d[0]|=1 later |
103 | * since BN_lshift1 will only work once there is a value :-) */ | 103 | * since BN_lshift1 will only work once there is a value :-) */ |
104 | BN_zero(dv); | 104 | BN_zero(dv); |
105 | bn_wexpand(dv,1); | 105 | if(bn_wexpand(dv,1) == NULL) goto end; |
106 | dv->top=1; | 106 | dv->top=1; |
107 | 107 | ||
108 | if (!BN_lshift(D,D,nm-nd)) goto end; | 108 | if (!BN_lshift(D,D,nm-nd)) goto end; |
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c index 306f029f27..ae642ccb39 100644 --- a/src/lib/libcrypto/bn/bn_gf2m.c +++ b/src/lib/libcrypto/bn/bn_gf2m.c | |||
@@ -294,7 +294,8 @@ int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | |||
294 | if (a->top < b->top) { at = b; bt = a; } | 294 | if (a->top < b->top) { at = b; bt = a; } |
295 | else { at = a; bt = b; } | 295 | else { at = a; bt = b; } |
296 | 296 | ||
297 | bn_wexpand(r, at->top); | 297 | if(bn_wexpand(r, at->top) == NULL) |
298 | return 0; | ||
298 | 299 | ||
299 | for (i = 0; i < bt->top; i++) | 300 | for (i = 0; i < bt->top; i++) |
300 | { | 301 | { |
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c index 5cd1eac41f..522d036ca1 100644 --- a/src/lib/libcrypto/ec/ec2_smpl.c +++ b/src/lib/libcrypto/ec/ec2_smpl.c | |||
@@ -174,8 +174,10 @@ int ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src) | |||
174 | dest->poly[2] = src->poly[2]; | 174 | dest->poly[2] = src->poly[2]; |
175 | dest->poly[3] = src->poly[3]; | 175 | dest->poly[3] = src->poly[3]; |
176 | dest->poly[4] = src->poly[4]; | 176 | dest->poly[4] = src->poly[4]; |
177 | bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 177 | if(bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) |
178 | bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 178 | return 0; |
179 | if(bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) | ||
180 | return 0; | ||
179 | for (i = dest->a.top; i < dest->a.dmax; i++) dest->a.d[i] = 0; | 181 | for (i = dest->a.top; i < dest->a.dmax; i++) dest->a.d[i] = 0; |
180 | for (i = dest->b.top; i < dest->b.dmax; i++) dest->b.d[i] = 0; | 182 | for (i = dest->b.top; i < dest->b.dmax; i++) dest->b.d[i] = 0; |
181 | return 1; | 183 | return 1; |
@@ -199,12 +201,12 @@ int ec_GF2m_simple_group_set_curve(EC_GROUP *group, | |||
199 | 201 | ||
200 | /* group->a */ | 202 | /* group->a */ |
201 | if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) goto err; | 203 | if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) goto err; |
202 | bn_wexpand(&group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 204 | if(bn_wexpand(&group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) goto err; |
203 | for (i = group->a.top; i < group->a.dmax; i++) group->a.d[i] = 0; | 205 | for (i = group->a.top; i < group->a.dmax; i++) group->a.d[i] = 0; |
204 | 206 | ||
205 | /* group->b */ | 207 | /* group->b */ |
206 | if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) goto err; | 208 | if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) goto err; |
207 | bn_wexpand(&group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 209 | if(bn_wexpand(&group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) goto err; |
208 | for (i = group->b.top; i < group->b.dmax; i++) group->b.d[i] = 0; | 210 | for (i = group->b.top; i < group->b.dmax; i++) group->b.d[i] = 0; |
209 | 211 | ||
210 | ret = 1; | 212 | ret = 1; |
diff --git a/src/lib/libssl/src/crypto/bn/bn_div.c b/src/lib/libssl/src/crypto/bn/bn_div.c index 1e8e57626b..d6ddc9cbe3 100644 --- a/src/lib/libssl/src/crypto/bn/bn_div.c +++ b/src/lib/libssl/src/crypto/bn/bn_div.c | |||
@@ -102,7 +102,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | |||
102 | /* The next 2 are needed so we can do a dv->d[0]|=1 later | 102 | /* The next 2 are needed so we can do a dv->d[0]|=1 later |
103 | * since BN_lshift1 will only work once there is a value :-) */ | 103 | * since BN_lshift1 will only work once there is a value :-) */ |
104 | BN_zero(dv); | 104 | BN_zero(dv); |
105 | bn_wexpand(dv,1); | 105 | if(bn_wexpand(dv,1) == NULL) goto end; |
106 | dv->top=1; | 106 | dv->top=1; |
107 | 107 | ||
108 | if (!BN_lshift(D,D,nm-nd)) goto end; | 108 | if (!BN_lshift(D,D,nm-nd)) goto end; |
diff --git a/src/lib/libssl/src/crypto/bn/bn_gf2m.c b/src/lib/libssl/src/crypto/bn/bn_gf2m.c index 306f029f27..ae642ccb39 100644 --- a/src/lib/libssl/src/crypto/bn/bn_gf2m.c +++ b/src/lib/libssl/src/crypto/bn/bn_gf2m.c | |||
@@ -294,7 +294,8 @@ int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | |||
294 | if (a->top < b->top) { at = b; bt = a; } | 294 | if (a->top < b->top) { at = b; bt = a; } |
295 | else { at = a; bt = b; } | 295 | else { at = a; bt = b; } |
296 | 296 | ||
297 | bn_wexpand(r, at->top); | 297 | if(bn_wexpand(r, at->top) == NULL) |
298 | return 0; | ||
298 | 299 | ||
299 | for (i = 0; i < bt->top; i++) | 300 | for (i = 0; i < bt->top; i++) |
300 | { | 301 | { |
diff --git a/src/lib/libssl/src/crypto/ec/ec2_smpl.c b/src/lib/libssl/src/crypto/ec/ec2_smpl.c index 5cd1eac41f..522d036ca1 100644 --- a/src/lib/libssl/src/crypto/ec/ec2_smpl.c +++ b/src/lib/libssl/src/crypto/ec/ec2_smpl.c | |||
@@ -174,8 +174,10 @@ int ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src) | |||
174 | dest->poly[2] = src->poly[2]; | 174 | dest->poly[2] = src->poly[2]; |
175 | dest->poly[3] = src->poly[3]; | 175 | dest->poly[3] = src->poly[3]; |
176 | dest->poly[4] = src->poly[4]; | 176 | dest->poly[4] = src->poly[4]; |
177 | bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 177 | if(bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) |
178 | bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 178 | return 0; |
179 | if(bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) | ||
180 | return 0; | ||
179 | for (i = dest->a.top; i < dest->a.dmax; i++) dest->a.d[i] = 0; | 181 | for (i = dest->a.top; i < dest->a.dmax; i++) dest->a.d[i] = 0; |
180 | for (i = dest->b.top; i < dest->b.dmax; i++) dest->b.d[i] = 0; | 182 | for (i = dest->b.top; i < dest->b.dmax; i++) dest->b.d[i] = 0; |
181 | return 1; | 183 | return 1; |
@@ -199,12 +201,12 @@ int ec_GF2m_simple_group_set_curve(EC_GROUP *group, | |||
199 | 201 | ||
200 | /* group->a */ | 202 | /* group->a */ |
201 | if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) goto err; | 203 | if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) goto err; |
202 | bn_wexpand(&group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 204 | if(bn_wexpand(&group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) goto err; |
203 | for (i = group->a.top; i < group->a.dmax; i++) group->a.d[i] = 0; | 205 | for (i = group->a.top; i < group->a.dmax; i++) group->a.d[i] = 0; |
204 | 206 | ||
205 | /* group->b */ | 207 | /* group->b */ |
206 | if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) goto err; | 208 | if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) goto err; |
207 | bn_wexpand(&group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2); | 209 | if(bn_wexpand(&group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2) == NULL) goto err; |
208 | for (i = group->b.top; i < group->b.dmax; i++) group->b.d[i] = 0; | 210 | for (i = group->b.top; i < group->b.dmax; i++) group->b.d[i] = 0; |
209 | 211 | ||
210 | ret = 1; | 212 | ret = 1; |
diff --git a/src/lib/libssl/src/engines/e_ubsec.c b/src/lib/libssl/src/engines/e_ubsec.c index e8389de6a1..a0f320caf5 100644 --- a/src/lib/libssl/src/engines/e_ubsec.c +++ b/src/lib/libssl/src/engines/e_ubsec.c | |||
@@ -934,7 +934,7 @@ static int ubsec_dh_generate_key(DH *dh) | |||
934 | priv_key = BN_new(); | 934 | priv_key = BN_new(); |
935 | if (priv_key == NULL) goto err; | 935 | if (priv_key == NULL) goto err; |
936 | priv_key_len = BN_num_bits(dh->p); | 936 | priv_key_len = BN_num_bits(dh->p); |
937 | bn_wexpand(priv_key, dh->p->top); | 937 | if(bn_wexpand(priv_key, dh->p->top) == NULL) goto err; |
938 | do | 938 | do |
939 | if (!BN_rand_range(priv_key, dh->p)) goto err; | 939 | if (!BN_rand_range(priv_key, dh->p)) goto err; |
940 | while (BN_is_zero(priv_key)); | 940 | while (BN_is_zero(priv_key)); |
@@ -949,7 +949,7 @@ static int ubsec_dh_generate_key(DH *dh) | |||
949 | { | 949 | { |
950 | pub_key = BN_new(); | 950 | pub_key = BN_new(); |
951 | pub_key_len = BN_num_bits(dh->p); | 951 | pub_key_len = BN_num_bits(dh->p); |
952 | bn_wexpand(pub_key, dh->p->top); | 952 | if(bn_wexpand(pub_key, dh->p->top) == NULL) goto err; |
953 | if(pub_key == NULL) goto err; | 953 | if(pub_key == NULL) goto err; |
954 | } | 954 | } |
955 | else | 955 | else |