Coverage Report

Created: 2025-06-13 06:58

/src/openssl32/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
87.9k
{
22
87.9k
    DECLARE_IS_ENDIAN;
23
24
87.9k
    if (IS_LITTLE_ENDIAN) {
25
87.9k
        uint32_t w;
26
87.9k
        memcpy(&w, src, sizeof(w));
27
87.9k
        return w;
28
87.9k
    } 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
87.9k
}
Unexecuted instantiation: blake2b_prov.c:load32
blake2s_prov.c:load32
Line
Count
Source
21
87.9k
{
22
87.9k
    DECLARE_IS_ENDIAN;
23
24
87.9k
    if (IS_LITTLE_ENDIAN) {
25
87.9k
        uint32_t w;
26
87.9k
        memcpy(&w, src, sizeof(w));
27
87.9k
        return w;
28
87.9k
    } 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
87.9k
}
36
37
static ossl_inline uint64_t load64(const uint8_t *src)
38
1.51M
{
39
1.51M
    DECLARE_IS_ENDIAN;
40
41
1.51M
    if (IS_LITTLE_ENDIAN) {
42
1.51M
        uint64_t w;
43
1.51M
        memcpy(&w, src, sizeof(w));
44
1.51M
        return w;
45
1.51M
    } 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
1.51M
}
blake2b_prov.c:load64
Line
Count
Source
38
1.51M
{
39
1.51M
    DECLARE_IS_ENDIAN;
40
41
1.51M
    if (IS_LITTLE_ENDIAN) {
42
1.51M
        uint64_t w;
43
1.51M
        memcpy(&w, src, sizeof(w));
44
1.51M
        return w;
45
1.51M
    } 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
1.51M
}
Unexecuted instantiation: blake2s_prov.c:load64
57
58
static ossl_inline void store32(uint8_t *dst, uint32_t w)
59
40.4k
{
60
40.4k
    DECLARE_IS_ENDIAN;
61
62
40.4k
    if (IS_LITTLE_ENDIAN) {
63
40.4k
        memcpy(dst, &w, sizeof(w));
64
40.4k
    } 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
40.4k
}
blake2b_prov.c:store32
Line
Count
Source
59
27.7k
{
60
27.7k
    DECLARE_IS_ENDIAN;
61
62
27.7k
    if (IS_LITTLE_ENDIAN) {
63
27.7k
        memcpy(dst, &w, sizeof(w));
64
27.7k
    } 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
27.7k
}
blake2s_prov.c:store32
Line
Count
Source
59
12.6k
{
60
12.6k
    DECLARE_IS_ENDIAN;
61
62
12.6k
    if (IS_LITTLE_ENDIAN) {
63
12.6k
        memcpy(dst, &w, sizeof(w));
64
12.6k
    } 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
12.6k
}
72
73
static ossl_inline void store64(uint8_t *dst, uint64_t w)
74
255k
{
75
255k
    DECLARE_IS_ENDIAN;
76
77
255k
    if (IS_LITTLE_ENDIAN) {
78
255k
        memcpy(dst, &w, sizeof(w));
79
255k
    } 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
255k
}
blake2b_prov.c:store64
Line
Count
Source
74
255k
{
75
255k
    DECLARE_IS_ENDIAN;
76
77
255k
    if (IS_LITTLE_ENDIAN) {
78
255k
        memcpy(dst, &w, sizeof(w));
79
255k
    } 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
255k
}
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
605
{
101
605
    uint8_t *p = (uint8_t *)dst;
102
605
    p[0] = (uint8_t)w;
103
605
    p[1] = (uint8_t)(w>>8);
104
605
    p[2] = (uint8_t)(w>>16);
105
605
    p[3] = (uint8_t)(w>>24);
106
605
    p[4] = (uint8_t)(w>>32);
107
605
    p[5] = (uint8_t)(w>>40);
108
605
}
Unexecuted instantiation: blake2b_prov.c:store48
blake2s_prov.c:store48
Line
Count
Source
100
605
{
101
605
    uint8_t *p = (uint8_t *)dst;
102
605
    p[0] = (uint8_t)w;
103
605
    p[1] = (uint8_t)(w>>8);
104
605
    p[2] = (uint8_t)(w>>16);
105
605
    p[3] = (uint8_t)(w>>24);
106
605
    p[4] = (uint8_t)(w>>32);
107
605
    p[5] = (uint8_t)(w>>40);
108
605
}
109
110
static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c)
111
1.52M
{
112
1.52M
    return (w >> c) | (w << (32 - c));
113
1.52M
}
Unexecuted instantiation: blake2b_prov.c:rotr32
blake2s_prov.c:rotr32
Line
Count
Source
111
1.52M
{
112
1.52M
    return (w >> c) | (w << (32 - c));
113
1.52M
}
114
115
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
116
30.9M
{
117
30.9M
    return (w >> c) | (w << (64 - c));
118
30.9M
}
blake2b_prov.c:rotr64
Line
Count
Source
116
30.9M
{
117
30.9M
    return (w >> c) | (w << (64 - c));
118
30.9M
}
Unexecuted instantiation: blake2s_prov.c:rotr64