| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/p5_crpt2.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, | - | ||||||||||||||||||
| 3 | const unsigned char *salt, int saltlen, int iter, | - | ||||||||||||||||||
| 4 | const EVP_MD *digest, int keylen, unsigned char *out) | - | ||||||||||||||||||
| 5 | { | - | ||||||||||||||||||
| 6 | const char *empty = ""; | - | ||||||||||||||||||
| 7 | unsigned char digtmp[64], *p, itmp[4]; | - | ||||||||||||||||||
| 8 | int cplen, j, k, tkeylen, mdlen; | - | ||||||||||||||||||
| 9 | unsigned long i = 1; | - | ||||||||||||||||||
| 10 | HMAC_CTX *hctx_tpl = | - | ||||||||||||||||||
| 11 | ((void *)0) | - | ||||||||||||||||||
| 12 | , *hctx = | - | ||||||||||||||||||
| 13 | ((void *)0) | - | ||||||||||||||||||
| 14 | ; | - | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | mdlen = EVP_MD_size(digest); | - | ||||||||||||||||||
| 17 | if (mdlen < 0
| 0-39 | ||||||||||||||||||
| 18 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | hctx_tpl = HMAC_CTX_new(); | - | ||||||||||||||||||
| 21 | if (hctx_tpl ==
| 0-39 | ||||||||||||||||||
| 22 | ((void *)0)
| 0-39 | ||||||||||||||||||
| 23 | ) | - | ||||||||||||||||||
| 24 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 25 | p = out; | - | ||||||||||||||||||
| 26 | tkeylen = keylen; | - | ||||||||||||||||||
| 27 | if (pass ==
| 3-36 | ||||||||||||||||||
| 28 | ((void *)0)
| 3-36 | ||||||||||||||||||
| 29 | ) { | - | ||||||||||||||||||
| 30 | pass = empty; | - | ||||||||||||||||||
| 31 | passlen = 0; | - | ||||||||||||||||||
| 32 | } executed 3 times by 1 test: else if (passlen == -1end of blockExecuted by:
| 0-36 | ||||||||||||||||||
| 33 | passlen = strlen(pass); | - | ||||||||||||||||||
| 34 | } never executed: end of block | 0 | ||||||||||||||||||
| 35 | if (!HMAC_Init_ex(hctx_tpl, pass, passlen, digest,
| 0-39 | ||||||||||||||||||
| 36 | ((void *)0)
| 0-39 | ||||||||||||||||||
| 37 | )
| 0-39 | ||||||||||||||||||
| 38 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 39 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 40 | } | - | ||||||||||||||||||
| 41 | hctx = HMAC_CTX_new(); | - | ||||||||||||||||||
| 42 | if (hctx ==
| 0-39 | ||||||||||||||||||
| 43 | ((void *)0)
| 0-39 | ||||||||||||||||||
| 44 | ) { | - | ||||||||||||||||||
| 45 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 46 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 47 | } | - | ||||||||||||||||||
| 48 | while (tkeylen
| 39-2673 | ||||||||||||||||||
| 49 | if (tkeylen > mdlen
| 39-2634 | ||||||||||||||||||
| 50 | cplen = mdlen; executed 2634 times by 1 test: cplen = mdlen;Executed by:
| 2634 | ||||||||||||||||||
| 51 | else | - | ||||||||||||||||||
| 52 | cplen = tkeylen; executed 39 times by 1 test: cplen = tkeylen;Executed by:
| 39 | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | itmp[0] = (unsigned char)((i >> 24) & 0xff); | - | ||||||||||||||||||
| 58 | itmp[1] = (unsigned char)((i >> 16) & 0xff); | - | ||||||||||||||||||
| 59 | itmp[2] = (unsigned char)((i >> 8) & 0xff); | - | ||||||||||||||||||
| 60 | itmp[3] = (unsigned char)(i & 0xff); | - | ||||||||||||||||||
| 61 | if (!HMAC_CTX_copy(hctx, hctx_tpl)
| 0-2673 | ||||||||||||||||||
| 62 | HMAC_CTX_free(hctx); | - | ||||||||||||||||||
| 63 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 64 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 65 | } | - | ||||||||||||||||||
| 66 | if (!HMAC_Update(hctx, salt, saltlen)
| 0-2673 | ||||||||||||||||||
| 67 | || !HMAC_Update(hctx, itmp, 4)
| 0-2673 | ||||||||||||||||||
| 68 | || !HMAC_Final(hctx, digtmp,
| 0-2673 | ||||||||||||||||||
| 69 | ((void *)0)
| 0-2673 | ||||||||||||||||||
| 70 | )
| 0-2673 | ||||||||||||||||||
| 71 | HMAC_CTX_free(hctx); | - | ||||||||||||||||||
| 72 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 73 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 74 | } | - | ||||||||||||||||||
| 75 | memcpy(p, digtmp, cplen); | - | ||||||||||||||||||
| 76 | for (j = 1; j < iter
| 2673-45048 | ||||||||||||||||||
| 77 | if (!HMAC_CTX_copy(hctx, hctx_tpl)
| 0-45048 | ||||||||||||||||||
| 78 | HMAC_CTX_free(hctx); | - | ||||||||||||||||||
| 79 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 80 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | if (!HMAC_Update(hctx, digtmp, mdlen)
| 0-45048 | ||||||||||||||||||
| 83 | || !HMAC_Final(hctx, digtmp,
| 0-45048 | ||||||||||||||||||
| 84 | ((void *)0)
| 0-45048 | ||||||||||||||||||
| 85 | )
| 0-45048 | ||||||||||||||||||
| 86 | HMAC_CTX_free(hctx); | - | ||||||||||||||||||
| 87 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 88 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 89 | } | - | ||||||||||||||||||
| 90 | for (k = 0; k < cplen
| 45048-1199951 | ||||||||||||||||||
| 91 | p[k] ^= digtmp[k]; executed 1199951 times by 1 test: p[k] ^= digtmp[k];Executed by:
| 1199951 | ||||||||||||||||||
| 92 | } executed 45048 times by 1 test: end of blockExecuted by:
| 45048 | ||||||||||||||||||
| 93 | tkeylen -= cplen; | - | ||||||||||||||||||
| 94 | i++; | - | ||||||||||||||||||
| 95 | p += cplen; | - | ||||||||||||||||||
| 96 | } executed 2673 times by 1 test: end of blockExecuted by:
| 2673 | ||||||||||||||||||
| 97 | HMAC_CTX_free(hctx); | - | ||||||||||||||||||
| 98 | HMAC_CTX_free(hctx_tpl); | - | ||||||||||||||||||
| 99 | return executed 39 times by 1 test: 1;return 1;Executed by:
executed 39 times by 1 test: return 1;Executed by:
| 39 | ||||||||||||||||||
| 100 | } | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, | - | ||||||||||||||||||
| 103 | const unsigned char *salt, int saltlen, int iter, | - | ||||||||||||||||||
| 104 | int keylen, unsigned char *out) | - | ||||||||||||||||||
| 105 | { | - | ||||||||||||||||||
| 106 | return never executed: PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(),return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(), keylen, out);never executed: return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(), keylen, out); | 0 | ||||||||||||||||||
| 107 | keylen, out); never executed: return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(), keylen, out); | 0 | ||||||||||||||||||
| 108 | } | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | - | ||||||||||||||||||
| 117 | ASN1_TYPE *param, const EVP_CIPHER *c, | - | ||||||||||||||||||
| 118 | const EVP_MD *md, int en_de) | - | ||||||||||||||||||
| 119 | { | - | ||||||||||||||||||
| 120 | PBE2PARAM *pbe2 = | - | ||||||||||||||||||
| 121 | ((void *)0) | - | ||||||||||||||||||
| 122 | ; | - | ||||||||||||||||||
| 123 | const EVP_CIPHER *cipher; | - | ||||||||||||||||||
| 124 | EVP_PBE_KEYGEN *kdf; | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | int rv = 0; | - | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | pbe2 = ASN1_TYPE_unpack_sequence((&(PBE2PARAM_it)), param); | - | ||||||||||||||||||
| 129 | if (pbe2 ==
| 0 | ||||||||||||||||||
| 130 | ((void *)0)
| 0 | ||||||||||||||||||
| 131 | ) { | - | ||||||||||||||||||
| 132 | ERR_put_error(6,(118),(114),__FILE__,150); | - | ||||||||||||||||||
| 133 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 134 | } | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | if (!EVP_PBE_find(0x2, OBJ_obj2nid(pbe2->keyfunc->algorithm),
| 0 | ||||||||||||||||||
| 138 |
| 0 | ||||||||||||||||||
| 139 | ((void *)0)
| 0 | ||||||||||||||||||
| 140 | ,
| 0 | ||||||||||||||||||
| 141 | ((void *)0)
| 0 | ||||||||||||||||||
| 142 | , &kdf)
| 0 | ||||||||||||||||||
| 143 | ERR_put_error(6,(118),(124),__FILE__,158) | - | ||||||||||||||||||
| 144 | ; | - | ||||||||||||||||||
| 145 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 146 | } | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | cipher = EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm))); | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | if (!cipher
| 0 | ||||||||||||||||||
| 155 | ERR_put_error(6,(118),(107),__FILE__,169); | - | ||||||||||||||||||
| 156 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | if (!EVP_CipherInit_ex(ctx, cipher,
| 0 | ||||||||||||||||||
| 161 | ((void *)0)
| 0 | ||||||||||||||||||
| 162 | ,
| 0 | ||||||||||||||||||
| 163 | ((void *)0)
| 0 | ||||||||||||||||||
| 164 | ,
| 0 | ||||||||||||||||||
| 165 | ((void *)0)
| 0 | ||||||||||||||||||
| 166 | , en_de)
| 0 | ||||||||||||||||||
| 167 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 168 | if (EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0
| 0 | ||||||||||||||||||
| 169 | ERR_put_error(6,(118),(122),__FILE__,177); | - | ||||||||||||||||||
| 170 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 171 | } | - | ||||||||||||||||||
| 172 | rv = kdf(ctx, pass, passlen, pbe2->keyfunc->parameter, | - | ||||||||||||||||||
| 173 | ((void *)0) | - | ||||||||||||||||||
| 174 | , | - | ||||||||||||||||||
| 175 | ((void *)0) | - | ||||||||||||||||||
| 176 | , en_de); | - | ||||||||||||||||||
| 177 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
| 178 | PBE2PARAM_free(pbe2); | - | ||||||||||||||||||
| 179 | return never executed: rv;return rv;never executed: return rv; | 0 | ||||||||||||||||||
| 180 | } | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, | - | ||||||||||||||||||
| 183 | int passlen, ASN1_TYPE *param, | - | ||||||||||||||||||
| 184 | const EVP_CIPHER *c, const EVP_MD *md, int en_de) | - | ||||||||||||||||||
| 185 | { | - | ||||||||||||||||||
| 186 | unsigned char *salt, key[64]; | - | ||||||||||||||||||
| 187 | int saltlen, iter; | - | ||||||||||||||||||
| 188 | int rv = 0; | - | ||||||||||||||||||
| 189 | unsigned int keylen = 0; | - | ||||||||||||||||||
| 190 | int prf_nid, hmac_md_nid; | - | ||||||||||||||||||
| 191 | PBKDF2PARAM *kdf = | - | ||||||||||||||||||
| 192 | ((void *)0) | - | ||||||||||||||||||
| 193 | ; | - | ||||||||||||||||||
| 194 | const EVP_MD *prfmd; | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | if (EVP_CIPHER_CTX_cipher(ctx) ==
| 0 | ||||||||||||||||||
| 197 | ((void *)0)
| 0 | ||||||||||||||||||
| 198 | ) { | - | ||||||||||||||||||
| 199 | ERR_put_error(6,(164),(131),__FILE__,199); | - | ||||||||||||||||||
| 200 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 201 | } | - | ||||||||||||||||||
| 202 | keylen = EVP_CIPHER_CTX_key_length(ctx); | - | ||||||||||||||||||
| 203 | (void)((keylen <= sizeof(key)) ? 0 : (OPENSSL_die("assertion failed: " "keylen <= sizeof(key)", __FILE__, 203), 1)); | - | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | kdf = ASN1_TYPE_unpack_sequence((&(PBKDF2PARAM_it)), param); | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | if (kdf ==
| 0 | ||||||||||||||||||
| 210 | ((void *)0)
| 0 | ||||||||||||||||||
| 211 | ) { | - | ||||||||||||||||||
| 212 | ERR_put_error(6,(164),(114),__FILE__,210); | - | ||||||||||||||||||
| 213 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 214 | } | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | keylen = EVP_CIPHER_CTX_key_length(ctx); | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | if (kdf->keylength
| 0 | ||||||||||||||||||
| 221 | ERR_put_error(6,(164),(123),__FILE__,219); | - | ||||||||||||||||||
| 222 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 223 | } | - | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | if (kdf->prf
| 0 | ||||||||||||||||||
| 226 | prf_nid = OBJ_obj2nid(kdf->prf->algorithm); never executed: prf_nid = OBJ_obj2nid(kdf->prf->algorithm); | 0 | ||||||||||||||||||
| 227 | else | - | ||||||||||||||||||
| 228 | prf_nid = 163; never executed: prf_nid = 163; | 0 | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | if (!EVP_PBE_find(0x1, prf_nid,
| 0 | ||||||||||||||||||
| 231 | ((void *)0)
| 0 | ||||||||||||||||||
| 232 | , &hmac_md_nid, 0)
| 0 | ||||||||||||||||||
| 233 | ERR_put_error(6,(164),(125),__FILE__,229); | - | ||||||||||||||||||
| 234 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | prfmd = EVP_get_digestbyname(OBJ_nid2sn(hmac_md_nid)); | - | ||||||||||||||||||
| 238 | if (prfmd ==
| 0 | ||||||||||||||||||
| 239 | ((void *)0)
| 0 | ||||||||||||||||||
| 240 | ) { | - | ||||||||||||||||||
| 241 | ERR_put_error(6,(164),(125),__FILE__,235); | - | ||||||||||||||||||
| 242 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 243 | } | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | if (kdf->salt->type != 4
| 0 | ||||||||||||||||||
| 246 | ERR_put_error(6,(164),(126),__FILE__,240); | - | ||||||||||||||||||
| 247 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | salt = kdf->salt->value.octet_string->data; | - | ||||||||||||||||||
| 252 | saltlen = kdf->salt->value.octet_string->length; | - | ||||||||||||||||||
| 253 | iter = ASN1_INTEGER_get(kdf->iter); | - | ||||||||||||||||||
| 254 | if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd,
| 0 | ||||||||||||||||||
| 255 | keylen, key)
| 0 | ||||||||||||||||||
| 256 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 257 | rv = EVP_CipherInit_ex(ctx, | - | ||||||||||||||||||
| 258 | ((void *)0) | - | ||||||||||||||||||
| 259 | , | - | ||||||||||||||||||
| 260 | ((void *)0) | - | ||||||||||||||||||
| 261 | , key, | - | ||||||||||||||||||
| 262 | ((void *)0) | - | ||||||||||||||||||
| 263 | , en_de); | - | ||||||||||||||||||
| 264 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
| 265 | OPENSSL_cleanse(key, keylen); | - | ||||||||||||||||||
| 266 | PBKDF2PARAM_free(kdf); | - | ||||||||||||||||||
| 267 | return never executed: rv;return rv;never executed: return rv; | 0 | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |