* [Openvpn-devel] GOST algorithm support for OpenVPN
@ 2012-08-16 8:38 Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC Heiko Hund
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
OpenSSL since version 1.0.0 supports the Russian cryptographic
standard algorithms, commonly called GOST algorithms. Use of GOST in
SSL/TLS is standardized by the IETF, thus openvpn is the VPN software
of choice for Russian users when constrained to use GOST algorithms.
With this patch series, users can choose to use GOST by using the
algorithms in the X.509 PKI and configuring openvpn with, e.g.
--engine gost
--auth gost-mac
--cipher gost89
--tls-cipher GOST2001-GOST89-GOST89
More information about the GOST algorithms can be found in IETF RFCs:
4357 Additional Cryptographic Algorithms for Use with GOST Algorithms
4490 GOST Algorithms with the Cryptographic Message Syntax (CMS)
4491 GOST Algorithms with the Internet X.509 Public Key Infrastructure (PKI)
5830 GOST 28147-89 Block Cipher and MAC Algorithms
5831 GOST R 34.11-94 Hash Function Algorithm
5832 GOST R 34.10-2001 Digital Signature Algorithm
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
2013-02-02 12:28 ` Arne Schwabe
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 2/7] init crypto engine before SSL library Heiko Hund
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
cipher_ctx_final() only returns an outlen in CBC mode. If CFB or OFB
are used the assertion outlen == iv_len is always false.
There's no CBC mode defined for the GOST 28147-89 block cipher. Hence
this patch is needed for it to work. It's needed for other ciphers like
BF-CFB as well, though.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
src/openvpn/crypto.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index ac2eecd..2f67e5e 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -153,7 +153,7 @@ openvpn_encrypt (struct buffer *buf, struct buffer work,
/* Flush the encryption buffer */
ASSERT(cipher_ctx_final(ctx->cipher, BPTR (&work) + outlen, &outlen));
work.len += outlen;
- ASSERT (outlen == iv_size);
+ ASSERT (mode != OPENVPN_MODE_CBC || outlen == iv_size);
/* prepend the IV to the ciphertext */
if (opt->flags & CO_USE_IV)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 2/7] init crypto engine before SSL library
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 3/7] remove API for crypto engine initialization Heiko Hund
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
Since GOST in OpenSSL is implemented in an engine, the engine must
be loaded before the SSL library is initialized for the algorithms
to become available for SSL/TLS.
This delays the initialization of the ssl lib until after the options
are parsed, so a possibly configured engine can be loaded before.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
src/openvpn/init.c | 65 +++++++++++++++++--------------------------------
src/openvpn/init.h | 1 +
src/openvpn/openvpn.c | 22 +++++++++++++++++
3 files changed, 45 insertions(+), 43 deletions(-)
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 270ee6a..564621d 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -589,10 +589,6 @@ init_static (void)
{
/* configure_path (); */
-#if defined(ENABLE_CRYPTO) && defined(DMALLOC)
- crypto_init_dmalloc();
-#endif
-
init_random_seed (); /* init random() function, only used as
source for weak random numbers */
error_reset (); /* initialize error.c */
@@ -612,15 +608,6 @@ init_static (void)
update_time ();
-#ifdef ENABLE_CRYPTO
- init_ssl_lib ();
-
- /* init PRNG used for IV generation */
- /* When forking, copy this to more places in the code to avoid fork
- random-state predictability */
- prng_init (NULL, 0);
-#endif
-
#ifdef PID_TEST
packet_id_interactive_test (); /* test the sequence number code */
return false;
@@ -699,29 +686,6 @@ init_static (void)
}
#endif
-#ifdef PRNG_TEST
- {
- struct gc_arena gc = gc_new ();
- uint8_t rndbuf[8];
- int i;
- prng_init ("sha1", 16);
- /*prng_init (NULL, 0);*/
- const int factor = 1;
- for (i = 0; i < factor * 8; ++i)
- {
-#if 1
- prng_bytes (rndbuf, sizeof (rndbuf));
-#else
- ASSERT(rand_bytes (rndbuf, sizeof (rndbuf)));
-#endif
- printf ("[%d] %s\n", i, format_hex (rndbuf, sizeof (rndbuf), 0, &gc));
- }
- gc_free (&gc);
- prng_uninit ();
- return false;
- }
-#endif
-
#ifdef BUFFER_LIST_AGGREGATE_TEST
/* test buffer_list_aggregate function */
{
@@ -798,10 +762,6 @@ init_static (void)
void
uninit_static (void)
{
-#ifdef ENABLE_CRYPTO
- free_ssl_lib ();
-#endif
-
#ifdef ENABLE_PKCS11
pkcs11_terminate ();
#endif
@@ -1942,9 +1902,6 @@ key_schedule_free (struct key_schedule *ks, bool free_ssl_ctx)
static void
init_crypto_pre (struct context *c, const unsigned int flags)
{
- if (c->options.engine)
- crypto_init_lib_engine (c->options.engine);
-
if (flags & CF_LOAD_PERSISTED_PACKET_ID)
{
/* load a persisted packet-id for cross-session replay-protection */
@@ -3715,6 +3672,28 @@ test_crypto_thread (void *arg)
#endif
bool
+do_test_prng ()
+{
+#ifdef PRNG_TEST
+ struct gc_arena gc = gc_new ();
+ uint8_t rndbuf[8];
+ int i;
+ prng_init ("sha1", 16);
+ const int factor = 1;
+ for (i = 0; i < factor * 8; ++i)
+ {
+ prng_bytes (rndbuf, sizeof (rndbuf));
+ printf ("[%d] %s\n", i, format_hex (rndbuf, sizeof (rndbuf), 0, &gc));
+ }
+ gc_free (&gc);
+ prng_uninit ();
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool
do_test_crypto (const struct options *o)
{
#ifdef ENABLE_CRYPTO
diff --git a/src/openvpn/init.h b/src/openvpn/init.h
index 5a1d1dc..ed95f85 100644
--- a/src/openvpn/init.h
+++ b/src/openvpn/init.h
@@ -70,6 +70,7 @@ void do_route (const struct options *options,
void close_instance (struct context *c);
+bool do_test_prng ();
bool do_test_crypto (const struct options *o);
void context_gc_free (struct context *c);
diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c
index 104c9e9..170abe1 100644
--- a/src/openvpn/openvpn.c
+++ b/src/openvpn/openvpn.c
@@ -187,6 +187,25 @@ openvpn_main (int argc, char *argv[])
/* parse command line options, and read configuration file */
parse_argv (&c.options, argc, argv, M_USAGE, OPT_P_DEFAULT, NULL, c.es);
+#ifdef ENABLE_CRYPTO
+#ifdef DMALLOC
+ crypto_init_dmalloc ();
+#endif
+ /* initialize crypto and ssl/tls libraries */
+ if (c.options.engine)
+ crypto_init_lib_engine (c.options.engine);
+ init_ssl_lib ();
+
+ /*
+ * init PRNG used for IV generation
+ * when forking, copy this to more places in the code to avoid fork
+ * random-state predictability
+ */
+ prng_init (NULL, 0);
+ if (do_test_prng ())
+ break;
+#endif
+
#ifdef ENABLE_PLUGIN
/* plugins may contribute options configuration */
init_verb_mute (&c, IVM_LEVEL_1);
@@ -269,6 +288,9 @@ openvpn_main (int argc, char *argv[])
}
while (c.sig->signal_received == SIGUSR1);
+#ifdef ENABLE_CRYPTO
+ free_ssl_lib ();
+#endif
uninit_options (&c.options);
gc_reset (&c.gc);
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 3/7] remove API for crypto engine initialization
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 2/7] init crypto engine before SSL library Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 4/7] support crypto engine options Heiko Hund
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
Since the crypto library and the crypto engine initialization are now
happening at the same time, there's no apparent need for two distinct
APIs the init them anymore.
The crypto engine is now initialized within the crypto library init
function, which makes to code look a bit cleaner.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
src/openvpn/crypto.c | 4 ++--
src/openvpn/crypto.h | 2 +-
src/openvpn/crypto_backend.h | 7 +------
src/openvpn/crypto_openssl.c | 7 +++++--
| 18 ++++--------------
src/openvpn/openvpn.c | 4 +---
src/openvpn/ssl.c | 5 ++---
src/openvpn/ssl.h | 2 +-
8 files changed, 17 insertions(+), 32 deletions(-)
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 2f67e5e..b95865e 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1376,9 +1376,9 @@ get_random()
#ifndef ENABLE_SSL
void
-init_ssl_lib (void)
+init_ssl_lib (const char *engine_name)
{
- crypto_init_lib ();
+ crypto_init_lib (engine_name);
}
void
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 3b4b88e..cd08cf3 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -358,7 +358,7 @@ void get_tls_handshake_key (const struct key_type *key_type,
#else
-void init_ssl_lib (void);
+void init_ssl_lib (const char *engine_name);
void free_ssl_lib (void);
#endif /* ENABLE_SSL */
diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h
index 1eac611..9727a92 100644
--- a/src/openvpn/crypto_backend.h
+++ b/src/openvpn/crypto_backend.h
@@ -43,17 +43,12 @@
* This routine should have additional OpenSSL crypto library initialisations
* used by both crypto and ssl components of OpenVPN.
*/
-void crypto_init_lib (void);
+void crypto_init_lib (const char *engine_name);
void crypto_uninit_lib (void);
void crypto_clear_error (void);
-/*
- * Initialise the given named crypto engine.
- */
-void crypto_init_lib_engine (const char *engine_name);
-
#ifdef DMALLOC
/*
* OpenSSL memory debugging. If dmalloc debugging is enabled, tell
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index 5342502..a7ee168 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -169,7 +169,7 @@ setup_engine (const char *engine)
#endif /* HAVE_OPENSSL_ENGINE */
-void
+static void
crypto_init_lib_engine (const char *engine_name)
{
#if HAVE_OPENSSL_ENGINE
@@ -192,8 +192,11 @@ crypto_init_lib_engine (const char *engine_name)
*/
void
-crypto_init_lib (void)
+crypto_init_lib (const char *engine_name)
{
+ if (engine_name)
+ crypto_init_lib_engine (engine_name);
+
#ifndef USE_SSL
#ifndef ENABLE_SMALL
ERR_load_crypto_strings ();
--git a/src/openvpn/crypto_polarssl.c b/src/openvpn/crypto_polarssl.c
index 3978a3c..b7f13e3 100644
--- a/src/openvpn/crypto_polarssl.c
+++ b/src/openvpn/crypto_polarssl.c
@@ -54,26 +54,16 @@
/*
*
- * Hardware engine support. Allows loading/unloading of engines.
- *
- */
-
-void
-crypto_init_lib_engine (const char *engine_name)
-{
- msg (M_WARN, "Note: PolarSSL hardware crypto engine functionality is not "
- "available");
-}
-
-/*
- *
* Functions related to the core crypto library
*
*/
void
-crypto_init_lib (void)
+crypto_init_lib (const char *engine_name)
{
+ if (engine_name)
+ msg (M_WARN, "Note: PolarSSL hardware crypto engine functionality is not "
+ "available");
}
void
diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c
index 170abe1..65f43c3 100644
--- a/src/openvpn/openvpn.c
+++ b/src/openvpn/openvpn.c
@@ -192,9 +192,7 @@ openvpn_main (int argc, char *argv[])
crypto_init_dmalloc ();
#endif
/* initialize crypto and ssl/tls libraries */
- if (c.options.engine)
- crypto_init_lib_engine (c.options.engine);
- init_ssl_lib ();
+ init_ssl_lib (c.options.engine);
/*
* init PRNG used for IV generation
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 19512c0..e9a7d0a 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -153,11 +153,10 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame
}
void
-init_ssl_lib ()
+init_ssl_lib (const char *engine_name)
{
+ crypto_init_lib (engine_name);
tls_init_lib ();
-
- crypto_init_lib ();
}
void
diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h
index cd7cae2..daa654c 100644
--- a/src/openvpn/ssl.h
+++ b/src/openvpn/ssl.h
@@ -144,7 +144,7 @@ struct tls_auth_standalone
/*
* Prepare the SSL library for use
*/
-void init_ssl_lib (void);
+void init_ssl_lib (const char *engine_name);
/*
* Free any internal state that the SSL library might have
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 4/7] support crypto engine options
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
` (2 preceding siblings ...)
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 3/7] remove API for crypto engine initialization Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 5/7] have crypto backends report the MAC key length Heiko Hund
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
OpenVPN supports using OpenSSL engines by loading them with the
--engine configuration option. Some of those engines require
configuration options themself.
This patch extends the --engine option so that engine-options can be
specified as well.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
doc/openvpn.8 | 11 ++++++-----
src/openvpn/crypto.c | 4 ++--
src/openvpn/crypto.h | 2 +-
src/openvpn/crypto_backend.h | 17 ++++++++++++++++-
src/openvpn/crypto_openssl.c | 33 +++++++++++++++++++++------------
| 4 ++--
src/openvpn/options.c | 32 +++++++++++++++++++++++++++-----
src/openvpn/options.h | 3 ++-
src/openvpn/ssl.c | 4 ++--
src/openvpn/ssl.h | 2 +-
10 files changed, 80 insertions(+), 32 deletions(-)
diff --git a/doc/openvpn.8 b/doc/openvpn.8
index 56be29e..d967ebd 100644
--- a/doc/openvpn.8
+++ b/doc/openvpn.8
@@ -3704,13 +3704,14 @@ to disable the PRNG and use the OpenSSL RAND_bytes function
instead for all of OpenVPN's pseudo-random number needs.
.\"*********************************************************
.TP
-.B \-\-engine [engine-name]
-Enable OpenSSL hardware-based crypto engine functionality.
-
+.B \-\-engine [engine-name [engine-option ...]]
+Enable OpenSSL crypto engine functionality.
If
.B engine-name
-is specified,
-use a specific crypto engine. Use the
+is specified, use a specific crypto engine.
+.B engine-options
+must be given as name=value pairs.
+Use the
.B \-\-show-engines
standalone option to list the crypto engines which are
supported by OpenSSL.
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index b95865e..7fdbb95 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1376,9 +1376,9 @@ get_random()
#ifndef ENABLE_SSL
void
-init_ssl_lib (const char *engine_name)
+init_ssl_lib (const struct crypto_engine *engine)
{
- crypto_init_lib (engine_name);
+ crypto_init_lib (engine);
}
void
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index cd08cf3..5c34597 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -358,7 +358,7 @@ void get_tls_handshake_key (const struct key_type *key_type,
#else
-void init_ssl_lib (const char *engine_name);
+void init_ssl_lib (const struct crypto_engine *engine);
void free_ssl_lib (void);
#endif /* ENABLE_SSL */
diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h
index 9727a92..4b68687 100644
--- a/src/openvpn/crypto_backend.h
+++ b/src/openvpn/crypto_backend.h
@@ -40,10 +40,25 @@
/*
+ * Structures for crypto library engine configuration.
+ */
+struct crypto_engine_option
+{
+ struct crypto_engine_option *next;
+ const char *name;
+ const char *value;
+};
+struct crypto_engine
+{
+ const char *name;
+ struct crypto_engine_option *options;
+};
+
+/*
* This routine should have additional OpenSSL crypto library initialisations
* used by both crypto and ssl components of OpenVPN.
*/
-void crypto_init_lib (const char *engine_name);
+void crypto_init_lib (const struct crypto_engine *engine);
void crypto_uninit_lib (void);
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index a7ee168..deaf0ca 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -135,7 +135,7 @@ try_load_engine (const char *engine)
}
static ENGINE *
-setup_engine (const char *engine)
+setup_engine (const struct crypto_engine *engine)
{
ENGINE *e = NULL;
@@ -143,24 +143,33 @@ setup_engine (const char *engine)
if (engine)
{
- if (strcmp (engine, "auto") == 0)
+ struct crypto_engine_option *o;
+
+ if (strcmp (engine->name, "auto") == 0)
{
msg (M_INFO, "Initializing OpenSSL auto engine support");
ENGINE_register_all_complete ();
return NULL;
}
- if ((e = ENGINE_by_id (engine)) == NULL
- && (e = try_load_engine (engine)) == NULL)
+ if ((e = ENGINE_by_id (engine->name)) == NULL
+ && (e = try_load_engine (engine->name)) == NULL)
{
- msg (M_FATAL, "OpenSSL error: cannot load engine '%s'", engine);
+ msg (M_FATAL, "OpenSSL error: cannot load engine '%s'", engine->name);
}
if (!ENGINE_set_default (e, ENGINE_METHOD_ALL))
{
msg (M_FATAL, "OpenSSL error: ENGINE_set_default failed on engine '%s'",
- engine);
+ engine->name);
}
+ for (o = engine->options; o; o = o->next)
+ {
+ if (!ENGINE_ctrl_cmd_string (e, o->name, o->value, 0))
+ msg (M_FATAL, "OpenSSL error: ENGINE_ctrl_cmd_string failed on engine '%s'",
+ engine->name);
+ }
+
msg (M_INFO, "Initializing OpenSSL support for engine '%s'",
ENGINE_get_id (e));
}
@@ -170,14 +179,14 @@ setup_engine (const char *engine)
#endif /* HAVE_OPENSSL_ENGINE */
static void
-crypto_init_lib_engine (const char *engine_name)
+crypto_init_lib_engine (const struct crypto_engine *engine)
{
#if HAVE_OPENSSL_ENGINE
if (!engine_initialized)
{
- ASSERT (engine_name);
+ ASSERT (engine->name);
ASSERT (!engine_persist);
- engine_persist = setup_engine (engine_name);
+ engine_persist = setup_engine (engine);
engine_initialized = true;
}
#else
@@ -192,10 +201,10 @@ crypto_init_lib_engine (const char *engine_name)
*/
void
-crypto_init_lib (const char *engine_name)
+crypto_init_lib (const struct crypto_engine *engine)
{
- if (engine_name)
- crypto_init_lib_engine (engine_name);
+ if (engine)
+ crypto_init_lib_engine (engine);
#ifndef USE_SSL
#ifndef ENABLE_SMALL
--git a/src/openvpn/crypto_polarssl.c b/src/openvpn/crypto_polarssl.c
index b7f13e3..6b1193a 100644
--- a/src/openvpn/crypto_polarssl.c
+++ b/src/openvpn/crypto_polarssl.c
@@ -59,9 +59,9 @@
*/
void
-crypto_init_lib (const char *engine_name)
+crypto_init_lib (const struct crypto_engine *engine)
{
- if (engine_name)
+ if (engine)
msg (M_WARN, "Note: PolarSSL hardware crypto engine functionality is not "
"available");
}
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 19690e1..b78ff15 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -531,7 +531,7 @@ static const char usage_message[] =
" If unspecified, defaults to cipher-specific default.\n"
#endif
#ifndef ENABLE_CRYPTO_POLARSSL
- "--engine [name] : Enable OpenSSL hardware crypto engine functionality.\n"
+ "--engine [name [opts]] : Enable OpenSSL crypto engine functionality.\n"
#endif
"--no-replay : Disable replay protection.\n"
"--mute-replay-warnings : Silence the output of replay warnings to log file.\n"
@@ -6287,12 +6287,34 @@ add_option (struct options *options,
else if (streq (p[0], "engine"))
{
VERIFY_PERMISSION (OPT_P_GENERAL);
+ ALLOC_OBJ_CLEAR_GC (options->engine, struct crypto_engine, &options->gc);
+
if (p[1])
- {
- options->engine = p[1];
- }
+ {
+ int i;
+
+ options->engine->name = p[1];
+
+ for (i = 2; p[i]; i++)
+ {
+ struct crypto_engine_option *next_option;
+ char *eq = strchr (p[i], '=');
+ if (eq == NULL)
+ {
+ msg (msglevel, "Bad option for engine %s: %s", p[1], p[i]);
+ goto err;
+ }
+ *eq = '\0';
+
+ next_option = options->engine->options;
+ ALLOC_OBJ_GC (options->engine->options, struct crypto_engine_option, &options->gc);
+ options->engine->options->next = next_option;
+ options->engine->options->name = p[i];
+ options->engine->options->value = eq + 1;
+ }
+ }
else
- options->engine = "auto";
+ options->engine->name = "auto";
}
#endif /* ENABLE_CRYPTO_POLARSSL */
#ifdef HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH
diff --git a/src/openvpn/options.h b/src/openvpn/options.h
index 306520b..36eab25 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h
@@ -42,6 +42,7 @@
#include "lzo.h"
#include "pushlist.h"
#include "clinat.h"
+#include "crypto.h"
/*
* Maximum number of parameters associated with an option,
@@ -481,7 +482,7 @@ struct options
int keysize;
const char *prng_hash;
int prng_nonce_secret_len;
- const char *engine;
+ struct crypto_engine *engine;
bool replay;
bool mute_replay_warnings;
int replay_window;
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index e9a7d0a..a1a0628 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -153,9 +153,9 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame
}
void
-init_ssl_lib (const char *engine_name)
+init_ssl_lib (const struct crypto_engine *engine)
{
- crypto_init_lib (engine_name);
+ crypto_init_lib (engine);
tls_init_lib ();
}
diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h
index daa654c..001e4fd 100644
--- a/src/openvpn/ssl.h
+++ b/src/openvpn/ssl.h
@@ -144,7 +144,7 @@ struct tls_auth_standalone
/*
* Prepare the SSL library for use
*/
-void init_ssl_lib (const char *engine_name);
+void init_ssl_lib (const struct crypto_engine *engine);
/*
* Free any internal state that the SSL library might have
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 5/7] have crypto backends report the MAC key length
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
` (3 preceding siblings ...)
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 4/7] support crypto engine options Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 6/7] do MACs using EVP_MD_CTX with openssl >= 1.0.0 Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 7/7] change HMAC to MAC where applicable Heiko Hund
6 siblings, 0 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
This is in preparation for GOST MAC support. GOST MAC takes a 256 bit key
and produces a 32 bit signature. Hence there needs to be an API for
querying the key length as well.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
src/openvpn/crypto.c | 45 +++++++++++++++++++++--------------------
src/openvpn/crypto.h | 1 +
src/openvpn/crypto_backend.h | 9 +++++++++
src/openvpn/crypto_openssl.c | 7 +++++++
| 8 ++++++++
src/openvpn/openvpn.h | 2 +-
6 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 7fdbb95..f86c83a 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -430,6 +430,7 @@ init_key_type (struct key_type *kt, const char *ciphername,
{
kt->digest = md_kt_get (authname);
kt->hmac_length = md_kt_size (kt->digest);
+ kt->hmac_key_length = hmac_key_size (kt->digest);
}
else
{
@@ -465,17 +466,17 @@ init_key_ctx (struct key_ctx *ctx, struct key *key,
cipher_kt_block_size(kt->cipher),
cipher_kt_iv_size(kt->cipher));
}
- if (kt->digest && kt->hmac_length > 0)
+ if (kt->digest && kt->hmac_key_length > 0)
{
ALLOC_OBJ(ctx->hmac, hmac_ctx_t);
- hmac_ctx_init (ctx->hmac, key->hmac, kt->hmac_length, kt->digest);
+ hmac_ctx_init (ctx->hmac, key->hmac, kt->hmac_key_length, kt->digest);
msg (D_HANDSHAKE,
"%s: Using %d bit message hash '%s' for HMAC authentication",
prefix, md_kt_size(kt->digest) * 8, md_kt_name(kt->digest));
dmsg (D_SHOW_KEYS, "%s: HMAC KEY: %s", prefix,
- format_hex (key->hmac, kt->hmac_length, 0, &gc));
+ format_hex (key->hmac, kt->hmac_key_length, 0, &gc));
dmsg (D_CRYPTO_DEBUG, "%s: HMAC size=%d block_size=%d",
prefix,
@@ -610,7 +611,7 @@ void
generate_key_random (struct key *key, const struct key_type *kt)
{
int cipher_len = MAX_CIPHER_KEY_LENGTH;
- int hmac_len = MAX_HMAC_KEY_LENGTH;
+ int hmac_key_len = MAX_HMAC_KEY_LENGTH;
struct gc_arena gc = gc_new ();
@@ -621,15 +622,15 @@ generate_key_random (struct key *key, const struct key_type *kt)
if (kt->cipher && kt->cipher_length > 0 && kt->cipher_length <= cipher_len)
cipher_len = kt->cipher_length;
- if (kt->digest && kt->hmac_length > 0 && kt->hmac_length <= hmac_len)
- hmac_len = kt->hmac_length;
+ if (kt->digest && kt->hmac_key_length > 0 && kt->hmac_key_length <= hmac_key_len)
+ hmac_key_len = kt->hmac_key_length;
}
if (!rand_bytes (key->cipher, cipher_len)
- || !rand_bytes (key->hmac, hmac_len))
+ || !rand_bytes (key->hmac, hmac_key_len))
msg (M_FATAL, "ERROR: Random number generator cannot obtain entropy for key generation");
dmsg (D_SHOW_KEY_SOURCE, "Cipher source entropy: %s", format_hex (key->cipher, cipher_len, 0, &gc));
- dmsg (D_SHOW_KEY_SOURCE, "HMAC source entropy: %s", format_hex (key->hmac, hmac_len, 0, &gc));
+ dmsg (D_SHOW_KEY_SOURCE, "HMAC source entropy: %s", format_hex (key->hmac, hmac_key_len, 0, &gc));
if (kt)
fixup_key (key, kt);
@@ -654,13 +655,13 @@ key2_print (const struct key2* k,
format_hex (k->keys[0].cipher, kt->cipher_length, 0, &gc));
dmsg (D_SHOW_KEY_SOURCE, "%s (hmac): %s",
prefix0,
- format_hex (k->keys[0].hmac, kt->hmac_length, 0, &gc));
+ format_hex (k->keys[0].hmac, kt->hmac_key_length, 0, &gc));
dmsg (D_SHOW_KEY_SOURCE, "%s (cipher): %s",
prefix1,
format_hex (k->keys[1].cipher, kt->cipher_length, 0, &gc));
dmsg (D_SHOW_KEY_SOURCE, "%s (hmac): %s",
prefix1,
- format_hex (k->keys[1].hmac, kt->hmac_length, 0, &gc));
+ format_hex (k->keys[1].hmac, kt->hmac_key_length, 0, &gc));
gc_free (&gc);
}
@@ -727,7 +728,7 @@ get_tls_handshake_key (const struct key_type *key_type,
const int key_direction,
const unsigned int flags)
{
- if (passphrase_file && key_type->hmac_length)
+ if (passphrase_file && key_type->hmac_key_length)
{
struct key2 key2;
struct key_type kt = *key_type;
@@ -762,16 +763,16 @@ get_tls_handshake_key (const struct key_type *key_type,
}
else
{
- int hash_size;
+ int hash_key_size;
CLEAR (key2);
/* failed, now try to get hash from a freeform file */
- hash_size = read_passphrase_hash (passphrase_file,
+ hash_key_size = read_passphrase_hash (passphrase_file,
kt.digest,
key2.keys[0].hmac,
MAX_HMAC_KEY_LENGTH);
- ASSERT (hash_size == kt.hmac_length);
+ ASSERT (hash_key_size == kt.hmac_key_length);
/* suceeded */
key2.n = 1;
@@ -1223,15 +1224,15 @@ write_key (const struct key *key, const struct key_type *kt,
struct buffer *buf)
{
ASSERT (kt->cipher_length <= MAX_CIPHER_KEY_LENGTH
- && kt->hmac_length <= MAX_HMAC_KEY_LENGTH);
+ && kt->hmac_key_length <= MAX_HMAC_KEY_LENGTH);
if (!buf_write (buf, &kt->cipher_length, 1))
return false;
- if (!buf_write (buf, &kt->hmac_length, 1))
+ if (!buf_write (buf, &kt->hmac_key_length, 1))
return false;
if (!buf_write (buf, key->cipher, kt->cipher_length))
return false;
- if (!buf_write (buf, key->hmac, kt->hmac_length))
+ if (!buf_write (buf, key->hmac, kt->hmac_key_length))
return false;
return true;
@@ -1247,20 +1248,20 @@ int
read_key (struct key *key, const struct key_type *kt, struct buffer *buf)
{
uint8_t cipher_length;
- uint8_t hmac_length;
+ uint8_t hmac_key_length;
CLEAR (*key);
if (!buf_read (buf, &cipher_length, 1))
goto read_err;
- if (!buf_read (buf, &hmac_length, 1))
+ if (!buf_read (buf, &hmac_key_length, 1))
goto read_err;
if (!buf_read (buf, key->cipher, cipher_length))
goto read_err;
- if (!buf_read (buf, key->hmac, hmac_length))
+ if (!buf_read (buf, key->hmac, hmac_key_length))
goto read_err;
- if (cipher_length != kt->cipher_length || hmac_length != kt->hmac_length)
+ if (cipher_length != kt->cipher_length || hmac_key_length != kt->hmac_key_length)
goto key_len_err;
return 1;
@@ -1272,7 +1273,7 @@ read_err:
key_len_err:
msg (D_TLS_ERRORS,
"TLS Error: key length mismatch, local cipher/hmac %d/%d, remote cipher/hmac %d/%d",
- kt->cipher_length, kt->hmac_length, cipher_length, hmac_length);
+ kt->cipher_length, kt->hmac_key_length, cipher_length, hmac_key_length);
return 0;
}
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 5c34597..6f91b6f 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -47,6 +47,7 @@ struct key_type
{
uint8_t cipher_length; /**< Cipher length, in bytes */
uint8_t hmac_length; /**< HMAC length, in bytes */
+ uint8_t hmac_key_length; /**< HMAC key length, in bytes */
const cipher_kt_t *cipher; /**< Cipher static parameters */
const md_kt_t *digest; /**< Message digest static parameters */
};
diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h
index 4b68687..deff011 100644
--- a/src/openvpn/crypto_backend.h
+++ b/src/openvpn/crypto_backend.h
@@ -443,6 +443,15 @@ void md_ctx_final (md_ctx_t *ctx, uint8_t *dst);
*/
/*
+ * Returns the size of the HMAC key by the given message digest.
+ *
+ * @param ctx Message digest context. May not be NULL.
+ *
+ * @return Size of the HMAC key in bytes.
+ */
+int hmac_key_size (const md_kt_t *ctx);
+
+/*
* Initialises the given HMAC context, using the given digest
* and key.
*
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index deaf0ca..5665e29 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -714,6 +714,13 @@ md_ctx_final (EVP_MD_CTX *ctx, uint8_t *dst)
*
*/
+int
+hmac_key_size (const EVP_MD *kt)
+{
+ if (NULL == kt)
+ return 0;
+ return md_kt_size (kt);
+}
void
hmac_ctx_init (HMAC_CTX *ctx, const uint8_t *key, int key_len,
--git a/src/openvpn/crypto_polarssl.c b/src/openvpn/crypto_polarssl.c
index 6b1193a..b44ea12 100644
--- a/src/openvpn/crypto_polarssl.c
+++ b/src/openvpn/crypto_polarssl.c
@@ -546,6 +546,14 @@ md_ctx_final (md_context_t *ctx, uint8_t *dst)
/*
* TODO: re-enable dmsg for crypto debug
*/
+int
+hmac_key_size (const md_info_t *kt)
+{
+ if (NULL == kt)
+ return 0;
+ return md_get_size (kt);
+}
+
void
hmac_ctx_init (md_context_t *ctx, const uint8_t *key, int key_len, const md_info_t *kt)
{
diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h
index 0732d0f..3ff5470 100644
--- a/src/openvpn/openvpn.h
+++ b/src/openvpn/openvpn.h
@@ -572,7 +572,7 @@ struct context
#define PROTO_DUMP(buf, gc) protocol_dump((buf), \
PROTO_DUMP_FLAGS | \
(c->c2.tls_multi ? PD_TLS : 0) | \
- (c->options.tls_auth_file ? c->c1.ks.key_type.hmac_length : 0), \
+ (c->options.tls_auth_file ? c->c1.ks.key_type.hmac_key_length : 0), \
gc)
#else
#define TLS_MODE(c) (false)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 6/7] do MACs using EVP_MD_CTX with openssl >= 1.0.0
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
` (4 preceding siblings ...)
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 5/7] have crypto backends report the MAC key length Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 7/7] change HMAC to MAC where applicable Heiko Hund
6 siblings, 0 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
Using EVP_MD_CTX for MAC calculation allows to use other algorithms
than HMAC. In this particular case it allows the GOST-MAC to be used.
GOST-MAC uses a 256 bit key and produces a 32 bit signature.
Unfortunately OpenSSL has no API for querying a MAC's key length, so
the key length is returned statically in the case of GOST-MAC.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
src/openvpn/crypto_openssl.c | 62 ++++++++++++++++++++++++++++++++++++++++++
src/openvpn/crypto_openssl.h | 4 +++
2 files changed, 66 insertions(+)
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index 5665e29..b5f3cef 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -714,6 +714,66 @@ md_ctx_final (EVP_MD_CTX *ctx, uint8_t *dst)
*
*/
+#if SSLEAY_VERSION_NUMBER >= 0x10000000L
+
+int
+hmac_key_size (const EVP_MD *kt)
+{
+ if (NULL == kt)
+ return 0;
+ return (EVP_MD_type (kt) == NID_id_Gost28147_89_MAC ? 32 : md_kt_size (kt));
+}
+
+void
+hmac_ctx_init (EVP_MD_CTX *ctx, const uint8_t *key, int key_len,
+ const EVP_MD *kt)
+{
+ int pkey_id;
+
+ ASSERT (NULL != kt && NULL != ctx);
+
+ pkey_id = ( EVP_MD_type (kt) == NID_id_Gost28147_89_MAC
+ ? NID_id_Gost28147_89_MAC : EVP_PKEY_HMAC );
+
+ EVP_MD_CTX_init (ctx);
+ EVP_DigestSignInit (ctx, NULL, kt, NULL,
+ EVP_PKEY_new_mac_key (pkey_id, NULL, (uint8_t *)key, key_len));
+}
+
+void
+hmac_ctx_cleanup (EVP_MD_CTX *ctx)
+{
+ /* frees the key implicitly */
+ EVP_MD_CTX_cleanup (ctx);
+}
+
+int
+hmac_ctx_size (const EVP_MD_CTX *ctx)
+{
+ return EVP_MD_CTX_size (ctx);
+}
+
+void
+hmac_ctx_reset (EVP_MD_CTX *ctx)
+{
+ EVP_DigestInit_ex (ctx, EVP_MD_CTX_md (ctx), NULL);
+}
+
+void
+hmac_ctx_update (EVP_MD_CTX *ctx, const uint8_t *src, int src_len)
+{
+ EVP_DigestSignUpdate (ctx, src, src_len);
+}
+
+void
+hmac_ctx_final (EVP_MD_CTX *ctx, uint8_t *dst)
+{
+ size_t mac_len = hmac_ctx_size (ctx);
+ EVP_DigestSignFinal (ctx, dst, &mac_len);
+}
+
+#else /* SSLEAY_VERSION_NUMBER >= 0x10000000L */
+
int
hmac_key_size (const EVP_MD *kt)
{
@@ -769,4 +829,6 @@ hmac_ctx_final (HMAC_CTX *ctx, uint8_t *dst)
HMAC_Final (ctx, dst, &in_hmac_len);
}
+#endif /* SSLEAY_VERSION_NUMBER >= 0x10000000L */
+
#endif /* ENABLE_CRYPTO && ENABLE_CRYPTO_OPENSSL */
diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h
index f883c2a..d7c9dd8 100644
--- a/src/openvpn/crypto_openssl.h
+++ b/src/openvpn/crypto_openssl.h
@@ -47,7 +47,11 @@ typedef EVP_CIPHER_CTX cipher_ctx_t;
typedef EVP_MD_CTX md_ctx_t;
/** Generic HMAC %context. */
+#if OPENSSL_VERSION_NUMBER >= 0x10000000L
+typedef EVP_MD_CTX hmac_ctx_t;
+#else
typedef HMAC_CTX hmac_ctx_t;
+#endif
/** Maximum length of an IV */
#define OPENVPN_MAX_IV_LENGTH EVP_MAX_IV_LENGTH
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH 7/7] change HMAC to MAC where applicable
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
` (5 preceding siblings ...)
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 6/7] do MACs using EVP_MD_CTX with openssl >= 1.0.0 Heiko Hund
@ 2012-08-16 8:38 ` Heiko Hund
6 siblings, 0 replies; 13+ messages in thread
From: Heiko Hund @ 2012-08-16 8:38 UTC (permalink / raw)
To: openvpn-devel
Sine there's --auth gost-mac, using HMAC throughout the code
is misleading. Especially in the crypto code itself.
This changes function and variable names as well as comments
to use the more generic MAC instead.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
doc/openvpn.8 | 46 ++++++-------
sample/sample-config-files/server.conf | 2 +-
src/openvpn/crypto.c | 118 ++++++++++++++++----------------
src/openvpn/crypto.h | 42 ++++++------
src/openvpn/crypto_backend.h | 58 ++++++++--------
src/openvpn/crypto_openssl.c | 42 ++++++------
src/openvpn/crypto_openssl.h | 6 +-
| 22 +++---
| 4 +-
src/openvpn/forward.c | 4 +-
src/openvpn/forward.h | 2 +-
src/openvpn/init.c | 2 +-
src/openvpn/ntlm.c | 10 +--
src/openvpn/openvpn.h | 8 +--
src/openvpn/options.c | 2 +-
src/openvpn/ssl.c | 94 ++++++++++++-------------
src/openvpn/ssl.h | 12 ++--
src/openvpn/ssl_common.h | 4 +-
18 files changed, 239 insertions(+), 239 deletions(-)
diff --git a/doc/openvpn.8 b/doc/openvpn.8
index d967ebd..c10283c 100644
--- a/doc/openvpn.8
+++ b/doc/openvpn.8
@@ -3565,14 +3565,14 @@ which was generated with
The optional
.B direction
parameter enables the use of 4 distinct keys
-(HMAC-send, cipher-encrypt, HMAC-receive, cipher-decrypt), so that
-each data flow direction has a different set of HMAC and cipher keys.
+(MAC-send, cipher-encrypt, MAC-receive, cipher-decrypt), so that
+each data flow direction has a different set of MAC and cipher keys.
This has a number of desirable security properties including
eliminating certain kinds of DoS and message replay attacks.
When the
.B direction
-parameter is omitted, 2 keys are used bidirectionally, one for HMAC
+parameter is omitted, 2 keys are used bidirectionally, one for MAC
and the other for encryption/decryption.
The
@@ -3622,25 +3622,25 @@ but random-looking data.
.\"*********************************************************
.TP
.B \-\-auth alg
-Authenticate packets with HMAC using message
-digest algorithm
+Authenticate packets with a message authentication algorithm (MAC) using
+message digest algorithm
.B alg.
(The default is
.B SHA1
).
-HMAC is a commonly used message authentication algorithm (MAC) that uses
+The commonly used message authentication algorithm is HMAC 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.
+OpenVPN's usage of the MAC is to first encrypt a packet, then MAC the resulting ciphertext.
-In static-key encryption mode, the HMAC key
+In static-key encryption mode, the MAC key
is included in the key file generated by
.B \-\-genkey.
-In TLS mode, the HMAC key is dynamically generated and shared
+In TLS mode, the MAC key is dynamically generated and shared
between peers via the TLS control channel. If OpenVPN receives a packet with
-a bad HMAC it will drop the packet.
-HMAC usually adds 16 or 20 bytes per packet.
+a bad MAC it will drop the packet.
+MACs usually adds 16 or 20 bytes per packet.
Set
.B alg=none
to disable authentication.
@@ -3945,12 +3945,12 @@ TLS mode is the most powerful crypto mode of OpenVPN in both security and flexib
TLS mode works by establishing control and
data channels which are multiplexed over a single TCP/UDP port. OpenVPN initiates
a TLS session over the control channel and uses it to exchange cipher
-and HMAC keys to protect the data channel. TLS mode uses a robust reliability
+and MAC keys to protect the data channel. TLS mode uses a robust reliability
layer over the UDP connection for all control channel communication, while
the data channel, over which encrypted tunnel data passes, is forwarded without
any mediation. The result is the best of both worlds: a fast data channel
that forwards over UDP with only the overhead of encrypt,
-decrypt, and HMAC functions,
+decrypt, and MAC functions,
and a control channel that provides all of the security features of TLS,
including certificate-based authentication and Diffie Hellman forward secrecy.
@@ -4226,7 +4226,7 @@ for protecting the tunnel data channel is generated and
exchanged over the TLS session.
In method 1 (the default for OpenVPN 1.x), both sides generate
-random encrypt and HMAC-send keys which are forwarded to
+random encrypt and MAC-send keys which are forwarded to
the other host over the TLS channel.
In method 2, (the default for OpenVPN 2.0)
@@ -4364,14 +4364,14 @@ Exit on TLS negotiation failure.
.\"*********************************************************
.TP
.B \-\-tls-auth file [direction]
-Add an additional layer of HMAC authentication on top of the TLS
+Add an additional layer of MAC authentication on top of the TLS
control channel to protect against DoS attacks.
In a nutshell,
.B \-\-tls-auth
-enables a kind of "HMAC firewall" on OpenVPN's TCP/UDP port,
+enables a kind of "MAC firewall" on OpenVPN's TCP/UDP port,
where TLS control channel packets
-bearing an incorrect HMAC signature can be dropped immediately without
+bearing an incorrect MAC signature can be dropped immediately without
response.
.B file
@@ -4385,7 +4385,7 @@ An OpenVPN static key file generated by
parameter is used).
.B (2)
-A freeform passphrase file. In this case the HMAC key will
+A freeform passphrase file. In this case the MAC key will
be derived by taking a secure hash of this file, similar to
the
.BR md5sum (1)
@@ -4430,14 +4430,14 @@ fallen to buffer overflow attacks.
So as a second line of defense, OpenVPN offers
this special layer of authentication on top of the TLS control channel so that
every packet on the control channel is authenticated by an
-HMAC signature and a unique ID for replay protection.
+MAC signature and a unique ID for replay protection.
This signature will also help protect against DoS (Denial of Service) attacks.
An important rule of thumb in reducing vulnerability to DoS attacks is to
minimize the amount of resources a potential, but as yet unauthenticated,
client is able to consume.
.B \-\-tls-auth
-does this by signing every TLS control channel packet with an HMAC signature,
+does this by signing every TLS control channel packet with an MAC signature,
including packets which are sent before the TLS level has had a chance
to authenticate the peer.
The result is that packets without
@@ -6214,9 +6214,9 @@ packets. On Linux 2.4+:
This will allow incoming packets on UDP port 1194 (OpenVPN's default UDP port)
from an OpenVPN peer at 1.2.3.4.
-If you are using HMAC-based packet authentication (the default in any of
+If you are using MAC-based packet authentication (the default in any of
OpenVPN's secure modes), having the firewall filter on source
-address can be considered optional, since HMAC packet authentication
+address can be considered optional, since MAC packet authentication
is a much more secure method of verifying the authenticity of
a packet source. In that case:
.IP
@@ -6263,7 +6263,7 @@ other hosts on the local network.
These rules are secure if you use packet authentication,
since no incoming packets will arrive on a TUN or TAP
virtual device
-unless they first pass an HMAC authentication test.
+unless they first pass an MAC authentication test.
.\"*********************************************************
.SH FAQ
.I http://openvpn.net/faq.html
diff --git a/sample/sample-config-files/server.conf b/sample/sample-config-files/server.conf
index f483b6b..60d1355 100644
--- a/sample/sample-config-files/server.conf
+++ b/sample/sample-config-files/server.conf
@@ -226,7 +226,7 @@ ifconfig-pool-persist ipp.txt
keepalive 10 120
# For extra security beyond that provided
-# by SSL/TLS, create an "HMAC firewall"
+# by SSL/TLS, create an "MAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index f86c83a..fb935ba 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -177,16 +177,16 @@ openvpn_encrypt (struct buffer *buf, struct buffer work,
work = *buf;
}
- /* HMAC the ciphertext (or plaintext if !cipher) */
- if (ctx->hmac)
+ /* MAC the ciphertext (or plaintext if !cipher) */
+ if (ctx->mac)
{
uint8_t *output = NULL;
- hmac_ctx_reset (ctx->hmac);
- hmac_ctx_update (ctx->hmac, BPTR(&work), BLEN(&work));
- output = buf_prepend (&work, hmac_ctx_size(ctx->hmac));
+ mac_ctx_reset (ctx->mac);
+ mac_ctx_update (ctx->mac, BPTR (&work), BLEN (&work));
+ output = buf_prepend (&work, mac_ctx_size (ctx->mac));
ASSERT (output);
- hmac_ctx_final (ctx->hmac, output);
+ mac_ctx_final (ctx->mac, output);
}
*buf = work;
@@ -225,29 +225,29 @@ openvpn_decrypt (struct buffer *buf, struct buffer work,
struct packet_id_net pin;
bool have_pin = false;
- /* Verify the HMAC */
- if (ctx->hmac)
+ /* Verify the MAC */
+ if (ctx->mac)
{
- int hmac_len;
- uint8_t local_hmac[MAX_HMAC_KEY_LENGTH]; /* HMAC of ciphertext computed locally */
+ int mac_len;
+ uint8_t local_mac[MAX_MAC_KEY_LENGTH]; /* MAC of ciphertext computed locally */
- hmac_ctx_reset(ctx->hmac);
+ mac_ctx_reset(ctx->mac);
- /* Assume the length of the input HMAC */
- hmac_len = hmac_ctx_size (ctx->hmac);
+ /* Assume the length of the input MAC */
+ mac_len = mac_ctx_size (ctx->mac);
- /* Authentication fails if insufficient data in packet for HMAC */
- if (buf->len < hmac_len)
+ /* Authentication fails if insufficient data in packet for MAC */
+ if (buf->len < mac_len)
CRYPT_ERROR ("missing authentication info");
- hmac_ctx_update (ctx->hmac, BPTR (buf) + hmac_len, BLEN (buf) - hmac_len);
- hmac_ctx_final (ctx->hmac, local_hmac);
+ mac_ctx_update (ctx->mac, BPTR (buf) + mac_len, BLEN (buf) - mac_len);
+ mac_ctx_final (ctx->mac, local_mac);
- /* Compare locally computed HMAC with packet HMAC */
- if (memcmp (local_hmac, BPTR (buf), hmac_len))
- CRYPT_ERROR ("packet HMAC authentication failed");
+ /* Compare locally computed MAC with packet MAC */
+ if (memcmp (local_mac, BPTR (buf), mac_len))
+ CRYPT_ERROR ("packet MAC authentication failed");
- ASSERT (buf_advance (buf, hmac_len));
+ ASSERT (buf_advance (buf, mac_len));
}
/* Decrypt packet ID + payload */
@@ -386,7 +386,7 @@ crypto_adjust_frame_parameters(struct frame *frame,
(packet_id ? packet_id_size (packet_id_long_form) : 0) +
((cipher_defined && use_iv) ? cipher_kt_iv_size (kt->cipher) : 0) +
(cipher_defined ? cipher_kt_block_size (kt->cipher) : 0) + /* worst case padding expansion */
- kt->hmac_length);
+ kt->mac_length);
}
/*
@@ -429,8 +429,8 @@ init_key_type (struct key_type *kt, const char *ciphername,
if (authname && authname_defined)
{
kt->digest = md_kt_get (authname);
- kt->hmac_length = md_kt_size (kt->digest);
- kt->hmac_key_length = hmac_key_size (kt->digest);
+ kt->mac_length = md_kt_size (kt->digest);
+ kt->mac_key_length = mac_key_size (kt->digest);
}
else
{
@@ -466,22 +466,22 @@ init_key_ctx (struct key_ctx *ctx, struct key *key,
cipher_kt_block_size(kt->cipher),
cipher_kt_iv_size(kt->cipher));
}
- if (kt->digest && kt->hmac_key_length > 0)
+ if (kt->digest && kt->mac_key_length > 0)
{
- ALLOC_OBJ(ctx->hmac, hmac_ctx_t);
- hmac_ctx_init (ctx->hmac, key->hmac, kt->hmac_key_length, kt->digest);
+ ALLOC_OBJ(ctx->mac, mac_ctx_t);
+ mac_ctx_init (ctx->mac, key->mac, kt->mac_key_length, kt->digest);
msg (D_HANDSHAKE,
- "%s: Using %d bit message hash '%s' for HMAC authentication",
+ "%s: Using %d bit message hash '%s' for MAC authentication",
prefix, md_kt_size(kt->digest) * 8, md_kt_name(kt->digest));
- dmsg (D_SHOW_KEYS, "%s: HMAC KEY: %s", prefix,
- format_hex (key->hmac, kt->hmac_key_length, 0, &gc));
+ dmsg (D_SHOW_KEYS, "%s: MAC KEY: %s", prefix,
+ format_hex (key->mac, kt->mac_key_length, 0, &gc));
- dmsg (D_CRYPTO_DEBUG, "%s: HMAC size=%d block_size=%d",
+ dmsg (D_CRYPTO_DEBUG, "%s: MAC size=%d block_size=%d",
prefix,
md_kt_size(kt->digest),
- hmac_ctx_size(ctx->hmac));
+ mac_ctx_size(ctx->mac));
}
gc_free (&gc);
@@ -496,11 +496,11 @@ free_key_ctx (struct key_ctx *ctx)
free(ctx->cipher);
ctx->cipher = NULL;
}
- if (ctx->hmac)
+ if (ctx->mac)
{
- hmac_ctx_cleanup(ctx->hmac);
- free(ctx->hmac);
- ctx->hmac = NULL;
+ mac_ctx_cleanup (ctx->mac);
+ free (ctx->mac);
+ ctx->mac = NULL;
}
}
@@ -611,7 +611,7 @@ void
generate_key_random (struct key *key, const struct key_type *kt)
{
int cipher_len = MAX_CIPHER_KEY_LENGTH;
- int hmac_key_len = MAX_HMAC_KEY_LENGTH;
+ int mac_key_len = MAX_MAC_KEY_LENGTH;
struct gc_arena gc = gc_new ();
@@ -622,15 +622,15 @@ generate_key_random (struct key *key, const struct key_type *kt)
if (kt->cipher && kt->cipher_length > 0 && kt->cipher_length <= cipher_len)
cipher_len = kt->cipher_length;
- if (kt->digest && kt->hmac_key_length > 0 && kt->hmac_key_length <= hmac_key_len)
- hmac_key_len = kt->hmac_key_length;
+ if (kt->digest && kt->mac_key_length > 0 && kt->mac_key_length <= mac_key_len)
+ mac_key_len = kt->mac_key_length;
}
if (!rand_bytes (key->cipher, cipher_len)
- || !rand_bytes (key->hmac, hmac_key_len))
+ || !rand_bytes (key->mac, mac_key_len))
msg (M_FATAL, "ERROR: Random number generator cannot obtain entropy for key generation");
dmsg (D_SHOW_KEY_SOURCE, "Cipher source entropy: %s", format_hex (key->cipher, cipher_len, 0, &gc));
- dmsg (D_SHOW_KEY_SOURCE, "HMAC source entropy: %s", format_hex (key->hmac, hmac_key_len, 0, &gc));
+ dmsg (D_SHOW_KEY_SOURCE, "MAC source entropy: %s", format_hex (key->mac, mac_key_len, 0, &gc));
if (kt)
fixup_key (key, kt);
@@ -653,15 +653,15 @@ key2_print (const struct key2* k,
dmsg (D_SHOW_KEY_SOURCE, "%s (cipher): %s",
prefix0,
format_hex (k->keys[0].cipher, kt->cipher_length, 0, &gc));
- dmsg (D_SHOW_KEY_SOURCE, "%s (hmac): %s",
+ dmsg (D_SHOW_KEY_SOURCE, "%s (mac): %s",
prefix0,
- format_hex (k->keys[0].hmac, kt->hmac_key_length, 0, &gc));
+ format_hex (k->keys[0].mac, kt->mac_key_length, 0, &gc));
dmsg (D_SHOW_KEY_SOURCE, "%s (cipher): %s",
prefix1,
format_hex (k->keys[1].cipher, kt->cipher_length, 0, &gc));
- dmsg (D_SHOW_KEY_SOURCE, "%s (hmac): %s",
+ dmsg (D_SHOW_KEY_SOURCE, "%s (mac): %s",
prefix1,
- format_hex (k->keys[1].hmac, kt->hmac_key_length, 0, &gc));
+ format_hex (k->keys[1].mac, kt->mac_key_length, 0, &gc));
gc_free (&gc);
}
@@ -728,7 +728,7 @@ get_tls_handshake_key (const struct key_type *key_type,
const int key_direction,
const unsigned int flags)
{
- if (passphrase_file && key_type->hmac_key_length)
+ if (passphrase_file && key_type->mac_key_length)
{
struct key2 key2;
struct key_type kt = *key_type;
@@ -770,9 +770,9 @@ get_tls_handshake_key (const struct key_type *key_type,
/* failed, now try to get hash from a freeform file */
hash_key_size = read_passphrase_hash (passphrase_file,
kt.digest,
- key2.keys[0].hmac,
- MAX_HMAC_KEY_LENGTH);
- ASSERT (hash_key_size == kt.hmac_key_length);
+ key2.keys[0].mac,
+ MAX_MAC_KEY_LENGTH);
+ ASSERT (hash_key_size == kt.mac_key_length);
/* suceeded */
key2.n = 1;
@@ -787,7 +787,7 @@ get_tls_handshake_key (const struct key_type *key_type,
key_direction_state_init (&kds, key_direction);
must_have_n_keys (passphrase_file, "tls-auth", &key2, kds.need_keys);
- /* initialize hmac key in both directions */
+ /* initialize MAC key in both directions */
init_key_ctx (&ctx->encrypt, &key2.keys[kds.out_key], &kt, OPENVPN_OP_ENCRYPT,
"Outgoing Control Channel Authentication");
@@ -1224,15 +1224,15 @@ write_key (const struct key *key, const struct key_type *kt,
struct buffer *buf)
{
ASSERT (kt->cipher_length <= MAX_CIPHER_KEY_LENGTH
- && kt->hmac_key_length <= MAX_HMAC_KEY_LENGTH);
+ && kt->mac_key_length <= MAX_MAC_KEY_LENGTH);
if (!buf_write (buf, &kt->cipher_length, 1))
return false;
- if (!buf_write (buf, &kt->hmac_key_length, 1))
+ if (!buf_write (buf, &kt->mac_key_length, 1))
return false;
if (!buf_write (buf, key->cipher, kt->cipher_length))
return false;
- if (!buf_write (buf, key->hmac, kt->hmac_key_length))
+ if (!buf_write (buf, key->mac, kt->mac_key_length))
return false;
return true;
@@ -1248,20 +1248,20 @@ int
read_key (struct key *key, const struct key_type *kt, struct buffer *buf)
{
uint8_t cipher_length;
- uint8_t hmac_key_length;
+ uint8_t mac_key_length;
CLEAR (*key);
if (!buf_read (buf, &cipher_length, 1))
goto read_err;
- if (!buf_read (buf, &hmac_key_length, 1))
+ if (!buf_read (buf, &mac_key_length, 1))
goto read_err;
if (!buf_read (buf, key->cipher, cipher_length))
goto read_err;
- if (!buf_read (buf, key->hmac, hmac_key_length))
+ if (!buf_read (buf, key->mac, mac_key_length))
goto read_err;
- if (cipher_length != kt->cipher_length || hmac_key_length != kt->hmac_key_length)
+ if (cipher_length != kt->cipher_length || mac_key_length != kt->mac_key_length)
goto key_len_err;
return 1;
@@ -1272,8 +1272,8 @@ read_err:
key_len_err:
msg (D_TLS_ERRORS,
- "TLS Error: key length mismatch, local cipher/hmac %d/%d, remote cipher/hmac %d/%d",
- kt->cipher_length, kt->hmac_key_length, cipher_length, hmac_key_length);
+ "TLS Error: key length mismatch, local cipher/mac %d/%d, remote cipher/mac %d/%d",
+ kt->cipher_length, kt->mac_key_length, cipher_length, mac_key_length);
return 0;
}
diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 6f91b6f..2c34db2 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -41,38 +41,38 @@
#include "mtu.h"
/*
- * Defines a key type and key length for both cipher and HMAC.
+ * Defines a key type and key length for both cipher and MAC.
*/
struct key_type
{
uint8_t cipher_length; /**< Cipher length, in bytes */
- uint8_t hmac_length; /**< HMAC length, in bytes */
- uint8_t hmac_key_length; /**< HMAC key length, in bytes */
+ uint8_t mac_length; /**< MAC length, in bytes */
+ uint8_t mac_key_length; /**< MAC key length, in bytes */
const cipher_kt_t *cipher; /**< Cipher static parameters */
const md_kt_t *digest; /**< Message digest static parameters */
};
/**
- * Container for unidirectional cipher and HMAC %key material.
+ * Container for unidirectional cipher and MAC %key material.
* @ingroup control_processor
*/
struct key
{
uint8_t cipher[MAX_CIPHER_KEY_LENGTH];
/**< %Key material for cipher operations. */
- uint8_t hmac[MAX_HMAC_KEY_LENGTH];
- /**< %Key material for HMAC operations. */
+ uint8_t mac[MAX_MAC_KEY_LENGTH];
+ /**< %Key material for MAC operations. */
};
/**
- * Container for one set of OpenSSL cipher and/or HMAC contexts.
+ * Container for one set of OpenSSL cipher and/or MAC contexts.
* @ingroup control_processor
*/
struct key_ctx
{
cipher_ctx_t *cipher; /**< Generic cipher %context. */
- hmac_ctx_t *hmac; /**< Generic HMAC %context. */
+ mac_ctx_t *mac; /**< Generic MAC %context. */
};
#define KEY_DIRECTION_BIDIRECTIONAL 0 /* same keys for both directions */
@@ -80,7 +80,7 @@ struct key_ctx
#define KEY_DIRECTION_INVERSE 2 /* encrypt with keys[1], decrypt with keys[0] */
/**
- * Container for bidirectional cipher and HMAC %key material.
+ * Container for bidirectional cipher and MAC %key material.
* @ingroup control_processor
*/
struct key2
@@ -117,15 +117,15 @@ struct key_direction_state
};
/**
- * Container for two sets of OpenSSL cipher and/or HMAC contexts for both
+ * Container for two sets of OpenSSL cipher and/or MAC contexts for both
* sending and receiving directions.
* @ingroup control_processor
*/
struct key_ctx_bi
{
- struct key_ctx encrypt; /**< OpenSSL cipher and/or HMAC contexts
+ struct key_ctx encrypt; /**< OpenSSL cipher and/or MAC contexts
* for sending direction. */
- struct key_ctx decrypt; /**< OpenSSL cipher and/or HMAC contexts
+ struct key_ctx decrypt; /**< OpenSSL cipher and/or MAC contexts
* for receiving direction. */
};
@@ -136,7 +136,7 @@ struct key_ctx_bi
struct crypto_options
{
struct key_ctx_bi *key_ctx_bi;
- /**< OpenSSL cipher and HMAC contexts for
+ /**< OpenSSL cipher and MAC contexts for
* both sending and receiving
* directions. */
struct packet_id *packet_id; /**< Current packet ID state for both
@@ -214,17 +214,17 @@ void free_key_ctx_bi (struct key_ctx_bi *ctx);
* @{ */
/**
- * Encrypt and HMAC sign a packet so that it can be sent as a data channel
+ * Encrypt and MAC sign a packet so that it can be sent as a data channel
* VPN tunnel packet to a remote OpenVPN peer.
* @ingroup data_crypto
*
- * This function handles encryption and HMAC signing of a data channel
+ * This function handles encryption and MAC signing of a data channel
* packet before it is sent to its remote OpenVPN peer. It receives the
* necessary security parameters in the \a opt argument, which should have
* been set to the correct values by the \c tls_pre_encrypt() function.
*
- * This function calls the \c EVP_Cipher* and \c HMAC_* functions of the
- * OpenSSL library to perform the actual security operations.
+ * This function calls the \c cipher_* and \c mac_* functions of the
+ * crypto backend to perform the actual security operations.
*
* If an error occurs during processing, then the \a buf %buffer is set to
* empty.
@@ -246,7 +246,7 @@ void openvpn_encrypt (struct buffer *buf, struct buffer work,
/**
- * HMAC verify and decrypt a data channel packet received from a remote
+ * MAC verify and decrypt a data channel packet received from a remote
* OpenVPN peer.
* @ingroup data_crypto
*
@@ -255,8 +255,8 @@ void openvpn_encrypt (struct buffer *buf, struct buffer work,
* security parameters in the \a opt argument, which should have been set
* to the correct values by the \c tls_pre_decrypt() function.
*
- * This function calls the \c EVP_Cipher* and \c HMAC_* functions of the
- * OpenSSL library to perform the actual security operations.
+ * This function calls the \c cipher_* and \c mac_* functions of the
+ * crypto backend to perform the actual security operations.
*
* If an error occurs during processing, then the \a buf %buffer is set to
* empty.
@@ -391,7 +391,7 @@ bool md5_digest_equal (const struct md5_digest *d1, const struct md5_digest *d2)
static inline bool
key_ctx_bi_defined(const struct key_ctx_bi* key)
{
- return key->encrypt.cipher || key->encrypt.hmac || key->decrypt.cipher || key->decrypt.hmac;
+ return key->encrypt.cipher || key->encrypt.mac || key->decrypt.cipher || key->decrypt.mac;
}
diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h
index deff011..1c9a7f3 100644
--- a/src/openvpn/crypto_backend.h
+++ b/src/openvpn/crypto_backend.h
@@ -335,18 +335,18 @@ int cipher_ctx_final (cipher_ctx_t *ctx, uint8_t *dst, int *dst_len);
*/
/*
- * Max size in bytes of any HMAC key that might conceivably be used.
+ * Max size in bytes of any MAC key that might conceivably be used.
*
* This value is checked at compile time in crypto.c to make sure
* it is always at least EVP_MAX_MD_SIZE. We define our own value
* for the same reason as above.
*/
-#define MAX_HMAC_KEY_LENGTH 64
+#define MAX_MAC_KEY_LENGTH 64
/**
* Return message digest parameters, based on the given digest name. The
* contents of these parameters are library-specific, and can be used to
- * initialise HMAC or message digest operations.
+ * initialise MAC or message digest operations.
*
* @param digest Name of the digest to retrieve parameters for (e.g.
* \c MD5).
@@ -438,70 +438,70 @@ void md_ctx_final (md_ctx_t *ctx, uint8_t *dst);
/*
*
- * Generic HMAC functions
+ * Generic MAC functions
*
*/
/*
- * Returns the size of the HMAC key by the given message digest.
+ * Returns the size of the MAC key by the given message digest.
*
* @param ctx Message digest context. May not be NULL.
*
- * @return Size of the HMAC key in bytes.
+ * @return Size of the MAC key in bytes.
*/
-int hmac_key_size (const md_kt_t *ctx);
+int mac_key_size (const md_kt_t *ctx);
/*
- * Initialises the given HMAC context, using the given digest
+ * Initialises the given MAC context, using the given digest
* and key.
*
- * @param ctx HMAC context to intialise
- * @param key The key to use for the HMAC
+ * @param ctx MAC context to intialise
+ * @param key The key to use for the MAC
* @param key_len The key length to use
* @param kt Static message digest parameters
*
*/
-void hmac_ctx_init (hmac_ctx_t *ctx, const uint8_t *key, int key_length,
+void mac_ctx_init (mac_ctx_t *ctx, const uint8_t *key, int key_length,
const md_kt_t *kt);
/*
- * Free the given HMAC context.
+ * Free the given MAC context.
*
- * @param ctx HMAC context
+ * @param ctx MAC context
*/
-void hmac_ctx_cleanup(hmac_ctx_t *ctx);
+void mac_ctx_cleanup(mac_ctx_t *ctx);
/*
- * Returns the size of the HMAC output by the given HMAC Context
+ * Returns the size of the MAC output by the given MAC Context
*
- * @param ctx HMAC context.
+ * @param ctx MAC context.
*
- * @return Size of the HMAC, or \0 if ctx is NULL.
+ * @return Size of the MAC, or \0 if ctx is NULL.
*/
-int hmac_ctx_size (const hmac_ctx_t *ctx);
+int mac_ctx_size (const mac_ctx_t *ctx);
/*
- * Resets the given HMAC context, preserving the associated key information
+ * Resets the given MAC context, preserving the associated key information
*
- * @param ctx HMAC context. May not be NULL.
+ * @param ctx MAC context. May not be NULL.
*/
-void hmac_ctx_reset (hmac_ctx_t *ctx);
+void mac_ctx_reset (mac_ctx_t *ctx);
/*
- * Process the given data for use in the HMAC.
+ * Process the given data for use in the MAC.
*
- * @param ctx HMAC context. May not be NULL.
- * @param src The buffer to HMAC. May not be NULL.
+ * @param ctx MAC context. May not be NULL.
+ * @param src The buffer to MAC. May not be NULL.
* @param src_len The length of the incoming buffer.
*/
-void hmac_ctx_update (hmac_ctx_t *ctx, const uint8_t *src, int src_len);
+void mac_ctx_update (mac_ctx_t *ctx, const uint8_t *src, int src_len);
/*
- * Output the HMAC to the given buffer.
+ * Output the MAC to the given buffer.
*
- * @param ctx HMAC context. May not be NULL.
- * @param dst buffer to write the HMAC to. May not be NULL.
+ * @param ctx MAC context. May not be NULL.
+ * @param dst buffer to write the MAC to. May not be NULL.
*/
-void hmac_ctx_final (hmac_ctx_t *ctx, uint8_t *dst);
+void mac_ctx_final (mac_ctx_t *ctx, uint8_t *dst);
#endif /* CRYPTO_BACKEND_H_ */
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index b5f3cef..33ad1da 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -53,8 +53,8 @@
#warning Some OpenSSL EVP ciphers now support key lengths greater than MAX_CIPHER_KEY_LENGTH -- consider increasing MAX_CIPHER_KEY_LENGTH
#endif
-#if MAX_HMAC_KEY_LENGTH < EVP_MAX_MD_SIZE
-#warning Some OpenSSL HMAC message digests now support key lengths greater than MAX_HMAC_KEY_LENGTH -- consider increasing MAX_HMAC_KEY_LENGTH
+#if MAX_MAC_KEY_LENGTH < EVP_MAX_MD_SIZE
+#warning Some OpenSSL MAC message digests now support key lengths greater than MAX_MAC_KEY_LENGTH -- consider increasing MAX_MAC_KEY_LENGTH
#endif
/*
@@ -336,7 +336,7 @@ show_available_digests ()
#ifndef ENABLE_SMALL
printf ("The following message digests are available for use with\n"
PACKAGE_NAME ". A message digest is used in conjunction with\n"
- "the HMAC function, to authenticate received packets.\n"
+ "the MAC function, to authenticate received packets.\n"
"You can specify a message digest as parameter to\n"
"the --auth option.\n\n");
#endif
@@ -633,11 +633,11 @@ md_kt_get (const char *digest)
md = EVP_get_digestbyname (digest);
if (!md)
msg (M_SSLERR, "Message hash algorithm '%s' not found", digest);
- if (EVP_MD_size (md) > MAX_HMAC_KEY_LENGTH)
+ if (EVP_MD_size (md) > MAX_MAC_KEY_LENGTH)
msg (M_FATAL, "Message hash algorithm '%s' uses a default hash size (%d bytes) which is larger than " PACKAGE_NAME "'s current maximum hash size (%d bytes)",
digest,
EVP_MD_size (md),
- MAX_HMAC_KEY_LENGTH);
+ MAX_MAC_KEY_LENGTH);
return md;
}
@@ -710,14 +710,14 @@ md_ctx_final (EVP_MD_CTX *ctx, uint8_t *dst)
/*
*
- * Generic HMAC functions
+ * Generic MAC functions
*
*/
#if SSLEAY_VERSION_NUMBER >= 0x10000000L
int
-hmac_key_size (const EVP_MD *kt)
+mac_key_size (const EVP_MD *kt)
{
if (NULL == kt)
return 0;
@@ -725,7 +725,7 @@ hmac_key_size (const EVP_MD *kt)
}
void
-hmac_ctx_init (EVP_MD_CTX *ctx, const uint8_t *key, int key_len,
+mac_ctx_init (EVP_MD_CTX *ctx, const uint8_t *key, int key_len,
const EVP_MD *kt)
{
int pkey_id;
@@ -741,41 +741,41 @@ hmac_ctx_init (EVP_MD_CTX *ctx, const uint8_t *key, int key_len,
}
void
-hmac_ctx_cleanup (EVP_MD_CTX *ctx)
+mac_ctx_cleanup (EVP_MD_CTX *ctx)
{
/* frees the key implicitly */
EVP_MD_CTX_cleanup (ctx);
}
int
-hmac_ctx_size (const EVP_MD_CTX *ctx)
+mac_ctx_size (const EVP_MD_CTX *ctx)
{
return EVP_MD_CTX_size (ctx);
}
void
-hmac_ctx_reset (EVP_MD_CTX *ctx)
+mac_ctx_reset (EVP_MD_CTX *ctx)
{
EVP_DigestInit_ex (ctx, EVP_MD_CTX_md (ctx), NULL);
}
void
-hmac_ctx_update (EVP_MD_CTX *ctx, const uint8_t *src, int src_len)
+mac_ctx_update (EVP_MD_CTX *ctx, const uint8_t *src, int src_len)
{
EVP_DigestSignUpdate (ctx, src, src_len);
}
void
-hmac_ctx_final (EVP_MD_CTX *ctx, uint8_t *dst)
+mac_ctx_final (EVP_MD_CTX *ctx, uint8_t *dst)
{
- size_t mac_len = hmac_ctx_size (ctx);
+ size_t mac_len = mac_ctx_size (ctx);
EVP_DigestSignFinal (ctx, dst, &mac_len);
}
#else /* SSLEAY_VERSION_NUMBER >= 0x10000000L */
int
-hmac_key_size (const EVP_MD *kt)
+mac_key_size (const EVP_MD *kt)
{
if (NULL == kt)
return 0;
@@ -783,7 +783,7 @@ hmac_key_size (const EVP_MD *kt)
}
void
-hmac_ctx_init (HMAC_CTX *ctx, const uint8_t *key, int key_len,
+mac_ctx_init (HMAC_CTX *ctx, const uint8_t *key, int key_len,
const EVP_MD *kt)
{
ASSERT(NULL != kt && NULL != ctx);
@@ -798,31 +798,31 @@ hmac_ctx_init (HMAC_CTX *ctx, const uint8_t *key, int key_len,
}
void
-hmac_ctx_cleanup(HMAC_CTX *ctx)
+mac_ctx_cleanup(HMAC_CTX *ctx)
{
HMAC_CTX_cleanup (ctx);
}
int
-hmac_ctx_size (const HMAC_CTX *ctx)
+mac_ctx_size (const HMAC_CTX *ctx)
{
return HMAC_size (ctx);
}
void
-hmac_ctx_reset (HMAC_CTX *ctx)
+mac_ctx_reset (HMAC_CTX *ctx)
{
HMAC_Init_ex (ctx, NULL, 0, NULL, NULL);
}
void
-hmac_ctx_update (HMAC_CTX *ctx, const uint8_t *src, int src_len)
+mac_ctx_update (HMAC_CTX *ctx, const uint8_t *src, int src_len)
{
HMAC_Update (ctx, src, src_len);
}
void
-hmac_ctx_final (HMAC_CTX *ctx, uint8_t *dst)
+mac_ctx_final (HMAC_CTX *ctx, uint8_t *dst)
{
unsigned int in_hmac_len = 0;
diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h
index d7c9dd8..4c172db 100644
--- a/src/openvpn/crypto_openssl.h
+++ b/src/openvpn/crypto_openssl.h
@@ -46,11 +46,11 @@ typedef EVP_CIPHER_CTX cipher_ctx_t;
/** Generic message digest %context. */
typedef EVP_MD_CTX md_ctx_t;
-/** Generic HMAC %context. */
+/** Generic MAC %context. */
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
-typedef EVP_MD_CTX hmac_ctx_t;
+typedef EVP_MD_CTX mac_ctx_t;
#else
-typedef HMAC_CTX hmac_ctx_t;
+typedef HMAC_CTX mac_ctx_t;
#endif
/** Maximum length of an IV */
--git a/src/openvpn/crypto_polarssl.c b/src/openvpn/crypto_polarssl.c
index b44ea12..e35fc07 100644
--- a/src/openvpn/crypto_polarssl.c
+++ b/src/openvpn/crypto_polarssl.c
@@ -119,7 +119,7 @@ show_available_digests ()
#ifndef ENABLE_SMALL
printf ("The following message digests are available for use with\n"
PACKAGE_NAME ". A message digest is used in conjunction with\n"
- "the HMAC function, to authenticate received packets.\n"
+ "the MAC function, to authenticate received packets.\n"
"You can specify a message digest as parameter to\n"
"the --auth option.\n\n");
#endif
@@ -461,11 +461,11 @@ md_kt_get (const char *digest)
md = md_info_from_string(digest);
if (!md)
msg (M_FATAL, "Message hash algorithm '%s' not found", digest);
- if (md->size > MAX_HMAC_KEY_LENGTH)
+ if (md->size > MAX_MAC_KEY_LENGTH)
msg (M_FATAL, "Message hash algorithm '%s' uses a default hash size (%d bytes) which is larger than " PACKAGE_NAME "'s current maximum hash size (%d bytes)",
digest,
md->size,
- MAX_HMAC_KEY_LENGTH);
+ MAX_MAC_KEY_LENGTH);
return md;
}
@@ -538,7 +538,7 @@ md_ctx_final (md_context_t *ctx, uint8_t *dst)
/*
*
- * Generic HMAC functions
+ * Generic MAC functions
*
*/
@@ -547,7 +547,7 @@ md_ctx_final (md_context_t *ctx, uint8_t *dst)
* TODO: re-enable dmsg for crypto debug
*/
int
-hmac_key_size (const md_info_t *kt)
+mac_key_size (const md_info_t *kt)
{
if (NULL == kt)
return 0;
@@ -555,7 +555,7 @@ hmac_key_size (const md_info_t *kt)
}
void
-hmac_ctx_init (md_context_t *ctx, const uint8_t *key, int key_len, const md_info_t *kt)
+mac_ctx_init (md_context_t *ctx, const uint8_t *key, int key_len, const md_info_t *kt)
{
ASSERT(NULL != kt && NULL != ctx);
@@ -569,13 +569,13 @@ hmac_ctx_init (md_context_t *ctx, const uint8_t *key, int key_len, const md_info
}
void
-hmac_ctx_cleanup(md_context_t *ctx)
+mac_ctx_cleanup(md_context_t *ctx)
{
ASSERT(0 == md_free_ctx(ctx));
}
int
-hmac_ctx_size (const md_context_t *ctx)
+mac_ctx_size (const md_context_t *ctx)
{
if (NULL == ctx)
return 0;
@@ -583,19 +583,19 @@ hmac_ctx_size (const md_context_t *ctx)
}
void
-hmac_ctx_reset (md_context_t *ctx)
+mac_ctx_reset (md_context_t *ctx)
{
ASSERT(0 == md_hmac_reset(ctx));
}
void
-hmac_ctx_update (md_context_t *ctx, const uint8_t *src, int src_len)
+mac_ctx_update (md_context_t *ctx, const uint8_t *src, int src_len)
{
ASSERT(0 == md_hmac_update(ctx, src, src_len));
}
void
-hmac_ctx_final (md_context_t *ctx, uint8_t *dst)
+mac_ctx_final (md_context_t *ctx, uint8_t *dst)
{
ASSERT(0 == md_hmac_finish(ctx, dst));
}
--git a/src/openvpn/crypto_polarssl.h b/src/openvpn/crypto_polarssl.h
index bfabb91..7590353 100644
--- a/src/openvpn/crypto_polarssl.h
+++ b/src/openvpn/crypto_polarssl.h
@@ -47,8 +47,8 @@ typedef cipher_context_t cipher_ctx_t;
/** Generic message digest %context. */
typedef md_context_t md_ctx_t;
-/** Generic HMAC %context. */
-typedef md_context_t hmac_ctx_t;
+/** Generic MAC %context. */
+typedef md_context_t mac_ctx_t;
/** Maximum length of an IV */
#define OPENVPN_MAX_IV_LENGTH POLARSSL_MAX_IV_LENGTH
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 57c7846..156703c 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -423,7 +423,7 @@ buffer_turnover (const uint8_t *orig_buf, struct buffer *dest_stub, struct buffe
}
/*
- * Compress, fragment, encrypt and HMAC-sign an outgoing packet.
+ * Compress, fragment, encrypt and MAC-sign an outgoing packet.
* Input: c->c2.buf
* Output: c->c2.to_link
*/
@@ -469,7 +469,7 @@ encrypt_sign (struct context *c, bool comp_frag)
/*
* Encrypt the packet and write an optional
- * HMAC signature.
+ * MAC signature.
*/
openvpn_encrypt (&c->c2.buf, b->encrypt_buf, &c->c2.crypto_options, &c->c2.frame);
#endif
diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h
index 0f829bd..efca2bb 100644
--- a/src/openvpn/forward.h
+++ b/src/openvpn/forward.h
@@ -88,7 +88,7 @@ void show_wait_status (struct context *c);
* security operations on the packet.
* - Call \c tls_pre_encrypt() to choose the appropriate security
* parameters for this packet.
- * - Call \c openvpn_encrypt() to encrypt and HMAC signed the packet.
+ * - Call \c openvpn_encrypt() to encrypt and MAC signed the packet.
* - Call \c tls_post_encrypt() to prepend the one-byte OpenVPN header
* and do some TLS accounting.
* - Place the resulting packet in \c c->c2.to_link so that it can be sent
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 564621d..118e2f9 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -1961,7 +1961,7 @@ do_init_crypto_static (struct context *c, const unsigned int flags)
options->authname_defined, options->keysize,
options->test_crypto, true);
- /* Read cipher and hmac keys from shared secret file */
+ /* Read cipher and MAC keys from shared secret file */
{
unsigned int rkf_flags = RKF_MUST_SUCCEED;
const char *rkf_file = options->shared_secret_file;
diff --git a/src/openvpn/ntlm.c b/src/openvpn/ntlm.c
index 3390bdd..570a375 100644
--- a/src/openvpn/ntlm.c
+++ b/src/openvpn/ntlm.c
@@ -87,13 +87,13 @@ static void
gen_hmac_md5 (const char* data, int data_len, const char* key, int key_len,char *result)
{
const md_kt_t *md5_kt = md_kt_get("MD5");
- hmac_ctx_t hmac_ctx;
+ mac_ctx_t hmac_ctx;
CLEAR(hmac_ctx);
- hmac_ctx_init(&hmac_ctx, key, key_len, md5_kt);
- hmac_ctx_update(&hmac_ctx, (const unsigned char *)data, data_len);
- hmac_ctx_final(&hmac_ctx, (unsigned char *)result);
- hmac_ctx_cleanup(&hmac_ctx);
+ mac_ctx_init(&hmac_ctx, key, key_len, md5_kt);
+ mac_ctx_update(&hmac_ctx, (const unsigned char *)data, data_len);
+ mac_ctx_final(&hmac_ctx, (unsigned char *)result);
+ mac_ctx_cleanup(&hmac_ctx);
}
static void
diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h
index 3ff5470..a96beab 100644
--- a/src/openvpn/openvpn.h
+++ b/src/openvpn/openvpn.h
@@ -56,7 +56,7 @@
struct key_schedule
{
#ifdef ENABLE_CRYPTO
- /* which cipher, HMAC digest, and key sizes are we using? */
+ /* which cipher, MAC digest, and key sizes are we using? */
struct key_type key_type;
/* pre-shared static key, read from a file */
@@ -66,7 +66,7 @@ struct key_schedule
/* our global SSL context */
struct tls_root_ctx ssl_ctx;
- /* optional authentication HMAC key for TLS control channel */
+ /* optional authentication MAC key for TLS control channel */
struct key_ctx_bi tls_auth_key;
#endif /* ENABLE_SSL */
@@ -347,7 +347,7 @@ struct context_2
* connection attempt. This structure
* is used by the \c
* tls_pre_decrypt_lite() function when
- * it performs the HMAC firewall check
+ * it performs the MAC firewall check
* on the first connection packet
* received from a new client. See the
* \c --tls-auth commandline option. */
@@ -572,7 +572,7 @@ struct context
#define PROTO_DUMP(buf, gc) protocol_dump((buf), \
PROTO_DUMP_FLAGS | \
(c->c2.tls_multi ? PD_TLS : 0) | \
- (c->options.tls_auth_file ? c->c1.ks.key_type.hmac_key_length : 0), \
+ (c->options.tls_auth_file ? c->c1.ks.key_type.mac_key_length : 0), \
gc)
#else
#define TLS_MODE(c) (false)
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index b78ff15..225c453 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -517,7 +517,7 @@ static const char usage_message[] =
" If d is specified, use separate keys for each\n"
" direction, set d=0 on one side of the connection,\n"
" and d=1 on the other side.\n"
- "--auth alg : Authenticate packets with HMAC using message\n"
+ "--auth alg : Authenticate packets with MAC using message\n"
" digest algorithm alg (default=%s).\n"
" (usually adds 16 or 20 bytes per packet)\n"
" Set alg=none to disable authentication.\n"
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index a1a0628..3d1c6a1 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -33,7 +33,7 @@
/*
* The routines in this file deal with dynamically negotiating
- * the data channel HMAC and cipher keys through a TLS session.
+ * the data channel MAC and cipher keys through a TLS session.
*
* Both the TLS session and the data channel are multiplexed
* over the same TCP/UDP port.
@@ -873,7 +873,7 @@ tls_multi_init (struct tls_options *tls_options)
/* get command line derived options */
ret->opt = *tls_options;
- /* set up pointer to HMAC object for TLS packet authentication */
+ /* set up pointer to MAC object for TLS packet authentication */
ret->opt.tls_auth.key_ctx_bi = &ret->opt.tls_auth_key;
/* set up list of keys to be scanned by data channel encrypt and decrypt routines */
@@ -910,7 +910,7 @@ tls_auth_standalone_init (struct tls_options *tls_options,
ALLOC_OBJ_CLEAR_GC (tas, struct tls_auth_standalone, gc);
- /* set up pointer to HMAC object for TLS packet authentication */
+ /* set up pointer to MAC object for TLS packet authentication */
tas->tls_auth_key = tls_options->tls_auth_key;
tas->tls_auth_options.key_ctx_bi = &tas->tls_auth_key;
tas->tls_auth_options.flags |= CO_PACKET_ID_LONG_FORM;
@@ -980,29 +980,29 @@ tls_multi_free (struct tls_multi *multi, bool clear)
/*
- * Move a packet authentication HMAC + related fields to or from the front
+ * Move a packet authentication MAC + related fields to or from the front
* of the buffer so it can be processed by encrypt/decrypt.
*/
/*
- * Dependent on hmac size, opcode size, and session_id size.
+ * Dependent on MAC size, opcode size, and session_id size.
* Will assert if too small.
*/
#define SWAP_BUF_SIZE 256
static bool
-swap_hmac (struct buffer *buf, const struct crypto_options *co, bool incoming)
+swap_mac (struct buffer *buf, const struct crypto_options *co, bool incoming)
{
struct key_ctx *ctx;
ASSERT (co);
ctx = (incoming ? &co->key_ctx_bi->decrypt : &co->key_ctx_bi->encrypt);
- ASSERT (ctx->hmac);
+ ASSERT (ctx->mac);
{
- /* hmac + packet_id (8 bytes) */
- const int hmac_size = hmac_ctx_size (ctx->hmac) + packet_id_size (true);
+ /* MAC + packet_id (8 bytes) */
+ const int mac_size = mac_ctx_size (ctx->mac) + packet_id_size (true);
/* opcode + session_id */
const int osid_size = 1 + SID_SIZE;
@@ -1015,11 +1015,11 @@ swap_hmac (struct buffer *buf, const struct crypto_options *co, bool incoming)
if (incoming)
{
e1 = osid_size;
- e2 = hmac_size;
+ e2 = mac_size;
}
else
{
- e1 = hmac_size;
+ e1 = mac_size;
e2 = osid_size;
}
@@ -1061,11 +1061,11 @@ write_control_auth (struct tls_session *session,
ASSERT (session_id_write_prepend (&session->session_id, buf));
ASSERT (header = buf_prepend (buf, 1));
*header = ks->key_id | (opcode << P_OPCODE_SHIFT);
- if (session->tls_auth.key_ctx_bi->encrypt.hmac)
+ if (session->tls_auth.key_ctx_bi->encrypt.mac)
{
- /* no encryption, only write hmac */
+ /* no encryption, only write MAC */
openvpn_encrypt (buf, null, &session->tls_auth, NULL);
- ASSERT (swap_hmac (buf, &session->tls_auth, false));
+ ASSERT (swap_mac (buf, &session->tls_auth, false));
}
*to_link_addr = &ks->remote_addr;
}
@@ -1080,21 +1080,21 @@ read_control_auth (struct buffer *buf,
{
struct gc_arena gc = gc_new ();
- if (co->key_ctx_bi->decrypt.hmac)
+ if (co->key_ctx_bi->decrypt.mac)
{
struct buffer null = clear_buf ();
- /* move the hmac record to the front of the packet */
- if (!swap_hmac (buf, co, true))
+ /* move the MAC record to the front of the packet */
+ if (!swap_mac (buf, co, true))
{
msg (D_TLS_ERRORS,
- "TLS Error: cannot locate HMAC in incoming packet from %s",
+ "TLS Error: cannot locate MAC in incoming packet from %s",
print_link_socket_actual (from, &gc));
gc_free (&gc);
return false;
}
- /* authenticate only (no decrypt) and remove the hmac record
+ /* authenticate only (no decrypt) and remove the MAC record
from the head of the buffer */
openvpn_decrypt (buf, null, co, NULL);
if (!buf->len)
@@ -1175,9 +1175,9 @@ tls1_P_hash(const md_kt_t *md_kt,
{
struct gc_arena gc = gc_new ();
int chunk,n;
- hmac_ctx_t ctx;
- hmac_ctx_t ctx_tmp;
- uint8_t A1[MAX_HMAC_KEY_LENGTH];
+ mac_ctx_t ctx;
+ mac_ctx_t ctx_tmp;
+ uint8_t A1[MAX_MAC_KEY_LENGTH];
unsigned int A1_len;
#ifdef ENABLE_DEBUG
@@ -1194,37 +1194,37 @@ tls1_P_hash(const md_kt_t *md_kt,
chunk = md_kt_size(md_kt);
A1_len = md_kt_size(md_kt);
- hmac_ctx_init(&ctx, sec, sec_len, md_kt);
- hmac_ctx_init(&ctx_tmp, sec, sec_len, md_kt);
+ mac_ctx_init(&ctx, sec, sec_len, md_kt);
+ mac_ctx_init(&ctx_tmp, sec, sec_len, md_kt);
- hmac_ctx_update(&ctx,seed,seed_len);
- hmac_ctx_final(&ctx, A1);
+ mac_ctx_update(&ctx,seed,seed_len);
+ mac_ctx_final(&ctx, A1);
n=0;
for (;;)
{
- hmac_ctx_reset(&ctx);
- hmac_ctx_reset(&ctx_tmp);
- hmac_ctx_update(&ctx,A1,A1_len);
- hmac_ctx_update(&ctx_tmp,A1,A1_len);
- hmac_ctx_update(&ctx,seed,seed_len);
+ mac_ctx_reset(&ctx);
+ mac_ctx_reset(&ctx_tmp);
+ mac_ctx_update(&ctx,A1,A1_len);
+ mac_ctx_update(&ctx_tmp,A1,A1_len);
+ mac_ctx_update(&ctx,seed,seed_len);
if (olen > chunk)
{
- hmac_ctx_final(&ctx, out);
+ mac_ctx_final(&ctx, out);
out+=chunk;
olen-=chunk;
- hmac_ctx_final(&ctx_tmp, A1); /* calc the next A1 value */
+ mac_ctx_final(&ctx_tmp, A1); /* calc the next A1 value */
}
else /* last one */
{
- hmac_ctx_final(&ctx, A1);
+ mac_ctx_final(&ctx, A1);
memcpy(out,A1,olen);
break;
}
}
- hmac_ctx_cleanup(&ctx);
- hmac_ctx_cleanup(&ctx_tmp);
+ mac_ctx_cleanup(&ctx);
+ mac_ctx_cleanup(&ctx_tmp);
CLEAR (A1);
dmsg (D_SHOW_KEY_SOURCE, "tls1_P_hash out: %s", format_hex (out_orig, olen_orig, 0, &gc));
@@ -3033,7 +3033,7 @@ tls_pre_decrypt (struct tls_multi *multi,
* determine whether we should generate a client instance
* object, in which case true is returned.
*
- * This function is essentially the first-line HMAC firewall
+ * This function is essentially the first-line MAC firewall
* on the UDP port listener in --mode server mode.
*/
bool
@@ -3103,7 +3103,7 @@ tls_pre_decrypt_lite (const struct tls_auth_standalone *tas,
*/
co.flags |= CO_IGNORE_PACKET_ID;
- /* HMAC test, if --tls-auth was specified */
+ /* MAC test, if --tls-auth was specified */
status = read_control_auth (&newbuf, &co, from);
free_buf (&newbuf);
if (!status)
@@ -3111,11 +3111,11 @@ tls_pre_decrypt_lite (const struct tls_auth_standalone *tas,
/*
* At this point, if --tls-auth is being used, we know that
- * the packet has passed the HMAC test, but we don't know if
+ * the packet has passed the MAC test, but we don't know if
* it is a replay yet. We will attempt to defeat replays
* by not advancing to the S_START state until we
* receive an ACK from our first reply to the client
- * that includes an HMAC of our randomly generated 64 bit
+ * that includes an MAC of our randomly generated 64 bit
* session ID.
*
* On the other hand if --tls-auth is not being used, we
@@ -3294,7 +3294,7 @@ protocol_dump (struct buffer *buffer, unsigned int flags, struct gc_arena *gc)
int op;
int key_id;
- int tls_auth_hmac_size = (flags & PD_TLS_AUTH_HMAC_SIZE_MASK);
+ int tls_auth_mac_size = (flags & PD_TLS_AUTH_MAC_SIZE_MASK);
if (buf.len <= 0)
{
@@ -3330,19 +3330,19 @@ protocol_dump (struct buffer *buffer, unsigned int flags, struct gc_arena *gc)
}
/*
- * tls-auth hmac + packet_id
+ * tls-auth MAC + packet_id
*/
- if (tls_auth_hmac_size)
+ if (tls_auth_mac_size)
{
struct packet_id_net pin;
- uint8_t tls_auth_hmac[MAX_HMAC_KEY_LENGTH];
+ uint8_t tls_auth_mac[MAX_MAC_KEY_LENGTH];
- ASSERT (tls_auth_hmac_size <= MAX_HMAC_KEY_LENGTH);
+ ASSERT (tls_auth_mac_size <= MAX_MAC_KEY_LENGTH);
- if (!buf_read (&buf, tls_auth_hmac, tls_auth_hmac_size))
+ if (!buf_read (&buf, tls_auth_mac, tls_auth_mac_size))
goto done;
if (flags & PD_VERBOSE)
- buf_printf (&out, " tls_hmac=%s", format_hex (tls_auth_hmac, tls_auth_hmac_size, 0, gc));
+ buf_printf (&out, " tls_mac=%s", format_hex (tls_auth_mac, tls_auth_mac_size, 0, gc));
if (!packet_id_read (&pin, &buf, true))
goto done;
diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h
index 001e4fd..f5046e7 100644
--- a/src/openvpn/ssl.h
+++ b/src/openvpn/ssl.h
@@ -326,7 +326,7 @@ bool tls_pre_decrypt (struct tls_multi *multi,
* The tests performed by this function are whether the packet's opcode is
* correct for establishing a new VPN tunnel, whether its key ID is 0, and
* whether its size is not too large. This function also performs the
- * initial HMAC firewall test, if configured to do so.
+ * initial MAC firewall test, if configured to do so.
*
* The incoming packet and the local VPN tunnel state are not modified by
* this function. Its sole purpose is to inspect the packet and determine
@@ -341,7 +341,7 @@ bool tls_pre_decrypt (struct tls_multi *multi,
* @return
* @li True if the packet is valid and a new VPN tunnel should be created
* for this client.
- * @li False if the packet is not valid, did not pass the HMAC firewall
+ * @li False if the packet is not valid, did not pass the MAC firewall
* test, or some other error occurred.
*/
bool tls_pre_decrypt_lite (const struct tls_auth_standalone *tas,
@@ -482,10 +482,10 @@ tls_set_single_session (struct tls_multi *multi)
/*
* protocol_dump() flags
*/
-#define PD_TLS_AUTH_HMAC_SIZE_MASK 0xFF
-#define PD_SHOW_DATA (1<<8)
-#define PD_TLS (1<<9)
-#define PD_VERBOSE (1<<10)
+#define PD_TLS_AUTH_MAC_SIZE_MASK 0xFF
+#define PD_SHOW_DATA (1<<8)
+#define PD_TLS (1<<9)
+#define PD_VERBOSE (1<<10)
const char *protocol_dump (struct buffer *buffer,
unsigned int flags,
diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h
index f3f43be..3adf507 100644
--- a/src/openvpn/ssl_common.h
+++ b/src/openvpn/ssl_common.h
@@ -162,7 +162,7 @@ struct key_state
struct link_socket_actual remote_addr; /* peer's IP addr */
struct packet_id packet_id; /* for data channel, to prevent replay attacks */
- struct key_ctx_bi key; /* data channel keys for encrypt/decrypt/hmac */
+ struct key_ctx_bi key; /* data channel keys for encrypt/decrypt/MAC */
struct key_source2 *key_src; /* source entropy for key expansion */
@@ -209,7 +209,7 @@ struct tls_options
/* our master TLS context from which all SSL objects derived */
struct tls_root_ctx ssl_ctx;
- /* data channel cipher, hmac, and key lengths */
+ /* data channel cipher, MAC, and key lengths */
struct key_type key_type;
/* true if we are a TLS server, client otherwise */
--
1.7.9.5
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC Heiko Hund
@ 2013-02-02 12:28 ` Arne Schwabe
2013-02-03 13:55 ` Jan Just Keijser
0 siblings, 1 reply; 13+ messages in thread
From: Arne Schwabe @ 2013-02-02 12:28 UTC (permalink / raw)
To: Heiko Hund <heiko.hund@; +Cc: openvpn-devel
Am 16.08.12 10:38, schrieb Heiko Hund:
> cipher_ctx_final() only returns an outlen in CBC mode. If CFB or OFB
> are used the assertion outlen == iv_len is always false.
>
> There's no CBC mode defined for the GOST 28147-89 block cipher. Hence
> this patch is needed for it to work. It's needed for other ciphers like
> BF-CFB as well, though.
>
> Signed-off-by: Heiko Hund <heiko.hund@...1489...>
> ---
> src/openvpn/crypto.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
> index ac2eecd..2f67e5e 100644
> --- a/src/openvpn/crypto.c
> +++ b/src/openvpn/crypto.c
> @@ -153,7 +153,7 @@ openvpn_encrypt (struct buffer *buf, struct buffer work,
> /* Flush the encryption buffer */
> ASSERT(cipher_ctx_final(ctx->cipher, BPTR (&work) + outlen, &outlen));
> work.len += outlen;
> - ASSERT (outlen == iv_size);
> + ASSERT (mode != OPENVPN_MODE_CBC || outlen == iv_size);
>
> /* prepend the IV to the ciphertext */
> if (opt->flags & CO_USE_IV)
I have a user of my app that also tripped over this asssert line:
> Here is the log that pointed it to me from the server side.
>
> Wed Jan 30 14:47:56 2013 208.54.86.158:52876 WARNING: 'cipher' is used
> inconsistently, local='cipher AES-128-CBC', remote='cipher AES-128-CFB'
>
> Before that I had used cipher AES-256-CFB8, but I had forgotten the 8 on the
> Android.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC
2013-02-02 12:28 ` Arne Schwabe
@ 2013-02-03 13:55 ` Jan Just Keijser
2013-02-03 14:08 ` Arne Schwabe
2014-05-31 16:17 ` Steffan Karger
0 siblings, 2 replies; 13+ messages in thread
From: Jan Just Keijser @ 2013-02-03 13:55 UTC (permalink / raw)
To: Arne Schwabe <arne@; +Cc: openvpn-devel
Arne Schwabe wrote:
> Am 16.08.12 10:38, schrieb Heiko Hund:
>
>> cipher_ctx_final() only returns an outlen in CBC mode. If CFB or OFB
>> are used the assertion outlen == iv_len is always false.
>>
>> There's no CBC mode defined for the GOST 28147-89 block cipher. Hence
>> this patch is needed for it to work. It's needed for other ciphers like
>> BF-CFB as well, though.
>>
>> Signed-off-by: Heiko Hund <heiko.hund@...1489...>
>> ---
>> src/openvpn/crypto.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
>> index ac2eecd..2f67e5e 100644
>> --- a/src/openvpn/crypto.c
>> +++ b/src/openvpn/crypto.c
>> @@ -153,7 +153,7 @@ openvpn_encrypt (struct buffer *buf, struct buffer work,
>> /* Flush the encryption buffer */
>> ASSERT(cipher_ctx_final(ctx->cipher, BPTR (&work) + outlen, &outlen));
>> work.len += outlen;
>> - ASSERT (outlen == iv_size);
>> + ASSERT (mode != OPENVPN_MODE_CBC || outlen == iv_size);
>>
>> /* prepend the IV to the ciphertext */
>> if (opt->flags & CO_USE_IV)
>>
>
> I have a user of my app that also tripped over this asssert line:
>
>
eeeehhh - removing the assert is nice, but do the other ciphers actually
*WORK* after that? does the test
openvpn --test-crypto
pass after that? I remember commenting out the assert for a few elliptic
curve ciphers, but openvpn was still not able to encrypt/decrypt
traffic successfully.
JJK
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC
2013-02-03 13:55 ` Jan Just Keijser
@ 2013-02-03 14:08 ` Arne Schwabe
2014-05-31 16:17 ` Steffan Karger
1 sibling, 0 replies; 13+ messages in thread
From: Arne Schwabe @ 2013-02-03 14:08 UTC (permalink / raw)
To: Jan Just Keijser <janjust@; +Cc: openvpn-devel
Am 03.02.13 14:55, schrieb Jan Just Keijser:
> Arne Schwabe wrote:
>> Am 16.08.12 10:38, schrieb Heiko Hund:
>>
>>> cipher_ctx_final() only returns an outlen in CBC mode. If CFB or OFB
>>> are used the assertion outlen == iv_len is always false.
>>>
>>> There's no CBC mode defined for the GOST 28147-89 block cipher. Hence
>>> this patch is needed for it to work. It's needed for other ciphers like
>>> BF-CFB as well, though.
>>>
>>> Signed-off-by: Heiko Hund <heiko.hund@...1489...>
>>> ---
>>> src/openvpn/crypto.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
>>> index ac2eecd..2f67e5e 100644
>>> --- a/src/openvpn/crypto.c
>>> +++ b/src/openvpn/crypto.c
>>> @@ -153,7 +153,7 @@ openvpn_encrypt (struct buffer *buf, struct
>>> buffer work,
>>> /* Flush the encryption buffer */
>>> ASSERT(cipher_ctx_final(ctx->cipher, BPTR (&work) + outlen,
>>> &outlen));
>>> work.len += outlen;
>>> - ASSERT (outlen == iv_size);
>>> + ASSERT (mode != OPENVPN_MODE_CBC || outlen == iv_size);
>>>
>>> /* prepend the IV to the ciphertext */
>>> if (opt->flags & CO_USE_IV)
>>>
>>
>> I have a user of my app that also tripped over this asssert line:
>>
>>
> eeeehhh - removing the assert is nice, but do the other ciphers
> actually *WORK* after that? does the test
> openvpn --test-crypto
> pass after that? I remember commenting out the assert for a few
> elliptic curve ciphers, but openvpn was still not able to
> encrypt/decrypt traffic successfully
I have no idea of the crypto involved. But if there is a known class of
cryptos that fails in this "obscure" way we should exit with error much
earlier.
Arne
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC
2013-02-03 13:55 ` Jan Just Keijser
2013-02-03 14:08 ` Arne Schwabe
@ 2014-05-31 16:17 ` Steffan Karger
2014-06-05 7:17 ` [Openvpn-devel] [PATCH applied] " Gert Doering
1 sibling, 1 reply; 13+ messages in thread
From: Steffan Karger @ 2014-05-31 16:17 UTC (permalink / raw)
To: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]
ACK (see attached and below for more details).
On 03-02-13 14:55, Jan Just Keijser wrote:
> Arne Schwabe wrote:
>> Am 16.08.12 10:38, schrieb Heiko Hund:
>>
>>> cipher_ctx_final() only returns an outlen in CBC mode. If CFB or OFB
>>> are used the assertion outlen == iv_len is always false.
>>>
>>> There's no CBC mode defined for the GOST 28147-89 block cipher. Hence
>>> this patch is needed for it to work. It's needed for other ciphers like
>>> BF-CFB as well, though.
>>>
>>> Signed-off-by: Heiko Hund <heiko.hund@...1489...>
>>> ---
>>> src/openvpn/crypto.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
>>> index ac2eecd..2f67e5e 100644
>>> --- a/src/openvpn/crypto.c
>>> +++ b/src/openvpn/crypto.c
>>> @@ -153,7 +153,7 @@ openvpn_encrypt (struct buffer *buf, struct buffer work,
>>> /* Flush the encryption buffer */
>>> ASSERT(cipher_ctx_final(ctx->cipher, BPTR (&work) + outlen, &outlen));
>>> work.len += outlen;
>>> - ASSERT (outlen == iv_size);
>>> + ASSERT (mode != OPENVPN_MODE_CBC || outlen == iv_size);
>>>
>>> /* prepend the IV to the ciphertext */
>>> if (opt->flags & CO_USE_IV)
>>>
>>
>> I have a user of my app that also tripped over this asssert line:
>>
>>
> eeeehhh - removing the assert is nice, but do the other ciphers actually
> *WORK* after that? does the test
> openvpn --test-crypto
> pass after that? I remember commenting out the assert for a few elliptic
> curve ciphers, but openvpn was still not able to encrypt/decrypt
> traffic successfully.
I came up with (almost) the same patch to fix OFB and CFB modes last
week, but then came across this almost 2 years old patch from Heiko
while searching for the history on these modes in OpenVPN. I rebased it
on master and ran some tests (attached the updated patch).
Manual --test-crypto and t_lpback tests for CBC, OFB and CFB, as well as
the regular t_client tests for CBC succeed. Everything looks good to me.
-Steffan
[-- Attachment #2: 0001-refine-assertion-to-allow-other-modes-than-CBC.patch --]
[-- Type: text/x-patch, Size: 1175 bytes --]
From 606ed6ba90b1705de1546f4f151b524f46393082 Mon Sep 17 00:00:00 2001
From: Heiko Hund <heiko.hund@...1489...>
Date: Thu, 16 Aug 2012 10:38:50 +0200
Subject: [PATCH] refine assertion to allow other modes than CBC
cipher_ctx_final() only returns an outlen in CBC mode. If CFB or OFB
are used the assertion outlen == iv_len is always false.
There's no CBC mode defined for the GOST 28147-89 block cipher. Hence
this patch is needed for it to work. It's needed for other ciphers like
BF-CFB as well, though.
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
---
src/openvpn/crypto.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index c4c356d..d0dc069 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -171,7 +171,7 @@ openvpn_encrypt (struct buffer *buf, struct buffer work,
/* Flush the encryption buffer */
ASSERT(cipher_ctx_final(ctx->cipher, BPTR (&work) + outlen, &outlen));
work.len += outlen;
- ASSERT (outlen == iv_size);
+ ASSERT (mode != OPENVPN_MODE_CBC || outlen == iv_size);
/* prepend the IV to the ciphertext */
if (opt->flags & CO_USE_IV)
--
1.9.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Openvpn-devel] [PATCH applied] Re: refine assertion to allow other modes than CBC
2014-05-31 16:17 ` Steffan Karger
@ 2014-06-05 7:17 ` Gert Doering
0 siblings, 0 replies; 13+ messages in thread
From: Gert Doering @ 2014-06-05 7:17 UTC (permalink / raw)
To: Heiko Hund <heiko.hund@; +Cc: openvpn-devel
Your patch has been applied to the master branch.
commit be46a2c083a6bd77754bc1674249eab583d25dac
Author: Heiko Hund
Date: Thu Aug 16 10:38:50 2012 +0200
refine assertion to allow other modes than CBC
Signed-off-by: Heiko Hund <heiko.hund@...1489...>
Acked-by: Steffan Karger <steffan.karger@...1435...>
Message-Id: <538A00AA.7090007@...1856...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8748
Signed-off-by: Gert Doering <gert@...1296...>
--
kind regards,
Gert Doering
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-06-05 7:17 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-16 8:38 [Openvpn-devel] GOST algorithm support for OpenVPN Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 1/7] refine assertion to allow other modes than CBC Heiko Hund
2013-02-02 12:28 ` Arne Schwabe
2013-02-03 13:55 ` Jan Just Keijser
2013-02-03 14:08 ` Arne Schwabe
2014-05-31 16:17 ` Steffan Karger
2014-06-05 7:17 ` [Openvpn-devel] [PATCH applied] " Gert Doering
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 2/7] init crypto engine before SSL library Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 3/7] remove API for crypto engine initialization Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 4/7] support crypto engine options Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 5/7] have crypto backends report the MAC key length Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 6/7] do MACs using EVP_MD_CTX with openssl >= 1.0.0 Heiko Hund
2012-08-16 8:38 ` [Openvpn-devel] [PATCH 7/7] change HMAC to MAC where applicable Heiko Hund
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.