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 /*
wolfSSL 0:d92f9d21154c 2 BLAKE2 reference source code package - reference C implementations
wolfSSL 0:d92f9d21154c 3
wolfSSL 0:d92f9d21154c 4 Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
wolfSSL 0:d92f9d21154c 5
wolfSSL 0:d92f9d21154c 6 To the extent possible under law, the author(s) have dedicated all copyright
wolfSSL 0:d92f9d21154c 7 and related and neighboring rights to this software to the public domain
wolfSSL 0:d92f9d21154c 8 worldwide. This software is distributed without any warranty.
wolfSSL 0:d92f9d21154c 9
wolfSSL 0:d92f9d21154c 10 You should have received a copy of the CC0 Public Domain Dedication along with
wolfSSL 0:d92f9d21154c 11 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
wolfSSL 0:d92f9d21154c 12 */
wolfSSL 0:d92f9d21154c 13 /* blake2-impl.h
wolfSSL 0:d92f9d21154c 14 *
wolfSSL 0:d92f9d21154c 15 * Copyright (C) 2006-2015 wolfSSL Inc.
wolfSSL 0:d92f9d21154c 16 *
wolfSSL 0:d92f9d21154c 17 * This file is part of wolfSSL. (formerly known as CyaSSL)
wolfSSL 0:d92f9d21154c 18 *
wolfSSL 0:d92f9d21154c 19 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 0:d92f9d21154c 20 * it under the terms of the GNU General Public License as published by
wolfSSL 0:d92f9d21154c 21 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:d92f9d21154c 22 * (at your option) any later version.
wolfSSL 0:d92f9d21154c 23 *
wolfSSL 0:d92f9d21154c 24 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 0:d92f9d21154c 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:d92f9d21154c 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:d92f9d21154c 27 * GNU General Public License for more details.
wolfSSL 0:d92f9d21154c 28 *
wolfSSL 0:d92f9d21154c 29 * You should have received a copy of the GNU General Public License
wolfSSL 0:d92f9d21154c 30 * along with this program; if not, write to the Free Software
wolfSSL 0:d92f9d21154c 31 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:d92f9d21154c 32 */
wolfSSL 0:d92f9d21154c 33
wolfSSL 0:d92f9d21154c 34
wolfSSL 0:d92f9d21154c 35 #ifndef WOLFCRYPT_BLAKE2_IMPL_H
wolfSSL 0:d92f9d21154c 36 #define WOLFCRYPT_BLAKE2_IMPL_H
wolfSSL 0:d92f9d21154c 37
wolfSSL 0:d92f9d21154c 38 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 0:d92f9d21154c 39
wolfSSL 0:d92f9d21154c 40 static inline word32 load32( const void *src )
wolfSSL 0:d92f9d21154c 41 {
wolfSSL 0:d92f9d21154c 42 #if defined(LITTLE_ENDIAN_ORDER)
wolfSSL 0:d92f9d21154c 43 return *( word32 * )( src );
wolfSSL 0:d92f9d21154c 44 #else
wolfSSL 0:d92f9d21154c 45 const byte *p = ( byte * )src;
wolfSSL 0:d92f9d21154c 46 word32 w = *p++;
wolfSSL 0:d92f9d21154c 47 w |= ( word32 )( *p++ ) << 8;
wolfSSL 0:d92f9d21154c 48 w |= ( word32 )( *p++ ) << 16;
wolfSSL 0:d92f9d21154c 49 w |= ( word32 )( *p++ ) << 24;
wolfSSL 0:d92f9d21154c 50 return w;
wolfSSL 0:d92f9d21154c 51 #endif
wolfSSL 0:d92f9d21154c 52 }
wolfSSL 0:d92f9d21154c 53
wolfSSL 0:d92f9d21154c 54 static inline word64 load64( const void *src )
wolfSSL 0:d92f9d21154c 55 {
wolfSSL 0:d92f9d21154c 56 #if defined(LITTLE_ENDIAN_ORDER)
wolfSSL 0:d92f9d21154c 57 return *( word64 * )( src );
wolfSSL 0:d92f9d21154c 58 #else
wolfSSL 0:d92f9d21154c 59 const byte *p = ( byte * )src;
wolfSSL 0:d92f9d21154c 60 word64 w = *p++;
wolfSSL 0:d92f9d21154c 61 w |= ( word64 )( *p++ ) << 8;
wolfSSL 0:d92f9d21154c 62 w |= ( word64 )( *p++ ) << 16;
wolfSSL 0:d92f9d21154c 63 w |= ( word64 )( *p++ ) << 24;
wolfSSL 0:d92f9d21154c 64 w |= ( word64 )( *p++ ) << 32;
wolfSSL 0:d92f9d21154c 65 w |= ( word64 )( *p++ ) << 40;
wolfSSL 0:d92f9d21154c 66 w |= ( word64 )( *p++ ) << 48;
wolfSSL 0:d92f9d21154c 67 w |= ( word64 )( *p++ ) << 56;
wolfSSL 0:d92f9d21154c 68 return w;
wolfSSL 0:d92f9d21154c 69 #endif
wolfSSL 0:d92f9d21154c 70 }
wolfSSL 0:d92f9d21154c 71
wolfSSL 0:d92f9d21154c 72 static inline void store32( void *dst, word32 w )
wolfSSL 0:d92f9d21154c 73 {
wolfSSL 0:d92f9d21154c 74 #if defined(LITTLE_ENDIAN_ORDER)
wolfSSL 0:d92f9d21154c 75 *( word32 * )( dst ) = w;
wolfSSL 0:d92f9d21154c 76 #else
wolfSSL 0:d92f9d21154c 77 byte *p = ( byte * )dst;
wolfSSL 0:d92f9d21154c 78 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 79 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 80 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 81 *p++ = ( byte )w;
wolfSSL 0:d92f9d21154c 82 #endif
wolfSSL 0:d92f9d21154c 83 }
wolfSSL 0:d92f9d21154c 84
wolfSSL 0:d92f9d21154c 85 static inline void store64( void *dst, word64 w )
wolfSSL 0:d92f9d21154c 86 {
wolfSSL 0:d92f9d21154c 87 #if defined(LITTLE_ENDIAN_ORDER)
wolfSSL 0:d92f9d21154c 88 *( word64 * )( dst ) = w;
wolfSSL 0:d92f9d21154c 89 #else
wolfSSL 0:d92f9d21154c 90 byte *p = ( byte * )dst;
wolfSSL 0:d92f9d21154c 91 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 92 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 93 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 94 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 95 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 96 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 97 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 98 *p++ = ( byte )w;
wolfSSL 0:d92f9d21154c 99 #endif
wolfSSL 0:d92f9d21154c 100 }
wolfSSL 0:d92f9d21154c 101
wolfSSL 0:d92f9d21154c 102 static inline word64 load48( const void *src )
wolfSSL 0:d92f9d21154c 103 {
wolfSSL 0:d92f9d21154c 104 const byte *p = ( const byte * )src;
wolfSSL 0:d92f9d21154c 105 word64 w = *p++;
wolfSSL 0:d92f9d21154c 106 w |= ( word64 )( *p++ ) << 8;
wolfSSL 0:d92f9d21154c 107 w |= ( word64 )( *p++ ) << 16;
wolfSSL 0:d92f9d21154c 108 w |= ( word64 )( *p++ ) << 24;
wolfSSL 0:d92f9d21154c 109 w |= ( word64 )( *p++ ) << 32;
wolfSSL 0:d92f9d21154c 110 w |= ( word64 )( *p++ ) << 40;
wolfSSL 0:d92f9d21154c 111 return w;
wolfSSL 0:d92f9d21154c 112 }
wolfSSL 0:d92f9d21154c 113
wolfSSL 0:d92f9d21154c 114 static inline void store48( void *dst, word64 w )
wolfSSL 0:d92f9d21154c 115 {
wolfSSL 0:d92f9d21154c 116 byte *p = ( byte * )dst;
wolfSSL 0:d92f9d21154c 117 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 118 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 119 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 120 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 121 *p++ = ( byte )w; w >>= 8;
wolfSSL 0:d92f9d21154c 122 *p++ = ( byte )w;
wolfSSL 0:d92f9d21154c 123 }
wolfSSL 0:d92f9d21154c 124
wolfSSL 0:d92f9d21154c 125 static inline word32 rotl32( const word32 w, const unsigned c )
wolfSSL 0:d92f9d21154c 126 {
wolfSSL 0:d92f9d21154c 127 return ( w << c ) | ( w >> ( 32 - c ) );
wolfSSL 0:d92f9d21154c 128 }
wolfSSL 0:d92f9d21154c 129
wolfSSL 0:d92f9d21154c 130 static inline word64 rotl64( const word64 w, const unsigned c )
wolfSSL 0:d92f9d21154c 131 {
wolfSSL 0:d92f9d21154c 132 return ( w << c ) | ( w >> ( 64 - c ) );
wolfSSL 0:d92f9d21154c 133 }
wolfSSL 0:d92f9d21154c 134
wolfSSL 0:d92f9d21154c 135 static inline word32 rotr32( const word32 w, const unsigned c )
wolfSSL 0:d92f9d21154c 136 {
wolfSSL 0:d92f9d21154c 137 return ( w >> c ) | ( w << ( 32 - c ) );
wolfSSL 0:d92f9d21154c 138 }
wolfSSL 0:d92f9d21154c 139
wolfSSL 0:d92f9d21154c 140 static inline word64 rotr64( const word64 w, const unsigned c )
wolfSSL 0:d92f9d21154c 141 {
wolfSSL 0:d92f9d21154c 142 return ( w >> c ) | ( w << ( 64 - c ) );
wolfSSL 0:d92f9d21154c 143 }
wolfSSL 0:d92f9d21154c 144
wolfSSL 0:d92f9d21154c 145 /* prevents compiler optimizing out memset() */
wolfSSL 0:d92f9d21154c 146 static inline void secure_zero_memory( void *v, word64 n )
wolfSSL 0:d92f9d21154c 147 {
wolfSSL 0:d92f9d21154c 148 volatile byte *p = ( volatile byte * )v;
wolfSSL 0:d92f9d21154c 149
wolfSSL 0:d92f9d21154c 150 while( n-- ) *p++ = 0;
wolfSSL 0:d92f9d21154c 151 }
wolfSSL 0:d92f9d21154c 152
wolfSSL 0:d92f9d21154c 153 #endif /* WOLFCRYPT_BLAKE2_IMPL_H */
wolfSSL 0:d92f9d21154c 154
wolfSSL 0:d92f9d21154c 155