Line 0
Link Here
|
|
|
1 |
--- dh.h.orig 2018-10-08 01:20:49 UTC |
2 |
+++ dh.h |
3 |
@@ -250,23 +250,27 @@ DHInit(int nKeyBits) |
4 |
size_t res; |
5 |
MDH *dh = MDH_new(); |
6 |
|
7 |
+ |
8 |
if (!dh) |
9 |
goto failed; |
10 |
|
11 |
- MP_new(dh->g); |
12 |
+ const BIGNUM *p; |
13 |
+ const BIGNUM *g; |
14 |
+ DH_get0_pqg(dh,&p,NULL,&g); |
15 |
+ MP_new(g); |
16 |
|
17 |
- if (!dh->g) |
18 |
+ if (!g) |
19 |
goto failed; |
20 |
|
21 |
- MP_gethex(dh->p, P1024, res); /* prime P1024, see dhgroups.h */ |
22 |
+ MP_gethex(p, P1024, res); /* prime P1024, see dhgroups.h */ |
23 |
if (!res) |
24 |
{ |
25 |
goto failed; |
26 |
} |
27 |
|
28 |
- MP_set_w(dh->g, 2); /* base 2 */ |
29 |
+ MP_set_w(g, 2); /* base 2 */ |
30 |
|
31 |
- dh->length = nKeyBits; |
32 |
+ DH_set_length(dh, nKeyBits); |
33 |
return dh; |
34 |
|
35 |
failed: |
36 |
@@ -293,12 +297,15 @@ DHGenerateKey(MDH *dh) |
37 |
MP_gethex(q1, Q1024, res); |
38 |
assert(res); |
39 |
|
40 |
- res = isValidPublicKey(dh->pub_key, dh->p, q1); |
41 |
+ BIGNUM *pub_key, *priv_key, *p; |
42 |
+ DH_get0_key(dh, &pub_key, &priv_key); |
43 |
+ DH_get0_pqg(dh,&p,NULL,NULL); |
44 |
+ res = isValidPublicKey(pub_key, p, q1); |
45 |
if (!res) |
46 |
{ |
47 |
- MP_free(dh->pub_key); |
48 |
- MP_free(dh->priv_key); |
49 |
- dh->pub_key = dh->priv_key = 0; |
50 |
+ MP_free(pub_key); |
51 |
+ MP_free(priv_key); |
52 |
+ DH_set0_key(dh, 0, 0); |
53 |
} |
54 |
|
55 |
MP_free(q1); |
56 |
@@ -314,15 +321,17 @@ static int |
57 |
DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen) |
58 |
{ |
59 |
int len; |
60 |
- if (!dh || !dh->pub_key) |
61 |
+ BIGNUM *pub_key; |
62 |
+ DH_get0_key(dh, &pub_key, NULL); |
63 |
+ if (!dh || !pub_key) |
64 |
return 0; |
65 |
|
66 |
- len = MP_bytes(dh->pub_key); |
67 |
+ len = MP_bytes(pub_key); |
68 |
if (len <= 0 || len > (int) nPubkeyLen) |
69 |
return 0; |
70 |
|
71 |
memset(pubkey, 0, nPubkeyLen); |
72 |
- MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len); |
73 |
+ MP_setbin(pub_key, pubkey + (nPubkeyLen - len), len); |
74 |
return 1; |
75 |
} |
76 |
|
77 |
@@ -364,7 +373,9 @@ DHComputeSharedSecretKey(MDH *dh, uint8_t *pubkey, siz |
78 |
MP_gethex(q1, Q1024, len); |
79 |
assert(len); |
80 |
|
81 |
- if (isValidPublicKey(pubkeyBn, dh->p, q1)) |
82 |
+ BIGNUM *p; |
83 |
+ DH_get0_pqg(dh,&p,NULL,NULL); |
84 |
+ if (isValidPublicKey(pubkeyBn, p, q1)) |
85 |
res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh); |
86 |
else |
87 |
res = -1; |