OpenCoverage

hm_pmeth.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/hmac/hm_pmeth.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (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 <stdio.h>-
11#include "internal/cryptlib.h"-
12#include <openssl/x509.h>-
13#include <openssl/x509v3.h>-
14#include <openssl/evp.h>-
15#include <openssl/hmac.h>-
16#include <openssl/err.h>-
17#include "internal/evp_int.h"-
18-
19/* HMAC pkey context structure */-
20-
21typedef struct {-
22 const EVP_MD *md; /* MD for HMAC use */-
23 ASN1_OCTET_STRING ktmp; /* Temp storage for key */-
24 HMAC_CTX *ctx;-
25} HMAC_PKEY_CTX;-
26-
27static int pkey_hmac_init(EVP_PKEY_CTX *ctx)-
28{-
29 HMAC_PKEY_CTX *hctx;-
30-
31 if ((hctx = OPENSSL_zalloc(sizeof(*hctx))) == NULL) {
(hctx = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 181560 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-181560
32 CRYPTOerr(CRYPTO_F_PKEY_HMAC_INIT, ERR_R_MALLOC_FAILURE);-
33 return 0;
never executed: return 0;
0
34 }-
35 hctx->ktmp.type = V_ASN1_OCTET_STRING;-
36 hctx->ctx = HMAC_CTX_new();-
37 if (hctx->ctx == NULL) {
hctx->ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 181560 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-181560
38 OPENSSL_free(hctx);-
39 return 0;
never executed: return 0;
0
40 }-
41-
42 ctx->data = hctx;-
43 ctx->keygen_info_count = 0;-
44-
45 return 1;
executed 181560 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
181560
46}-
47-
48static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx);-
49-
50static int pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)-
51{-
52 HMAC_PKEY_CTX *sctx, *dctx;-
53-
54 /* allocate memory for dst->data and a new HMAC_CTX in dst->data->ctx */-
55 if (!pkey_hmac_init(dst))
!pkey_hmac_init(dst)Description
TRUEnever evaluated
FALSEevaluated 159608 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-159608
56 return 0;
never executed: return 0;
0
57 sctx = EVP_PKEY_CTX_get_data(src);-
58 dctx = EVP_PKEY_CTX_get_data(dst);-
59 dctx->md = sctx->md;-
60 if (!HMAC_CTX_copy(dctx->ctx, sctx->ctx))
!HMAC_CTX_copy...tx, sctx->ctx)Description
TRUEnever evaluated
FALSEevaluated 159608 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-159608
61 goto err;
never executed: goto err;
0
62 if (sctx->ktmp.data) {
sctx->ktmp.dataDescription
TRUEnever evaluated
FALSEevaluated 159608 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-159608
63 if (!ASN1_OCTET_STRING_set(&dctx->ktmp,
!ASN1_OCTET_ST...->ktmp.length)Description
TRUEnever evaluated
FALSEnever evaluated
0
64 sctx->ktmp.data, sctx->ktmp.length))
!ASN1_OCTET_ST...->ktmp.length)Description
TRUEnever evaluated
FALSEnever evaluated
0
65 goto err;
never executed: goto err;
0
66 }
never executed: end of block
0
67 return 1;
executed 159608 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
159608
68err:-
69 /* release HMAC_CTX in dst->data->ctx and memory allocated for dst->data */-
70 pkey_hmac_cleanup (dst);-
71 return 0;
never executed: return 0;
0
72}-
73-
74static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)-
75{-
76 HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);-
77-
78 if (hctx != NULL) {
hctx != ((void *)0)Description
TRUEevaluated 181560 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-181560
79 HMAC_CTX_free(hctx->ctx);-
80 OPENSSL_clear_free(hctx->ktmp.data, hctx->ktmp.length);-
81 OPENSSL_free(hctx);-
82 EVP_PKEY_CTX_set_data(ctx, NULL);-
83 }
executed 181560 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
181560
84}
executed 181560 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
181560
85-
86static int pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)-
87{-
88 ASN1_OCTET_STRING *hkey = NULL;-
89 HMAC_PKEY_CTX *hctx = ctx->data;-
90 if (!hctx->ktmp.data)
!hctx->ktmp.dataDescription
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
91 return 0;
never executed: return 0;
0
92 hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp);-
93 if (!hkey)
!hkeyDescription
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
94 return 0;
never executed: return 0;
0
95 EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);-
96-
97 return 1;
executed 2746 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2746
98}-
99-
100static int int_update(EVP_MD_CTX *ctx, const void *data, size_t count)-
101{-
102 HMAC_PKEY_CTX *hctx = EVP_MD_CTX_pkey_ctx(ctx)->data;-
103 if (!HMAC_Update(hctx->ctx, data, count))
!HMAC_Update(h..., data, count)Description
TRUEnever evaluated
FALSEevaluated 106076 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-106076
104 return 0;
never executed: return 0;
0
105 return 1;
executed 106076 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
106076
106}-
107-
108static int hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)-
109{-
110 HMAC_PKEY_CTX *hctx = ctx->data;-
111 HMAC_CTX_set_flags(hctx->ctx,-
112 EVP_MD_CTX_test_flags(mctx, ~EVP_MD_CTX_FLAG_NO_INIT));-
113 EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);-
114 EVP_MD_CTX_set_update_fn(mctx, int_update);-
115 return 1;
executed 19206 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
19206
116}-
117-
118static int hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,-
119 EVP_MD_CTX *mctx)-
120{-
121 unsigned int hlen;-
122 HMAC_PKEY_CTX *hctx = ctx->data;-
123 int l = EVP_MD_CTX_size(mctx);-
124-
125 if (l < 0)
l < 0Description
TRUEnever evaluated
FALSEevaluated 81201 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-81201
126 return 0;
never executed: return 0;
0
127 *siglen = l;-
128 if (!sig)
!sigDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 81171 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
30-81171
129 return 1;
executed 30 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
30
130-
131 if (!HMAC_Final(hctx->ctx, sig, &hlen))
!HMAC_Final(hc...x, sig, &hlen)Description
TRUEnever evaluated
FALSEevaluated 81171 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-81171
132 return 0;
never executed: return 0;
0
133 *siglen = (size_t)hlen;-
134 return 1;
executed 81171 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
81171
135}-
136-
137static int pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)-
138{-
139 HMAC_PKEY_CTX *hctx = ctx->data;-
140 ASN1_OCTET_STRING *key;-
141 switch (type) {-
142-
143 case EVP_PKEY_CTRL_SET_MAC_KEY:
executed 2746 times by 1 test: case 6:
Executed by:
  • libcrypto.so.1.1
2746
144 if ((!p2 && p1 > 0) || (p1 < -1))
!p2Description
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p1 > 0Description
TRUEnever evaluated
FALSEnever evaluated
(p1 < -1)Description
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
145 return 0;
never executed: return 0;
0
146 if (!ASN1_OCTET_STRING_set(&hctx->ktmp, p2, p1))
!ASN1_OCTET_ST...>ktmp, p2, p1)Description
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
147 return 0;
never executed: return 0;
0
148 break;
executed 2746 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
2746
149-
150 case EVP_PKEY_CTRL_MD:
executed 19206 times by 1 test: case 1:
Executed by:
  • libcrypto.so.1.1
19206
151 hctx->md = p2;-
152 break;
executed 19206 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
19206
153-
154 case EVP_PKEY_CTRL_DIGESTINIT:
executed 19206 times by 1 test: case 7:
Executed by:
  • libcrypto.so.1.1
19206
155 key = (ASN1_OCTET_STRING *)ctx->pkey->pkey.ptr;-
156 if (!HMAC_Init_ex(hctx->ctx, key->data, key->length, hctx->md,
!HMAC_Init_ex(..., ctx->engine)Description
TRUEnever evaluated
FALSEevaluated 19206 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-19206
157 ctx->engine))
!HMAC_Init_ex(..., ctx->engine)Description
TRUEnever evaluated
FALSEevaluated 19206 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-19206
158 return 0;
never executed: return 0;
0
159 break;
executed 19206 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
19206
160-
161 default:
never executed: default:
0
162 return -2;
never executed: return -2;
0
163-
164 }-
165 return 1;
executed 41158 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
41158
166}-
167-
168static int pkey_hmac_ctrl_str(EVP_PKEY_CTX *ctx,-
169 const char *type, const char *value)-
170{-
171 if (!value) {
!valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
172 return 0;
never executed: return 0;
0
173 }-
174 if (strcmp(type, "key") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( type ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "key" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
175 return EVP_PKEY_CTX_str2ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, value);
never executed: return EVP_PKEY_CTX_str2ctrl(ctx, 6, value);
0
176 if (strcmp(type, "hexkey") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( type ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "hexkey" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
177 return EVP_PKEY_CTX_hex2ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, value);
never executed: return EVP_PKEY_CTX_hex2ctrl(ctx, 6, value);
0
178 return -2;
never executed: return -2;
0
179}-
180-
181const EVP_PKEY_METHOD hmac_pkey_meth = {-
182 EVP_PKEY_HMAC,-
183 0,-
184 pkey_hmac_init,-
185 pkey_hmac_copy,-
186 pkey_hmac_cleanup,-
187-
188 0, 0,-
189-
190 0,-
191 pkey_hmac_keygen,-
192-
193 0, 0,-
194-
195 0, 0,-
196-
197 0, 0,-
198-
199 hmac_signctx_init,-
200 hmac_signctx,-
201-
202 0, 0,-
203-
204 0, 0,-
205-
206 0, 0,-
207-
208 0, 0,-
209-
210 pkey_hmac_ctrl,-
211 pkey_hmac_ctrl_str-
212};-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2