| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/evp_key.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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. */ | - | ||||||||||||
| 18 | static char prompt_string[80]; | - | ||||||||||||
| 19 | - | |||||||||||||
| 20 | void EVP_set_pw_prompt(const char *prompt) | - | ||||||||||||
| 21 | { | - | ||||||||||||
| 22 | if (prompt == NULL)
| 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 | - | |||||||||||||
| 30 | char *EVP_get_pw_prompt(void) | - | ||||||||||||
| 31 | { | - | ||||||||||||
| 32 | if (prompt_string[0] == '\0')
| 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 | */ | - | ||||||||||||
| 43 | int 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 | - | |||||||||||||
| 48 | int 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'))
| 0 | ||||||||||||
| 56 | prompt = prompt_string; never executed: prompt = prompt_string; | 0 | ||||||||||||
| 57 | ui = UI_new(); | - | ||||||||||||
| 58 | if (ui == NULL)
| 0 | ||||||||||||
| 59 | return ret; never executed: return ret; | 0 | ||||||||||||
| 60 | if (UI_add_input_string(ui, prompt, 0, buf, min,
| 0 | ||||||||||||
| 61 | (len >= BUFSIZ) ? BUFSIZ - 1 : len) < 0
| 0 | ||||||||||||
| 62 | || (verify
| 0 | ||||||||||||
| 63 | && UI_add_verify_string(ui, prompt, 0, buff, min,
| 0 | ||||||||||||
| 64 | (len >= BUFSIZ) ? BUFSIZ - 1 : len,
| 0 | ||||||||||||
| 65 | buf) < 0))
| 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 | - | |||||||||||||
| 74 | int 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)
| 0-605 | ||||||||||||
| 90 | return nkey; never executed: return nkey; | 0 | ||||||||||||
| 91 | - | |||||||||||||
| 92 | c = EVP_MD_CTX_new(); | - | ||||||||||||
| 93 | if (c == NULL)
| 0-605 | ||||||||||||
| 94 | goto err; never executed: goto err; | 0 | ||||||||||||
| 95 | for (;;) { | - | ||||||||||||
| 96 | if (!EVP_DigestInit_ex(c, md, NULL))
| 0-761 | ||||||||||||
| 97 | goto err; never executed: goto err; | 0 | ||||||||||||
| 98 | if (addmd++)
| 156-605 | ||||||||||||
| 99 | if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
| 0-156 | ||||||||||||
| 100 | goto err; never executed: goto err; | 0 | ||||||||||||
| 101 | if (!EVP_DigestUpdate(c, data, datal))
| 0-761 | ||||||||||||
| 102 | goto err; never executed: goto err; | 0 | ||||||||||||
| 103 | if (salt != NULL)
| 0-761 | ||||||||||||
| 104 | if (!EVP_DigestUpdate(c, salt, PKCS5_SALT_LEN))
| 0-761 | ||||||||||||
| 105 | goto err; never executed: goto err; | 0 | ||||||||||||
| 106 | if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
| 0-761 | ||||||||||||
| 107 | goto err; never executed: goto err; | 0 | ||||||||||||
| 108 | - | |||||||||||||
| 109 | for (i = 1; i < (unsigned int)count; i++) {
| 0-761 | ||||||||||||
| 110 | if (!EVP_DigestInit_ex(c, md, NULL))
| 0 | ||||||||||||
| 111 | goto err; never executed: goto err; | 0 | ||||||||||||
| 112 | if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
| 0 | ||||||||||||
| 113 | goto err; never executed: goto err; | 0 | ||||||||||||
| 114 | if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
| 0 | ||||||||||||
| 115 | goto err; never executed: goto err; | 0 | ||||||||||||
| 116 | } never executed: end of block | 0 | ||||||||||||
| 117 | i = 0; | - | ||||||||||||
| 118 | if (nkey) {
| 153-608 | ||||||||||||
| 119 | for (;;) { | - | ||||||||||||
| 120 | if (nkey == 0)
| 605-11833 | ||||||||||||
| 121 | break; executed 605 times by 1 test: break;Executed by:
| 605 | ||||||||||||
| 122 | if (i == mds)
| 3-11830 | ||||||||||||
| 123 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||
| 124 | if (key != NULL)
| 0-11830 | ||||||||||||
| 125 | *(key++) = md_buf[i]; executed 11830 times by 1 test: *(key++) = md_buf[i];Executed by:
| 11830 | ||||||||||||
| 126 | nkey--; | - | ||||||||||||
| 127 | i++; | - | ||||||||||||
| 128 | } executed 11830 times by 1 test: end of blockExecuted by:
| 11830 | ||||||||||||
| 129 | } executed 608 times by 1 test: end of blockExecuted by:
| 608 | ||||||||||||
| 130 | if (niv && (i != mds)) {
| 82-637 | ||||||||||||
| 131 | for (;;) { | - | ||||||||||||
| 132 | if (niv == 0)
| 481-6138 | ||||||||||||
| 133 | break; executed 481 times by 1 test: break;Executed by:
| 481 | ||||||||||||
| 134 | if (i == mds)
| 74-6064 | ||||||||||||
| 135 | break; executed 74 times by 1 test: break;Executed by:
| 74 | ||||||||||||
| 136 | if (iv != NULL)
| 48-6016 | ||||||||||||
| 137 | *(iv++) = md_buf[i]; executed 6016 times by 1 test: *(iv++) = md_buf[i];Executed by:
| 6016 | ||||||||||||
| 138 | niv--; | - | ||||||||||||
| 139 | i++; | - | ||||||||||||
| 140 | } executed 6064 times by 1 test: end of blockExecuted by:
| 6064 | ||||||||||||
| 141 | } executed 555 times by 1 test: end of blockExecuted by:
| 555 | ||||||||||||
| 142 | if ((nkey == 0) && (niv == 0))
| 3-758 | ||||||||||||
| 143 | break; executed 605 times by 1 test: break;Executed by:
| 605 | ||||||||||||
| 144 | } executed 156 times by 1 test: end of blockExecuted by:
| 156 | ||||||||||||
| 145 | rv = EVP_CIPHER_key_length(type); | - | ||||||||||||
| 146 | err: code before this statement executed 605 times by 1 test: err:Executed by:
| 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:
| 605 | ||||||||||||
| 150 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |