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