summaryrefslogtreecommitdiff
path: root/lib/libssl/s3_srvr.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2016-11-17 15:22:42 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2016-11-17 15:22:42 +0000
commit1f1bdf20243270a0519192c8c457c1051bb6b6c5 (patch)
tree8f7d0de7850969a0bae4d88d8086bb32ec709c53 /lib/libssl/s3_srvr.c
parent00fe6fb48dacef684b1ffdd8eebc55eca419add5 (diff)
Convert ssl3_get_client_kex_dhe() to CBS and perform some general code
cleanup, including the removal of a dead code path. ok beck@
Diffstat (limited to 'lib/libssl/s3_srvr.c')
-rw-r--r--lib/libssl/s3_srvr.c67
1 files changed, 29 insertions, 38 deletions
diff --git a/lib/libssl/s3_srvr.c b/lib/libssl/s3_srvr.c
index 65625cef26b..e0d16e5cf2f 100644
--- a/lib/libssl/s3_srvr.c
+++ b/lib/libssl/s3_srvr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: s3_srvr.c,v 1.132 2016/11/06 15:06:52 jsing Exp $ */
+/* $OpenBSD: s3_srvr.c,v 1.133 2016/11/17 15:22:41 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -1742,62 +1742,53 @@ err:
static int
ssl3_get_client_kex_dhe(SSL *s, unsigned char *p, long n)
{
- BIGNUM *pub = NULL;
- DH *dh_srvr;
- int i, al;
+ BIGNUM *bn = NULL;
+ int key_size, al;
+ CBS cbs, dh_Yc;
+ DH *dh;
- if (2 > n)
- goto truncated;
- n2s(p, i);
- if (n != i + 2) {
- SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
- SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
+ if (n < 0)
goto err;
- }
- if (n == 0L) {
- /* the parameters are in the cert */
+ CBS_init(&cbs, p, n);
+
+ if (!CBS_get_u16_length_prefixed(&cbs, &dh_Yc))
+ goto truncated;
+
+ if (CBS_len(&cbs) != 0)
+ goto truncated;
+
+ if (s->s3->tmp.dh == NULL) {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
- SSL_R_UNABLE_TO_DECODE_DH_CERTS);
+ SSL_R_MISSING_TMP_DH_KEY);
goto f_err;
- } else {
- if (s->s3->tmp.dh == NULL) {
- al = SSL_AD_HANDSHAKE_FAILURE;
- SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
- SSL_R_MISSING_TMP_DH_KEY);
- goto f_err;
- } else
- dh_srvr = s->s3->tmp.dh;
}
+ dh = s->s3->tmp.dh;
- pub = BN_bin2bn(p, i, NULL);
- if (pub == NULL) {
+ if ((bn = BN_bin2bn(CBS_data(&dh_Yc), CBS_len(&dh_Yc), NULL)) == NULL) {
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_BN_LIB);
goto err;
}
- i = DH_compute_key(p, pub, dh_srvr);
-
- if (i <= 0) {
- SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
- ERR_R_DH_LIB);
- BN_clear_free(pub);
+ key_size = DH_compute_key(p, bn, dh);
+ if (key_size <= 0) {
+ SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, ERR_R_DH_LIB);
+ BN_clear_free(bn);
goto err;
}
- DH_free(s->s3->tmp.dh);
- s->s3->tmp.dh = NULL;
-
- BN_clear_free(pub);
- pub = NULL;
-
s->session->master_key_length =
s->method->ssl3_enc->generate_master_secret(
- s, s->session->master_key, p, i);
+ s, s->session->master_key, p, key_size);
- explicit_bzero(p, i);
+ explicit_bzero(p, key_size);
+
+ DH_free(s->s3->tmp.dh);
+ s->s3->tmp.dh = NULL;
+
+ BN_clear_free(bn);
return (1);