wolfSSL 3.11.1 for TLS1.3 beta

Fork of wolfSSL by wolf SSL

Committer:
wolfSSL
Date:
Thu Apr 28 00:57:21 2016 +0000
Revision:
4:1b0d80432c79
wolfSSL 3.9.0

Who changed what in which revision?

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