• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/libgcrypt-1.5.1/tests/
1/* t-kdf.c -  KDF regression tests
2 * Copyright (C) 2011 Free Software Foundation, Inc.
3 *
4 * This file is part of Libgcrypt.
5 *
6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 */
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdarg.h>
28#include <assert.h>
29
30#include "../src/gcrypt.h"
31
32#ifndef DIM
33# define DIM(v)		     (sizeof(v)/sizeof((v)[0]))
34#endif
35
36/* Program option flags.  */
37static int verbose;
38static int error_count;
39
40static void
41fail (const char *format, ...)
42{
43  va_list arg_ptr;
44
45  va_start (arg_ptr, format);
46  vfprintf (stderr, format, arg_ptr);
47  va_end (arg_ptr);
48  error_count++;
49}
50
51static void
52die (const char *format, ...)
53{
54  va_list arg_ptr;
55
56  va_start (arg_ptr, format);
57  vfprintf (stderr, format, arg_ptr);
58  va_end (arg_ptr);
59  exit (1);
60}
61
62
63static void
64check_openpgp (void)
65{
66  /* Test vectors manually created with gpg 1.4 derived code: In
67     passphrase.c:hash_passpharse, add this code to the end of the
68     function:
69
70       ===8<===
71       printf ("{\n"
72               "  \"");
73       for (i=0; i < pwlen; i++)
74         {
75           if (i && !(i%16))
76             printf ("\"\n  \"");
77           printf ("\\x%02x", ((const unsigned char *)pw)[i]);
78         }
79       printf ("\", %d,\n", pwlen);
80
81       printf ("  %s, %s,\n",
82               s2k->mode == 0? "GCRY_KDF_SIMPLE_S2K":
83               s2k->mode == 1? "GCRY_KDF_SALTED_S2K":
84               s2k->mode == 3? "GCRY_KDF_ITERSALTED_S2K":"?",
85               s2k->hash_algo == DIGEST_ALGO_MD5   ? "GCRY_MD_MD5" :
86               s2k->hash_algo == DIGEST_ALGO_SHA1  ? "GCRY_MD_SHA1" :
87               s2k->hash_algo == DIGEST_ALGO_RMD160? "GCRY_MD_RMD160" :
88               s2k->hash_algo == DIGEST_ALGO_SHA256? "GCRY_MD_SHA256" :
89               s2k->hash_algo == DIGEST_ALGO_SHA384? "GCRY_MD_SHA384" :
90               s2k->hash_algo == DIGEST_ALGO_SHA512? "GCRY_MD_SHA512" :
91               s2k->hash_algo == DIGEST_ALGO_SHA224? "GCRY_MD_SHA224" : "?");
92
93       if (s2k->mode == 0)
94         printf ("  NULL, 0,\n");
95       else
96         {
97           printf ("  \"");
98           for (i=0; i < 8; i++)
99             printf ("\\x%02x", (unsigned int)s2k->salt[i]);
100           printf ("\", %d,\n", 8);
101         }
102
103       if (s2k->mode == 3)
104         printf ("  %lu,\n", (unsigned long)S2K_DECODE_COUNT(s2k->count));
105       else
106         printf ("  0,\n");
107
108       printf ("  %d,\n", (int)dek->keylen);
109
110       printf ("  \"");
111       for (i=0; i < dek->keylen; i++)
112         {
113           if (i && !(i%16))
114             printf ("\"\n  \"");
115           printf ("\\x%02x", ((unsigned char *)dek->key)[i]);
116         }
117       printf ("\"\n},\n");
118       ===>8===
119
120     Then prepare a file x.inp with utf8 encoding:
121
122       ===8<===
123       0 aes    md5 1024 a
124       0 aes    md5 1024 ab
125       0 aes    md5 1024 abc
126       0 aes    md5 1024 abcd
127       0 aes    md5 1024 abcde
128       0 aes    md5 1024 abcdef
129       0 aes    md5 1024 abcdefg
130       0 aes    md5 1024 abcdefgh
131       0 aes    md5 1024 abcdefghi
132       0 aes    md5 1024 abcdefghijklmno
133       0 aes    md5 1024 abcdefghijklmnop
134       0 aes    md5 1024 abcdefghijklmnopq
135       0 aes    md5 1024 Long_sentence_used_as_passphrase
136       0 aes    md5 1024 With_utf8_umlauts:��������
137       0 aes    sha1 1024 a
138       0 aes    sha1 1024 ab
139       0 aes    sha1 1024 abc
140       0 aes    sha1 1024 abcd
141       0 aes    sha1 1024 abcde
142       0 aes    sha1 1024 abcdef
143       0 aes    sha1 1024 abcdefg
144       0 aes    sha1 1024 abcdefgh
145       0 aes    sha1 1024 abcdefghi
146       0 aes    sha1 1024 abcdefghijklmno
147       0 aes    sha1 1024 abcdefghijklmnop
148       0 aes    sha1 1024 abcdefghijklmnopq
149       0 aes    sha1 1024 abcdefghijklmnopqr
150       0 aes    sha1 1024 abcdefghijklmnopqrs
151       0 aes    sha1 1024 abcdefghijklmnopqrst
152       0 aes    sha1 1024 abcdefghijklmnopqrstu
153       0 aes    sha1 1024 Long_sentence_used_as_passphrase
154       0 aes256 sha1 1024 Long_sentence_used_as_passphrase
155       0 aes    sha1 1024 With_utf8_umlauts:��������
156       3 aes    sha1 1024 a
157       3 aes    sha1 1024 ab
158       3 aes    sha1 1024 abc
159       3 aes    sha1 1024 abcd
160       3 aes    sha1 1024 abcde
161       3 aes    sha1 1024 abcdef
162       3 aes    sha1 1024 abcdefg
163       3 aes    sha1 1024 abcdefgh
164       3 aes    sha1 1024 abcdefghi
165       3 aes    sha1 1024 abcdefghijklmno
166       3 aes    sha1 1024 abcdefghijklmnop
167       3 aes    sha1 1024 abcdefghijklmnopq
168       3 aes    sha1 1024 abcdefghijklmnopqr
169       3 aes    sha1 1024 abcdefghijklmnopqrs
170       3 aes    sha1 1024 abcdefghijklmnopqrst
171       3 aes    sha1 1024 abcdefghijklmnopqrstu
172       3 aes    sha1 1024 With_utf8_umlauts:��������
173       3 aes    sha1 1024 Long_sentence_used_as_passphrase
174       3 aes    sha1 10240 Long_sentence_used_as_passphrase
175       3 aes    sha1 102400 Long_sentence_used_as_passphrase
176       3 aes192 sha1 1024 a
177       3 aes192 sha1 1024 abcdefg
178       3 aes192 sha1 1024 abcdefghi
179       3 aes192 sha1 1024 abcdefghi
180       3 aes192 sha1 1024 Long_sentence_used_as_passphrase
181       3 aes256 sha1 1024 a
182       3 aes256 sha1 1024 abcdefg
183       3 aes256 sha1 1024 abcdefghi
184       3 aes256 sha1 1024 abcdefghi
185       3 aes256 sha1 1024 Long_sentence_used_as_passphrase
186       0 aes    sha256 1024 Long_sentence_used_as_passphrase
187       1 aes    sha256 1024 Long_sentence_used_as_passphrase
188       3 aes    sha256 1024 Long_sentence_used_as_passphrase
189       3 aes    sha256 10240 Long_sentence_used_as_passphrase
190       3 aes    sha384 1024 Long_sentence_used_as_passphrase
191       3 aes    sha512 1024 Long_sentence_used_as_passphrase
192       3 aes256 sha512 1024 Long_sentence_used_as_passphrase
193       3 3des   sha512 1024 Long_sentence_used_as_passphrase
194       ===>8===
195
196    and finally using a proper utf-8 enabled shell, run:
197
198       cat x.inp | while read mode cipher digest count pass dummy; do \
199         ./gpg </dev/null -o /dev/null -c  --passphrase "$pass" \
200           --s2k-mode $mode --s2k-digest $digest --s2k-count $count \
201           --cipher-algo $cipher ; done >x.out
202  */
203  static struct {
204    const char *p;   /* Passphrase.  */
205    size_t plen;     /* Length of P. */
206    int algo;
207    int hashalgo;
208    const char *salt;
209    size_t saltlen;
210    unsigned long c; /* Iterations.  */
211    int dklen;       /* Requested key length.  */
212    const char *dk;  /* Derived key.  */
213    int disabled;
214  } tv[] = {
215    {
216      "\x61", 1,
217      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
218      NULL, 0,
219      0,
220      16,
221      "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61"
222    },
223    {
224      "\x61\x62", 2,
225      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
226      NULL, 0,
227      0,
228      16,
229      "\x18\x7e\xf4\x43\x61\x22\xd1\xcc\x2f\x40\xdc\x2b\x92\xf0\xeb\xa0"
230    },
231    {
232      "\x61\x62\x63", 3,
233      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
234      NULL, 0,
235      0,
236      16,
237      "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
238    },
239    {
240      "\x61\x62\x63\x64", 4,
241      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
242      NULL, 0,
243      0,
244      16,
245      "\xe2\xfc\x71\x4c\x47\x27\xee\x93\x95\xf3\x24\xcd\x2e\x7f\x33\x1f"
246    },
247    {
248      "\x61\x62\x63\x64\x65", 5,
249      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
250      NULL, 0,
251      0,
252      16,
253      "\xab\x56\xb4\xd9\x2b\x40\x71\x3a\xcc\x5a\xf8\x99\x85\xd4\xb7\x86"
254    },
255    {
256      "\x61\x62\x63\x64\x65\x66", 6,
257      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
258      NULL, 0,
259      0,
260      16,
261      "\xe8\x0b\x50\x17\x09\x89\x50\xfc\x58\xaa\xd8\x3c\x8c\x14\x97\x8e"
262    },
263    {
264      "\x61\x62\x63\x64\x65\x66\x67", 7,
265      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
266      NULL, 0,
267      0,
268      16,
269      "\x7a\xc6\x6c\x0f\x14\x8d\xe9\x51\x9b\x8b\xd2\x64\x31\x2c\x4d\x64"
270    },
271    {
272      "\x61\x62\x63\x64\x65\x66\x67\x68", 8,
273      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
274      NULL, 0,
275      0,
276      16,
277      "\xe8\xdc\x40\x81\xb1\x34\x34\xb4\x51\x89\xa7\x20\xb7\x7b\x68\x18"
278    },
279    {
280      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
281      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
282      NULL, 0,
283      0,
284      16,
285      "\x8a\xa9\x9b\x1f\x43\x9f\xf7\x12\x93\xe9\x53\x57\xba\xc6\xfd\x94"
286    },
287    {
288      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f", 15,
289      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
290      NULL, 0,
291      0,
292      16,
293      "\x8a\x73\x19\xdb\xf6\x54\x4a\x74\x22\xc9\xe2\x54\x52\x58\x0e\xa5"
294    },
295    {
296      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70", 16,
297      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
298      NULL, 0,
299      0,
300      16,
301      "\x1d\x64\xdc\xe2\x39\xc4\x43\x7b\x77\x36\x04\x1d\xb0\x89\xe1\xb9"
302    },
303    {
304      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
305      "\x71", 17,
306      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
307      NULL, 0,
308      0,
309      16,
310      "\x9a\x8d\x98\x45\xa6\xb4\xd8\x2d\xfc\xb2\xc2\xe3\x51\x62\xc8\x30"
311    },
312    {
313      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
314      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
315      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
316      NULL, 0,
317      0,
318      16,
319      "\x35\x2a\xf0\xfc\xdf\xe9\xbb\x62\x16\xfc\x99\x9d\x8d\x58\x05\xcb"
320    },
321    {
322      "\x57\x69\x74\x68\x5f\x75\x74\x66\x38\x5f\x75\x6d\x6c\x61\x75\x74"
323      "\x73\x3a\xc3\xa4\xc3\xbc\xc3\x96\xc3\x9f", 26,
324      GCRY_KDF_SIMPLE_S2K, GCRY_MD_MD5,
325      NULL, 0,
326      0,
327      16,
328      "\x21\xa4\xeb\xd8\xfd\xf0\x59\x25\xd1\x32\x31\xdb\xe7\xf2\x13\x5d"
329    },
330    {
331      "\x61", 1,
332      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
333      NULL, 0,
334      0,
335      16,
336      "\x86\xf7\xe4\x37\xfa\xa5\xa7\xfc\xe1\x5d\x1d\xdc\xb9\xea\xea\xea"
337    },
338    {
339      "\x61\x62", 2,
340      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
341      NULL, 0,
342      0,
343      16,
344      "\xda\x23\x61\x4e\x02\x46\x9a\x0d\x7c\x7b\xd1\xbd\xab\x5c\x9c\x47"
345    },
346    {
347      "\x61\x62\x63", 3,
348      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
349      NULL, 0,
350      0,
351      16,
352      "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e\x25\x71\x78\x50\xc2\x6c"
353    },
354    {
355      "\x61\x62\x63\x64", 4,
356      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
357      NULL, 0,
358      0,
359      16,
360      "\x81\xfe\x8b\xfe\x87\x57\x6c\x3e\xcb\x22\x42\x6f\x8e\x57\x84\x73"
361    },
362    {
363      "\x61\x62\x63\x64\x65", 5,
364      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
365      NULL, 0,
366      0,
367      16,
368      "\x03\xde\x6c\x57\x0b\xfe\x24\xbf\xc3\x28\xcc\xd7\xca\x46\xb7\x6e"
369    },
370    {
371      "\x61\x62\x63\x64\x65\x66", 6,
372      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
373      NULL, 0,
374      0,
375      16,
376      "\x1f\x8a\xc1\x0f\x23\xc5\xb5\xbc\x11\x67\xbd\xa8\x4b\x83\x3e\x5c"
377    },
378    {
379      "\x61\x62\x63\x64\x65\x66\x67", 7,
380      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
381      NULL, 0,
382      0,
383      16,
384      "\x2f\xb5\xe1\x34\x19\xfc\x89\x24\x68\x65\xe7\xa3\x24\xf4\x76\xec"
385    },
386    {
387      "\x61\x62\x63\x64\x65\x66\x67\x68", 8,
388      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
389      NULL, 0,
390      0,
391      16,
392      "\x42\x5a\xf1\x2a\x07\x43\x50\x2b\x32\x2e\x93\xa0\x15\xbc\xf8\x68"
393    },
394    {
395      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
396      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
397      NULL, 0,
398      0,
399      16,
400      "\xc6\x3b\x19\xf1\xe4\xc8\xb5\xf7\x6b\x25\xc4\x9b\x8b\x87\xf5\x7d"
401    },
402    {
403      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f", 15,
404      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
405      NULL, 0,
406      0,
407      16,
408      "\x29\x38\xdc\xc2\xe3\xaa\x77\x98\x7c\x7e\x5d\x4a\x0f\x26\x96\x67"
409    },
410    {
411      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70", 16,
412      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
413      NULL, 0,
414      0,
415      16,
416      "\x14\xf3\x99\x52\x88\xac\xd1\x89\xe6\xe5\x0a\x7a\xf4\x7e\xe7\x09"
417    },
418    {
419      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
420      "\x71", 17,
421      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
422      NULL, 0,
423      0,
424      16,
425      "\xd8\x3d\x62\x1f\xcd\x2d\x4d\x29\x85\x54\x70\x43\xa7\xa5\xfd\x4d"
426    },
427    {
428      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
429      "\x71\x72", 18,
430      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
431      NULL, 0,
432      0,
433      16,
434      "\xe3\x81\xfe\x42\xc5\x7e\x48\xa0\x82\x17\x86\x41\xef\xfd\x1c\xb9"
435    },
436    {
437      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
438      "\x71\x72\x73", 19,
439      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
440      NULL, 0,
441      0,
442      16,
443      "\x89\x3e\x69\xff\x01\x09\xf3\x45\x9c\x42\x43\x01\x3b\x3d\xe8\xb1"
444    },
445    {
446      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
447      "\x71\x72\x73\x74", 20,
448      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
449      NULL, 0,
450      0,
451      16,
452      "\x14\xa2\x3a\xd7\x0f\x2a\x5d\xd7\x25\x57\x5d\xe6\xc4\x3e\x1c\xdd"
453    },
454    {
455      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
456      "\x71\x72\x73\x74\x75", 21,
457      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
458      NULL, 0,
459      0,
460      16,
461      "\xec\xa9\x86\xb9\x5d\x58\x7f\x34\xd7\x1c\xa7\x75\x2a\x4e\x00\x10"
462    },
463    {
464      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
465      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
466      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
467      NULL, 0,
468      0,
469      16,
470      "\x3e\x1b\x9a\x50\x7d\x6e\x9a\xd8\x93\x64\x96\x7a\x3f\xcb\x27\x3f"
471    },
472    {
473      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
474      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
475      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
476      NULL, 0,
477      0,
478      32,
479      "\x3e\x1b\x9a\x50\x7d\x6e\x9a\xd8\x93\x64\x96\x7a\x3f\xcb\x27\x3f"
480      "\xc3\x7b\x3a\xb2\xef\x4d\x68\xaa\x9c\xd7\xe4\x88\xee\xd1\x5e\x70"
481    },
482    {
483      "\x57\x69\x74\x68\x5f\x75\x74\x66\x38\x5f\x75\x6d\x6c\x61\x75\x74"
484      "\x73\x3a\xc3\xa4\xc3\xbc\xc3\x96\xc3\x9f", 26,
485      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA1,
486      NULL, 0,
487      0,
488      16,
489      "\xe0\x4e\x1e\xe3\xad\x0b\x49\x7c\x7a\x5f\x37\x3b\x4d\x90\x3c\x2e"
490    },
491    {
492      "\x61", 1,
493      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
494      "\x6d\x47\xe3\x68\x5d\x2c\x36\x16", 8,
495      1024,
496      16,
497      "\x41\x9f\x48\x6e\xbf\xe6\xdd\x05\x9a\x72\x23\x17\x44\xd8\xd3\xf3"
498    },
499    {
500      "\x61\x62", 2,
501      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
502      "\x7c\x34\x78\xfb\x28\x2d\x25\xc7", 8,
503      1024,
504      16,
505      "\x0a\x9d\x09\x06\x43\x3d\x4f\xf9\x87\xd6\xf7\x48\x90\xde\xd1\x1c"
506    },
507    {
508      "\x61\x62\x63", 3,
509      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
510      "\xc3\x16\x37\x2e\x27\xf6\x9f\x6f", 8,
511      1024,
512      16,
513      "\xf8\x27\xa0\x07\xc6\xcb\xdd\xf1\xfe\x5c\x88\x3a\xfc\xcd\x84\x4d"
514    },
515    {
516      "\x61\x62\x63\x64", 4,
517      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
518      "\xf0\x0c\x73\x38\xb7\xc3\xd5\x14", 8,
519      1024,
520      16,
521      "\x9b\x5f\x26\xba\x52\x3b\xcd\xd9\xa5\x2a\xef\x3c\x03\x4d\xd1\x52"
522    },
523    {
524      "\x61\x62\x63\x64\x65", 5,
525      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
526      "\xe1\x7d\xa2\x36\x09\x59\xee\xc5", 8,
527      1024,
528      16,
529      "\x94\x9d\x5b\x1a\x5a\x66\x8c\xfa\x8f\x6f\x22\xaf\x8b\x60\x9f\xaf"
530    },
531    {
532      "\x61\x62\x63\x64\x65\x66", 6,
533      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
534      "\xaf\xa7\x0c\x68\xdf\x7e\xaa\x27", 8,
535      1024,
536      16,
537      "\xe5\x38\xf4\x39\x62\x27\xcd\xcc\x91\x37\x7f\x1b\xdc\x58\x64\x27"
538    },
539    {
540      "\x61\x62\x63\x64\x65\x66\x67", 7,
541      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
542      "\x40\x57\xb2\x9d\x5f\xbb\x11\x4f", 8,
543      1024,
544      16,
545      "\xad\xa2\x33\xd9\xdd\xe0\xfb\x94\x8e\xcc\xec\xcc\xb3\xa8\x3a\x9e"
546    },
547    {
548      "\x61\x62\x63\x64\x65\x66\x67\x68", 8,
549      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
550      "\x38\xf5\x65\xc5\x0f\x8c\x19\x61", 8,
551      1024,
552      16,
553      "\xa0\xb0\x3e\x29\x76\xe6\x8f\xa0\xd8\x34\x8f\xa4\x2d\xfd\x65\xee"
554    },
555    {
556      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
557      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
558      "\xc3\xb7\x99\xcc\xda\x2d\x05\x7b", 8,
559      1024,
560      16,
561      "\x27\x21\xc8\x99\x5f\xcf\x20\xeb\xf2\xd9\xff\x6a\x69\xff\xad\xe8"
562    },
563    {
564      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f", 15,
565      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
566      "\x7d\xd8\x68\x8a\x1c\xc5\x47\x22", 8,
567      1024,
568      16,
569      "\x0f\x96\x7a\x12\x23\x54\xf6\x92\x61\x67\x07\xb4\x68\x17\xb8\xaa"
570    },
571    {
572      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70", 16,
573      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
574      "\x8a\x95\xd4\x88\x0b\xb8\xe9\x9d", 8,
575      1024,
576      16,
577      "\xcc\xe4\xc8\x82\x53\x32\xf1\x93\x5a\x00\xd4\x7f\xd4\x46\xfa\x07"
578    },
579    {
580      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
581      "\x71", 17,
582      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
583      "\xb5\x22\x48\xa6\xc4\xad\x74\x67", 8,
584      1024,
585      16,
586      "\x0c\xe3\xe0\xee\x3d\x8f\x35\xd2\x35\x14\x14\x29\x0c\xf1\xe3\x34"
587    },
588    {
589      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
590      "\x71\x72", 18,
591      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
592      "\xac\x9f\x04\x63\x83\x0e\x3c\x95", 8,
593      1024,
594      16,
595      "\x49\x0a\x04\x68\xa8\x2a\x43\x6f\xb9\x73\x94\xb4\x85\x9a\xaa\x0e"
596    },
597    {
598      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
599      "\x71\x72\x73", 19,
600      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
601      "\x03\x6f\x60\x30\x3a\x19\x61\x0d", 8,
602      1024,
603      16,
604      "\x15\xe5\x9b\xbf\x1c\xf0\xbe\x74\x95\x1a\xb2\xc4\xda\x09\xcd\x99"
605    },
606    {
607      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
608      "\x71\x72\x73\x74", 20,
609      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
610      "\x51\x40\xa5\x57\xf5\x28\xfd\x03", 8,
611      1024,
612      16,
613      "\xa6\xf2\x7e\x6b\x30\x4d\x8d\x67\xd4\xa2\x7f\xa2\x57\x27\xab\x96"
614    },
615    {
616      "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
617      "\x71\x72\x73\x74\x75", 21,
618      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
619      "\x4c\xf1\x10\x11\x04\x70\xd3\x6e", 8,
620      1024,
621      16,
622      "\x2c\x50\x79\x8d\x83\x23\xac\xd6\x22\x29\x37\xaf\x15\x0d\xdd\x8f"
623    },
624    {
625      "\x57\x69\x74\x68\x5f\x75\x74\x66\x38\x5f\x75\x6d\x6c\x61\x75\x74"
626      "\x73\x3a\xc3\xa4\xc3\xbc\xc3\x96\xc3\x9f", 26,
627      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
628      "\xfe\x3a\x25\xcb\x78\xef\xe1\x21", 8,
629      1024,
630      16,
631      "\x2a\xb0\x53\x08\xf3\x2f\xd4\x6e\xeb\x01\x49\x5d\x87\xf6\x27\xf6"
632    },
633    {
634      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
635      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
636      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
637      "\x04\x97\xd0\x02\x6a\x44\x2d\xde", 8,
638      1024,
639      16,
640      "\x57\xf5\x70\x41\xa0\x9b\x8c\x09\xca\x74\xa9\x22\xa5\x82\x2d\x17"
641    },
642    {
643      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
644      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
645      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
646      "\xdd\xf3\x31\x7c\xce\xf4\x81\x26", 8,
647      10240,
648      16,
649      "\xc3\xdd\x01\x6d\xaf\xf6\x58\xc8\xd7\x79\xb4\x40\x00\xb5\xe8\x0b"
650    },
651    {
652      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
653      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
654      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
655      "\x95\xd6\x72\x4e\xfb\xe1\xc3\x1a", 8,
656      102400,
657      16,
658      "\xf2\x3f\x36\x7f\xb4\x6a\xd0\x3a\x31\x9e\x65\x11\x8e\x2b\x99\x9b"
659    },
660    {
661      "\x61", 1,
662      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
663      "\x6d\x69\x15\x18\xe4\x13\x42\x82", 8,
664      1024,
665      24,
666      "\x28\x0c\x7e\xf2\x31\xf6\x1c\x6b\x5c\xef\x6a\xd5\x22\x64\x97\x91"
667      "\xe3\x5e\x37\xfd\x50\xe2\xfc\x6c"
668    },
669    {
670      "\x61\x62\x63\x64\x65\x66\x67", 7,
671      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
672      "\x9b\x76\x5e\x81\xde\x13\xdf\x15", 8,
673      1024,
674      24,
675      "\x91\x1b\xa1\xc1\x7b\x4f\xc3\xb1\x80\x61\x26\x08\xbe\x53\xe6\x50"
676      "\x40\x6f\x28\xed\xc6\xe6\x67\x55"
677    },
678    {
679      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
680      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
681      "\x7a\xac\xcc\x6e\x15\x56\xbd\xa1", 8,
682      1024,
683      24,
684      "\xfa\x7e\x20\x07\xb6\x47\xb0\x09\x46\xb8\x38\xfb\xa1\xaf\xf7\x75"
685      "\x2a\xfa\x77\x14\x06\x54\xcb\x34"
686    },
687    {
688      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
689      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
690      "\x1c\x68\xf8\xfb\x98\xf7\x8c\x39", 8,
691      1024,
692      24,
693      "\xcb\x1e\x86\xf5\xe0\xe4\xfb\xbf\x71\x34\x99\x24\xf4\x39\x8c\xc2"
694      "\x8e\x25\x1c\x4c\x96\x47\x22\xe8"
695    },
696    {
697      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
698      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
699      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
700      "\x10\xa9\x4e\xc1\xa5\xec\x17\x52", 8,
701      1024,
702      24,
703      "\x0f\x83\xa2\x77\x92\xbb\xe4\x58\x68\xc5\xf2\x14\x6e\x6e\x2e\x6b"
704      "\x98\x17\x70\x92\x07\x44\xe0\x51"
705    },
706    {
707      "\x61", 1,
708      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
709      "\xef\x8f\x37\x61\x8f\xab\xae\x4f", 8,
710      1024,
711      32,
712      "\x6d\x65\xae\x86\x23\x91\x39\x98\xec\x1c\x23\x44\xb6\x0d\xad\x32"
713      "\x54\x46\xc7\x23\x26\xbb\xdf\x4b\x54\x6e\xd4\xc2\xfa\xc6\x17\x17"
714    },
715    {
716      "\x61\x62\x63\x64\x65\x66\x67", 7,
717      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
718      "\xaa\xfb\xd9\x06\x7d\x7c\x40\xaf", 8,
719      1024,
720      32,
721      "\x7d\x10\x54\x13\x3c\x43\x7a\xb3\x54\x1f\x38\xd4\x8f\x70\x0a\x09"
722      "\xe2\xfa\xab\x97\x9a\x70\x16\xef\x66\x68\xca\x34\x2e\xce\xfa\x1f"
723    },
724    {
725      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
726      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
727      "\x58\x03\x4f\x56\x8b\x97\xd4\x98", 8,
728      1024,
729      32,
730      "\xf7\x40\xb1\x25\x86\x0d\x35\x8f\x9f\x91\x2d\xce\x04\xee\x5a\x04"
731      "\x9d\xbd\x44\x23\x4c\xa6\xbb\xab\xb0\xd0\x56\x82\xa9\xda\x47\x16"
732    },
733    {
734      "\x61\x62\x63\x64\x65\x66\x67\x68\x69", 9,
735      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
736      "\x5d\x41\x3d\xa3\xa7\xfc\x5d\x0c", 8,
737      1024,
738      32,
739      "\x4c\x7a\x86\xed\x81\x8a\x94\x99\x7d\x4a\xc4\xf7\x1c\xf8\x08\xdb"
740      "\x09\x35\xd9\xa3\x2d\x22\xde\x32\x2d\x74\x38\xe5\xc8\xf2\x50\x6e"
741    },
742    {
743      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
744      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
745      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA1,
746      "\xca\xa7\xdc\x59\xce\x31\xe7\x49", 8,
747      1024,
748      32,
749      "\x67\xe9\xd6\x29\x49\x1c\xb6\xa0\x85\xe8\xf9\x8b\x85\x47\x3a\x7e"
750      "\xa7\xee\x89\x52\x6f\x19\x00\x53\x93\x07\x0a\x8b\xb9\xa8\x86\x94"
751    },
752    {
753      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
754      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
755      GCRY_KDF_SIMPLE_S2K, GCRY_MD_SHA256,
756      NULL, 0,
757      0,
758      16,
759      "\x88\x36\x78\x6b\xd9\x5a\x62\xff\x47\xd3\xfb\x79\xc9\x08\x70\x56"
760    },
761    {
762      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
763      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
764      GCRY_KDF_SALTED_S2K, GCRY_MD_SHA256,
765      "\x05\x8b\xfe\x31\xaa\xf3\x29\x11", 8,
766      0,
767      16,
768      "\xb2\x42\xfe\x5e\x09\x02\xd9\x62\xb9\x35\xf3\xa8\x43\x80\x9f\xb1"
769    },
770    {
771      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
772      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
773      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA256,
774      "\xd3\x4a\xea\xc9\x97\x1b\xcc\x83", 8,
775      1024,
776      16,
777      "\x35\x37\x99\x62\x07\x26\x68\x23\x05\x47\xb2\xa0\x0b\x2b\x2b\x8d"
778    },
779    {
780      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
781      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
782      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA256,
783      "\x5e\x71\xbd\x00\x5f\x96\xc4\x23", 8,
784      10240,
785      16,
786      "\xa1\x6a\xee\xba\xde\x73\x25\x25\xd1\xab\xa0\xc5\x7e\xc6\x39\xa7"
787    },
788    {
789      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
790      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
791      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA384,
792      "\xc3\x08\xeb\x17\x62\x08\x89\xef", 8,
793      1024,
794      16,
795      "\x9b\x7f\x0c\x81\x6f\x71\x59\x9b\xd5\xf6\xbf\x3a\x86\x20\x16\x33"
796    },
797    {
798      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
799      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
800      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA512,
801      "\xe6\x7d\x13\x6b\x39\xe3\x44\x05", 8,
802      1024,
803      16,
804      "\xc8\xcd\x4b\xa4\xf3\xf1\xd5\xb0\x59\x06\xf0\xbb\x89\x34\x6a\xad"
805    },
806    {
807      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
808      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
809      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA512,
810      "\xed\x7d\x30\x47\xe4\xc3\xf8\xb6", 8,
811      1024,
812      32,
813      "\x89\x7a\xef\x70\x97\xe7\x10\xdb\x75\xcc\x20\x22\xab\x7b\xf3\x05"
814      "\x4b\xb6\x2e\x17\x11\x9f\xd6\xeb\xbf\xdf\x4d\x70\x59\xf0\xf9\xe5"
815    },
816    {
817      "\x4c\x6f\x6e\x67\x5f\x73\x65\x6e\x74\x65\x6e\x63\x65\x5f\x75\x73"
818      "\x65\x64\x5f\x61\x73\x5f\x70\x61\x73\x73\x70\x68\x72\x61\x73\x65", 32,
819      GCRY_KDF_ITERSALTED_S2K, GCRY_MD_SHA512,
820      "\xbb\x1a\x45\x30\x68\x62\x6d\x63", 8,
821      1024,
822      24,
823      "\xde\x5c\xb8\xd5\x75\xf6\xad\x69\x5b\xc9\xf6\x2f\xba\xeb\xfb\x36"
824      "\x34\xf2\xb8\xee\x3b\x37\x21\xb7"
825    }
826  };
827  int tvidx;
828  gpg_error_t err;
829  unsigned char outbuf[32];
830  int i;
831
832  for (tvidx=0; tvidx < DIM(tv); tvidx++)
833    {
834      if (tv[tvidx].disabled)
835        continue;
836      if (verbose)
837        fprintf (stderr, "checking S2K test vector %d\n", tvidx);
838      assert (tv[tvidx].dklen <= sizeof outbuf);
839      err = gcry_kdf_derive (tv[tvidx].p, tv[tvidx].plen,
840                             tv[tvidx].algo, tv[tvidx].hashalgo,
841                             tv[tvidx].salt, tv[tvidx].saltlen,
842                             tv[tvidx].c, tv[tvidx].dklen, outbuf);
843      if (err)
844        fail ("s2k test %d failed: %s\n", tvidx, gpg_strerror (err));
845      else if (memcmp (outbuf, tv[tvidx].dk, tv[tvidx].dklen))
846        {
847          fail ("s2k test %d failed: mismatch\n", tvidx);
848          fputs ("got:", stderr);
849          for (i=0; i < tv[tvidx].dklen; i++)
850            fprintf (stderr, " %02x", outbuf[i]);
851          putc ('\n', stderr);
852        }
853    }
854}
855
856
857static void
858check_pbkdf2 (void)
859{
860  /* Test vectors are from RFC-6070.  */
861  static struct {
862    const char *p;   /* Passphrase.  */
863    size_t plen;     /* Length of P. */
864    const char *salt;
865    size_t saltlen;
866    unsigned long c; /* Iterations.  */
867    int dklen;       /* Requested key length.  */
868    const char *dk;  /* Derived key.  */
869    int disabled;
870  } tv[] = {
871    {
872      "password", 8,
873      "salt", 4,
874      1,
875      20,
876      "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9"
877      "\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6"
878    },
879    {
880      "password", 8,
881      "salt", 4,
882      2,
883      20,
884      "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e"
885      "\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57"
886    },
887    {
888      "password", 8,
889      "salt", 4,
890      4096,
891      20,
892      "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad"
893      "\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1"
894    },
895    {
896      "password", 8,
897      "salt", 4,
898      16777216,
899      20,
900      "\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94"
901      "\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84",
902      1 /* This test takes too long.  */
903    },
904    {
905      "passwordPASSWORDpassword", 24,
906      "saltSALTsaltSALTsaltSALTsaltSALTsalt", 36,
907      4096,
908      25,
909      "\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8"
910      "\xd8\x36\x62\xc0\xe4\x4a\x8b\x29\x1a\x96"
911      "\x4c\xf2\xf0\x70\x38"
912    },
913    {
914      "pass\0word", 9,
915      "sa\0lt", 5,
916      4096,
917      16,
918      "\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37"
919      "\xd7\xf0\x34\x25\xe0\xc3"
920    },
921    { /* empty password test, not in RFC-6070 */
922      "", 0,
923      "salt", 4,
924      2,
925      20,
926      "\x13\x3a\x4c\xe8\x37\xb4\xd2\x52\x1e\xe2"
927      "\xbf\x03\xe1\x1c\x71\xca\x79\x4e\x07\x97"
928    },
929  };
930  int tvidx;
931  gpg_error_t err;
932  unsigned char outbuf[32];
933  int i;
934
935  for (tvidx=0; tvidx < DIM(tv); tvidx++)
936    {
937      if (tv[tvidx].disabled)
938        continue;
939      if (verbose)
940        fprintf (stderr, "checking PBKDF2 test vector %d\n", tvidx);
941      assert (tv[tvidx].dklen <= sizeof outbuf);
942      err = gcry_kdf_derive (tv[tvidx].p, tv[tvidx].plen,
943                             GCRY_KDF_PBKDF2, GCRY_MD_SHA1,
944                             tv[tvidx].salt, tv[tvidx].saltlen,
945                             tv[tvidx].c, tv[tvidx].dklen, outbuf);
946      if (err)
947        fail ("pbkdf2 test %d failed: %s\n", tvidx, gpg_strerror (err));
948      else if (memcmp (outbuf, tv[tvidx].dk, tv[tvidx].dklen))
949        {
950          fail ("pbkdf2 test %d failed: mismatch\n", tvidx);
951          fputs ("got:", stderr);
952          for (i=0; i < tv[tvidx].dklen; i++)
953            fprintf (stderr, " %02x", outbuf[i]);
954          putc ('\n', stderr);
955        }
956    }
957}
958
959
960int
961main (int argc, char **argv)
962{
963  int debug = 0;
964
965  if (argc > 1 && !strcmp (argv[1], "--verbose"))
966    verbose = 1;
967  else if (argc > 1 && !strcmp (argv[1], "--debug"))
968    verbose = debug = 1;
969
970  if (!gcry_check_version (GCRYPT_VERSION))
971    die ("version mismatch\n");
972
973  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
974  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
975  if (debug)
976    gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
977
978  check_openpgp ();
979  check_pbkdf2 ();
980
981  return error_count ? 1 : 0;
982}
983