From patchwork Sun Oct 7 11:30:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 504 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id mItfIl2JulsmaAAAIUCqbw for ; Sun, 07 Oct 2018 18:31:57 -0400 Received: from proxy3.mail.ord1d.rsapps.net ([172.30.191.6]) by director7.mail.ord1d.rsapps.net with LMTP id ONMsIl2JulscOAAAovjBpQ ; Sun, 07 Oct 2018 18:31:57 -0400 Received: from smtp4.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy3.mail.ord1d.rsapps.net with LMTP id 4EIBIl2JulsySAAA7WKfLA ; Sun, 07 Oct 2018 18:31:57 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp4.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Suspicious-Flag: YES X-Classification-ID: cc649446-ca80-11e8-8d91-525400760ffc-1-1 Received: from [216.105.38.7] ([216.105.38.7:59914] helo=lists.sourceforge.net) by smtp4.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 5B/C0-13544-D598ABB5; Sun, 07 Oct 2018 18:31:57 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1g9HZd-0003ia-S0; Sun, 07 Oct 2018 22:30:53 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1g9HZc-0003iO-CE for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 22:30:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JsI4+uSbqf6uoKVT4jl3ayDJo7zDCssRsAOYAECaDT0=; b=RDWwaonRO233VzPdsSBjKBmu6+ lc6LDZlX4mgCLyfrNYeAaGBdp56/IsQ4xMIaX4Wi3ZbS1VSzJI7UVaZF+V7+MEYxFmxDkC2VFTM4p FehRaolIpJLl+PdxdkbO/awgEmZvoVrQOIPOLVonxIvywNldmk8kT2koIFaYQbN9/s1I=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=JsI4+uSbqf6uoKVT4jl3ayDJo7zDCssRsAOYAECaDT0=; b=kZg37+qJ4fZwXdoFZpAJOAVbo8 v7hqNbkocT5wOFrqJMAwetp1aAiNvljsh9eS3XlWbQ6bW6wJON5uiKx1AwKse10epCeBrDiFicYen jy3x93hcc3EuKFl8jVFajc+pBeVkZWsOwiBxDBWkD1cqBzYlByia6FWtaw/W9juKhlqQ=; Received: from mail-ed1-f67.google.com ([209.85.208.67]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1g9HZY-00E58Y-JK for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 22:30:51 +0000 Received: by mail-ed1-f67.google.com with SMTP id w19-v6so797477eds.1 for ; Sun, 07 Oct 2018 15:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JsI4+uSbqf6uoKVT4jl3ayDJo7zDCssRsAOYAECaDT0=; b=ypFzcJN3ihS7LZZLSVNLE0KE28mb9eot1ywGnk07+q+t33fptlonKD3eBEbKLopYwh idg7qluPv/KT0NvU49c/NynWUm4BUykBHZzWcOj5fYr8uQabBPdM56R9bpmmzwgNY/7L pm6mjwmibG8vNF1riEK5p/8nboU0zYhRz2B/0j4uv+H2eILpaRSKH6cKzLBulXs8AhmN aTpEenCQ2ksFBgFpAYkpnMyZkJ3Oe5wJqsoF7Y10LxqbLwiCzGqX8tBrO9BdTtJ6p/fI GRuSn79rDsLEl5vDTZBRpfRlezcwO849EpWV65frp+FbS4w1ER8y2Z6Y3TiaILWqPKDN o+lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JsI4+uSbqf6uoKVT4jl3ayDJo7zDCssRsAOYAECaDT0=; b=tVGxdv8MHAgVzgY7k7pIqPu/iJAmU53g0wNx5+qfnZ58WGdP2otmL94eA/XkRDHyjC n05kwoDR+NsI+NT+52a7sLZHzqyvPrKezA2jxJYyx66YwBOodzGsncXhX0DSNWx6YCG3 1Up2mbZns5rF1/+RGqcvnnnrz3nIaQjD/qCoWjFHtrM03VDSifWDTHekp5rrdvhaEesE 4R0r1ebrMSfhiIv9fykkFQVoodiLNFka6PG1aF2vqpiZWXYE+/OlFQImDAAnDYbGGRHu rcqEIHjgeOyehNIleZYq4YzXGpHYIYhmJ5mL4nbplJklhnuwHDDOq2bDnrORD5mSYF6s cHZQ== X-Gm-Message-State: ABuFfohkHvDgyajpZR804ulh4LZHxUCkQq06YaPH3J7AlOL/RGcF35NW CSFmWjHaMPM3m6nk7x1dGBlwLI4QO+zroA== X-Google-Smtp-Source: ACcGV63KyEZM58qOoipEBKJd+kmFLytiyFp8UH6lk7ZCkUnJUPIiRpXw7OcA+rG/2NPgpAA+78QEJA== X-Received: by 2002:a17:906:5114:: with SMTP id w20-v6mr20777004ejk.46.1538951441553; Sun, 07 Oct 2018 15:30:41 -0700 (PDT) Received: from vesta.fritz.box ([2001:985:e54:1:f574:9f7d:c43:8bcf]) by smtp.gmail.com with ESMTPSA id p3-v6sm3716410eda.88.2018.10.07.15.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 15:30:40 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Mon, 8 Oct 2018 00:30:34 +0200 Message-Id: <20181007223035.21179-1-steffan@karger.me> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.67 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.67 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Whitelisted Medium sender -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1g9HZY-00E58Y-JK Subject: [Openvpn-devel] [PATCH v2 1/2] Add support for CHACHA20-POLY1305 in the data channel X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox We explicitly only supported GCM as a valid AEAD mode, change that to also allow ChaCha20-Poly1305 as an AEAD cipher. That works nicely with our new (GCM) data channel format, because is has the same 96-bit IV. Note that we need some tricks to not treat the cipher as insecure, because we used to only look at the block size of a cipher to determine if find a cipher insecure. But ChaCha20-Poly1305 is a stream cipher, which essentially has a 'block size' of 1 byte and is reported as such. So, special-case this cipher to be in the list of secure ciphers. Signed-off-by: Steffan Karger Acked-by: Antonio Quartulli --- v2: code style fixes, remove unneeded version check Changes.rst | 10 ++++++++++ src/openvpn/crypto.c | 2 +- src/openvpn/crypto_backend.h | 5 +++++ src/openvpn/crypto_mbedtls.c | 20 +++++++++++++++++--- src/openvpn/crypto_openssl.c | 33 ++++++++++++++++++++++++++++----- src/openvpn/ssl.c | 2 +- 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Changes.rst b/Changes.rst index a6090cf5..70ce2e10 100644 --- a/Changes.rst +++ b/Changes.rst @@ -1,3 +1,13 @@ +Overview of changes in 2.5 +========================== + +New features +------------ +ChaCha20-Poly1305 cipher support + Added support for using the ChaCha20-Poly1305 cipher in the OpenVPN data + channel. + + Overview of changes in 2.4 ========================== diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index c8d95f3b..6d34acd7 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -841,7 +841,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, dmsg(D_CRYPTO_DEBUG, "%s: CIPHER block_size=%d iv_size=%d", prefix, cipher_kt_block_size(kt->cipher), cipher_kt_iv_size(kt->cipher)); - if (cipher_kt_block_size(kt->cipher) < 128/8) + if (cipher_kt_insecure(kt->cipher)) { msg(M_WARN, "WARNING: INSECURE cipher with block size less than 128" " bit (%d bit). This allows attacks like SWEET32. Mitigate by " diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index f917c8d7..38b2c175 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -284,6 +284,11 @@ int cipher_kt_block_size(const cipher_kt_t *cipher_kt); */ int cipher_kt_tag_size(const cipher_kt_t *cipher_kt); +/** + * Returns true if we consider this cipher to be insecure. + */ +bool cipher_kt_insecure(const cipher_kt_t *cipher); + /** * Returns the mode that the cipher runs in. * diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 82f4e574..0c39eccc 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -175,7 +175,7 @@ show_available_ciphers(void) while (*ciphers != 0) { const cipher_kt_t *info = mbedtls_cipher_info_from_type(*ciphers); - if (info && cipher_kt_block_size(info) >= 128/8) + if (info && !cipher_kt_insecure(info)) { print_cipher(info); } @@ -188,7 +188,7 @@ show_available_ciphers(void) while (*ciphers != 0) { const cipher_kt_t *info = mbedtls_cipher_info_from_type(*ciphers); - if (info && cipher_kt_block_size(info) < 128/8) + if (info && cipher_kt_insecure(info)) { print_cipher(info); } @@ -550,6 +550,16 @@ cipher_kt_tag_size(const mbedtls_cipher_info_t *cipher_kt) return 0; } +bool +cipher_kt_insecure(const mbedtls_cipher_info_t *cipher_kt) +{ + return !(cipher_kt_block_size(cipher_kt) >= 128 / 8 +#ifdef MBEDTLS_CHACHAPOLY_C + || cipher_kt->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 +#endif + ); +} + int cipher_kt_mode(const mbedtls_cipher_info_t *cipher_kt) { @@ -573,7 +583,11 @@ cipher_kt_mode_ofb_cfb(const cipher_kt_t *cipher) bool cipher_kt_mode_aead(const cipher_kt_t *cipher) { - return cipher && cipher_kt_mode(cipher) == OPENVPN_MODE_GCM; + return cipher && (cipher_kt_mode(cipher) == OPENVPN_MODE_GCM +#ifdef MBEDTLS_CHACHAPOLY_C + || cipher_kt_mode(cipher) == MBEDTLS_MODE_CHACHAPOLY +#endif + ); } diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 9ec2048d..1c0fae86 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -245,6 +245,7 @@ const cipher_name_pair cipher_name_translation_table[] = { { "AES-128-GCM", "id-aes128-GCM" }, { "AES-192-GCM", "id-aes192-GCM" }, { "AES-256-GCM", "id-aes256-GCM" }, + { "CHACHA20-POLY1305", "ChaCha20-Poly1305" }, }; const size_t cipher_name_translation_table_count = sizeof(cipher_name_translation_table) / sizeof(*cipher_name_translation_table); @@ -321,7 +322,7 @@ show_available_ciphers(void) qsort(cipher_list, num_ciphers, sizeof(*cipher_list), cipher_name_cmp); for (i = 0; i < num_ciphers; i++) { - if (cipher_kt_block_size(cipher_list[i]) >= 128/8) + if (!cipher_kt_insecure(cipher_list[i])) { print_cipher(cipher_list[i]); } @@ -330,7 +331,7 @@ show_available_ciphers(void) printf("\nThe following ciphers have a block size of less than 128 bits, \n" "and are therefore deprecated. Do not use unless you have to.\n\n"); for (i = 0; i < num_ciphers; i++) { - if (cipher_kt_block_size(cipher_list[i]) < 128/8) + if (cipher_kt_insecure(cipher_list[i])) { print_cipher(cipher_list[i]); } @@ -686,6 +687,16 @@ cipher_kt_tag_size(const EVP_CIPHER *cipher_kt) } } +bool +cipher_kt_insecure(const EVP_CIPHER *cipher) +{ + return !(cipher_kt_block_size(cipher) >= 128 / 8 +#ifdef NID_chacha20_poly1305 + || EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305 +#endif + ); +} + int cipher_kt_mode(const EVP_CIPHER *cipher_kt) { @@ -720,10 +731,22 @@ bool cipher_kt_mode_aead(const cipher_kt_t *cipher) { #ifdef HAVE_AEAD_CIPHER_MODES - return cipher && (cipher_kt_mode(cipher) == OPENVPN_MODE_GCM); -#else - return false; + if (cipher) + { + switch (EVP_CIPHER_nid(cipher)) + { + case NID_aes_128_gcm: + case NID_aes_192_gcm: + case NID_aes_256_gcm: +#ifdef NID_chacha20_poly1305 + case NID_chacha20_poly1305: #endif + return true; + } + } +#endif + + return false; } /* diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 4257c33d..315303b0 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -294,7 +294,7 @@ tls_get_cipher_name_pair(const char *cipher_name, size_t len) static void tls_limit_reneg_bytes(const cipher_kt_t *cipher, int *reneg_bytes) { - if (cipher && (cipher_kt_block_size(cipher) < 128/8)) + if (cipher && cipher_kt_insecure(cipher)) { if (*reneg_bytes == -1) /* Not user-specified */ { From patchwork Sun Oct 7 11:30:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 503 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id oPBHIlyJuluLGgAAIUCqbw for ; Sun, 07 Oct 2018 18:31:56 -0400 Received: from proxy8.mail.ord1d.rsapps.net ([172.30.191.6]) by director9.mail.ord1d.rsapps.net with LMTP id gBUgIlyJulsdRgAAalYnBA ; Sun, 07 Oct 2018 18:31:56 -0400 Received: from smtp20.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy8.mail.ord1d.rsapps.net with LMTP id eIvVIVyJulsXfwAAGdz6CA ; Sun, 07 Oct 2018 18:31:56 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp20.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Suspicious-Flag: YES X-Classification-ID: cb9206f2-ca80-11e8-966c-525400b8bfda-1-1 Received: from [216.105.38.7] ([216.105.38.7:20189] helo=lists.sourceforge.net) by smtp20.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 69/80-07746-B598ABB5; Sun, 07 Oct 2018 18:31:56 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1g9HZe-0003ir-UE; Sun, 07 Oct 2018 22:30:54 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1g9HZe-0003il-Dt for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 22:30:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WiUfcpeHx8cVY61FfBEAC3tyOIAKsZD+risVgQP8YlY=; b=Zpj6LyJbm1IXMJQNlMNIj7jYRq QIaX0RxldpM7tEoM+MtLicdcfZIp3kHhSuSdj/rjqyZKVLixBqt7suSCKOMV+hAWW2WBcYiqM7aq7 QFOimza0oHrmI0KapXeUpyD26LvG8MqbgJXo2cdUVkBhz6MV9XYRfCFHq9AssYHNHu9U=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WiUfcpeHx8cVY61FfBEAC3tyOIAKsZD+risVgQP8YlY=; b=JyfWAaTUiyOKrgrAfa+H/qldh6 L0Qi9mrHc2mrJd8p1PXQ0N8UCcJ+G+GQIeU7Cy6LfpKszuC+L+2aGApvrqURdgz7OEGnQrTtJsKGk iI/F+MA+pgxY4PJeHLrjs1aiawveSUWMhNVEV6+fYjRQjV5AZwRTaJz6i02s3WDCPNnM=; Received: from mail-ed1-f44.google.com ([209.85.208.44]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1g9HZa-00E58c-LV for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 22:30:54 +0000 Received: by mail-ed1-f44.google.com with SMTP id y19-v6so15991115edd.2 for ; Sun, 07 Oct 2018 15:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WiUfcpeHx8cVY61FfBEAC3tyOIAKsZD+risVgQP8YlY=; b=hEQ9UoG20QRbruxU8jgekvhM+c9XT1Io90nGU8vcpYRsOUCPBoDrPPRzN1SWesMlDf 3j67+//odLy2cUzxl66whtllr7gJHdR2P5GNcDP3wB05EwvUzQwqYPIlFuFIZjhBDyCj iSY1nIao1YofEGqqbWXUK1t1RuMoFCxow4lgwmjrpzus6WpSpESFcJGNR13llFsr9KJb GtkmLRtdbRXy7rJMujyJNqgdvUxcUnRuda1FBH0EU2wv5ukADL5RJ6nYxULzBf9MfnFo A5y2XE03MiTrTgIphEZZcASrvP86SmsHqKOGDoS5xFcjYT8qIJMb44C3Omph41b0g2B3 CFIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WiUfcpeHx8cVY61FfBEAC3tyOIAKsZD+risVgQP8YlY=; b=NUzMXvM33INdRIZBmY59FDj9xW5uAZrVozs6NQ1UPAteRWl9qy52geCb9NpfySj0nH EmNcxTNsL9/WxRmq+cTsPLQOR6b8wKf8uB9bkqe9Xm/1MBBM0HVQCa23km2W97lJAzxR oU34uSoWQjcDlVXQjFK67fuPD9+UzP7ooWHM0mtZaUVqrfHJ/OQ/1Ohs3g7SsZPqJdZs +ZVtHzsZcRb81atJO/dF8tUht6yLBh9/7SOLuzoWbCD6UQJt1ZmSGDbb33FIFY8xmONs uVxzY7n2XFNUegzvlm5kGPyl178CbcUKn6IbC/0e/g5PHO1WEicttcbsFY80O5/bApxB 7k8w== X-Gm-Message-State: ABuFfojCp3hG0VPfYP1e2UdD35pGU3c6JfUmqJj1PaKT+670FZmqV6gV g2T0LDmayzivb4cdDWBiI9MrP7m8WMJpPw== X-Google-Smtp-Source: ACcGV62JP2mv5YXN8VAUis2j50qfkfaeT4d5fHfWQUIHDVWiMS+82w+zlcpe1CFJMROB1mvPAp6gwg== X-Received: by 2002:a05:6402:2c9:: with SMTP id b9mr26518586edx.149.1538951443729; Sun, 07 Oct 2018 15:30:43 -0700 (PDT) Received: from vesta.fritz.box ([2001:985:e54:1:f574:9f7d:c43:8bcf]) by smtp.gmail.com with ESMTPSA id p3-v6sm3716410eda.88.2018.10.07.15.30.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 15:30:43 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Mon, 8 Oct 2018 00:30:35 +0200 Message-Id: <20181007223035.21179-2-steffan@karger.me> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181007223035.21179-1-steffan@karger.me> References: <20181007223035.21179-1-steffan@karger.me> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.44 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.44 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Whitelisted Medium sender -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1g9HZa-00E58c-LV Subject: [Openvpn-devel] [PATCH v2 2/2] List ChaCha20-Poly1305 as stream cipher X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox As Antonio pointed out, "8-bit block cipher" is a bit funny. So teach print_cipher() to print such cipher as "stream cipher". Because I didn't want to write the same code twice, I decided to merge the two print_cipher() implementations into one shared function. That should make it easier to keep both backends consistent. Signed-off-by: Steffan Karger --- v2: introduce this patch src/openvpn/crypto.c | 27 +++++++++++++++++++++++++++ src/openvpn/crypto.h | 3 +++ src/openvpn/crypto_mbedtls.c | 23 ++--------------------- src/openvpn/crypto_mbedtls.h | 4 ++++ src/openvpn/crypto_openssl.c | 15 --------------- src/openvpn/crypto_openssl.h | 4 ++++ 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 6d34acd7..e81399b7 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -1769,6 +1769,33 @@ get_random(void) return l; } +void +print_cipher(const cipher_kt_t *cipher) +{ + const char *var_key_size = cipher_kt_var_key_size(cipher) ? + " by default" : ""; + + printf("%s (%d bit key%s, ", + translate_cipher_name_to_openvpn(cipher_kt_name(cipher)), + cipher_kt_key_size(cipher) * 8, var_key_size); + + if (cipher_kt_block_size(cipher) == 1) + { + printf("stream cipher"); + } + else + { + printf("%d bit block", cipher_kt_block_size(cipher) * 8); + } + + if (!cipher_kt_mode_cbc(cipher)) + { + printf(", TLS client/server mode only"); + } + + printf(")\n"); +} + static const cipher_name_pair * get_cipher_name_pair(const char *cipher_name) { diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index f4b3dca3..cf87cb49 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -465,6 +465,9 @@ void prng_uninit(void); /* an analogue to the random() function, but use prng_bytes */ long int get_random(void); +/** Print a cipher list entry */ +void print_cipher(const cipher_kt_t *cipher); + void test_crypto(struct crypto_options *co, struct frame *f); diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 0c39eccc..54ac1893 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -140,26 +140,6 @@ const cipher_name_pair cipher_name_translation_table[] = { const size_t cipher_name_translation_table_count = sizeof(cipher_name_translation_table) / sizeof(*cipher_name_translation_table); -static void -print_cipher(const cipher_kt_t *info) -{ - if (info && (cipher_kt_mode_cbc(info) -#ifdef HAVE_AEAD_CIPHER_MODES - || cipher_kt_mode_aead(info) -#endif - )) - { - const char *ssl_only = cipher_kt_mode_cbc(info) ? - "" : ", TLS client/server mode only"; - const char *var_key_size = info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ? - " by default" : ""; - - printf("%s (%d bit key%s, %d bit block%s)\n", - cipher_kt_name(info), cipher_kt_key_size(info) * 8, var_key_size, - cipher_kt_block_size(info) * 8, ssl_only); - } -} - void show_available_ciphers(void) { @@ -175,7 +155,8 @@ show_available_ciphers(void) while (*ciphers != 0) { const cipher_kt_t *info = mbedtls_cipher_info_from_type(*ciphers); - if (info && !cipher_kt_insecure(info)) + if (info && !cipher_kt_insecure(info) + && (cipher_kt_mode_aead(info) || cipher_kt_mode_cbc(info))) { print_cipher(info); } diff --git a/src/openvpn/crypto_mbedtls.h b/src/openvpn/crypto_mbedtls.h index 452b06ed..81b542bc 100644 --- a/src/openvpn/crypto_mbedtls.h +++ b/src/openvpn/crypto_mbedtls.h @@ -146,5 +146,9 @@ mbed_log_func_line_lite(unsigned int flags, int errval, #define mbed_ok(errval) \ mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func__, __LINE__) +static inline bool cipher_kt_var_key_size(const cipher_kt_t *cipher) +{ + return cipher->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN; +} #endif /* CRYPTO_MBEDTLS_H_ */ diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 1c0fae86..7989127b 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -265,21 +265,6 @@ cipher_name_cmp(const void *a, const void *b) return strcmp(cipher_name_a, cipher_name_b); } -static void -print_cipher(const EVP_CIPHER *cipher) -{ - const char *var_key_size = - (EVP_CIPHER_flags(cipher) & EVP_CIPH_VARIABLE_LENGTH) ? - " by default" : ""; - const char *ssl_only = cipher_kt_mode_cbc(cipher) ? - "" : ", TLS client/server mode only"; - - printf("%s (%d bit key%s, %d bit block%s)\n", - translate_cipher_name_to_openvpn(EVP_CIPHER_name(cipher)), - EVP_CIPHER_key_length(cipher) * 8, var_key_size, - cipher_kt_block_size(cipher) * 8, ssl_only); -} - void show_available_ciphers(void) { diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h index 0a413705..1ea3e858 100644 --- a/src/openvpn/crypto_openssl.h +++ b/src/openvpn/crypto_openssl.h @@ -101,5 +101,9 @@ void crypto_print_openssl_errors(const unsigned int flags); msg((flags), __VA_ARGS__); \ } while (false) +static inline bool cipher_kt_var_key_size(const cipher_kt_t *cipher) +{ + return EVP_CIPHER_flags(cipher) & EVP_CIPH_VARIABLE_LENGTH; +} #endif /* CRYPTO_OPENSSL_H_ */