Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / lib / mac_test.c @ 6b3f1a54

History | View | Annotate | Download (39 KB)

1
/*
2
 *        BIRD Library -- SHA and HMAC-SHA functions tests
3
 *
4
 *        (c) 2015 CZ.NIC z.s.p.o.
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include "test/birdtest.h"
10
#include "test/bt-utils.h"
11

    
12
#include "lib/mac.h"
13

    
14

    
15
#define define_test_hash_fn(name,id)                                        \
16
static int                                                                \
17
test_##name(void *out_, const void *in_, const void *expected_out_)        \
18
{                                                                        \
19
  char *out = out_;                                                        \
20
  const char *in = in_;                                                        \
21
  const char *expected_out = expected_out_;                                \
22
                                                                        \
23
  struct mac_context ctx;                                                \
24
  mac_init(&ctx, id, NULL, 0);                                                \
25
  mac_update(&ctx, in, strlen(in));                                        \
26
  byte *out_bin = mac_final(&ctx);                                        \
27
                                                                        \
28
  uint len = mac_type_length(id);                                        \
29
  bt_bytes_to_hex(out, out_bin, len);                                        \
30
                                                                        \
31
  return strncmp(out, expected_out, 2*len+1) == 0; \
32
}
33

    
34
define_test_hash_fn(md5,        ALG_MD5)
35
define_test_hash_fn(sha1,        ALG_SHA1)
36
define_test_hash_fn(sha224,        ALG_SHA224)
37
define_test_hash_fn(sha256,        ALG_SHA256)
38
define_test_hash_fn(sha384,        ALG_SHA384)
39
define_test_hash_fn(sha512,        ALG_SHA512)
40

    
41

    
42
static int
43
t_md5(void)
44
{
45
  struct bt_pair test_vectors[] = {
46
    {
47
      .in  = "",
48
      .out = "d41d8cd98f00b204e9800998ecf8427e",
49
    },
50
    {
51
      .in  = "a",
52
      .out = "0cc175b9c0f1b6a831c399e269772661",
53
    },
54
    {
55
      .in  = "abc",
56
      .out = "900150983cd24fb0d6963f7d28e17f72",
57
    },
58
    {
59
      .in  = "message digest",
60
      .out = "f96b697d7cb7938d525a2f31aaf161d0",
61
    },
62
    {
63
      .in  = "abcdefghijklmnopqrstuvwxyz",
64
      .out = "c3fcd3d76192e4007dfb496cca67e13b",
65
    },
66
    {
67
      .in  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
68
      .out = "d174ab98d277d9f5a5611c2c9f419d9f",
69
    },
70
    {
71
      .in  = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72
      .out = "57edf4a22be3c955ac49da2e2107b67a",
73
    },
74
  };
75

    
76
  return bt_assert_batch(test_vectors, test_md5, bt_fmt_str, bt_fmt_str);
77
}
78

    
79

    
80
/*
81
 * Testing SHAxxx functions
82
 */
