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 05 00:11:07 2020 +0000
Revision:
17:a5f916481144
Parent:
16:8e0d178b1d1e
wolfSSL 4.4.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 15:117db924cf7c 1 /* poly1305.h
wolfSSL 15:117db924cf7c 2 *
wolfSSL 16:8e0d178b1d1e 3 * Copyright (C) 2006-2020 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 16:8e0d178b1d1e 85 #if defined(WOLFSSL_ARMASM) && defined(__aarch64__)
wolfSSL 16:8e0d178b1d1e 86 ALIGN128 word32 r[5];
wolfSSL 16:8e0d178b1d1e 87 ALIGN128 word32 r_2[5]; // r^2
wolfSSL 16:8e0d178b1d1e 88 ALIGN128 word32 r_4[5]; // r^4
wolfSSL 16:8e0d178b1d1e 89 ALIGN128 word32 h[5];
wolfSSL 16:8e0d178b1d1e 90 word32 pad[4];
wolfSSL 16:8e0d178b1d1e 91 word64 leftover;
wolfSSL 16:8e0d178b1d1e 92 #else
wolfSSL 15:117db924cf7c 93 #if defined(POLY130564)
wolfSSL 15:117db924cf7c 94 word64 r[3];
wolfSSL 15:117db924cf7c 95 word64 h[3];
wolfSSL 15:117db924cf7c 96 word64 pad[2];
wolfSSL 15:117db924cf7c 97 #else
wolfSSL 15:117db924cf7c 98 word32 r[5];
wolfSSL 15:117db924cf7c 99 word32 h[5];
wolfSSL 15:117db924cf7c 100 word32 pad[4];
wolfSSL 15:117db924cf7c 101 #endif
wolfSSL 15:117db924cf7c 102 size_t leftover;
wolfSSL 16:8e0d178b1d1e 103 #endif /* WOLFSSL_ARMASM */
wolfSSL 15:117db924cf7c 104 unsigned char buffer[POLY1305_BLOCK_SIZE];
wolfSSL 15:117db924cf7c 105 unsigned char finished;
wolfSSL 15:117db924cf7c 106 #endif
wolfSSL 15:117db924cf7c 107 } Poly1305;
wolfSSL 15:117db924cf7c 108
wolfSSL 15:117db924cf7c 109 /* does init */
wolfSSL 15:117db924cf7c 110
wolfSSL 15:117db924cf7c 111 WOLFSSL_API int wc_Poly1305SetKey(Poly1305* poly1305, const byte* key,
wolfSSL 15:117db924cf7c 112 word32 kySz);
wolfSSL 15:117db924cf7c 113 WOLFSSL_API int wc_Poly1305Update(Poly1305* poly1305, const byte*, word32);
wolfSSL 15:117db924cf7c 114 WOLFSSL_API int wc_Poly1305Final(Poly1305* poly1305, byte* tag);
wolfSSL 16:8e0d178b1d1e 115
wolfSSL 16:8e0d178b1d1e 116 /* AEAD Functions */
wolfSSL 16:8e0d178b1d1e 117 WOLFSSL_API int wc_Poly1305_Pad(Poly1305* ctx, word32 lenToPad);
wolfSSL 16:8e0d178b1d1e 118 WOLFSSL_API int wc_Poly1305_EncodeSizes(Poly1305* ctx, word32 aadSz, word32 dataSz);
wolfSSL 15:117db924cf7c 119 WOLFSSL_API int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
wolfSSL 15:117db924cf7c 120 byte* input, word32 sz, byte* tag, word32 tagSz);
wolfSSL 16:8e0d178b1d1e 121
wolfSSL 16:8e0d178b1d1e 122 void poly1305_block(Poly1305* ctx, const unsigned char *m);
wolfSSL 16:8e0d178b1d1e 123 void poly1305_blocks(Poly1305* ctx, const unsigned char *m,
wolfSSL 16:8e0d178b1d1e 124 size_t bytes);
wolfSSL 15:117db924cf7c 125 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 126 } /* extern "C" */
wolfSSL 15:117db924cf7c 127 #endif
wolfSSL 15:117db924cf7c 128
wolfSSL 15:117db924cf7c 129 #endif /* HAVE_POLY1305 */
wolfSSL 15:117db924cf7c 130 #endif /* WOLF_CRYPT_POLY1305_H */
wolfSSL 15:117db924cf7c 131