| 1 |
/* poly1305-internal.h - Poly1305 internals |
| 2 |
* Copyright (C) 2014 Jussi Kivilinna <[email protected]> |
| 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 |
|
| 20 |
#ifndef G10_POLY1305_INTERNAL_H |
| 21 |
#define G10_POLY1305_INTERNAL_H |
| 22 |
|
| 23 |
#include <config.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
#include "types.h" |
| 28 |
#include "g10lib.h" |
| 29 |
#include "cipher.h" |
| 30 |
#include "bufhelp.h" |
| 31 |
|
| 32 |
#define POLY1305_TAGLEN 16 |
| 33 |
#define POLY1305_KEYLEN 32 |
| 34 |
#define POLY1305_BLOCKSIZE 16 |
| 35 |
|
| 36 |
|
| 37 |
/* POLY1305_USE_AVX512 indicates whether to compile with Intel AVX512 code. */ |
| 38 |
#undef POLY1305_USE_AVX512 |
| 39 |
#if defined(__x86_64__) && defined(HAVE_GCC_INLINE_ASM_AVX512) && \ |
| 40 |
defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \ |
| 41 |
(defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ |
| 42 |
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) |
| 43 |
# define POLY1305_USE_AVX512 1 |
| 44 |
#endif |
| 45 |
|
| 46 |
/* POLY1305_USE_PPC_VEC indicates whether to enable PowerPC vector code. */ |
| 47 |
#undef POLY1305_USE_PPC_VEC |
| 48 |
#ifdef ENABLE_PPC_CRYPTO_SUPPORT |
| 49 |
# if defined(HAVE_COMPATIBLE_CC_PPC_ALTIVEC) && \ |
| 50 |
defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && \ |
| 51 |
!defined(WORDS_BIGENDIAN) |
| 52 |
# if __GNUC__ >= 4 |
| 53 |
# define POLY1305_USE_PPC_VEC 1 |
| 54 |
# endif |
| 55 |
# endif |
| 56 |
#endif |
| 57 |
|
| 58 |
|
| 59 |
typedef struct |
| 60 |
{ |
| 61 |
u32 k[4]; |
| 62 |
u32 r[4]; |
| 63 |
u32 h[5]; |
| 64 |
} POLY1305_STATE; |
| 65 |
|
| 66 |
typedef struct poly1305_context_s |
| 67 |
{ |
| 68 |
POLY1305_STATE state; |
| 69 |
byte buffer[POLY1305_BLOCKSIZE]; |
| 70 |
unsigned int leftover; |
| 71 |
#ifdef POLY1305_USE_AVX512 |
| 72 |
unsigned int use_avx512:1; |
| 73 |
#endif |
| 74 |
#ifdef POLY1305_USE_PPC_VEC |
| 75 |
unsigned int use_p10:1; |
| 76 |
#endif |
| 77 |
} poly1305_context_t; |
| 78 |
|
| 79 |
|
| 80 |
gcry_err_code_t _gcry_poly1305_init (poly1305_context_t *ctx, const byte *key, |
| 81 |
size_t keylen); |
| 82 |
|
| 83 |
void _gcry_poly1305_finish (poly1305_context_t *ctx, |
| 84 |
byte mac[POLY1305_TAGLEN]); |
| 85 |
|
| 86 |
void _gcry_poly1305_update (poly1305_context_t *ctx, const byte *buf, |
| 87 |
size_t buflen); |
| 88 |
|
| 89 |
unsigned int _gcry_poly1305_update_burn (poly1305_context_t *ctx, |
| 90 |
const byte *m, size_t bytes); |
| 91 |
|
| 92 |
#endif /* G10_POLY1305_INTERNAL_H */ |