FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/sha.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 29 30 96.7%
Functions: 1 1 100.0%
Branches: 16 18 88.9%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20
21 #include "libavutil/mem.h"
22 #include "libavutil/sha.h"
23
24 1 int main(void)
25 {
26 int i, j, k;
27 struct AVSHA *ctx;
28 unsigned char digest[32];
29 static const int lengths[3] = { 160, 224, 256 };
30
31 1 ctx = av_sha_alloc();
32
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!ctx)
33 return 1;
34
35
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (j = 0; j < 3; j++) {
36 3 printf("Testing SHA-%d\n", lengths[j]);
37
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (k = 0; k < 3; k++) {
38 9 av_sha_init(ctx, lengths[j]);
39
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (k == 0)
40 3 av_sha_update(ctx, "abc", 3);
41
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 else if (k == 1)
42 3 av_sha_update(ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
43 else
44
2/2
✓ Branch 0 taken 3000000 times.
✓ Branch 1 taken 3 times.
3000003 for (i = 0; i < 1000*1000; i++)
45 3000000 av_sha_update(ctx, "a", 1);
46 9 av_sha_final(ctx, digest);
47
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 9 times.
249 for (i = 0; i < lengths[j] >> 3; i++)
48 240 printf("%02X", digest[i]);
49 9 putchar('\n');
50 }
51
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
3 switch (j) {
52 1 case 0:
53 //test vectors (from FIPS PUB 180-1)
54 1 printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
55 "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
56 "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
57 1 break;
58 1 case 1:
59 //test vectors (from FIPS PUB 180-2 Appendix A)
60 1 printf("23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7\n"
61 "75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525\n"
62 "20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67\n");
63 1 break;
64 1 case 2:
65 //test vectors (from FIPS PUB 180-2)
66 1 printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad\n"
67 "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1\n"
68 "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0\n");
69 1 break;
70 }
71 }
72 1 av_free(ctx);
73
74 1 return 0;
75 }
76