| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/blake2/blake2-impl.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count |
|---|---|---|
| 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 : https://creativecommons.org/publicdomain/zero/1.0 | - |
| 9 | - OpenSSL license : https://www.openssl.org/source/license.html | - |
| 10 | - Apache 2.0 : https://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 | #ifndef BLAKE2_IMPL_H | - |
| 16 | #define BLAKE2_IMPL_H | - |
| 17 | - | |
| 18 | #include <stdint.h> | - |
| 19 | #include <string.h> | - |
| 20 | - | |
| 21 | #if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) | - |
| 22 | #if defined(_MSC_VER) | - |
| 23 | #define BLAKE2_INLINE __inline | - |
| 24 | #elif defined(__GNUC__) | - |
| 25 | #define BLAKE2_INLINE __inline__ | - |
| 26 | #else | - |
| 27 | #define BLAKE2_INLINE | - |
| 28 | #endif | - |
| 29 | #else | - |
| 30 | #define BLAKE2_INLINE inline | - |
| 31 | #endif | - |
| 32 | - | |
| 33 | static BLAKE2_INLINE uint32_t load32( const void *src ) | - |
| 34 | { | - |
| 35 | #if defined(NATIVE_LITTLE_ENDIAN) | - |
| 36 | uint32_t w; | - |
| 37 | memcpy(&w, src, sizeof w); | - |
| 38 | return w; | - |
| 39 | #else | - |
| 40 | const uint8_t *p = ( const uint8_t * )src; | - |
| 41 | return (( uint32_t )( p[0] ) << 0) | never executed: return (( uint32_t )( p[0] ) << 0) | (( uint32_t )( p[1] ) << 8) | (( uint32_t )( p[2] ) << 16) | (( uint32_t )( p[3] ) << 24) ; | 0 |
| 42 | (( uint32_t )( p[1] ) << 8) | never executed: return (( uint32_t )( p[0] ) << 0) | (( uint32_t )( p[1] ) << 8) | (( uint32_t )( p[2] ) << 16) | (( uint32_t )( p[3] ) << 24) ; | 0 |
| 43 | (( uint32_t )( p[2] ) << 16) | never executed: return (( uint32_t )( p[0] ) << 0) | (( uint32_t )( p[1] ) << 8) | (( uint32_t )( p[2] ) << 16) | (( uint32_t )( p[3] ) << 24) ; | 0 |
| 44 | (( uint32_t )( p[3] ) << 24) ; never executed: return (( uint32_t )( p[0] ) << 0) | (( uint32_t )( p[1] ) << 8) | (( uint32_t )( p[2] ) << 16) | (( uint32_t )( p[3] ) << 24) ; | 0 |
| 45 | #endif | - |
| 46 | } | - |
| 47 | - | |
| 48 | static BLAKE2_INLINE uint64_t load64( const void *src ) | - |
| 49 | { | - |
| 50 | #if defined(NATIVE_LITTLE_ENDIAN) | - |
| 51 | uint64_t w; | - |
| 52 | memcpy(&w, src, sizeof w); | - |
| 53 | return w; | - |
| 54 | #else | - |
| 55 | const uint8_t *p = ( const uint8_t * )src; | - |
| 56 | return (( uint64_t )( p[0] ) << 0) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 57 | (( uint64_t )( p[1] ) << 8) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 58 | (( uint64_t )( p[2] ) << 16) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 59 | (( uint64_t )( p[3] ) << 24) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 60 | (( uint64_t )( p[4] ) << 32) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 61 | (( uint64_t )( p[5] ) << 40) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 62 | (( uint64_t )( p[6] ) << 48) | executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 63 | (( uint64_t )( p[7] ) << 56) ; executed 928 times by 1 test: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) | (( uint64_t )( p[6] ) << 48) | (( uint64_t )( p[7] ) << 56) ;Executed by:
| 928 |
| 64 | #endif | - |
| 65 | } | - |
| 66 | - | |
| 67 | static BLAKE2_INLINE uint16_t load16( const void *src ) | - |
| 68 | { | - |
| 69 | #if defined(NATIVE_LITTLE_ENDIAN) | - |
| 70 | uint16_t w; | - |
| 71 | memcpy(&w, src, sizeof w); | - |
| 72 | return w; | - |
| 73 | #else | - |
| 74 | const uint8_t *p = ( const uint8_t * )src; | - |
| 75 | return (( uint16_t )( p[0] ) << 0) | never executed: return (( uint16_t )( p[0] ) << 0) | (( uint16_t )( p[1] ) << 8) ; | 0 |
| 76 | (( uint16_t )( p[1] ) << 8) ; never executed: return (( uint16_t )( p[0] ) << 0) | (( uint16_t )( p[1] ) << 8) ; | 0 |
| 77 | #endif | - |
| 78 | } | - |
| 79 | - | |
| 80 | static BLAKE2_INLINE void store16( void *dst, uint16_t w ) | - |
| 81 | { | - |
| 82 | #if defined(NATIVE_LITTLE_ENDIAN) | - |
| 83 | memcpy(dst, &w, sizeof w); | - |
| 84 | #else | - |
| 85 | uint8_t *p = ( uint8_t * )dst; | - |
| 86 | *p++ = ( uint8_t )w; w >>= 8; | - |
| 87 | *p++ = ( uint8_t )w; | - |
| 88 | #endif | - |
| 89 | } never executed: end of block | 0 |
| 90 | - | |
| 91 | static BLAKE2_INLINE void store32( void *dst, uint32_t w ) | - |
| 92 | { | - |
| 93 | #if defined(NATIVE_LITTLE_ENDIAN) | - |
| 94 | memcpy(dst, &w, sizeof w); | - |
| 95 | #else | - |
| 96 | uint8_t *p = ( uint8_t * )dst; | - |
| 97 | p[0] = (uint8_t)(w >> 0); | - |
| 98 | p[1] = (uint8_t)(w >> 8); | - |
| 99 | p[2] = (uint8_t)(w >> 16); | - |
| 100 | p[3] = (uint8_t)(w >> 24); | - |
| 101 | #endif | - |
| 102 | } executed 114 times by 1 test: end of blockExecuted by:
| 114 |
| 103 | - | |
| 104 | static BLAKE2_INLINE void store64( void *dst, uint64_t w ) | - |
| 105 | { | - |
| 106 | #if defined(NATIVE_LITTLE_ENDIAN) | - |
| 107 | memcpy(dst, &w, sizeof w); | - |
| 108 | #else | - |
| 109 | uint8_t *p = ( uint8_t * )dst; | - |
| 110 | p[0] = (uint8_t)(w >> 0); | - |
| 111 | p[1] = (uint8_t)(w >> 8); | - |
| 112 | p[2] = (uint8_t)(w >> 16); | - |
| 113 | p[3] = (uint8_t)(w >> 24); | - |
| 114 | p[4] = (uint8_t)(w >> 32); | - |
| 115 | p[5] = (uint8_t)(w >> 40); | - |
| 116 | p[6] = (uint8_t)(w >> 48); | - |
| 117 | p[7] = (uint8_t)(w >> 56); | - |
| 118 | #endif | - |
| 119 | } executed 304 times by 1 test: end of blockExecuted by:
| 304 |
| 120 | - | |
| 121 | static BLAKE2_INLINE uint64_t load48( const void *src ) | - |
| 122 | { | - |
| 123 | const uint8_t *p = ( const uint8_t * )src; | - |
| 124 | return (( uint64_t )( p[0] ) << 0) | never executed: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) ; | 0 |
| 125 | (( uint64_t )( p[1] ) << 8) | never executed: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) ; | 0 |
| 126 | (( uint64_t )( p[2] ) << 16) | never executed: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) ; | 0 |
| 127 | (( uint64_t )( p[3] ) << 24) | never executed: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) ; | 0 |
| 128 | (( uint64_t )( p[4] ) << 32) | never executed: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) ; | 0 |
| 129 | (( uint64_t )( p[5] ) << 40) ; never executed: return (( uint64_t )( p[0] ) << 0) | (( uint64_t )( p[1] ) << 8) | (( uint64_t )( p[2] ) << 16) | (( uint64_t )( p[3] ) << 24) | (( uint64_t )( p[4] ) << 32) | (( uint64_t )( p[5] ) << 40) ; | 0 |
| 130 | } | - |
| 131 | - | |
| 132 | static BLAKE2_INLINE void store48( void *dst, uint64_t w ) | - |
| 133 | { | - |
| 134 | uint8_t *p = ( uint8_t * )dst; | - |
| 135 | p[0] = (uint8_t)(w >> 0); | - |
| 136 | p[1] = (uint8_t)(w >> 8); | - |
| 137 | p[2] = (uint8_t)(w >> 16); | - |
| 138 | p[3] = (uint8_t)(w >> 24); | - |
| 139 | p[4] = (uint8_t)(w >> 32); | - |
| 140 | p[5] = (uint8_t)(w >> 40); | - |
| 141 | } never executed: end of block | 0 |
| 142 | - | |
| 143 | static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c ) | - |
| 144 | { | - |
| 145 | return ( w >> c ) | ( w << ( 32 - c ) ); never executed: return ( w >> c ) | ( w << ( 32 - c ) ); | 0 |
| 146 | } | - |
| 147 | - | |
| 148 | static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c ) | - |
| 149 | { | - |
| 150 | return ( w >> c ) | ( w << ( 64 - c ) ); executed 14976 times by 1 test: return ( w >> c ) | ( w << ( 64 - c ) );Executed by:
| 14976 |
| 151 | } | - |
| 152 | - | |
| 153 | /* prevents compiler optimizing out memset() */ | - |
| 154 | static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n) | - |
| 155 | { | - |
| 156 | static void *(*const volatile memset_v)(void *, int, size_t) = &memset; | - |
| 157 | memset_v(v, 0, n); | - |
| 158 | } executed 38 times by 1 test: end of blockExecuted by:
| 38 |
| 159 | - | |
| 160 | #endif | - |
| Source code | Switch to Preprocessed file |