Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/pmeth_gn.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: pmeth_gn.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */ | - | ||||||||||||||||||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | - | ||||||||||||||||||
3 | * project 2006. | - | ||||||||||||||||||
4 | */ | - | ||||||||||||||||||
5 | /* ==================================================================== | - | ||||||||||||||||||
6 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | - | ||||||||||||||||||
7 | * | - | ||||||||||||||||||
8 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||
9 | * modification, are permitted provided that the following conditions | - | ||||||||||||||||||
10 | * are met: | - | ||||||||||||||||||
11 | * | - | ||||||||||||||||||
12 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||||||||
13 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||
14 | * | - | ||||||||||||||||||
15 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||
16 | * notice, this list of conditions and the following disclaimer in | - | ||||||||||||||||||
17 | * the documentation and/or other materials provided with the | - | ||||||||||||||||||
18 | * distribution. | - | ||||||||||||||||||
19 | * | - | ||||||||||||||||||
20 | * 3. All advertising materials mentioning features or use of this | - | ||||||||||||||||||
21 | * software must display the following acknowledgment: | - | ||||||||||||||||||
22 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||||||||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | - | ||||||||||||||||||
24 | * | - | ||||||||||||||||||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||||||||||||||
26 | * endorse or promote products derived from this software without | - | ||||||||||||||||||
27 | * prior written permission. For written permission, please contact | - | ||||||||||||||||||
28 | * licensing@OpenSSL.org. | - | ||||||||||||||||||
29 | * | - | ||||||||||||||||||
30 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||||||||||||||
31 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||||||||||||||
32 | * permission of the OpenSSL Project. | - | ||||||||||||||||||
33 | * | - | ||||||||||||||||||
34 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||||||||||||||
35 | * acknowledgment: | - | ||||||||||||||||||
36 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||||||||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | - | ||||||||||||||||||
38 | * | - | ||||||||||||||||||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||||||||||||||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||||||||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||||||||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||||||||||||||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||||||||||||||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||||||||||||||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||||||||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||||||||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||||||||||||||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||||||||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||||||||||||||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||
51 | * ==================================================================== | - | ||||||||||||||||||
52 | * | - | ||||||||||||||||||
53 | * This product includes cryptographic software written by Eric Young | - | ||||||||||||||||||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||||||||||||||
55 | * Hudson (tjh@cryptsoft.com). | - | ||||||||||||||||||
56 | * | - | ||||||||||||||||||
57 | */ | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | #include <stdio.h> | - | ||||||||||||||||||
60 | #include <stdlib.h> | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | #include <openssl/bn.h> | - | ||||||||||||||||||
63 | #include <openssl/err.h> | - | ||||||||||||||||||
64 | #include <openssl/evp.h> | - | ||||||||||||||||||
65 | #include <openssl/objects.h> | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | #include "evp_locl.h" | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | int | - | ||||||||||||||||||
70 | EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx) | - | ||||||||||||||||||
71 | { | - | ||||||||||||||||||
72 | int ret; | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) {
| 0 | ||||||||||||||||||
75 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
76 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
77 | } | - | ||||||||||||||||||
78 | ctx->operation = EVP_PKEY_OP_PARAMGEN; | - | ||||||||||||||||||
79 | if (!ctx->pmeth->paramgen_init)
| 0 | ||||||||||||||||||
80 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
81 | ret = ctx->pmeth->paramgen_init(ctx); | - | ||||||||||||||||||
82 | if (ret <= 0)
| 0 | ||||||||||||||||||
83 | ctx->operation = EVP_PKEY_OP_UNDEFINED; never executed: ctx->operation = 0; | 0 | ||||||||||||||||||
84 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | int | - | ||||||||||||||||||
88 | EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) | - | ||||||||||||||||||
89 | { | - | ||||||||||||||||||
90 | int ret; | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) {
| 0 | ||||||||||||||||||
93 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
94 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
95 | } | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | if (ctx->operation != EVP_PKEY_OP_PARAMGEN) {
| 0 | ||||||||||||||||||
98 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); | - | ||||||||||||||||||
99 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
100 | } | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | if (!ppkey)
| 0 | ||||||||||||||||||
103 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | if (!*ppkey)
| 0 | ||||||||||||||||||
106 | *ppkey = EVP_PKEY_new(); never executed: *ppkey = EVP_PKEY_new(); | 0 | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | ret = ctx->pmeth->paramgen(ctx, *ppkey); | - | ||||||||||||||||||
109 | if (ret <= 0) {
| 0 | ||||||||||||||||||
110 | EVP_PKEY_free(*ppkey); | - | ||||||||||||||||||
111 | *ppkey = NULL; | - | ||||||||||||||||||
112 | } never executed: end of block | 0 | ||||||||||||||||||
113 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
114 | } | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | int | - | ||||||||||||||||||
117 | EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx) | - | ||||||||||||||||||
118 | { | - | ||||||||||||||||||
119 | int ret; | - | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
| 0-1813 | ||||||||||||||||||
122 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
123 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
124 | } | - | ||||||||||||||||||
125 | ctx->operation = EVP_PKEY_OP_KEYGEN; | - | ||||||||||||||||||
126 | if (!ctx->pmeth->keygen_init)
| 0-1813 | ||||||||||||||||||
127 | return 1; executed 1813 times by 5 tests: return 1; Executed by:
| 1813 | ||||||||||||||||||
128 | ret = ctx->pmeth->keygen_init(ctx); | - | ||||||||||||||||||
129 | if (ret <= 0)
| 0 | ||||||||||||||||||
130 | ctx->operation = EVP_PKEY_OP_UNDEFINED; never executed: ctx->operation = 0; | 0 | ||||||||||||||||||
131 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
132 | } | - | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | int | - | ||||||||||||||||||
135 | EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) | - | ||||||||||||||||||
136 | { | - | ||||||||||||||||||
137 | int ret; | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
| 0-1813 | ||||||||||||||||||
140 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | - | ||||||||||||||||||
141 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
142 | } | - | ||||||||||||||||||
143 | if (ctx->operation != EVP_PKEY_OP_KEYGEN) {
| 0-1813 | ||||||||||||||||||
144 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); | - | ||||||||||||||||||
145 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
146 | } | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | if (!ppkey)
| 0-1813 | ||||||||||||||||||
149 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | if (!*ppkey)
| 0-1813 | ||||||||||||||||||
152 | *ppkey = EVP_PKEY_new(); executed 1813 times by 5 tests: *ppkey = EVP_PKEY_new(); Executed by:
| 1813 | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | ret = ctx->pmeth->keygen(ctx, *ppkey); | - | ||||||||||||||||||
155 | if (ret <= 0) {
| 0-1813 | ||||||||||||||||||
156 | EVP_PKEY_free(*ppkey); | - | ||||||||||||||||||
157 | *ppkey = NULL; | - | ||||||||||||||||||
158 | } never executed: end of block | 0 | ||||||||||||||||||
159 | return ret; executed 1813 times by 5 tests: return ret; Executed by:
| 1813 | ||||||||||||||||||
160 | } | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | void | - | ||||||||||||||||||
163 | EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb) | - | ||||||||||||||||||
164 | { | - | ||||||||||||||||||
165 | ctx->pkey_gencb = cb; | - | ||||||||||||||||||
166 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | EVP_PKEY_gen_cb * | - | ||||||||||||||||||
169 | EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx) | - | ||||||||||||||||||
170 | { | - | ||||||||||||||||||
171 | return ctx->pkey_gencb; never executed: return ctx->pkey_gencb; | 0 | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | /* "translation callback" to call EVP_PKEY_CTX callbacks using BN_GENCB | - | ||||||||||||||||||
175 | * style callbacks. | - | ||||||||||||||||||
176 | */ | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | static int | - | ||||||||||||||||||
179 | trans_cb(int a, int b, BN_GENCB *gcb) | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | EVP_PKEY_CTX *ctx = gcb->arg; | - | ||||||||||||||||||
182 | ctx->keygen_info[0] = a; | - | ||||||||||||||||||
183 | ctx->keygen_info[1] = b; | - | ||||||||||||||||||
184 | return ctx->pkey_gencb(ctx); never executed: return ctx->pkey_gencb(ctx); | 0 | ||||||||||||||||||
185 | } | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | void | - | ||||||||||||||||||
188 | evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx) | - | ||||||||||||||||||
189 | { | - | ||||||||||||||||||
190 | BN_GENCB_set(cb, trans_cb, ctx) | - | ||||||||||||||||||
191 | } never executed: end of block | 0 | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | int | - | ||||||||||||||||||
194 | EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx) | - | ||||||||||||||||||
195 | { | - | ||||||||||||||||||
196 | if (idx == -1)
| 0 | ||||||||||||||||||
197 | return ctx->keygen_info_count; never executed: return ctx->keygen_info_count; | 0 | ||||||||||||||||||
198 | if (idx < 0 || idx > ctx->keygen_info_count)
| 0 | ||||||||||||||||||
199 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
200 | return ctx->keygen_info[idx]; never executed: return ctx->keygen_info[idx]; | 0 | ||||||||||||||||||
201 | } | - | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | EVP_PKEY * | - | ||||||||||||||||||
204 | EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen) | - | ||||||||||||||||||
205 | { | - | ||||||||||||||||||
206 | EVP_PKEY_CTX *mac_ctx = NULL; | - | ||||||||||||||||||
207 | EVP_PKEY *mac_key = NULL; | - | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | mac_ctx = EVP_PKEY_CTX_new_id(type, e); | - | ||||||||||||||||||
210 | if (!mac_ctx)
| 0-1812 | ||||||||||||||||||
211 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
212 | if (EVP_PKEY_keygen_init(mac_ctx) <= 0)
| 0-1812 | ||||||||||||||||||
213 | goto merr; never executed: goto merr; | 0 | ||||||||||||||||||
214 | if (EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
| 0-1812 | ||||||||||||||||||
215 | EVP_PKEY_CTRL_SET_MAC_KEY, keylen, (void *)key) <= 0)
| 0-1812 | ||||||||||||||||||
216 | goto merr; never executed: goto merr; | 0 | ||||||||||||||||||
217 | if (EVP_PKEY_keygen(mac_ctx, &mac_key) <= 0)
| 0-1812 | ||||||||||||||||||
218 | goto merr; never executed: goto merr; | 0 | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | merr: code before this statement executed 1812 times by 4 tests: merr: Executed by:
| 1812 | ||||||||||||||||||
221 | EVP_PKEY_CTX_free(mac_ctx); | - | ||||||||||||||||||
222 | return mac_key; executed 1812 times by 4 tests: return mac_key; Executed by:
| 1812 | ||||||||||||||||||
223 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |