33 if (!data[datalen - 1])
35 out =
av_hmac_calc(hmac, data, datalen, key, keylen, buf,
sizeof(buf));
36 for (i = 0; i <
out; i++)
37 printf(
"%02x", buf[i]);
43 uint8_t key1[20], key3[131], data3[50];
46 static const uint8_t key2[] =
"Jefe";
47 static const uint8_t data1[] =
"Hi There";
48 static const uint8_t data2[] =
"what do ya want for nothing?";
49 static const uint8_t data4[] =
"Test Using Larger Than Block-Size Key - Hash Key First";
50 static const uint8_t data5[] =
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
51 static const uint8_t data6[] =
"This is a test using a larger than block-size key and a larger " 52 "than block-size data. The key needs to be hashed before being used" 53 " by the HMAC algorithm.";
54 memset(key1, 0x0b,
sizeof(key1));
55 memset(key3, 0xaa,
sizeof(key3));
56 memset(data3, 0xdd,
sizeof(data3));
64 test(hmac, key1, hmac->
hashlen, data1,
sizeof(data1));
65 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
66 test(hmac, key3, hmac->
hashlen, data3,
sizeof(data3));
67 test(hmac, key3, 80, data4,
sizeof(data4));
68 test(hmac, key3, 80, data5,
sizeof(data5));
78 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
79 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
80 test(hmac, key3, 20, data3,
sizeof(data3));
81 test(hmac, key3,
sizeof(key3), data4,
sizeof(data4));
82 test(hmac, key3,
sizeof(key3), data6,
sizeof(data6));
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.
AVHMAC * av_hmac_alloc(enum AVHMACType type)
Allocate an AVHMAC context.
static void test(AVHMAC *hmac, const uint8_t *key, int keylen, const uint8_t *data, int datalen)
void av_hmac_free(AVHMAC *c)
Free an AVHMAC context.