Coverage Report

Created: 2026-10-16 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/digests/blake2_impl.h
Line
Count
Source
1
/*
2
 * Copyright 2016-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (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
#if !defined(OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H)
18
#define OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H
19
20
#include <string.h>
21
22
#include <openssl/e_os2.h>
23
24
#include "internal/endian.h"
25
26
static ossl_inline uint32_t load32(const uint8_t *src)
27
25.8M
{
28
25.8M
    DECLARE_IS_ENDIAN;
29
30
25.8M
    if (IS_LITTLE_ENDIAN) {
31
25.8M
        uint32_t w;
32
25.8M
        memcpy(&w, src, sizeof(w));
33
25.8M
        return w;
34
25.8M
    } else {
35
0
        uint32_t w = ((uint32_t)src[0])
36
0
            | ((uint32_t)src[1] << 8)
37
0
            | ((uint32_t)src[2] << 16)
38
0
            | ((uint32_t)src[3] << 24);
39
0
        return w;
40
0
    }
41
25.8M
}
Unexecuted instantiation: blake2b_prov.c:load32
blake2s_prov.c:load32
Line
Count
Source
27
25.8M
{
28
25.8M
    DECLARE_IS_ENDIAN;
29
30
25.8M
    if (IS_LITTLE_ENDIAN) {
31
25.8M
        uint32_t w;
32
25.8M
        memcpy(&w, src, sizeof(w));
33
25.8M
        return w;
34
25.8M
    } else {
35
0
        uint32_t w = ((uint32_t)src[0])
36
0
            | ((uint32_t)src[1] << 8)
37
0
            | ((uint32_t)src[2] << 16)
38
0
            | ((uint32_t)src[3] << 24);
39
0
        return w;
40
0
    }
41
25.8M
}
42
43
static ossl_inline uint64_t load64(const uint8_t *src)
44
15.2M
{
45
15.2M
    DECLARE_IS_ENDIAN;
46
47
15.2M
    if (IS_LITTLE_ENDIAN) {
48
15.2M
        uint64_t w;
49
15.2M
        memcpy(&w, src, sizeof(w));
50
15.2M
        return w;
51
15.2M
    } else {
52
0
        uint64_t w = ((uint64_t)src[0])
53
0
            | ((uint64_t)src[1] << 8)
54
0
            | ((uint64_t)src[2] << 16)
55
0
            | ((uint64_t)src[3] << 24)
56
0
            | ((uint64_t)src[4] << 32)
57
0
            | ((uint64_t)src[5] << 40)
58
0
            | ((uint64_t)src[6] << 48)
59
0
            | ((uint64_t)src[7] << 56);
60
0
        return w;
61
0
    }
62
15.2M
}
blake2b_prov.c:load64
Line
Count
Source
44
15.2M
{
45
15.2M
    DECLARE_IS_ENDIAN;
46
47
15.2M
    if (IS_LITTLE_ENDIAN) {
48
15.2M
        uint64_t w;
49
15.2M
        memcpy(&w, src, sizeof(w));
50
15.2M
        return w;
51
15.2M
    } else {
52
0
        uint64_t w = ((uint64_t)src[0])
53
0
            | ((uint64_t)src[1] << 8)
54
0
            | ((uint64_t)src[2] << 16)
55
0
            | ((uint64_t)src[3] << 24)
56
0
            | ((uint64_t)src[4] << 32)
57
0
            | ((uint64_t)src[5] << 40)
58
0
            | ((uint64_t)src[6] << 48)
59
0
            | ((uint64_t)src[7] << 56);
60
0
        return w;
61
0
    }
62
15.2M
}
Unexecuted instantiation: blake2s_prov.c:load64
63
64
static ossl_inline void store32(uint8_t *dst, uint32_t w)
65
828
{
66
828
    DECLARE_IS_ENDIAN;
67
68
828
    if (IS_LITTLE_ENDIAN) {
69
828
        memcpy(dst, &w, sizeof(w));
70
828
    } else {
71
0
        uint8_t *p = (uint8_t *)dst;
72
0
        int i;
73
74
0
        for (i = 0; i < 4; i++)
75
0
            p[i] = (uint8_t)(w >> (8 * i));
76
0
    }
77
828
}
blake2b_prov.c:store32
Line
Count
Source
65
148
{
66
148
    DECLARE_IS_ENDIAN;
67
68
148
    if (IS_LITTLE_ENDIAN) {
69
148
        memcpy(dst, &w, sizeof(w));
70
148
    } else {
71
0
        uint8_t *p = (uint8_t *)dst;
72
0
        int i;
73
74
0
        for (i = 0; i < 4; i++)
75
0
            p[i] = (uint8_t)(w >> (8 * i));
76
0
    }
77
148
}
blake2s_prov.c:store32
Line
Count
Source
65
680
{
66
680
    DECLARE_IS_ENDIAN;
67
68
680
    if (IS_LITTLE_ENDIAN) {
69
680
        memcpy(dst, &w, sizeof(w));
70
680
    } else {
71
0
        uint8_t *p = (uint8_t *)dst;
72
0
        int i;
73
74
0
        for (i = 0; i < 4; i++)
75
0
            p[i] = (uint8_t)(w >> (8 * i));
76
0
    }
77
680
}
78
79
static ossl_inline void store64(uint8_t *dst, uint64_t w)
80
740
{
81
740
    DECLARE_IS_ENDIAN;
82
83
740
    if (IS_LITTLE_ENDIAN) {
84
740
        memcpy(dst, &w, sizeof(w));
85
740
    } else {
86
0
        uint8_t *p = (uint8_t *)dst;
87
0
        int i;
88
89
0
        for (i = 0; i < 8; i++)
90
0
            p[i] = (uint8_t)(w >> (8 * i));
91
0
    }
92
740
}
blake2b_prov.c:store64
Line
Count
Source
80
740
{
81
740
    DECLARE_IS_ENDIAN;
82
83
740
    if (IS_LITTLE_ENDIAN) {
84
740
        memcpy(dst, &w, sizeof(w));
85
740
    } else {
86
0
        uint8_t *p = (uint8_t *)dst;
87
0
        int i;
88
89
0
        for (i = 0; i < 8; i++)
90
0
            p[i] = (uint8_t)(w >> (8 * i));
91
0
    }
92
740
}
Unexecuted instantiation: blake2s_prov.c:store64
93
94
static ossl_inline uint64_t load48(const uint8_t *src)
95
0
{
96
0
    uint64_t w = ((uint64_t)src[0])
97
0
        | ((uint64_t)src[1] << 8)
98
0
        | ((uint64_t)src[2] << 16)
99
0
        | ((uint64_t)src[3] << 24)
100
0
        | ((uint64_t)src[4] << 32)
101
0
        | ((uint64_t)src[5] << 40);
102
0
    return w;
103
0
}
Unexecuted instantiation: blake2b_prov.c:load48
Unexecuted instantiation: blake2s_prov.c:load48
104
105
static ossl_inline void store48(uint8_t *dst, uint64_t w)
106
136
{
107
136
    uint8_t *p = (uint8_t *)dst;
108
136
    p[0] = (uint8_t)w;
109
136
    p[1] = (uint8_t)(w >> 8);
110
136
    p[2] = (uint8_t)(w >> 16);
111
136
    p[3] = (uint8_t)(w >> 24);
112
136
    p[4] = (uint8_t)(w >> 32);
113
136
    p[5] = (uint8_t)(w >> 40);
114
136
}
Unexecuted instantiation: blake2b_prov.c:store48
blake2s_prov.c:store48
Line
Count
Source
106
136
{
107
136
    uint8_t *p = (uint8_t *)dst;
108
136
    p[0] = (uint8_t)w;
109
136
    p[1] = (uint8_t)(w >> 8);
110
136
    p[2] = (uint8_t)(w >> 16);
111
136
    p[3] = (uint8_t)(w >> 24);
112
136
    p[4] = (uint8_t)(w >> 32);
113
136
    p[5] = (uint8_t)(w >> 40);
114
136
}
115
116
static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c)
117
516M
{
118
516M
    return (w >> c) | (w << (32 - c));
119
516M
}
Unexecuted instantiation: blake2b_prov.c:rotr32
blake2s_prov.c:rotr32
Line
Count
Source
117
516M
{
118
516M
    return (w >> c) | (w << (32 - c));
119
516M
}
120
121
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
122
366M
{
123
366M
    return (w >> c) | (w << (64 - c));
124
366M
}
blake2b_prov.c:rotr64
Line
Count
Source
122
366M
{
123
366M
    return (w >> c) | (w << (64 - c));
124
366M
}
Unexecuted instantiation: blake2s_prov.c:rotr64
125
126
#endif /* !defined(OSSL_PROVIDERS_IMPLEMENTATIONS_DIGESTS_BLAKE2_IMPL_H) */