diff options
author | Niels Möller <nisse@lysator.liu.se> | 2022-02-09 19:14:17 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2022-02-09 19:14:17 +0100 |
commit | 4335a676c3a06e862d78a2ce2e7f4ec786f2ecef (patch) | |
tree | 641184a284efc96052daca1b1f9cf7f50a81a56c | |
parent | 66f4c372b15a081747d03ee6edc586914ff3d25d (diff) | |
download | nettle-4335a676c3a06e862d78a2ce2e7f4ec786f2ecef.tar.gz |
Define _gcm_hash alias in gcm-internal.h
-rw-r--r-- | gcm-internal.h | 35 | ||||
-rw-r--r-- | gcm.c | 30 | ||||
-rw-r--r-- | testsuite/gcm-test.c | 2 |
3 files changed, 35 insertions, 32 deletions
diff --git a/gcm-internal.h b/gcm-internal.h index d90a0f9f..a2f6ded3 100644 --- a/gcm-internal.h +++ b/gcm-internal.h @@ -32,6 +32,26 @@ #ifndef NETTLE_GCM_INTERNAL_H_INCLUDED #define NETTLE_GCM_INTERNAL_H_INCLUDED +#if GCM_TABLE_BITS != 8 +/* The native implementations (currently ppc64 only) depend on the + GCM_TABLE_BITS == 8 layout */ +#undef HAVE_NATIVE_gcm_hash +#undef HAVE_NATIVE_gcm_init_key +#undef HAVE_NATIVE_fat_gcm_hash +#undef HAVE_NATIVE_fat_gcm_init_key +#endif + +/* Arrange so that _gcm_hash is an alias for the right implementation. */ + +#if HAVE_NATIVE_gcm_hash +# define _gcm_hash _nettle_gcm_hash +#elif GCM_TABLE_BITS == 8 && HAVE_NATIVE_gcm_hash8 +# define _gcm_hash _nettle_gcm_hash8 +#elif !HAVE_NATIVE_fat_gcm_hash +# define _gcm_hash _nettle_gcm_hash_c +#endif + +/* Declare all variants, if defined depends on configuration. */ void _nettle_gcm_set_key (struct gcm_key *gcm, const uint8_t *key); @@ -39,7 +59,14 @@ void _nettle_gcm_hash(const struct gcm_key *key, union nettle_block16 *x, size_t length, const uint8_t *data); -/* Functions available only in some configurations */ +void +_nettle_gcm_hash8(const struct gcm_key *key, union nettle_block16 *x, + size_t length, const uint8_t *data); + +void +_nettle_gcm_hash_c(const struct gcm_key *key, union nettle_block16 *x, + size_t length, const uint8_t *data); + void _nettle_gcm_init_key (union nettle_block16 *table); @@ -48,10 +75,4 @@ void _nettle_gcm_init_key_c (union nettle_block16 *table); #endif -#if HAVE_NATIVE_fat_gcm_hash -void -_nettle_gcm_hash_c (const struct gcm_key *key, union nettle_block16 *x, - size_t length, const uint8_t *data); -#endif - #endif /* NETTLE_GCM_INTERNAL_H_INCLUDED */ @@ -56,15 +56,6 @@ #include "ctr-internal.h" #include "block-internal.h" -#if GCM_TABLE_BITS != 8 -/* The native implementations (currently ppc64 only) depend on the - GCM_TABLE_BITS == 8 layout */ -#undef HAVE_NATIVE_gcm_hash -#undef HAVE_NATIVE_gcm_init_key -#undef HAVE_NATIVE_fat_gcm_hash -#undef HAVE_NATIVE_fat_gcm_init_key -#endif - #if !HAVE_NATIVE_gcm_hash # if GCM_TABLE_BITS == 0 /* Sets x <- x * y mod r, using the plain bitwise algorithm from the @@ -151,13 +142,7 @@ gcm_gf_mul (union nettle_block16 *x, const union nettle_block16 *table) memcpy (x->b, Z.b, sizeof(Z)); } # elif GCM_TABLE_BITS == 8 -# if HAVE_NATIVE_gcm_hash8 - -#define _nettle_gcm_hash8 _nettle_gcm_hash -void -_nettle_gcm_hash8 (const struct gcm_key *key, union nettle_block16 *x, - size_t length, const uint8_t *data); -# else /* !HAVE_NATIVE_gcm_hash8 */ +# if !HAVE_NATIVE_gcm_hash8 static const uint16_t shift_table[0x100] = { W(00,00),W(01,c2),W(03,84),W(02,46),W(07,08),W(06,ca),W(04,8c),W(05,4e), @@ -294,9 +279,6 @@ gcm_set_key(struct gcm_key *key, } #if !(HAVE_NATIVE_gcm_hash || HAVE_NATIVE_gcm_hash8) -# if !HAVE_NATIVE_fat_gcm_hash -# define _nettle_gcm_hash_c _nettle_gcm_hash -# endif void _nettle_gcm_hash_c(const struct gcm_key *key, union nettle_block16 *x, size_t length, const uint8_t *data) @@ -327,7 +309,7 @@ gcm_hash_sizes(const struct gcm_key *key, union nettle_block16 *x, WRITE_UINT64 (buffer, auth_size); WRITE_UINT64 (buffer + 8, data_size); - _nettle_gcm_hash(key, x, GCM_BLOCK_SIZE, buffer); + _gcm_hash(key, x, GCM_BLOCK_SIZE, buffer); } /* NOTE: The key is needed only if length != GCM_IV_SIZE */ @@ -346,7 +328,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key, else { memset(ctx->iv.b, 0, GCM_BLOCK_SIZE); - _nettle_gcm_hash(key, &ctx->iv, length, iv); + _gcm_hash(key, &ctx->iv, length, iv); gcm_hash_sizes(key, &ctx->iv, 0, length); } @@ -365,7 +347,7 @@ gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key, assert(ctx->auth_size % GCM_BLOCK_SIZE == 0); assert(ctx->data_size == 0); - _nettle_gcm_hash(key, &ctx->x, length, data); + _gcm_hash(key, &ctx->x, length, data); ctx->auth_size += length; } @@ -436,7 +418,7 @@ gcm_encrypt (struct gcm_ctx *ctx, const struct gcm_key *key, assert(ctx->data_size % GCM_BLOCK_SIZE == 0); _nettle_ctr_crypt16(cipher, f, gcm_fill, ctx->ctr.b, length, dst, src); - _nettle_gcm_hash(key, &ctx->x, length, dst); + _gcm_hash(key, &ctx->x, length, dst); ctx->data_size += length; } @@ -448,7 +430,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key, { assert(ctx->data_size % GCM_BLOCK_SIZE == 0); - _nettle_gcm_hash(key, &ctx->x, length, src); + _gcm_hash(key, &ctx->x, length, src); _nettle_ctr_crypt16(cipher, f, gcm_fill, ctx->ctr.b, length, dst, src); ctx->data_size += length; diff --git a/testsuite/gcm-test.c b/testsuite/gcm-test.c index 2a2ca827..d68af4e0 100644 --- a/testsuite/gcm-test.c +++ b/testsuite/gcm-test.c @@ -43,7 +43,7 @@ test_ghash_internal (const struct tstring *key, _nettle_gcm_set_key (&gcm_key, key->data); memcpy (state.b, iv->data, GCM_BLOCK_SIZE); - _nettle_gcm_hash (&gcm_key, &state, message->length, message->data); + _gcm_hash (&gcm_key, &state, message->length, message->data); if (!MEMEQ(GCM_BLOCK_SIZE, state.b, digest->data)) { fprintf (stderr, "gcm_hash (internal) failed\n"); |