OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at> | 2 * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at> |
3 * Copyright (C) 2009 Konstantin Shishkov | 3 * Copyright (C) 2009 Konstantin Shishkov |
4 * based on public domain SHA-1 code by Steve Reid <steve@edmweb.com> | 4 * based on public domain SHA-1 code by Steve Reid <steve@edmweb.com> |
5 * and on BSD-licensed SHA-2 code by Aaron D. Gifford | 5 * and on BSD-licensed SHA-2 code by Aaron D. Gifford |
6 * | 6 * |
7 * This file is part of FFmpeg. | 7 * This file is part of FFmpeg. |
8 * | 8 * |
9 * FFmpeg is free software; you can redistribute it and/or | 9 * FFmpeg is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
12 * version 2.1 of the License, or (at your option) any later version. | 12 * version 2.1 of the License, or (at your option) any later version. |
13 * | 13 * |
14 * FFmpeg is distributed in the hope that it will be useful, | 14 * FFmpeg is distributed in the hope that it will be useful, |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 * Lesser General Public License for more details. | 17 * Lesser General Public License for more details. |
18 * | 18 * |
19 * You should have received a copy of the GNU Lesser General Public | 19 * You should have received a copy of the GNU Lesser General Public |
20 * License along with FFmpeg; if not, write to the Free Software | 20 * License along with FFmpeg; if not, write to the Free Software |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 */ | 22 */ |
23 | 23 |
24 #include "common.h" | 24 #include "common.h" |
25 #include "avutil.h" | 25 #include "avutil.h" |
26 #include "bswap.h" | 26 #include "bswap.h" |
27 #include "sha.h" | 27 #include "sha.h" |
| 28 #include "sha1.h" |
| 29 #include "intreadwrite.h" |
28 | 30 |
29 /** hash context */ | 31 /** hash context */ |
30 typedef struct AVSHA { | 32 typedef struct AVSHA { |
31 uint8_t digest_len; ///< digest length in 32-bit words | 33 uint8_t digest_len; ///< digest length in 32-bit words |
32 uint64_t count; ///< number of bytes in buffer | 34 uint64_t count; ///< number of bytes in buffer |
33 uint8_t buffer[64]; ///< 512-bit buffer of input values used in hash updat
ing | 35 uint8_t buffer[64]; ///< 512-bit buffer of input values used in hash updat
ing |
34 uint32_t state[8]; ///< current hash value | 36 uint32_t state[8]; ///< current hash value |
35 /** function used to update hash for 512-bit input block */ | 37 /** function used to update hash for 512-bit input block */ |
36 void (*transform)(uint32_t *state, const uint8_t buffer[64]); | 38 void (*transform)(uint32_t *state, const uint8_t buffer[64]); |
37 } AVSHA; | 39 } AVSHA; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 void av_sha_final(AVSHA* ctx, uint8_t *digest) | 314 void av_sha_final(AVSHA* ctx, uint8_t *digest) |
313 { | 315 { |
314 int i; | 316 int i; |
315 uint64_t finalcount = be2me_64(ctx->count << 3); | 317 uint64_t finalcount = be2me_64(ctx->count << 3); |
316 | 318 |
317 av_sha_update(ctx, "\200", 1); | 319 av_sha_update(ctx, "\200", 1); |
318 while ((ctx->count & 63) != 56) | 320 while ((ctx->count & 63) != 56) |
319 av_sha_update(ctx, "", 1); | 321 av_sha_update(ctx, "", 1); |
320 av_sha_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform()
*/ | 322 av_sha_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform()
*/ |
321 for (i = 0; i < ctx->digest_len; i++) | 323 for (i = 0; i < ctx->digest_len; i++) |
322 ((uint32_t*)digest)[i] = be2me_32(ctx->state[i]); | 324 AV_WB32(digest + i*4, ctx->state[i]); |
323 } | 325 } |
324 | 326 |
325 #if LIBAVUTIL_VERSION_MAJOR < 51 | 327 #if LIBAVUTIL_VERSION_MAJOR < 51 |
326 struct AVSHA1 { | 328 struct AVSHA1 { |
327 AVSHA sha; | 329 AVSHA sha; |
328 }; | 330 }; |
329 | 331 |
330 const int av_sha1_size = sizeof(struct AVSHA1); | 332 const int av_sha1_size = sizeof(struct AVSHA1); |
331 | 333 |
332 void av_sha1_init(struct AVSHA1* context) | 334 void av_sha1_init(struct AVSHA1* context) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff
61 f20015ad\n" | 392 printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff
61 f20015ad\n" |
391 "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6eced
d4 19db06c1\n" | 393 "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6eced
d4 19db06c1\n" |
392 "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39
cc c7112cd0\n"); | 394 "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39
cc c7112cd0\n"); |
393 break; | 395 break; |
394 } | 396 } |
395 } | 397 } |
396 | 398 |
397 return 0; | 399 return 0; |
398 } | 400 } |
399 #endif | 401 #endif |
OLD | NEW |