83

    
84

    
85
static int
86
t_sha1(void)
87
{
88
  struct bt_pair test_vectors[] = {
89
    {
90
      .in  = "",
91
      .out = "da39a3ee5e6b4b0d3255bfef95601890afd80709",
92
    },
93
    {
94
      .in  = "a",
95
      .out = "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8",
96
    },
97
    {
98
      .in  = "abc",
99
      .out = "a9993e364706816aba3e25717850c26c9cd0d89d",
100
    },
101
    {
102
      .in  = "message digest",
103
      .out = "c12252ceda8be8994d5fa0290a47231c1d16aae3",
104
    },
105
    {
106
      .in  = "abcdefghijklmnopqrstuvwxyz",
107
      .out = "32d10c7b8cf96570ca04ce37f2a19d84240d3a89",
108
    },
109
    {
110
      .in  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
111
      .out = "761c457bf73b14d27e9e9265c46f4b4dda11f940",
112
    },
113
    {
114
      .in  = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
115
      .out = "50abf5706a150990a08b2c5ea40fa0e585554732",
116
    },
117
    {
118
      .in  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
119
      .out = "6a64fcc1fb970f7339ce886601775d2efea5cd4b",
120
    },
121
  };
122

    
123
  return bt_assert_batch(test_vectors, test_sha1, bt_fmt_str, bt_fmt_str);
124
}
125

    
126
static int
127
t_sha224(void)
128
{
129
  struct bt_pair test_vectors[] = {
130
    {
131
      .in  = "",
132
      .out = "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f",
133
    },
134
    {
135
      .in  = "a",
136
      .out = "abd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5",
137
    },
138
    {
139
      .in  = "abc",
140
      .out = "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7",
141
    },
142
    {
143
      .in  = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
144
      .out = "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525",
145
    },
146
    {
147
      .in  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
148
      .out = "cca7dd1a332a17775d8b0429bdb45055c2d4368ebaab0c7cf385586e",
149
    },
150
  };
151

    
152
  return bt_assert_batch(test_vectors, test_sha224, bt_fmt_str, bt_fmt_str);
153
}
154

    
155
static int
156
t_sha256(void)
157
{
158
  struct bt_pair test_vectors[] = {
159
    {
160
      .in  = "",
161
      .out = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
162
    },
163
    {
164
      .in  = "a",
165
      .out = "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
166
    },
167
    {
168
      .in  = "abc",
169
      .out = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
170
    },
171
    {
172
      .in  = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
173
      .out = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
174
    },
175
    {
176
      .in  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
177
      .out = "bf18b43b61652b5d73f41ebf3d72e5e43aebf5076f497dde31ea3de9de4998ef",
178
    },
179
  };
180

    
181
  return bt_assert_batch(test_vectors, test_sha256, bt_fmt_str, bt_fmt_str);
182
}
183

    
184
static int
185
t_sha384(void)
186
{
187
  struct bt_pair test_vectors[] = {
188
    {
189
      .in  = "",
190
      .out = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",
191
    },
192
    {
193
      .in  = "a",
194
      .out = "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31",
195
    },
196
    {
197
      .in  = "abc",
198
      .out = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
199
    },
200
    {
201
      .in  = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
202
      .out = "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b",
203
    },
204
    {
205
      .in  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
206
      .out = "6452928a62ca915a60f2d16ea22cc832d8ecb35443d78a3ff6986e7def9174a1dc16ce2ff65d3ed1666db98357f3c05e",
207
    },
208
  };
209

    
210
  return bt_assert_batch(test_vectors, test_sha384, bt_fmt_str, bt_fmt_str);
211
}
212

    
213
static int
214
t_sha512(void)
215
{
216
  struct bt_pair test_vectors[] = {
217
    {
218
      .in  = "",
219
      .out = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e",
220
    },
221
    {
222
      .in  = "a",
223
      .out = "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75",
224
    },
225
    {
226
      .in  = "abc",
227
      .out = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
228
    },
229
    {
230
      .in  = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
231
      .out = "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445",
232
    },
233
    {
234
      .in  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
235
      .out = "415509a1c345371acb3e27a88b3835e3b6dfebcbbab5134850596f4db64d7bb22ac42c3cd179446a80c92b8be955460eb536eac01389a7e1fdf09d1dca83922f",
236
    },
237
  };
238

    
239
  return bt_assert_batch(test_vectors, test_sha512, bt_fmt_str, bt_fmt_str);
240
}
241

    
242

    
243
/*
244
 * Testing SHAxxx HMAC functions
245
 */
