Skip to content

Commit b0dc773

Browse files
committed
Add AEAD cipher support (GCM)
Add Authenticated Encryption with Additional Data (AEAD) support for ciphers, which obviates 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. Signed-off-by: Steffan Karger <steffan@karger.me>
1 parent 03c325b commit b0dc773

File tree

11 files changed

+810
-102
lines changed

11 files changed

+810
-102
lines changed

configure.ac

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ AC_ARG_ENABLE(
9292
[enable_crypto_ofb_cfb="yes"]
9393
)
9494

95+
AC_ARG_ENABLE(
96+
[aead-modes],
97+
[AS_HELP_STRING([--disable-aead-modes], [disable AEAD crypto modes @<:@default=yes@:>@])],
98+
,
99+
[enable_aead_modes="yes"]
100+
)
101+
95102
AC_ARG_ENABLE(
96103
[x509-alt-username],
97104
[AS_HELP_STRING([--enable-x509-alt-username], [enable the --x509-username-field feature @<:@default=no@:>@])],
@@ -828,6 +835,13 @@ if test "${have_openssl_crypto}" = "yes"; then
828835
[have_openssl_engine="no"; break]
829836
)
830837

838+
have_crypto_aead_modes="yes"
839+
AC_CHECK_FUNCS(
840+
[EVP_aes_256_gcm],
841+
,
842+
[have_crypto_aead_modes="no"; break]
843+
)
844+
831845
CFLAGS="${saved_CFLAGS}"
832846
LIBS="${saved_LIBS}"
833847
fi
@@ -857,8 +871,10 @@ fi
857871

858872
if test "${with_crypto_library}" = "polarssl" ; then
859873
AC_MSG_CHECKING([polarssl version])
860-
old_CFLAGS="${CFLAGS}"
861-
CFLAGS="${POLARSSL_CFLAGS} ${CFLAGS}"
874+
saved_CFLAGS="${CFLAGS}"
875+
saved_LIBS="${LIBS}"
876+
CFLAGS="${POLARSSL_CFLAGS} ${PKCS11_HELPER_CFLAGS} ${CFLAGS}"
877+
LIBS="${POLARSSL_LIBS} ${PKCS11_HELPER_LIBS} ${LIBS}"
862878
AC_COMPILE_IFELSE(
863879
[AC_LANG_PROGRAM(
864880
[[
@@ -887,7 +903,6 @@ if test "${with_crypto_library}" = "polarssl" ; then
887903
]]
888904
)],
889905
polarssl_with_pkcs11="yes")
890-
CFLAGS="${old_CFLAGS}"
891906

892907
AC_MSG_CHECKING([polarssl pkcs11 support])
893908
if test "${enable_pkcs11}" = "yes"; then
@@ -904,6 +919,17 @@ if test "${with_crypto_library}" = "polarssl" ; then
904919
fi
905920
fi
906921

922+
have_crypto_aead_modes="yes"
923+
AC_CHECK_FUNCS(
924+
[ \
925+
cipher_write_tag \
926+
cipher_check_tag \
927+
],
928+
,
929+
[have_crypto_aead_modes="no"; break]
930+
)
931+
CFLAGS="${saved_CFLAGS}"
932+
LIBS="${saved_LIBS}"
907933
fi
908934

909935
AC_ARG_VAR([LZO_CFLAGS], [C compiler flags for lzo])
@@ -1072,6 +1098,10 @@ esac
10721098
if test "${enable_crypto}" = "yes"; then
10731099
test "${have_crypto_crypto}" != "yes" && AC_MSG_ERROR([${with_crypto_library} crypto is required but missing])
10741100
test "${enable_crypto_ofb_cfb}" = "yes" && AC_DEFINE([ENABLE_OFB_CFB_MODE], [1], [Enable OFB and CFB cipher modes])
1101+
if test "${enable_aead_modes}" = "yes"; then
1102+
test "${have_crypto_aead_modes}" = "yes" && AC_DEFINE([HAVE_AEAD_CIPHER_MODES], [1], [Use crypto library])
1103+
test "${have_crypto_aead_modes}" != "yes" && AC_MSG_ERROR([AEAD modes required but missing])
1104+
fi
10751105
OPTIONAL_CRYPTO_CFLAGS="${OPTIONAL_CRYPTO_CFLAGS} ${CRYPTO_CRYPTO_CFLAGS} ${CRYPTO_SSL_CFLAGS}"
10761106
OPTIONAL_CRYPTO_LIBS="${OPTIONAL_CRYPTO_LIBS} ${CRYPTO_SSL_LIBS} ${CRYPTO_CRYPTO_LIBS}"
10771107
AC_DEFINE([ENABLE_CRYPTO], [1], [Enable crypto library])

0 commit comments

Comments
 (0)