| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/digest-openssl.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | struct ssh_digest_ctx { | - | ||||||||||||
| 10 | int alg; | - | ||||||||||||
| 11 | EVP_MD_CTX *mdctx; | - | ||||||||||||
| 12 | }; | - | ||||||||||||
| 13 | - | |||||||||||||
| 14 | struct ssh_digest { | - | ||||||||||||
| 15 | int id; | - | ||||||||||||
| 16 | const char *name; | - | ||||||||||||
| 17 | size_t digest_len; | - | ||||||||||||
| 18 | const EVP_MD *(*mdfunc)(void); | - | ||||||||||||
| 19 | }; | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | - | |||||||||||||
| 22 | const struct ssh_digest digests[] = { | - | ||||||||||||
| 23 | { 0, "MD5", 16, EVP_md5 }, | - | ||||||||||||
| 24 | { 1, "SHA1", 20, EVP_sha1 }, | - | ||||||||||||
| 25 | { 2, "SHA256", 32, EVP_sha256 }, | - | ||||||||||||
| 26 | { 3, "SHA384", 48, EVP_sha384 }, | - | ||||||||||||
| 27 | { 4, "SHA512", 64, EVP_sha512 }, | - | ||||||||||||
| 28 | { -1, | - | ||||||||||||
| 29 | ((void *)0) | - | ||||||||||||
| 30 | , 0, | - | ||||||||||||
| 31 | ((void *)0) | - | ||||||||||||
| 32 | }, | - | ||||||||||||
| 33 | }; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | static const struct ssh_digest * | - | ||||||||||||
| 36 | ssh_digest_by_alg(int alg) | - | ||||||||||||
| 37 | { | - | ||||||||||||
| 38 | if (alg < 0
| 0-212817 | ||||||||||||
| 39 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 40 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 41 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 42 | if (digests[alg].id != alg
| 0-212817 | ||||||||||||
| 43 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 44 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 45 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 46 | if (digests[alg].mdfunc ==
| 0-212817 | ||||||||||||
| 47 | ((void *)0)
| 0-212817 | ||||||||||||
| 48 | ) | - | ||||||||||||
| 49 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 50 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 51 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 52 | return executed 212817 times by 5 tests: &(digests[alg]);return &(digests[alg]);Executed by:
executed 212817 times by 5 tests: return &(digests[alg]);Executed by:
| 212817 | ||||||||||||
| 53 | } | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | int | - | ||||||||||||
| 56 | ssh_digest_alg_by_name(const char *name) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | int alg; | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | for (alg = 0; digests[alg].id != -1
| 0-4 | ||||||||||||
| 61 | if (strcasecmp(name, digests[alg].name) == 0
| 2 | ||||||||||||
| 62 | return executed 2 times by 1 test: digests[alg].id;return digests[alg].id;Executed by:
executed 2 times by 1 test: return digests[alg].id;Executed by:
| 2 | ||||||||||||
| 63 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 64 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 65 | } | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | const char * | - | ||||||||||||
| 68 | ssh_digest_alg_name(int alg) | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | const struct ssh_digest *digest = ssh_digest_by_alg(alg); | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | return executed 31 times by 3 tests: digest == return digest == ((void *)0) ? ((void *)0) : digest->name;Executed by:
executed 31 times by 3 tests: return digest == ((void *)0) ? ((void *)0) : digest->name;Executed by:
| 0-31 | ||||||||||||
| 73 | ((void *)0)
executed 31 times by 3 tests: return digest == ((void *)0) ? ((void *)0) : digest->name;Executed by:
| 0-31 | ||||||||||||
| 74 | ? executed 31 times by 3 tests: return digest == ((void *)0) ? ((void *)0) : digest->name;Executed by:
| 31 | ||||||||||||
| 75 | ((void *)0) executed 31 times by 3 tests: return digest == ((void *)0) ? ((void *)0) : digest->name;Executed by:
| 31 | ||||||||||||
| 76 | : digest->name; executed 31 times by 3 tests: return digest == ((void *)0) ? ((void *)0) : digest->name;Executed by:
| 31 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | size_t | - | ||||||||||||
| 80 | ssh_digest_bytes(int alg) | - | ||||||||||||
| 81 | { | - | ||||||||||||
| 82 | const struct ssh_digest *digest = ssh_digest_by_alg(alg); | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | return executed 125439 times by 5 tests: digest == return digest == ((void *)0) ? 0 : digest->digest_len;Executed by:
executed 125439 times by 5 tests: return digest == ((void *)0) ? 0 : digest->digest_len;Executed by:
| 0-125439 | ||||||||||||
| 85 | ((void *)0)
executed 125439 times by 5 tests: return digest == ((void *)0) ? 0 : digest->digest_len;Executed by:
| 0-125439 | ||||||||||||
| 86 | ? 0 : digest->digest_len; executed 125439 times by 5 tests: return digest == ((void *)0) ? 0 : digest->digest_len;Executed by:
| 125439 | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | size_t | - | ||||||||||||
| 90 | ssh_digest_blocksize(struct ssh_digest_ctx *ctx) | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | return executed 416 times by 1 test: return EVP_MD_block_size(EVP_MD_CTX_md( ctx->mdctx )) ;Executed by:
executed 416 times by 1 test: return EVP_MD_block_size(EVP_MD_CTX_md( ctx->mdctx )) ;Executed by:
| 416 | ||||||||||||
| 93 | EVP_MD_block_size(EVP_MD_CTX_md( executed 416 times by 1 test: return EVP_MD_block_size(EVP_MD_CTX_md( ctx->mdctx )) ;Executed by:
| 416 | ||||||||||||
| 94 | ctx->mdctx executed 416 times by 1 test: return EVP_MD_block_size(EVP_MD_CTX_md( ctx->mdctx )) ;Executed by:
| 416 | ||||||||||||
| 95 | )) executed 416 times by 1 test: return EVP_MD_block_size(EVP_MD_CTX_md( ctx->mdctx )) ;Executed by:
| 416 | ||||||||||||
| 96 | ; executed 416 times by 1 test: return EVP_MD_block_size(EVP_MD_CTX_md( ctx->mdctx )) ;Executed by:
| 416 | ||||||||||||
| 97 | } | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | struct ssh_digest_ctx * | - | ||||||||||||
| 100 | ssh_digest_start(int alg) | - | ||||||||||||
| 101 | { | - | ||||||||||||
| 102 | const struct ssh_digest *digest = ssh_digest_by_alg(alg); | - | ||||||||||||
| 103 | struct ssh_digest_ctx *ret; | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | if (digest ==
| 0-6290 | ||||||||||||
| 106 | ((void *)0)
| 0-6290 | ||||||||||||
| 107 | || ((
| 0-6290 | ||||||||||||
| 108 | ((void *)0)
| 0-6290 | ||||||||||||
| 109 | )
| 0-6290 | ||||||||||||
| 110 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 111 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 112 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 113 | ret->alg = alg; | - | ||||||||||||
| 114 | if ((
| 0-6290 | ||||||||||||
| 115 | ((void *)0)
| 0-6290 | ||||||||||||
| 116 | ) { | - | ||||||||||||
| 117 | free(ret); | - | ||||||||||||
| 118 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 119 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 120 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | if (EVP_DigestInit_ex(ret->mdctx, digest->mdfunc(),
| 0-6290 | ||||||||||||
| 123 | ((void *)0)
| 0-6290 | ||||||||||||
| 124 | ) != 1
| 0-6290 | ||||||||||||
| 125 | ssh_digest_free(ret); | - | ||||||||||||
| 126 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 127 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 128 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 129 | } | - | ||||||||||||
| 130 | return executed 6290 times by 3 tests: ret;return ret;Executed by:
executed 6290 times by 3 tests: return ret;Executed by:
| 6290 | ||||||||||||
| 131 | } | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | int | - | ||||||||||||
| 134 | ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to) | - | ||||||||||||
| 135 | { | - | ||||||||||||
| 136 | if (from->alg != to->alg
| 0-832 | ||||||||||||
| 137 | return never executed: -10;return -10;never executed: return -10; | 0 | ||||||||||||
| 138 | - | |||||||||||||
| 139 | if (!EVP_MD_CTX_copy_ex(to->mdctx, from->mdctx)
| 0-832 | ||||||||||||
| 140 | return never executed: -22;return -22;never executed: return -22; | 0 | ||||||||||||
| 141 | return executed 832 times by 1 test: 0;return 0;Executed by:
executed 832 times by 1 test: return 0;Executed by:
| 832 | ||||||||||||
| 142 | } | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | int | - | ||||||||||||
| 145 | ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen) | - | ||||||||||||
| 146 | { | - | ||||||||||||
| 147 | if (EVP_DigestUpdate(ctx->mdctx, m, mlen) != 1
| 0-18710 | ||||||||||||
| 148 | return never executed: -22;return -22;never executed: return -22; | 0 | ||||||||||||
| 149 | return executed 18710 times by 3 tests: 0;return 0;Executed by:
executed 18710 times by 3 tests: return 0;Executed by:
| 18710 | ||||||||||||
| 150 | } | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | int | - | ||||||||||||
| 153 | ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, const struct sshbuf *b) | - | ||||||||||||
| 154 | { | - | ||||||||||||
| 155 | return executed 5040 times by 1 test: ssh_digest_update(ctx, sshbuf_ptr(b), sshbuf_len(b));return ssh_digest_update(ctx, sshbuf_ptr(b), sshbuf_len(b));Executed by:
executed 5040 times by 1 test: return ssh_digest_update(ctx, sshbuf_ptr(b), sshbuf_len(b));Executed by:
| 5040 | ||||||||||||
| 156 | } | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | int | - | ||||||||||||
| 159 | ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen) | - | ||||||||||||
| 160 | { | - | ||||||||||||
| 161 | const struct ssh_digest *digest = ssh_digest_by_alg(ctx->alg); | - | ||||||||||||
| 162 | u_int l = dlen; | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | if (digest ==
| 0-5874 | ||||||||||||
| 165 | ((void *)0)
| 0-5874 | ||||||||||||
| 166 | || dlen >
| 0-5874 | ||||||||||||
| 167 | (0x7fffffff * 2U + 1U)
| 0-5874 | ||||||||||||
| 168 | ) | - | ||||||||||||
| 169 | return never executed: -10;return -10;never executed: return -10; | 0 | ||||||||||||
| 170 | if (dlen < digest->digest_len
| 0-5874 | ||||||||||||
| 171 | return never executed: -10;return -10;never executed: return -10; | 0 | ||||||||||||
| 172 | if (EVP_DigestFinal_ex(ctx->mdctx, d, &l) != 1
| 0-5874 | ||||||||||||
| 173 | return never executed: -22;return -22;never executed: return -22; | 0 | ||||||||||||
| 174 | if (l != digest->digest_len
| 0-5874 | ||||||||||||
| 175 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 176 | return executed 5874 times by 3 tests: 0;return 0;Executed by:
executed 5874 times by 3 tests: return 0;Executed by:
| 5874 | ||||||||||||
| 177 | } | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | void | - | ||||||||||||
| 180 | ssh_digest_free(struct ssh_digest_ctx *ctx) | - | ||||||||||||
| 181 | { | - | ||||||||||||
| 182 | if (ctx ==
| 1920-6290 | ||||||||||||
| 183 | ((void *)0)
| 1920-6290 | ||||||||||||
| 184 | ) | - | ||||||||||||
| 185 | return; executed 1920 times by 1 test: return;Executed by:
| 1920 | ||||||||||||
| 186 | EVP_MD_CTX_free(ctx->mdctx); | - | ||||||||||||
| 187 | freezero(ctx, sizeof(*ctx)); | - | ||||||||||||
| 188 | } executed 6290 times by 3 tests: end of blockExecuted by:
| 6290 | ||||||||||||
| 189 | - | |||||||||||||
| 190 | int | - | ||||||||||||
| 191 | ssh_digest_memory(int alg, const void *m, size_t mlen, u_char *d, size_t dlen) | - | ||||||||||||
| 192 | { | - | ||||||||||||
| 193 | const struct ssh_digest *digest = ssh_digest_by_alg(alg); | - | ||||||||||||
| 194 | u_int mdlen; | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | if (digest ==
| 0-75183 | ||||||||||||
| 197 | ((void *)0)
| 0-75183 | ||||||||||||
| 198 | ) | - | ||||||||||||
| 199 | return never executed: -10;return -10;never executed: return -10; | 0 | ||||||||||||
| 200 | if (dlen >
| 0-75183 | ||||||||||||
| 201 | (0x7fffffff * 2U + 1U)
| 0-75183 | ||||||||||||
| 202 | ) | - | ||||||||||||
| 203 | return never executed: -10;return -10;never executed: return -10; | 0 | ||||||||||||
| 204 | if (dlen < digest->digest_len
| 0-75183 | ||||||||||||
| 205 | return never executed: -10;return -10;never executed: return -10; | 0 | ||||||||||||
| 206 | mdlen = dlen; | - | ||||||||||||
| 207 | if (!EVP_Digest(m, mlen, d, &mdlen, digest->mdfunc(),
| 0-75183 | ||||||||||||
| 208 | ((void *)0)
| 0-75183 | ||||||||||||
| 209 | )
| 0-75183 | ||||||||||||
| 210 | return never executed: -22;return -22;never executed: return -22; | 0 | ||||||||||||
| 211 | return executed 75183 times by 4 tests: 0;return 0;Executed by:
executed 75183 times by 4 tests: return 0;Executed by:
| 75183 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | int | - | ||||||||||||
| 215 | ssh_digest_buffer(int alg, const struct sshbuf *b, u_char *d, size_t dlen) | - | ||||||||||||
| 216 | { | - | ||||||||||||
| 217 | return executed 320 times by 1 test: ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen);return ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen);Executed by:
executed 320 times by 1 test: return ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen);Executed by:
| 320 | ||||||||||||
| 218 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |