Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssh/src/cipher-chachapoly.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | int | - | ||||||
7 | chachapoly_init(struct chachapoly_ctx *ctx, | - | ||||||
8 | const u_char *key, u_int keylen) | - | ||||||
9 | { | - | ||||||
10 | if (keylen != (32 + 32)
| 0-704 | ||||||
11 | return never executed: -10;return -10; never executed: return -10; | 0 | ||||||
12 | chacha_keysetup(&ctx->main_ctx, key, 256); | - | ||||||
13 | chacha_keysetup(&ctx->header_ctx, key + 32, 256); | - | ||||||
14 | return executed 704 times by 1 test: 0;return 0; Executed by:
executed 704 times by 1 test: return 0; Executed by:
| 704 | ||||||
15 | } | - | ||||||
16 | int | - | ||||||
17 | chachapoly_crypt(struct chachapoly_ctx *ctx, u_int seqnr, u_char *dest, | - | ||||||
18 | const u_char *src, u_int len, u_int aadlen, u_int authlen, int do_encrypt) | - | ||||||
19 | { | - | ||||||
20 | u_char seqbuf[8]; | - | ||||||
21 | const u_char one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; | - | ||||||
22 | u_char expected_tag[16], poly_key[32]; | - | ||||||
23 | int r = -1; | - | ||||||
24 | - | |||||||
25 | - | |||||||
26 | - | |||||||
27 | - | |||||||
28 | - | |||||||
29 | memset(poly_key, 0, sizeof(poly_key)); | - | ||||||
30 | do { const u_int64_t __v = (seqnr); ((u_char *)(seqbuf))[0] = (__v >> 56) & 0xff; ((u_char *)(seqbuf))[1] = (__v >> 48) & 0xff; ((u_char *)(seqbuf))[2] = (__v >> 40) & 0xff; ((u_char *)(seqbuf))[3] = (__v >> 32) & 0xff; ((u_char *)(seqbuf))[4] = (__v >> 24) & 0xff; ((u_char *)(seqbuf))[5] = (__v >> 16) & 0xff; ((u_char *)(seqbuf))[6] = (__v >> 8) & 0xff; ((u_char *)(seqbuf))[7] = __v & 0xff; } while (0); | - | ||||||
31 | chacha_ivsetup(&ctx->main_ctx, seqbuf, | - | ||||||
32 | ((void *)0) | - | ||||||
33 | ); | - | ||||||
34 | chacha_encrypt_bytes(&ctx->main_ctx, | - | ||||||
35 | poly_key, poly_key, sizeof(poly_key)); | - | ||||||
36 | - | |||||||
37 | - | |||||||
38 | if (!do_encrypt
| 832 | ||||||
39 | const u_char *tag = src + aadlen + len; | - | ||||||
40 | - | |||||||
41 | poly1305_auth(expected_tag, src, aadlen + len, poly_key); | - | ||||||
42 | if (timingsafe_bcmp(expected_tag, tag, 16) != 0
| 0-832 | ||||||
43 | r = -30; | - | ||||||
44 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||
45 | } | - | ||||||
46 | } executed 832 times by 1 test: end of block Executed by:
| 832 | ||||||
47 | - | |||||||
48 | - | |||||||
49 | if (aadlen
| 0-1664 | ||||||
50 | chacha_ivsetup(&ctx->header_ctx, seqbuf, | - | ||||||
51 | ((void *)0) | - | ||||||
52 | ); | - | ||||||
53 | chacha_encrypt_bytes(&ctx->header_ctx, src, dest, aadlen); | - | ||||||
54 | } executed 1664 times by 1 test: end of block Executed by:
| 1664 | ||||||
55 | - | |||||||
56 | - | |||||||
57 | chacha_ivsetup(&ctx->main_ctx, seqbuf, one); | - | ||||||
58 | chacha_encrypt_bytes(&ctx->main_ctx, src + aadlen, | - | ||||||
59 | dest + aadlen, len); | - | ||||||
60 | - | |||||||
61 | - | |||||||
62 | if (do_encrypt
| 832 | ||||||
63 | poly1305_auth(dest + aadlen + len, dest, aadlen + len, | - | ||||||
64 | poly_key); | - | ||||||
65 | } executed 832 times by 1 test: end of block Executed by:
| 832 | ||||||
66 | r = 0; | - | ||||||
67 | out: code before this statement executed 1664 times by 1 test: out: Executed by:
| 1664 | ||||||
68 | explicit_bzero(expected_tag, sizeof(expected_tag)); | - | ||||||
69 | explicit_bzero(seqbuf, sizeof(seqbuf)); | - | ||||||
70 | explicit_bzero(poly_key, sizeof(poly_key)); | - | ||||||
71 | return executed 1664 times by 1 test: r;return r; Executed by:
executed 1664 times by 1 test: return r; Executed by:
| 1664 | ||||||
72 | } | - | ||||||
73 | - | |||||||
74 | - | |||||||
75 | int | - | ||||||
76 | chachapoly_get_length(struct chachapoly_ctx *ctx, | - | ||||||
77 | u_int *plenp, u_int seqnr, const u_char *cp, u_int len) | - | ||||||
78 | { | - | ||||||
79 | u_char buf[4], seqbuf[8]; | - | ||||||
80 | - | |||||||
81 | if (len < 4
| 832-1728 | ||||||
82 | return executed 1728 times by 1 test: -3;return -3; Executed by:
executed 1728 times by 1 test: return -3; Executed by:
| 1728 | ||||||
83 | do { const u_int64_t __v = (seqnr); ((u_char *)(seqbuf))[0] = (__v >> 56) & 0xff; ((u_char *)(seqbuf))[1] = (__v >> 48) & 0xff; ((u_char *)(seqbuf))[2] = (__v >> 40) & 0xff; ((u_char *)(seqbuf))[3] = (__v >> 32) & 0xff; ((u_char *)(seqbuf))[4] = (__v >> 24) & 0xff; ((u_char *)(seqbuf))[5] = (__v >> 16) & 0xff; ((u_char *)(seqbuf))[6] = (__v >> 8) & 0xff; ((u_char *)(seqbuf))[7] = __v & 0xff; } while (0); | - | ||||||
84 | chacha_ivsetup(&ctx->header_ctx, seqbuf, | - | ||||||
85 | ((void *)0) | - | ||||||
86 | ); | - | ||||||
87 | chacha_encrypt_bytes(&ctx->header_ctx, cp, buf, 4); | - | ||||||
88 | *plenp = (((u_int32_t)(((const u_char *)(buf))[0]) << 24) | ((u_int32_t)(((const u_char *)(buf))[1]) << 16) | ((u_int32_t)(((const u_char *)(buf))[2]) << 8) | (u_int32_t)(((const u_char *)(buf))[3])); | - | ||||||
89 | return executed 832 times by 1 test: 0;return 0; Executed by:
executed 832 times by 1 test: return 0; Executed by:
| 832 | ||||||
90 | } | - | ||||||
Switch to Source code | Preprocessed file |