diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-01-16 12:07:04 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-01-16 12:07:27 +0100 |
commit | 9ea65c65f70029896b1c23afd9925ae42c4d009f (patch) | |
tree | 213694091e2eb5a1480ca8427649f8be51be0a17 /libavutil/hmac.c | |
parent | 06af724c56c9fd74bb6ace457f39e1768bd94246 (diff) | |
parent | 0eecafc948b74c247ebbc59f18f508db5d590d0b (diff) | |
download | ffmpeg-9ea65c65f70029896b1c23afd9925ae42c4d009f.tar.gz |
Merge commit '0eecafc948b74c247ebbc59f18f508db5d590d0b'
* commit '0eecafc948b74c247ebbc59f18f508db5d590d0b':
configure: Make the new srtp protocol depend on the rtp protocol
lavf: Add a fate test for the SRTP functions
lavu: Add a fate test for the HMAC API
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/hmac.c')
-rw-r--r-- | libavutil/hmac.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libavutil/hmac.c b/libavutil/hmac.c index 1520148246..e5f1434f9a 100644 --- a/libavutil/hmac.c +++ b/libavutil/hmac.c @@ -136,3 +136,51 @@ int av_hmac_calc(AVHMAC *c, const uint8_t *data, unsigned int len, av_hmac_update(c, data, len); return av_hmac_final(c, out, outlen); } + +#ifdef TEST +#include <stdio.h> + +static void test(AVHMAC *hmac, const uint8_t *key, int keylen, + const uint8_t *data, int datalen) +{ + uint8_t buf[MAX_HASHLEN]; + int out, i; + // Some of the test vectors are strings, where sizeof() includes the + // trailing null byte - remove that. + if (!key[keylen - 1]) + keylen--; + if (!data[datalen - 1]) + datalen--; + out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf)); + for (i = 0; i < out; i++) + printf("%02x", buf[i]); + printf("\n"); +} + +int main(void) +{ + uint8_t key1[16], key3[16], data3[50], key4[63], key5[64], key6[65]; + const uint8_t key2[] = "Jefe"; + const uint8_t data1[] = "Hi There"; + const uint8_t data2[] = "what do ya want for nothing?"; + AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5); + if (!hmac) + return 1; + memset(key1, 0x0b, sizeof(key1)); + memset(key3, 0xaa, sizeof(key3)); + memset(key4, 0x44, sizeof(key4)); + memset(key5, 0x55, sizeof(key5)); + memset(key6, 0x66, sizeof(key6)); + memset(data3, 0xdd, sizeof(data3)); + // RFC 2104 test vectors + test(hmac, key1, sizeof(key1), data1, sizeof(data1)); + test(hmac, key2, sizeof(key2), data2, sizeof(data2)); + test(hmac, key3, sizeof(key3), data3, sizeof(data3)); + // Additional tests, to test cases where the key is too long + test(hmac, key4, sizeof(key4), data1, sizeof(data1)); + test(hmac, key5, sizeof(key5), data2, sizeof(data2)); + test(hmac, key6, sizeof(key6), data3, sizeof(data3)); + av_hmac_free(hmac); + return 0; +} +#endif /* TEST */ |