Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers poly1305.h Source File

poly1305.h

00001 /* poly1305.h
00002  *
00003  * Copyright (C) 2006-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023 #ifndef WOLF_CRYPT_POLY1305_H
00024 #define WOLF_CRYPT_POLY1305_H
00025 
00026 #include <wolfssl/wolfcrypt/types.h>
00027 
00028 #ifdef HAVE_POLY1305
00029 
00030 #ifdef __cplusplus
00031     extern "C" {
00032 #endif
00033 
00034 /* auto detect between 32bit / 64bit */
00035 #define HAS_SIZEOF_INT128_64BIT (defined(__SIZEOF_INT128__) && defined(__LP64__))
00036 #define HAS_MSVC_64BIT (defined(_MSC_VER) && defined(_M_X64))
00037 #define HAS_GCC_4_4_64BIT (defined(__GNUC__) && defined(__LP64__) && \
00038         ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))))
00039 
00040 #if (HAS_SIZEOF_INT128_64BIT || HAS_MSVC_64BIT || HAS_GCC_4_4_64BIT)
00041 #define POLY130564
00042 #else
00043 #define POLY130532
00044 #endif
00045 
00046 enum {
00047     POLY1305 = 7,
00048     POLY1305_BLOCK_SIZE = 16,
00049     POLY1305_DIGEST_SIZE = 16,
00050 };
00051 
00052 #define WC_POLY1305_PAD_SZ 16
00053 #define WC_POLY1305_MAC_SZ 16
00054 
00055 /* Poly1305 state */
00056 typedef struct Poly1305 {
00057 #if defined(POLY130564)
00058     word64 r[3];
00059     word64 h[3];
00060     word64 pad[2];
00061 #else
00062     word32 r[5];
00063     word32 h[5];
00064     word32 pad[4];
00065 #endif
00066     size_t leftover;
00067     unsigned char buffer[POLY1305_BLOCK_SIZE];
00068     unsigned char final;
00069 } Poly1305;
00070 
00071 
00072 /* does init */
00073 
00074 WOLFSSL_API int wc_Poly1305SetKey(Poly1305* poly1305, const byte* key, word32 kySz);
00075 WOLFSSL_API int wc_Poly1305Update(Poly1305* poly1305, const byte*, word32);
00076 WOLFSSL_API int wc_Poly1305Final(Poly1305* poly1305, byte* tag);
00077 WOLFSSL_API int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
00078                                byte* input, word32 sz, byte* tag, word32 tagSz);
00079 #ifdef __cplusplus
00080     } /* extern "C" */
00081 #endif
00082 
00083 #endif /* HAVE_POLY1305 */
00084 #endif /* WOLF_CRYPT_POLY1305_H */
00085 
00086