Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/m_sha3.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len, | - | ||||||||||||
5 | size_t r); | - | ||||||||||||
6 | void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r); | - | ||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | typedef struct { | - | ||||||||||||
11 | uint64_t A[5][5]; | - | ||||||||||||
12 | size_t block_size; | - | ||||||||||||
13 | size_t md_size; | - | ||||||||||||
14 | size_t num; | - | ||||||||||||
15 | unsigned char buf[1600 / 8 - 32]; | - | ||||||||||||
16 | unsigned char pad; | - | ||||||||||||
17 | } KECCAK1600_CTX; | - | ||||||||||||
18 | - | |||||||||||||
19 | static int init(EVP_MD_CTX *evp_ctx, unsigned char pad) | - | ||||||||||||
20 | { | - | ||||||||||||
21 | KECCAK1600_CTX *ctx = evp_ctx->md_data; | - | ||||||||||||
22 | size_t bsz = evp_ctx->digest->block_size; | - | ||||||||||||
23 | - | |||||||||||||
24 | if (bsz <= sizeof(ctx->buf)
| 0-181 | ||||||||||||
25 | memset(ctx->A, 0, sizeof(ctx->A)); | - | ||||||||||||
26 | - | |||||||||||||
27 | ctx->num = 0; | - | ||||||||||||
28 | ctx->block_size = bsz; | - | ||||||||||||
29 | ctx->md_size = evp_ctx->digest->md_size; | - | ||||||||||||
30 | ctx->pad = pad; | - | ||||||||||||
31 | - | |||||||||||||
32 | return executed 181 times by 2 tests: 1;return 1; Executed by:
executed 181 times by 2 tests: return 1; Executed by:
| 181 | ||||||||||||
33 | } | - | ||||||||||||
34 | - | |||||||||||||
35 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
36 | } | - | ||||||||||||
37 | - | |||||||||||||
38 | static int sha3_init(EVP_MD_CTX *evp_ctx) | - | ||||||||||||
39 | { | - | ||||||||||||
40 | return executed 45 times by 1 test: init(evp_ctx, '\x06');return init(evp_ctx, '\x06'); Executed by:
executed 45 times by 1 test: return init(evp_ctx, '\x06'); Executed by:
| 45 | ||||||||||||
41 | } | - | ||||||||||||
42 | - | |||||||||||||
43 | static int shake_init(EVP_MD_CTX *evp_ctx) | - | ||||||||||||
44 | { | - | ||||||||||||
45 | return executed 136 times by 2 tests: init(evp_ctx, '\x1f');return init(evp_ctx, '\x1f'); Executed by:
executed 136 times by 2 tests: return init(evp_ctx, '\x1f'); Executed by:
| 136 | ||||||||||||
46 | } | - | ||||||||||||
47 | - | |||||||||||||
48 | static int sha3_update(EVP_MD_CTX *evp_ctx, const void *_inp, size_t len) | - | ||||||||||||
49 | { | - | ||||||||||||
50 | KECCAK1600_CTX *ctx = evp_ctx->md_data; | - | ||||||||||||
51 | const unsigned char *inp = _inp; | - | ||||||||||||
52 | size_t bsz = ctx->block_size; | - | ||||||||||||
53 | size_t num, rem; | - | ||||||||||||
54 | - | |||||||||||||
55 | if (len == 0
| 71-1598 | ||||||||||||
56 | return executed 71 times by 2 tests: 1;return 1; Executed by:
executed 71 times by 2 tests: return 1; Executed by:
| 71 | ||||||||||||
57 | - | |||||||||||||
58 | if ((
| 205-1393 | ||||||||||||
59 | rem = bsz - num; | - | ||||||||||||
60 | - | |||||||||||||
61 | if (len < rem
| 38-1355 | ||||||||||||
62 | memcpy(ctx->buf + num, inp, len); | - | ||||||||||||
63 | ctx->num += len; | - | ||||||||||||
64 | return executed 1355 times by 2 tests: 1;return 1; Executed by:
executed 1355 times by 2 tests: return 1; Executed by:
| 1355 | ||||||||||||
65 | } | - | ||||||||||||
66 | - | |||||||||||||
67 | - | |||||||||||||
68 | - | |||||||||||||
69 | - | |||||||||||||
70 | - | |||||||||||||
71 | memcpy(ctx->buf + num, inp, rem); | - | ||||||||||||
72 | inp += rem, len -= rem; | - | ||||||||||||
73 | (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); | - | ||||||||||||
74 | ctx->num = 0; | - | ||||||||||||
75 | - | |||||||||||||
76 | } executed 38 times by 2 tests: end of block Executed by:
| 38 | ||||||||||||
77 | - | |||||||||||||
78 | if (len >= bsz
| 51-192 | ||||||||||||
79 | rem = SHA3_absorb(ctx->A, inp, len, bsz); executed 51 times by 2 tests: rem = SHA3_absorb(ctx->A, inp, len, bsz); Executed by:
| 51 | ||||||||||||
80 | else | - | ||||||||||||
81 | rem = len; executed 192 times by 2 tests: rem = len; Executed by:
| 192 | ||||||||||||
82 | - | |||||||||||||
83 | if (rem
| 33-210 | ||||||||||||
84 | memcpy(ctx->buf, inp + len - rem, rem); | - | ||||||||||||
85 | ctx->num = rem; | - | ||||||||||||
86 | } executed 210 times by 2 tests: end of block Executed by:
| 210 | ||||||||||||
87 | - | |||||||||||||
88 | return executed 243 times by 2 tests: 1;return 1; Executed by:
executed 243 times by 2 tests: return 1; Executed by:
| 243 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | static int sha3_final(EVP_MD_CTX *evp_ctx, unsigned char *md) | - | ||||||||||||
92 | { | - | ||||||||||||
93 | KECCAK1600_CTX *ctx = evp_ctx->md_data; | - | ||||||||||||
94 | size_t bsz = ctx->block_size; | - | ||||||||||||
95 | size_t num = ctx->num; | - | ||||||||||||
96 | - | |||||||||||||
97 | - | |||||||||||||
98 | - | |||||||||||||
99 | - | |||||||||||||
100 | - | |||||||||||||
101 | - | |||||||||||||
102 | memset(ctx->buf + num, 0, bsz - num); | - | ||||||||||||
103 | ctx->buf[num] = ctx->pad; | - | ||||||||||||
104 | ctx->buf[bsz - 1] |= 0x80; | - | ||||||||||||
105 | - | |||||||||||||
106 | (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); | - | ||||||||||||
107 | - | |||||||||||||
108 | SHA3_squeeze(ctx->A, md, ctx->md_size, bsz); | - | ||||||||||||
109 | - | |||||||||||||
110 | return executed 181 times by 2 tests: 1;return 1; Executed by:
executed 181 times by 2 tests: return 1; Executed by:
| 181 | ||||||||||||
111 | } | - | ||||||||||||
112 | - | |||||||||||||
113 | static int shake_ctrl(EVP_MD_CTX *evp_ctx, int cmd, int p1, void *p2) | - | ||||||||||||
114 | { | - | ||||||||||||
115 | KECCAK1600_CTX *ctx = evp_ctx->md_data; | - | ||||||||||||
116 | - | |||||||||||||
117 | switch (cmd) { | - | ||||||||||||
118 | case executed 136 times by 2 tests: 0x3:case 0x3: Executed by:
executed 136 times by 2 tests: case 0x3: Executed by:
| 136 | ||||||||||||
119 | ctx->md_size = p1; | - | ||||||||||||
120 | return executed 136 times by 2 tests: 1;return 1; Executed by:
executed 136 times by 2 tests: return 1; Executed by:
| 136 | ||||||||||||
121 | default never executed: :default: never executed: default: | 0 | ||||||||||||
122 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
123 | } | - | ||||||||||||
124 | } | - | ||||||||||||
125 | const EVP_MD *EVP_sha3_224(void) { static const EVP_MD sha3_224_md = { 1096, 1116, 224 / 8, 0x0008, sha3_init, sha3_update, sha3_final, | - | ||||||||||||
126 | ((void *)0) | - | ||||||||||||
127 | , | - | ||||||||||||
128 | ((void *)0) | - | ||||||||||||
129 | , (1600 - 224 * 2) / 8, sizeof(KECCAK1600_CTX), }; return executed 1969 times by 1 test: &sha3_224_md;return &sha3_224_md; Executed by:
executed 1969 times by 1 test: }return &sha3_224_md; Executed by:
| 1969 | ||||||||||||
130 | const EVP_MD *EVP_sha3_256(void) { static const EVP_MD sha3_256_md = { 1097, 1117, 256 / 8, 0x0008, sha3_init, sha3_update, sha3_final, | - | ||||||||||||
131 | ((void *)0) | - | ||||||||||||
132 | , | - | ||||||||||||
133 | ((void *)0) | - | ||||||||||||
134 | , (1600 - 256 * 2) / 8, sizeof(KECCAK1600_CTX), }; return executed 1969 times by 1 test: &sha3_256_md;return &sha3_256_md; Executed by:
executed 1969 times by 1 test: }return &sha3_256_md; Executed by:
| 1969 | ||||||||||||
135 | const EVP_MD *EVP_sha3_384(void) { static const EVP_MD sha3_384_md = { 1098, 1118, 384 / 8, 0x0008, sha3_init, sha3_update, sha3_final, | - | ||||||||||||
136 | ((void *)0) | - | ||||||||||||
137 | , | - | ||||||||||||
138 | ((void *)0) | - | ||||||||||||
139 | , (1600 - 384 * 2) / 8, sizeof(KECCAK1600_CTX), }; return executed 1969 times by 1 test: &sha3_384_md;return &sha3_384_md; Executed by:
executed 1969 times by 1 test: }return &sha3_384_md; Executed by:
| 1969 | ||||||||||||
140 | const EVP_MD *EVP_sha3_512(void) { static const EVP_MD sha3_512_md = { 1099, 1119, 512 / 8, 0x0008, sha3_init, sha3_update, sha3_final, | - | ||||||||||||
141 | ((void *)0) | - | ||||||||||||
142 | , | - | ||||||||||||
143 | ((void *)0) | - | ||||||||||||
144 | , (1600 - 512 * 2) / 8, sizeof(KECCAK1600_CTX), }; return executed 1969 times by 1 test: &sha3_512_md;return &sha3_512_md; Executed by:
executed 1969 times by 1 test: }return &sha3_512_md; Executed by:
| 1969 | ||||||||||||
145 | - | |||||||||||||
146 | const EVP_MD *EVP_shake128(void) { static const EVP_MD shake128_md = { 1100, 0, 128 / 8, 0x0002, shake_init, sha3_update, sha3_final, | - | ||||||||||||
147 | ((void *)0) | - | ||||||||||||
148 | , | - | ||||||||||||
149 | ((void *)0) | - | ||||||||||||
150 | , (1600 - 128 * 2) / 8, sizeof(KECCAK1600_CTX), shake_ctrl }; return executed 1969 times by 1 test: &shake128_md;return &shake128_md; Executed by:
executed 1969 times by 1 test: }return &shake128_md; Executed by:
| 1969 | ||||||||||||
151 | const EVP_MD *EVP_shake256(void) { static const EVP_MD shake256_md = { 1101, 0, 256 / 8, 0x0002, shake_init, sha3_update, sha3_final, | - | ||||||||||||
152 | ((void *)0) | - | ||||||||||||
153 | , | - | ||||||||||||
154 | ((void *)0) | - | ||||||||||||
155 | , (1600 - 256 * 2) / 8, sizeof(KECCAK1600_CTX), shake_ctrl }; return executed 2093 times by 2 tests: &shake256_md;return &shake256_md; Executed by:
executed 2093 times by 2 tests: }return &shake256_md; Executed by:
| 2093 | ||||||||||||
Switch to Source code | Preprocessed file |