OpenCoverage

ecdh_ossl.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ecdh_ossl.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2002-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 <string.h>-
12#include <limits.h>-
13-
14#include "internal/cryptlib.h"-
15-
16#include <openssl/err.h>-
17#include <openssl/bn.h>-
18#include <openssl/objects.h>-
19#include <openssl/ec.h>-
20#include "ec_lcl.h"-
21-
22int ossl_ecdh_compute_key(unsigned char **psec, size_t *pseclen,-
23 const EC_POINT *pub_key, const EC_KEY *ecdh)-
24{-
25 if (ecdh->group->meth->ecdh_compute_key == NULL) {
ecdh->group->m...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1213
26 ECerr(EC_F_OSSL_ECDH_COMPUTE_KEY, EC_R_CURVE_DOES_NOT_SUPPORT_ECDH);-
27 return 0;
never executed: return 0;
0
28 }-
29-
30 return ecdh->group->meth->ecdh_compute_key(psec, pseclen, pub_key, ecdh);
executed 1213 times by 1 test: return ecdh->group->meth->ecdh_compute_key(psec, pseclen, pub_key, ecdh);
Executed by:
  • libcrypto.so.1.1
1213
31}-
32-
33/*--
34 * This implementation is based on the following primitives in the IEEE 1363 standard:-
35 * - ECKAS-DH1-
36 * - ECSVDP-DH-
37 */-
38int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen,-
39 const EC_POINT *pub_key, const EC_KEY *ecdh)-
40{-
41 BN_CTX *ctx;-
42 EC_POINT *tmp = NULL;-
43 BIGNUM *x = NULL;-
44 const BIGNUM *priv_key;-
45 const EC_GROUP *group;-
46 int ret = 0;-
47 size_t buflen, len;-
48 unsigned char *buf = NULL;-
49-
50 if ((ctx = BN_CTX_new()) == NULL)
(ctx = BN_CTX_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1213
51 goto err;
never executed: goto err;
0
52 BN_CTX_start(ctx);-
53 x = BN_CTX_get(ctx);-
54 if (x == NULL) {
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1213
55 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);-
56 goto err;
never executed: goto err;
0
57 }-
58-
59 priv_key = EC_KEY_get0_private_key(ecdh);-
60 if (priv_key == NULL) {
priv_key == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1213
61 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_NO_PRIVATE_VALUE);-
62 goto err;
never executed: goto err;
0
63 }-
64-
65 group = EC_KEY_get0_group(ecdh);-
66-
67 if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) {
EC_KEY_get_fla...ecdh) & 0x1000Description
TRUEevaluated 421 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 792 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
421-792
68 if (!EC_GROUP_get_cofactor(group, x, NULL) ||
!EC_GROUP_get_... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 421 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-421
69 !BN_mul(x, x, priv_key, ctx)) {
!BN_mul(x, x, priv_key, ctx)Description
TRUEnever evaluated
FALSEevaluated 421 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-421
70 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);-
71 goto err;
never executed: goto err;
0
72 }-
73 priv_key = x;-
74 }
executed 421 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
421
75-
76 if ((tmp = EC_POINT_new(group)) == NULL) {
(tmp = EC_POIN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1213
77 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);-
78 goto err;
never executed: goto err;
0
79 }-
80-
81 if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) {
!EC_POINT_mul(...priv_key, ctx)Description
TRUEnever evaluated
FALSEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1213
82 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_POINT_ARITHMETIC_FAILURE);-
83 goto err;
never executed: goto err;
0
84 }-
85-
86 if (!EC_POINT_get_affine_coordinates(group, tmp, x, NULL, ctx)) {
!EC_POINT_get_...id *)0) , ctx)Description
TRUEevaluated 93 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1120 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
93-1120
87 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, EC_R_POINT_ARITHMETIC_FAILURE);-
88 goto err;
executed 93 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
93
89 }-
90-
91 buflen = (EC_GROUP_get_degree(group) + 7) / 8;-
92 len = BN_num_bytes(x);-
93 if (len > buflen) {
len > buflenDescription
TRUEnever evaluated
FALSEevaluated 1120 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1120
94 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_INTERNAL_ERROR);-
95 goto err;
never executed: goto err;
0
96 }-
97 if ((buf = OPENSSL_malloc(buflen)) == NULL) {
(buf = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1120 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1120
98 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);-
99 goto err;
never executed: goto err;
0
100 }-
101-
102 memset(buf, 0, buflen - len);-
103 if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) {
len != (size_t... buflen - len)Description
TRUEnever evaluated
FALSEevaluated 1120 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1120
104 ECerr(EC_F_ECDH_SIMPLE_COMPUTE_KEY, ERR_R_BN_LIB);-
105 goto err;
never executed: goto err;
0
106 }-
107-
108 *pout = buf;-
109 *poutlen = buflen;-
110 buf = NULL;-
111-
112 ret = 1;-
113-
114 err:
code before this statement executed 1120 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
1120
115 EC_POINT_free(tmp);-
116 if (ctx)
ctxDescription
TRUEevaluated 1213 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1213
117 BN_CTX_end(ctx);
executed 1213 times by 1 test: BN_CTX_end(ctx);
Executed by:
  • libcrypto.so.1.1
1213
118 BN_CTX_free(ctx);-
119 OPENSSL_free(buf);-
120 return ret;
executed 1213 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1213
121}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2