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

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

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

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