| @@ -81,6 +81,9 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type) · 80 unmodified lines |
| 81 | 81 | c->hash = av_sha_alloc(); |
| 82 | 82 | break; |
| 83 | 83 | case AV_HMAC_SHA224: |
| 84 | +#if FF_API_HMAC |
| 85 | + case AV_HMAC_SHA224_DEPRECATED: |
| 86 | +#endif |
| 84 | 87 | c->blocklen = 64; |
| 85 | 88 | c->hashlen = 28; |
| 86 | 89 | c->init = sha224_init; |
| @@ -89,6 +92,9 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type) · 2 unmodified lines |
| 89 | 92 | c->hash = av_sha_alloc(); |
| 90 | 93 | break; |
| 91 | 94 | case AV_HMAC_SHA256: |
| 95 | +#if FF_API_HMAC |
| 96 | + case AV_HMAC_SHA256_DEPRECATED: |
| 97 | +#endif |
| 92 | 98 | c->blocklen = 64; |
| 93 | 99 | c->hashlen = 32; |
| 94 | 100 | c->init = sha256_init; |
| @@ -207,7 +213,8 @@ static void test(AVHMAC *hmac, const uint8_t *key, int keylen, · 112 unmodified lines |
| 207 | 213 | int main(void) |
| 208 | 214 | { |
| 209 | 215 | uint8_t key1[20], key3[131], data3[50]; |
| 210 | | − enum AVHMACType i = AV_HMAC_SHA224; |
| 216 | + AVHMAC *hmac; |
| 217 | + enum AVHMACType i; |
| 211 | 218 | static const uint8_t key2[] = "Jefe"; |
| 212 | 219 | static const uint8_t data1[] = "Hi There"; |
| 213 | 220 | static const uint8_t data2[] = "what do ya want for nothing?"; |
| @@ -216,34 +223,39 @@ int main(void) · 2 unmodified lines |
| 216 | 223 | static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger " |
| 217 | 224 | "than block-size data. The key needs to be hashed before being used" |
| 218 | 225 | " by the HMAC algorithm."; |
| 219 | | − AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5); |
| 220 | | − if (!hmac) |
| 221 | | − return 1; |
| 222 | 226 | memset(key1, 0x0b, sizeof(key1)); |
| 223 | 227 | memset(key3, 0xaa, sizeof(key3)); |
| 224 | 228 | memset(data3, 0xdd, sizeof(data3)); |
| 225 | | − // RFC 2202 test vectors |
| 226 | | − test(hmac, key1, 16, data1, sizeof(data1)); |
| 227 | | − test(hmac, key2, sizeof(key2), data2, sizeof(data2)); |
| 228 | | − test(hmac, key3, 16, data3, sizeof(data3)); |
| 229 | | − test(hmac, key3, 80, data4, sizeof(data4)); |
| 230 | | − test(hmac, key3, 80, data5, sizeof(data5)); |
| 231 | | − av_hmac_free(hmac); |
| 232 | 229 | |
| 233 | | − /* SHA-1 */ |
| 234 | | − hmac = av_hmac_alloc(AV_HMAC_SHA1); |
| 235 | | − if (!hmac) |
| 236 | | − return 1; |
| 237 | | − // RFC 2202 test vectors |
| 238 | | − test(hmac, key1, sizeof(key1), data1, sizeof(data1)); |
| 239 | | − test(hmac, key2, sizeof(key2), data2, sizeof(data2)); |
| 240 | | − test(hmac, key3, 20, data3, sizeof(data3)); |
| 241 | | − test(hmac, key3, 80, data4, sizeof(data4)); |
| 242 | | − test(hmac, key3, 80, data5, sizeof(data5)); |
| 243 | | − av_hmac_free(hmac); |
| 230 | + /* MD5, SHA-1 */ |
| 231 | + for (i = AV_HMAC_MD5; i <= AV_HMAC_SHA1; i++) { |
| 232 | + hmac = av_hmac_alloc(i); |
| 233 | + if (!hmac) |
| 234 | + return 1; |
| 235 | + // RFC 2202 test vectors |
| 236 | + test(hmac, key1, hmac->hashlen, data1, sizeof(data1)); |
| 237 | + test(hmac, key2, sizeof(key2), data2, sizeof(data2)); |
| 238 | + test(hmac, key3, hmac->hashlen, data3, sizeof(data3)); |
| 239 | + test(hmac, key3, 80, data4, sizeof(data4)); |
| 240 | + test(hmac, key3, 80, data5, sizeof(data5)); |
| 241 | + av_hmac_free(hmac); |
| 242 | + } |
| 244 | 243 | |
| 245 | 244 | /* SHA-2 */ |
| 246 | | − while (i <= AV_HMAC_SHA512) { |
| 245 | + for (i = AV_HMAC_SHA224; i <= AV_HMAC_SHA256; i++) { |
| 246 | + hmac = av_hmac_alloc(i); |
| 247 | + if (!hmac) |
| 248 | + return 1; |
| 249 | + // RFC 4231 test vectors |
| 250 | + test(hmac, key1, sizeof(key1), data1, sizeof(data1)); |
| 251 | + test(hmac, key2, sizeof(key2), data2, sizeof(data2)); |
| 252 | + test(hmac, key3, 20, data3, sizeof(data3)); |
| 253 | + test(hmac, key3, sizeof(key3), data4, sizeof(data4)); |
| 254 | + test(hmac, key3, sizeof(key3), data6, sizeof(data6)); |
| 255 | + av_hmac_free(hmac); |
| 256 | + } |
| 257 | + |
| 258 | + for (i = AV_HMAC_SHA384; i <= AV_HMAC_SHA512; i++) { |
| 247 | 259 | hmac = av_hmac_alloc(i); |
| 248 | 260 | if (!hmac) |
| 249 | 261 | return 1; |
| @@ -254,7 +266,6 @@ int main(void) · 4 unmodified lines |
| 254 | 266 | test(hmac, key3, sizeof(key3), data4, sizeof(data4)); |
| 255 | 267 | test(hmac, key3, sizeof(key3), data6, sizeof(data6)); |
| 256 | 268 | av_hmac_free(hmac); |
| 257 | | − i++; |
| 258 | 269 | } |
| 259 | 270 | return 0; |
| 260 | 271 | } |