Coverage Report

Created: 2023-06-08 06:40

/src/openssl111/crypto/blake2/blake2_impl.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the OpenSSL license (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/*
11
 * Derived from the BLAKE2 reference implementation written by Samuel Neves.
12
 * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
13
 * More information about the BLAKE2 hash function and its implementations
14
 * can be found at https://blake2.net.
15
 */
16
17
#include <string.h>
18
19
static ossl_inline uint32_t load32(const uint8_t *src)
20
0
{
21
0
    const union {
22
0
        long one;
23
0
        char little;
24
0
    } is_endian = { 1 };
25
26
0
    if (is_endian.little) {
27
0
        uint32_t w;
28
0
        memcpy(&w, src, sizeof(w));
29
0
        return w;
30
0
    } else {
31
0
        uint32_t w = ((uint32_t)src[0])
32
0
                   | ((uint32_t)src[1] <<  8)
33
0
                   | ((uint32_t)src[2] << 16)
34
0
                   | ((uint32_t)src[3] << 24);
35
0
        return w;
36
0
    }
37
0
}
Unexecuted instantiation: blake2b.c:load32
Unexecuted instantiation: blake2s.c:load32
38
39
static ossl_inline uint64_t load64(const uint8_t *src)
40
0
{
41
0
    const union {
42
0
        long one;
43
0
        char little;
44
0
    } is_endian = { 1 };
45
46
0
    if (is_endian.little) {
47
0
        uint64_t w;
48
0
        memcpy(&w, src, sizeof(w));
49
0
        return w;
50
0
    } else {
51
0
        uint64_t w = ((uint64_t)src[0])
52
0
                   | ((uint64_t)src[1] <<  8)
53
0
                   | ((uint64_t)src[2] << 16)
54
0
                   | ((uint64_t)src[3] << 24)
55
0
                   | ((uint64_t)src[4] << 32)
56
0
                   | ((uint64_t)src[5] << 40)
57
0
                   | ((uint64_t)src[6] << 48)
58
0
                   | ((uint64_t)src[7] << 56);
59
0
        return w;
60
0
    }
61
0
}
Unexecuted instantiation: blake2b.c:load64
Unexecuted instantiation: blake2s.c:load64
62
63
static ossl_inline void store32(uint8_t *dst, uint32_t w)
64
0
{
65
0
    const union {
66
0
        long one;
67
0
        char little;
68
0
    } is_endian = { 1 };
69
70
0
    if (is_endian.little) {
71
0
        memcpy(dst, &w, sizeof(w));
72
0
    } else {
73
0
        uint8_t *p = (uint8_t *)dst;
74
0
        int i;
75
76
0
        for (i = 0; i < 4; i++)
77
0
            p[i] = (uint8_t)(w >> (8 * i));
78
0
    }
79
0
}
Unexecuted instantiation: blake2b.c:store32
Unexecuted instantiation: blake2s.c:store32
80
81
static ossl_inline void store64(uint8_t *dst, uint64_t w)
82
0
{
83
0
    const union {
84
0
        long one;
85
0
        char little;
86
0
    } is_endian = { 1 };
87
88
0
    if (is_endian.little) {
89
0
        memcpy(dst, &w, sizeof(w));
90
0
    } else {
91
0
        uint8_t *p = (uint8_t *)dst;
92
0
        int i;
93
94
0
        for (i = 0; i < 8; i++)
95
0
            p[i] = (uint8_t)(w >> (8 * i));
96
0
    }
97
0
}
Unexecuted instantiation: blake2b.c:store64
Unexecuted instantiation: blake2s.c:store64
98
99
static ossl_inline uint64_t load48(const uint8_t *src)
100
0
{
101
0
    uint64_t w = ((uint64_t)src[0])
102
0
               | ((uint64_t)src[1] <<  8)
103
0
               | ((uint64_t)src[2] << 16)
104
0
               | ((uint64_t)src[3] << 24)
105
0
               | ((uint64_t)src[4] << 32)
106
0
               | ((uint64_t)src[5] << 40);
107
0
    return w;
108
0
}
Unexecuted instantiation: blake2b.c:load48
Unexecuted instantiation: blake2s.c:load48
109
110
static ossl_inline void store48(uint8_t *dst, uint64_t w)
111
0
{
112
0
    uint8_t *p = (uint8_t *)dst;
113
0
    p[0] = (uint8_t)w;
114
0
    p[1] = (uint8_t)(w>>8);
115
0
    p[2] = (uint8_t)(w>>16);
116
0
    p[3] = (uint8_t)(w>>24);
117
0
    p[4] = (uint8_t)(w>>32);
118
0
    p[5] = (uint8_t)(w>>40);
119
0
}
Unexecuted instantiation: blake2b.c:store48
Unexecuted instantiation: blake2s.c:store48
120
121
static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c)
122
0
{
123
0
    return (w >> c) | (w << (32 - c));
124
0
}
Unexecuted instantiation: blake2b.c:rotr32
Unexecuted instantiation: blake2s.c:rotr32
125
126
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
127
0
{
128
0
    return (w >> c) | (w << (64 - c));
129
0
}
Unexecuted instantiation: blake2b.c:rotr64
Unexecuted instantiation: blake2s.c:rotr64