Skip to content

Commit

Permalink
Add AEAD cipher support (GCM)
Browse files Browse the repository at this point in the history
Add Authenticated Encryption with Additional Data (AEAD) support for
ciphers, which removes the need for a separate HMAC step.  The MAC is
integrated into the cipher and the MAC tag is prepended to the payload.

This patch is inspired by the patch originally submitted by Kenny Root
on the openvpn-devel mailinglist, but does a number things differently:
 * Don't support XTS (makes no sense for VPN)
 * Don't support CCM (needs extra code to make it actually work)
 * Don't force the user to specify "auth none" (that would break
   tls-auth)
 * Add support for PolarSSL (and change internal API for this)
 * Update openvpn frame size ('link mtu') calculation for AEAD modes
 * Use the HMAC key as an implicit part of the IV to save 8 bytes per
   data channel network packet.
 * Also authenticate the opcode/peer-id as AD in P_DATA_V2 packets.

By using the negotiated HMAC key as an implicit part of the IV for
AEAD-mode ciphers in TLS mode, we can save (at least) 8 bytes on each
packet sent.  This is particularly interesting for connections which
transfer many small packets, such as remote desktop or voip connections.

The current AEAD-mode ciphers (for now GCM) are based on CTR-mode cipher
operation, which requires the IV to be unique (but does not require
unpredictability).

IV uniqueness is guaranteed by using a combination of at least 64-bits
of the HMAC key (unique per TLS session), and a 32-bit packet counter.
The last 32-bit word of the 128-bit cipher block is not part of the IV,
but is used as a block counter.

AEAD cipher mode is not available for static key mode, since IV
uniqueness is harder the guarantee over sessions, and I believe
supporting AEAD in static key mode too is not worth the extra
complexity.  Modern setups should simply use TLS mode.

OpenSSL 1.0.1-1.0.1c will not work with AEAD mode, because those
versions have an unnecessary check that fails to update the cipher if
the tag was not already set.  1.0.1d, which fixes that, was released in
February 2013.  People should have updated, and distros should have
backported the fix by now.

Changes in v2:
 * Remove extra code that was just for making OpenSSL 1.0.1-1.0.1c work
   in AEAD mode.
 * Do not make AEAD support configurable in ./configure.
 * Get rid of '12' magic constant in openvpn_encrypt_aead().
 * Update manpage to explain that --auth is ignored for the data channel
   when using an AEAD cipher.
 * Move setting the IV in AEAD cipher modes to the IV generation code.
   This is a more natural place and now we can pull iv[] into the IV
   generation scope.
 * Read packet ID directly from packet buffer instead of from iv buffer,
   to remove the need for an extra buffer.

Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <CAA1AbxL_S4umZr5Nd0VTvUvXEHjoWmji18GqM6FgmWqntOKqaA@mail.gmail.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11162
Signed-off-by: Gert Doering <gert@greenie.muc.de>
  • Loading branch information
syzzer authored and cron2 committed Feb 15, 2016
1 parent 5f5229e commit 66407e1
Show file tree
Hide file tree
Showing 13 changed files with 789 additions and 103 deletions.
7 changes: 7 additions & 0 deletions Changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Windows version
Windows version is detected, logged and possibly signalled to server
(IV_PLAT_VER=<nn> if --push-peer-info is set on client)

AEAD (GCM) data channel cipher support
The data channel now supports AEAD ciphers (currently only GCM). The AEAD
packet format has a smaller overhead than the CBC packet format, (e.g. 20
bytes per packet for AES-128-GCM instead of 36 bytes per packet for
AES-128-CBC + HMAC-SHA1).


User-visible Changes
--------------------
- For certificate DNs with duplicate fields, e.g. "OU=one,OU=two", both fields
Expand Down
20 changes: 19 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,13 @@ if test "${with_crypto_library}" = "openssl"; then
AC_DEFINE([HAVE_OPENSSL_ENGINE], [1], [OpenSSL engine support available])
fi

have_crypto_aead_modes="yes"
AC_CHECK_FUNCS(
[EVP_aes_256_gcm],
,
[have_crypto_aead_modes="no"; break]
)

CFLAGS="${saved_CFLAGS}"
LIBS="${saved_LIBS}"

Expand Down Expand Up @@ -897,9 +904,19 @@ elif test "${with_crypto_library}" = "polarssl"; then
AC_MSG_ERROR([PolarSSL compiled with PKCS11, while OpenVPN is not])
fi
fi

have_crypto_aead_modes="yes"
AC_CHECK_FUNCS(
[ \
cipher_write_tag \
cipher_check_tag \
],
,
[have_crypto_aead_modes="no"; break]
)

CFLAGS="${saved_CFLAGS}"
LIBS="${saved_LIBS}"

have_crypto="yes"
AC_DEFINE([ENABLE_CRYPTO_POLARSSL], [1], [Use PolarSSL library])
CRYPTO_CFLAGS="${POLARSSL_CFLAGS}"
Expand Down Expand Up @@ -1054,6 +1071,7 @@ test "${enable_strict_options}" = "yes" && AC_DEFINE([ENABLE_STRICT_OPTIONS_CHEC
if test "${enable_crypto}" = "yes"; then
test "${have_crypto}" != "yes" && AC_MSG_ERROR([${with_crypto_library} crypto is required but missing])
test "${enable_crypto_ofb_cfb}" = "yes" && AC_DEFINE([ENABLE_OFB_CFB_MODE], [1], [Enable OFB and CFB cipher modes])
test "${have_crypto_aead_modes}" = "yes" && AC_DEFINE([HAVE_AEAD_CIPHER_MODES], [1], [Use crypto library])
OPTIONAL_CRYPTO_CFLAGS="${OPTIONAL_CRYPTO_CFLAGS} ${CRYPTO_CFLAGS}"
OPTIONAL_CRYPTO_LIBS="${OPTIONAL_CRYPTO_LIBS} ${CRYPTO_LIBS}"
AC_DEFINE([ENABLE_CRYPTO], [1], [Enable crypto library])
Expand Down
17 changes: 14 additions & 3 deletions doc/openvpn.8
Original file line number Diff line number Diff line change
Expand Up @@ -3979,8 +3979,9 @@ options. Useful when using inline files (See section on inline files).
.\"*********************************************************
.TP
.B \-\-auth alg
Authenticate packets with HMAC using message
digest algorithm
Authenticate data channel packets and (if enabled)
.B tls-auth
control channel packets with HMAC using message digest algorithm
.B alg.
(The default is
.B SHA1
Expand All @@ -3989,7 +3990,17 @@ HMAC is a commonly used message authentication algorithm (MAC) that uses
a data string, a secure hash algorithm, and a key, to produce
a digital signature.

OpenVPN's usage of HMAC is to first encrypt a packet, then HMAC the resulting ciphertext.
The OpenVPN data channel protocol uses encrypt-then-mac (i.e. first encrypt a
packet, then HMAC the resulting ciphertext), which prevents padding oracle
attacks.

If an AEAD cipher mode (e.g. GCM) is chosen, the specified
.B \-\-auth
algorithm is ignored for the data channel, and the authentication method of the
AEAD cipher is used instead. Note that
.B alg
still specifies the digest used for
.B tls-auth\fR.

In static-key encryption mode, the HMAC key
is included in the key file generated by
Expand Down
Loading

0 comments on commit 66407e1

Please sign in to comment.