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