diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-08-25 00:09:19 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-08-25 00:09:19 +0200 |
commit | f2d84afd9d8373bf2778d1a1635384000c03f887 (patch) | |
tree | 42af8a7430278871e3a1b1e14006099aa50eae80 /src/crypto/mac | |
parent | 9855a34f48acf6ae3aaeba9ec37756da41507e64 (diff) | |
download | fastd-f2d84afd9d8373bf2778d1a1635384000c03f887.tar fastd-f2d84afd9d8373bf2778d1a1635384000c03f887.zip |
MAC: rename hash() to digest() and change length unit from blocks to bytes
Diffstat (limited to 'src/crypto/mac')
4 files changed, 18 insertions, 5 deletions
diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c index 981b588..32ed5e7 100644 --- a/src/crypto/mac/ghash/builtin/ghash_builtin.c +++ b/src/crypto/mac/ghash/builtin/ghash_builtin.c @@ -31,6 +31,7 @@ #include "../../../../crypto.h" +#include "../../../../log.h" /** MAC state used by this GHASH implmentation */ @@ -119,7 +120,12 @@ static fastd_mac_state_t * ghash_init(const uint8_t *key) { } /** Calculates the GHASH of the supplied blocks */ -static bool ghash_hash(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks) { +static bool ghash_digest(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t length) { + if (length % sizeof(fastd_block128_t)) + exit_bug("ghash_digest (builtin): invalid length"); + + size_t n_blocks = length / sizeof(fastd_block128_t); + memset(out, 0, sizeof(fastd_block128_t)); size_t i; @@ -142,6 +148,6 @@ static void ghash_free(fastd_mac_state_t *state) { /** The builtin GHASH implementation */ const fastd_mac_t fastd_mac_ghash_builtin = { .init = ghash_init, - .hash = ghash_hash, + .digest = ghash_digest, .free = ghash_free, }; diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c index 5d5977a..2fe5bca 100644 --- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c +++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c @@ -46,6 +46,6 @@ const fastd_mac_t fastd_mac_ghash_pclmulqdq = { .available = ghash_available, .init = fastd_ghash_pclmulqdq_init, - .hash = fastd_ghash_pclmulqdq_hash, + .digest = fastd_ghash_pclmulqdq_digest, .free = fastd_ghash_pclmulqdq_free, }; diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h index bd10de4..f1a3f52 100644 --- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h +++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h @@ -36,5 +36,5 @@ fastd_mac_state_t * fastd_ghash_pclmulqdq_init(const uint8_t *key); -bool fastd_ghash_pclmulqdq_hash(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks); +bool fastd_ghash_pclmulqdq_digest(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t length); void fastd_ghash_pclmulqdq_free(fastd_mac_state_t *state); diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c index 17e7aa2..6117735 100644 --- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c +++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c @@ -31,6 +31,8 @@ #include "ghash_pclmulqdq.h" +#include "../../../../log.h" + #include <wmmintrin.h> #include <emmintrin.h> #include <tmmintrin.h> @@ -150,7 +152,12 @@ static __m128i gmul(__m128i v, __m128i h) { /** Calculates the GHASH of the supplied input blocks */ -bool fastd_ghash_pclmulqdq_hash(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks) { +bool fastd_ghash_pclmulqdq_digest(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t length) { + if (length % sizeof(fastd_block128_t)) + exit_bug("ghash_digest (pclmulqdq): invalid length"); + + size_t n_blocks = length / sizeof(fastd_block128_t); + vecblock_t v = {.v = _mm_setzero_si128()}; size_t i; |