version 1.23, 2002/11/21 22:22:50 |
version 1.23.2.2, 2004/03/04 18:18:15 |
|
|
|
|
if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL && |
if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL && |
(f = fopen(_PATH_DH_PRIMES, "r")) == NULL) { |
(f = fopen(_PATH_DH_PRIMES, "r")) == NULL) { |
log("WARNING: %s does not exist, using old modulus", _PATH_DH_MODULI); |
logit("WARNING: %s does not exist, using old modulus", _PATH_DH_MODULI); |
return (dh_new_group1()); |
return (dh_new_group1()); |
} |
} |
|
|
|
|
|
|
if (bestcount == 0) { |
if (bestcount == 0) { |
fclose(f); |
fclose(f); |
log("WARNING: no suitable primes in %s", _PATH_DH_PRIMES); |
logit("WARNING: no suitable primes in %s", _PATH_DH_PRIMES); |
return (NULL); |
return (NULL); |
} |
} |
|
|
|
|
int bits_set = 0; |
int bits_set = 0; |
|
|
if (dh_pub->neg) { |
if (dh_pub->neg) { |
log("invalid public DH value: negativ"); |
logit("invalid public DH value: negativ"); |
return 0; |
return 0; |
} |
} |
for (i = 0; i <= n; i++) |
for (i = 0; i <= n; i++) |
|
|
/* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial */ |
/* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial */ |
if (bits_set > 1 && (BN_cmp(dh_pub, dh->p) == -1)) |
if (bits_set > 1 && (BN_cmp(dh_pub, dh->p) == -1)) |
return 1; |
return 1; |
log("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p)); |
logit("invalid public DH value (%d/%d)", bits_set, BN_num_bits(dh->p)); |
return 0; |
return 0; |
} |
} |
|
|
|
|
|
|
if (dh->p == NULL) |
if (dh->p == NULL) |
fatal("dh_gen_key: dh->p == NULL"); |
fatal("dh_gen_key: dh->p == NULL"); |
if (2*need >= BN_num_bits(dh->p)) |
if (need > INT_MAX / 2 || 2 * need >= BN_num_bits(dh->p)) |
fatal("dh_gen_key: group too small: %d (2*need %d)", |
fatal("dh_gen_key: group too small: %d (2*need %d)", |
BN_num_bits(dh->p), 2*need); |
BN_num_bits(dh->p), 2*need); |
do { |
do { |
|
|
dh_estimate(int bits) |
dh_estimate(int bits) |
{ |
{ |
|
|
if (bits < 64) |
if (bits <= 128) |
return (512); /* O(2**63) */ |
|
if (bits < 128) |
|
return (1024); /* O(2**86) */ |
return (1024); /* O(2**86) */ |
if (bits < 192) |
if (bits <= 192) |
return (2048); /* O(2**116) */ |
return (2048); /* O(2**116) */ |
return (4096); /* O(2**156) */ |
return (4096); /* O(2**156) */ |
} |
} |