MultiTech / CyaSSL

Dependents:   HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL

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-2014 wolfSSL Inc.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL 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  * CyaSSL 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-1301, USA
00020  */
00021 
00022 
00023 #ifdef HAVE_POLY1305
00024 
00025 #ifndef CTAO_CRYPT_POLY1305_H
00026 #define CTAO_CRYPT_POLY1305_H
00027 
00028 #include <cyassl/ctaocrypt/types.h>
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     POLY1305_PAD_SIZE = 56
00051 };
00052 
00053 /* Poly1305 state */
00054 typedef struct Poly1305 {
00055 #if defined(POLY130564)
00056     word64 r[3];
00057     word64 h[3];
00058     word64 pad[2];
00059 #else
00060     word32 r[5];
00061     word32 h[5];
00062     word32 pad[4];
00063 #endif
00064     size_t leftover;
00065     unsigned char buffer[POLY1305_BLOCK_SIZE];
00066     unsigned char final;
00067 } Poly1305;
00068 
00069 
00070 /* does init */
00071 
00072 CYASSL_API int Poly1305SetKey(Poly1305* poly1305, const byte* key, word32 kySz);
00073 CYASSL_API int Poly1305Update(Poly1305* poly1305, const byte*, word32);
00074 CYASSL_API int Poly1305Final(Poly1305* poly1305, byte* tag);
00075 
00076 #ifdef __cplusplus
00077     } /* extern "C" */
00078 #endif
00079 
00080 #endif /* CTAO_CRYPT_POLY1305_H */
00081 
00082 #endif /* HAVE_POLY1305 */
00083