summaryrefslogtreecommitdiff
path: root/lib/nettle/mac.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nettle/mac.c')
-rw-r--r--lib/nettle/mac.c270
1 files changed, 132 insertions, 138 deletions
diff --git a/lib/nettle/mac.c b/lib/nettle/mac.c
index 5435f2e31f..a9294df33f 100644
--- a/lib/nettle/mac.c
+++ b/lib/nettle/mac.c
@@ -36,11 +36,11 @@
#include <nettle/pbkdf2.h>
#include <nettle/cmac.h>
#if ENABLE_GOST
-# include "gost/hmac-gost.h"
-# ifndef HAVE_NETTLE_GOST28147_SET_KEY
-# include "gost/gost28147.h"
-# endif
-# include "gost/cmac.h"
+#include "gost/hmac-gost.h"
+#ifndef HAVE_NETTLE_GOST28147_SET_KEY
+#include "gost/gost28147.h"
+#endif
+#include "gost/cmac.h"
#endif
#include <nettle/gcm.h>
@@ -129,55 +129,55 @@ struct nettle_mac_ctx {
};
#if ENABLE_GOST
-static void
-_wrap_gost28147_imit_set_key_tc26z(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_gost28147_imit_set_key_tc26z(void *ctx, size_t len,
+ const uint8_t *key)
{
gost28147_imit_set_param(ctx, &gost28147_param_TC26_Z);
gost28147_imit_set_key(ctx, len, key);
}
-static void _wrap_cmac_magma_set_key(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_cmac_magma_set_key(void *ctx, size_t len, const uint8_t *key)
{
cmac_magma_set_key(ctx, key);
}
-static void
-_wrap_cmac_kuznyechik_set_key(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_cmac_kuznyechik_set_key(void *ctx, size_t len,
+ const uint8_t *key)
{
cmac_kuznyechik_set_key(ctx, key);
}
#endif
-static void _wrap_umac96_set_key(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_umac96_set_key(void *ctx, size_t len, const uint8_t *key)
{
if (unlikely(len != 16))
abort();
umac96_set_key(ctx, key);
}
-static void _wrap_umac128_set_key(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_umac128_set_key(void *ctx, size_t len, const uint8_t *key)
{
if (unlikely(len != 16))
abort();
umac128_set_key(ctx, key);
}
-static void _wrap_cmac128_set_key(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_cmac128_set_key(void *ctx, size_t len, const uint8_t *key)
{
if (unlikely(len != 16))
abort();
cmac_aes128_set_key(ctx, key);
}
-static void _wrap_cmac256_set_key(void *ctx, size_t len, const uint8_t * key)
+static void _wrap_cmac256_set_key(void *ctx, size_t len, const uint8_t *key)
{
if (unlikely(len != 32))
abort();
cmac_aes256_set_key(ctx, key);
}
-static void
-_wrap_gmac_aes128_set_key(void *_ctx, size_t len, const uint8_t * key)
+static void _wrap_gmac_aes128_set_key(void *_ctx, size_t len,
+ const uint8_t *key)
{
struct gmac_ctx *ctx = _ctx;
@@ -188,8 +188,8 @@ _wrap_gmac_aes128_set_key(void *_ctx, size_t len, const uint8_t * key)
ctx->pos = 0;
}
-static void
-_wrap_gmac_aes192_set_key(void *_ctx, size_t len, const uint8_t * key)
+static void _wrap_gmac_aes192_set_key(void *_ctx, size_t len,
+ const uint8_t *key)
{
struct gmac_ctx *ctx = _ctx;
@@ -200,8 +200,8 @@ _wrap_gmac_aes192_set_key(void *_ctx, size_t len, const uint8_t * key)
ctx->pos = 0;
}
-static void
-_wrap_gmac_aes256_set_key(void *_ctx, size_t len, const uint8_t * key)
+static void _wrap_gmac_aes256_set_key(void *_ctx, size_t len,
+ const uint8_t *key)
{
struct gmac_ctx *ctx = _ctx;
@@ -213,14 +213,14 @@ _wrap_gmac_aes256_set_key(void *_ctx, size_t len, const uint8_t * key)
}
static void _wrap_gmac_set_nonce(void *_ctx, size_t nonce_length,
- const uint8_t * nonce)
+ const uint8_t *nonce)
{
struct gmac_ctx *ctx = _ctx;
gcm_set_iv(&ctx->ctx, &ctx->key, nonce_length, nonce);
}
-static void _wrap_gmac_update(void *_ctx, size_t length, const uint8_t * data)
+static void _wrap_gmac_update(void *_ctx, size_t length, const uint8_t *data)
{
struct gmac_ctx *ctx = _ctx;
@@ -248,7 +248,7 @@ static void _wrap_gmac_update(void *_ctx, size_t length, const uint8_t * data)
ctx->pos = length;
}
-static void _wrap_gmac_digest(void *_ctx, size_t length, uint8_t * digest)
+static void _wrap_gmac_digest(void *_ctx, size_t length, uint8_t *digest)
{
struct gmac_ctx *ctx = _ctx;
@@ -268,117 +268,117 @@ static int _mac_ctx_init(gnutls_mac_algorithm_t algo,
ctx->set_nonce = NULL;
switch (algo) {
case GNUTLS_MAC_MD5:
- ctx->update = (update_func) hmac_md5_update;
- ctx->digest = (digest_func) hmac_md5_digest;
- ctx->set_key = (set_key_func) hmac_md5_set_key;
+ ctx->update = (update_func)hmac_md5_update;
+ ctx->digest = (digest_func)hmac_md5_digest;
+ ctx->set_key = (set_key_func)hmac_md5_set_key;
ctx->ctx_ptr = &ctx->ctx.md5;
ctx->length = MD5_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA1:
- ctx->update = (update_func) hmac_sha1_update;
- ctx->digest = (digest_func) hmac_sha1_digest;
- ctx->set_key = (set_key_func) hmac_sha1_set_key;
+ ctx->update = (update_func)hmac_sha1_update;
+ ctx->digest = (digest_func)hmac_sha1_digest;
+ ctx->set_key = (set_key_func)hmac_sha1_set_key;
ctx->ctx_ptr = &ctx->ctx.sha1;
ctx->length = SHA1_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA224:
- ctx->update = (update_func) hmac_sha224_update;
- ctx->digest = (digest_func) hmac_sha224_digest;
- ctx->set_key = (set_key_func) hmac_sha224_set_key;
+ ctx->update = (update_func)hmac_sha224_update;
+ ctx->digest = (digest_func)hmac_sha224_digest;
+ ctx->set_key = (set_key_func)hmac_sha224_set_key;
ctx->ctx_ptr = &ctx->ctx.sha224;
ctx->length = SHA224_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA256:
- ctx->update = (update_func) hmac_sha256_update;
- ctx->digest = (digest_func) hmac_sha256_digest;
- ctx->set_key = (set_key_func) hmac_sha256_set_key;
+ ctx->update = (update_func)hmac_sha256_update;
+ ctx->digest = (digest_func)hmac_sha256_digest;
+ ctx->set_key = (set_key_func)hmac_sha256_set_key;
ctx->ctx_ptr = &ctx->ctx.sha256;
ctx->length = SHA256_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA384:
- ctx->update = (update_func) hmac_sha384_update;
- ctx->digest = (digest_func) hmac_sha384_digest;
- ctx->set_key = (set_key_func) hmac_sha384_set_key;
+ ctx->update = (update_func)hmac_sha384_update;
+ ctx->digest = (digest_func)hmac_sha384_digest;
+ ctx->set_key = (set_key_func)hmac_sha384_set_key;
ctx->ctx_ptr = &ctx->ctx.sha384;
ctx->length = SHA384_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA512:
- ctx->update = (update_func) hmac_sha512_update;
- ctx->digest = (digest_func) hmac_sha512_digest;
- ctx->set_key = (set_key_func) hmac_sha512_set_key;
+ ctx->update = (update_func)hmac_sha512_update;
+ ctx->digest = (digest_func)hmac_sha512_digest;
+ ctx->set_key = (set_key_func)hmac_sha512_set_key;
ctx->ctx_ptr = &ctx->ctx.sha512;
ctx->length = SHA512_DIGEST_SIZE;
break;
#if ENABLE_GOST
case GNUTLS_MAC_GOSTR_94:
- ctx->update = (update_func) hmac_gosthash94cp_update;
- ctx->digest = (digest_func) hmac_gosthash94cp_digest;
- ctx->set_key = (set_key_func) hmac_gosthash94cp_set_key;
+ ctx->update = (update_func)hmac_gosthash94cp_update;
+ ctx->digest = (digest_func)hmac_gosthash94cp_digest;
+ ctx->set_key = (set_key_func)hmac_gosthash94cp_set_key;
ctx->ctx_ptr = &ctx->ctx.gosthash94cp;
ctx->length = GOSTHASH94CP_DIGEST_SIZE;
break;
case GNUTLS_MAC_STREEBOG_256:
- ctx->update = (update_func) hmac_streebog256_update;
- ctx->digest = (digest_func) hmac_streebog256_digest;
- ctx->set_key = (set_key_func) hmac_streebog256_set_key;
+ ctx->update = (update_func)hmac_streebog256_update;
+ ctx->digest = (digest_func)hmac_streebog256_digest;
+ ctx->set_key = (set_key_func)hmac_streebog256_set_key;
ctx->ctx_ptr = &ctx->ctx.streebog256;
ctx->length = STREEBOG256_DIGEST_SIZE;
break;
case GNUTLS_MAC_STREEBOG_512:
- ctx->update = (update_func) hmac_streebog512_update;
- ctx->digest = (digest_func) hmac_streebog512_digest;
- ctx->set_key = (set_key_func) hmac_streebog512_set_key;
+ ctx->update = (update_func)hmac_streebog512_update;
+ ctx->digest = (digest_func)hmac_streebog512_digest;
+ ctx->set_key = (set_key_func)hmac_streebog512_set_key;
ctx->ctx_ptr = &ctx->ctx.streebog512;
ctx->length = STREEBOG512_DIGEST_SIZE;
break;
case GNUTLS_MAC_GOST28147_TC26Z_IMIT:
- ctx->update = (update_func) gost28147_imit_update;
- ctx->digest = (digest_func) gost28147_imit_digest;
+ ctx->update = (update_func)gost28147_imit_update;
+ ctx->digest = (digest_func)gost28147_imit_digest;
ctx->set_key = _wrap_gost28147_imit_set_key_tc26z;
ctx->ctx_ptr = &ctx->ctx.gost28147_imit;
ctx->length = GOST28147_IMIT_DIGEST_SIZE;
break;
case GNUTLS_MAC_MAGMA_OMAC:
- ctx->update = (update_func) cmac_magma_update;
- ctx->digest = (digest_func) cmac_magma_digest;
+ ctx->update = (update_func)cmac_magma_update;
+ ctx->digest = (digest_func)cmac_magma_digest;
ctx->set_key = _wrap_cmac_magma_set_key;
ctx->ctx_ptr = &ctx->ctx.magma;
ctx->length = CMAC64_DIGEST_SIZE;
break;
case GNUTLS_MAC_KUZNYECHIK_OMAC:
- ctx->update = (update_func) cmac_kuznyechik_update;
- ctx->digest = (digest_func) cmac_kuznyechik_digest;
+ ctx->update = (update_func)cmac_kuznyechik_update;
+ ctx->digest = (digest_func)cmac_kuznyechik_digest;
ctx->set_key = _wrap_cmac_kuznyechik_set_key;
ctx->ctx_ptr = &ctx->ctx.kuznyechik;
ctx->length = CMAC128_DIGEST_SIZE;
break;
#endif
case GNUTLS_MAC_UMAC_96:
- ctx->update = (update_func) umac96_update;
- ctx->digest = (digest_func) umac96_digest;
+ ctx->update = (update_func)umac96_update;
+ ctx->digest = (digest_func)umac96_digest;
ctx->set_key = _wrap_umac96_set_key;
- ctx->set_nonce = (set_nonce_func) umac96_set_nonce;
+ ctx->set_nonce = (set_nonce_func)umac96_set_nonce;
ctx->ctx_ptr = &ctx->ctx.umac96;
ctx->length = 12;
break;
case GNUTLS_MAC_UMAC_128:
- ctx->update = (update_func) umac128_update;
- ctx->digest = (digest_func) umac128_digest;
+ ctx->update = (update_func)umac128_update;
+ ctx->digest = (digest_func)umac128_digest;
ctx->set_key = _wrap_umac128_set_key;
- ctx->set_nonce = (set_nonce_func) umac128_set_nonce;
+ ctx->set_nonce = (set_nonce_func)umac128_set_nonce;
ctx->ctx_ptr = &ctx->ctx.umac128;
ctx->length = 16;
break;
case GNUTLS_MAC_AES_CMAC_128:
- ctx->update = (update_func) cmac_aes128_update;
- ctx->digest = (digest_func) cmac_aes128_digest;
+ ctx->update = (update_func)cmac_aes128_update;
+ ctx->digest = (digest_func)cmac_aes128_digest;
ctx->set_key = _wrap_cmac128_set_key;
ctx->ctx_ptr = &ctx->ctx.cmac128;
ctx->length = CMAC128_DIGEST_SIZE;
break;
case GNUTLS_MAC_AES_CMAC_256:
- ctx->update = (update_func) cmac_aes256_update;
- ctx->digest = (digest_func) cmac_aes256_digest;
+ ctx->update = (update_func)cmac_aes256_update;
+ ctx->digest = (digest_func)cmac_aes256_digest;
ctx->set_key = _wrap_cmac256_set_key;
ctx->ctx_ptr = &ctx->ctx.cmac256;
ctx->length = CMAC128_DIGEST_SIZE;
@@ -390,7 +390,7 @@ static int _mac_ctx_init(gnutls_mac_algorithm_t algo,
ctx->digest = _wrap_gmac_digest;
ctx->ctx_ptr = &ctx->ctx.gmac;
ctx->length = GCM_DIGEST_SIZE;
- ctx->ctx.gmac.encrypt = (nettle_cipher_func *) aes128_encrypt;
+ ctx->ctx.gmac.encrypt = (nettle_cipher_func *)aes128_encrypt;
break;
case GNUTLS_MAC_AES_GMAC_192:
ctx->set_key = _wrap_gmac_aes192_set_key;
@@ -399,7 +399,7 @@ static int _mac_ctx_init(gnutls_mac_algorithm_t algo,
ctx->digest = _wrap_gmac_digest;
ctx->ctx_ptr = &ctx->ctx.gmac;
ctx->length = GCM_DIGEST_SIZE;
- ctx->ctx.gmac.encrypt = (nettle_cipher_func *) aes192_encrypt;
+ ctx->ctx.gmac.encrypt = (nettle_cipher_func *)aes192_encrypt;
break;
case GNUTLS_MAC_AES_GMAC_256:
ctx->set_key = _wrap_gmac_aes256_set_key;
@@ -408,7 +408,7 @@ static int _mac_ctx_init(gnutls_mac_algorithm_t algo,
ctx->digest = _wrap_gmac_digest;
ctx->ctx_ptr = &ctx->ctx.gmac;
ctx->length = GCM_DIGEST_SIZE;
- ctx->ctx.gmac.encrypt = (nettle_cipher_func *) aes256_encrypt;
+ ctx->ctx.gmac.encrypt = (nettle_cipher_func *)aes256_encrypt;
break;
default:
gnutls_assert();
@@ -418,11 +418,10 @@ static int _mac_ctx_init(gnutls_mac_algorithm_t algo,
return 0;
}
-static int wrap_nettle_mac_fast(gnutls_mac_algorithm_t algo,
- const void *nonce, size_t nonce_size,
- const void *key, size_t key_size,
- const void *text, size_t text_size,
- void *digest)
+static int wrap_nettle_mac_fast(gnutls_mac_algorithm_t algo, const void *nonce,
+ size_t nonce_size, const void *key,
+ size_t key_size, const void *text,
+ size_t text_size, void *digest)
{
struct nettle_mac_ctx ctx;
int ret;
@@ -504,14 +503,14 @@ static void *wrap_nettle_mac_copy(const void *_ctx)
{
const struct nettle_mac_ctx *ctx = _ctx;
struct nettle_mac_ctx *new_ctx;
- ptrdiff_t off = (uint8_t *) ctx->ctx_ptr - (uint8_t *) (&ctx->ctx);
+ ptrdiff_t off = (uint8_t *)ctx->ctx_ptr - (uint8_t *)(&ctx->ctx);
new_ctx = gnutls_calloc(1, sizeof(struct nettle_mac_ctx));
if (new_ctx == NULL)
return NULL;
memcpy(new_ctx, ctx, sizeof(*ctx));
- new_ctx->ctx_ptr = (uint8_t *) & new_ctx->ctx + off;
+ new_ctx->ctx_ptr = (uint8_t *)&new_ctx->ctx + off;
return new_ctx;
}
@@ -524,8 +523,8 @@ static int wrap_nettle_mac_set_key(void *_ctx, const void *key, size_t keylen)
return 0;
}
-static int
-wrap_nettle_mac_set_nonce(void *_ctx, const void *nonce, size_t noncelen)
+static int wrap_nettle_mac_set_nonce(void *_ctx, const void *nonce,
+ size_t noncelen)
{
struct nettle_mac_ctx *ctx = _ctx;
@@ -549,8 +548,8 @@ static int wrap_nettle_mac_update(void *_ctx, const void *text, size_t textsize)
return GNUTLS_E_SUCCESS;
}
-static int
-wrap_nettle_mac_output(void *src_ctx, void *digest, size_t digestsize)
+static int wrap_nettle_mac_output(void *src_ctx, void *digest,
+ size_t digestsize)
{
struct nettle_mac_ctx *ctx;
ctx = src_ctx;
@@ -575,8 +574,8 @@ static void wrap_nettle_mac_deinit(void *hd)
/* Hash functions
*/
-static int
-wrap_nettle_hash_update(void *_ctx, const void *text, size_t textsize)
+static int wrap_nettle_hash_update(void *_ctx, const void *text,
+ size_t textsize)
{
struct nettle_hash_ctx *ctx = _ctx;
@@ -626,7 +625,7 @@ static int wrap_nettle_hash_exists(gnutls_digest_algorithm_t algo)
}
}
-static void _md5_sha1_update(void *_ctx, size_t len, const uint8_t * data)
+static void _md5_sha1_update(void *_ctx, size_t len, const uint8_t *data)
{
struct md5_sha1_ctx *ctx = _ctx;
@@ -634,7 +633,7 @@ static void _md5_sha1_update(void *_ctx, size_t len, const uint8_t * data)
sha1_update(&ctx->sha1, len, data);
}
-static void _md5_sha1_digest(void *_ctx, size_t len, uint8_t * digest)
+static void _md5_sha1_digest(void *_ctx, size_t len, uint8_t *digest)
{
struct md5_sha1_ctx *ctx = _ctx;
@@ -654,110 +653,110 @@ static int _ctx_init(gnutls_digest_algorithm_t algo,
switch (algo) {
case GNUTLS_DIG_MD5:
md5_init(&ctx->ctx.md5);
- ctx->update = (update_func) md5_update;
- ctx->digest = (digest_func) md5_digest;
+ ctx->update = (update_func)md5_update;
+ ctx->digest = (digest_func)md5_digest;
ctx->ctx_ptr = &ctx->ctx.md5;
ctx->length = MD5_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA1:
sha1_init(&ctx->ctx.sha1);
- ctx->update = (update_func) sha1_update;
- ctx->digest = (digest_func) sha1_digest;
+ ctx->update = (update_func)sha1_update;
+ ctx->digest = (digest_func)sha1_digest;
ctx->ctx_ptr = &ctx->ctx.sha1;
ctx->length = SHA1_DIGEST_SIZE;
break;
case GNUTLS_DIG_MD5_SHA1:
md5_init(&ctx->ctx.md5_sha1.md5);
sha1_init(&ctx->ctx.md5_sha1.sha1);
- ctx->update = (update_func) _md5_sha1_update;
- ctx->digest = (digest_func) _md5_sha1_digest;
+ ctx->update = (update_func)_md5_sha1_update;
+ ctx->digest = (digest_func)_md5_sha1_digest;
ctx->ctx_ptr = &ctx->ctx.md5_sha1;
ctx->length = MD5_DIGEST_SIZE + SHA1_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA224:
sha224_init(&ctx->ctx.sha224);
- ctx->update = (update_func) sha224_update;
- ctx->digest = (digest_func) sha224_digest;
+ ctx->update = (update_func)sha224_update;
+ ctx->digest = (digest_func)sha224_digest;
ctx->ctx_ptr = &ctx->ctx.sha224;
ctx->length = SHA224_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA256:
sha256_init(&ctx->ctx.sha256);
- ctx->update = (update_func) sha256_update;
- ctx->digest = (digest_func) sha256_digest;
+ ctx->update = (update_func)sha256_update;
+ ctx->digest = (digest_func)sha256_digest;
ctx->ctx_ptr = &ctx->ctx.sha256;
ctx->length = SHA256_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA384:
sha384_init(&ctx->ctx.sha384);
- ctx->update = (update_func) sha384_update;
- ctx->digest = (digest_func) sha384_digest;
+ ctx->update = (update_func)sha384_update;
+ ctx->digest = (digest_func)sha384_digest;
ctx->ctx_ptr = &ctx->ctx.sha384;
ctx->length = SHA384_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA512:
sha512_init(&ctx->ctx.sha512);
- ctx->update = (update_func) sha512_update;
- ctx->digest = (digest_func) sha512_digest;
+ ctx->update = (update_func)sha512_update;
+ ctx->digest = (digest_func)sha512_digest;
ctx->ctx_ptr = &ctx->ctx.sha512;
ctx->length = SHA512_DIGEST_SIZE;
break;
#ifdef NETTLE_SHA3_FIPS202
case GNUTLS_DIG_SHA3_224:
sha3_224_init(&ctx->ctx.sha3_224);
- ctx->update = (update_func) sha3_224_update;
- ctx->digest = (digest_func) sha3_224_digest;
+ ctx->update = (update_func)sha3_224_update;
+ ctx->digest = (digest_func)sha3_224_digest;
ctx->ctx_ptr = &ctx->ctx.sha3_224;
ctx->length = SHA3_224_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA3_256:
sha3_256_init(&ctx->ctx.sha3_256);
- ctx->update = (update_func) sha3_256_update;
- ctx->digest = (digest_func) sha3_256_digest;
+ ctx->update = (update_func)sha3_256_update;
+ ctx->digest = (digest_func)sha3_256_digest;
ctx->ctx_ptr = &ctx->ctx.sha3_256;
ctx->length = SHA3_256_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA3_384:
sha3_384_init(&ctx->ctx.sha3_384);
- ctx->update = (update_func) sha3_384_update;
- ctx->digest = (digest_func) sha3_384_digest;
+ ctx->update = (update_func)sha3_384_update;
+ ctx->digest = (digest_func)sha3_384_digest;
ctx->ctx_ptr = &ctx->ctx.sha3_384;
ctx->length = SHA3_384_DIGEST_SIZE;
break;
case GNUTLS_DIG_SHA3_512:
sha3_512_init(&ctx->ctx.sha3_512);
- ctx->update = (update_func) sha3_512_update;
- ctx->digest = (digest_func) sha3_512_digest;
+ ctx->update = (update_func)sha3_512_update;
+ ctx->digest = (digest_func)sha3_512_digest;
ctx->ctx_ptr = &ctx->ctx.sha3_512;
ctx->length = SHA3_512_DIGEST_SIZE;
break;
#endif
case GNUTLS_DIG_MD2:
md2_init(&ctx->ctx.md2);
- ctx->update = (update_func) md2_update;
- ctx->digest = (digest_func) md2_digest;
+ ctx->update = (update_func)md2_update;
+ ctx->digest = (digest_func)md2_digest;
ctx->ctx_ptr = &ctx->ctx.md2;
ctx->length = MD2_DIGEST_SIZE;
break;
#if ENABLE_GOST
case GNUTLS_DIG_GOSTR_94:
gosthash94cp_init(&ctx->ctx.gosthash94cp);
- ctx->update = (update_func) gosthash94cp_update;
- ctx->digest = (digest_func) gosthash94cp_digest;
+ ctx->update = (update_func)gosthash94cp_update;
+ ctx->digest = (digest_func)gosthash94cp_digest;
ctx->ctx_ptr = &ctx->ctx.gosthash94cp;
ctx->length = GOSTHASH94_DIGEST_SIZE;
break;
case GNUTLS_DIG_STREEBOG_256:
streebog256_init(&ctx->ctx.streebog256);
- ctx->update = (update_func) streebog256_update;
- ctx->digest = (digest_func) streebog256_digest;
+ ctx->update = (update_func)streebog256_update;
+ ctx->digest = (digest_func)streebog256_digest;
ctx->ctx_ptr = &ctx->ctx.streebog256;
ctx->length = STREEBOG256_DIGEST_SIZE;
break;
case GNUTLS_DIG_STREEBOG_512:
streebog512_init(&ctx->ctx.streebog512);
- ctx->update = (update_func) streebog512_update;
- ctx->digest = (digest_func) streebog512_digest;
+ ctx->update = (update_func)streebog512_update;
+ ctx->digest = (digest_func)streebog512_digest;
ctx->ctx_ptr = &ctx->ctx.streebog512;
ctx->length = STREEBOG512_DIGEST_SIZE;
break;
@@ -818,20 +817,20 @@ static void *wrap_nettle_hash_copy(const void *_ctx)
{
const struct nettle_hash_ctx *ctx = _ctx;
struct nettle_hash_ctx *new_ctx;
- ptrdiff_t off = (uint8_t *) ctx->ctx_ptr - (uint8_t *) (&ctx->ctx);
+ ptrdiff_t off = (uint8_t *)ctx->ctx_ptr - (uint8_t *)(&ctx->ctx);
new_ctx = gnutls_calloc(1, sizeof(struct nettle_hash_ctx));
if (new_ctx == NULL)
return NULL;
memcpy(new_ctx, ctx, sizeof(*ctx));
- new_ctx->ctx_ptr = (uint8_t *) & new_ctx->ctx + off;
+ new_ctx->ctx_ptr = (uint8_t *)&new_ctx->ctx + off;
return new_ctx;
}
-static int
-wrap_nettle_hash_output(void *src_ctx, void *digest, size_t digestsize)
+static int wrap_nettle_hash_output(void *src_ctx, void *digest,
+ size_t digestsize)
{
struct nettle_hash_ctx *ctx;
ctx = src_ctx;
@@ -848,10 +847,9 @@ wrap_nettle_hash_output(void *src_ctx, void *digest, size_t digestsize)
/* KDF functions based on MAC
*/
-static int
-wrap_nettle_hkdf_extract(gnutls_mac_algorithm_t mac,
- const void *key, size_t keysize,
- const void *salt, size_t saltsize, void *output)
+static int wrap_nettle_hkdf_extract(gnutls_mac_algorithm_t mac, const void *key,
+ size_t keysize, const void *salt,
+ size_t saltsize, void *output)
{
struct nettle_mac_ctx ctx;
int ret;
@@ -861,18 +859,16 @@ wrap_nettle_hkdf_extract(gnutls_mac_algorithm_t mac,
return gnutls_assert_val(ret);
ctx.set_key(&ctx, saltsize, salt);
- hkdf_extract(&ctx.ctx, ctx.update, ctx.digest, ctx.length,
- keysize, key, output);
+ hkdf_extract(&ctx.ctx, ctx.update, ctx.digest, ctx.length, keysize, key,
+ output);
zeroize_temp_key(&ctx, sizeof(ctx));
return 0;
}
-static int
-wrap_nettle_hkdf_expand(gnutls_mac_algorithm_t mac,
- const void *key, size_t keysize,
- const void *info, size_t infosize,
- void *output, size_t length)
+static int wrap_nettle_hkdf_expand(gnutls_mac_algorithm_t mac, const void *key,
+ size_t keysize, const void *info,
+ size_t infosize, void *output, size_t length)
{
struct nettle_mac_ctx ctx;
int ret;
@@ -887,18 +883,16 @@ wrap_nettle_hkdf_expand(gnutls_mac_algorithm_t mac,
}
ctx.set_key(&ctx, keysize, key);
- hkdf_expand(&ctx.ctx, ctx.update, ctx.digest, ctx.length,
- infosize, info, length, output);
+ hkdf_expand(&ctx.ctx, ctx.update, ctx.digest, ctx.length, infosize,
+ info, length, output);
zeroize_temp_key(&ctx, sizeof(ctx));
return 0;
}
-static int
-wrap_nettle_pbkdf2(gnutls_mac_algorithm_t mac,
- const void *key, size_t keysize,
- const void *salt, size_t saltsize,
- unsigned iter_count, void *output, size_t length)
+static int wrap_nettle_pbkdf2(gnutls_mac_algorithm_t mac, const void *key,
+ size_t keysize, const void *salt, size_t saltsize,
+ unsigned iter_count, void *output, size_t length)
{
struct nettle_mac_ctx ctx;
int ret;
@@ -908,8 +902,8 @@ wrap_nettle_pbkdf2(gnutls_mac_algorithm_t mac,
return gnutls_assert_val(ret);
ctx.set_key(&ctx, keysize, key);
- pbkdf2(&ctx.ctx, ctx.update, ctx.digest, ctx.length,
- iter_count, saltsize, salt, length, output);
+ pbkdf2(&ctx.ctx, ctx.update, ctx.digest, ctx.length, iter_count,
+ saltsize, salt, length, output);
zeroize_temp_key(&ctx, sizeof(ctx));
return 0;