Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Utilities/cmlibarchive/libarchive/archive_blake2_impl.h
Line
Count
Source
1
/*
2
   BLAKE2 reference source code package - reference C implementations
3
4
   Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
5
   terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6
   your option.  The terms of these licenses can be found at:
7
8
   - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9
   - OpenSSL license   : https://www.openssl.org/source/license.html
10
   - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
11
12
   More information about the BLAKE2 hash function can be found at
13
   https://blake2.net.
14
*/
15
16
#ifndef ARCHIVE_BLAKE2_IMPL_H
17
#define ARCHIVE_BLAKE2_IMPL_H
18
19
#include <stdint.h>
20
#include <string.h>
21
22
#if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
23
  #if   defined(_MSC_VER)
24
    #define BLAKE2_INLINE __inline
25
  #elif defined(__GNUC__)
26
    #define BLAKE2_INLINE __inline__
27
  #else
28
    #define BLAKE2_INLINE
29
  #endif
30
#else
31
  #define BLAKE2_INLINE inline
32
#endif
33
34
static BLAKE2_INLINE uint32_t load32( const void *src )
35
0
{
36
#if defined(NATIVE_LITTLE_ENDIAN)
37
  uint32_t w;
38
  memcpy(&w, src, sizeof w);
39
  return w;
40
#else
41
0
  const uint8_t *p = ( const uint8_t * )src;
42
0
  return (( uint32_t )( p[0] ) <<  0) |
43
0
         (( uint32_t )( p[1] ) <<  8) |
44
0
         (( uint32_t )( p[2] ) << 16) |
45
0
         (( uint32_t )( p[3] ) << 24) ;
46
0
#endif
47
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:load32
Unexecuted instantiation: archive_blake2s_ref.c:load32
48
49
static BLAKE2_INLINE uint64_t load64( const void *src )
50
0
{
51
0
#if defined(NATIVE_LITTLE_ENDIAN)
52
0
  uint64_t w;
53
0
  memcpy(&w, src, sizeof w);
54
0
  return w;
55
0
#else
56
0
  const uint8_t *p = ( const uint8_t * )src;
57
0
  return (( uint64_t )( p[0] ) <<  0) |
58
0
         (( uint64_t )( p[1] ) <<  8) |
59
0
         (( uint64_t )( p[2] ) << 16) |
60
0
         (( uint64_t )( p[3] ) << 24) |
61
0
         (( uint64_t )( p[4] ) << 32) |
62
0
         (( uint64_t )( p[5] ) << 40) |
63
0
         (( uint64_t )( p[6] ) << 48) |
64
0
         (( uint64_t )( p[7] ) << 56) ;
65
0
#endif
66
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:load64
Unexecuted instantiation: archive_blake2s_ref.c:load64
67
68
static BLAKE2_INLINE uint16_t load16( const void *src )
69
0
{
70
0
#if defined(NATIVE_LITTLE_ENDIAN)
71
0
  uint16_t w;
72
0
  memcpy(&w, src, sizeof w);
73
0
  return w;
74
0
#else
75
0
  const uint8_t *p = ( const uint8_t * )src;
76
0
  return ( uint16_t )((( uint32_t )( p[0] ) <<  0) |
77
0
                      (( uint32_t )( p[1] ) <<  8));
78
0
#endif
79
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:load16
Unexecuted instantiation: archive_blake2s_ref.c:load16
80
81
static BLAKE2_INLINE void store16( void *dst, uint16_t w )
82
0
{
83
#if defined(NATIVE_LITTLE_ENDIAN)
84
  memcpy(dst, &w, sizeof w);
85
#else
86
0
  uint8_t *p = ( uint8_t * )dst;
87
0
  *p++ = ( uint8_t )w; w >>= 8;
88
0
  *p++ = ( uint8_t )w;
89
0
#endif
90
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:store16
Unexecuted instantiation: archive_blake2s_ref.c:store16
91
92
static BLAKE2_INLINE void store32( void *dst, uint32_t w )
93
0
{
94
#if defined(NATIVE_LITTLE_ENDIAN)
95
  memcpy(dst, &w, sizeof w);
96
#else
97
0
  uint8_t *p = ( uint8_t * )dst;
98
0
  p[0] = (uint8_t)(w >>  0);
99
0
  p[1] = (uint8_t)(w >>  8);
100
0
  p[2] = (uint8_t)(w >> 16);
101
0
  p[3] = (uint8_t)(w >> 24);
102
0
#endif
103
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:store32
Unexecuted instantiation: archive_blake2s_ref.c:store32
104
105
static BLAKE2_INLINE void store64( void *dst, uint64_t w )
106
0
{
107
0
#if defined(NATIVE_LITTLE_ENDIAN)
108
0
  memcpy(dst, &w, sizeof w);
109
0
#else
110
0
  uint8_t *p = ( uint8_t * )dst;
111
0
  p[0] = (uint8_t)(w >>  0);
112
0
  p[1] = (uint8_t)(w >>  8);
113
0
  p[2] = (uint8_t)(w >> 16);
114
0
  p[3] = (uint8_t)(w >> 24);
115
0
  p[4] = (uint8_t)(w >> 32);
116
0
  p[5] = (uint8_t)(w >> 40);
117
0
  p[6] = (uint8_t)(w >> 48);
118
0
  p[7] = (uint8_t)(w >> 56);
119
0
#endif
120
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:store64
Unexecuted instantiation: archive_blake2s_ref.c:store64
121
122
static BLAKE2_INLINE uint64_t load48( const void *src )
123
0
{
124
0
  const uint8_t *p = ( const uint8_t * )src;
125
0
  return (( uint64_t )( p[0] ) <<  0) |
126
0
         (( uint64_t )( p[1] ) <<  8) |
127
0
         (( uint64_t )( p[2] ) << 16) |
128
0
         (( uint64_t )( p[3] ) << 24) |
129
0
         (( uint64_t )( p[4] ) << 32) |
130
0
         (( uint64_t )( p[5] ) << 40) ;
131
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:load48
Unexecuted instantiation: archive_blake2s_ref.c:load48
132
133
static BLAKE2_INLINE void store48( void *dst, uint64_t w )
134
0
{
135
0
  uint8_t *p = ( uint8_t * )dst;
136
0
  p[0] = (uint8_t)(w >>  0);
137
0
  p[1] = (uint8_t)(w >>  8);
138
0
  p[2] = (uint8_t)(w >> 16);
139
0
  p[3] = (uint8_t)(w >> 24);
140
0
  p[4] = (uint8_t)(w >> 32);
141
0
  p[5] = (uint8_t)(w >> 40);
142
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:store48
Unexecuted instantiation: archive_blake2s_ref.c:store48
143
144
static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c )
145
0
{
146
0
  return ( w >> c ) | ( w << ( 32 - c ) );
147
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:rotr32
Unexecuted instantiation: archive_blake2s_ref.c:rotr32
148
149
static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
150
0
{
151
0
  return ( w >> c ) | ( w << ( 64 - c ) );
152
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:rotr64
Unexecuted instantiation: archive_blake2s_ref.c:rotr64
153
154
/* prevents compiler optimizing out memset() */
155
static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
156
0
{
157
0
  static void *(__LA_LIBC_CC *const volatile memset_v)(void *, int, size_t) = &memset;
158
0
  memset_v(v, 0, n);
159
0
}
Unexecuted instantiation: archive_blake2sp_ref.c:secure_zero_memory
Unexecuted instantiation: archive_blake2s_ref.c:secure_zero_memory
160
161
#endif