OpenCoverage

m_sha3.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/m_sha3.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len,-
5 size_t r);-
6void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r);-
7-
8-
9-
10typedef 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-
19static 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)
bsz <= sizeof(ctx->buf)Description
TRUEevaluated 181 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEnever evaluated
) {
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: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
1;
executed 181 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
181
33 }-
34-
35 return
never executed: return 0;
0;
never executed: return 0;
0
36}-
37-
38static int sha3_init(EVP_MD_CTX *evp_ctx)-
39{-
40 return
executed 45 times by 1 test: return init(evp_ctx, '\x06');
Executed by:
  • libcrypto.so.1.1
init(evp_ctx, '\x06');
executed 45 times by 1 test: return init(evp_ctx, '\x06');
Executed by:
  • libcrypto.so.1.1
45
41}-
42-
43static int shake_init(EVP_MD_CTX *evp_ctx)-
44{-
45 return
executed 136 times by 2 tests: return init(evp_ctx, '\x1f');
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
init(evp_ctx, '\x1f');
executed 136 times by 2 tests: return init(evp_ctx, '\x1f');
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
136
46}-
47-
48static 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
len == 0Description
TRUEevaluated 71 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 1598 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
)
71-1598
56 return
executed 71 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
1;
executed 71 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
71
57-
58 if ((
(num = ctx->num) != 0Description
TRUEevaluated 1393 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 205 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
num = ctx->num) != 0
(num = ctx->num) != 0Description
TRUEevaluated 1393 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 205 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
) {
205-1393
59 rem = bsz - num;-
60-
61 if (len < rem
len < remDescription
TRUEevaluated 1355 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 38 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
) {
38-1355
62 memcpy(ctx->buf + num, inp, len);-
63 ctx->num += len;-
64 return
executed 1355 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
1;
executed 1355 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
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:
  • curve448_internal_test
  • libcrypto.so.1.1
38
77-
78 if (len >= bsz
len >= bszDescription
TRUEevaluated 51 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 192 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
)
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:
  • curve448_internal_test
  • libcrypto.so.1.1
51
80 else-
81 rem = len;
executed 192 times by 2 tests: rem = len;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
192
82-
83 if (rem
remDescription
TRUEevaluated 210 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
FALSEevaluated 33 times by 2 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
) {
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:
  • curve448_internal_test
  • libcrypto.so.1.1
210
87-
88 return
executed 243 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
1;
executed 243 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
243
89}-
90-
91static 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: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
1;
executed 181 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
181
111}-
112-
113static 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: case 0x3:
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
0x3:
executed 136 times by 2 tests: case 0x3:
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
136
119 ctx->md_size = p1;-
120 return
executed 136 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
1;
executed 136 times by 2 tests: return 1;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
136
121 default
never executed: default:
:
never executed: default:
0
122 return
never executed: return 0;
0;
never executed: return 0;
0
123 }-
124}-
125const 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: return &sha3_224_md;
Executed by:
  • libcrypto.so.1.1
&sha3_224_md;
executed 1969 times by 1 test: return &sha3_224_md;
Executed by:
  • libcrypto.so.1.1
}
1969
130const 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: return &sha3_256_md;
Executed by:
  • libcrypto.so.1.1
&sha3_256_md;
executed 1969 times by 1 test: return &sha3_256_md;
Executed by:
  • libcrypto.so.1.1
}
1969
135const 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: return &sha3_384_md;
Executed by:
  • libcrypto.so.1.1
&sha3_384_md;
executed 1969 times by 1 test: return &sha3_384_md;
Executed by:
  • libcrypto.so.1.1
}
1969
140const 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: return &sha3_512_md;
Executed by:
  • libcrypto.so.1.1
&sha3_512_md;
executed 1969 times by 1 test: return &sha3_512_md;
Executed by:
  • libcrypto.so.1.1
}
1969
145-
146const 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: return &shake128_md;
Executed by:
  • libcrypto.so.1.1
&shake128_md;
executed 1969 times by 1 test: return &shake128_md;
Executed by:
  • libcrypto.so.1.1
}
1969
151const 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: return &shake256_md;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
&shake256_md;
executed 2093 times by 2 tests: return &shake256_md;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
}
2093
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2