Coverage Report

Created: 2026-09-20 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wolfssl-sp-math-all-8bit/wolfssl/wolfcrypt/blake2-impl.h
Line
Count
Source
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-2026 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 3 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
    (!defined(WOLFSSL_GENERAL_ALIGNMENT) || (WOLFSSL_GENERAL_ALIGNMENT == 0))
45
0
  return *( const word32 * )( src );
46
#else
47
  const byte *p = ( const byte * )src;
48
  word32 w = *p++;
49
  w |= ( word32 )( *p++ ) <<  8;
50
  w |= ( word32 )( *p++ ) << 16;
51
  w |= ( word32 )( *p++ ) << 24;
52
  return w;
53
#endif
54
0
}
Unexecuted instantiation: blake2b.c:load32
Unexecuted instantiation: blake2s.c:load32
55
56
static WC_INLINE word64 load64( const void *src )
57
0
{
58
0
#if defined(LITTLE_ENDIAN_ORDER) && \
59
0
    (!defined(WOLFSSL_GENERAL_ALIGNMENT) || (WOLFSSL_GENERAL_ALIGNMENT == 0))
60
0
  return *( const word64 * )( src );
61
#else
62
  const byte *p = ( const byte * )src;
63
  word64 w = *p++;
64
  w |= ( word64 )( *p++ ) <<  8;
65
  w |= ( word64 )( *p++ ) << 16;
66
  w |= ( word64 )( *p++ ) << 24;
67
  w |= ( word64 )( *p++ ) << 32;
68
  w |= ( word64 )( *p++ ) << 40;
69
  w |= ( word64 )( *p++ ) << 48;
70
  w |= ( word64 )( *p++ ) << 56;
71
  return w;
72
#endif
73
0
}
Unexecuted instantiation: blake2b.c:load64
Unexecuted instantiation: blake2s.c:load64
74
75
static WC_INLINE void store32( void *dst, word32 w )
76
0
{
77
0
#if defined(LITTLE_ENDIAN_ORDER) && \
78
0
    (!defined(WOLFSSL_GENERAL_ALIGNMENT) || (WOLFSSL_GENERAL_ALIGNMENT == 0))
79
0
  *( word32 * )( dst ) = w;
80
#else
81
  byte *p = ( byte * )dst;
82
  *p++ = ( byte )w; w >>= 8;
83
  *p++ = ( byte )w; w >>= 8;
84
  *p++ = ( byte )w; w >>= 8;
85
  *p++ = ( byte )w;
86
#endif
87
0
}
Unexecuted instantiation: blake2b.c:store32
Unexecuted instantiation: blake2s.c:store32
88
89
static WC_INLINE void store64( void *dst, word64 w )
90
0
{
91
0
#if defined(LITTLE_ENDIAN_ORDER) && \
92
0
    (!defined(WOLFSSL_GENERAL_ALIGNMENT) || (WOLFSSL_GENERAL_ALIGNMENT == 0))
93
0
  *( word64 * )( dst ) = w;
94
#else
95
  byte *p = ( byte * )dst;
96
  *p++ = ( byte )w; w >>= 8;
97
  *p++ = ( byte )w; w >>= 8;
98
  *p++ = ( byte )w; w >>= 8;
99
  *p++ = ( byte )w; w >>= 8;
100
  *p++ = ( byte )w; w >>= 8;
101
  *p++ = ( byte )w; w >>= 8;
102
  *p++ = ( byte )w; w >>= 8;
103
  *p++ = ( byte )w;
104
#endif
105
0
}
Unexecuted instantiation: blake2b.c:store64
Unexecuted instantiation: blake2s.c:store64
106
107
static WC_INLINE word64 load48( const void *src )
108
0
{
109
0
  const byte *p = ( const byte * )src;
110
0
  word64 w = *p++;
111
0
  w |= ( word64 )( *p++ ) <<  8;
112
0
  w |= ( word64 )( *p++ ) << 16;
113
0
  w |= ( word64 )( *p++ ) << 24;
114
0
  w |= ( word64 )( *p++ ) << 32;
115
0
  w |= ( word64 )( *p++ ) << 40;
116
0
  return w;
117
0
}
Unexecuted instantiation: blake2b.c:load48
Unexecuted instantiation: blake2s.c:load48
118
119
static WC_INLINE void store48( void *dst, word64 w )
120
0
{
121
0
  byte *p = ( byte * )dst;
122
0
  *p++ = ( byte )w; w >>= 8;
123
0
  *p++ = ( byte )w; w >>= 8;
124
0
  *p++ = ( byte )w; w >>= 8;
125
0
  *p++ = ( byte )w; w >>= 8;
126
0
  *p++ = ( byte )w; w >>= 8;
127
0
  *p++ = ( byte )w;
128
0
}
Unexecuted instantiation: blake2b.c:store48
Unexecuted instantiation: blake2s.c:store48
129
130
static WC_INLINE word32 rotl32( const word32 w, const unsigned c )
131
0
{
132
0
  return ( w << c ) | ( w >> ( 32 - c ) );
133
0
}
Unexecuted instantiation: blake2b.c:rotl32
Unexecuted instantiation: blake2s.c:rotl32
134
135
static WC_INLINE word64 rotl64( const word64 w, const unsigned c )
136
0
{
137
0
  return ( w << c ) | ( w >> ( 64 - c ) );
138
0
}
Unexecuted instantiation: blake2b.c:rotl64
Unexecuted instantiation: blake2s.c:rotl64
139
140
static WC_INLINE word32 rotr32( const word32 w, const unsigned c )
141
0
{
142
0
  return ( w >> c ) | ( w << ( 32 - c ) );
143
0
}
Unexecuted instantiation: blake2b.c:rotr32
Unexecuted instantiation: blake2s.c:rotr32
144
145
static WC_INLINE word64 rotr64( const word64 w, const unsigned c )
146
0
{
147
0
  return ( w >> c ) | ( w << ( 64 - c ) );
148
0
}
Unexecuted instantiation: blake2b.c:rotr64
Unexecuted instantiation: blake2s.c:rotr64
149
150
/* prevents compiler optimizing out memset() */
151
static WC_INLINE void secure_zero_memory( void *v, word64 n )
152
0
{
153
0
  volatile byte *p = ( volatile byte * )v;
154
155
0
  while( n-- ) *p++ = 0;
156
0
}
Unexecuted instantiation: blake2b.c:secure_zero_memory
Unexecuted instantiation: blake2s.c:secure_zero_memory
157
158
#endif  /* WOLFCRYPT_BLAKE2_IMPL_H */
159