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];
45 static const uint8_t key2[] =
"Jefe";
46 static const uint8_t data1[] =
"Hi There";
47 static const uint8_t data2[] =
"what do ya want for nothing?";
48 static const uint8_t data4[] =
"Test Using Larger Than Block-Size Key - Hash Key First";
49 static const uint8_t data5[] =
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
50 static const uint8_t data6[] =
"This is a test using a larger than block-size key and a larger " 51 "than block-size data. The key needs to be hashed before being used" 52 " by the HMAC algorithm.";
56 memset(key1, 0x0b,
sizeof(key1));
57 memset(key3, 0xaa,
sizeof(key3));
58 memset(data3, 0xdd,
sizeof(data3));
60 test(hmac, key1, 16, data1,
sizeof(data1));
61 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
62 test(hmac, key3, 16, data3,
sizeof(data3));
63 test(hmac, key3, 80, data4,
sizeof(data4));
64 test(hmac, key3, 80, data5,
sizeof(data5));
72 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
73 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
74 test(hmac, key3, 20, data3,
sizeof(data3));
75 test(hmac, key3, 80, data4,
sizeof(data4));
76 test(hmac, key3, 80, data5,
sizeof(data5));
83 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
84 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
85 test(hmac, key3, 20, data3,
sizeof(data3));
86 test(hmac, key3,
sizeof(key3), data4,
sizeof(data4));
87 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.