From d12b5b2f135aade4099f4b26b0fe678656158c13 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 17 Mar 2016 19:13:17 +0100 Subject: build: Split test programs off into separate files This avoids spurious library rebuilds when only the test program code is changed and simplifies the build system. --- libavutil/hmac.c | 74 -------------------------------------------------------- 1 file changed, 74 deletions(-) (limited to 'libavutil/hmac.c') diff --git a/libavutil/hmac.c b/libavutil/hmac.c index abbee368b0..378be62fd3 100644 --- a/libavutil/hmac.c +++ b/libavutil/hmac.c @@ -158,77 +158,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 - -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]; - enum AVHMACType i = AV_HMAC_SHA224; - const uint8_t key2[] = "Jefe"; - const uint8_t data1[] = "Hi There"; - const uint8_t data2[] = "what do ya want for nothing?"; - const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First"; - const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"; - 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."; - AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5); - if (!hmac) - return 1; - memset(key1, 0x0b, sizeof(key1)); - memset(key3, 0xaa, sizeof(key3)); - memset(data3, 0xdd, sizeof(data3)); - // RFC 2202 test vectors - test(hmac, key1, 16, data1, sizeof(data1)); - test(hmac, key2, sizeof(key2), data2, sizeof(data2)); - test(hmac, key3, 16, data3, sizeof(data3)); - test(hmac, key3, 80, data4, sizeof(data4)); - test(hmac, key3, 80, data5, sizeof(data5)); - av_hmac_free(hmac); - - /* SHA-1 */ - hmac = av_hmac_alloc(AV_HMAC_SHA1); - if (!hmac) - return 1; - // RFC 2202 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, 80, data4, sizeof(data4)); - test(hmac, key3, 80, data5, sizeof(data5)); - av_hmac_free(hmac); - - /* SHA-2 */ - while (i <= AV_HMAC_SHA256) { - hmac = av_hmac_alloc(i); - // 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); - i++; - } - return 0; -} -#endif /* TEST */ -- cgit v1.2.3