246

    
247
#define HMAC_BUFFER_SIZE 160
248
struct hmac_data_in {
249
  byte key[HMAC_BUFFER_SIZE];
250
  uint key_len;
251
  byte data[HMAC_BUFFER_SIZE];
252
  uint data_len;
253
};
254

    
255
static void
256
hmac_in_fmt(char *buf, size_t size, const void *data_)
257
{
258
  uint i;
259
  const struct hmac_data_in *data = data_;
260

    
261
  snprintf(buf, size, "data: '");
262
  for (i = 0; i < data->data_len; i++)
263
    snprintf(buf+strlen(buf), size-strlen(buf), bt_is_char(data->data[i]) ? "%c" : " 0x%02x", data->data[i]);
264

    
265
  snprintf(buf+strlen(buf), size-strlen(buf), "', key: '");
266
  for (i = 0; i < data->key_len; i++)
267
    snprintf(buf+strlen(buf), size-strlen(buf), bt_is_char(data->key[i]) ? "%c" : " 0x%02x", data->key[i]);
268
  snprintf(buf+strlen(buf), size-strlen(buf), "'");
269
}
270

    
271
#define define_test_hmac_fn(name,id)                                        \
272
static int                                                                \
273
test_##name##_hmac(void *out_, const void *in_, const void *expected_out_)        \
274
{                                                                        \
275
  char *out = out_;                                                        \
276
  const struct hmac_data_in *in = in_;                                        \
277
  const char *expected_out = expected_out_;                                \
278
                                                                          \
279
  struct mac_context ctx;                                                \
280
  mac_init(&ctx, id, in->key, in->key_len);                                \
281
  mac_update(&ctx, in->data, in->data_len);                                \
282
  byte *out_bin = mac_final(&ctx);                                        \
283
                                                                        \
284
  uint len = mac_type_length(id);                                        \
285
  bt_bytes_to_hex(out, out_bin, len);                                        \
286
                                                                        \
287
  return strncmp(out, expected_out, 2*len+1) == 0; \
288
}
289

    
290
define_test_hmac_fn(md5,        ALG_HMAC_MD5)
291
define_test_hmac_fn(sha1,        ALG_HMAC_SHA1)
292
define_test_hmac_fn(sha224,        ALG_HMAC_SHA224)
293
define_test_hmac_fn(sha256,        ALG_HMAC_SHA256)
294
define_test_hmac_fn(sha384,        ALG_HMAC_SHA384)
295
define_test_hmac_fn(sha512,        ALG_HMAC_SHA512)
296

    
297

    
298
static int
299
t_md5_hmac(void)
300
{
301
  struct bt_pair test_vectors[] = {
302
    {
303
      .in  = & (struct hmac_data_in) {
304
        .key = {
305
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
306
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
307
        },
308
        .key_len = 16,
309
        .data = "Hi There",
310
        .data_len = 8,
311
      },
312
      .out = "9294727a3638bb1c13f48ef8158bfc9d",
313
    },
314
    {
315
      .in  = & (struct hmac_data_in) {
316
        .key = "Jefe",
317
        .key_len = 4,
318
        .data = "what do ya want for nothing?",
319
        .data_len = 28,
320
      },
321
      .out = "750c783e6ab0b503eaa86e310a5db738",
322
    },
323
    {
324
      .in  = & (struct hmac_data_in) {
325
        .key = {
326
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
327
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
328
        },
329
        .key_len = 16,
330
        .data = {
331
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
332
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
333
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
334
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
335
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
336
        },
337
        .data_len = 50,
338
      },
339
      .out = "56be34521d144c88dbb8c733f0e8b3f6",
340
    },
341
    {
342
      .in  = & (struct hmac_data_in) {
343
        .key = {
344
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
345
          0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
346
          0x15, 0x16, 0x17, 0x18, 0x19,
347
        },
348
        .key_len = 25,
349
        .data = {
350
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
351
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
352
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
353
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
354
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
355
        },
356
        .data_len = 50,
357
      },
358
      .out = "697eaf0aca3a3aea3a75164746ffaa79",
359
    },
360
    {
361
      .in  = & (struct hmac_data_in) {
362
        .key = {
363
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
364
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
365
        },
366
        .key_len = 16,
367
        .data = "Test With Truncation",
368
        .data_len = 20,
369
      },
370
      .out = "56461ef2342edc00f9bab995690efd4c",
371
    },
372
    {
373
      .in  = & (struct hmac_data_in) {
374
        .key = {
375
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
376
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
377
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
378
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
379
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
380
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
381
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
382
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
383
        },
384
        .key_len = 80,
385
        .data = "Test Using Larger Than Block-Size Key - Hash Key First",
386
        .data_len = 54,
387
      },
388
      .out = "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd",
389
    },
390
    {
391
      .in  = & (struct hmac_data_in) {
392
        .key = {
393
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
394
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
395
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
396
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
397
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
398
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
399
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
400
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
401
        },
402
        .key_len = 80,
403
        .data = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
404
        .data_len = 73,
405
      },
406
      .out = "6f630fad67cda0ee1fb1f562db3aa53e",
407
    },
408
  };
409

    
410
  return bt_assert_batch(test_vectors, test_md5_hmac, hmac_in_fmt, bt_fmt_str);
411
}
412

    
413
static int
414
t_sha1_hmac(void)
415
{
416
  struct bt_pair test_vectors[] = {
417
    {
418
      .in  = & (struct hmac_data_in) {
419
        .key = {
420
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
421
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
422
        },
423
        .key_len = 20,
424
        .data = "Hi There",
425
        .data_len = 8,
426
      },
427
      .out = "b617318655057264e28bc0b6fb378c8ef146be00",
428
    },
429
    {
430
      .in  = & (struct hmac_data_in) {
431
        .key = "Jefe",
432
        .key_len = 4,
433
        .data = "what do ya want for nothing?",
434
        .data_len = 28,
435
      },
436
      .out = "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
437
    },
438
    {
439
      .in  = & (struct hmac_data_in) {
440
        .key = {
441
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
442
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
443
        },
444
        .key_len = 20,
445
        .data = {
446
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
447
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
448
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
449
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
450
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
451
        },
452
        .data_len = 50,
453
      },
454
      .out = "125d7342b9ac11cd91a39af48aa17b4f63f175d3",
455
    },
456
    {
457
      .in  = & (struct hmac_data_in) {
458
        .key = {
459
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
460
          0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
461
          0x15, 0x16, 0x17, 0x18, 0x19,
462
        },
463
        .key_len = 25,
464
        .data = {
465
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
466
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
467
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
468
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
469
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
470
        },
471
        .data_len = 50,
472
      },
473
      .out = "4c9007f4026250c6bc8414f9bf50c86c2d7235da",
474
    },
475
    {
476
      .in  = & (struct hmac_data_in) {
477
        .key = {
478
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
479
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
480
        },
481
        .key_len = 20,
482
        .data = "Test With Truncation",
483
        .data_len = 20,
484
      },
485
      .out = "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04",
486
    },
487
    {
488
      .in  = & (struct hmac_data_in) {
489
        .key = {
490
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
491
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
492
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
493
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
494
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
495
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
496
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
497
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
498
        },
499
        .key_len = 80,
500
        .data = "Test Using Larger Than Block-Size Key - Hash Key First",
501
        .data_len = 54,
502
      },
503
      .out = "aa4ae5e15272d00e95705637ce8a3b55ed402112",
504
    },
505
    {
506
      .in  = & (struct hmac_data_in) {
507
        .key = {
508
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
509
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
510
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
511
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
512
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
513
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
514
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
515
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
516
        },
517
        .key_len = 80,
518
        .data = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
519
        .data_len = 73,
520
      },
521
      .out = "e8e99d0f45237d786d6bbaa7965c7808bbff1a91",
522
    },
523
    {
524
      .in  = & (struct hmac_data_in) {
525
        .key = {
526
          0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
527
          0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
528
          0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
529
          0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
530
          0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
531
          0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
532
          0x61, 0x61, 0x61, 0x61,
533
        },
534
        .key_len = 64,
535
        .data = "Test Using key 64 bytes sized",
536
        .data_len = 29,
537
      },
538
      .out = "a55d4fb80962a6b3d2e720705314bee417d68cf6",
539
    },
540
  };
541

    
542
  return bt_assert_batch(test_vectors, test_sha1_hmac, hmac_in_fmt, bt_fmt_str);
543
}
544

    
545
static int
546
t_sha224_hmac(void)
547
{
548
  struct bt_pair test_vectors[] = {
549
    {
550
      .in  = & (struct hmac_data_in) {
551
        .key = {
552
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
553
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
554
        },
555
        .key_len = 20,
556
        .data = "Hi There",
557
        .data_len = 8,
558
      },
559
      .out = "896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22",
560
    },
561
    {
562
      .in  = & (struct hmac_data_in) {
563
        .key = "Jefe",
564
        .key_len = 4,
565
        .data = "what do ya want for nothing?",
566
        .data_len = 28,
567
      },
568
      .out = "a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44",
569
    },
570
    {
571
      .in  = & (struct hmac_data_in) {
572
        .key = {
573
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
574
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
575
        },
576
        .key_len = 20,
577
        .data = {
578
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
579
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
580
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
581
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
582
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
583
        },
584
        .data_len = 50,
585
      },
586
      .out = "7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea",
587
    },
588
    {
589
      .in  = & (struct hmac_data_in) {
590
        .key = {
591
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
592
          0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
593
          0x15, 0x16, 0x17, 0x18, 0x19,
594
        },
595
        .key_len = 25,
596
        .data = {
597
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
598
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
599
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
600
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
601
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
602
        },
603
        .data_len = 50,
604
      },
605
      .out = "6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a",
606
    },
607
    {
608
      .in  = & (struct hmac_data_in) {
609
        .key = {
610
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
611
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
612
        },
613
        .key_len = 20,
614
        .data = "Test With Truncation",
615
        .data_len = 20,
616
      },
617
      .out = "0e2aea68a90c8d37c988bcdb9fca6fa8099cd857c7ec4a1815cac54c",
618
    },
619
    {
620
      .in  = & (struct hmac_data_in) {
621
        .key = {
622
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
623
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
624
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
625
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
626
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
627
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
628
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
629
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
630
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
631
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
632
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
633
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
634
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
635
          0xaa,
636
        },
637
        .key_len = 131,
638
        .data = "Test Using Larger Than Block-Size Key - Hash Key First",
639
        .data_len = 54,
640
      },
641
      .out = "95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e",
642
    },
643
    {
644
      .in  = & (struct hmac_data_in) {
645
        .key = {
646
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
647
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
648
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
649
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
650
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
651
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
652
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
653
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
654
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
655
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
656
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
657
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
658
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
659
          0xaa,
660
        },
661
        .key_len = 131,
662
        .data = "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.",
663
        .data_len = 152,
664
      },
665
      .out = "3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1",
666
    },
667
  };
668

    
669
  return bt_assert_batch(test_vectors, test_sha224_hmac, hmac_in_fmt, bt_fmt_str);
670
}
671

    
672
static int
673
t_sha256_hmac(void)
674
{
675
  struct bt_pair test_vectors[] = {
676
    {
677
      .in  = & (struct hmac_data_in) {
678
        .key = {
679
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
680
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
681
        },
682
        .key_len = 20,
683
        .data = "Hi There",
684
        .data_len = 8,
685
      },
686
      .out = "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7",
687
    },
688
    {
689
      .in  = & (struct hmac_data_in) {
690
        .key = "Jefe",
691
        .key_len = 4,
692
        .data = "what do ya want for nothing?",
693
        .data_len = 28,
694
      },
695
      .out = "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843",
696
    },
697
    {
698
      .in  = & (struct hmac_data_in) {
699
        .key = {
700
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
701
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
702
        },
703
        .key_len = 20,
704
        .data = {
705
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
706
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
707
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
708
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
709
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
710
        },
711
        .data_len = 50,
712
      },
713
      .out = "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe",
714
    },
715
    {
716
      .in  = & (struct hmac_data_in) {
717
        .key = {
718
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
719
          0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
720
          0x15, 0x16, 0x17, 0x18, 0x19,
721
        },
722
        .key_len = 25,
723
        .data = {
724
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
725
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
726
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
727
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
728
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
729
        },
730
        .data_len = 50,
731
      },
732
      .out = "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b",
733
    },
734
    {
735
      .in  = & (struct hmac_data_in) {
736
        .key = {
737
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
738
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
739
        },
740
        .key_len = 20,
741
        .data = "Test With Truncation",
742
        .data_len = 20,
743
      },
744
      .out = "a3b6167473100ee06e0c796c2955552bfa6f7c0a6a8aef8b93f860aab0cd20c5",
745
    },
746
    {
747
      .in  = & (struct hmac_data_in) {
748
        .key = {
749
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
750
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
751
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
752
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
753
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
754
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
755
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
756
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
757
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
758
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
759
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
760
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
761
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
762
          0xaa,
763
        },
764
        .key_len = 131,
765
        .data = "Test Using Larger Than Block-Size Key - Hash Key First",
766
        .data_len = 54,
767
      },
768
      .out = "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54",
769
    },
770
    {
771
      .in  = & (struct hmac_data_in) {
772
        .key = {
773
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
774
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
775
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
776
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
777
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
778
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
779
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
780
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
781
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
782
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
783
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
784
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
785
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
786
          0xaa,
787
        },
788
        .key_len = 131,
789
        .data = "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.",
790
        .data_len = 152,
791
      },
792
      .out = "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2",
793
    },
794
  };
795

    
796
  return bt_assert_batch(test_vectors, test_sha256_hmac, hmac_in_fmt, bt_fmt_str);
797
}
798

    
799
static int
800
t_sha384_hmac(void)
801
{
802
  struct bt_pair test_vectors[] = {
803
    {
804
      .in  = & (struct hmac_data_in) {
805
        .key = {
806
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
807
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
808
        },
809
        .key_len = 20,
810
        .data = "Hi There",
811
        .data_len = 8,
812
      },
813
      .out = "afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6",
814
    },
815
    {
816
      .in  = & (struct hmac_data_in) {
817
        .key = "Jefe",
818
        .key_len = 4,
819
        .data = "what do ya want for nothing?",
820
        .data_len = 28,
821
      },
822
      .out = "af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649",
823
    },
824
    {
825
      .in  = & (struct hmac_data_in) {
826
        .key = {
827
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
828
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
829
        },
830
        .key_len = 20,
831
        .data = {
832
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
833
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
834
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
835
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
836
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
837
        },
838
        .data_len = 50,
839
      },
840
      .out = "88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27",
841
    },
842
    {
843
      .in  = & (struct hmac_data_in) {
844
        .key = {
845
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
846
          0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
847
          0x15, 0x16, 0x17, 0x18, 0x19,
848
        },
849
        .key_len = 25,
850
        .data = {
851
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
852
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
853
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
854
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
855
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
856
        },
857
        .data_len = 50,
858
      },
859
      .out = "3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb",
860
    },
861
    {
862
      .in  = & (struct hmac_data_in) {
863
        .key = {
864
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
865
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
866
        },
867
        .key_len = 20,
868
        .data = "Test With Truncation",
869
        .data_len = 20,
870
      },
871
      .out = "3abf34c3503b2a23a46efc619baef897f4c8e42c934ce55ccbae9740fcbc1af4ca62269e2a37cd88ba926341efe4aeea",
872
    },
873
    {
874
      .in  = & (struct hmac_data_in) {
875
        .key = {
876
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
877
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
878
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
879
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
880
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
881
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
882
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
883
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
884
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
885
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
886
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
887
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
888
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
889
          0xaa,
890
        },
891
        .key_len = 131,
892
        .data = "Test Using Larger Than Block-Size Key - Hash Key First",
893
        .data_len = 54,
894
      },
895
      .out = "4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05033ac4c60c2ef6ab4030fe8296248df163f44952",
896
    },
897
    {
898
      .in  = & (struct hmac_data_in) {
899
        .key = {
900
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
901
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
902
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
903
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
904
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
905
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
906
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
907
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
908
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
909
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
910
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
911
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
912
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
913
          0xaa,
914
        },
915
        .key_len = 131,
916
        .data = "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.",
917
        .data_len = 152,
918
      },
919
      .out = "6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82461e99c5a678cc31e799176d3860e6110c46523e",
920
    },
921
  };
922

    
923
  return bt_assert_batch(test_vectors, test_sha384_hmac, hmac_in_fmt, bt_fmt_str);
924
}
925

    
926
static int
927
t_sha512_hmac(void)
928
{
929
  struct bt_pair test_vectors[] = {
930
    {
931
      .in  = & (struct hmac_data_in) {
932
        .key = {
933
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
934
          0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
935
        },
936
        .key_len = 20,
937
        .data = "Hi There",
938
        .data_len = 8,
939
      },
940
      .out = "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854",
941
    },
942
    {
943
      .in  = & (struct hmac_data_in) {
944
        .key = "Jefe",
945
        .key_len = 4,
946
        .data = "what do ya want for nothing?",
947
        .data_len = 28,
948
      },
949
      .out = "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737",
950
    },
951
    {
952
      .in  = & (struct hmac_data_in) {
953
        .key = {
954
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
955
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
956
        },
957
        .key_len = 20,
958
        .data = {
959
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
960
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
961
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
962
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
963
          0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
964
        },
965
        .data_len = 50,
966
      },
967
      .out = "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb",
968
    },
969
    {
970
      .in  = & (struct hmac_data_in) {
971
        .key = {
972
          0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
973
          0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
974
          0x15, 0x16, 0x17, 0x18, 0x19,
975
        },
976
        .key_len = 25,
977
        .data = {
978
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
979
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
980
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
981
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
982
          0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
983
        },
984
        .data_len = 50,
985
      },
986
      .out = "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd",
987
    },
988
    {
989
      .in  = & (struct hmac_data_in) {
990
        .key = {
991
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
992
          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
993
        },
994
        .key_len = 20,
995
        .data = "Test With Truncation",
996
        .data_len = 20,
997
      },
998
      .out = "415fad6271580a531d4179bc891d87a650188707922a4fbb36663a1eb16da008711c5b50ddd0fc235084eb9d3364a1454fb2ef67cd1d29fe6773068ea266e96b",
999
    },
1000
    {
1001
      .in  = & (struct hmac_data_in) {
1002
        .key = {
1003
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1004
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1005
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1006
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1007
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1008
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1009
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1010
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1011
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1012
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1013
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1014
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1015
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1016
          0xaa,
1017
        },
1018
        .key_len = 131,
1019
        .data = "Test Using Larger Than Block-Size Key - Hash Key First",
1020
        .data_len = 54,
1021
      },
1022
      .out = "80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598",
1023
    },
1024
    {
1025
      .in  = & (struct hmac_data_in) {
1026
        .key = {
1027
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1028
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1029
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1030
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1031
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1032
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1033
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1034
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1035
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1036
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1037
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1038
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1039
          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
1040
          0xaa,
1041
        },
1042
        .key_len = 131,
1043
        .data = "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.",
1044
        .data_len = 152,
1045
      },
1046
      .out = "e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58",
1047
    },
1048
  };
1049

    
1050
  return bt_assert_batch(test_vectors, test_sha512_hmac, hmac_in_fmt, bt_fmt_str);
1051
}
1052

    
1053

    
1054
/*
1055
 * Testing SHAxxx concating independence
1056
 */
