| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/hkdf/hkdf.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | int | - | ||||||||||||
| 6 | HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest, | - | ||||||||||||
| 7 | const uint8_t *secret, size_t secret_len, const uint8_t *salt, | - | ||||||||||||
| 8 | size_t salt_len, const uint8_t *info, size_t info_len) | - | ||||||||||||
| 9 | { | - | ||||||||||||
| 10 | uint8_t prk[64]; | - | ||||||||||||
| 11 | size_t prk_len; | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | if (!HKDF_extract(prk, &prk_len, digest, secret, secret_len, salt,
| 0-7 | ||||||||||||
| 14 | salt_len)
| 0-7 | ||||||||||||
| 15 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 16 | if (!HKDF_expand(out_key, out_len, digest, prk, prk_len, info,
| 0-7 | ||||||||||||
| 17 | info_len)
| 0-7 | ||||||||||||
| 18 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 19 | - | |||||||||||||
| 20 | return executed 7 times by 1 test: 1;return 1;Executed by:
executed 7 times by 1 test: return 1;Executed by:
| 7 | ||||||||||||
| 21 | } | - | ||||||||||||
| 22 | - | |||||||||||||
| 23 | - | |||||||||||||
| 24 | int | - | ||||||||||||
| 25 | HKDF_extract(uint8_t *out_key, size_t *out_len, | - | ||||||||||||
| 26 | const EVP_MD *digest, const uint8_t *secret, size_t secret_len, | - | ||||||||||||
| 27 | const uint8_t *salt, size_t salt_len) | - | ||||||||||||
| 28 | { | - | ||||||||||||
| 29 | unsigned int len; | - | ||||||||||||
| 30 | - | |||||||||||||
| 31 | - | |||||||||||||
| 32 | - | |||||||||||||
| 33 | - | |||||||||||||
| 34 | - | |||||||||||||
| 35 | if (HMAC(digest, salt, salt_len, secret, secret_len, out_key, &len) ==
| 0-14 | ||||||||||||
| 36 |
| 0-14 | ||||||||||||
| 37 | ((void *)0)
| 0-14 | ||||||||||||
| 38 | ) { | - | ||||||||||||
| 39 | ERR_put_error(15,(0xfff),(15),__FILE__,58); | - | ||||||||||||
| 40 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 41 | } | - | ||||||||||||
| 42 | *out_len = len; | - | ||||||||||||
| 43 | return executed 14 times by 1 test: 1;return 1;Executed by:
executed 14 times by 1 test: return 1;Executed by:
| 14 | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | - | |||||||||||||
| 47 | int | - | ||||||||||||
| 48 | HKDF_expand(uint8_t *out_key, size_t out_len, | - | ||||||||||||
| 49 | const EVP_MD *digest, const uint8_t *prk, size_t prk_len, | - | ||||||||||||
| 50 | const uint8_t *info, size_t info_len) | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | const size_t digest_len = EVP_MD_size(digest); | - | ||||||||||||
| 53 | uint8_t previous[64]; | - | ||||||||||||
| 54 | size_t n, done = 0; | - | ||||||||||||
| 55 | unsigned int i; | - | ||||||||||||
| 56 | int ret = 0; | - | ||||||||||||
| 57 | HMAC_CTX hmac; | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | - | |||||||||||||
| 60 | n = (out_len + digest_len - 1) / digest_len; | - | ||||||||||||
| 61 | if (out_len + digest_len < out_len
| 0-14 | ||||||||||||
| 62 | ERR_put_error(15,(0xfff),(164),__FILE__,81); | - | ||||||||||||
| 63 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 64 | } | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | HMAC_CTX_init(&hmac); | - | ||||||||||||
| 67 | if (!HMAC_Init_ex(&hmac, prk, prk_len, digest,
| 0-14 | ||||||||||||
| 68 | ((void *)0)
| 0-14 | ||||||||||||
| 69 | )
| 0-14 | ||||||||||||
| 70 | goto never executed: out;goto out;never executed: goto out; | 0 | ||||||||||||
| 71 | - | |||||||||||||
| 72 | for (i = 0; i < n
| 14-42 | ||||||||||||
| 73 | uint8_t ctr = i + 1; | - | ||||||||||||
| 74 | size_t todo; | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | if (i != 0
| 0-28 | ||||||||||||
| 77 | ((void *)0)
| 0-28 | ||||||||||||
| 78 | , 0,
| 0-28 | ||||||||||||
| 79 | ((void *)0)
| 0-28 | ||||||||||||
| 80 | ,
| 0-28 | ||||||||||||
| 81 | ((void *)0)
| 0-28 | ||||||||||||
| 82 | )
| 0-28 | ||||||||||||
| 83 | !HMAC_Update(&hmac, previous, digest_len)
| 0-28 | ||||||||||||
| 84 | goto never executed: out;goto out;never executed: goto out; | 0 | ||||||||||||
| 85 | - | |||||||||||||
| 86 | if (!HMAC_Update(&hmac, info, info_len)
| 0-42 | ||||||||||||
| 87 | !HMAC_Update(&hmac, &ctr, 1)
| 0-42 | ||||||||||||
| 88 | !HMAC_Final(&hmac, previous,
| 0-42 | ||||||||||||
| 89 | ((void *)0)
| 0-42 | ||||||||||||
| 90 | )
| 0-42 | ||||||||||||
| 91 | goto never executed: out;goto out;never executed: goto out; | 0 | ||||||||||||
| 92 | - | |||||||||||||
| 93 | todo = digest_len; | - | ||||||||||||
| 94 | if (done + todo > out_len
| 14-28 | ||||||||||||
| 95 | todo = out_len - done; executed 14 times by 1 test: todo = out_len - done;Executed by:
| 14 | ||||||||||||
| 96 | - | |||||||||||||
| 97 | memcpy(out_key + done, previous, todo); | - | ||||||||||||
| 98 | done += todo; | - | ||||||||||||
| 99 | } executed 42 times by 1 test: end of blockExecuted by:
| 42 | ||||||||||||
| 100 | - | |||||||||||||
| 101 | ret = 1; | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | out: code before this statement executed 14 times by 1 test: out:Executed by:
| 14 | ||||||||||||
| 104 | HMAC_CTX_cleanup(&hmac); | - | ||||||||||||
| 105 | if (ret != 1
| 0-14 | ||||||||||||
| 106 | ERR_put_error(15,(0xfff),(15),__FILE__,115); never executed: ERR_put_error(15,(0xfff),(15),__FILE__,115); | 0 | ||||||||||||
| 107 | return executed 14 times by 1 test: ret;return ret;Executed by:
executed 14 times by 1 test: return ret;Executed by:
| 14 | ||||||||||||
| 108 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |