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