Skip to contentSkip to conversation

Some crypto_openssl.c cleanup

PATCH New Steffan Karger 2 participants 7 messages May 25, 2014 – May 26, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Some crypto_openssl.c cleanup

Hi,

The following three patches clean up minor stuff I came along while working in crypto_openssl.c. No functional changes.

1/3 and 2/3 can be applied to master as well as release/2.3, to keep the code differences between 2.3 and 2.4 smaller. I'll send rebased patches for these later on.

3/3 requires OpenSSL 0.9.8 or later, so is for master only.

-Steffan

#1 lore raw

PATCH 1/3 Remove function without effect (cipher_ok() always returned true).

---
 src/openvpn/crypto_openssl.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
src/openvpn/crypto_openssl.c +2 -8
index 6199e61..f471eee 100644
@@ -69,12 +69,6 @@ EVP_CipherUpdate_ov (EVP_CIPHER_CTX *ctx, uint8_t *out, int *outl, uint8_t *in,
   return EVP_CipherUpdate (ctx, out, outl, in, inl);
 }
 
-static inline bool
-cipher_ok (const char* name)
-{
-  return true;
-}
-
 #ifndef EVP_CIPHER_name
 #define EVP_CIPHER_name(e)		OBJ_nid2sn(EVP_CIPHER_nid(e))
 #endif
@@ -285,7 +279,7 @@ show_available_ciphers ()
   for (nid = 0; nid < 10000; ++nid)	/* is there a better way to get the size of the nid list? */
     {
       const EVP_CIPHER *cipher = EVP_get_cipherbynid (nid);
-      if (cipher && cipher_ok (OBJ_nid2sn (nid)))
+      if (cipher)
 	{
 	  const unsigned int mode = EVP_CIPHER_mode (cipher);
 	  if (mode == EVP_CIPH_CBC_MODE
@@ -464,7 +458,7 @@ cipher_kt_get (const char *ciphername)
 
   cipher = EVP_get_cipherbyname (ciphername);
 
-  if ((NULL == cipher) || !cipher_ok (OBJ_nid2sn (EVP_CIPHER_nid (cipher))))
+  if (NULL == cipher)
     msg (M_SSLERR, "Cipher algorithm '%s' not found", ciphername);
 
   if (EVP_CIPHER_key_length (cipher) > MAX_CIPHER_KEY_LENGTH)
Signature · 1 line
1.9.1
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove function without effect (cipher_ok() always returned true).

ACK. Patch has been applied to the master branch.

commit bb669e502596ccb52972d64acf964286f67f0e86

Author: Steffan Karger
Date:   Sun May 25 21:18:19 2014 +0200
     Remove function without effect (cipher_ok() always returned true).

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw

PATCH 2/3 Remove unneeded wrapper functions in crypto_openssl.c

In reply to Steffan Karger

Both EVPCipherInit_ov() and EVPCipherUpdate_ov() wrapped OpenSSL functions without any changes, so lets just use the functions directly.

---
 src/openvpn/crypto_openssl.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
src/openvpn/crypto_openssl.c +4 -16
index f471eee..22bb7c9 100644
@@ -57,18 +57,6 @@
 #warning Some OpenSSL HMAC message digests now support key lengths greater than MAX_HMAC_KEY_LENGTH -- consider increasing MAX_HMAC_KEY_LENGTH
 #endif
 
-static inline int
-EVP_CipherInit_ov (EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, uint8_t *key, uint8_t *iv, int enc)
-{
-  return EVP_CipherInit (ctx, type, key, iv, enc);
-}
-
-static inline int
-EVP_CipherUpdate_ov (EVP_CIPHER_CTX *ctx, uint8_t *out, int *outl, uint8_t *in, int inl)
-{
-  return EVP_CipherUpdate (ctx, out, outl, in, inl);
-}
-
 #ifndef EVP_CIPHER_name
 #define EVP_CIPHER_name(e)		OBJ_nid2sn(EVP_CIPHER_nid(e))
 #endif
@@ -519,13 +507,13 @@ cipher_ctx_init (EVP_CIPHER_CTX *ctx, uint8_t *key, int key_len,
   CLEAR (*ctx);
 
   EVP_CIPHER_CTX_init (ctx);
-  if (!EVP_CipherInit_ov (ctx, kt, NULL, NULL, enc))
+  if (!EVP_CipherInit (ctx, kt, NULL, NULL, enc))
     msg (M_SSLERR, "EVP cipher init #1");
 #ifdef HAVE_EVP_CIPHER_CTX_SET_KEY_LENGTH
   if (!EVP_CIPHER_CTX_set_key_length (ctx, key_len))
     msg (M_SSLERR, "EVP set key size");
 #endif
-  if (!EVP_CipherInit_ov (ctx, NULL, key, NULL, enc))
+  if (!EVP_CipherInit (ctx, NULL, key, NULL, enc))
     msg (M_SSLERR, "EVP cipher init #2");
 
   /* make sure we used a big enough key */
@@ -559,14 +547,14 @@ cipher_ctx_mode (const EVP_CIPHER_CTX *ctx)
 int
 cipher_ctx_reset (EVP_CIPHER_CTX *ctx, uint8_t *iv_buf)
 {
-  return EVP_CipherInit_ov (ctx, NULL, NULL, iv_buf, -1);
+  return EVP_CipherInit (ctx, NULL, NULL, iv_buf, -1);
 }
 
 int
 cipher_ctx_update (EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len,
     uint8_t *src, int src_len)
 {
-  return EVP_CipherUpdate_ov (ctx, dst, dst_len, src, src_len);
+  return EVP_CipherUpdate (ctx, dst, dst_len, src, src_len);
 }
 
 int
Signature · 1 line
1.9.1
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove unneeded wrapper functions in crypto_openssl.c

ACK. Patch has been applied to the master branch.

commit 9fbd056873616e9101f5007f92e98b53b245968e

Author: Steffan Karger
Date:   Sun May 25 21:18:20 2014 +0200
     Remove unneeded wrapper functions in crypto_openssl.c

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw

PATCH 3/3 Remove unneeded defines (were needed for pre-0.9.7 OpenSSL).

In reply to Steffan Karger

Since we now require OpenSSL 0.9.8, we don't need these anymore.

---
 src/openvpn/crypto_openssl.c | 8 --------
 1 file changed, 8 deletions(-)
src/openvpn/crypto_openssl.c +0 -8
index 22bb7c9..c3480e0 100644
@@ -57,14 +57,6 @@
 #warning Some OpenSSL HMAC message digests now support key lengths greater than MAX_HMAC_KEY_LENGTH -- consider increasing MAX_HMAC_KEY_LENGTH
 #endif
 
-#ifndef EVP_CIPHER_name
-#define EVP_CIPHER_name(e)		OBJ_nid2sn(EVP_CIPHER_nid(e))
-#endif
-
-#ifndef EVP_MD_name
-#define EVP_MD_name(e)			OBJ_nid2sn(EVP_MD_type(e))
-#endif
-
 #if HAVE_OPENSSL_ENGINE
 #include <openssl/engine.h>
 
Signature · 1 line
1.9.1
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Remove unneeded defines (were needed for pre-0.9.7 OpenSSL).

ACK. Patch has been applied to the master branch.

commit 0c5632510ce14a25a31b5065019f64ca9724a294

Author: Steffan Karger
Date:   Sun May 25 21:18:21 2014 +0200
     Remove unneeded defines (were needed for pre-0.9.7 OpenSSL).

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering