OpenCoverage

pmeth_gn.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/pmeth_gn.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2006-2016 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 <stdlib.h>-
12#include "internal/cryptlib.h"-
13#include <openssl/objects.h>-
14#include <openssl/evp.h>-
15#include "internal/bn_int.h"-
16#include "internal/asn1_int.h"-
17#include "internal/evp_int.h"-
18-
19int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx)-
20{-
21 int ret;-
22 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) {
!ctxDescription
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmethDescription
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmeth->paramgenDescription
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-229
23 EVPerr(EVP_F_EVP_PKEY_PARAMGEN_INIT,-
24 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
25 return -2;
never executed: return -2;
0
26 }-
27 ctx->operation = EVP_PKEY_OP_PARAMGEN;-
28 if (!ctx->pmeth->paramgen_init)
!ctx->pmeth->paramgen_initDescription
TRUEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-229
29 return 1;
executed 229 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
229
30 ret = ctx->pmeth->paramgen_init(ctx);-
31 if (ret <= 0)
ret <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
32 ctx->operation = EVP_PKEY_OP_UNDEFINED;
never executed: ctx->operation = 0;
0
33 return ret;
never executed: return ret;
0
34}-
35-
36int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)-
37{-
38 int ret;-
39 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) {
!ctxDescription
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmethDescription
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmeth->paramgenDescription
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-229
40 EVPerr(EVP_F_EVP_PKEY_PARAMGEN,-
41 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
42 return -2;
never executed: return -2;
0
43 }-
44-
45 if (ctx->operation != EVP_PKEY_OP_PARAMGEN) {
ctx->operation != (1<<1)Description
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-229
46 EVPerr(EVP_F_EVP_PKEY_PARAMGEN, EVP_R_OPERATON_NOT_INITIALIZED);-
47 return -1;
never executed: return -1;
0
48 }-
49-
50 if (ppkey == NULL)
ppkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-229
51 return -1;
never executed: return -1;
0
52-
53 if (*ppkey == NULL)
*ppkey == ((void *)0)Description
TRUEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-229
54 *ppkey = EVP_PKEY_new();
executed 229 times by 1 test: *ppkey = EVP_PKEY_new();
Executed by:
  • libcrypto.so.1.1
229
55-
56 if (*ppkey == NULL) {
*ppkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-229
57 EVPerr(EVP_F_EVP_PKEY_PARAMGEN, ERR_R_MALLOC_FAILURE);-
58 return -1;
never executed: return -1;
0
59 }-
60-
61 ret = ctx->pmeth->paramgen(ctx, *ppkey);-
62 if (ret <= 0) {
ret <= 0Description
TRUEnever evaluated
FALSEevaluated 229 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-229
63 EVP_PKEY_free(*ppkey);-
64 *ppkey = NULL;-
65 }
never executed: end of block
0
66 return ret;
executed 229 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
229
67}-
68-
69int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx)-
70{-
71 int ret;-
72 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
!ctxDescription
TRUEnever evaluated
FALSEevaluated 10113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmethDescription
TRUEnever evaluated
FALSEevaluated 10113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmeth->keygenDescription
TRUEnever evaluated
FALSEevaluated 10113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10113
73 EVPerr(EVP_F_EVP_PKEY_KEYGEN_INIT,-
74 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
75 return -2;
never executed: return -2;
0
76 }-
77 ctx->operation = EVP_PKEY_OP_KEYGEN;-
78 if (!ctx->pmeth->keygen_init)
!ctx->pmeth->keygen_initDescription
TRUEevaluated 10113 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-10113
79 return 1;
executed 10113 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
10113
80 ret = ctx->pmeth->keygen_init(ctx);-
81 if (ret <= 0)
ret <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
82 ctx->operation = EVP_PKEY_OP_UNDEFINED;
never executed: ctx->operation = 0;
0
83 return ret;
never executed: return ret;
0
84}-
85-
86int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)-
87{-
88 int ret;-
89-
90 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
!ctxDescription
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmethDescription
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!ctx->pmeth->keygenDescription
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10112
91 EVPerr(EVP_F_EVP_PKEY_KEYGEN,-
92 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
93 return -2;
never executed: return -2;
0
94 }-
95 if (ctx->operation != EVP_PKEY_OP_KEYGEN) {
ctx->operation != (1<<2)Description
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10112
96 EVPerr(EVP_F_EVP_PKEY_KEYGEN, EVP_R_OPERATON_NOT_INITIALIZED);-
97 return -1;
never executed: return -1;
0
98 }-
99-
100 if (ppkey == NULL)
ppkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10112
101 return -1;
never executed: return -1;
0
102-
103 if (*ppkey == NULL)
*ppkey == ((void *)0)Description
TRUEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-10112
104 *ppkey = EVP_PKEY_new();
executed 10112 times by 1 test: *ppkey = EVP_PKEY_new();
Executed by:
  • libcrypto.so.1.1
10112
105 if (*ppkey == NULL)
*ppkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10112
106 return -1;
never executed: return -1;
0
107-
108 ret = ctx->pmeth->keygen(ctx, *ppkey);-
109 if (ret <= 0) {
ret <= 0Description
TRUEnever evaluated
FALSEevaluated 10112 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10112
110 EVP_PKEY_free(*ppkey);-
111 *ppkey = NULL;-
112 }
never executed: end of block
0
113 return ret;
executed 10112 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
10112
114}-
115-
116void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb)-
117{-
118 ctx->pkey_gencb = cb;-
119}
executed 13 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
13
120-
121EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx)-
122{-
123 return ctx->pkey_gencb;
never executed: return ctx->pkey_gencb;
0
124}-
125-
126/*-
127 * "translation callback" to call EVP_PKEY_CTX callbacks using BN_GENCB style-
128 * callbacks.-
129 */-
130-
131static int trans_cb(int a, int b, BN_GENCB *gcb)-
132{-
133 EVP_PKEY_CTX *ctx = BN_GENCB_get_arg(gcb);-
134 ctx->keygen_info[0] = a;-
135 ctx->keygen_info[1] = b;-
136 return ctx->pkey_gencb(ctx);
executed 2168 times by 1 test: return ctx->pkey_gencb(ctx);
Executed by:
  • libcrypto.so.1.1
2168
137}-
138-
139void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx)-
140{-
141 BN_GENCB_set(cb, trans_cb, ctx);-
142}
executed 12 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12
143-
144int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx)-
145{-
146 if (idx == -1)
idx == -1Description
TRUEnever evaluated
FALSEevaluated 2168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2168
147 return ctx->keygen_info_count;
never executed: return ctx->keygen_info_count;
0
148 if (idx < 0 || idx > ctx->keygen_info_count)
idx < 0Description
TRUEnever evaluated
FALSEevaluated 2168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
idx > ctx->keygen_info_countDescription
TRUEnever evaluated
FALSEevaluated 2168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2168
149 return 0;
never executed: return 0;
0
150 return ctx->keygen_info[idx];
executed 2168 times by 1 test: return ctx->keygen_info[idx];
Executed by:
  • libcrypto.so.1.1
2168
151}-
152-
153EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e,-
154 const unsigned char *key, int keylen)-
155{-
156 EVP_PKEY_CTX *mac_ctx = NULL;-
157 EVP_PKEY *mac_key = NULL;-
158 mac_ctx = EVP_PKEY_CTX_new_id(type, e);-
159 if (!mac_ctx)
!mac_ctxDescription
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
160 return NULL;
never executed: return ((void *)0) ;
0
161 if (EVP_PKEY_keygen_init(mac_ctx) <= 0)
EVP_PKEY_keyge...(mac_ctx) <= 0Description
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
162 goto merr;
never executed: goto merr;
0
163 if (EVP_PKEY_CTX_set_mac_key(mac_ctx, key, keylen) <= 0)
EVP_PKEY_CTX_c... *)(key)) <= 0Description
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
164 goto merr;
never executed: goto merr;
0
165 if (EVP_PKEY_keygen(mac_ctx, &mac_key) <= 0)
EVP_PKEY_keyge...&mac_key) <= 0Description
TRUEnever evaluated
FALSEevaluated 2746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2746
166 goto merr;
never executed: goto merr;
0
167 merr:
code before this statement executed 2746 times by 1 test: merr:
Executed by:
  • libcrypto.so.1.1
2746
168 EVP_PKEY_CTX_free(mac_ctx);-
169 return mac_key;
executed 2746 times by 1 test: return mac_key;
Executed by:
  • libcrypto.so.1.1
2746
170}-
171-
172int EVP_PKEY_check(EVP_PKEY_CTX *ctx)-
173{-
174 EVP_PKEY *pkey = ctx->pkey;-
175-
176 if (pkey == NULL) {
pkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
177 EVPerr(EVP_F_EVP_PKEY_CHECK, EVP_R_NO_KEY_SET);-
178 return 0;
never executed: return 0;
0
179 }-
180-
181 /* call customized check function first */-
182 if (ctx->pmeth->check != NULL)
ctx->pmeth->ch...!= ((void *)0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5
183 return ctx->pmeth->check(pkey);
executed 5 times by 1 test: return ctx->pmeth->check(pkey);
Executed by:
  • libcrypto.so.1.1
5
184-
185 /* use default check function in ameth */-
186 if (pkey->ameth == NULL || pkey->ameth->pkey_check == NULL) {
pkey->ameth == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
pkey->ameth->p...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
187 EVPerr(EVP_F_EVP_PKEY_CHECK,-
188 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
189 return -2;
never executed: return -2;
0
190 }-
191-
192 return pkey->ameth->pkey_check(pkey);
executed 5 times by 1 test: return pkey->ameth->pkey_check(pkey);
Executed by:
  • libcrypto.so.1.1
5
193}-
194-
195int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx)-
196{-
197 EVP_PKEY *pkey = ctx->pkey;-
198-
199 if (pkey == NULL) {
pkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
200 EVPerr(EVP_F_EVP_PKEY_PUBLIC_CHECK, EVP_R_NO_KEY_SET);-
201 return 0;
never executed: return 0;
0
202 }-
203-
204 /* call customized public key check function first */-
205 if (ctx->pmeth->public_check != NULL)
ctx->pmeth->pu...!= ((void *)0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5
206 return ctx->pmeth->public_check(pkey);
executed 5 times by 1 test: return ctx->pmeth->public_check(pkey);
Executed by:
  • libcrypto.so.1.1
5
207-
208 /* use default public key check function in ameth */-
209 if (pkey->ameth == NULL || pkey->ameth->pkey_public_check == NULL) {
pkey->ameth == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
pkey->ameth->p...== ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
210 EVPerr(EVP_F_EVP_PKEY_PUBLIC_CHECK,-
211 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
212 return -2;
executed 2 times by 1 test: return -2;
Executed by:
  • libcrypto.so.1.1
2
213 }-
214-
215 return pkey->ameth->pkey_public_check(pkey);
executed 3 times by 1 test: return pkey->ameth->pkey_public_check(pkey);
Executed by:
  • libcrypto.so.1.1
3
216}-
217-
218int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx)-
219{-
220 EVP_PKEY *pkey = ctx->pkey;-
221-
222 if (pkey == NULL) {
pkey == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
223 EVPerr(EVP_F_EVP_PKEY_PARAM_CHECK, EVP_R_NO_KEY_SET);-
224 return 0;
never executed: return 0;
0
225 }-
226-
227 /* call customized param check function first */-
228 if (ctx->pmeth->param_check != NULL)
ctx->pmeth->pa...!= ((void *)0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5
229 return ctx->pmeth->param_check(pkey);
executed 5 times by 1 test: return ctx->pmeth->param_check(pkey);
Executed by:
  • libcrypto.so.1.1
5
230-
231 /* use default param check function in ameth */-
232 if (pkey->ameth == NULL || pkey->ameth->pkey_param_check == NULL) {
pkey->ameth == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
pkey->ameth->p...== ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
233 EVPerr(EVP_F_EVP_PKEY_PARAM_CHECK,-
234 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);-
235 return -2;
executed 2 times by 1 test: return -2;
Executed by:
  • libcrypto.so.1.1
2
236 }-
237-
238 return pkey->ameth->pkey_param_check(pkey);
executed 3 times by 1 test: return pkey->ameth->pkey_param_check(pkey);
Executed by:
  • libcrypto.so.1.1
3
239}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2