1 /*
2 * Copyright (C) 2012 Martin Storsjo
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <string.h>
24
32
33 #define MAX_HASHLEN 64
34 #define MAX_BLOCKLEN 128
35
37 #if FF_API_CRYPTO_SIZE_T
39 #else
41 #endif
43
52 };
53
54 #define DEFINE_SHA(bits) \
55 static av_cold void sha ## bits ##_init(void *ctx) \
56 { \
57 av_sha_init(ctx, bits); \
58 }
59
60 #define DEFINE_SHA512(bits) \
61 static av_cold void sha ## bits ##_init(void *ctx) \
62 { \
63 av_sha512_init(ctx, bits); \
64 }
65
71
73 {
75 if (!c)
77 switch (type) {
85 break;
89 c->
init = sha160_init;
93 break;
97 c->
init = sha224_init;
101 break;
105 c->
init = sha256_init;
109 break;
113 c->
init = sha384_init;
117 break;
121 c->
init = sha512_init;
125 break;
126 default:
129 }
133 }
135 }
136
138 {
139 if (!c)
140 return;
143 }
144
146 {
147 int i;
154 } else {
155 memcpy(c->
key, key, keylen);
157 }
159 for (i = 0; i < c->
keylen; i++)
160 block[i] = c->
key[i] ^ 0x36;
161 for (i = c->
keylen; i < c->blocklen; i++)
162 block[i] = 0x36;
164 }
165
167 {
169 }
170
172 {
174 int i;
175 if (outlen < c->hashlen)
179 for (i = 0; i < c->
keylen; i++)
180 block[i] = c->
key[i] ^ 0x5C;
181 for (i = c->
keylen; i < c->blocklen; i++)
182 block[i] = 0x5C;
187 }
188
192 {
196 }
void av_sha_final(AVSHA *ctx, uint8_t *digest)
Finish hashing and output digest value.
int av_hmac_calc(AVHMAC *c, const uint8_t *data, unsigned int len, const uint8_t *key, unsigned int keylen, uint8_t *out, unsigned int outlen)
Hash an array of data with a key.
ptrdiff_t const GLvoid * data
AVHMAC * av_hmac_alloc(enum AVHMACType type)
Allocate an AVHMAC context.
Memory handling functions.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
Update hash value.
Macro definitions for various function/variable attributes.
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
void av_hmac_update(AVHMAC *c, const uint8_t *data, unsigned int len)
Hash data with the HMAC.
struct AVSHA512 * av_sha512_alloc(void)
Allocate an AVSHA512 context.
Libavutil version macros.
void(* hmac_final)(void *ctx, uint8_t *dst)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len)
Update hash value.
void av_hmac_init(AVHMAC *c, const uint8_t *key, unsigned int keylen)
Initialize an AVHMAC context with an authentication key.
uint8_t key[MAX_BLOCKLEN]
void av_sha512_update(AVSHA512 *ctx, const uint8_t *data, unsigned int len)
Update hash value.
Public header for SHA-1 & SHA-256 hash function implementations.
struct AVSHA * av_sha_alloc(void)
Allocate an AVSHA context.
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing.
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
int av_hmac_final(AVHMAC *c, uint8_t *out, unsigned int outlen)
Finish hashing and output the HMAC digest.
void(* hmac_update)(void *ctx, const uint8_t *src, int len)
Public header for SHA-512 implementation.
#define DEFINE_SHA512(bits)
void av_hmac_free(AVHMAC *c)
Free an AVHMAC context.
void av_sha512_final(AVSHA512 *ctx, uint8_t *digest)
Finish hashing and output digest value.
void(* hmac_init)(void *ctx)
Public header for MD5 hash function implementation.