OpenCoverage

eck_prn.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/eck_prn.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved-
4 *-
5 * Licensed under the OpenSSL license (the "License"). You may not use-
6 * this file except in compliance with the License. You can obtain a copy-
7 * in the file LICENSE in the source distribution or at-
8 * https://www.openssl.org/source/license.html-
9 */-
10-
11#include <stdio.h>-
12#include "internal/cryptlib.h"-
13#include <openssl/evp.h>-
14#include <openssl/ec.h>-
15#include <openssl/bn.h>-
16-
17#ifndef OPENSSL_NO_STDIO-
18int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off)-
19{-
20 BIO *b;-
21 int ret;-
22-
23 if ((b = BIO_new(BIO_s_file())) == NULL) {
(b = BIO_new(B...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
24 ECerr(EC_F_ECPKPARAMETERS_PRINT_FP, ERR_R_BUF_LIB);-
25 return 0;
never executed: return 0;
0
26 }-
27 BIO_set_fp(b, fp, BIO_NOCLOSE);-
28 ret = ECPKParameters_print(b, x, off);-
29 BIO_free(b);-
30 return ret;
never executed: return ret;
0
31}-
32-
33int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off)-
34{-
35 BIO *b;-
36 int ret;-
37-
38 if ((b = BIO_new(BIO_s_file())) == NULL) {
(b = BIO_new(B...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
39 ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB);-
40 return 0;
never executed: return 0;
0
41 }-
42 BIO_set_fp(b, fp, BIO_NOCLOSE);-
43 ret = EC_KEY_print(b, x, off);-
44 BIO_free(b);-
45 return ret;
never executed: return ret;
0
46}-
47-
48int ECParameters_print_fp(FILE *fp, const EC_KEY *x)-
49{-
50 BIO *b;-
51 int ret;-
52-
53 if ((b = BIO_new(BIO_s_file())) == NULL) {
(b = BIO_new(B...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
54 ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB);-
55 return 0;
never executed: return 0;
0
56 }-
57 BIO_set_fp(b, fp, BIO_NOCLOSE);-
58 ret = ECParameters_print(b, x);-
59 BIO_free(b);-
60 return ret;
never executed: return ret;
0
61}-
62#endif-
63-
64static int print_bin(BIO *fp, const char *str, const unsigned char *num,-
65 size_t len, int off);-
66-
67int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)-
68{-
69 int ret = 0, reason = ERR_R_BIO_LIB;-
70 BN_CTX *ctx = NULL;-
71 const EC_POINT *point = NULL;-
72 BIGNUM *p = NULL, *a = NULL, *b = NULL, *gen = NULL;-
73 const BIGNUM *order = NULL, *cofactor = NULL;-
74 const unsigned char *seed;-
75 size_t seed_len = 0;-
76-
77 static const char *gen_compressed = "Generator (compressed):";-
78 static const char *gen_uncompressed = "Generator (uncompressed):";-
79 static const char *gen_hybrid = "Generator (hybrid):";-
80-
81 if (!x) {
!xDescription
TRUEnever evaluated
FALSEevaluated 279 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-279
82 reason = ERR_R_PASSED_NULL_PARAMETER;-
83 goto err;
never executed: goto err;
0
84 }-
85-
86 ctx = BN_CTX_new();-
87 if (ctx == NULL) {
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 279 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-279
88 reason = ERR_R_MALLOC_FAILURE;-
89 goto err;
never executed: goto err;
0
90 }-
91-
92 if (EC_GROUP_get_asn1_flag(x)) {
EC_GROUP_get_asn1_flag(x)Description
TRUEevaluated 234 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
45-234
93 /* the curve parameter are given by an asn1 OID */-
94 int nid;-
95 const char *nname;-
96-
97 if (!BIO_indent(bp, off, 128))
!BIO_indent(bp, off, 128)Description
TRUEnever evaluated
FALSEevaluated 234 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-234
98 goto err;
never executed: goto err;
0
99-
100 nid = EC_GROUP_get_curve_name(x);-
101 if (nid == 0)
nid == 0Description
TRUEnever evaluated
FALSEevaluated 234 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-234
102 goto err;
never executed: goto err;
0
103 if (BIO_printf(bp, "ASN1 OID: %s", OBJ_nid2sn(nid)) <= 0)
BIO_printf(bp,...2sn(nid)) <= 0Description
TRUEnever evaluated
FALSEevaluated 234 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-234
104 goto err;
never executed: goto err;
0
105 if (BIO_printf(bp, "\n") <= 0)
BIO_printf(bp, "\n") <= 0Description
TRUEnever evaluated
FALSEevaluated 234 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-234
106 goto err;
never executed: goto err;
0
107 nname = EC_curve_nid2nist(nid);-
108 if (nname) {
nnameDescription
TRUEevaluated 142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 92 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
92-142
109 if (!BIO_indent(bp, off, 128))
!BIO_indent(bp, off, 128)Description
TRUEnever evaluated
FALSEevaluated 142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-142
110 goto err;
never executed: goto err;
0
111 if (BIO_printf(bp, "NIST CURVE: %s\n", nname) <= 0)
BIO_printf(bp,...", nname) <= 0Description
TRUEnever evaluated
FALSEevaluated 142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-142
112 goto err;
never executed: goto err;
0
113 }
executed 142 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
142
114 } else {
executed 234 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
234
115 /* explicit parameters */-
116 int is_char_two = 0;-
117 point_conversion_form_t form;-
118 int tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(x));-
119-
120 if (tmp_nid == NID_X9_62_characteristic_two_field)
tmp_nid == 407Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
121 is_char_two = 1;
never executed: is_char_two = 1;
0
122-
123 if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
(p = BN_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(a = BN_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
124 (b = BN_new()) == NULL) {
(b = BN_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
125 reason = ERR_R_MALLOC_FAILURE;-
126 goto err;
never executed: goto err;
0
127 }-
128-
129 if (!EC_GROUP_get_curve(x, p, a, b, ctx)) {
!EC_GROUP_get_... p, a, b, ctx)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
130 reason = ERR_R_EC_LIB;-
131 goto err;
never executed: goto err;
0
132 }-
133-
134 if ((point = EC_GROUP_get0_generator(x)) == NULL) {
(point = EC_GR...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
135 reason = ERR_R_EC_LIB;-
136 goto err;
never executed: goto err;
0
137 }-
138 order = EC_GROUP_get0_order(x);-
139 cofactor = EC_GROUP_get0_cofactor(x);-
140 if (order == NULL) {
order == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
141 reason = ERR_R_EC_LIB;-
142 goto err;
never executed: goto err;
0
143 }-
144-
145 form = EC_GROUP_get_point_conversion_form(x);-
146-
147 if ((gen = EC_POINT_point2bn(x, point, form, NULL, ctx)) == NULL) {
(gen = EC_POIN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
148 reason = ERR_R_EC_LIB;-
149 goto err;
never executed: goto err;
0
150 }-
151-
152 if ((seed = EC_GROUP_get0_seed(x)) != NULL)
(seed = EC_GRO...!= ((void *)0)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 28 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
17-28
153 seed_len = EC_GROUP_get_seed_len(x);
executed 17 times by 1 test: seed_len = EC_GROUP_get_seed_len(x);
Executed by:
  • libcrypto.so.1.1
17
154-
155 if (!BIO_indent(bp, off, 128))
!BIO_indent(bp, off, 128)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
156 goto err;
never executed: goto err;
0
157-
158 /* print the 'short name' of the field type */-
159 if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid))
BIO_printf(bp,...tmp_nid)) <= 0Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
160 <= 0)
BIO_printf(bp,...tmp_nid)) <= 0Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
161 goto err;
never executed: goto err;
0
162-
163 if (is_char_two) {
is_char_twoDescription
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
164 /* print the 'short name' of the base type OID */-
165 int basis_type = EC_GROUP_get_basis_type(x);-
166 if (basis_type == 0)
basis_type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
167 goto err;
never executed: goto err;
0
168-
169 if (!BIO_indent(bp, off, 128))
!BIO_indent(bp, off, 128)Description
TRUEnever evaluated
FALSEnever evaluated
0
170 goto err;
never executed: goto err;
0
171-
172 if (BIO_printf(bp, "Basis Type: %s\n",
BIO_printf(bp,...is_type)) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
173 OBJ_nid2sn(basis_type)) <= 0)
BIO_printf(bp,...is_type)) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
174 goto err;
never executed: goto err;
0
175-
176 /* print the polynomial */-
177 if ((p != NULL) && !ASN1_bn_print(bp, "Polynomial:", p, NULL,
(p != ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEnever evaluated
0
178 off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEnever evaluated
0
179 goto err;
never executed: goto err;
0
180 } else {
never executed: end of block
0
181 if ((p != NULL) && !ASN1_bn_print(bp, "Prime:", p, NULL, off))
(p != ((void *)0) )Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
182 goto err;
never executed: goto err;
0
183 }
executed 45 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
45
184 if ((a != NULL) && !ASN1_bn_print(bp, "A: ", a, NULL, off))
(a != ((void *)0) )Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
185 goto err;
never executed: goto err;
0
186 if ((b != NULL) && !ASN1_bn_print(bp, "B: ", b, NULL, off))
(b != ((void *)0) )Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
187 goto err;
never executed: goto err;
0
188 if (form == POINT_CONVERSION_COMPRESSED) {
form == POINT_...ION_COMPRESSEDDescription
TRUEevaluated 41 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-41
189 if ((gen != NULL) && !ASN1_bn_print(bp, gen_compressed, gen,
(gen != ((void *)0) )Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 41 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-41
190 NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 41 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-41
191 goto err;
never executed: goto err;
0
192 } else if (form == POINT_CONVERSION_UNCOMPRESSED) {
executed 41 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
form == POINT_...N_UNCOMPRESSEDDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-41
193 if ((gen != NULL) && !ASN1_bn_print(bp, gen_uncompressed, gen,
(gen != ((void *)0) )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
194 NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
195 goto err;
never executed: goto err;
0
196 } else { /* form == POINT_CONVERSION_HYBRID */
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
197-
198 if ((gen != NULL) && !ASN1_bn_print(bp, gen_hybrid, gen,
(gen != ((void *)0) )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
199 NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
200 goto err;
never executed: goto err;
0
201 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
202 if ((order != NULL) && !ASN1_bn_print(bp, "Order: ", order,
(order != ((void *)0) )Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
203 NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
204 goto err;
never executed: goto err;
0
205 if ((cofactor != NULL) && !ASN1_bn_print(bp, "Cofactor: ", cofactor,
(cofactor != ((void *)0) )Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
206 NULL, off))
!ASN1_bn_print...id *)0) , off)Description
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
207 goto err;
never executed: goto err;
0
208 if (seed && !print_bin(bp, "Seed:", seed, seed_len, off))
seedDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 28 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!print_bin(bp,...seed_len, off)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-28
209 goto err;
never executed: goto err;
0
210 }
executed 45 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
45
211 ret = 1;-
212 err:
code before this statement executed 279 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
279
213 if (!ret)
!retDescription
TRUEnever evaluated
FALSEevaluated 279 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-279
214 ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
never executed: ERR_put_error(16,(149),(reason),__FILE__,214);
0
215 BN_free(p);-
216 BN_free(a);-
217 BN_free(b);-
218 BN_free(gen);-
219 BN_CTX_free(ctx);-
220 return ret;
executed 279 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
279
221}-
222-
223static int print_bin(BIO *fp, const char *name, const unsigned char *buf,-
224 size_t len, int off)-
225{-
226 size_t i;-
227 char str[128 + 1 + 4];-
228-
229 if (buf == NULL)
buf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-17
230 return 1;
never executed: return 1;
0
231 if (off > 0) {
off > 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-12
232 if (off > 128)
off > 128Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
233 off = 128;
never executed: off = 128;
0
234 memset(str, ' ', off);-
235 if (BIO_write(fp, str, off) <= 0)
BIO_write(fp, str, off) <= 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
236 return 0;
never executed: return 0;
0
237 } else {
executed 5 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
5
238 off = 0;-
239 }
executed 12 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
12
240-
241 if (BIO_printf(fp, "%s", name) <= 0)
BIO_printf(fp,...s", name) <= 0Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-17
242 return 0;
never executed: return 0;
0
243-
244 for (i = 0; i < len; i++) {
i < lenDescription
TRUEevaluated 340 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
17-340
245 if ((i % 15) == 0) {
(i % 15) == 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 306 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
34-306
246 str[0] = '\n';-
247 memset(&(str[1]), ' ', off + 4);-
248 if (BIO_write(fp, str, off + 1 + 4) <= 0)
BIO_write(fp, ... + 1 + 4) <= 0Description
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-34
249 return 0;
never executed: return 0;
0
250 }
executed 34 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
34
251 if (BIO_printf(fp, "%02x%s", buf[i], ((i + 1) == len) ? "" : ":") <=
BIO_printf(fp,..."" : ":") <= 0Description
TRUEnever evaluated
FALSEevaluated 340 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-340
252 0)
BIO_printf(fp,..."" : ":") <= 0Description
TRUEnever evaluated
FALSEevaluated 340 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-340
253 return 0;
never executed: return 0;
0
254 }
executed 340 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
340
255 if (BIO_write(fp, "\n", 1) <= 0)
BIO_write(fp, "\n", 1) <= 0Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-17
256 return 0;
never executed: return 0;
0
257-
258 return 1;
executed 17 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
17
259}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2