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
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
207int main(void)213int 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 vectors234 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}
libavutil/hmac.h+6−6
@@ -23,7 +23,7 @@ · 22 unmodified lines
23 23
24#include <stdint.h>24#include <stdint.h>
25 25
26#include "libavutil/avconfig.h"26#include "version.h"
27/**27/**
28 * @defgroup lavu_hmac HMAC28 * @defgroup lavu_hmac HMAC
29 * @ingroup lavu_crypto29 * @ingroup lavu_crypto
@@ -33,13 +33,13 @@ · 3 unmodified lines
33enum AVHMACType {33enum AVHMACType {
34 AV_HMAC_MD5,34 AV_HMAC_MD5,
35 AV_HMAC_SHA1,35 AV_HMAC_SHA1,
36#if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
37 AV_HMAC_SHA224,36 AV_HMAC_SHA224,
38#else
39 AV_HMAC_SHA224 = 10,
40#endif
41 AV_HMAC_SHA256,37 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,
43 AV_HMAC_SHA512,43 AV_HMAC_SHA512,
44};44};
45 45
libavutil/version.h+3−0
@@ -122,6 +122,9 @@ · 121 unmodified lines
122#ifndef FF_API_DLOG122#ifndef FF_API_DLOG
123#define FF_API_DLOG (LIBAVUTIL_VERSION_MAJOR < 55)123#define FF_API_DLOG (LIBAVUTIL_VERSION_MAJOR < 55)
124#endif124#endif
125#ifndef FF_API_HMAC
126#define FF_API_HMAC (LIBAVUTIL_VERSION_MAJOR < 55)
127#endif
125 128
126#ifndef FF_CONST_AVUTIL55129#ifndef FF_CONST_AVUTIL55
127#if LIBAVUTIL_VERSION_MAJOR >= 55130#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