OpenCoverage

hmac.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/hmac.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5struct 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-
14size_t-
15ssh_hmac_bytes(int alg)-
16{-
17 return
executed 416 times by 1 test: return ssh_digest_bytes(alg);
Executed by:
  • test_hostkeys
ssh_digest_bytes(alg);
executed 416 times by 1 test: return ssh_digest_bytes(alg);
Executed by:
  • test_hostkeys
416
18}-
19-
20struct ssh_hmac_ctx *-
21ssh_hmac_start(int alg)-
22{-
23 struct ssh_hmac_ctx *ret;-
24-
25 if ((
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
ret = calloc(1, sizeof(*ret))) ==
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
26 ((void *)0)
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
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 ((
(ret->ictx = s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
ret->ictx = ssh_digest_start(alg)) ==
(ret->ictx = s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
33 ((void *)0)
(ret->ictx = s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
34 ||-
35 (
(ret->octx = s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
ret->octx = ssh_digest_start(alg)) ==
(ret->octx = s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
36 ((void *)0)
(ret->octx = s...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
37 ||-
38 (
(ret->digest =...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
ret->digest = ssh_digest_start(alg)) ==
(ret->digest =...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
39 ((void *)0)
(ret->digest =...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
40 )-
41 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
42 ret->buf_len = ssh_digest_blocksize(ret->ictx);-
43 if ((
(ret->buf = ca...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
ret->buf = calloc(1, ret->buf_len)) ==
(ret->buf = ca...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
44 ((void *)0)
(ret->buf = ca...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
0-416
45 )-
46 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
47 return
executed 416 times by 1 test: return ret;
Executed by:
  • test_hostkeys
ret;
executed 416 times by 1 test: return ret;
Executed by:
  • test_hostkeys
416
48fail:-
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-
55int-
56ssh_hmac_init(struct ssh_hmac_ctx *ctx, const void *key, size_t klen)-
57{-
58 size_t i;-
59-
60-
61 if (key !=
key != ((void *)0)Description
TRUEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEnever evaluated
0-416
62 ((void *)0)
key != ((void *)0)Description
TRUEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEnever evaluated
0-416
63 ) {-
64-
65 if (klen <= ctx->buf_len
klen <= ctx->buf_lenDescription
TRUEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEnever evaluated
)
0-416
66 memcpy(ctx->buf, key, klen);
executed 416 times by 1 test: memcpy(ctx->buf, key, klen);
Executed by:
  • test_hostkeys
416
67 else if (ssh_digest_memory(ctx->alg, key, klen, ctx->buf,
ssh_digest_mem...->buf_len) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
68 ctx->buf_len) < 0
ssh_digest_mem...->buf_len) < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
69 return
never executed: return -1;
-1;
never executed: return -1;
0
70 for (i = 0; i < ctx->buf_len
i < ctx->buf_lenDescription
TRUEevaluated 26624 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
; i++)
416-26624
71 ctx->buf[i] ^= 0x36;
executed 26624 times by 1 test: ctx->buf[i] ^= 0x36;
Executed by:
  • test_hostkeys
26624
72 if (ssh_digest_update(ctx->ictx, ctx->buf, ctx->buf_len) < 0
ssh_digest_upd...->buf_len) < 0Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
)
0-416
73 return
never executed: return -1;
-1;
never executed: return -1;
0
74 for (i = 0; i < ctx->buf_len
i < ctx->buf_lenDescription
TRUEevaluated 26624 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
; i++)
416-26624
75 ctx->buf[i] ^= 0x36 ^ 0x5c;
executed 26624 times by 1 test: ctx->buf[i] ^= 0x36 ^ 0x5c;
Executed by:
  • test_hostkeys
26624
76 if (ssh_digest_update(ctx->octx, ctx->buf, ctx->buf_len) < 0
ssh_digest_upd...->buf_len) < 0Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
)
0-416
77 return
never executed: return -1;
-1;
never executed: return -1;
0
78 explicit_bzero(ctx->buf, ctx->buf_len);-
79 }
executed 416 times by 1 test: end of block
Executed by:
  • test_hostkeys
416
80-
81 if (ssh_digest_copy_state(ctx->ictx, ctx->digest) < 0
ssh_digest_cop...x->digest) < 0Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
)
0-416
82 return
never executed: return -1;
-1;
never executed: return -1;
0
83 return
executed 416 times by 1 test: return 0;
Executed by:
  • test_hostkeys
0;
executed 416 times by 1 test: return 0;
Executed by:
  • test_hostkeys
416
84}-
85-
86int-
87ssh_hmac_update(struct ssh_hmac_ctx *ctx, const void *m, size_t mlen)-
88{-
89 return
executed 416 times by 1 test: return ssh_digest_update(ctx->digest, m, mlen);
Executed by:
  • test_hostkeys
ssh_digest_update(ctx->digest, m, mlen);
executed 416 times by 1 test: return ssh_digest_update(ctx->digest, m, mlen);
Executed by:
  • test_hostkeys
416
90}-
91-
92int-
93ssh_hmac_update_buffer(struct ssh_hmac_ctx *ctx, const struct sshbuf *b)-
94{-
95 return
never executed: return ssh_digest_update_buffer(ctx->digest, b);
ssh_digest_update_buffer(ctx->digest, b);
never executed: return ssh_digest_update_buffer(ctx->digest, b);
0
96}-
97-
98int-
99ssh_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
dlen < lenDescription
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
||
0-416
105 ssh_digest_final(ctx->digest, ctx->buf, len)
ssh_digest_fin...ctx->buf, len)Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
)
0-416
106 return
never executed: return -1;
-1;
never executed: return -1;
0
107-
108 if (ssh_digest_copy_state(ctx->octx, ctx->digest) < 0
ssh_digest_cop...x->digest) < 0Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
||
0-416
109 ssh_digest_update(ctx->digest, ctx->buf, len) < 0
ssh_digest_upd...>buf, len) < 0Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
||
0-416
110 ssh_digest_final(ctx->digest, d, dlen) < 0
ssh_digest_fin..., d, dlen) < 0Description
TRUEnever evaluated
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
)
0-416
111 return
never executed: return -1;
-1;
never executed: return -1;
0
112 return
executed 416 times by 1 test: return 0;
Executed by:
  • test_hostkeys
0;
executed 416 times by 1 test: return 0;
Executed by:
  • test_hostkeys
416
113}-
114-
115void-
116ssh_hmac_free(struct ssh_hmac_ctx *ctx)-
117{-
118 if (ctx !=
ctx != ((void *)0)Description
TRUEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEnever evaluated
0-416
119 ((void *)0)
ctx != ((void *)0)Description
TRUEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEnever evaluated
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
ctx->bufDescription
TRUEevaluated 416 times by 1 test
Evaluated by:
  • test_hostkeys
FALSEnever evaluated
) {
0-416
125 explicit_bzero(ctx->buf, ctx->buf_len);-
126 free(ctx->buf);-
127 }
executed 416 times by 1 test: end of block
Executed by:
  • test_hostkeys
416
128 explicit_bzero(ctx, sizeof(*ctx));-
129 free(ctx);-
130 }
executed 416 times by 1 test: end of block
Executed by:
  • test_hostkeys
416
131}
executed 416 times by 1 test: end of block
Executed by:
  • test_hostkeys
416
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2