/* * Copyright (C) 2007 Michael Niedermayer <[email protected]> * Copyright (C) 2009 Konstantin Shishkov * based on public domain SHA-1 code by Steve Reid <[email protected]> * and on BSD-licensed SHA-2 code by Aaron D. Gifford * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <string.h> #include "config.h" #include "attributes.h" #include "bswap.h" #include "error.h" #include "sha.h" #include "intreadwrite.h" #include "mem.h" /** hash context */ AVSHA; const int av_sha_size = …; struct AVSHA *av_sha_alloc(void) { … } #define rol(value, bits) … /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ #define blk0(i) … #define blk(i) … #define R0(v,w,x,y,z,i) … #define R1(v,w,x,y,z,i) … #define R2(v,w,x,y,z,i) … #define R3(v,w,x,y,z,i) … #define R4(v,w,x,y,z,i) … /* Hash a single 512-bit block. This is the core of the algorithm. */ static void sha1_transform(uint32_t state[5], const uint8_t buffer[64]) { … } static const uint32_t K256[64] = …; #define Ch(x,y,z) … #define Maj(z,y,x) … #define Sigma0_256(x) … #define Sigma1_256(x) … #define sigma0_256(x) … #define sigma1_256(x) … #undef blk #define blk(i) … #define ROUND256(a,b,c,d,e,f,g,h) … #define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) … #define ROUND256_16_TO_63(a,b,c,d,e,f,g,h) … static void sha256_transform(uint32_t *state, const uint8_t buffer[64]) { … } av_cold int av_sha_init(AVSHA *ctx, int bits) { … } void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len) { … } void av_sha_final(AVSHA* ctx, uint8_t *digest) { … }