diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-05-11 19:10:10 +0100 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-05-11 19:13:03 +0100 |
commit | 96d616052b3d39678e477fa10610ca688f46fff9 (patch) | |
tree | 8bd31d06318bc786ea8f1d84f92090c9c860bc11 /libavutil/hmac.c | |
parent | 27506aceda8115f82f89691a4441d62a8cf24a6e (diff) | |
parent | d12b5b2f135aade4099f4b26b0fe678656158c13 (diff) | |
download | ffmpeg-96d616052b3d39678e477fa10610ca688f46fff9.tar.gz |
Merge commit 'd12b5b2f135aade4099f4b26b0fe678656158c13'
* commit 'd12b5b2f135aade4099f4b26b0fe678656158c13':
build: Split test programs off into separate files
Some conversions done by: James Almer <jamrial@gmail.com>
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavutil/hmac.c')
-rw-r--r-- | libavutil/hmac.c | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/libavutil/hmac.c b/libavutil/hmac.c index 3e11509a27..8ec6d70406 100644 --- a/libavutil/hmac.c +++ b/libavutil/hmac.c @@ -183,84 +183,3 @@ 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[20], key3[131], data3[50]; - AVHMAC *hmac; - enum AVHMACType i; - static const uint8_t key2[] = "Jefe"; - static const uint8_t data1[] = "Hi There"; - static const uint8_t data2[] = "what do ya want for nothing?"; - static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First"; - static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; - static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger " - "than block-size data. The key needs to be hashed before being used" - " by the HMAC algorithm."; - memset(key1, 0x0b, sizeof(key1)); - memset(key3, 0xaa, sizeof(key3)); - memset(data3, 0xdd, sizeof(data3)); - - /* MD5, SHA-1 */ - for (i = AV_HMAC_MD5; i <= AV_HMAC_SHA1; i++) { - hmac = av_hmac_alloc(i); - if (!hmac) - return 1; - // RFC 2202 test vectors - test(hmac, key1, hmac->hashlen, data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, hmac->hashlen, data3, sizeof(data3)); - test(hmac, key3, 80, data4, sizeof(data4)); - test(hmac, key3, 80, data5, sizeof(data5)); - av_hmac_free(hmac); - } - - /* SHA-2 */ - for (i = AV_HMAC_SHA224; i <= AV_HMAC_SHA256; i++) { - hmac = av_hmac_alloc(i); - if (!hmac) - return 1; - // RFC 4231 test vectors - test(hmac, key1, sizeof(key1), data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, 20, data3, sizeof(data3)); - test(hmac, key3, sizeof(key3), data4, sizeof(data4)); - test(hmac, key3, sizeof(key3), data6, sizeof(data6)); - av_hmac_free(hmac); - } - - for (i = AV_HMAC_SHA384; i <= AV_HMAC_SHA512; i++) { - hmac = av_hmac_alloc(i); - if (!hmac) - return 1; - // RFC 4231 test vectors - test(hmac, key1, sizeof(key1), data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, 20, data3, sizeof(data3)); - test(hmac, key3, sizeof(key3), data4, sizeof(data4)); - test(hmac, key3, sizeof(key3), data6, sizeof(data6)); - av_hmac_free(hmac); - } - return 0; -} -#endif /* TEST */ |