Rename and collapse tls12_get_sigandhash_cbb().
authorjsing <jsing@openbsd.org>
Sun, 19 Aug 2018 15:38:03 +0000 (15:38 +0000)
committerjsing <jsing@openbsd.org>
Sun, 19 Aug 2018 15:38:03 +0000 (15:38 +0000)
Now that all callers of tls12_get_sigandhash() have been converted to CBB,
collapse tls12_get_sigandhash() and tls12_get_sigandhash_cbb() into a
single function. Rename it to tls12_gethashandsig() to be representative
of the actual order of the sigalgs parameters, and perform some other
clean up.

ok inoguchi@ tb@

lib/libssl/ssl_clnt.c
lib/libssl/ssl_locl.h
lib/libssl/ssl_srvr.c
lib/libssl/t1_lib.c

index fd78a8e..b026aaa 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_clnt.c,v 1.31 2018/08/17 16:28:21 jsing Exp $ */
+/* $OpenBSD: ssl_clnt.c,v 1.32 2018/08/19 15:38:03 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -2416,7 +2416,7 @@ ssl3_send_client_verify(SSL *s)
                            &hdata);
                        md = s->cert->key->digest;
                        if (hdatalen <= 0 ||
-                           !tls12_get_sigandhash_cbb(&cert_verify, pkey, md)) {
+                           !tls12_get_hashandsig(&cert_verify, pkey, md)) {
                                SSLerror(s, ERR_R_INTERNAL_ERROR);
                                goto err;
                        }
index da4bde0..8e85f10 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_locl.h,v 1.206 2018/08/16 17:49:48 jsing Exp $ */
+/* $OpenBSD: ssl_locl.h,v 1.207 2018/08/19 15:38:03 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -1282,11 +1282,9 @@ int ssl_check_serverhello_tlsext(SSL *s);
 #define tlsext_tick_md EVP_sha256
 int tls1_process_ticket(SSL *s, const unsigned char *session_id, int len,
     const unsigned char *limit, SSL_SESSION **ret);
-int tls12_get_sigandhash_cbb(CBB *cbb, const EVP_PKEY *pk,
-    const EVP_MD *md);
-int tls12_get_sigandhash(unsigned char *p, const EVP_PKEY *pk,
-    const EVP_MD *md);
+int tls12_get_hashid(const EVP_MD *md);
 int tls12_get_sigid(const EVP_PKEY *pk);
+int tls12_get_hashandsig(CBB *cbb, const EVP_PKEY *pk, const EVP_MD *md);
 const EVP_MD *tls12_get_hash(unsigned char hash_alg);
 
 void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
index 80c7208..01fe647 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl_srvr.c,v 1.40 2018/08/19 15:29:26 jsing Exp $ */
+/* $OpenBSD: ssl_srvr.c,v 1.41 2018/08/19 15:38:03 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -1565,8 +1565,7 @@ ssl3_send_server_key_exchange(SSL *s)
 
                        /* Send signature algorithm. */
                        if (SSL_USE_SIGALGS(s)) {
-                               if (!tls12_get_sigandhash_cbb(&server_kex, pkey,
-                                   md)) {
+                               if (!tls12_get_hashandsig(&server_kex, pkey, md)) {
                                        /* Should never happen */
                                        al = SSL_AD_INTERNAL_ERROR;
                                        SSLerror(s, ERR_R_INTERNAL_ERROR);
index 7f16694..1b2e084 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: t1_lib.c,v 1.142 2018/08/16 17:49:48 jsing Exp $ */
+/* $OpenBSD: t1_lib.c,v 1.143 2018/08/19 15:38:03 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -1116,51 +1116,43 @@ tls12_find_id(int nid, tls12_lookup *table, size_t tlen)
 }
 
 int
-tls12_get_sigandhash_cbb(CBB *cbb, const EVP_PKEY *pk, const EVP_MD *md)
+tls12_get_hashid(const EVP_MD *md)
 {
-       unsigned char p[2];
+       if (md == NULL)
+               return -1;
 
-       if (!tls12_get_sigandhash(p, pk, md))
-               return 0;
+       return tls12_find_id(EVP_MD_type(md), tls12_md,
+           sizeof(tls12_md) / sizeof(tls12_lookup));
+}
 
-       if (!CBB_add_u8(cbb, p[0]))
-               return 0;
-       if (!CBB_add_u8(cbb, p[1]))
-               return 0;
+int
+tls12_get_sigid(const EVP_PKEY *pk)
+{
+       if (pk == NULL)
+               return -1;
 
-       return 1;
+       return tls12_find_id(pk->type, tls12_sig,
+           sizeof(tls12_sig) / sizeof(tls12_lookup));
 }
 
 int
-tls12_get_sigandhash(unsigned char *p, const EVP_PKEY *pk, const EVP_MD *md)
+tls12_get_hashandsig(CBB *cbb, const EVP_PKEY *pk, const EVP_MD *md)
 {
-       int sig_id, md_id;
+       int hash_id, sig_id;
 
-       if (md == NULL)
+       if ((hash_id = tls12_get_hashid(md)) == -1)
                return 0;
-
-       md_id = tls12_find_id(EVP_MD_type(md), tls12_md,
-           sizeof(tls12_md) / sizeof(tls12_lookup));
-       if (md_id == -1)
+       if ((sig_id = tls12_get_sigid(pk)) == -1)
                return 0;
 
-       sig_id = tls12_get_sigid(pk);
-       if (sig_id == -1)
+       if (!CBB_add_u8(cbb, hash_id))
+               return 0;
+       if (!CBB_add_u8(cbb, sig_id))
                return 0;
-
-       p[0] = (unsigned char)md_id;
-       p[1] = (unsigned char)sig_id;
 
        return 1;
 }
 
-int
-tls12_get_sigid(const EVP_PKEY *pk)
-{
-       return tls12_find_id(pk->type, tls12_sig,
-           sizeof(tls12_sig) / sizeof(tls12_lookup));
-}
-
 const EVP_MD *
 tls12_get_hash(unsigned char hash_alg)
 {