1057

    
1058
#include "lib/sha256.h"
1059
#include "lib/sha512.h"
1060

    
1061
static int
1062
t_sha256_concating(void)
1063
{
1064
  char hash_a[SHA256_HEX_SIZE];
1065
  char hash_b[SHA256_HEX_SIZE];
1066

    
1067
  char *str_a  = "a" "bb" "ccc" "dddd" "eeeee" "ffffff";
1068
  char *str_b1 = "a"                                   ;
1069
  char *str_b2 =     "bb"                              ;
1070
  char *str_b3 =          "ccc"                        ;
1071
  char *str_b4 =                "dddd"                 ;
1072
  char *str_b5 =                       "eeeee"         ;
1073
  char *str_b6 =                               "ffffff";
1074

    
1075
  struct hash_context ctx_a;
1076
  sha256_init(&ctx_a);
1077
  sha256_update(&ctx_a, str_a, strlen(str_a));
1078
  byte *hash_a_ = sha256_final(&ctx_a);
1079
  bt_bytes_to_hex(hash_a, hash_a_, SHA256_SIZE);
1080

    
1081
  struct hash_context ctx_b;
1082
  sha256_init(&ctx_b);
1083
  sha256_update(&ctx_b, str_b1, strlen(str_b1));
1084
  sha256_update(&ctx_b, str_b2, strlen(str_b2));
1085
  sha256_update(&ctx_b, str_b3, strlen(str_b3));
1086
  sha256_update(&ctx_b, str_b4, strlen(str_b4));
1087
  sha256_update(&ctx_b, str_b5, strlen(str_b5));
1088
  sha256_update(&ctx_b, str_b6, strlen(str_b6));
1089
  byte *hash_b_ = sha256_final(&ctx_b);
1090
  bt_bytes_to_hex(hash_b, hash_b_, SHA256_SIZE);
1091

    
1092
  int are_hash_a_b_equal = (strncmp(hash_a, hash_b, sizeof(hash_a)) == 0);
1093
  bt_assert_msg(are_hash_a_b_equal, "Hashes A: %s, B: %s should be same", hash_a, hash_b);
1094

    
1095
  return 1;
1096
}
1097

    
1098

    
1099
static int
1100
t_sha512_concating(void)
1101
{
1102
  char hash_a[SHA512_HEX_SIZE];
1103
  char hash_b[SHA512_HEX_SIZE];
1104

    
1105
  char *str_a  = "a" "bb" "ccc" "dddd" "eeeee" "ffffff";
1106
  char *str_b1 = "a"                                   ;
1107
  char *str_b2 =     "bb"                              ;
1108
  char *str_b3 =          "ccc"                        ;
1109
  char *str_b4 =                "dddd"                 ;
1110
  char *str_b5 =                       "eeeee"         ;
1111
  char *str_b6 =                               "ffffff";
1112

    
1113
  struct hash_context ctx_a;
1114
  sha512_init(&ctx_a);
1115
  sha512_update(&ctx_a, str_a, strlen(str_a));
1116
  byte *hash_a_ = sha512_final(&ctx_a);
1117
  bt_bytes_to_hex(hash_a, hash_a_, SHA512_SIZE);
1118

    
1119
  struct hash_context ctx_b;
1120
  sha512_init(&ctx_b);
1121
  sha512_update(&ctx_b, str_b1, strlen(str_b1));
1122
  sha512_update(&ctx_b, str_b2, strlen(str_b2));
1123
  sha512_update(&ctx_b, str_b3, strlen(str_b3));
1124
  sha512_update(&ctx_b, str_b4, strlen(str_b4));
1125
  sha512_update(&ctx_b, str_b5, strlen(str_b5));
1126
  sha512_update(&ctx_b, str_b6, strlen(str_b6));
1127
  byte *hash_b_ = sha512_final(&ctx_b);
1128
  bt_bytes_to_hex(hash_b, hash_b_, SHA512_SIZE);
1129

    
1130
  int are_hash_a_b_equal = (strncmp(hash_a, hash_b, sizeof(hash_a)) == 0);
1131
  bt_assert_msg(are_hash_a_b_equal, "Hashes A: %s, B: %s should be same", hash_a, hash_b);
1132

    
1133
  return 1;
1134
}
1135

    
1136
int
1137
main(int argc, char *argv[])
1138
{
1139
  bt_init(argc, argv);
1140

    
1141
  bt_test_suite(t_md5,    "Testing MD5 by RFC 1321");
1142
  bt_test_suite(t_sha1,   "Testing SHA-1");
1143
  bt_test_suite(t_sha224, "Testing SHA-224");
1144
  bt_test_suite(t_sha256, "Testing SHA-256");
1145
  bt_test_suite(t_sha384, "Testing SHA-384");
1146
  bt_test_suite(t_sha512, "Testing SHA-512");
1147

    
1148
  bt_test_suite(t_md5_hmac, "Testing HMAC-MD5 by RFC 2202");
1149
  bt_test_suite(t_sha1_hmac,   "Testing HMAC-SHA-1 by RFC 2202");
1150
  bt_test_suite(t_sha224_hmac, "Testing HMAC-SHA-224 by RFC 4231");
1151
  bt_test_suite(t_sha256_hmac, "Testing HMAC-SHA-256 by RFC 4231");
1152
  bt_test_suite(t_sha384_hmac, "Testing HMAC-SHA-384 by RFC 4231");
1153
  bt_test_suite(t_sha512_hmac, "Testing HMAC-SHA-512 by RFC 4231");
1154

    
1155
  bt_test_suite(t_sha256_concating, "Testing concatenation input string to hash using sha256_update");
1156
  bt_test_suite(t_sha512_concating, "Testing concatenation input string to hash using sha512_update");
1157

    
1158
  return bt_exit_value();
1159
}