| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at> | ||
| 3 | * Copyright (C) 2013 James Almer | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | |||
| 24 | #include "libavutil/mem.h" | ||
| 25 | #include "libavutil/ripemd.h" | ||
| 26 | |||
| 27 | 1 | int main(void) | |
| 28 | { | ||
| 29 | int i, j, k; | ||
| 30 | struct AVRIPEMD *ctx; | ||
| 31 | unsigned char digest[40]; | ||
| 32 | static const int lengths[4] = { 128, 160, 256, 320 }; | ||
| 33 | |||
| 34 | 1 | ctx = av_ripemd_alloc(); | |
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!ctx) |
| 36 | ✗ | return 1; | |
| 37 | |||
| 38 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (j = 0; j < 4; j++) { |
| 39 | 4 | printf("Testing RIPEMD-%d\n", lengths[j]); | |
| 40 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
|
16 | for (k = 0; k < 3; k++) { |
| 41 | 12 | av_ripemd_init(ctx, lengths[j]); | |
| 42 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 | if (k == 0) |
| 43 | 4 | av_ripemd_update(ctx, "abc", 3); | |
| 44 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | else if (k == 1) |
| 45 | 4 | av_ripemd_update(ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56); | |
| 46 | else | ||
| 47 |
2/2✓ Branch 0 taken 4000000 times.
✓ Branch 1 taken 4 times.
|
4000004 | for (i = 0; i < 1000*1000; i++) |
| 48 | 4000000 | av_ripemd_update(ctx, "a", 1); | |
| 49 | 12 | av_ripemd_final(ctx, digest); | |
| 50 |
2/2✓ Branch 0 taken 324 times.
✓ Branch 1 taken 12 times.
|
336 | for (i = 0; i < lengths[j] >> 3; i++) |
| 51 | 324 | printf("%02X", digest[i]); | |
| 52 | 12 | putchar('\n'); | |
| 53 | } | ||
| 54 |
4/5✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
4 | switch (j) { //test vectors (from ISO:IEC 10118-3 (2004) and http://homes.esat.kuleuven.be/~bosselae/ripemd160.html) |
| 55 | 1 | case 0: | |
| 56 | 1 | printf("c14a1219 9c66e4ba 84636b0f 69144c77\n" | |
| 57 | "a1aa0689 d0fafa2d dc22e88b 49133a06\n" | ||
| 58 | "4a7f5723 f954eba1 216c9d8f 6320431f\n"); | ||
| 59 | 1 | break; | |
| 60 | 1 | case 1: | |
| 61 | 1 | printf("8eb208f7 e05d987a 9b044a8e 98c6b087 f15a0bfc\n" | |
| 62 | "12a05338 4a9c0c88 e405a06c 27dcf49a da62eb2b\n" | ||
| 63 | "52783243 c1697bdb e16d37f9 7f68f083 25dc1528\n"); | ||
| 64 | 1 | break; | |
| 65 | 1 | case 2: | |
| 66 | 1 | printf("afbd6e22 8b9d8cbb cef5ca2d 03e6dba1 0ac0bc7d cbe4680e 1e42d2e9 75459b65\n" | |
| 67 | "38430455 83aac6c8 c8d91285 73e7a980 9afb2a0f 34ccc36e a9e72f16 f6368e3f\n" | ||
| 68 | "ac953744 e10e3151 4c150d4d 8d7b6773 42e33399 788296e4 3ae4850c e4f97978\n"); | ||
| 69 | 1 | break; | |
| 70 | 1 | case 3: | |
| 71 | 1 | printf("de4c01b3 054f8930 a79d09ae 738e9230 1e5a1708 5beffdc1 b8d11671 3e74f82f a942d64c dbc4682d\n" | |
| 72 | "d034a795 0cf72202 1ba4b84d f769a5de 2060e259 df4c9bb4 a4268c0e 935bbc74 70a969c9 d072a1ac\n" | ||
| 73 | "bdee37f4 371e2064 6b8b0d86 2dda1629 2ae36f40 965e8c85 09e63d1d bddecc50 3e2b63eb 9245bb66\n"); | ||
| 74 | 1 | break; | |
| 75 | } | ||
| 76 | } | ||
| 77 | 1 | av_free(ctx); | |
| 78 | |||
| 79 | 1 | return 0; | |
| 80 | } | ||
| 81 |