wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
Parent:
11:cee25a834751
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

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