Bug Summary

File:out/../deps/openssl/openssl/providers/implementations/macs/gmac_prov.c
Warning:line 215, column 10
Although the value stored to 'p' is used in the enclosing expression, the value is never actually read from 'p'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gmac_prov.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D OPENSSL_NO_HW -D OPENSSL_API_COMPAT=0x10100001L -D STATIC_LEGACY -D NDEBUG -D OPENSSL_USE_NODELETE -D L_ENDIAN -D OPENSSL_BUILDING_OPENSSL -D AES_ASM -D BSAES_ASM -D CMLL_ASM -D ECP_NISTZ256_ASM -D GHASH_ASM -D KECCAK1600_ASM -D MD5_ASM -D OPENSSL_BN_ASM_GF2m -D OPENSSL_BN_ASM_MONT -D OPENSSL_BN_ASM_MONT5 -D OPENSSL_CPUID_OBJ -D OPENSSL_IA32_SSE2 -D PADLOCK_ASM -D POLY1305_ASM -D SHA1_ASM -D SHA256_ASM -D SHA512_ASM -D VPAES_ASM -D WHIRLPOOL_ASM -D X25519_ASM -D OPENSSL_PIC -D MODULESDIR="/home/maurizio/node-v18.6.0/out/Release/obj.target/deps/openssl/lib/openssl-modules" -D OPENSSLDIR="/home/maurizio/node-v18.6.0/out/Release/obj.target/deps/openssl" -D OPENSSLDIR="/etc/ssl" -D ENGINESDIR="/dev/null" -D TERMIOS -I ../deps/openssl/openssl -I ../deps/openssl/openssl/include -I ../deps/openssl/openssl/crypto -I ../deps/openssl/openssl/crypto/include -I ../deps/openssl/openssl/crypto/modes -I ../deps/openssl/openssl/crypto/ec/curve448 -I ../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I ../deps/openssl/openssl/providers/common/include -I ../deps/openssl/openssl/providers/implementations/include -I ../deps/openssl/config -I ../deps/openssl/config/archs/linux-x86_64/asm -I ../deps/openssl/config/archs/linux-x86_64/asm/include -I ../deps/openssl/config/archs/linux-x86_64/asm/crypto -I ../deps/openssl/config/archs/linux-x86_64/asm/crypto/include/internal -I ../deps/openssl/config/archs/linux-x86_64/asm/providers/common/include -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-missing-field-initializers -Wno-old-style-declaration -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c ../deps/openssl/openssl/providers/implementations/macs/gmac_prov.c
1/*
2 * Copyright 2018-2022 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#include <stdlib.h>
11#include <openssl/core_dispatch.h>
12#include <openssl/core_names.h>
13#include <openssl/params.h>
14#include <openssl/evp.h>
15#include <openssl/err.h>
16#include <openssl/proverr.h>
17
18#include "prov/implementations.h"
19#include "prov/provider_ctx.h"
20#include "prov/provider_util.h"
21#include "prov/providercommon.h"
22
23/*
24 * Forward declaration of everything implemented here. This is not strictly
25 * necessary for the compiler, but provides an assurance that the signatures
26 * of the functions in the dispatch table are correct.
27 */
28static OSSL_FUNC_mac_newctx_fn gmac_new;
29static OSSL_FUNC_mac_dupctx_fn gmac_dup;
30static OSSL_FUNC_mac_freectx_fn gmac_free;
31static OSSL_FUNC_mac_gettable_params_fn gmac_gettable_params;
32static OSSL_FUNC_mac_get_params_fn gmac_get_params;
33static OSSL_FUNC_mac_settable_ctx_params_fn gmac_settable_ctx_params;
34static OSSL_FUNC_mac_set_ctx_params_fn gmac_set_ctx_params;
35static OSSL_FUNC_mac_init_fn gmac_init;
36static OSSL_FUNC_mac_update_fn gmac_update;
37static OSSL_FUNC_mac_final_fn gmac_final;
38
39/* local GMAC pkey structure */
40
41struct gmac_data_st {
42 void *provctx;
43 EVP_CIPHER_CTX *ctx; /* Cipher context */
44 PROV_CIPHER cipher;
45};
46
47static void gmac_free(void *vmacctx)
48{
49 struct gmac_data_st *macctx = vmacctx;
50
51 if (macctx != NULL((void*)0)) {
52 EVP_CIPHER_CTX_free(macctx->ctx);
53 ossl_prov_cipher_reset(&macctx->cipher);
54 OPENSSL_free(macctx)CRYPTO_free(macctx, "../deps/openssl/openssl/providers/implementations/macs/gmac_prov.c"
, 54)
;
55 }
56}
57
58static void *gmac_new(void *provctx)
59{
60 struct gmac_data_st *macctx;
61
62 if (!ossl_prov_is_running())
63 return NULL((void*)0);
64
65 if ((macctx = OPENSSL_zalloc(sizeof(*macctx))CRYPTO_zalloc(sizeof(*macctx), "../deps/openssl/openssl/providers/implementations/macs/gmac_prov.c"
, 65)
) == NULL((void*)0)
66 || (macctx->ctx = EVP_CIPHER_CTX_new()) == NULL((void*)0)) {
67 gmac_free(macctx);
68 return NULL((void*)0);
69 }
70 macctx->provctx = provctx;
71
72 return macctx;
73}
74
75static void *gmac_dup(void *vsrc)
76{
77 struct gmac_data_st *src = vsrc;
78 struct gmac_data_st *dst;
79
80 if (!ossl_prov_is_running())
81 return NULL((void*)0);
82
83 dst = gmac_new(src->provctx);
84 if (dst == NULL((void*)0))
85 return NULL((void*)0);
86
87 if (!EVP_CIPHER_CTX_copy(dst->ctx, src->ctx)
88 || !ossl_prov_cipher_copy(&dst->cipher, &src->cipher)) {
89 gmac_free(dst);
90 return NULL((void*)0);
91 }
92 return dst;
93}
94
95static size_t gmac_size(void)
96{
97 return EVP_GCM_TLS_TAG_LEN16;
98}
99
100static int gmac_setkey(struct gmac_data_st *macctx,
101 const unsigned char *key, size_t keylen)
102{
103 EVP_CIPHER_CTX *ctx = macctx->ctx;
104
105 if (keylen != (size_t)EVP_CIPHER_CTX_get_key_length(ctx)) {
106 ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/providers/implementations/macs/gmac_prov.c"
,106,__func__), ERR_set_error)((57),(105),((void*)0))
;
107 return 0;
108 }
109 if (!EVP_EncryptInit_ex(ctx, NULL((void*)0), NULL((void*)0), key, NULL((void*)0)))
110 return 0;
111 return 1;
112}
113
114static int gmac_init(void *vmacctx, const unsigned char *key,
115 size_t keylen, const OSSL_PARAM params[])
116{
117 struct gmac_data_st *macctx = vmacctx;
118
119 if (!ossl_prov_is_running() || !gmac_set_ctx_params(macctx, params))
120 return 0;
121 if (key != NULL((void*)0))
122 return gmac_setkey(macctx, key, keylen);
123 return EVP_EncryptInit_ex(macctx->ctx, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
124}
125
126static int gmac_update(void *vmacctx, const unsigned char *data,
127 size_t datalen)
128{
129 struct gmac_data_st *macctx = vmacctx;
130 EVP_CIPHER_CTX *ctx = macctx->ctx;
131 int outlen;
132
133 if (datalen == 0)
134 return 1;
135
136 while (datalen > INT_MAX2147483647) {
137 if (!EVP_EncryptUpdate(ctx, NULL((void*)0), &outlen, data, INT_MAX2147483647))
138 return 0;
139 data += INT_MAX2147483647;
140 datalen -= INT_MAX2147483647;
141 }
142 return EVP_EncryptUpdate(ctx, NULL((void*)0), &outlen, data, datalen);
143}
144
145static int gmac_final(void *vmacctx, unsigned char *out, size_t *outl,
146 size_t outsize)
147{
148 OSSL_PARAM params[2] = { OSSL_PARAM_END{ ((void*)0), 0, ((void*)0), 0, 0 }, OSSL_PARAM_END{ ((void*)0), 0, ((void*)0), 0, 0 } };
149 struct gmac_data_st *macctx = vmacctx;
150 int hlen = 0;
151
152 if (!ossl_prov_is_running())
153 return 0;
154
155 if (!EVP_EncryptFinal_ex(macctx->ctx, out, &hlen))
156 return 0;
157
158 hlen = gmac_size();
159 params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG"tag",
160 out, (size_t)hlen);
161 if (!EVP_CIPHER_CTX_get_params(macctx->ctx, params))
162 return 0;
163
164 *outl = hlen;
165 return 1;
166}
167
168static const OSSL_PARAM known_gettable_params[] = {
169 OSSL_PARAM_size_t(OSSL_MAC_PARAM_SIZE, NULL){ (("size")), (2), ((((void*)0))), (sizeof(size_t)), ((size_t
)-1) }
,
170 OSSL_PARAM_END{ ((void*)0), 0, ((void*)0), 0, 0 }
171};
172static const OSSL_PARAM *gmac_gettable_params(void *provctx)
173{
174 return known_gettable_params;
175}
176
177static int gmac_get_params(OSSL_PARAM params[])
178{
179 OSSL_PARAM *p;
180
181 if ((p = OSSL_PARAM_locate(params, OSSL_MAC_PARAM_SIZE"size")) != NULL((void*)0))
182 return OSSL_PARAM_set_size_t(p, gmac_size());
183
184 return 1;
185}
186
187static const OSSL_PARAM known_settable_ctx_params[] = {
188 OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_CIPHER, NULL, 0){ (("cipher")), (4), ((((void*)0))), (0), ((size_t)-1) },
189 OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_PROPERTIES, NULL, 0){ (("properties")), (4), ((((void*)0))), (0), ((size_t)-1) },
190 OSSL_PARAM_octet_string(OSSL_MAC_PARAM_KEY, NULL, 0){ (("key")), (5), ((((void*)0))), (0), ((size_t)-1) },
191 OSSL_PARAM_octet_string(OSSL_MAC_PARAM_IV, NULL, 0){ (("iv")), (5), ((((void*)0))), (0), ((size_t)-1) },
192 OSSL_PARAM_END{ ((void*)0), 0, ((void*)0), 0, 0 }
193};
194static const OSSL_PARAM *gmac_settable_ctx_params(ossl_unused__attribute__((unused)) void *ctx,
195 ossl_unused__attribute__((unused)) void *provctx)
196{
197 return known_settable_ctx_params;
198}
199
200/*
201 * ALL parameters should be set before init().
202 */
203static int gmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
204{
205 struct gmac_data_st *macctx = vmacctx;
206 EVP_CIPHER_CTX *ctx = macctx->ctx;
207 OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(macctx->provctx)ossl_prov_ctx_get0_libctx((macctx->provctx));
208 const OSSL_PARAM *p;
209
210 if (params == NULL((void*)0))
211 return 1;
212 if (ctx == NULL((void*)0))
213 return 0;
214
215 if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CIPHER"cipher")) != NULL((void*)0)) {
Although the value stored to 'p' is used in the enclosing expression, the value is never actually read from 'p'
216 if (!ossl_prov_cipher_load_from_params(&macctx->cipher, params, provctx))
217 return 0;
218 if (EVP_CIPHER_get_mode(ossl_prov_cipher_cipher(&macctx->cipher))
219 != EVP_CIPH_GCM_MODE0x6) {
220 ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_MODE)(ERR_new(), ERR_set_debug("../deps/openssl/openssl/providers/implementations/macs/gmac_prov.c"
,220,__func__), ERR_set_error)((57),(125),((void*)0))
;
221 return 0;
222 }
223 if (!EVP_EncryptInit_ex(ctx, ossl_prov_cipher_cipher(&macctx->cipher),
224 ossl_prov_cipher_engine(&macctx->cipher), NULL((void*)0),
225 NULL((void*)0)))
226 return 0;
227 }
228
229 if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY"key")) != NULL((void*)0))
230 if (p->data_type != OSSL_PARAM_OCTET_STRING5
231 || !gmac_setkey(macctx, p->data, p->data_size))
232 return 0;
233
234 if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_IV"iv")) != NULL((void*)0)) {
235 if (p->data_type != OSSL_PARAM_OCTET_STRING5)
236 return 0;
237
238 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN0x9,
239 p->data_size, NULL((void*)0)) <= 0
240 || !EVP_EncryptInit_ex(ctx, NULL((void*)0), NULL((void*)0), NULL((void*)0), p->data))
241 return 0;
242 }
243 return 1;
244}
245
246const OSSL_DISPATCH ossl_gmac_functions[] = {
247 { OSSL_FUNC_MAC_NEWCTX1, (void (*)(void))gmac_new },
248 { OSSL_FUNC_MAC_DUPCTX2, (void (*)(void))gmac_dup },
249 { OSSL_FUNC_MAC_FREECTX3, (void (*)(void))gmac_free },
250 { OSSL_FUNC_MAC_INIT4, (void (*)(void))gmac_init },
251 { OSSL_FUNC_MAC_UPDATE5, (void (*)(void))gmac_update },
252 { OSSL_FUNC_MAC_FINAL6, (void (*)(void))gmac_final },
253 { OSSL_FUNC_MAC_GETTABLE_PARAMS10, (void (*)(void))gmac_gettable_params },
254 { OSSL_FUNC_MAC_GET_PARAMS7, (void (*)(void))gmac_get_params },
255 { OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS12,
256 (void (*)(void))gmac_settable_ctx_params },
257 { OSSL_FUNC_MAC_SET_CTX_PARAMS9, (void (*)(void))gmac_set_ctx_params },
258 { 0, NULL((void*)0) }
259};