summaryrefslogtreecommitdiff
path: root/lib/accelerated/x86/hmac-padlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/accelerated/x86/hmac-padlock.c')
-rw-r--r--lib/accelerated/x86/hmac-padlock.c144
1 files changed, 65 insertions, 79 deletions
diff --git a/lib/accelerated/x86/hmac-padlock.c b/lib/accelerated/x86/hmac-padlock.c
index 8913166f34..5dd3f450dc 100644
--- a/lib/accelerated/x86/hmac-padlock.c
+++ b/lib/accelerated/x86/hmac-padlock.c
@@ -37,9 +37,9 @@
#ifdef HAVE_LIBNETTLE
-# define IPAD 0x36
-# define OPAD 0x5c
-# define MAX_SHA_DIGEST_SIZE (512/8)
+#define IPAD 0x36
+#define OPAD 0x5c
+#define MAX_SHA_DIGEST_SIZE (512 / 8)
typedef void (*update_func)(void *, size_t, const uint8_t *);
typedef void (*digest_func)(void *, size_t, uint8_t *);
@@ -62,133 +62,120 @@ struct padlock_hmac_ctx {
set_key_func setkey;
};
-static void
-padlock_hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
- size_t key_length, const uint8_t * key)
+static void padlock_hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
+ size_t key_length, const uint8_t *key)
{
HMAC_SET_KEY(ctx, &padlock_sha1, key_length, key);
}
-static void
-padlock_hmac_sha1_update(struct hmac_sha1_ctx *ctx,
- size_t length, const uint8_t * data)
+static void padlock_hmac_sha1_update(struct hmac_sha1_ctx *ctx, size_t length,
+ const uint8_t *data)
{
padlock_sha1_update(&ctx->state, length, data);
}
-static void
-padlock_hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
- size_t length, uint8_t * digest)
+static void padlock_hmac_sha1_digest(struct hmac_sha1_ctx *ctx, size_t length,
+ uint8_t *digest)
{
HMAC_DIGEST(ctx, &padlock_sha1, length, digest);
}
-static void
-padlock_hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
- size_t key_length, const uint8_t * key)
+static void padlock_hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
+ size_t key_length, const uint8_t *key)
{
HMAC_SET_KEY(ctx, &padlock_sha256, key_length, key);
}
-static void
-padlock_hmac_sha256_update(struct hmac_sha256_ctx *ctx,
- size_t length, const uint8_t * data)
+static void padlock_hmac_sha256_update(struct hmac_sha256_ctx *ctx,
+ size_t length, const uint8_t *data)
{
padlock_sha256_update(&ctx->state, length, data);
}
-static void
-padlock_hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
- size_t length, uint8_t * digest)
+static void padlock_hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
+ size_t length, uint8_t *digest)
{
HMAC_DIGEST(ctx, &padlock_sha256, length, digest);
}
-static void
-padlock_hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
- size_t key_length, const uint8_t * key)
+static void padlock_hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
+ size_t key_length, const uint8_t *key)
{
HMAC_SET_KEY(ctx, &padlock_sha224, key_length, key);
}
-static void
-padlock_hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
- size_t length, uint8_t * digest)
+static void padlock_hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
+ size_t length, uint8_t *digest)
{
HMAC_DIGEST(ctx, &padlock_sha224, length, digest);
}
-static void
-padlock_hmac_sha384_set_key(struct hmac_sha384_ctx *ctx,
- size_t key_length, const uint8_t * key)
+static void padlock_hmac_sha384_set_key(struct hmac_sha384_ctx *ctx,
+ size_t key_length, const uint8_t *key)
{
HMAC_SET_KEY(ctx, &padlock_sha384, key_length, key);
}
-static void
-padlock_hmac_sha384_digest(struct hmac_sha384_ctx *ctx,
- size_t length, uint8_t * digest)
+static void padlock_hmac_sha384_digest(struct hmac_sha384_ctx *ctx,
+ size_t length, uint8_t *digest)
{
HMAC_DIGEST(ctx, &padlock_sha384, length, digest);
}
-static void
-padlock_hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
- size_t key_length, const uint8_t * key)
+static void padlock_hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
+ size_t key_length, const uint8_t *key)
{
HMAC_SET_KEY(ctx, &padlock_sha512, key_length, key);
}
-static void
-padlock_hmac_sha512_update(struct hmac_sha512_ctx *ctx,
- size_t length, const uint8_t * data)
+static void padlock_hmac_sha512_update(struct hmac_sha512_ctx *ctx,
+ size_t length, const uint8_t *data)
{
padlock_sha512_update(&ctx->state, length, data);
}
-static void
-padlock_hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
- size_t length, uint8_t * digest)
+static void padlock_hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
+ size_t length, uint8_t *digest)
{
HMAC_DIGEST(ctx, &padlock_sha512, length, digest);
}
-static int
-_hmac_ctx_init(gnutls_mac_algorithm_t algo, struct padlock_hmac_ctx *ctx)
+static int _hmac_ctx_init(gnutls_mac_algorithm_t algo,
+ struct padlock_hmac_ctx *ctx)
{
switch (algo) {
case GNUTLS_MAC_SHA1:
- ctx->update = (update_func) padlock_hmac_sha1_update;
- ctx->digest = (digest_func) padlock_hmac_sha1_digest;
- ctx->setkey = (set_key_func) padlock_hmac_sha1_set_key;
+ ctx->update = (update_func)padlock_hmac_sha1_update;
+ ctx->digest = (digest_func)padlock_hmac_sha1_digest;
+ ctx->setkey = (set_key_func)padlock_hmac_sha1_set_key;
ctx->ctx_ptr = &ctx->ctx.sha1;
ctx->length = SHA1_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA224:
- ctx->update = (update_func) padlock_hmac_sha256_update;
- ctx->digest = (digest_func) padlock_hmac_sha224_digest;
- ctx->setkey = (set_key_func) padlock_hmac_sha224_set_key;
+ ctx->update = (update_func)padlock_hmac_sha256_update;
+ ctx->digest = (digest_func)padlock_hmac_sha224_digest;
+ ctx->setkey = (set_key_func)padlock_hmac_sha224_set_key;
ctx->ctx_ptr = &ctx->ctx.sha224;
ctx->length = SHA224_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA256:
- ctx->update = (update_func) padlock_hmac_sha256_update;
- ctx->digest = (digest_func) padlock_hmac_sha256_digest;
- ctx->setkey = (set_key_func) padlock_hmac_sha256_set_key;
+ ctx->update = (update_func)padlock_hmac_sha256_update;
+ ctx->digest = (digest_func)padlock_hmac_sha256_digest;
+ ctx->setkey = (set_key_func)padlock_hmac_sha256_set_key;
ctx->ctx_ptr = &ctx->ctx.sha256;
ctx->length = SHA256_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA384:
- ctx->update = (update_func) padlock_hmac_sha512_update;
- ctx->digest = (digest_func) padlock_hmac_sha384_digest;
- ctx->setkey = (set_key_func) padlock_hmac_sha384_set_key;
+ ctx->update = (update_func)padlock_hmac_sha512_update;
+ ctx->digest = (digest_func)padlock_hmac_sha384_digest;
+ ctx->setkey = (set_key_func)padlock_hmac_sha384_set_key;
ctx->ctx_ptr = &ctx->ctx.sha384;
ctx->length = SHA384_DIGEST_SIZE;
break;
case GNUTLS_MAC_SHA512:
- ctx->update = (update_func) padlock_hmac_sha512_update;
- ctx->digest = (digest_func) padlock_hmac_sha512_digest;
- ctx->setkey = (set_key_func) padlock_hmac_sha512_set_key;
+ ctx->update = (update_func)padlock_hmac_sha512_update;
+ ctx->digest = (digest_func)padlock_hmac_sha512_digest;
+ ctx->setkey = (set_key_func)padlock_hmac_sha512_set_key;
ctx->ctx_ptr = &ctx->ctx.sha512;
ctx->length = SHA512_DIGEST_SIZE;
break;
@@ -226,7 +213,7 @@ static void *wrap_padlock_hmac_copy(const void *_ctx)
{
struct padlock_hmac_ctx *new_ctx;
const struct padlock_hmac_ctx *ctx = _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_malloc(sizeof(struct padlock_hmac_ctx));
if (new_ctx == NULL) {
@@ -235,7 +222,7 @@ static void *wrap_padlock_hmac_copy(const void *_ctx)
}
memcpy(new_ctx, ctx, sizeof(*new_ctx));
- new_ctx->ctx_ptr = (uint8_t *) & new_ctx->ctx + off;
+ new_ctx->ctx_ptr = (uint8_t *)&new_ctx->ctx + off;
return new_ctx;
}
@@ -249,8 +236,8 @@ static int wrap_padlock_hmac_setkey(void *_ctx, const void *key, size_t keylen)
return GNUTLS_E_SUCCESS;
}
-static int
-wrap_padlock_hmac_update(void *_ctx, const void *text, size_t textsize)
+static int wrap_padlock_hmac_update(void *_ctx, const void *text,
+ size_t textsize)
{
struct padlock_hmac_ctx *ctx = _ctx;
@@ -259,8 +246,8 @@ wrap_padlock_hmac_update(void *_ctx, const void *text, size_t textsize)
return GNUTLS_E_SUCCESS;
}
-static int
-wrap_padlock_hmac_output(void *src_ctx, void *digest, size_t digestsize)
+static int wrap_padlock_hmac_output(void *src_ctx, void *digest,
+ size_t digestsize)
{
struct padlock_hmac_ctx *ctx;
ctx = src_ctx;
@@ -283,22 +270,22 @@ static void wrap_padlock_hmac_deinit(void *hd)
gnutls_free(ctx);
}
-static int
-wrap_padlock_hmac_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_padlock_hmac_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)
{
if (algo == GNUTLS_MAC_SHA1 || algo == GNUTLS_MAC_SHA256) {
unsigned char *pad;
unsigned char pad2[SHA1_DATA_SIZE + MAX_SHA_DIGEST_SIZE];
unsigned char hkey[MAX_SHA_DIGEST_SIZE];
unsigned int digest_size =
- _gnutls_mac_get_algo_len(mac_to_entry(algo));
+ _gnutls_mac_get_algo_len(mac_to_entry(algo));
if (key_size > SHA1_DATA_SIZE) {
- wrap_padlock_hash_fast((gnutls_digest_algorithm_t)
- algo, key, key_size, hkey);
+ wrap_padlock_hash_fast((gnutls_digest_algorithm_t)algo,
+ key, key_size, hkey);
key = hkey;
key_size = digest_size;
}
@@ -312,8 +299,8 @@ wrap_padlock_hmac_fast(gnutls_mac_algorithm_t algo,
memcpy(&pad[SHA1_DATA_SIZE], text, text_size);
- wrap_padlock_hash_fast((gnutls_digest_algorithm_t) algo,
- pad, text_size + SHA1_DATA_SIZE,
+ wrap_padlock_hash_fast((gnutls_digest_algorithm_t)algo, pad,
+ text_size + SHA1_DATA_SIZE,
&pad2[SHA1_DATA_SIZE]);
zeroize_temp_key(pad, text_size + SHA1_DATA_SIZE);
@@ -322,9 +309,8 @@ wrap_padlock_hmac_fast(gnutls_mac_algorithm_t algo,
memset(pad2, OPAD, SHA1_DATA_SIZE);
memxor(pad2, key, key_size);
- wrap_padlock_hash_fast((gnutls_digest_algorithm_t) algo,
- pad2, digest_size + SHA1_DATA_SIZE,
- digest);
+ wrap_padlock_hash_fast((gnutls_digest_algorithm_t)algo, pad2,
+ digest_size + SHA1_DATA_SIZE, digest);
zeroize_temp_key(pad2, sizeof(pad2));
zeroize_temp_key(hkey, sizeof(hkey));
@@ -370,4 +356,4 @@ const gnutls_crypto_mac_st _gnutls_hmac_sha_padlock = {
.fast = wrap_padlock_hmac_fast,
};
-#endif /* HAVE_LIBNETTLE */
+#endif /* HAVE_LIBNETTLE */