diff options
author | Simon Josefsson <simon@josefsson.org> | 2010-10-14 15:02:12 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2010-10-14 15:02:12 +0200 |
commit | 03636f4440ae918d6f710935a00806469f65f1c6 (patch) | |
tree | 1969ad6201816d1eb1421d93ef6900ec3b647788 /lib/nettle/mac.c | |
parent | 59425cbec511cdc314f2a22ee95b299f8fa06fc8 (diff) | |
download | gnutls-03636f4440ae918d6f710935a00806469f65f1c6.tar.gz |
Indent (using GNU indent 2.2.11).
Diffstat (limited to 'lib/nettle/mac.c')
-rw-r--r-- | lib/nettle/mac.c | 400 |
1 files changed, 208 insertions, 192 deletions
diff --git a/lib/nettle/mac.c b/lib/nettle/mac.c index 71b9d012cb..a0b3ee098f 100644 --- a/lib/nettle/mac.c +++ b/lib/nettle/mac.c @@ -37,276 +37,292 @@ typedef void (*update_func) (void *, unsigned, const uint8_t *); typedef void (*digest_func) (void *, unsigned, uint8_t *); typedef void (*set_key_func) (void *, unsigned, const uint8_t *); -static int wrap_nettle_hash_init(gnutls_mac_algorithm_t algo, void **_ctx); - -struct nettle_hash_ctx { - union { - struct md5_ctx md5; - struct md2_ctx md2; - struct sha224_ctx sha224; - struct sha256_ctx sha256; - struct sha384_ctx sha384; - struct sha512_ctx sha512; - struct sha1_ctx sha1; - } ctx; - void *ctx_ptr; - gnutls_mac_algorithm_t algo; - size_t length; - update_func update; - digest_func digest; +static int wrap_nettle_hash_init (gnutls_mac_algorithm_t algo, void **_ctx); + +struct nettle_hash_ctx +{ + union + { + struct md5_ctx md5; + struct md2_ctx md2; + struct sha224_ctx sha224; + struct sha256_ctx sha256; + struct sha384_ctx sha384; + struct sha512_ctx sha512; + struct sha1_ctx sha1; + } ctx; + void *ctx_ptr; + gnutls_mac_algorithm_t algo; + size_t length; + update_func update; + digest_func digest; }; -struct nettle_hmac_ctx { - union { - struct hmac_md5_ctx md5; - struct hmac_sha224_ctx sha224; - struct hmac_sha256_ctx sha256; - struct hmac_sha384_ctx sha384; - struct hmac_sha512_ctx sha512; - struct hmac_sha1_ctx sha1; - } ctx; - void *ctx_ptr; - gnutls_mac_algorithm_t algo; - size_t length; - update_func update; - digest_func digest; - set_key_func setkey; +struct nettle_hmac_ctx +{ + union + { + struct hmac_md5_ctx md5; + struct hmac_sha224_ctx sha224; + struct hmac_sha256_ctx sha256; + struct hmac_sha384_ctx sha384; + struct hmac_sha512_ctx sha512; + struct hmac_sha1_ctx sha1; + } ctx; + void *ctx_ptr; + gnutls_mac_algorithm_t algo; + size_t length; + update_func update; + digest_func digest; + set_key_func setkey; }; -static int wrap_nettle_hmac_init(gnutls_mac_algorithm_t algo, void **_ctx) +static int +wrap_nettle_hmac_init (gnutls_mac_algorithm_t algo, void **_ctx) { - struct nettle_hmac_ctx* ctx; + struct nettle_hmac_ctx *ctx; - ctx = gnutls_malloc(sizeof(struct nettle_hmac_ctx)); - if (ctx == NULL) { - gnutls_assert(); - return GNUTLS_E_MEMORY_ERROR; + ctx = gnutls_malloc (sizeof (struct nettle_hmac_ctx)); + if (ctx == NULL) + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; } - ctx->algo = algo; + ctx->algo = algo; - switch (algo) { + switch (algo) + { case GNUTLS_MAC_MD5: - ctx->update = (update_func)hmac_md5_update; - ctx->digest = (digest_func)hmac_md5_digest; - ctx->setkey = (set_key_func)hmac_md5_set_key; - ctx->ctx_ptr = &ctx->ctx.md5; - ctx->length = MD5_DIGEST_SIZE; - break; + ctx->update = (update_func) hmac_md5_update; + ctx->digest = (digest_func) hmac_md5_digest; + ctx->setkey = (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->setkey = (set_key_func)hmac_sha1_set_key; - ctx->ctx_ptr = &ctx->ctx.sha1; - ctx->length = SHA1_DIGEST_SIZE; - break; + ctx->update = (update_func) hmac_sha1_update; + ctx->digest = (digest_func) hmac_sha1_digest; + ctx->setkey = (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->setkey = (set_key_func)hmac_sha224_set_key; - ctx->ctx_ptr = &ctx->ctx.sha224; - ctx->length = SHA224_DIGEST_SIZE; - break; + ctx->update = (update_func) hmac_sha224_update; + ctx->digest = (digest_func) hmac_sha224_digest; + ctx->setkey = (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->setkey = (set_key_func)hmac_sha256_set_key; - ctx->ctx_ptr = &ctx->ctx.sha256; - ctx->length = SHA256_DIGEST_SIZE; - break; + ctx->update = (update_func) hmac_sha256_update; + ctx->digest = (digest_func) hmac_sha256_digest; + ctx->setkey = (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->setkey = (set_key_func)hmac_sha384_set_key; - ctx->ctx_ptr = &ctx->ctx.sha384; - ctx->length = SHA384_DIGEST_SIZE; - break; + ctx->update = (update_func) hmac_sha384_update; + ctx->digest = (digest_func) hmac_sha384_digest; + ctx->setkey = (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->setkey = (set_key_func)hmac_sha512_set_key; - ctx->ctx_ptr = &ctx->ctx.sha512; - ctx->length = SHA512_DIGEST_SIZE; - break; + ctx->update = (update_func) hmac_sha512_update; + ctx->digest = (digest_func) hmac_sha512_digest; + ctx->setkey = (set_key_func) hmac_sha512_set_key; + ctx->ctx_ptr = &ctx->ctx.sha512; + ctx->length = SHA512_DIGEST_SIZE; + break; default: - gnutls_assert(); - return GNUTLS_E_INVALID_REQUEST; + gnutls_assert (); + return GNUTLS_E_INVALID_REQUEST; } - *_ctx = ctx; + *_ctx = ctx; - return 0; + return 0; } -static int wrap_nettle_hmac_setkey(void *_ctx, const void *key, size_t keylen) +static int +wrap_nettle_hmac_setkey (void *_ctx, const void *key, size_t keylen) { - struct nettle_hmac_ctx *ctx = _ctx; - - ctx->setkey(ctx->ctx_ptr, keylen, key); + struct nettle_hmac_ctx *ctx = _ctx; + + ctx->setkey (ctx->ctx_ptr, keylen, key); - return GNUTLS_E_SUCCESS; + return GNUTLS_E_SUCCESS; } static int -wrap_nettle_hmac_update(void *_ctx, const void *text, size_t textsize) +wrap_nettle_hmac_update (void *_ctx, const void *text, size_t textsize) { - struct nettle_hmac_ctx *ctx = _ctx; + struct nettle_hmac_ctx *ctx = _ctx; - ctx->update(ctx->ctx_ptr, textsize, text); + ctx->update (ctx->ctx_ptr, textsize, text); - return GNUTLS_E_SUCCESS; + return GNUTLS_E_SUCCESS; } static int -wrap_nettle_hash_update(void *_ctx, const void *text, size_t textsize) +wrap_nettle_hash_update (void *_ctx, const void *text, size_t textsize) { - struct nettle_hash_ctx *ctx = _ctx; + struct nettle_hash_ctx *ctx = _ctx; - ctx->update(ctx->ctx_ptr, textsize, text); + ctx->update (ctx->ctx_ptr, textsize, text); - return GNUTLS_E_SUCCESS; + return GNUTLS_E_SUCCESS; } -static int wrap_nettle_hash_copy(void **bhd, void *ahd) +static int +wrap_nettle_hash_copy (void **bhd, void *ahd) { - struct nettle_hash_ctx *ctx = ahd; - struct nettle_hash_ctx *dst_ctx; - int ret; - - ret = wrap_nettle_hash_init(ctx->algo, bhd); - if (ret < 0) { - gnutls_assert(); - return ret; - } - - dst_ctx = *bhd; - - memcpy(&dst_ctx->ctx, &ctx->ctx, sizeof(ctx->ctx)); - - return 0; + struct nettle_hash_ctx *ctx = ahd; + struct nettle_hash_ctx *dst_ctx; + int ret; + + ret = wrap_nettle_hash_init (ctx->algo, bhd); + if (ret < 0) + { + gnutls_assert (); + return ret; + } + + dst_ctx = *bhd; + + memcpy (&dst_ctx->ctx, &ctx->ctx, sizeof (ctx->ctx)); + + return 0; } -static void wrap_nettle_md_close(void *hd) +static void +wrap_nettle_md_close (void *hd) { - gnutls_free(hd); + gnutls_free (hd); } -static int wrap_nettle_hash_init(gnutls_mac_algorithm_t algo, void **_ctx) +static int +wrap_nettle_hash_init (gnutls_mac_algorithm_t algo, void **_ctx) { - struct nettle_hash_ctx* ctx; + struct nettle_hash_ctx *ctx; - ctx = gnutls_malloc(sizeof(struct nettle_hash_ctx)); - if (ctx == NULL) { - gnutls_assert(); - return GNUTLS_E_MEMORY_ERROR; + ctx = gnutls_malloc (sizeof (struct nettle_hash_ctx)); + if (ctx == NULL) + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; } - ctx->algo = algo; + ctx->algo = algo; - switch (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->ctx_ptr = &ctx->ctx.md5; - ctx->length = MD5_DIGEST_SIZE; - break; + md5_init (&ctx->ctx.md5); + 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->ctx_ptr = &ctx->ctx.sha1; - ctx->length = SHA1_DIGEST_SIZE; - break; + sha1_init (&ctx->ctx.sha1); + 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_MD2: - md2_init(&ctx->ctx.md2); - ctx->update = (update_func)md2_update; - ctx->digest = (digest_func)md2_digest; - ctx->ctx_ptr = &ctx->ctx.md2; - ctx->length = MD2_DIGEST_SIZE; - break; + md2_init (&ctx->ctx.md2); + ctx->update = (update_func) md2_update; + ctx->digest = (digest_func) md2_digest; + ctx->ctx_ptr = &ctx->ctx.md2; + ctx->length = MD2_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->ctx_ptr = &ctx->ctx.sha224; - ctx->length = SHA224_DIGEST_SIZE; - break; + sha224_init (&ctx->ctx.sha224); + 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->ctx_ptr = &ctx->ctx.sha256; - ctx->length = SHA256_DIGEST_SIZE; - break; + sha256_init (&ctx->ctx.sha256); + 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->ctx_ptr = &ctx->ctx.sha384; - ctx->length = SHA384_DIGEST_SIZE; - break; + sha384_init (&ctx->ctx.sha384); + 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->ctx_ptr = &ctx->ctx.sha512; - ctx->length = SHA512_DIGEST_SIZE; - break; + sha512_init (&ctx->ctx.sha512); + ctx->update = (update_func) sha512_update; + ctx->digest = (digest_func) sha512_digest; + ctx->ctx_ptr = &ctx->ctx.sha512; + ctx->length = SHA512_DIGEST_SIZE; + break; default: - gnutls_assert(); - return GNUTLS_E_INVALID_REQUEST; + gnutls_assert (); + return GNUTLS_E_INVALID_REQUEST; } - - *_ctx = ctx; - return 0; + *_ctx = ctx; + + return 0; } static int -wrap_nettle_hash_output(void *src_ctx, void *digest, size_t digestsize) +wrap_nettle_hash_output (void *src_ctx, void *digest, size_t digestsize) { - struct nettle_hash_ctx *ctx; - ctx = src_ctx; + struct nettle_hash_ctx *ctx; + ctx = src_ctx; - if (digestsize < ctx->length) { - gnutls_assert(); - return GNUTLS_E_SHORT_MEMORY_BUFFER; + if (digestsize < ctx->length) + { + gnutls_assert (); + return GNUTLS_E_SHORT_MEMORY_BUFFER; } - ctx->digest(ctx->ctx_ptr, digestsize, digest); + ctx->digest (ctx->ctx_ptr, digestsize, digest); - return 0; + return 0; } static int -wrap_nettle_hmac_output(void *src_ctx, void *digest, size_t digestsize) +wrap_nettle_hmac_output (void *src_ctx, void *digest, size_t digestsize) { - struct nettle_hmac_ctx *ctx; - ctx = src_ctx; + struct nettle_hmac_ctx *ctx; + ctx = src_ctx; - if (digestsize < ctx->length) { - gnutls_assert(); - return GNUTLS_E_SHORT_MEMORY_BUFFER; + if (digestsize < ctx->length) + { + gnutls_assert (); + return GNUTLS_E_SHORT_MEMORY_BUFFER; } - ctx->digest(ctx->ctx_ptr, digestsize, digest); + ctx->digest (ctx->ctx_ptr, digestsize, digest); - return 0; + return 0; } gnutls_crypto_mac_st _gnutls_mac_ops = { - .init = wrap_nettle_hmac_init, - .setkey = wrap_nettle_hmac_setkey, - .hash = wrap_nettle_hmac_update, - .output = wrap_nettle_hmac_output, - .deinit = wrap_nettle_md_close, + .init = wrap_nettle_hmac_init, + .setkey = wrap_nettle_hmac_setkey, + .hash = wrap_nettle_hmac_update, + .output = wrap_nettle_hmac_output, + .deinit = wrap_nettle_md_close, }; gnutls_crypto_digest_st _gnutls_digest_ops = { - .init = wrap_nettle_hash_init, - .hash = wrap_nettle_hash_update, - .copy = wrap_nettle_hash_copy, - .output = wrap_nettle_hash_output, - .deinit = wrap_nettle_md_close, + .init = wrap_nettle_hash_init, + .hash = wrap_nettle_hash_update, + .copy = wrap_nettle_hash_copy, + .output = wrap_nettle_hash_output, + .deinit = wrap_nettle_md_close, }; |