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