Coverage Report

Created: 2024-11-21 07:03

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