Coverage Report

Created: 2025-08-28 06:41

/src/openssl/providers/implementations/digests/blake2_impl.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2016-2020 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
#include <string.h>
18
#include "internal/endian.h"
19
20
static ossl_inline uint32_t load32(const uint8_t *src)
21
32.3M
{
22
32.3M
    DECLARE_IS_ENDIAN;
23
24
32.3M
    if (IS_LITTLE_ENDIAN) {
25
32.3M
        uint32_t w;
26
32.3M
        memcpy(&w, src, sizeof(w));
27
32.3M
        return w;
28
32.3M
    } else {
29
0
        uint32_t w = ((uint32_t)src[0])
30
0
                   | ((uint32_t)src[1] <<  8)
31
0
                   | ((uint32_t)src[2] << 16)
32
0
                   | ((uint32_t)src[3] << 24);
33
0
        return w;
34
0
    }
35
32.3M
}
Unexecuted instantiation: blake2b_prov.c:load32
blake2s_prov.c:load32
Line
Count
Source
21
32.3M
{
22
32.3M
    DECLARE_IS_ENDIAN;
23
24
32.3M
    if (IS_LITTLE_ENDIAN) {
25
32.3M
        uint32_t w;
26
32.3M
        memcpy(&w, src, sizeof(w));
27
32.3M
        return w;
28
32.3M
    } else {
29
0
        uint32_t w = ((uint32_t)src[0])
30
0
                   | ((uint32_t)src[1] <<  8)
31
0
                   | ((uint32_t)src[2] << 16)
32
0
                   | ((uint32_t)src[3] << 24);
33
0
        return w;
34
0
    }
35
32.3M
}
36
37
static ossl_inline uint64_t load64(const uint8_t *src)
38
15.0M
{
39
15.0M
    DECLARE_IS_ENDIAN;
40
41
15.0M
    if (IS_LITTLE_ENDIAN) {
42
15.0M
        uint64_t w;
43
15.0M
        memcpy(&w, src, sizeof(w));
44
15.0M
        return w;
45
15.0M
    } else {
46
0
        uint64_t w = ((uint64_t)src[0])
47
0
                   | ((uint64_t)src[1] <<  8)
48
0
                   | ((uint64_t)src[2] << 16)
49
0
                   | ((uint64_t)src[3] << 24)
50
0
                   | ((uint64_t)src[4] << 32)
51
0
                   | ((uint64_t)src[5] << 40)
52
0
                   | ((uint64_t)src[6] << 48)
53
0
                   | ((uint64_t)src[7] << 56);
54
0
        return w;
55
0
    }
56
15.0M
}
blake2b_prov.c:load64
Line
Count
Source
38
15.0M
{
39
15.0M
    DECLARE_IS_ENDIAN;
40
41
15.0M
    if (IS_LITTLE_ENDIAN) {
42
15.0M
        uint64_t w;
43
15.0M
        memcpy(&w, src, sizeof(w));
44
15.0M
        return w;
45
15.0M
    } else {
46
0
        uint64_t w = ((uint64_t)src[0])
47
0
                   | ((uint64_t)src[1] <<  8)
48
0
                   | ((uint64_t)src[2] << 16)
49
0
                   | ((uint64_t)src[3] << 24)
50
0
                   | ((uint64_t)src[4] << 32)
51
0
                   | ((uint64_t)src[5] << 40)
52
0
                   | ((uint64_t)src[6] << 48)
53
0
                   | ((uint64_t)src[7] << 56);
54
0
        return w;
55
0
    }
56
15.0M
}
Unexecuted instantiation: blake2s_prov.c:load64
57
58
static ossl_inline void store32(uint8_t *dst, uint32_t w)
59
930
{
60
930
    DECLARE_IS_ENDIAN;
61
62
930
    if (IS_LITTLE_ENDIAN) {
63
930
        memcpy(dst, &w, sizeof(w));
64
930
    } else {
65
0
        uint8_t *p = (uint8_t *)dst;
66
0
        int i;
67
68
0
        for (i = 0; i < 4; i++)
69
0
            p[i] = (uint8_t)(w >> (8 * i));
70
0
    }
71
930
}
blake2b_prov.c:store32
Line
Count
Source
59
130
{
60
130
    DECLARE_IS_ENDIAN;
61
62
130
    if (IS_LITTLE_ENDIAN) {
63
130
        memcpy(dst, &w, sizeof(w));
64
130
    } else {
65
0
        uint8_t *p = (uint8_t *)dst;
66
0
        int i;
67
68
0
        for (i = 0; i < 4; i++)
69
0
            p[i] = (uint8_t)(w >> (8 * i));
70
0
    }
71
130
}
blake2s_prov.c:store32
Line
Count
Source
59
800
{
60
800
    DECLARE_IS_ENDIAN;
61
62
800
    if (IS_LITTLE_ENDIAN) {
63
800
        memcpy(dst, &w, sizeof(w));
64
800
    } else {
65
0
        uint8_t *p = (uint8_t *)dst;
66
0
        int i;
67
68
0
        for (i = 0; i < 4; i++)
69
0
            p[i] = (uint8_t)(w >> (8 * i));
70
0
    }
71
800
}
72
73
static ossl_inline void store64(uint8_t *dst, uint64_t w)
74
650
{
75
650
    DECLARE_IS_ENDIAN;
76
77
650
    if (IS_LITTLE_ENDIAN) {
78
650
        memcpy(dst, &w, sizeof(w));
79
650
    } else {
80
0
        uint8_t *p = (uint8_t *)dst;
81
0
        int i;
82
83
0
        for (i = 0; i < 8; i++)
84
0
            p[i] = (uint8_t)(w >> (8 * i));
85
0
    }
86
650
}
blake2b_prov.c:store64
Line
Count
Source
74
650
{
75
650
    DECLARE_IS_ENDIAN;
76
77
650
    if (IS_LITTLE_ENDIAN) {
78
650
        memcpy(dst, &w, sizeof(w));
79
650
    } else {
80
0
        uint8_t *p = (uint8_t *)dst;
81
0
        int i;
82
83
0
        for (i = 0; i < 8; i++)
84
0
            p[i] = (uint8_t)(w >> (8 * i));
85
0
    }
86
650
}
Unexecuted instantiation: blake2s_prov.c:store64
87
88
static ossl_inline uint64_t load48(const uint8_t *src)
89
0
{
90
0
    uint64_t w = ((uint64_t)src[0])
91
0
               | ((uint64_t)src[1] <<  8)
92
0
               | ((uint64_t)src[2] << 16)
93
0
               | ((uint64_t)src[3] << 24)
94
0
               | ((uint64_t)src[4] << 32)
95
0
               | ((uint64_t)src[5] << 40);
96
0
    return w;
97
0
}
Unexecuted instantiation: blake2b_prov.c:load48
Unexecuted instantiation: blake2s_prov.c:load48
98
99
static ossl_inline void store48(uint8_t *dst, uint64_t w)
100
160
{
101
160
    uint8_t *p = (uint8_t *)dst;
102
160
    p[0] = (uint8_t)w;
103
160
    p[1] = (uint8_t)(w>>8);
104
160
    p[2] = (uint8_t)(w>>16);
105
160
    p[3] = (uint8_t)(w>>24);
106
160
    p[4] = (uint8_t)(w>>32);
107
160
    p[5] = (uint8_t)(w>>40);
108
160
}
Unexecuted instantiation: blake2b_prov.c:store48
blake2s_prov.c:store48
Line
Count
Source
100
160
{
101
160
    uint8_t *p = (uint8_t *)dst;
102
160
    p[0] = (uint8_t)w;
103
160
    p[1] = (uint8_t)(w>>8);
104
160
    p[2] = (uint8_t)(w>>16);
105
160
    p[3] = (uint8_t)(w>>24);
106
160
    p[4] = (uint8_t)(w>>32);
107
160
    p[5] = (uint8_t)(w>>40);
108
160
}
109
110
static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c)
111
647M
{
112
647M
    return (w >> c) | (w << (32 - c));
113
647M
}
Unexecuted instantiation: blake2b_prov.c:rotr32
blake2s_prov.c:rotr32
Line
Count
Source
111
647M
{
112
647M
    return (w >> c) | (w << (32 - c));
113
647M
}
114
115
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
116
361M
{
117
361M
    return (w >> c) | (w << (64 - c));
118
361M
}
blake2b_prov.c:rotr64
Line
Count
Source
116
361M
{
117
361M
    return (w >> c) | (w << (64 - c));
118
361M
}
Unexecuted instantiation: blake2s_prov.c:rotr64