]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: Reformatted dcrypt-gnutls.c.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 18:18:28 +0000 (19:18 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 18 Mar 2018 13:57:15 +0000 (14:57 +0100)
src/lib-dcrypt/dcrypt-gnutls.c

index 09421f1b58030a53dce3c9b7c8e9e617ea9d8fbc..33a2a231a11dbcf4c2e796fc2a38b8a89dab9376 100644 (file)
@@ -44,11 +44,12 @@ struct dcrypt_private_key {
        void *ctx;
 };
 
-static
-int dcrypt_gnutls_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r);
+static int
+dcrypt_gnutls_private_to_public_key(struct dcrypt_private_key *priv_key,
+                                   struct dcrypt_public_key **pub_key_r,
+                                   const char **error_r);
 
-static
-int dcrypt_gnutls_error(int ec, const char **error_r)
+static int dcrypt_gnutls_error(int ec, const char **error_r)
 {
        i_assert(ec < 0);
        if(error_r != NULL) {
@@ -57,13 +58,21 @@ int dcrypt_gnutls_error(int ec, const char **error_r)
        return -1;
 }
 
-static
-int dcrypt_gnutls_ctx_sym_create(const char *algorithm, enum dcrypt_sym_mode mode, struct dcrypt_context_symmetric **ctx_r, const char **error_r)
+static int
+dcrypt_gnutls_ctx_sym_create(const char *algorithm,
+                            enum dcrypt_sym_mode mode,
+                            struct dcrypt_context_symmetric **ctx_r,
+                            const char **error_r)
 {
        gnutls_cipher_algorithm_t cipher = gnutls_cipher_get_id(algorithm);
-       if(cipher == GNUTLS_CIPHER_UNKNOWN) return dcrypt_gnutls_error(cipher, error_r);
-       pool_t pool = pool_alloconly_create("dcrypt gnutls", 128);
-       struct dcrypt_context_symmetric *ctx = p_new(pool, struct dcrypt_context_symmetric, 1);
+       struct dcrypt_context_symmetric *ctx;
+       pool_t pool;
+
+       if(cipher == GNUTLS_CIPHER_UNKNOWN)
+               return dcrypt_gnutls_error(cipher, error_r);
+
+       pool = pool_alloconly_create("dcrypt gnutls", 128);
+       ctx = p_new(pool, struct dcrypt_context_symmetric, 1);
        ctx->pool = pool;
        ctx->cipher = cipher;
        ctx->mode = mode;
@@ -71,121 +80,158 @@ int dcrypt_gnutls_ctx_sym_create(const char *algorithm, enum dcrypt_sym_mode mod
        return 0;
 }
 
-static
-int dcrypt_gnutls_ctx_sym_destroy(struct dcrypt_context_symmetric **ctx)
+static int
+dcrypt_gnutls_ctx_sym_destroy(struct dcrypt_context_symmetric **ctx)
 {
-       pool_t pool =(*ctx)->pool;
+       pool_t pool = (*ctx)->pool;
+
        gnutls_cipher_deinit((*ctx)->ctx);
        pool_unref(&pool);
        *ctx = NULL;
        return 0;
 }
 
-static
-void dcrypt_gnutls_ctx_sym_set_key(struct dcrypt_context_symmetric *ctx, const unsigned char *key, size_t key_len)
+static void
+dcrypt_gnutls_ctx_sym_set_key(struct dcrypt_context_symmetric *ctx,
+                             const unsigned char *key, size_t key_len)
 {
-       if(ctx->key.data != NULL) p_free(ctx->pool, ctx->key.data);
-       ctx->key.size = I_MIN(key_len,(size_t)gnutls_cipher_get_key_size(ctx->cipher));
+       if(ctx->key.data != NULL)
+               p_free(ctx->pool, ctx->key.data);
+
+       ctx->key.size = I_MIN(key_len,
+                             (size_t)gnutls_cipher_get_key_size(ctx->cipher));
        ctx->key.data = p_malloc(ctx->pool, ctx->key.size);
        memcpy(ctx->key.data, key, ctx->key.size);
 }
 
-static
-void dcrypt_gnutls_ctx_sym_set_iv(struct dcrypt_context_symmetric *ctx, const unsigned char *iv, size_t iv_len)
+static void
+dcrypt_gnutls_ctx_sym_set_iv(struct dcrypt_context_symmetric *ctx,
+                            const unsigned char *iv, size_t iv_len)
 {
-       if(ctx->iv.data != NULL) p_free(ctx->pool, ctx->iv.data);
-       ctx->iv.size = I_MIN(iv_len,(size_t)gnutls_cipher_get_iv_size(ctx->cipher));
+       if(ctx->iv.data != NULL)
+               p_free(ctx->pool, ctx->iv.data);
+       ctx->iv.size = I_MIN(iv_len,
+                            (size_t)gnutls_cipher_get_iv_size(ctx->cipher));
        ctx->iv.data = p_malloc(ctx->pool, ctx->iv.size);
        memcpy(ctx->iv.data, iv, ctx->iv.size);
 }
 
-static
-void dcrypt_gnutls_ctx_sym_set_key_iv_random(struct dcrypt_context_symmetric *ctx)
+static void
+dcrypt_gnutls_ctx_sym_set_key_iv_random(struct dcrypt_context_symmetric *ctx)
 {
-       if(ctx->key.data != NULL) p_free(ctx->pool, ctx->key.data);
-       if(ctx->iv.data != NULL) p_free(ctx->pool, ctx->iv.data);
-       ctx->key.data = p_malloc(ctx->pool, gnutls_cipher_get_key_size(ctx->cipher));
+       if(ctx->key.data != NULL)
+               p_free(ctx->pool, ctx->key.data);
+       if(ctx->iv.data != NULL)
+               p_free(ctx->pool, ctx->iv.data);
+
+       ctx->key.data = p_malloc(ctx->pool,
+                                gnutls_cipher_get_key_size(ctx->cipher));
        random_fill(ctx->key.data, gnutls_cipher_get_key_size(ctx->cipher));
        ctx->key.size = gnutls_cipher_get_key_size(ctx->cipher);
-       ctx->iv.data = p_malloc(ctx->pool, gnutls_cipher_get_iv_size(ctx->cipher));
+       ctx->iv.data = p_malloc(ctx->pool,
+                               gnutls_cipher_get_iv_size(ctx->cipher));
        random_fill(ctx->iv.data, gnutls_cipher_get_iv_size(ctx->cipher));
        ctx->iv.size = gnutls_cipher_get_iv_size(ctx->cipher);
 }
 
-static
-int dcrypt_gnutls_ctx_sym_get_key(struct dcrypt_context_symmetric *ctx, buffer_t *key)
+static int
+dcrypt_gnutls_ctx_sym_get_key(struct dcrypt_context_symmetric *ctx,
+                             buffer_t *key)
 {
-       if(ctx->key.data == NULL) return -1;
+       if(ctx->key.data == NULL)
+               return -1;
+
        buffer_append(key, ctx->key.data, ctx->key.size);
        return 0;
 }
-static
-int dcrypt_gnutls_ctx_sym_get_iv(struct dcrypt_context_symmetric *ctx, buffer_t *iv)
+
+static int 
+dcrypt_gnutls_ctx_sym_get_iv(struct dcrypt_context_symmetric *ctx, buffer_t *iv)
 {
-       if(ctx->iv.data == NULL) return -1;
+       if(ctx->iv.data == NULL)
+               return -1;
+
        buffer_append(iv, ctx->iv.data, ctx->iv.size);
        return 0;
 }
 
-static
-int dcrypt_gnutls_ctx_sym_get_key_length(struct dcrypt_context_symmetric *ctx)
+static int
+dcrypt_gnutls_ctx_sym_get_key_length(struct dcrypt_context_symmetric *ctx)
 {
        return gnutls_cipher_get_iv_size(ctx->cipher);
 }
-static
-int dcrypt_gnutls_ctx_sym_get_iv_length(struct dcrypt_context_symmetric *ctx)
+
+static int
+dcrypt_gnutls_ctx_sym_get_iv_length(struct dcrypt_context_symmetric *ctx)
 {
        return gnutls_cipher_get_iv_size(ctx->cipher);
 }
-static
-int dcrypt_gnutls_ctx_sym_get_block_size(struct dcrypt_context_symmetric *ctx)
+
+static int
+dcrypt_gnutls_ctx_sym_get_block_size(struct dcrypt_context_symmetric *ctx)
 {
        return gnutls_cipher_get_block_size(ctx->cipher);
 }
 
-static
-int dcrypt_gnutls_ctx_sym_init(struct dcrypt_context_symmetric *ctx, const char **error_r)
+static int
+dcrypt_gnutls_ctx_sym_init(struct dcrypt_context_symmetric *ctx,
+                          const char **error_r)
 {
        int ec;
+
        ec = gnutls_cipher_init(&ctx->ctx, ctx->cipher, &ctx->key, &ctx->iv);
-       if(ec < 0) return dcrypt_gnutls_error(ec, error_r);
+       if(ec < 0)
+               return dcrypt_gnutls_error(ec, error_r);
        return 0;
 }
 
-static
-int dcrypt_gnutls_ctx_sym_update(struct dcrypt_context_symmetric *ctx, const unsigned char *data, size_t data_len, buffer_t *result, const char **error_r)
+static int
+dcrypt_gnutls_ctx_sym_update(struct dcrypt_context_symmetric *ctx,
+                            const unsigned char *data, size_t data_len,
+                            buffer_t *result, const char **error_r)
 {
        int ec;
        size_t outl = gnutls_cipher_get_block_size(ctx->cipher);
        unsigned char buf[outl];
+
        ec = gnutls_cipher_encrypt2(ctx->ctx, data, data_len, buf, outl);
-       if(ec < 0) return dcrypt_gnutls_error(ec, error_r);
+       if(ec < 0)
+               return dcrypt_gnutls_error(ec, error_r);
+
        buffer_append(result, buf, outl);
        return ec;
 }
 
-static
-int dcrypt_gnutls_ctx_sym_final(struct dcrypt_context_symmetric *ctx, buffer_t *result, const char **error_r)
+static int
+dcrypt_gnutls_ctx_sym_final(struct dcrypt_context_symmetric *ctx,
+                           buffer_t *result, const char **error_r)
 {
-       return dcrypt_gnutls_ctx_sym_update(ctx, (const unsigned char*)"", 0, result, error_r);
+       return dcrypt_gnutls_ctx_sym_update(ctx, (const unsigned char*)"", 0,
+                                           result, error_r);
 }
 
-
-static
-int dcrypt_gnutls_ctx_hmac_create(const char *algorithm, struct dcrypt_context_hmac **ctx_r, const char **error_r)
+static int
+dcrypt_gnutls_ctx_hmac_create(const char *algorithm,
+                             struct dcrypt_context_hmac **ctx_r,
+                             const char **error_r)
 {
        gnutls_mac_algorithm_t md = gnutls_mac_get_id(algorithm);
-       if (md == GNUTLS_MAC_UNKNOWN) return dcrypt_gnutls_error(md, error_r);
-       pool_t pool = pool_alloconly_create("dcrypt gnutls", 128);
-       struct dcrypt_context_hmac *ctx = p_new(pool, struct dcrypt_context_hmac, 1);
+       struct dcrypt_context_hmac *ctx;
+       pool_t pool;
+
+       if (md == GNUTLS_MAC_UNKNOWN)
+               return dcrypt_gnutls_error(md, error_r);
+
+       pool = pool_alloconly_create("dcrypt gnutls", 128);
+       ctx = p_new(pool, struct dcrypt_context_hmac, 1);
        ctx->pool = pool;
        ctx->md = md;
        *ctx_r = ctx;
        return 0;
 }
 
-static
-int dcrypt_gnutls_ctx_hmac_destroy(struct dcrypt_context_hmac **ctx)
+static int
+dcrypt_gnutls_ctx_hmac_destroy(struct dcrypt_context_hmac **ctx)
 {
        pool_t pool = (*ctx)->pool;
        gnutls_hmac_deinit((*ctx)->ctx, NULL);
@@ -194,85 +240,114 @@ int dcrypt_gnutls_ctx_hmac_destroy(struct dcrypt_context_hmac **ctx)
        return 0;
 }
 
-
-static
-void dcrypt_gnutls_ctx_hmac_set_key(struct dcrypt_context_hmac *ctx, const unsigned char *key, size_t key_len)
+static void
+dcrypt_gnutls_ctx_hmac_set_key(struct dcrypt_context_hmac *ctx,
+                              const unsigned char *key, size_t key_len)
 {
-        if(ctx->key.data != NULL) p_free(ctx->pool, ctx->key.data);
+        if(ctx->key.data != NULL)
+               p_free(ctx->pool, ctx->key.data);
+
         ctx->key.size = I_MIN(key_len,(size_t)gnutls_hmac_get_len(ctx->md));
         ctx->key.data = p_malloc(ctx->pool, ctx->key.size);
         memcpy(ctx->key.data, key, ctx->key.size);
 }
 
-static
-int dcrypt_gnutls_ctx_hmac_get_key(struct dcrypt_context_hmac *ctx, buffer_t *key)
+static int
+dcrypt_gnutls_ctx_hmac_get_key(struct dcrypt_context_hmac *ctx, buffer_t *key)
 {
-       if (ctx->key.data == NULL) return -1;
+       if (ctx->key.data == NULL)
+               return -1;
+
        buffer_append(key, ctx->key.data, ctx->key.size);
        return 0;
 }
 
-static
-int dcrypt_gnutls_ctx_hmac_init(struct dcrypt_context_hmac *ctx, const char **error_r)
+static int
+dcrypt_gnutls_ctx_hmac_init(struct dcrypt_context_hmac *ctx,
+                           const char **error_r)
 {
        int ec;
+
        ec = gnutls_hmac_init(&ctx->ctx, ctx->md, ctx->key.data, ctx->key.size);
-       if (ec < 0) return dcrypt_gnutls_error(ec, error_r);
+       if (ec < 0)
+               return dcrypt_gnutls_error(ec, error_r);
        return 0;
 }
-static
-int dcrypt_gnutls_ctx_hmac_update(struct dcrypt_context_hmac *ctx, const unsigned char *data, size_t data_len, const char **error_r)
+
+static int
+dcrypt_gnutls_ctx_hmac_update(struct dcrypt_context_hmac *ctx,
+                             const unsigned char *data, size_t data_len,
+                             const char **error_r)
 {
        int ec;
+
        if ((ec = gnutls_hmac(ctx->ctx, data, data_len)) != 0)
                return dcrypt_gnutls_error(ec, error_r);
        return 0;
 }
-static
-int dcrypt_gnutls_ctx_hmac_final(struct dcrypt_context_hmac *ctx, buffer_t *result, const char **error_r)
+
+static int
+dcrypt_gnutls_ctx_hmac_final(struct dcrypt_context_hmac *ctx,
+                            buffer_t *result, const char **error_r)
 {
        size_t hlen = gnutls_hmac_get_len(ctx->md);
        unsigned char buf[hlen];
+
        gnutls_hmac_output(ctx->ctx, buf);
        buffer_append(result, buf, hlen);
        return 0;
 }
 
-static
-int dcrypt_gnutls_ecdh_derive_secret(struct dcrypt_public_key *peer_key, buffer_t *R, buffer_t *S, const char **error_r)
+static int
+dcrypt_gnutls_ecdh_derive_secret(struct dcrypt_public_key *peer_key,
+                                buffer_t *R, buffer_t *S,
+                                const char **error_r)
 {
 
 }
 
-static
-int dcrypt_gnutls_pbkdf2(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, const char *algorithm,
-       unsigned int rounds, buffer_t *result, unsigned int result_len, const char **error_r)
+static int
+dcrypt_gnutls_pbkdf2(const unsigned char *password, size_t password_len,
+                    const unsigned char *salt, size_t salt_len,
+                    const char *algorithm, unsigned int rounds,
+                    buffer_t *result, unsigned int result_len,
+                    const char **error_r)
 {
        unsigned char buf[result_len];
+
        /* only sha1 or sha256 is supported */
        if (strncasecmp(algorithm, "sha1", 4) == 0) {
-               pbkdf2_hmac_sha1(password_len, password, rounds, salt_len, salt, result_len, buf);
+               pbkdf2_hmac_sha1(password_len, password, rounds,
+                                salt_len, salt, result_len, buf);
        } else if (strncasecmp(algorithm, "sha256", 6) == 0) {
-               pbkdf2_hmac_sha256(password_len, password, rounds, salt_len, salt, result_len, buf);
+               pbkdf2_hmac_sha256(password_len, password, rounds,
+                                  salt_len, salt, result_len, buf);
        } else if (strncasecmp(algorithm, "sha512", 6) == 0) {
                struct hmac_sha512_ctx ctx;
+
                hmac_sha512_set_key(&ctx, password_len, password);
-               PBKDF2(&ctx, hmac_sha512_update, hmac_sha512_digest, 64, rounds, salt_len, salt, result_len, buf);
+               PBKDF2(&ctx, hmac_sha512_update, hmac_sha512_digest, 64, rounds,
+                      salt_len, salt, result_len, buf);
                i_zero(&ctx);
        } else {
                *error_r = "Unsupported algorithm";
                return -1;
        }
+
        buffer_append(result, buf, result_len);
        memset(buf, 0, sizeof(buf));
        return 0;
 }
 
-static
-int dcrypt_gnutls_generate_keypair(struct dcrypt_keypair *pair_r, enum dcrypt_key_type kind, unsigned int bits, const char *curve, const char **error_r)
+static int
+dcrypt_gnutls_generate_keypair(struct dcrypt_keypair *pair_r,
+                              enum dcrypt_key_type kind, unsigned int bits,
+                              const char *curve, const char **error_r)
 {
        gnutls_pk_algorithm_t pk_algo;
        gnutls_ecc_curve_t pk_curve;
+       gnutls_privkey_t priv;
+       int ec;
 
         if (kind == DCRYPT_KEY_EC) {
                pk_curve = gnutls_ecc_curve_get_id(curve);
@@ -285,7 +360,7 @@ int dcrypt_gnutls_generate_keypair(struct dcrypt_keypair *pair_r, enum dcrypt_ke
                pk_algo = gnutls_curve_get_pk(pk_curve);
 #else
                pk_algo = GNUTLS_PK_EC;
-#endif 
+#endif
         } else if (kind == DCRYPT_KEY_RSA) {
                 pk_algo = gnutls_pk_get_id("RSA");
         } else {
@@ -293,9 +368,8 @@ int dcrypt_gnutls_generate_keypair(struct dcrypt_keypair *pair_r, enum dcrypt_ke
                return -1;
        }
 
-       int ec;
-       gnutls_privkey_t priv;
-       if ((ec = gnutls_privkey_init(&priv)) != GNUTLS_E_SUCCESS) return dcrypt_gnutls_error(ec, error_r);
+       if ((ec = gnutls_privkey_init(&priv)) != GNUTLS_E_SUCCESS)
+               return dcrypt_gnutls_error(ec, error_r);
 #if GNUTLS_VERSION_NUMBER >= 0x030500
        gnutls_privkey_set_flags(priv, GNUTLS_PRIVKEY_FLAG_EXPORT_COMPAT);
 #endif
@@ -307,28 +381,39 @@ int dcrypt_gnutls_generate_keypair(struct dcrypt_keypair *pair_r, enum dcrypt_ke
 
        pair_r->priv = (struct dcrypt_private_key*)priv;
 
-       return dcrypt_gnutls_private_to_public_key(pair_r->priv, &pair_r->pub, error_r);
-} 
+       return dcrypt_gnutls_private_to_public_key(pair_r->priv,
+                                                  &pair_r->pub, error_r);
+}
 
-static
-int dcrypt_gnutls_load_private_key(struct dcrypt_private_key **key_r, const unsigned char *data, size_t data_len, dcrypt_password_cb *cb, void *ctx, const char **error_r)
+static int
+dcrypt_gnutls_load_private_key(struct dcrypt_private_key **key_r,
+                              const unsigned char *data, size_t data_len,
+                              dcrypt_password_cb *cb, void *ctx,
+                              const char **error_r)
 {
 
 }
-static
-int dcrypt_gnutls_load_public_key(struct dcrypt_public_key **key_r, const unsigned char *data, size_t data_len, const char **error_r)
+
+static int
+dcrypt_gnutls_load_public_key(struct dcrypt_public_key **key_r,
+                             const unsigned char *data, size_t data_len,
+                             const char **error_r)
 {
 
 }
 
-static
-int dcrypt_gnutls_store_private_key(struct dcrypt_private_key *key, const char *cipher, buffer_t *destination, dcrypt_password_cb *cb, void *ctx, const char **error_r)
+static int
+dcrypt_gnutls_store_private_key(struct dcrypt_private_key *key,
+                               const char *cipher, buffer_t *destination,
+                               dcrypt_password_cb *cb, void *ctx,
+                               const char **error_r)
 {
        gnutls_privkey_t priv = (gnutls_privkey_t)key;
        gnutls_x509_privkey_t xkey;
+       size_t outl = 0;
+
        gnutls_privkey_export_x509(priv, &xkey);
        /* then export PEM */
-       size_t outl = 0;
        gnutls_x509_privkey_export_pkcs8(xkey, GNUTLS_X509_FMT_PEM, NULL, 0, NULL, &outl);
        char buffer[outl];
        gnutls_x509_privkey_export_pkcs8(xkey, GNUTLS_X509_FMT_PEM, NULL, 0, buffer, &outl);
@@ -337,11 +422,12 @@ int dcrypt_gnutls_store_private_key(struct dcrypt_private_key *key, const char *
        return 0;
 }
 
-static
-int dcrypt_gnutls_store_public_key(struct dcrypt_public_key *key, buffer_t *destination, const char **error_r)
+static int
+dcrypt_gnutls_store_public_key(struct dcrypt_public_key *key, buffer_t *destination, const char **error_r)
 {
        gnutls_pubkey_t pub = (gnutls_pubkey_t)key;
        size_t outl = 0;
+
        gnutls_pubkey_export(pub, GNUTLS_X509_FMT_PEM, NULL, &outl);
        char buffer[outl];
        gnutls_pubkey_export(pub, GNUTLS_X509_FMT_PEM, buffer, &outl);
@@ -349,17 +435,22 @@ int dcrypt_gnutls_store_public_key(struct dcrypt_public_key *key, buffer_t *dest
        return 0;
 }
 
-static
-int dcrypt_gnutls_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r)
+static int
+dcrypt_gnutls_private_to_public_key(struct dcrypt_private_key *priv_key,
+                                   struct dcrypt_public_key **pub_key_r,
+                                   const char **error_r)
 {
+       gnutls_privkey_t priv = (gnutls_privkey_t)priv_key;
        int ec;
 
-       gnutls_privkey_t priv = (gnutls_privkey_t)priv_key;
        if (gnutls_privkey_get_pk_algorithm(priv, NULL) == GNUTLS_PK_RSA) {
                gnutls_datum_t m,e;
+
                /* do not extract anything we don't need */
-               ec = gnutls_privkey_export_rsa_raw(priv, &m, &e, NULL, NULL, NULL, NULL, NULL, NULL);
-               if (ec != GNUTLS_E_SUCCESS) return dcrypt_gnutls_error(ec, error_r);
+               ec = gnutls_privkey_export_rsa_raw(priv, &m, &e, NULL, NULL,
+                                                  NULL, NULL, NULL, NULL);
+               if (ec != GNUTLS_E_SUCCESS)
+                       return dcrypt_gnutls_error(ec, error_r);
                gnutls_pubkey_t pub;
                gnutls_pubkey_init(&pub);
                ec = gnutls_pubkey_import_rsa_raw(pub, &m, &e);
@@ -374,8 +465,10 @@ int dcrypt_gnutls_private_to_public_key(struct dcrypt_private_key *priv_key, str
        } else if (gnutls_privkey_get_pk_algorithm(priv, NULL) == GNUTLS_PK_EC) {
                gnutls_ecc_curve_t curve;
                gnutls_datum_t x,y,k;
+
                ec = gnutls_privkey_export_ecc_raw(priv, &curve, &x, &y, NULL);
-               if (ec != GNUTLS_E_SUCCESS) return dcrypt_gnutls_error(ec, error_r);
+               if (ec != GNUTLS_E_SUCCESS)
+                       return dcrypt_gnutls_error(ec, error_r);
                gnutls_pubkey_t pub;
                gnutls_pubkey_init(&pub);
                ec = gnutls_pubkey_import_ecc_raw(pub, curve, &x, &y);
@@ -392,54 +485,65 @@ int dcrypt_gnutls_private_to_public_key(struct dcrypt_private_key *priv_key, str
        return -1;
 }
 
-static
-void dcrypt_gnutls_free_public_key(struct dcrypt_public_key **key)
+static void
+dcrypt_gnutls_free_public_key(struct dcrypt_public_key **key)
 {
        gnutls_pubkey_deinit((gnutls_pubkey_t)*key);
        *key = NULL;
 }
-static
-void dcrypt_gnutls_free_private_key(struct dcrypt_private_key **key)
+
+static void
+dcrypt_gnutls_free_private_key(struct dcrypt_private_key **key)
 {
        gnutls_privkey_deinit((gnutls_privkey_t)*key);
        *key = NULL;
 }
-static
-void dcrypt_gnutls_free_keypair(struct dcrypt_keypair *keypair)
+
+static void
+dcrypt_gnutls_free_keypair(struct dcrypt_keypair *keypair)
 {
        dcrypt_gnutls_free_public_key(&keypair->pub);
        dcrypt_gnutls_free_private_key(&keypair->priv);
 }
 
-static
-int dcrypt_gnutls_rsa_encrypt(struct dcrypt_public_key *key, const unsigned char *data, size_t data_len, buffer_t *result, const char **error_r)
+static int
+dcrypt_gnutls_rsa_encrypt(struct dcrypt_public_key *key,
+                         const unsigned char *data, size_t data_len,
+                         buffer_t *result, const char **error_r)
 {
 
 }
-static
-int dcrypt_gnutls_rsa_decrypt(struct dcrypt_private_key *key, const unsigned char *data, size_t data_len, buffer_t *result, const char **error_r)
+
+static int
+dcrypt_gnutls_rsa_decrypt(struct dcrypt_private_key *key,
+                         const unsigned char *data, size_t data_len,
+                         buffer_t *result, const char **error_r)
 {
 
 }
 
-static
-int dcrypt_gnutls_oid_keytype(const unsigned char *oid, size_t oid_len, enum dcrypt_key_type *key_type, const char **error_r)
+static int
+dcrypt_gnutls_oid_keytype(const unsigned char *oid, size_t oid_len,
+                         enum dcrypt_key_type *key_type, const char **error_r)
 {
 
 }
-static
-int dcrypt_gnutls_keytype_oid(enum dcrypt_key_type key_type, buffer_t *oid, const char **error_r)
+
+static int
+dcrypt_gnutls_keytype_oid(enum dcrypt_key_type key_type, buffer_t *oid,
+                         const char **error_r)
 {
 
 }
 
-static
-const char *dcrypt_gnutls_oid2name(const unsigned char *oid, size_t oid_len, const char **error_r)
+static const char *
+dcrypt_gnutls_oid2name(const unsigned char *oid, size_t oid_len,
+                      const char **error_r)
 {
 }
 
-static
-int dcrypt_gnutls_name2oid(const char *name, buffer_t *oid, const char **error_r)
+static int
+dcrypt_gnutls_name2oid(const char *name, buffer_t *oid, const char **error_r)
 {
 
 }