FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ripemd.c
Go to the documentation of this file.
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 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  ctx = av_ripemd_alloc();
35  if (!ctx)
36  return 1;
37 
38  for (j = 0; j < 4; j++) {
39  printf("Testing RIPEMD-%d\n", lengths[j]);
40  for (k = 0; k < 3; k++) {
41  av_ripemd_init(ctx, lengths[j]);
42  if (k == 0)
43  av_ripemd_update(ctx, "abc", 3);
44  else if (k == 1)
45  av_ripemd_update(ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
46  else
47  for (i = 0; i < 1000*1000; i++)
48  av_ripemd_update(ctx, "a", 1);
49  av_ripemd_final(ctx, digest);
50  for (i = 0; i < lengths[j] >> 3; i++)
51  printf("%02X", digest[i]);
52  putchar('\n');
53  }
54  switch (j) { //test vectors (from ISO:IEC 10118-3 (2004) and http://homes.esat.kuleuven.be/~bosselae/ripemd160.html)
55  case 0:
56  printf("c14a1219 9c66e4ba 84636b0f 69144c77\n"
57  "a1aa0689 d0fafa2d dc22e88b 49133a06\n"
58  "4a7f5723 f954eba1 216c9d8f 6320431f\n");
59  break;
60  case 1:
61  printf("8eb208f7 e05d987a 9b044a8e 98c6b087 f15a0bfc\n"
62  "12a05338 4a9c0c88 e405a06c 27dcf49a da62eb2b\n"
63  "52783243 c1697bdb e16d37f9 7f68f083 25dc1528\n");
64  break;
65  case 2:
66  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  break;
70  case 3:
71  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  break;
75  }
76  }
77  av_free(ctx);
78 
79  return 0;
80 }
void av_ripemd_update(AVRIPEMD *ctx, const uint8_t *data, unsigned int len)
Update hash value.
Definition: ripemd.c:514
Memory handling functions.
Public header for RIPEMD hash function implementation.
void av_ripemd_final(AVRIPEMD *ctx, uint8_t *digest)
Finish hashing and output digest value.
Definition: ripemd.c:544
struct AVRIPEMD * av_ripemd_alloc(void)
Allocate an AVRIPEMD context.
Definition: ripemd.c:43
AVFormatContext * ctx
Definition: movenc.c:48
hash context
Definition: ripemd.c:32
av_cold int av_ripemd_init(AVRIPEMD *ctx, int bits)
Initialize RIPEMD hashing.
Definition: ripemd.c:463
#define av_free(p)
int main(void)
Definition: ripemd.c:27