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