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