| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/hmac.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | struct ssh_hmac_ctx { | - | ||||||||||||
| 6 | int alg; | - | ||||||||||||
| 7 | struct ssh_digest_ctx *ictx; | - | ||||||||||||
| 8 | struct ssh_digest_ctx *octx; | - | ||||||||||||
| 9 | struct ssh_digest_ctx *digest; | - | ||||||||||||
| 10 | u_char *buf; | - | ||||||||||||
| 11 | size_t buf_len; | - | ||||||||||||
| 12 | }; | - | ||||||||||||
| 13 | - | |||||||||||||
| 14 | size_t | - | ||||||||||||
| 15 | ssh_hmac_bytes(int alg) | - | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | return executed 416 times by 1 test: ssh_digest_bytes(alg);return ssh_digest_bytes(alg);Executed by:
executed 416 times by 1 test: return ssh_digest_bytes(alg);Executed by:
| 416 | ||||||||||||
| 18 | } | - | ||||||||||||
| 19 | - | |||||||||||||
| 20 | struct ssh_hmac_ctx * | - | ||||||||||||
| 21 | ssh_hmac_start(int alg) | - | ||||||||||||
| 22 | { | - | ||||||||||||
| 23 | struct ssh_hmac_ctx *ret; | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | if ((
| 0-416 | ||||||||||||
| 26 | ((void *)0)
| 0-416 | ||||||||||||
| 27 | ) | - | ||||||||||||
| 28 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 29 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 30 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 31 | ret->alg = alg; | - | ||||||||||||
| 32 | if ((
| 0-416 | ||||||||||||
| 33 | ((void *)0)
| 0-416 | ||||||||||||
| 34 | || | - | ||||||||||||
| 35 | (
| 0-416 | ||||||||||||
| 36 | ((void *)0)
| 0-416 | ||||||||||||
| 37 | || | - | ||||||||||||
| 38 | (
| 0-416 | ||||||||||||
| 39 | ((void *)0)
| 0-416 | ||||||||||||
| 40 | ) | - | ||||||||||||
| 41 | goto never executed: fail;goto fail;never executed: goto fail; | 0 | ||||||||||||
| 42 | ret->buf_len = ssh_digest_blocksize(ret->ictx); | - | ||||||||||||
| 43 | if ((
| 0-416 | ||||||||||||
| 44 | ((void *)0)
| 0-416 | ||||||||||||
| 45 | ) | - | ||||||||||||
| 46 | goto never executed: fail;goto fail;never executed: goto fail; | 0 | ||||||||||||
| 47 | return executed 416 times by 1 test: ret;return ret;Executed by:
executed 416 times by 1 test: return ret;Executed by:
| 416 | ||||||||||||
| 48 | fail: | - | ||||||||||||
| 49 | ssh_hmac_free(ret); | - | ||||||||||||
| 50 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||
| 51 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
| 52 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 53 | } | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | int | - | ||||||||||||
| 56 | ssh_hmac_init(struct ssh_hmac_ctx *ctx, const void *key, size_t klen) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | size_t i; | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | - | |||||||||||||
| 61 | if (key !=
| 0-416 | ||||||||||||
| 62 | ((void *)0)
| 0-416 | ||||||||||||
| 63 | ) { | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | if (klen <= ctx->buf_len
| 0-416 | ||||||||||||
| 66 | memcpy(ctx->buf, key, klen); executed 416 times by 1 test: memcpy(ctx->buf, key, klen);Executed by:
| 416 | ||||||||||||
| 67 | else if (ssh_digest_memory(ctx->alg, key, klen, ctx->buf,
| 0 | ||||||||||||
| 68 | ctx->buf_len) < 0
| 0 | ||||||||||||
| 69 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 70 | for (i = 0; i < ctx->buf_len
| 416-26624 | ||||||||||||
| 71 | ctx->buf[i] ^= 0x36; executed 26624 times by 1 test: ctx->buf[i] ^= 0x36;Executed by:
| 26624 | ||||||||||||
| 72 | if (ssh_digest_update(ctx->ictx, ctx->buf, ctx->buf_len) < 0
| 0-416 | ||||||||||||
| 73 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 74 | for (i = 0; i < ctx->buf_len
| 416-26624 | ||||||||||||
| 75 | ctx->buf[i] ^= 0x36 ^ 0x5c; executed 26624 times by 1 test: ctx->buf[i] ^= 0x36 ^ 0x5c;Executed by:
| 26624 | ||||||||||||
| 76 | if (ssh_digest_update(ctx->octx, ctx->buf, ctx->buf_len) < 0
| 0-416 | ||||||||||||
| 77 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 78 | explicit_bzero(ctx->buf, ctx->buf_len); | - | ||||||||||||
| 79 | } executed 416 times by 1 test: end of blockExecuted by:
| 416 | ||||||||||||
| 80 | - | |||||||||||||
| 81 | if (ssh_digest_copy_state(ctx->ictx, ctx->digest) < 0
| 0-416 | ||||||||||||
| 82 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 83 | return executed 416 times by 1 test: 0;return 0;Executed by:
executed 416 times by 1 test: return 0;Executed by:
| 416 | ||||||||||||
| 84 | } | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | int | - | ||||||||||||
| 87 | ssh_hmac_update(struct ssh_hmac_ctx *ctx, const void *m, size_t mlen) | - | ||||||||||||
| 88 | { | - | ||||||||||||
| 89 | return executed 416 times by 1 test: ssh_digest_update(ctx->digest, m, mlen);return ssh_digest_update(ctx->digest, m, mlen);Executed by:
executed 416 times by 1 test: return ssh_digest_update(ctx->digest, m, mlen);Executed by:
| 416 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | int | - | ||||||||||||
| 93 | ssh_hmac_update_buffer(struct ssh_hmac_ctx *ctx, const struct sshbuf *b) | - | ||||||||||||
| 94 | { | - | ||||||||||||
| 95 | return never executed: ssh_digest_update_buffer(ctx->digest, b);return ssh_digest_update_buffer(ctx->digest, b);never executed: return ssh_digest_update_buffer(ctx->digest, b); | 0 | ||||||||||||
| 96 | } | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | int | - | ||||||||||||
| 99 | ssh_hmac_final(struct ssh_hmac_ctx *ctx, u_char *d, size_t dlen) | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | size_t len; | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | len = ssh_digest_bytes(ctx->alg); | - | ||||||||||||
| 104 | if (dlen < len
| 0-416 | ||||||||||||
| 105 | ssh_digest_final(ctx->digest, ctx->buf, len)
| 0-416 | ||||||||||||
| 106 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | if (ssh_digest_copy_state(ctx->octx, ctx->digest) < 0
| 0-416 | ||||||||||||
| 109 | ssh_digest_update(ctx->digest, ctx->buf, len) < 0
| 0-416 | ||||||||||||
| 110 | ssh_digest_final(ctx->digest, d, dlen) < 0
| 0-416 | ||||||||||||
| 111 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 112 | return executed 416 times by 1 test: 0;return 0;Executed by:
executed 416 times by 1 test: return 0;Executed by:
| 416 | ||||||||||||
| 113 | } | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | void | - | ||||||||||||
| 116 | ssh_hmac_free(struct ssh_hmac_ctx *ctx) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | if (ctx !=
| 0-416 | ||||||||||||
| 119 | ((void *)0)
| 0-416 | ||||||||||||
| 120 | ) { | - | ||||||||||||
| 121 | ssh_digest_free(ctx->ictx); | - | ||||||||||||
| 122 | ssh_digest_free(ctx->octx); | - | ||||||||||||
| 123 | ssh_digest_free(ctx->digest); | - | ||||||||||||
| 124 | if (ctx->buf
| 0-416 | ||||||||||||
| 125 | explicit_bzero(ctx->buf, ctx->buf_len); | - | ||||||||||||
| 126 | free(ctx->buf); | - | ||||||||||||
| 127 | } executed 416 times by 1 test: end of blockExecuted by:
| 416 | ||||||||||||
| 128 | explicit_bzero(ctx, sizeof(*ctx)); | - | ||||||||||||
| 129 | free(ctx); | - | ||||||||||||
| 130 | } executed 416 times by 1 test: end of blockExecuted by:
| 416 | ||||||||||||
| 131 | } executed 416 times by 1 test: end of blockExecuted by:
| 416 | ||||||||||||
| Switch to Source code | Preprocessed file |