On 18/12/16 19:26, Steffan Karger wrote:
> Now that we have touched each and every file anyway, I decided to go over
> the code I regularly work with and reformat it some more by hand.  This is
> how for I got today, and is a large enough patch I think.
> 
> This commit is mostly just reordering and changing whitespace, with one
> exception: it removes the #if 0 around some debugging code in
> read_key_file(), and now always print the debugging if D_SHOW_KEYS is
> enabled.
> 
> This patch is best reviewed with something like
> 'git diff --ignore-space-change'.
> 
> Signed-off-by: Steffan Karger <stef...@karger.me>
> ---
> v2: fix wrong indent, add more 'for () {' -> 'for ()\n{' fixes.
> 
>  src/openvpn/crypto.c         | 425 
> ++++++++++++++++++++++---------------------
>  src/openvpn/crypto.h         |  27 ++-
>  src/openvpn/crypto_mbedtls.c |  63 ++++---
>  src/openvpn/crypto_openssl.c |  38 ++--
>  src/openvpn/cryptoapi.c      | 101 ++++++----
>  5 files changed, 356 insertions(+), 298 deletions(-)
> 
[...snip...]

Hmmm ... I like that we're trying to clean up the formatting further.
But I'm not too happy that uncrustify seems to disagree slightly ...
See the attached patch what happened after applying your patch and then
running:

   $ uncrustify --no-backup -l C $files

We should either see if our uncrustify config is correct or need slight
adjustments (without needing to re-run it on the complete tree once again)


--
kind regards,

David Sommerseth
OpenVPN Technologies, Inc

diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 06e7b7e..a665648 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -268,9 +268,9 @@ openvpn_encrypt_v1(struct buffer *buf, struct buffer work,
             {
                 struct packet_id_net pin;
                 packet_id_alloc_outgoing(&opt->packet_id.send, &pin,
-                        BOOL_CAST(opt->flags & CO_PACKET_ID_LONG_FORM));
+                                         BOOL_CAST(opt->flags & CO_PACKET_ID_LONG_FORM));
                 ASSERT(packet_id_write(&pin, buf,
-                        BOOL_CAST(opt->flags & CO_PACKET_ID_LONG_FORM), true));
+                                       BOOL_CAST(opt->flags & CO_PACKET_ID_LONG_FORM), true));
             }
             if (ctx->hmac)
             {
@@ -570,7 +570,7 @@ openvpn_decrypt_v1(struct buffer *buf, struct buffer work,
 
             /* initialize work buffer with FRAME_HEADROOM bytes of prepend capacity */
             const int work_headroom =
-                    FRAME_HEADROOM_ADJ(frame, FRAME_HEADROOM_MARKER_DECRYPT);
+                FRAME_HEADROOM_ADJ(frame, FRAME_HEADROOM_MARKER_DECRYPT);
             ASSERT(buf_init(&work, work_headroom));
 
             /* use IV if user requested it */
@@ -718,7 +718,7 @@ openvpn_decrypt(struct buffer *buf, struct buffer work,
 
 void
 crypto_adjust_frame_parameters(struct frame *frame, const struct key_type *kt,
-        bool use_iv, bool packet_id, bool packet_id_long_form)
+                               bool use_iv, bool packet_id, bool packet_id_long_form)
 {
     size_t crypto_overhead = 0;
 
@@ -840,7 +840,7 @@ init_key_type(struct key_type *kt, const char *ciphername,
 /* given a key and key_type, build a key_ctx */
 void
 init_key_ctx(struct key_ctx *ctx, struct key *key, const struct key_type *kt,
-        int enc, const char *prefix)
+             int enc, const char *prefix)
 {
     struct gc_arena gc = gc_new();
     CLEAR(*ctx);
@@ -1101,7 +1101,7 @@ test_crypto(struct crypto_options *co, struct frame *frame)
 #ifdef HAVE_AEAD_CIPHER_MODES
     /* init implicit IV */
     const cipher_kt_t *cipher =
-            cipher_ctx_get_cipher_kt(co->key_ctx_bi.encrypt.cipher);
+        cipher_ctx_get_cipher_kt(co->key_ctx_bi.encrypt.cipher);
     if (cipher_kt_mode_aead(cipher))
     {
         size_t impl_iv_len = cipher_kt_iv_size(cipher) - sizeof(packet_id_type);
@@ -1114,7 +1114,7 @@ test_crypto(struct crypto_options *co, struct frame *frame)
         co->key_ctx_bi.encrypt.implicit_iv_len = impl_iv_len;
 
         memcpy(co->key_ctx_bi.decrypt.implicit_iv,
-                co->key_ctx_bi.encrypt.implicit_iv, OPENVPN_MAX_IV_LENGTH);
+               co->key_ctx_bi.encrypt.implicit_iv, OPENVPN_MAX_IV_LENGTH);
         co->key_ctx_bi.decrypt.implicit_iv_len = impl_iv_len;
     }
 #endif /* ifdef HAVE_AEAD_CIPHER_MODES */
@@ -1172,8 +1172,8 @@ test_crypto(struct crypto_options *co, struct frame *frame)
 
 void
 crypto_read_openvpn_key(const struct key_type *key_type, struct key_ctx_bi *ctx,
-        const char *key_file, const char *key_inline, const int key_direction,
-        const char *key_name, const char *opt_name)
+                        const char *key_file, const char *key_inline, const int key_direction,
+                        const char *key_name, const char *opt_name)
 {
     struct key2 key2;
     struct key_direction_state kds;
@@ -1419,7 +1419,7 @@ read_key_file(struct key2 *key2, const char *file, const unsigned int flags)
     for (int i = 0; i < (int) SIZE(key2->keys); ++i)
     {
         const char *fmt = format_hex_ex((const uint8_t *)&key2->keys[i],
-                sizeof(key2->keys[i]), 0, 16, "\n", &gc);
+                                        sizeof(key2->keys[i]), 0, 16, "\n", &gc);
         dmsg(D_SHOW_KEYS, "[%d]\n%s\n\n", i, fmt);
     }
 
@@ -1715,7 +1715,7 @@ prng_reset_nonce()
         msg(M_FATAL,
             "ERROR: Random number generator cannot obtain entropy for PRNG");
     }
-#else
+#else  /* if 1 */
     /* Only for testing -- will cause a predictable PRNG sequence */
     {
         int i;
diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c
index 2f66e33..f8405bd 100644
--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvpn/crypto_mbedtls.c
@@ -150,9 +150,9 @@ print_cipher(const cipher_kt_t *info)
                  ))
     {
         const char *ssl_only =
-                cipher_kt_mode_cbc(info) ? "" : ", TLS client/server mode only";
+            cipher_kt_mode_cbc(info) ? "" : ", TLS client/server mode only";
         const char *var_key_size = info->flags
-                & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ? " by default" : "";
+                                   & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ? " by default" : "";
 
         printf("%s  (%d bit key%s, %d bit block%s)\n",
                cipher_kt_name(info), cipher_kt_key_size(info) * 8, var_key_size,
@@ -421,7 +421,7 @@ cipher_kt_get(const char *ciphername)
     {
         msg(D_LOW,
             "Cipher algorithm '%s' uses a default key size (%d bytes) which is "
-            "larger than "PACKAGE_NAME"'s current maximum key size (%d bytes)",
+            "larger than "PACKAGE_NAME "'s current maximum key size (%d bytes)",
             ciphername, cipher->key_bitlen/8, MAX_CIPHER_KEY_LENGTH);
         return NULL;
     }
diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c
index 5beac36..0d40312 100644
--- a/src/openvpn/cryptoapi.c
+++ b/src/openvpn/cryptoapi.c
@@ -87,25 +87,25 @@
 
 static ERR_STRING_DATA CRYPTOAPI_str_functs[] = {
     { ERR_PACK(ERR_LIB_CRYPTOAPI, 0, 0),
-            "microsoft cryptoapi"},
+      "microsoft cryptoapi"},
     { ERR_PACK(0, CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE, 0),
-            "CertOpenSystemStore" },
+      "CertOpenSystemStore" },
     { ERR_PACK(0, CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE, 0),
-            "CertFindCertificateInStore" },
+      "CertFindCertificateInStore" },
     { ERR_PACK(0, CRYPTOAPI_F_CRYPT_ACQUIRE_CERTIFICATE_PRIVATE_KEY, 0),
-            "CryptAcquireCertificatePrivateKey" },
+      "CryptAcquireCertificatePrivateKey" },
     { ERR_PACK(0, CRYPTOAPI_F_CRYPT_CREATE_HASH, 0),
-            "CryptCreateHash" },
+      "CryptCreateHash" },
     { ERR_PACK(0, CRYPTOAPI_F_CRYPT_GET_HASH_PARAM, 0),
-            "CryptGetHashParam" },
+      "CryptGetHashParam" },
     { ERR_PACK(0, CRYPTOAPI_F_CRYPT_SET_HASH_PARAM, 0),
-            "CryptSetHashParam" },
+      "CryptSetHashParam" },
     { ERR_PACK(0, CRYPTOAPI_F_CRYPT_SIGN_HASH, 0),
-            "CryptSignHash" },
+      "CryptSignHash" },
     { ERR_PACK(0, CRYPTOAPI_F_LOAD_LIBRARY, 0),
-            "LoadLibrary" },
+      "LoadLibrary" },
     { ERR_PACK(0, CRYPTOAPI_F_GET_PROC_ADDRESS, 0),
-            "GetProcAddress" },
+      "GetProcAddress" },
     { 0, NULL }
 };
 
@@ -308,7 +308,7 @@ rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, i
 /* decrypt */
 static int
 rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa,
-        int padding)
+             int padding)
 {
     /* I haven't been able to trigger this one, but I want to know if it happens... */
     assert(0);
@@ -537,7 +537,7 @@ SSL_CTX_use_CryptoAPI_certificate(SSL_CTX *ssl_ctx, const char *cert_prop)
         goto err;
     }
     /* SSL_CTX_use_RSAPrivateKey() increased the reference count in 'rsa', so
-     * we decrease it here with RSA_free(), or it will never be cleaned up. */
+    * we decrease it here with RSA_free(), or it will never be cleaned up. */
     RSA_free(rsa);
     return 1;
 

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to