poly1305-internal.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* poly1305-internal.h - Poly1305 internals
  2. * Copyright (C) 2014 Jussi Kivilinna <jussi.kivilinna@iki.fi>
  3. *
  4. * This file is part of Libgcrypt.
  5. *
  6. * Libgcrypt is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * Libgcrypt is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef G10_POLY1305_INTERNAL_H
  20. #define G10_POLY1305_INTERNAL_H
  21. #include <config.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include "types.h"
  26. #include "g10lib.h"
  27. #include "cipher.h"
  28. #include "bufhelp.h"
  29. #define POLY1305_TAGLEN 16
  30. #define POLY1305_KEYLEN 32
  31. #define POLY1305_BLOCKSIZE 16
  32. /* POLY1305_USE_AVX512 indicates whether to compile with Intel AVX512 code. */
  33. #undef POLY1305_USE_AVX512
  34. #if defined(__x86_64__) && defined(HAVE_GCC_INLINE_ASM_AVX512) && \
  35. defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \
  36. (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
  37. defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS))
  38. # define POLY1305_USE_AVX512 1
  39. #endif
  40. /* POLY1305_USE_PPC_VEC indicates whether to enable PowerPC vector code. */
  41. #undef POLY1305_USE_PPC_VEC
  42. #ifdef ENABLE_PPC_CRYPTO_SUPPORT
  43. # if defined(HAVE_COMPATIBLE_CC_PPC_ALTIVEC) && \
  44. defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && \
  45. !defined(WORDS_BIGENDIAN)
  46. # if __GNUC__ >= 4
  47. # define POLY1305_USE_PPC_VEC 1
  48. # endif
  49. # endif
  50. #endif
  51. typedef struct
  52. {
  53. u32 k[4];
  54. u32 r[4];
  55. u32 h[5];
  56. } POLY1305_STATE;
  57. typedef struct poly1305_context_s
  58. {
  59. POLY1305_STATE state;
  60. byte buffer[POLY1305_BLOCKSIZE];
  61. unsigned int leftover;
  62. #ifdef POLY1305_USE_AVX512
  63. unsigned int use_avx512:1;
  64. #endif
  65. #ifdef POLY1305_USE_PPC_VEC
  66. unsigned int use_p10:1;
  67. #endif
  68. } poly1305_context_t;
  69. gcry_err_code_t _gcry_poly1305_init (poly1305_context_t *ctx, const byte *key,
  70. size_t keylen);
  71. void _gcry_poly1305_finish (poly1305_context_t *ctx,
  72. byte mac[POLY1305_TAGLEN]);
  73. void _gcry_poly1305_update (poly1305_context_t *ctx, const byte *buf,
  74. size_t buflen);
  75. unsigned int _gcry_poly1305_update_burn (poly1305_context_t *ctx,
  76. const byte *m, size_t bytes);
  77. #endif /* G10_POLY1305_INTERNAL_H */