OpenCoverage

evp_key.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/evp_key.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-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 "internal/cryptlib.h"-
12#include <openssl/x509.h>-
13#include <openssl/objects.h>-
14#include <openssl/evp.h>-
15#include <openssl/ui.h>-
16-
17/* should be init to zeros. */-
18static char prompt_string[80];-
19-
20void EVP_set_pw_prompt(const char *prompt)-
21{-
22 if (prompt == NULL)
prompt == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
23 prompt_string[0] = '\0';
never executed: prompt_string[0] = '\0';
0
24 else {-
25 strncpy(prompt_string, prompt, 79);-
26 prompt_string[79] = '\0';-
27 }
never executed: end of block
0
28}-
29-
30char *EVP_get_pw_prompt(void)-
31{-
32 if (prompt_string[0] == '\0')
prompt_string[0] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
33 return NULL;
never executed: return ((void *)0) ;
0
34 else-
35 return prompt_string;
never executed: return prompt_string;
0
36}-
37-
38/*-
39 * For historical reasons, the standard function for reading passwords is in-
40 * the DES library -- if someone ever wants to disable DES, this function-
41 * will fail-
42 */-
43int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)-
44{-
45 return EVP_read_pw_string_min(buf, 0, len, prompt, verify);
never executed: return EVP_read_pw_string_min(buf, 0, len, prompt, verify);
0
46}-
47-
48int EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt,-
49 int verify)-
50{-
51 int ret = -1;-
52 char buff[BUFSIZ];-
53 UI *ui;-
54-
55 if ((prompt == NULL) && (prompt_string[0] != '\0'))
(prompt == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
(prompt_string[0] != '\0')Description
TRUEnever evaluated
FALSEnever evaluated
0
56 prompt = prompt_string;
never executed: prompt = prompt_string;
0
57 ui = UI_new();-
58 if (ui == NULL)
ui == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
59 return ret;
never executed: return ret;
0
60 if (UI_add_input_string(ui, prompt, 0, buf, min,
UI_add_input_s...- 1 : len) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
61 (len >= BUFSIZ) ? BUFSIZ - 1 : len) < 0
UI_add_input_s...- 1 : len) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
62 || (verify
verifyDescription
TRUEnever evaluated
FALSEnever evaluated
0
63 && UI_add_verify_string(ui, prompt, 0, buff, min,
UI_add_verify_... len, buf) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
64 (len >= BUFSIZ) ? BUFSIZ - 1 : len,
UI_add_verify_... len, buf) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
65 buf) < 0))
UI_add_verify_... len, buf) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
66 goto end;
never executed: goto end;
0
67 ret = UI_process(ui);-
68 OPENSSL_cleanse(buff, BUFSIZ);-
69 end:
code before this statement never executed: end:
0
70 UI_free(ui);-
71 return ret;
never executed: return ret;
0
72}-
73-
74int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,-
75 const unsigned char *salt, const unsigned char *data,-
76 int datal, int count, unsigned char *key,-
77 unsigned char *iv)-
78{-
79 EVP_MD_CTX *c;-
80 unsigned char md_buf[EVP_MAX_MD_SIZE];-
81 int niv, nkey, addmd = 0;-
82 unsigned int mds = 0, i;-
83 int rv = 0;-
84 nkey = EVP_CIPHER_key_length(type);-
85 niv = EVP_CIPHER_iv_length(type);-
86 OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);-
87 OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);-
88-
89 if (data == NULL)
data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 605 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-605
90 return nkey;
never executed: return nkey;
0
91-
92 c = EVP_MD_CTX_new();-
93 if (c == NULL)
c == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 605 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-605
94 goto err;
never executed: goto err;
0
95 for (;;) {-
96 if (!EVP_DigestInit_ex(c, md, NULL))
!EVP_DigestIni... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 761 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-761
97 goto err;
never executed: goto err;
0
98 if (addmd++)
addmd++Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 605 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
156-605
99 if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
!EVP_DigestUpd..._buf[0]), mds)Description
TRUEnever evaluated
FALSEevaluated 156 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-156
100 goto err;
never executed: goto err;
0
101 if (!EVP_DigestUpdate(c, data, datal))
!EVP_DigestUpd..., data, datal)Description
TRUEnever evaluated
FALSEevaluated 761 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-761
102 goto err;
never executed: goto err;
0
103 if (salt != NULL)
salt != ((void *)0)Description
TRUEevaluated 761 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-761
104 if (!EVP_DigestUpdate(c, salt, PKCS5_SALT_LEN))
!EVP_DigestUpdate(c, salt, 8)Description
TRUEnever evaluated
FALSEevaluated 761 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-761
105 goto err;
never executed: goto err;
0
106 if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
!EVP_DigestFin...buf[0]), &mds)Description
TRUEnever evaluated
FALSEevaluated 761 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-761
107 goto err;
never executed: goto err;
0
108-
109 for (i = 1; i < (unsigned int)count; i++) {
i < (unsigned int)countDescription
TRUEnever evaluated
FALSEevaluated 761 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-761
110 if (!EVP_DigestInit_ex(c, md, NULL))
!EVP_DigestIni... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
111 goto err;
never executed: goto err;
0
112 if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
!EVP_DigestUpd..._buf[0]), mds)Description
TRUEnever evaluated
FALSEnever evaluated
0
113 goto err;
never executed: goto err;
0
114 if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
!EVP_DigestFin...buf[0]), &mds)Description
TRUEnever evaluated
FALSEnever evaluated
0
115 goto err;
never executed: goto err;
0
116 }
never executed: end of block
0
117 i = 0;-
118 if (nkey) {
nkeyDescription
TRUEevaluated 608 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 153 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
153-608
119 for (;;) {-
120 if (nkey == 0)
nkey == 0Description
TRUEevaluated 605 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11833 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
605-11833
121 break;
executed 605 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
605
122 if (i == mds)
i == mdsDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11830 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3-11830
123 break;
executed 3 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
3
124 if (key != NULL)
key != ((void *)0)Description
TRUEevaluated 11830 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-11830
125 *(key++) = md_buf[i];
executed 11830 times by 1 test: *(key++) = md_buf[i];
Executed by:
  • libcrypto.so.1.1
11830
126 nkey--;-
127 i++;-
128 }
executed 11830 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
11830
129 }
executed 608 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
608
130 if (niv && (i != mds)) {
nivDescription
TRUEevaluated 637 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 124 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(i != mds)Description
TRUEevaluated 555 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 82 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
82-637
131 for (;;) {-
132 if (niv == 0)
niv == 0Description
TRUEevaluated 481 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6138 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
481-6138
133 break;
executed 481 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
481
134 if (i == mds)
i == mdsDescription
TRUEevaluated 74 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6064 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
74-6064
135 break;
executed 74 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
74
136 if (iv != NULL)
iv != ((void *)0)Description
TRUEevaluated 6016 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
48-6016
137 *(iv++) = md_buf[i];
executed 6016 times by 1 test: *(iv++) = md_buf[i];
Executed by:
  • libcrypto.so.1.1
6016
138 niv--;-
139 i++;-
140 }
executed 6064 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6064
141 }
executed 555 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
555
142 if ((nkey == 0) && (niv == 0))
(nkey == 0)Description
TRUEevaluated 758 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(niv == 0)Description
TRUEevaluated 605 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 153 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3-758
143 break;
executed 605 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
605
144 }
executed 156 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
156
145 rv = EVP_CIPHER_key_length(type);-
146 err:
code before this statement executed 605 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
605
147 EVP_MD_CTX_free(c);-
148 OPENSSL_cleanse(md_buf, sizeof(md_buf));-
149 return rv;
executed 605 times by 1 test: return rv;
Executed by:
  • libcrypto.so.1.1
605
150}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2