30 #define MAX_HASHLEN 64
31 #define MAX_BLOCKLEN 128
43 #define DEFINE_SHA(bits) \
44 static av_cold void sha ## bits ##_init(void *ctx) \
46 av_sha_init(ctx, bits); \
49 #define DEFINE_SHA512(bits) \
50 static av_cold void sha ## bits ##_init(void *ctx) \
52 av_sha512_init(ctx, bits); \
78 c->
init = sha160_init;
86 c->
init = sha224_init;
94 c->
init = sha256_init;
102 c->
init = sha384_init;
110 c->
init = sha512_init;
144 memcpy(c->
key, key, keylen);
148 for (i = 0; i < c->
keylen; i++)
149 block[i] = c->
key[i] ^ 0x36;
150 for (i = c->
keylen; i < c->blocklen; i++)
164 if (outlen < c->hashlen)
168 for (i = 0; i < c->
keylen; i++)
169 block[i] = c->
key[i] ^ 0x5C;
170 for (i = c->
keylen; i < c->blocklen; i++)
179 const uint8_t *key,
unsigned int keylen,
197 if (!key[keylen - 1])
199 if (!data[datalen - 1])
201 out =
av_hmac_calc(hmac, data, datalen, key, keylen, buf,
sizeof(buf));
202 for (i = 0; i <
out; i++)
203 printf(
"%02x", buf[i]);
209 uint8_t key1[20], key3[131], data3[50];
212 static const uint8_t key2[] =
"Jefe";
213 static const uint8_t data1[] =
"Hi There";
214 static const uint8_t data2[] =
"what do ya want for nothing?";
215 static const uint8_t data4[] =
"Test Using Larger Than Block-Size Key - Hash Key First";
216 static const uint8_t data5[] =
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
217 static const uint8_t data6[] =
"This is a test using a larger than block-size key and a larger "
218 "than block-size data. The key needs to be hashed before being used"
219 " by the HMAC algorithm.";
220 memset(key1, 0x0b,
sizeof(key1));
221 memset(key3, 0xaa,
sizeof(key3));
222 memset(data3, 0xdd,
sizeof(data3));
230 test(hmac, key1, hmac->
hashlen, data1,
sizeof(data1));
231 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
232 test(hmac, key3, hmac->
hashlen, data3,
sizeof(data3));
233 test(hmac, key3, 80, data4,
sizeof(data4));
234 test(hmac, key3, 80, data5,
sizeof(data5));
244 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
245 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
246 test(hmac, key3, 20, data3,
sizeof(data3));
247 test(hmac, key3,
sizeof(key3), data4,
sizeof(data4));
248 test(hmac, key3,
sizeof(key3), data6,
sizeof(data6));
257 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
258 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
259 test(hmac, key3, 20, data3,
sizeof(data3));
260 test(hmac, key3,
sizeof(key3), data4,
sizeof(data4));
261 test(hmac, key3,
sizeof(key3), data6,
sizeof(data6));
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.
void av_sha_update(AVSHA *ctx, const uint8_t *data, unsigned int len)
Update hash value.
ptrdiff_t const GLvoid * data
AVHMAC * av_hmac_alloc(enum AVHMACType type)
Allocate an AVHMAC context.
memory handling functions
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.
static void test(const char *pattern, const char *host)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
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(* final)(void *, uint8_t *)
void av_sha512_update(AVSHA512 *ctx, const uint8_t *data, unsigned int len)
Update hash value.
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(* update)(void *, const uint8_t *, int len)
#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.
int main(int argc, char **argv)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...