diff options
| author | tb <> | 2021-11-29 18:48:22 +0000 |
|---|---|---|
| committer | tb <> | 2021-11-29 18:48:22 +0000 |
| commit | 4512e3f52290dfeeecdd3d26cee6f9bf2223839e (patch) | |
| tree | 60e486cea0b09aba540041c1b807486240644883 /src | |
| parent | cd48de90fe30c83a4498a8023d52f5f0b9d62d5c (diff) | |
| download | openbsd-4512e3f52290dfeeecdd3d26cee6f9bf2223839e.tar.gz openbsd-4512e3f52290dfeeecdd3d26cee6f9bf2223839e.tar.bz2 openbsd-4512e3f52290dfeeecdd3d26cee6f9bf2223839e.zip | |
First pass of converting ssl_kex.c to opaque DH.
Assign the result of BN_dup() and BN_bn2bin() to local BIGNUMs, then
set the factors and pubkey on the dh using DH_set0_{pqg,key}().
A second pass will be done during the upcoming bump.
ok jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/ssl_kex.c | 88 |
1 files changed, 58 insertions, 30 deletions
diff --git a/src/lib/libssl/ssl_kex.c b/src/lib/libssl/ssl_kex.c index 26f991f190..61767c4006 100644 --- a/src/lib/libssl/ssl_kex.c +++ b/src/lib/libssl/ssl_kex.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ssl_kex.c,v 1.3 2021/11/29 16:00:32 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_kex.c,v 1.4 2021/11/29 18:48:22 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -28,20 +28,30 @@ | |||
| 28 | int | 28 | int |
| 29 | ssl_kex_generate_dhe(DH *dh, DH *dh_params) | 29 | ssl_kex_generate_dhe(DH *dh, DH *dh_params) |
| 30 | { | 30 | { |
| 31 | BN_free(dh->p); | 31 | BIGNUM *p = NULL, *g = NULL; |
| 32 | BN_free(dh->g); | 32 | int ret = 0; |
| 33 | dh->p = NULL; | ||
| 34 | dh->g = NULL; | ||
| 35 | 33 | ||
| 36 | if ((dh->p = BN_dup(dh_params->p)) == NULL) | 34 | if ((p = BN_dup(dh_params->p)) == NULL) |
| 37 | return 0; | 35 | goto err; |
| 38 | if ((dh->g = BN_dup(dh_params->g)) == NULL) | 36 | if ((g = BN_dup(dh_params->g)) == NULL) |
| 39 | return 0; | 37 | goto err; |
| 38 | |||
| 39 | if (!DH_set0_pqg(dh, p, NULL, g)) | ||
| 40 | goto err; | ||
| 41 | |||
| 42 | p = NULL; | ||
| 43 | g = NULL; | ||
| 40 | 44 | ||
| 41 | if (!DH_generate_key(dh)) | 45 | if (!DH_generate_key(dh)) |
| 42 | return 0; | 46 | goto err; |
| 43 | 47 | ||
| 44 | return 1; | 48 | ret = 1; |
| 49 | |||
| 50 | err: | ||
| 51 | BN_free(p); | ||
| 52 | BN_free(g); | ||
| 53 | |||
| 54 | return ret; | ||
| 45 | } | 55 | } |
| 46 | 56 | ||
| 47 | int | 57 | int |
| @@ -103,40 +113,58 @@ int | |||
| 103 | ssl_kex_peer_params_dhe(DH *dh, CBS *cbs) | 113 | ssl_kex_peer_params_dhe(DH *dh, CBS *cbs) |
| 104 | { | 114 | { |
| 105 | CBS dh_p, dh_g; | 115 | CBS dh_p, dh_g; |
| 106 | 116 | BIGNUM *p = NULL, *g = NULL; | |
| 107 | BN_free(dh->p); | 117 | int ret = 0; |
| 108 | BN_free(dh->g); | ||
| 109 | dh->p = NULL; | ||
| 110 | dh->g = NULL; | ||
| 111 | 118 | ||
| 112 | if (!CBS_get_u16_length_prefixed(cbs, &dh_p)) | 119 | if (!CBS_get_u16_length_prefixed(cbs, &dh_p)) |
| 113 | return 0; | 120 | goto err; |
| 114 | if (!CBS_get_u16_length_prefixed(cbs, &dh_g)) | 121 | if (!CBS_get_u16_length_prefixed(cbs, &dh_g)) |
| 115 | return 0; | 122 | goto err; |
| 116 | 123 | ||
| 117 | if ((dh->p = BN_bin2bn(CBS_data(&dh_p), CBS_len(&dh_p), NULL)) == NULL) | 124 | if ((p = BN_bin2bn(CBS_data(&dh_p), CBS_len(&dh_p), NULL)) == NULL) |
| 118 | return 0; | 125 | goto err; |
| 119 | if ((dh->g = BN_bin2bn(CBS_data(&dh_g), CBS_len(&dh_g), NULL)) == NULL) | 126 | if ((g = BN_bin2bn(CBS_data(&dh_g), CBS_len(&dh_g), NULL)) == NULL) |
| 120 | return 0; | 127 | goto err; |
| 121 | 128 | ||
| 122 | return 1; | 129 | if (!DH_set0_pqg(dh, p, NULL, g)) |
| 130 | goto err; | ||
| 131 | |||
| 132 | p = NULL; | ||
| 133 | g = NULL; | ||
| 134 | |||
| 135 | ret = 1; | ||
| 136 | |||
| 137 | err: | ||
| 138 | BN_free(p); | ||
| 139 | BN_free(g); | ||
| 140 | |||
| 141 | return ret; | ||
| 123 | } | 142 | } |
| 124 | 143 | ||
| 125 | int | 144 | int |
| 126 | ssl_kex_peer_public_dhe(DH *dh, CBS *cbs) | 145 | ssl_kex_peer_public_dhe(DH *dh, CBS *cbs) |
| 127 | { | 146 | { |
| 128 | CBS dh_y; | 147 | CBS dh_y; |
| 129 | 148 | BIGNUM *pub_key = NULL; | |
| 130 | BN_free(dh->pub_key); | 149 | int ret = 0; |
| 131 | dh->pub_key = NULL; | ||
| 132 | 150 | ||
| 133 | if (!CBS_get_u16_length_prefixed(cbs, &dh_y)) | 151 | if (!CBS_get_u16_length_prefixed(cbs, &dh_y)) |
| 134 | return 0; | 152 | goto err; |
| 135 | if ((dh->pub_key = BN_bin2bn(CBS_data(&dh_y), CBS_len(&dh_y), | 153 | if ((pub_key = BN_bin2bn(CBS_data(&dh_y), CBS_len(&dh_y), |
| 136 | NULL)) == NULL) | 154 | NULL)) == NULL) |
| 137 | return 0; | 155 | goto err; |
| 138 | 156 | ||
| 139 | return 1; | 157 | if (!DH_set0_key(dh, pub_key, NULL)) |
| 158 | goto err; | ||
| 159 | |||
| 160 | pub_key = NULL; | ||
| 161 | |||
| 162 | ret = 1; | ||
| 163 | |||
| 164 | err: | ||
| 165 | BN_free(pub_key); | ||
| 166 | |||
| 167 | return ret; | ||
| 140 | } | 168 | } |
| 141 | 169 | ||
| 142 | int | 170 | int |
