History

avutil/hmac: fix API/ABI compatibility with the fork

The test code is updated with some cosmetics to avoid the loop using undefined AVHMACType values. The old enum values will be removed in the next major bump, effectively making both projects synced and without API or ABI issues.

James Almer committed 11 years ago

Commit bc397241 parent 15a7a3c3 files · +44 −30Browse files

Unified · Split

3 files
  1. libavutil/hmac.c +35 −24
  2. libavutil/hmac.h +6 −6
  3. libavutil/version.h +3 −0
libavutil/hmac.c+35−24
@@ -81,6 +81,9 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type) · 80 unmodified lines
8181 c->hash = av_sha_alloc();
8282 break;
8383 case AV_HMAC_SHA224:
84+#if FF_API_HMAC
85+ case AV_HMAC_SHA224_DEPRECATED:
86+#endif
8487 c->blocklen = 64;
8588 c->hashlen = 28;
8689 c->init = sha224_init;
@@ -89,6 +92,9 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type) · 2 unmodified lines
8992 c->hash = av_sha_alloc();
9093 break;
9194 case AV_HMAC_SHA256:
95+#if FF_API_HMAC
96+ case AV_HMAC_SHA256_DEPRECATED:
97+#endif
9298 c->blocklen = 64;
9399 c->hashlen = 32;
94100 c->init = sha256_init;
@@ -207,7 +213,8 @@ static void test(AVHMAC *hmac, const uint8_t *key, int keylen, · 112 unmodified lines
207213 int main(void)
208214 {
209215 uint8_t key1[20], key3[131], data3[50];
210− enum AVHMACType i = AV_HMAC_SHA224;
216+ AVHMAC *hmac;
217+ enum AVHMACType i;
211218 static const uint8_t key2[] = "Jefe";
212219 static const uint8_t data1[] = "Hi There";
213220 static const uint8_t data2[] = "what do ya want for nothing?";
@@ -216,34 +223,39 @@ int main(void) · 2 unmodified lines
216223 static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger "
217224 "than block-size data. The key needs to be hashed before being used"
218225 " by the HMAC algorithm.";
219− AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5);
220− if (!hmac)
221− return 1;
222226 memset(key1, 0x0b, sizeof(key1));
223227 memset(key3, 0xaa, sizeof(key3));
224228 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);
232229
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+ }
244243
245244 /* 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++) {
247259 hmac = av_hmac_alloc(i);
248260 if (!hmac)
249261 return 1;
@@ -254,7 +266,6 @@ int main(void) · 4 unmodified lines
254266 test(hmac, key3, sizeof(key3), data4, sizeof(data4));
255267 test(hmac, key3, sizeof(key3), data6, sizeof(data6));
256268 av_hmac_free(hmac);
257− i++;
258269 }
259270 return 0;
260271 }
libavutil/hmac.h+6−6
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323
2424 #include <stdint.h>
2525
26−#include "libavutil/avconfig.h"
26+#include "version.h"
2727 /**
2828 * @defgroup lavu_hmac HMAC
2929 * @ingroup lavu_crypto
@@ -33,13 +33,13 @@ · 3 unmodified lines
3333 enum AVHMACType {
3434 AV_HMAC_MD5,
3535 AV_HMAC_SHA1,
36−#if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
3736 AV_HMAC_SHA224,
38−#else
39− AV_HMAC_SHA224 = 10,
40−#endif
4137 AV_HMAC_SHA256,
42− AV_HMAC_SHA384,
38+#if FF_API_HMAC
39+ AV_HMAC_SHA224_DEPRECATED = 10,
40+ AV_HMAC_SHA256_DEPRECATED,
41+#endif
42+ AV_HMAC_SHA384 = 12,
4343 AV_HMAC_SHA512,
4444 };
4545
libavutil/version.h+3−0
@@ -122,6 +122,9 @@ · 121 unmodified lines
122122 #ifndef FF_API_DLOG
123123 #define FF_API_DLOG (LIBAVUTIL_VERSION_MAJOR < 55)
124124 #endif
125+#ifndef FF_API_HMAC
126+#define FF_API_HMAC (LIBAVUTIL_VERSION_MAJOR < 55)
127+#endif
125128
126129 #ifndef FF_CONST_AVUTIL55
127130 #if LIBAVUTIL_VERSION_MAJOR >= 55

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t