Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
sPymbed
Date:
Tue Nov 19 14:32:16 2019 +0000
Revision:
16:048e5e270a58
Parent:
15:117db924cf7c
working ssl

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 15:117db924cf7c 1 /* poly1305.h
wolfSSL 15:117db924cf7c 2 *
wolfSSL 15:117db924cf7c 3 * Copyright (C) 2006-2017 wolfSSL Inc.
wolfSSL 15:117db924cf7c 4 *
wolfSSL 15:117db924cf7c 5 * This file is part of wolfSSL.
wolfSSL 15:117db924cf7c 6 *
wolfSSL 15:117db924cf7c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 15:117db924cf7c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 15:117db924cf7c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 15:117db924cf7c 10 * (at your option) any later version.
wolfSSL 15:117db924cf7c 11 *
wolfSSL 15:117db924cf7c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 15:117db924cf7c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 15:117db924cf7c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 15:117db924cf7c 15 * GNU General Public License for more details.
wolfSSL 15:117db924cf7c 16 *
wolfSSL 15:117db924cf7c 17 * You should have received a copy of the GNU General Public License
wolfSSL 15:117db924cf7c 18 * along with this program; if not, write to the Free Software
wolfSSL 15:117db924cf7c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 15:117db924cf7c 20 */
wolfSSL 15:117db924cf7c 21
wolfSSL 15:117db924cf7c 22 /*!
wolfSSL 15:117db924cf7c 23 \file wolfssl/wolfcrypt/poly1305.h
wolfSSL 15:117db924cf7c 24 */
wolfSSL 15:117db924cf7c 25
wolfSSL 15:117db924cf7c 26 #ifndef WOLF_CRYPT_POLY1305_H
wolfSSL 15:117db924cf7c 27 #define WOLF_CRYPT_POLY1305_H
wolfSSL 15:117db924cf7c 28
wolfSSL 15:117db924cf7c 29 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 15:117db924cf7c 30
wolfSSL 15:117db924cf7c 31 #ifdef HAVE_POLY1305
wolfSSL 15:117db924cf7c 32
wolfSSL 15:117db924cf7c 33 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 34 extern "C" {
wolfSSL 15:117db924cf7c 35 #endif
wolfSSL 15:117db924cf7c 36
wolfSSL 15:117db924cf7c 37 /* auto detect between 32bit / 64bit */
wolfSSL 15:117db924cf7c 38 #if defined(__SIZEOF_INT128__) && defined(__LP64__)
wolfSSL 15:117db924cf7c 39 #define WC_HAS_SIZEOF_INT128_64BIT
wolfSSL 15:117db924cf7c 40 #endif
wolfSSL 15:117db924cf7c 41
wolfSSL 15:117db924cf7c 42 #if defined(_MSC_VER) && defined(_M_X64)
wolfSSL 15:117db924cf7c 43 #define WC_HAS_MSVC_64BIT
wolfSSL 15:117db924cf7c 44 #endif
wolfSSL 15:117db924cf7c 45
wolfSSL 15:117db924cf7c 46 #if (defined(__GNUC__) && defined(__LP64__) && \
wolfSSL 15:117db924cf7c 47 ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))))
wolfSSL 15:117db924cf7c 48 #define WC_HAS_GCC_4_4_64BIT
wolfSSL 15:117db924cf7c 49 #endif
wolfSSL 15:117db924cf7c 50
wolfSSL 15:117db924cf7c 51 #ifdef USE_INTEL_SPEEDUP
wolfSSL 15:117db924cf7c 52 #elif (defined(WC_HAS_SIZEOF_INT128_64BIT) || defined(WC_HAS_MSVC_64BIT) || \
wolfSSL 15:117db924cf7c 53 defined(WC_HAS_GCC_4_4_64BIT))
wolfSSL 15:117db924cf7c 54 #define POLY130564
wolfSSL 15:117db924cf7c 55 #else
wolfSSL 15:117db924cf7c 56 #define POLY130532
wolfSSL 15:117db924cf7c 57 #endif
wolfSSL 15:117db924cf7c 58
wolfSSL 15:117db924cf7c 59 enum {
wolfSSL 15:117db924cf7c 60 POLY1305 = 7,
wolfSSL 15:117db924cf7c 61 POLY1305_BLOCK_SIZE = 16,
wolfSSL 15:117db924cf7c 62 POLY1305_DIGEST_SIZE = 16,
wolfSSL 15:117db924cf7c 63 };
wolfSSL 15:117db924cf7c 64
wolfSSL 15:117db924cf7c 65 #define WC_POLY1305_PAD_SZ 16
wolfSSL 15:117db924cf7c 66 #define WC_POLY1305_MAC_SZ 16
wolfSSL 15:117db924cf7c 67
wolfSSL 15:117db924cf7c 68 /* Poly1305 state */
wolfSSL 15:117db924cf7c 69 typedef struct Poly1305 {
wolfSSL 15:117db924cf7c 70 #ifdef USE_INTEL_SPEEDUP
wolfSSL 15:117db924cf7c 71 word64 r[3];
wolfSSL 15:117db924cf7c 72 word64 h[3];
wolfSSL 15:117db924cf7c 73 word64 pad[2];
wolfSSL 15:117db924cf7c 74 word64 hh[20];
wolfSSL 15:117db924cf7c 75 word32 r1[8];
wolfSSL 15:117db924cf7c 76 word32 r2[8];
wolfSSL 15:117db924cf7c 77 word32 r3[8];
wolfSSL 15:117db924cf7c 78 word32 r4[8];
wolfSSL 15:117db924cf7c 79 word64 hm[16];
wolfSSL 15:117db924cf7c 80 unsigned char buffer[8*POLY1305_BLOCK_SIZE];
wolfSSL 15:117db924cf7c 81 size_t leftover;
wolfSSL 15:117db924cf7c 82 unsigned char finished;
wolfSSL 15:117db924cf7c 83 unsigned char started;
wolfSSL 15:117db924cf7c 84 #else
wolfSSL 15:117db924cf7c 85 #if defined(POLY130564)
wolfSSL 15:117db924cf7c 86 word64 r[3];
wolfSSL 15:117db924cf7c 87 word64 h[3];
wolfSSL 15:117db924cf7c 88 word64 pad[2];
wolfSSL 15:117db924cf7c 89 #else
wolfSSL 15:117db924cf7c 90 word32 r[5];
wolfSSL 15:117db924cf7c 91 word32 h[5];
wolfSSL 15:117db924cf7c 92 word32 pad[4];
wolfSSL 15:117db924cf7c 93 #endif
wolfSSL 15:117db924cf7c 94 size_t leftover;
wolfSSL 15:117db924cf7c 95 unsigned char buffer[POLY1305_BLOCK_SIZE];
wolfSSL 15:117db924cf7c 96 unsigned char finished;
wolfSSL 15:117db924cf7c 97 #endif
wolfSSL 15:117db924cf7c 98 } Poly1305;
wolfSSL 15:117db924cf7c 99
wolfSSL 15:117db924cf7c 100 /* does init */
wolfSSL 15:117db924cf7c 101
wolfSSL 15:117db924cf7c 102 WOLFSSL_API int wc_Poly1305SetKey(Poly1305* poly1305, const byte* key,
wolfSSL 15:117db924cf7c 103 word32 kySz);
wolfSSL 15:117db924cf7c 104 WOLFSSL_API int wc_Poly1305Update(Poly1305* poly1305, const byte*, word32);
wolfSSL 15:117db924cf7c 105 WOLFSSL_API int wc_Poly1305Final(Poly1305* poly1305, byte* tag);
wolfSSL 15:117db924cf7c 106 WOLFSSL_API int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
wolfSSL 15:117db924cf7c 107 byte* input, word32 sz, byte* tag, word32 tagSz);
wolfSSL 15:117db924cf7c 108 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 109 } /* extern "C" */
wolfSSL 15:117db924cf7c 110 #endif
wolfSSL 15:117db924cf7c 111
wolfSSL 15:117db924cf7c 112 #endif /* HAVE_POLY1305 */
wolfSSL 15:117db924cf7c 113 #endif /* WOLF_CRYPT_POLY1305_H */
wolfSSL 15:117db924cf7c 114
wolfSSL 15:117db924cf7c 115