diff options
author | Darren Tucker <dtucker@zip.com.au> | 2006-05-06 17:43:33 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2006-05-06 17:43:33 +1000 |
commit | 31cde6828d7772c5ea06c882a17c06fc42845d79 (patch) | |
tree | a499dbe72bc84656acb77e5d65518459a6bc3875 /dh.c | |
parent | 232b76f9f8b883db9ff7e7a3a9942ad7a28119e0 (diff) |
- djm@cvs.openbsd.org 2006/05/04 14:55:23
[dh.c]
tighter DH exponent checks here too; feedback and ok markus@
Diffstat (limited to 'dh.c')
-rw-r--r-- | dh.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dh.c,v 1.35 2006/03/27 13:03:54 deraadt Exp $ */ | 1 | /* $OpenBSD: dh.c,v 1.36 2006/05/04 14:55:23 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Niels Provos. All rights reserved. | 3 | * Copyright (c) 2000 Niels Provos. All rights reserved. |
4 | * | 4 | * |
@@ -181,19 +181,36 @@ dh_pub_is_valid(DH *dh, BIGNUM *dh_pub) | |||
181 | int i; | 181 | int i; |
182 | int n = BN_num_bits(dh_pub); | 182 | int n = BN_num_bits(dh_pub); |
183 | int bits_set = 0; | 183 | int bits_set = 0; |
184 | BIGNUM *tmp; | ||
184 | 185 | ||
185 | if (dh_pub->neg) { | 186 | if (dh_pub->neg) { |
186 | logit("invalid public DH value: negativ"); | 187 | logit("invalid public DH value: negativ"); |
187 | return 0; | 188 | return 0; |
188 | } | 189 | } |
190 | if (BN_cmp(dh_pub, BN_value_one()) != 1) { /* pub_exp <= 1 */ | ||
191 | logit("invalid public DH value: <= 1"); | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | if ((tmp = BN_new()) == NULL) | ||
196 | return (-1); | ||
197 | if (!BN_sub(tmp, dh->p, BN_value_one()) || | ||
198 | BN_cmp(dh_pub, tmp) != -1) { /* pub_exp > p-2 */ | ||
199 | BN_clear_free(tmp); | ||
200 | logit("invalid public DH value: >= p-1"); | ||
201 | return 0; | ||
202 | } | ||
203 | BN_clear_free(tmp); | ||
204 | |||
189 | for (i = 0; i <= n; i++) | 205 | for (i = 0; i <= n; i++) |
190 | if (BN_is_bit_set(dh_pub, i)) | 206 | if (BN_is_bit_set(dh_pub, i)) |
191 | bits_set++; | 207 | bits_set++; |
192 | debug2("bits set: %d/%d", bits_set, BN_num_bits(dh->p)); | 208 | debug2("bits set: %d/%d", bits_set, BN_num_bits(dh->p)); |
193 | 209 | ||
194 | /* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial */ | 210 | /* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial */ |
195 | if (bits_set > 1 && (BN_cmp(dh_pub, dh->p) == -1)) | 211 | if (bits_set > 1) |
196 | return 1; | 212 | return 1; |
213 | |||
197 | logit("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p)); | 214 | logit("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p)); |
198 | return 0; | 215 | return 0; |
199 | } | 216 | } |