diff options
Diffstat (limited to 'src/lib/libcrypto/dh/dh_gen.c')
-rw-r--r-- | src/lib/libcrypto/dh/dh_gen.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c index cfd5b11868..23777f5a16 100644 --- a/src/lib/libcrypto/dh/dh_gen.c +++ b/src/lib/libcrypto/dh/dh_gen.c | |||
@@ -56,25 +56,11 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | /* NB: These functions have been upgraded - the previous prototypes are in | ||
60 | * dh_depr.c as wrappers to these ones. | ||
61 | * - Geoff | ||
62 | */ | ||
63 | |||
64 | #include <stdio.h> | 59 | #include <stdio.h> |
65 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
66 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
67 | #include <openssl/dh.h> | 62 | #include <openssl/dh.h> |
68 | 63 | ||
69 | static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb); | ||
70 | |||
71 | int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb) | ||
72 | { | ||
73 | if(ret->meth->generate_params) | ||
74 | return ret->meth->generate_params(ret, prime_len, generator, cb); | ||
75 | return dh_builtin_genparams(ret, prime_len, generator, cb); | ||
76 | } | ||
77 | |||
78 | /* We generate DH parameters as follows | 64 | /* We generate DH parameters as follows |
79 | * find a prime q which is prime_len/2 bits long. | 65 | * find a prime q which is prime_len/2 bits long. |
80 | * p=(2*q)+1 or (p-1)/2 = q | 66 | * p=(2*q)+1 or (p-1)/2 = q |
@@ -100,26 +86,29 @@ int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *c | |||
100 | * It's just as OK (and in some sense better) to use a generator of the | 86 | * It's just as OK (and in some sense better) to use a generator of the |
101 | * order-q subgroup. | 87 | * order-q subgroup. |
102 | */ | 88 | */ |
103 | static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb) | 89 | |
90 | #ifndef OPENSSL_FIPS | ||
91 | |||
92 | DH *DH_generate_parameters(int prime_len, int generator, | ||
93 | void (*callback)(int,int,void *), void *cb_arg) | ||
104 | { | 94 | { |
105 | BIGNUM *t1,*t2; | 95 | BIGNUM *p=NULL,*t1,*t2; |
96 | DH *ret=NULL; | ||
106 | int g,ok= -1; | 97 | int g,ok= -1; |
107 | BN_CTX *ctx=NULL; | 98 | BN_CTX *ctx=NULL; |
108 | 99 | ||
100 | ret=DH_new(); | ||
101 | if (ret == NULL) goto err; | ||
109 | ctx=BN_CTX_new(); | 102 | ctx=BN_CTX_new(); |
110 | if (ctx == NULL) goto err; | 103 | if (ctx == NULL) goto err; |
111 | BN_CTX_start(ctx); | 104 | BN_CTX_start(ctx); |
112 | t1 = BN_CTX_get(ctx); | 105 | t1 = BN_CTX_get(ctx); |
113 | t2 = BN_CTX_get(ctx); | 106 | t2 = BN_CTX_get(ctx); |
114 | if (t1 == NULL || t2 == NULL) goto err; | 107 | if (t1 == NULL || t2 == NULL) goto err; |
115 | |||
116 | /* Make sure 'ret' has the necessary elements */ | ||
117 | if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err; | ||
118 | if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err; | ||
119 | 108 | ||
120 | if (generator <= 1) | 109 | if (generator <= 1) |
121 | { | 110 | { |
122 | DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR); | 111 | DHerr(DH_F_DH_GENERATE_PARAMETERS, DH_R_BAD_GENERATOR); |
123 | goto err; | 112 | goto err; |
124 | } | 113 | } |
125 | if (generator == DH_GENERATOR_2) | 114 | if (generator == DH_GENERATOR_2) |
@@ -155,14 +144,18 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB | |||
155 | g=generator; | 144 | g=generator; |
156 | } | 145 | } |
157 | 146 | ||
158 | if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err; | 147 | p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg); |
159 | if(!BN_GENCB_call(cb, 3, 0)) goto err; | 148 | if (p == NULL) goto err; |
149 | if (callback != NULL) callback(3,0,cb_arg); | ||
150 | ret->p=p; | ||
151 | ret->g=BN_new(); | ||
152 | if (ret->g == NULL) goto err; | ||
160 | if (!BN_set_word(ret->g,g)) goto err; | 153 | if (!BN_set_word(ret->g,g)) goto err; |
161 | ok=1; | 154 | ok=1; |
162 | err: | 155 | err: |
163 | if (ok == -1) | 156 | if (ok == -1) |
164 | { | 157 | { |
165 | DHerr(DH_F_DH_BUILTIN_GENPARAMS,ERR_R_BN_LIB); | 158 | DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB); |
166 | ok=0; | 159 | ok=0; |
167 | } | 160 | } |
168 | 161 | ||
@@ -171,5 +164,12 @@ err: | |||
171 | BN_CTX_end(ctx); | 164 | BN_CTX_end(ctx); |
172 | BN_CTX_free(ctx); | 165 | BN_CTX_free(ctx); |
173 | } | 166 | } |
174 | return ok; | 167 | if (!ok && (ret != NULL)) |
168 | { | ||
169 | DH_free(ret); | ||
170 | ret=NULL; | ||
171 | } | ||
172 | return(ret); | ||
175 | } | 173 | } |
174 | |||
175 | #endif | ||