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 | |
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')
-rw-r--r-- | src/crypto.h | 2 | ||||
-rw-r--r-- | src/crypto/mac/ghash/builtin/ghash_builtin.c | 10 | ||||
-rw-r--r-- | src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c | 2 | ||||
-rw-r--r-- | src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h | 2 | ||||
-rw-r--r-- | src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c | 9 | ||||
-rw-r--r-- | src/methods/composed_gmac/composed_gmac.c | 4 | ||||
-rw-r--r-- | src/methods/generic_gmac/generic_gmac.c | 4 |
7 files changed, 23 insertions, 10 deletions
diff --git a/src/crypto.h b/src/crypto.h index f522c21..07b7d46 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -71,7 +71,7 @@ struct fastd_mac { /** Initializes a MAC context with the given key */ fastd_mac_state_t * (*init)(const uint8_t *key); /** Computes the MAC of data blocks */ - bool (*hash)(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks); + bool (*digest)(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t length); /** Frees a MAC context */ void (*free)(fastd_mac_state_t *state); }; 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; diff --git a/src/methods/composed_gmac/composed_gmac.c b/src/methods/composed_gmac/composed_gmac.c index a709c3f..72f5c8b 100644 --- a/src/methods/composed_gmac/composed_gmac.c +++ b/src/methods/composed_gmac/composed_gmac.c @@ -237,7 +237,7 @@ static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state put_size(&outblocks[n_blocks+1], in.len); - ok = session->ghash->hash(session->ghash_state, &tag, outblocks+1, n_blocks+1); + ok = session->ghash->digest(session->ghash_state, &tag, outblocks+1, (n_blocks+1)*sizeof(fastd_block128_t)); } if (!ok) { @@ -298,7 +298,7 @@ static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *ses put_size(&inblocks[n_blocks], in.len-sizeof(fastd_block128_t)); - ok = session->ghash->hash(session->ghash_state, &tag, inblocks+1, n_blocks); + ok = session->ghash->digest(session->ghash_state, &tag, inblocks+1, n_blocks*sizeof(fastd_block128_t)); } if (!ok || memcmp(&tag, &outblocks[0], sizeof(fastd_block128_t)) != 0) { diff --git a/src/methods/generic_gmac/generic_gmac.c b/src/methods/generic_gmac/generic_gmac.c index 5ee8427..30a2f2f 100644 --- a/src/methods/generic_gmac/generic_gmac.c +++ b/src/methods/generic_gmac/generic_gmac.c @@ -203,7 +203,7 @@ static bool method_encrypt(fastd_peer_t *peer UNUSED, fastd_method_session_state put_size(&outblocks[n_blocks], in.len-sizeof(fastd_block128_t)); - ok = session->ghash->hash(session->ghash_state, &tag, outblocks+1, n_blocks); + ok = session->ghash->digest(session->ghash_state, &tag, outblocks+1, n_blocks*sizeof(fastd_block128_t)); } if (!ok) { @@ -258,7 +258,7 @@ static bool method_decrypt(fastd_peer_t *peer, fastd_method_session_state_t *ses put_size(&inblocks[n_blocks], in.len-sizeof(fastd_block128_t)); - ok = session->ghash->hash(session->ghash_state, &tag, inblocks+1, n_blocks); + ok = session->ghash->digest(session->ghash_state, &tag, inblocks+1, n_blocks*sizeof(fastd_block128_t)); } if (!ok || memcmp(&tag, &outblocks[0], sizeof(fastd_block128_t)) != 0) { |