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