#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);
_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);
_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 */
#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
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),
}
#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)
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 */
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);
}
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;
}
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;
}
{
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;