LCOV - code coverage report
Current view: top level - tests - basic.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1453 2524 57.6 %
Date: 2016-12-01 18:32:04 Functions: 45 54 83.3 %

          Line data    Source code
       1             : /* basic.c  -  basic regression tests
       2             :  * Copyright (C) 2001, 2002, 2003, 2005, 2008,
       3             :  *               2009 Free Software Foundation, Inc.
       4             :  * Copyright (C) 2013 g10 Code GmbH
       5             :  *
       6             :  * This file is part of Libgcrypt.
       7             :  *
       8             :  * Libgcrypt is free software; you can redistribute it and/or modify
       9             :  * it under the terms of the GNU Lesser General Public License as
      10             :  * published by the Free Software Foundation; either version 2.1 of
      11             :  * the License, or (at your option) any later version.
      12             :  *
      13             :  * Libgcrypt is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :  * GNU Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
      20             :  */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : #include <stdio.h>
      26             : #include <stdlib.h>
      27             : #include <string.h>
      28             : #include <stdarg.h>
      29             : #include <assert.h>
      30             : 
      31             : #include "../src/gcrypt-int.h"
      32             : 
      33             : #ifndef DIM
      34             : # define DIM(v)              (sizeof(v)/sizeof((v)[0]))
      35             : #endif
      36             : 
      37             : #define PGM "basic"
      38             : 
      39             : typedef struct test_spec_pubkey_key
      40             : {
      41             :   const char *secret;
      42             :   const char *public;
      43             :   const char *grip;
      44             : }
      45             : test_spec_pubkey_key_t;
      46             : 
      47             : typedef struct test_spec_pubkey
      48             : {
      49             :   int id;
      50             :   int flags;
      51             :   test_spec_pubkey_key_t key;
      52             : }
      53             : test_spec_pubkey_t;
      54             : 
      55             : #define FLAG_CRYPT (1 << 0)
      56             : #define FLAG_SIGN  (1 << 1)
      57             : #define FLAG_GRIP  (1 << 2)
      58             : 
      59             : static int verbose;
      60             : static int error_count;
      61             : static int in_fips_mode;
      62             : static int die_on_error;
      63             : 
      64             : #define MAX_DATA_LEN 128
      65             : 
      66             : #define digitp(p)   (*(p) >= '0' && *(p) <= '9')
      67             : #define hexdigitp(a) (digitp (a)                     \
      68             :                       || (*(a) >= 'A' && *(a) <= 'F')  \
      69             :                       || (*(a) >= 'a' && *(a) <= 'f'))
      70             : #define xtoi_1(p)   (*(p) <= '9'? (*(p)- '0'): \
      71             :                      *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
      72             : #define xtoi_2(p)   ((xtoi_1(p) * 16) + xtoi_1((p)+1))
      73             : #define xmalloc(a)    gcry_xmalloc ((a))
      74             : #define xcalloc(a,b)  gcry_xcalloc ((a),(b))
      75             : #define xstrdup(a)    gcry_xstrdup ((a))
      76             : #define xfree(a)      gcry_free ((a))
      77             : 
      78             : 
      79             : 
      80             : static void
      81           0 : fail (const char *format, ...)
      82             : {
      83             :   va_list arg_ptr;
      84             : 
      85           0 :   va_start (arg_ptr, format);
      86           0 :   vfprintf (stderr, format, arg_ptr);
      87           0 :   va_end (arg_ptr);
      88           0 :   error_count++;
      89           0 :   if (die_on_error)
      90           0 :     exit (1);
      91           0 : }
      92             : 
      93             : 
      94             : static void
      95           0 : mismatch (const void *expected, size_t expectedlen,
      96             :           const void *computed, size_t computedlen)
      97             : {
      98             :   const unsigned char *p;
      99             : 
     100           0 :   fprintf (stderr, "expected:");
     101           0 :   for (p = expected; expectedlen; p++, expectedlen--)
     102           0 :     fprintf (stderr, " %02x", *p);
     103           0 :   fprintf (stderr, "\ncomputed:");
     104           0 :   for (p = computed; computedlen; p++, computedlen--)
     105           0 :     fprintf (stderr, " %02x", *p);
     106           0 :   fprintf (stderr, "\n");
     107           0 : }
     108             : 
     109             : 
     110             : static void
     111           0 : die (const char *format, ...)
     112             : {
     113             :   va_list arg_ptr;
     114             : 
     115           0 :   va_start (arg_ptr, format);
     116           0 :   vfprintf (stderr, format, arg_ptr);
     117           0 :   va_end (arg_ptr);
     118           0 :   exit (1);
     119             : }
     120             : 
     121             : 
     122             : /* Convert STRING consisting of hex characters into its binary
     123             :    representation and return it as an allocated buffer. The valid
     124             :    length of the buffer is returned at R_LENGTH.  The string is
     125             :    delimited by end of string.  The function terminates on error.  */
     126             : static void *
     127         231 : hex2buffer (const char *string, size_t *r_length)
     128             : {
     129             :   const char *s;
     130             :   unsigned char *buffer;
     131             :   size_t length;
     132             : 
     133         231 :   buffer = xmalloc (strlen(string)/2+1);
     134         231 :   length = 0;
     135        4163 :   for (s=string; *s; s +=2 )
     136             :     {
     137        3932 :       if (!hexdigitp (s) || !hexdigitp (s+1))
     138           0 :         die ("invalid hex digits in \"%s\"\n", string);
     139        3932 :       ((unsigned char*)buffer)[length++] = xtoi_2 (s);
     140             :     }
     141         231 :   *r_length = length;
     142         231 :   return buffer;
     143             : }
     144             : 
     145             : 
     146             : static void
     147           0 : show_sexp (const char *prefix, gcry_sexp_t a)
     148             : {
     149             :   char *buf;
     150             :   size_t size;
     151             : 
     152           0 :   if (prefix)
     153           0 :     fputs (prefix, stderr);
     154           0 :   size = gcry_sexp_sprint (a, GCRYSEXP_FMT_ADVANCED, NULL, 0);
     155           0 :   buf = gcry_xmalloc (size);
     156             : 
     157           0 :   gcry_sexp_sprint (a, GCRYSEXP_FMT_ADVANCED, buf, size);
     158           0 :   fprintf (stderr, "%.*s", (int)size, buf);
     159           0 :   gcry_free (buf);
     160           0 : }
     161             : 
     162             : 
     163             : static void
     164           0 : show_note (const char *format, ...)
     165             : {
     166             :   va_list arg_ptr;
     167             : 
     168           0 :   if (!verbose && getenv ("srcdir"))
     169           0 :     fputs ("      ", stderr);  /* To align above "PASS: ".  */
     170             :   else
     171           0 :     fprintf (stderr, "%s: ", PGM);
     172           0 :   va_start (arg_ptr, format);
     173           0 :   vfprintf (stderr, format, arg_ptr);
     174           0 :   if (*format && format[strlen(format)-1] != '\n')
     175           0 :     putc ('\n', stderr);
     176           0 :   va_end (arg_ptr);
     177           0 : }
     178             : 
     179             : 
     180             : static void
     181           3 : show_md_not_available (int algo)
     182             : {
     183             :   static int list[100];
     184             :   static int listlen;
     185             :   int i;
     186             : 
     187           3 :   if (!verbose && algo == GCRY_MD_MD2)
     188           3 :     return;  /* Do not print the diagnostic for that one.  */
     189             : 
     190           0 :   for (i=0; i < listlen; i++)
     191           0 :     if (algo == list[i])
     192           0 :       return; /* Note already printed.  */
     193           0 :   if (listlen < DIM (list))
     194           0 :     list[listlen++] = algo;
     195           0 :   show_note ("hash algorithm %d not available - skipping tests", algo);
     196             : }
     197             : 
     198             : 
     199             : static void
     200           0 : show_old_hmac_not_available (int algo)
     201             : {
     202             :   static int list[100];
     203             :   static int listlen;
     204             :   int i;
     205             : 
     206           0 :   if (!verbose && algo == GCRY_MD_MD2)
     207           0 :     return;  /* Do not print the diagnostic for that one.  */
     208             : 
     209           0 :   for (i=0; i < listlen; i++)
     210           0 :     if (algo == list[i])
     211           0 :       return; /* Note already printed.  */
     212           0 :   if (listlen < DIM (list))
     213           0 :     list[listlen++] = algo;
     214           0 :   show_note ("hash algorithm %d for old HMAC API not available "
     215             :              "- skipping tests", algo);
     216             : }
     217             : 
     218             : 
     219             : static void
     220           0 : show_mac_not_available (int algo)
     221             : {
     222             :   static int list[100];
     223             :   static int listlen;
     224             :   int i;
     225             : 
     226           0 :   if (!verbose && algo == GCRY_MD_MD2)
     227           0 :     return;  /* Do not print the diagnostic for that one.  */
     228             : 
     229           0 :   for (i=0; i < listlen; i++)
     230           0 :     if (algo == list[i])
     231           0 :       return; /* Note already printed.  */
     232           0 :   if (listlen < DIM (list))
     233           0 :     list[listlen++] = algo;
     234           0 :   show_note ("MAC algorithm %d not available - skipping tests", algo);
     235             : }
     236             : 
     237             : 
     238             : 
     239             : void
     240           0 : progress_handler (void *cb_data, const char *what, int printchar,
     241             :                   int current, int total)
     242             : {
     243             :   (void)cb_data;
     244             :   (void)what;
     245             :   (void)current;
     246             :   (void)total;
     247             : 
     248           0 :   if (printchar == '\n')
     249           0 :     fputs ( "<LF>", stdout);
     250             :   else
     251           0 :     putchar (printchar);
     252           0 :   fflush (stdout);
     253           0 : }
     254             : 
     255             : static void
     256           1 : check_cbc_mac_cipher (void)
     257             : {
     258             :   static const struct tv
     259             :   {
     260             :     int algo;
     261             :     char key[MAX_DATA_LEN];
     262             :     unsigned char plaintext[MAX_DATA_LEN];
     263             :     size_t plaintextlen;
     264             :     char mac[MAX_DATA_LEN];
     265             :   }
     266             :   tv[] =
     267             :     {
     268             :       { GCRY_CIPHER_AES,
     269             :         "chicken teriyaki",
     270             :         "This is a sample plaintext for CBC MAC of sixtyfour bytes.......",
     271             :         0, "\x23\x8f\x6d\xc7\x53\x6a\x62\x97\x11\xc4\xa5\x16\x43\xea\xb0\xb6" },
     272             :       { GCRY_CIPHER_3DES,
     273             :         "abcdefghABCDEFGH01234567",
     274             :         "This is a sample plaintext for CBC MAC of sixtyfour bytes.......",
     275             :         0, "\x5c\x11\xf0\x01\x47\xbd\x3d\x3a" },
     276             :       { GCRY_CIPHER_DES,
     277             :         "abcdefgh",
     278             :         "This is a sample plaintext for CBC MAC of sixtyfour bytes.......",
     279             :         0, "\xfa\x4b\xdf\x9d\xfa\xab\x01\x70" }
     280             :     };
     281             :   gcry_cipher_hd_t hd;
     282             :   unsigned char out[MAX_DATA_LEN];
     283             :   int i, blklen, keylen;
     284           1 :   gcry_error_t err = 0;
     285             : 
     286           1 :   if (verbose)
     287           0 :     fprintf (stderr, "  Starting CBC MAC checks.\n");
     288             : 
     289           4 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
     290             :     {
     291           3 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
     292             :         {
     293           0 :           if (verbose)
     294           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
     295             :                      tv[i].algo);
     296           0 :           continue;
     297             :         }
     298             : 
     299           3 :       err = gcry_cipher_open (&hd,
     300             :                               tv[i].algo,
     301             :                               GCRY_CIPHER_MODE_CBC, GCRY_CIPHER_CBC_MAC);
     302           3 :       if (!hd)
     303             :         {
     304           0 :           fail ("cbc-mac algo %d, gcry_cipher_open failed: %s\n",
     305             :                 tv[i].algo, gpg_strerror (err));
     306           0 :           return;
     307             :         }
     308             : 
     309           3 :       blklen = gcry_cipher_get_algo_blklen(tv[i].algo);
     310           3 :       if (!blklen)
     311             :         {
     312           0 :           fail ("cbc-mac algo %d, gcry_cipher_get_algo_blklen failed\n",
     313             :                  tv[i].algo);
     314           0 :           gcry_cipher_close (hd);
     315           0 :           return;
     316             :         }
     317             : 
     318           3 :       keylen = gcry_cipher_get_algo_keylen (tv[i].algo);
     319           3 :       if (!keylen)
     320             :         {
     321           0 :           fail ("cbc-mac algo %d, gcry_cipher_get_algo_keylen failed\n",
     322             :                 tv[i].algo);
     323           0 :           return;
     324             :         }
     325             : 
     326           3 :       err = gcry_cipher_setkey (hd, tv[i].key, keylen);
     327           3 :       if (err)
     328             :         {
     329           0 :           fail ("cbc-mac algo %d, gcry_cipher_setkey failed: %s\n",
     330             :                 tv[i].algo, gpg_strerror (err));
     331           0 :           gcry_cipher_close (hd);
     332           0 :           return;
     333             :         }
     334             : 
     335           3 :       err = gcry_cipher_setiv (hd, NULL, 0);
     336           3 :       if (err)
     337             :         {
     338           0 :           fail ("cbc-mac algo %d, gcry_cipher_setiv failed: %s\n",
     339             :                 tv[i].algo, gpg_strerror (err));
     340           0 :           gcry_cipher_close (hd);
     341           0 :           return;
     342             :         }
     343             : 
     344           3 :       if (verbose)
     345           0 :         fprintf (stderr, "    checking CBC MAC for %s [%i]\n",
     346             :                  gcry_cipher_algo_name (tv[i].algo),
     347             :                  tv[i].algo);
     348           9 :       err = gcry_cipher_encrypt (hd,
     349             :                                  out, blklen,
     350           3 :                                  tv[i].plaintext,
     351           3 :                                  tv[i].plaintextlen ?
     352             :                                  tv[i].plaintextlen :
     353           3 :                                  strlen ((char*)tv[i].plaintext));
     354           3 :       if (err)
     355             :         {
     356           0 :           fail ("cbc-mac algo %d, gcry_cipher_encrypt failed: %s\n",
     357             :                 tv[i].algo, gpg_strerror (err));
     358           0 :           gcry_cipher_close (hd);
     359           0 :           return;
     360             :         }
     361             : 
     362             : #if 0
     363             :       {
     364             :         int j;
     365             :         for (j = 0; j < gcry_cipher_get_algo_blklen (tv[i].algo); j++)
     366             :           printf ("\\x%02x", out[j] & 0xFF);
     367             :         printf ("\n");
     368             :       }
     369             : #endif
     370             : 
     371           3 :       if (memcmp (tv[i].mac, out, blklen))
     372           0 :         fail ("cbc-mac algo %d, encrypt mismatch entry %d\n", tv[i].algo, i);
     373             : 
     374           3 :       gcry_cipher_close (hd);
     375             :     }
     376           1 :   if (verbose)
     377           0 :     fprintf (stderr, "  Completed CBC MAC checks.\n");
     378             : }
     379             : 
     380             : static void
     381           1 : check_aes128_cbc_cts_cipher (void)
     382             : {
     383             :   static const char key[128 / 8] = "chicken teriyaki";
     384             :   static const unsigned char plaintext[] =
     385             :     "I would like the General Gau's Chicken, please, and wonton soup.";
     386             :   static const struct tv
     387             :   {
     388             :     unsigned char out[MAX_DATA_LEN];
     389             :     int inlen;
     390             :   } tv[] =
     391             :     {
     392             :       { "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
     393             :         "\x97",
     394             :         17 },
     395             :       { "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
     396             :         "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
     397             :         31 },
     398             :       { "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
     399             :         "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
     400             :         32 },
     401             :       { "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
     402             :         "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
     403             :         "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
     404             :         47 },
     405             :       { "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
     406             :         "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
     407             :         "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
     408             :         48 },
     409             :       { "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
     410             :         "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
     411             :         "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
     412             :         "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
     413             :         64 },
     414             :     };
     415             :   gcry_cipher_hd_t hd;
     416             :   unsigned char out[MAX_DATA_LEN];
     417             :   int i;
     418           1 :   gcry_error_t err = 0;
     419             : 
     420           1 :   if (verbose)
     421           0 :     fprintf (stderr, "  Starting AES128 CBC CTS checks.\n");
     422           1 :   err = gcry_cipher_open (&hd,
     423             :                           GCRY_CIPHER_AES,
     424             :                           GCRY_CIPHER_MODE_CBC, GCRY_CIPHER_CBC_CTS);
     425           1 :   if (err)
     426             :     {
     427           0 :       fail ("aes-cbc-cts, gcry_cipher_open failed: %s\n", gpg_strerror (err));
     428           0 :       return;
     429             :     }
     430             : 
     431           1 :   err = gcry_cipher_setkey (hd, key, 128 / 8);
     432           1 :   if (err)
     433             :     {
     434           0 :       fail ("aes-cbc-cts, gcry_cipher_setkey failed: %s\n",
     435             :             gpg_strerror (err));
     436           0 :       gcry_cipher_close (hd);
     437           0 :       return;
     438             :     }
     439             : 
     440           7 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
     441             :     {
     442           6 :       err = gcry_cipher_setiv (hd, NULL, 0);
     443           6 :       if (err)
     444             :         {
     445           0 :           fail ("aes-cbc-cts, gcry_cipher_setiv failed: %s\n",
     446             :                 gpg_strerror (err));
     447           0 :           gcry_cipher_close (hd);
     448           0 :           return;
     449             :         }
     450             : 
     451           6 :       if (verbose)
     452           0 :         fprintf (stderr, "    checking encryption for length %i\n", tv[i].inlen);
     453           6 :       err = gcry_cipher_encrypt (hd, out, MAX_DATA_LEN,
     454           6 :                                  plaintext, tv[i].inlen);
     455           6 :       if (err)
     456             :         {
     457           0 :           fail ("aes-cbc-cts, gcry_cipher_encrypt failed: %s\n",
     458             :                 gpg_strerror (err));
     459           0 :           gcry_cipher_close (hd);
     460           0 :           return;
     461             :         }
     462             : 
     463           6 :       if (memcmp (tv[i].out, out, tv[i].inlen))
     464           0 :         fail ("aes-cbc-cts, encrypt mismatch entry %d\n", i);
     465             : 
     466           6 :       err = gcry_cipher_setiv (hd, NULL, 0);
     467           6 :       if (err)
     468             :         {
     469           0 :           fail ("aes-cbc-cts, gcry_cipher_setiv failed: %s\n",
     470             :                 gpg_strerror (err));
     471           0 :           gcry_cipher_close (hd);
     472           0 :           return;
     473             :         }
     474           6 :       if (verbose)
     475           0 :         fprintf (stderr, "    checking decryption for length %i\n", tv[i].inlen);
     476           6 :       err = gcry_cipher_decrypt (hd, out, tv[i].inlen, NULL, 0);
     477           6 :       if (err)
     478             :         {
     479           0 :           fail ("aes-cbc-cts, gcry_cipher_decrypt failed: %s\n",
     480             :                 gpg_strerror (err));
     481           0 :           gcry_cipher_close (hd);
     482           0 :           return;
     483             :         }
     484             : 
     485           6 :       if (memcmp (plaintext, out, tv[i].inlen))
     486           0 :         fail ("aes-cbc-cts, decrypt mismatch entry %d\n", i);
     487             :     }
     488             : 
     489           1 :   gcry_cipher_close (hd);
     490           1 :   if (verbose)
     491           0 :     fprintf (stderr, "  Completed AES128 CBC CTS checks.\n");
     492             : }
     493             : 
     494             : static void
     495           1 : check_ctr_cipher (void)
     496             : {
     497             :   static const struct tv
     498             :   {
     499             :     int algo;
     500             :     char key[MAX_DATA_LEN];
     501             :     char ctr[MAX_DATA_LEN];
     502             :     struct data
     503             :     {
     504             :       unsigned char plaintext[MAX_DATA_LEN];
     505             :       int inlen;
     506             :       char out[MAX_DATA_LEN];
     507             :     } data[8];
     508             :   } tv[] =
     509             :     {
     510             :       /* http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf */
     511             :       { GCRY_CIPHER_AES,
     512             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     513             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     514             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     515             :             16,
     516             :             "\x87\x4d\x61\x91\xb6\x20\xe3\x26\x1b\xef\x68\x64\x99\x0d\xb6\xce" },
     517             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     518             :             16,
     519             :             "\x98\x06\xf6\x6b\x79\x70\xfd\xff\x86\x17\x18\x7b\xb9\xff\xfd\xff" },
     520             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     521             :             16,
     522             :             "\x5a\xe4\xdf\x3e\xdb\xd5\xd3\x5e\x5b\x4f\x09\x02\x0d\xb0\x3e\xab" },
     523             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     524             :             16,
     525             :             "\x1e\x03\x1d\xda\x2f\xbe\x03\xd1\x79\x21\x70\xa0\xf3\x00\x9c\xee" },
     526             : 
     527             :           { "", 0, "" }
     528             :         }
     529             :       },
     530             :       { GCRY_CIPHER_AES192,
     531             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b"
     532             :         "\x80\x90\x79\xe5\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
     533             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     534             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     535             :             16,
     536             :             "\x1a\xbc\x93\x24\x17\x52\x1c\xa2\x4f\x2b\x04\x59\xfe\x7e\x6e\x0b" },
     537             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     538             :             16,
     539             :             "\x09\x03\x39\xec\x0a\xa6\xfa\xef\xd5\xcc\xc2\xc6\xf4\xce\x8e\x94" },
     540             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     541             :             16,
     542             :             "\x1e\x36\xb2\x6b\xd1\xeb\xc6\x70\xd1\xbd\x1d\x66\x56\x20\xab\xf7" },
     543             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     544             :             16,
     545             :             "\x4f\x78\xa7\xf6\xd2\x98\x09\x58\x5a\x97\xda\xec\x58\xc6\xb0\x50" },
     546             :           { "", 0, "" }
     547             :         }
     548             :       },
     549             :       { GCRY_CIPHER_AES256,
     550             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
     551             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
     552             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     553             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     554             :             16,
     555             :             "\x60\x1e\xc3\x13\x77\x57\x89\xa5\xb7\xa7\xf5\x04\xbb\xf3\xd2\x28" },
     556             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     557             :             16,
     558             :             "\xf4\x43\xe3\xca\x4d\x62\xb5\x9a\xca\x84\xe9\x90\xca\xca\xf5\xc5" },
     559             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     560             :             16,
     561             :             "\x2b\x09\x30\xda\xa2\x3d\xe9\x4c\xe8\x70\x17\xba\x2d\x84\x98\x8d" },
     562             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     563             :             16,
     564             :             "\xdf\xc9\xc5\x8d\xb6\x7a\xad\xa6\x13\xc2\xdd\x08\x45\x79\x41\xa6" },
     565             :           { "", 0, "" }
     566             :         }
     567             :       },
     568             :       /* Some truncation tests.  With a truncated second block and
     569             :          also with a single truncated block.  */
     570             :       { GCRY_CIPHER_AES,
     571             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     572             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     573             :         {{"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     574             :           16,
     575             :           "\x87\x4d\x61\x91\xb6\x20\xe3\x26\x1b\xef\x68\x64\x99\x0d\xb6\xce" },
     576             :          {"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e",
     577             :           15,
     578             :           "\x98\x06\xf6\x6b\x79\x70\xfd\xff\x86\x17\x18\x7b\xb9\xff\xfd" },
     579             :          {"", 0, "" }
     580             :         }
     581             :       },
     582             :       { GCRY_CIPHER_AES,
     583             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     584             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     585             :         {{"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     586             :           16,
     587             :           "\x87\x4d\x61\x91\xb6\x20\xe3\x26\x1b\xef\x68\x64\x99\x0d\xb6\xce" },
     588             :          {"\xae",
     589             :           1,
     590             :           "\x98" },
     591             :          {"", 0, "" }
     592             :         }
     593             :       },
     594             :       { GCRY_CIPHER_AES,
     595             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     596             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     597             :         {{"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17",
     598             :           15,
     599             :           "\x87\x4d\x61\x91\xb6\x20\xe3\x26\x1b\xef\x68\x64\x99\x0d\xb6" },
     600             :          {"", 0, "" }
     601             :         }
     602             :       },
     603             :       { GCRY_CIPHER_AES,
     604             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     605             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     606             :         {{"\x6b",
     607             :           1,
     608             :           "\x87" },
     609             :          {"", 0, "" }
     610             :         }
     611             :       },
     612             :       /* Tests to see whether it works correctly as a stream cipher.  */
     613             :       { GCRY_CIPHER_AES,
     614             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     615             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     616             :         {{"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     617             :           16,
     618             :           "\x87\x4d\x61\x91\xb6\x20\xe3\x26\x1b\xef\x68\x64\x99\x0d\xb6\xce" },
     619             :          {"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e",
     620             :           15,
     621             :           "\x98\x06\xf6\x6b\x79\x70\xfd\xff\x86\x17\x18\x7b\xb9\xff\xfd" },
     622             :          {"\x51\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     623             :           17,
     624             :           "\xff\x5a\xe4\xdf\x3e\xdb\xd5\xd3\x5e\x5b\x4f\x09\x02\x0d\xb0\x3e\xab" },
     625             :          {"\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     626             :           16,
     627             :           "\x1e\x03\x1d\xda\x2f\xbe\x03\xd1\x79\x21\x70\xa0\xf3\x00\x9c\xee" },
     628             : 
     629             :           { "", 0, "" }
     630             :         }
     631             :       },
     632             :       { GCRY_CIPHER_AES,
     633             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     634             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
     635             :         {{"\x6b",
     636             :           1,
     637             :           "\x87" },
     638             :          {"\xc1\xbe",
     639             :           2,
     640             :           "\x4d\x61" },
     641             :          {"\xe2\x2e\x40",
     642             :           3,
     643             :           "\x91\xb6\x20" },
     644             :          {"\x9f",
     645             :           1,
     646             :           "\xe3" },
     647             :          {"\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     648             :           9,
     649             :           "\x26\x1b\xef\x68\x64\x99\x0d\xb6\xce" },
     650             :          {"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e",
     651             :           15,
     652             :           "\x98\x06\xf6\x6b\x79\x70\xfd\xff\x86\x17\x18\x7b\xb9\xff\xfd" },
     653             :          {"\x51\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
     654             :           9,
     655             :           "\xff\x5a\xe4\xdf\x3e\xdb\xd5\xd3\x5e" },
     656             : 
     657             :           { "", 0, "" }
     658             :         }
     659             :       },
     660             : #if USE_CAST5
     661             :       /* A selfmade test vector using an 64 bit block cipher.  */
     662             :       { GCRY_CIPHER_CAST5,
     663             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     664             :         "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8",
     665             :         {{"\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     666             :           16,
     667             :           "\xe8\xa7\xac\x68\xca\xca\xa0\x20\x10\xcb\x1b\xcc\x79\x2c\xc4\x48" },
     668             :          {"\xae\x2d\x8a\x57\x1e\x03\xac\x9c",
     669             :           8,
     670             :           "\x16\xe8\x72\x77\xb0\x98\x29\x68" },
     671             :          {"\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     672             :           8,
     673             :           "\x9a\xb3\xa8\x03\x3b\xb4\x14\xba" },
     674             :          {"\xae\x2d\x8a\x57\x1e\x03\xac\x9c\xa1\x00",
     675             :           10,
     676             :           "\x31\x5e\xd3\xfb\x1b\x8d\xd1\xf9\xb0\x83" },
     677             :          { "", 0, "" }
     678             :         }
     679             :       },
     680             : #endif /*USE_CAST5*/
     681             :       { 0,
     682             :         "",
     683             :         "",
     684             :         {
     685             :          {"", 0, "" }
     686             :         }
     687             :       }
     688             :     };
     689             :   gcry_cipher_hd_t hde, hdd;
     690             :   unsigned char out[MAX_DATA_LEN];
     691             :   int i, j, keylen, blklen;
     692           1 :   gcry_error_t err = 0;
     693             :   size_t taglen2;
     694             : 
     695           1 :   if (verbose)
     696           0 :     fprintf (stderr, "  Starting CTR cipher checks.\n");
     697          12 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
     698             :     {
     699          11 :       if (!tv[i].algo)
     700           1 :         continue;
     701             : 
     702          10 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
     703             :         {
     704           0 :           if (verbose)
     705           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
     706             :                      tv[i].algo);
     707           0 :           continue;
     708             :         }
     709             : 
     710          10 :       err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_CTR, 0);
     711          10 :       if (!err)
     712          10 :         err = gcry_cipher_open (&hdd, tv[i].algo, GCRY_CIPHER_MODE_CTR, 0);
     713          10 :       if (err)
     714             :         {
     715           0 :           fail ("aes-ctr, gcry_cipher_open failed: %s\n", gpg_strerror (err));
     716           0 :           return;
     717             :         }
     718             : 
     719          10 :       keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
     720          10 :       if (!keylen)
     721             :         {
     722           0 :           fail ("aes-ctr, gcry_cipher_get_algo_keylen failed\n");
     723           0 :           return;
     724             :         }
     725             : 
     726          10 :       err = gcry_cipher_setkey (hde, tv[i].key, keylen);
     727          10 :       if (!err)
     728          10 :         err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
     729          10 :       if (err)
     730             :         {
     731           0 :           fail ("aes-ctr, gcry_cipher_setkey failed: %s\n",
     732             :                 gpg_strerror (err));
     733           0 :           gcry_cipher_close (hde);
     734           0 :           gcry_cipher_close (hdd);
     735           0 :           return;
     736             :         }
     737             : 
     738          10 :       blklen = gcry_cipher_get_algo_blklen(tv[i].algo);
     739          10 :       if (!blklen)
     740             :         {
     741           0 :           fail ("aes-ctr, gcry_cipher_get_algo_blklen failed\n");
     742           0 :           return;
     743             :         }
     744             : 
     745          10 :       err = gcry_cipher_setctr (hde, tv[i].ctr, blklen);
     746          10 :       if (!err)
     747          10 :         err = gcry_cipher_setctr (hdd, tv[i].ctr, blklen);
     748          10 :       if (err)
     749             :         {
     750           0 :           fail ("aes-ctr, gcry_cipher_setctr failed: %s\n",
     751             :                 gpg_strerror (err));
     752           0 :           gcry_cipher_close (hde);
     753           0 :           gcry_cipher_close (hdd);
     754           0 :           return;
     755             :         }
     756             : 
     757             : 
     758          10 :       err = gcry_cipher_info (hde, GCRYCTL_GET_TAGLEN, NULL, &taglen2);
     759          10 :       if (gpg_err_code (err) != GPG_ERR_INV_CIPHER_MODE)
     760             :         {
     761           0 :           fail ("aes-ctr, gcryctl_get_taglen failed to fail (tv %d): %s\n",
     762             :                 i, gpg_strerror (err));
     763           0 :           gcry_cipher_close (hde);
     764           0 :           gcry_cipher_close (hdd);
     765           0 :           return;
     766             :         }
     767             : 
     768          10 :       if (verbose)
     769           0 :         fprintf (stderr, "    checking CTR mode for %s [%i]\n",
     770             :                  gcry_cipher_algo_name (tv[i].algo),
     771             :                  tv[i].algo);
     772          43 :       for (j = 0; tv[i].data[j].inlen; j++)
     773             :         {
     774          99 :           err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
     775          33 :                                      tv[i].data[j].plaintext,
     776          33 :                                      tv[i].data[j].inlen == -1 ?
     777           0 :                                      strlen ((char*)tv[i].data[j].plaintext) :
     778          33 :                                      tv[i].data[j].inlen);
     779          33 :           if (err)
     780             :             {
     781           0 :               fail ("aes-ctr, gcry_cipher_encrypt (%d, %d) failed: %s\n",
     782             :                     i, j, gpg_strerror (err));
     783           0 :               gcry_cipher_close (hde);
     784           0 :               gcry_cipher_close (hdd);
     785           0 :               return;
     786             :             }
     787             : 
     788          33 :           if (memcmp (tv[i].data[j].out, out, tv[i].data[j].inlen))
     789             :             {
     790           0 :               fail ("aes-ctr, encrypt mismatch entry %d:%d\n", i, j);
     791           0 :               mismatch (tv[i].data[j].out, tv[i].data[j].inlen,
     792           0 :                         out, tv[i].data[j].inlen);
     793             :             }
     794             : 
     795          33 :           err = gcry_cipher_decrypt (hdd, out, tv[i].data[j].inlen, NULL, 0);
     796          33 :           if (err)
     797             :             {
     798           0 :               fail ("aes-ctr, gcry_cipher_decrypt (%d, %d) failed: %s\n",
     799             :                     i, j, gpg_strerror (err));
     800           0 :               gcry_cipher_close (hde);
     801           0 :               gcry_cipher_close (hdd);
     802           0 :               return;
     803             :             }
     804             : 
     805          33 :           if (memcmp (tv[i].data[j].plaintext, out, tv[i].data[j].inlen))
     806             :             {
     807           0 :               fail ("aes-ctr, decrypt mismatch entry %d:%d\n", i, j);
     808           0 :               mismatch (tv[i].data[j].plaintext, tv[i].data[j].inlen,
     809           0 :                         out, tv[i].data[j].inlen);
     810             :             }
     811             : 
     812             :         }
     813             : 
     814             :       /* Now check that we get valid return codes back for good and
     815             :          bad inputs.  */
     816          10 :       err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
     817             :                                  "1234567890123456", 16);
     818          10 :       if (err)
     819           0 :         fail ("aes-ctr, encryption failed for valid input");
     820             : 
     821          10 :       err = gcry_cipher_encrypt (hde, out, 15,
     822             :                                  "1234567890123456", 16);
     823          10 :       if (gpg_err_code (err) != GPG_ERR_BUFFER_TOO_SHORT)
     824           0 :         fail ("aes-ctr, too short output buffer returned wrong error: %s\n",
     825             :               gpg_strerror (err));
     826             : 
     827          10 :       err = gcry_cipher_encrypt (hde, out, 0,
     828             :                                  "1234567890123456", 16);
     829          10 :       if (gpg_err_code (err) != GPG_ERR_BUFFER_TOO_SHORT)
     830           0 :         fail ("aes-ctr, 0 length output buffer returned wrong error: %s\n",
     831             :               gpg_strerror (err));
     832             : 
     833          10 :       err = gcry_cipher_encrypt (hde, out, 16,
     834             :                                  "1234567890123456", 16);
     835          10 :       if (err)
     836           0 :         fail ("aes-ctr, correct length output buffer returned error: %s\n",
     837             :               gpg_strerror (err));
     838             : 
     839             :       /* Again, now for decryption.  */
     840          10 :       err = gcry_cipher_decrypt (hde, out, MAX_DATA_LEN,
     841             :                                  "1234567890123456", 16);
     842          10 :       if (err)
     843           0 :         fail ("aes-ctr, decryption failed for valid input");
     844             : 
     845          10 :       err = gcry_cipher_decrypt (hde, out, 15,
     846             :                                  "1234567890123456", 16);
     847          10 :       if (gpg_err_code (err) != GPG_ERR_BUFFER_TOO_SHORT)
     848           0 :         fail ("aes-ctr, too short output buffer returned wrong error: %s\n",
     849             :               gpg_strerror (err));
     850             : 
     851          10 :       err = gcry_cipher_decrypt (hde, out, 0,
     852             :                                  "1234567890123456", 16);
     853          10 :       if (gpg_err_code (err) != GPG_ERR_BUFFER_TOO_SHORT)
     854           0 :         fail ("aes-ctr, 0 length output buffer returned wrong error: %s\n",
     855             :               gpg_strerror (err));
     856             : 
     857          10 :       err = gcry_cipher_decrypt (hde, out, 16,
     858             :                                  "1234567890123456", 16);
     859          10 :       if (err)
     860           0 :         fail ("aes-ctr, correct length output buffer returned error: %s\n",
     861             :               gpg_strerror (err));
     862             : 
     863          10 :       gcry_cipher_close (hde);
     864          10 :       gcry_cipher_close (hdd);
     865             :     }
     866           1 :   if (verbose)
     867           0 :     fprintf (stderr, "  Completed CTR cipher checks.\n");
     868             : }
     869             : 
     870             : static void
     871           1 : check_cfb_cipher (void)
     872             : {
     873             :   static const struct tv
     874             :   {
     875             :     int algo;
     876             :     int cfb8;
     877             :     char key[MAX_DATA_LEN];
     878             :     char iv[MAX_DATA_LEN];
     879             :     struct data
     880             :     {
     881             :       unsigned char plaintext[MAX_DATA_LEN];
     882             :       int inlen;
     883             :       char out[MAX_DATA_LEN];
     884             :     }
     885             :     data[MAX_DATA_LEN];
     886             :   } tv[] =
     887             :     {
     888             :       /* http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf */
     889             :       { GCRY_CIPHER_AES, 0,
     890             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
     891             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
     892             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     893             :             16,
     894             :             "\x3b\x3f\xd9\x2e\xb7\x2d\xad\x20\x33\x34\x49\xf8\xe8\x3c\xfb\x4a" },
     895             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     896             :             16,
     897             :             "\xc8\xa6\x45\x37\xa0\xb3\xa9\x3f\xcd\xe3\xcd\xad\x9f\x1c\xe5\x8b"},
     898             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     899             :             16,
     900             :             "\x26\x75\x1f\x67\xa3\xcb\xb1\x40\xb1\x80\x8c\xf1\x87\xa4\xf4\xdf" },
     901             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     902             :             16,
     903             :             "\xc0\x4b\x05\x35\x7c\x5d\x1c\x0e\xea\xc4\xc6\x6f\x9f\xf7\xf2\xe6" },
     904             :         }
     905             :       },
     906             :       { GCRY_CIPHER_AES192, 0,
     907             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b"
     908             :         "\x80\x90\x79\xe5\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
     909             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
     910             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     911             :             16,
     912             :             "\xcd\xc8\x0d\x6f\xdd\xf1\x8c\xab\x34\xc2\x59\x09\xc9\x9a\x41\x74" },
     913             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     914             :             16,
     915             :             "\x67\xce\x7f\x7f\x81\x17\x36\x21\x96\x1a\x2b\x70\x17\x1d\x3d\x7a" },
     916             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     917             :             16,
     918             :             "\x2e\x1e\x8a\x1d\xd5\x9b\x88\xb1\xc8\xe6\x0f\xed\x1e\xfa\xc4\xc9" },
     919             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     920             :             16,
     921             :             "\xc0\x5f\x9f\x9c\xa9\x83\x4f\xa0\x42\xae\x8f\xba\x58\x4b\x09\xff" },
     922             :         }
     923             :       },
     924             :       { GCRY_CIPHER_AES256, 0,
     925             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
     926             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
     927             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
     928             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
     929             :             16,
     930             :             "\xdc\x7e\x84\xbf\xda\x79\x16\x4b\x7e\xcd\x84\x86\x98\x5d\x38\x60" },
     931             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
     932             :             16,
     933             :             "\x39\xff\xed\x14\x3b\x28\xb1\xc8\x32\x11\x3c\x63\x31\xe5\x40\x7b" },
     934             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
     935             :             16,
     936             :             "\xdf\x10\x13\x24\x15\xe5\x4b\x92\xa1\x3e\xd0\xa8\x26\x7a\xe2\xf9" },
     937             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
     938             :             16,
     939             :             "\x75\xa3\x85\x74\x1a\xb9\xce\xf8\x20\x31\x62\x3d\x55\xb1\xe4\x71" }
     940             :         }
     941             :       }
     942             :     };
     943             :   gcry_cipher_hd_t hde, hdd;
     944             :   unsigned char out[MAX_DATA_LEN];
     945             :   int i, j, keylen, blklen, mode;
     946           1 :   gcry_error_t err = 0;
     947             : 
     948           1 :   if (verbose)
     949           0 :     fprintf (stderr, "  Starting CFB checks.\n");
     950             : 
     951           4 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
     952             :     {
     953           3 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
     954             :         {
     955           0 :           if (verbose)
     956           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
     957             :                      tv[i].algo);
     958           0 :           continue;
     959             :         }
     960             : 
     961           3 :       mode = tv[i].cfb8? GCRY_CIPHER_MODE_CFB8 : GCRY_CIPHER_MODE_CFB;
     962             : 
     963           3 :       if (verbose)
     964           0 :         fprintf (stderr, "    checking CFB mode for %s [%i]\n",
     965             :                  gcry_cipher_algo_name (tv[i].algo),
     966             :                  tv[i].algo);
     967           3 :       err = gcry_cipher_open (&hde, tv[i].algo, mode, 0);
     968           3 :       if (!err)
     969           3 :         err = gcry_cipher_open (&hdd, tv[i].algo, mode, 0);
     970           3 :       if (err)
     971             :         {
     972           0 :           fail ("aes-cfb, gcry_cipher_open failed: %s\n", gpg_strerror (err));
     973           0 :           return;
     974             :         }
     975             : 
     976           3 :       keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
     977           3 :       if (!keylen)
     978             :         {
     979           0 :           fail ("aes-cfb, gcry_cipher_get_algo_keylen failed\n");
     980           0 :           return;
     981             :         }
     982             : 
     983           3 :       err = gcry_cipher_setkey (hde, tv[i].key, keylen);
     984           3 :       if (!err)
     985           3 :         err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
     986           3 :       if (err)
     987             :         {
     988           0 :           fail ("aes-cfb, gcry_cipher_setkey failed: %s\n",
     989             :                 gpg_strerror (err));
     990           0 :           gcry_cipher_close (hde);
     991           0 :           gcry_cipher_close (hdd);
     992           0 :           return;
     993             :         }
     994             : 
     995           3 :       blklen = gcry_cipher_get_algo_blklen(tv[i].algo);
     996           3 :       if (!blklen)
     997             :         {
     998           0 :           fail ("aes-cfb, gcry_cipher_get_algo_blklen failed\n");
     999           0 :           return;
    1000             :         }
    1001             : 
    1002           3 :       err = gcry_cipher_setiv (hde, tv[i].iv, blklen);
    1003           3 :       if (!err)
    1004           3 :         err = gcry_cipher_setiv (hdd, tv[i].iv, blklen);
    1005           3 :       if (err)
    1006             :         {
    1007           0 :           fail ("aes-cfb, gcry_cipher_setiv failed: %s\n",
    1008             :                 gpg_strerror (err));
    1009           0 :           gcry_cipher_close (hde);
    1010           0 :           gcry_cipher_close (hdd);
    1011           0 :           return;
    1012             :         }
    1013             : 
    1014          15 :       for (j = 0; tv[i].data[j].inlen; j++)
    1015             :         {
    1016          24 :           err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
    1017          12 :                                      tv[i].data[j].plaintext,
    1018          12 :                                      tv[i].data[j].inlen);
    1019          12 :           if (err)
    1020             :             {
    1021           0 :               fail ("aes-cfb, gcry_cipher_encrypt (%d, %d) failed: %s\n",
    1022             :                     i, j, gpg_strerror (err));
    1023           0 :               gcry_cipher_close (hde);
    1024           0 :               gcry_cipher_close (hdd);
    1025           0 :               return;
    1026             :             }
    1027             : 
    1028          12 :           if (memcmp (tv[i].data[j].out, out, tv[i].data[j].inlen)) {
    1029           0 :             fail ("aes-cfb, encrypt mismatch entry %d:%d\n", i, j);
    1030             :           }
    1031          12 :           err = gcry_cipher_decrypt (hdd, out, tv[i].data[j].inlen, NULL, 0);
    1032          12 :           if (err)
    1033             :             {
    1034           0 :               fail ("aes-cfb, gcry_cipher_decrypt (%d, %d) failed: %s\n",
    1035             :                     i, j, gpg_strerror (err));
    1036           0 :               gcry_cipher_close (hde);
    1037           0 :               gcry_cipher_close (hdd);
    1038           0 :               return;
    1039             :             }
    1040             : 
    1041          12 :           if (memcmp (tv[i].data[j].plaintext, out, tv[i].data[j].inlen))
    1042           0 :             fail ("aes-cfb, decrypt mismatch entry %d:%d\n", i, j);
    1043             :         }
    1044             : 
    1045           3 :       gcry_cipher_close (hde);
    1046           3 :       gcry_cipher_close (hdd);
    1047             :     }
    1048           1 :   if (verbose)
    1049           0 :     fprintf (stderr, "  Completed CFB checks.\n");
    1050             : }
    1051             : 
    1052             : static void
    1053           1 : check_ofb_cipher (void)
    1054             : {
    1055             :   static const struct tv
    1056             :   {
    1057             :     int algo;
    1058             :     char key[MAX_DATA_LEN];
    1059             :     char iv[MAX_DATA_LEN];
    1060             :     struct data
    1061             :     {
    1062             :       unsigned char plaintext[MAX_DATA_LEN];
    1063             :       int inlen;
    1064             :       char out[MAX_DATA_LEN];
    1065             :     }
    1066             :     data[MAX_DATA_LEN];
    1067             :   } tv[] =
    1068             :     {
    1069             :       /* http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf */
    1070             :       { GCRY_CIPHER_AES,
    1071             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    1072             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
    1073             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    1074             :             16,
    1075             :             "\x3b\x3f\xd9\x2e\xb7\x2d\xad\x20\x33\x34\x49\xf8\xe8\x3c\xfb\x4a" },
    1076             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
    1077             :             16,
    1078             :             "\x77\x89\x50\x8d\x16\x91\x8f\x03\xf5\x3c\x52\xda\xc5\x4e\xd8\x25"},
    1079             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
    1080             :             16,
    1081             :             "\x97\x40\x05\x1e\x9c\x5f\xec\xf6\x43\x44\xf7\xa8\x22\x60\xed\xcc" },
    1082             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    1083             :             16,
    1084             :             "\x30\x4c\x65\x28\xf6\x59\xc7\x78\x66\xa5\x10\xd9\xc1\xd6\xae\x5e" },
    1085             :         }
    1086             :       },
    1087             :       { GCRY_CIPHER_AES192,
    1088             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b"
    1089             :         "\x80\x90\x79\xe5\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
    1090             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
    1091             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    1092             :             16,
    1093             :             "\xcd\xc8\x0d\x6f\xdd\xf1\x8c\xab\x34\xc2\x59\x09\xc9\x9a\x41\x74" },
    1094             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
    1095             :             16,
    1096             :             "\xfc\xc2\x8b\x8d\x4c\x63\x83\x7c\x09\xe8\x17\x00\xc1\x10\x04\x01" },
    1097             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
    1098             :             16,
    1099             :             "\x8d\x9a\x9a\xea\xc0\xf6\x59\x6f\x55\x9c\x6d\x4d\xaf\x59\xa5\xf2" },
    1100             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    1101             :             16,
    1102             :             "\x6d\x9f\x20\x08\x57\xca\x6c\x3e\x9c\xac\x52\x4b\xd9\xac\xc9\x2a" },
    1103             :         }
    1104             :       },
    1105             :       { GCRY_CIPHER_AES256,
    1106             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
    1107             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
    1108             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
    1109             :         { { "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    1110             :             16,
    1111             :             "\xdc\x7e\x84\xbf\xda\x79\x16\x4b\x7e\xcd\x84\x86\x98\x5d\x38\x60" },
    1112             :           { "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
    1113             :             16,
    1114             :             "\x4f\xeb\xdc\x67\x40\xd2\x0b\x3a\xc8\x8f\x6a\xd8\x2a\x4f\xb0\x8d" },
    1115             :           { "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef",
    1116             :             16,
    1117             :             "\x71\xab\x47\xa0\x86\xe8\x6e\xed\xf3\x9d\x1c\x5b\xba\x97\xc4\x08" },
    1118             :           { "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    1119             :             16,
    1120             :             "\x01\x26\x14\x1d\x67\xf3\x7b\xe8\x53\x8f\x5a\x8b\xe7\x40\xe4\x84" }
    1121             :         }
    1122             :       }
    1123             :     };
    1124             :   gcry_cipher_hd_t hde, hdd;
    1125             :   unsigned char out[MAX_DATA_LEN];
    1126             :   int i, j, keylen, blklen;
    1127           1 :   gcry_error_t err = 0;
    1128             : 
    1129           1 :   if (verbose)
    1130           0 :     fprintf (stderr, "  Starting OFB checks.\n");
    1131             : 
    1132           4 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    1133             :     {
    1134           3 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
    1135             :         {
    1136           0 :           if (verbose)
    1137           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    1138             :                      tv[i].algo);
    1139           0 :           continue;
    1140             :         }
    1141             : 
    1142           3 :       if (verbose)
    1143           0 :         fprintf (stderr, "    checking OFB mode for %s [%i]\n",
    1144             :                  gcry_cipher_algo_name (tv[i].algo),
    1145             :                  tv[i].algo);
    1146           3 :       err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_OFB, 0);
    1147           3 :       if (!err)
    1148           3 :         err = gcry_cipher_open (&hdd, tv[i].algo, GCRY_CIPHER_MODE_OFB, 0);
    1149           3 :       if (err)
    1150             :         {
    1151           0 :           fail ("aes-ofb, gcry_cipher_open failed: %s\n", gpg_strerror (err));
    1152           0 :           return;
    1153             :         }
    1154             : 
    1155           3 :       keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
    1156           3 :       if (!keylen)
    1157             :         {
    1158           0 :           fail ("aes-ofb, gcry_cipher_get_algo_keylen failed\n");
    1159           0 :           return;
    1160             :         }
    1161             : 
    1162           3 :       err = gcry_cipher_setkey (hde, tv[i].key, keylen);
    1163           3 :       if (!err)
    1164           3 :         err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
    1165           3 :       if (err)
    1166             :         {
    1167           0 :           fail ("aes-ofb, gcry_cipher_setkey failed: %s\n",
    1168             :                 gpg_strerror (err));
    1169           0 :           gcry_cipher_close (hde);
    1170           0 :           gcry_cipher_close (hdd);
    1171           0 :           return;
    1172             :         }
    1173             : 
    1174           3 :       blklen = gcry_cipher_get_algo_blklen(tv[i].algo);
    1175           3 :       if (!blklen)
    1176             :         {
    1177           0 :           fail ("aes-ofb, gcry_cipher_get_algo_blklen failed\n");
    1178           0 :           return;
    1179             :         }
    1180             : 
    1181           3 :       err = gcry_cipher_setiv (hde, tv[i].iv, blklen);
    1182           3 :       if (!err)
    1183           3 :         err = gcry_cipher_setiv (hdd, tv[i].iv, blklen);
    1184           3 :       if (err)
    1185             :         {
    1186           0 :           fail ("aes-ofb, gcry_cipher_setiv failed: %s\n",
    1187             :                 gpg_strerror (err));
    1188           0 :           gcry_cipher_close (hde);
    1189           0 :           gcry_cipher_close (hdd);
    1190           0 :           return;
    1191             :         }
    1192             : 
    1193          15 :       for (j = 0; tv[i].data[j].inlen; j++)
    1194             :         {
    1195          24 :           err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
    1196          12 :                                      tv[i].data[j].plaintext,
    1197          12 :                                      tv[i].data[j].inlen);
    1198          12 :           if (err)
    1199             :             {
    1200           0 :               fail ("aes-ofb, gcry_cipher_encrypt (%d, %d) failed: %s\n",
    1201             :                     i, j, gpg_strerror (err));
    1202           0 :               gcry_cipher_close (hde);
    1203           0 :               gcry_cipher_close (hdd);
    1204           0 :               return;
    1205             :             }
    1206             : 
    1207          12 :           if (memcmp (tv[i].data[j].out, out, tv[i].data[j].inlen))
    1208           0 :             fail ("aes-ofb, encrypt mismatch entry %d:%d\n", i, j);
    1209             : 
    1210          12 :           err = gcry_cipher_decrypt (hdd, out, tv[i].data[j].inlen, NULL, 0);
    1211          12 :           if (err)
    1212             :             {
    1213           0 :               fail ("aes-ofb, gcry_cipher_decrypt (%d, %d) failed: %s\n",
    1214             :                     i, j, gpg_strerror (err));
    1215           0 :               gcry_cipher_close (hde);
    1216           0 :               gcry_cipher_close (hdd);
    1217           0 :               return;
    1218             :             }
    1219             : 
    1220          12 :           if (memcmp (tv[i].data[j].plaintext, out, tv[i].data[j].inlen))
    1221           0 :             fail ("aes-ofb, decrypt mismatch entry %d:%d\n", i, j);
    1222             :         }
    1223             : 
    1224           3 :       err = gcry_cipher_reset(hde);
    1225           3 :       if (!err)
    1226           3 :         err = gcry_cipher_reset(hdd);
    1227           3 :       if (err)
    1228             :         {
    1229           0 :           fail ("aes-ofb, gcry_cipher_reset (%d, %d) failed: %s\n",
    1230             :                 i, j, gpg_strerror (err));
    1231           0 :           gcry_cipher_close (hde);
    1232           0 :           gcry_cipher_close (hdd);
    1233           0 :           return;
    1234             :         }
    1235             : 
    1236             :       /* gcry_cipher_reset clears the IV */
    1237           3 :       err = gcry_cipher_setiv (hde, tv[i].iv, blklen);
    1238           3 :       if (!err)
    1239           3 :         err = gcry_cipher_setiv (hdd, tv[i].iv, blklen);
    1240           3 :       if (err)
    1241             :         {
    1242           0 :           fail ("aes-ofb, gcry_cipher_setiv failed: %s\n",
    1243             :                 gpg_strerror (err));
    1244           0 :           gcry_cipher_close (hde);
    1245           0 :           gcry_cipher_close (hdd);
    1246           0 :           return;
    1247             :         }
    1248             : 
    1249             :       /* this time we encrypt and decrypt one byte at a time */
    1250          15 :       for (j = 0; tv[i].data[j].inlen; j++)
    1251             :         {
    1252             :           int byteNum;
    1253         204 :           for (byteNum = 0; byteNum < tv[i].data[j].inlen; ++byteNum)
    1254             :             {
    1255         192 :               err = gcry_cipher_encrypt (hde, out+byteNum, 1,
    1256         192 :                                          (tv[i].data[j].plaintext) + byteNum,
    1257             :                                          1);
    1258         192 :               if (err)
    1259             :                 {
    1260           0 :                   fail ("aes-ofb, gcry_cipher_encrypt (%d, %d) failed: %s\n",
    1261             :                         i, j, gpg_strerror (err));
    1262           0 :                   gcry_cipher_close (hde);
    1263           0 :                   gcry_cipher_close (hdd);
    1264           0 :                   return;
    1265             :                 }
    1266             :             }
    1267             : 
    1268          12 :           if (memcmp (tv[i].data[j].out, out, tv[i].data[j].inlen))
    1269           0 :             fail ("aes-ofb, encrypt mismatch entry %d:%d\n", i, j);
    1270             : 
    1271         204 :           for (byteNum = 0; byteNum < tv[i].data[j].inlen; ++byteNum)
    1272             :             {
    1273         192 :               err = gcry_cipher_decrypt (hdd, out+byteNum, 1, NULL, 0);
    1274         192 :               if (err)
    1275             :                 {
    1276           0 :                   fail ("aes-ofb, gcry_cipher_decrypt (%d, %d) failed: %s\n",
    1277             :                         i, j, gpg_strerror (err));
    1278           0 :                   gcry_cipher_close (hde);
    1279           0 :                   gcry_cipher_close (hdd);
    1280           0 :                   return;
    1281             :                 }
    1282             :             }
    1283             : 
    1284          12 :           if (memcmp (tv[i].data[j].plaintext, out, tv[i].data[j].inlen))
    1285           0 :             fail ("aes-ofb, decrypt mismatch entry %d:%d\n", i, j);
    1286             :         }
    1287             : 
    1288           3 :       gcry_cipher_close (hde);
    1289           3 :       gcry_cipher_close (hdd);
    1290             :     }
    1291           1 :   if (verbose)
    1292           0 :     fprintf (stderr, "  Completed OFB checks.\n");
    1293             : }
    1294             : 
    1295             : static void
    1296           4 : _check_gcm_cipher (unsigned int step)
    1297             : {
    1298             :   struct tv
    1299             :   {
    1300             :     int algo;
    1301             :     char key[MAX_DATA_LEN];
    1302             :     char iv[MAX_DATA_LEN];
    1303             :     int ivlen;
    1304             :     unsigned char aad[MAX_DATA_LEN];
    1305             :     int aadlen;
    1306             :     unsigned char plaintext[MAX_DATA_LEN];
    1307             :     int inlen;
    1308             :     char out[MAX_DATA_LEN];
    1309             :     char tag[MAX_DATA_LEN];
    1310             :     int taglen;
    1311             :     int should_fail;
    1312           4 :   } tv[] =
    1313             :     {
    1314             :       /* http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf */
    1315             :       { GCRY_CIPHER_AES,
    1316             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1317             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1318             :         "", 0,
    1319             :         "",
    1320             :         0,
    1321             :         "",
    1322             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7\x45\x5a" },
    1323             :       { GCRY_CIPHER_AES,
    1324             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1325             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1326             :         "", 0,
    1327             :         "",
    1328             :         0,
    1329             :         "",
    1330             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7\x45",
    1331             :         15 },
    1332             :       { GCRY_CIPHER_AES,
    1333             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1334             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1335             :         "", 0,
    1336             :         "",
    1337             :         0,
    1338             :         "",
    1339             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7",
    1340             :         14 },
    1341             :       { GCRY_CIPHER_AES,
    1342             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1343             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1344             :         "", 0,
    1345             :         "",
    1346             :         0,
    1347             :         "",
    1348             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4",
    1349             :         13 },
    1350             :       { GCRY_CIPHER_AES,
    1351             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1352             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1353             :         "", 0,
    1354             :         "",
    1355             :         0,
    1356             :         "",
    1357             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57",
    1358             :         12 },
    1359             :       { GCRY_CIPHER_AES,
    1360             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1361             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1362             :         "", 0,
    1363             :         "",
    1364             :         0,
    1365             :         "",
    1366             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d",
    1367             :         11, 1 },
    1368             :       { GCRY_CIPHER_AES,
    1369             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1370             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1371             :         "", 0,
    1372             :         "",
    1373             :         0,
    1374             :         "",
    1375             :         "\x58\xe2\xfc\xce\xfa\x7e\x30\x61",
    1376             :         8 },
    1377             :       { GCRY_CIPHER_AES,
    1378             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1379             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1380             :         "", 0,
    1381             :         "",
    1382             :         0,
    1383             :         "",
    1384             :         "\x58\xe2\xfc\xce",
    1385             :         4 },
    1386             :       { GCRY_CIPHER_AES,
    1387             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1388             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1389             :         "", 0,
    1390             :         "",
    1391             :         0,
    1392             :         "",
    1393             :         "\x58",
    1394             :         1, 1 },
    1395             :       { GCRY_CIPHER_AES,
    1396             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1397             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 12,
    1398             :         "", 0,
    1399             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    1400             :         16,
    1401             :         "\x03\x88\xda\xce\x60\xb6\xa3\x92\xf3\x28\xc2\xb9\x71\xb2\xfe\x78",
    1402             :         "\xab\x6e\x47\xd4\x2c\xec\x13\xbd\xf5\x3a\x67\xb2\x12\x57\xbd\xdf" },
    1403             :       { GCRY_CIPHER_AES,
    1404             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
    1405             :         "\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88", 12,
    1406             :         "", 0,
    1407             :         "\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
    1408             :         "\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72"
    1409             :         "\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25"
    1410             :         "\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39\x1a\xaf\xd2\x55",
    1411             :         64,
    1412             :         "\x42\x83\x1e\xc2\x21\x77\x74\x24\x4b\x72\x21\xb7\x84\xd0\xd4\x9c"
    1413             :         "\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0\x35\xc1\x7e\x23\x29\xac\xa1\x2e"
    1414             :         "\x21\xd5\x14\xb2\x54\x66\x93\x1c\x7d\x8f\x6a\x5a\xac\x84\xaa\x05"
    1415             :         "\x1b\xa3\x0b\x39\x6a\x0a\xac\x97\x3d\x58\xe0\x91\x47\x3f\x59\x85",
    1416             :         "\x4d\x5c\x2a\xf3\x27\xcd\x64\xa6\x2c\xf3\x5a\xbd\x2b\xa6\xfa\xb4" },
    1417             :       { GCRY_CIPHER_AES,
    1418             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
    1419             :         "\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88", 12,
    1420             :         "\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef"
    1421             :         "\xab\xad\xda\xd2", 20,
    1422             :         "\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
    1423             :         "\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72"
    1424             :         "\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25"
    1425             :         "\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
    1426             :         60,
    1427             :         "\x42\x83\x1e\xc2\x21\x77\x74\x24\x4b\x72\x21\xb7\x84\xd0\xd4\x9c"
    1428             :         "\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0\x35\xc1\x7e\x23\x29\xac\xa1\x2e"
    1429             :         "\x21\xd5\x14\xb2\x54\x66\x93\x1c\x7d\x8f\x6a\x5a\xac\x84\xaa\x05"
    1430             :         "\x1b\xa3\x0b\x39\x6a\x0a\xac\x97\x3d\x58\xe0\x91\x47\x3f\x59\x85",
    1431             :         "\x5b\xc9\x4f\xbc\x32\x21\xa5\xdb\x94\xfa\xe9\x5a\xe7\x12\x1a\x47" },
    1432             :       { GCRY_CIPHER_AES,
    1433             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
    1434             :         "\xca\xfe\xba\xbe\xfa\xce\xdb\xad", 8,
    1435             :         "\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef"
    1436             :         "\xab\xad\xda\xd2", 20,
    1437             :         "\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
    1438             :         "\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72"
    1439             :         "\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25"
    1440             :         "\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
    1441             :         60,
    1442             :         "\x61\x35\x3b\x4c\x28\x06\x93\x4a\x77\x7f\xf5\x1f\xa2\x2a\x47\x55"
    1443             :         "\x69\x9b\x2a\x71\x4f\xcd\xc6\xf8\x37\x66\xe5\xf9\x7b\x6c\x74\x23"
    1444             :         "\x73\x80\x69\x00\xe4\x9f\x24\xb2\x2b\x09\x75\x44\xd4\x89\x6b\x42"
    1445             :         "\x49\x89\xb5\xe1\xeb\xac\x0f\x07\xc2\x3f\x45\x98",
    1446             :         "\x36\x12\xd2\xe7\x9e\x3b\x07\x85\x56\x1b\xe1\x4a\xac\xa2\xfc\xcb" },
    1447             :       { GCRY_CIPHER_AES,
    1448             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
    1449             :         "\x93\x13\x22\x5d\xf8\x84\x06\xe5\x55\x90\x9c\x5a\xff\x52\x69\xaa"
    1450             :         "\x6a\x7a\x95\x38\x53\x4f\x7d\xa1\xe4\xc3\x03\xd2\xa3\x18\xa7\x28"
    1451             :         "\xc3\xc0\xc9\x51\x56\x80\x95\x39\xfc\xf0\xe2\x42\x9a\x6b\x52\x54"
    1452             :         "\x16\xae\xdb\xf5\xa0\xde\x6a\x57\xa6\x37\xb3\x9b", 60,
    1453             :         "\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef"
    1454             :         "\xab\xad\xda\xd2", 20,
    1455             :         "\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
    1456             :         "\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72"
    1457             :         "\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25"
    1458             :         "\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
    1459             :         60,
    1460             :         "\x8c\xe2\x49\x98\x62\x56\x15\xb6\x03\xa0\x33\xac\xa1\x3f\xb8\x94"
    1461             :         "\xbe\x91\x12\xa5\xc3\xa2\x11\xa8\xba\x26\x2a\x3c\xca\x7e\x2c\xa7"
    1462             :         "\x01\xe4\xa9\xa4\xfb\xa4\x3c\x90\xcc\xdc\xb2\x81\xd4\x8c\x7c\x6f"
    1463             :         "\xd6\x28\x75\xd2\xac\xa4\x17\x03\x4c\x34\xae\xe5",
    1464             :         "\x61\x9c\xc5\xae\xff\xfe\x0b\xfa\x46\x2a\xf4\x3c\x16\x99\xd0\x50" },
    1465             :       { GCRY_CIPHER_AES192,
    1466             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08"
    1467             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c",
    1468             :         "\x93\x13\x22\x5d\xf8\x84\x06\xe5\x55\x90\x9c\x5a\xff\x52\x69\xaa"
    1469             :         "\x6a\x7a\x95\x38\x53\x4f\x7d\xa1\xe4\xc3\x03\xd2\xa3\x18\xa7\x28"
    1470             :         "\xc3\xc0\xc9\x51\x56\x80\x95\x39\xfc\xf0\xe2\x42\x9a\x6b\x52\x54"
    1471             :         "\x16\xae\xdb\xf5\xa0\xde\x6a\x57\xa6\x37\xb3\x9b", 60,
    1472             :         "\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef"
    1473             :         "\xab\xad\xda\xd2", 20,
    1474             :         "\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
    1475             :         "\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72"
    1476             :         "\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25"
    1477             :         "\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
    1478             :         60,
    1479             :         "\xd2\x7e\x88\x68\x1c\xe3\x24\x3c\x48\x30\x16\x5a\x8f\xdc\xf9\xff"
    1480             :         "\x1d\xe9\xa1\xd8\xe6\xb4\x47\xef\x6e\xf7\xb7\x98\x28\x66\x6e\x45"
    1481             :         "\x81\xe7\x90\x12\xaf\x34\xdd\xd9\xe2\xf0\x37\x58\x9b\x29\x2d\xb3"
    1482             :         "\xe6\x7c\x03\x67\x45\xfa\x22\xe7\xe9\xb7\x37\x3b",
    1483             :         "\xdc\xf5\x66\xff\x29\x1c\x25\xbb\xb8\x56\x8f\xc3\xd3\x76\xa6\xd9" },
    1484             :       { GCRY_CIPHER_AES256,
    1485             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08"
    1486             :         "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
    1487             :         "\x93\x13\x22\x5d\xf8\x84\x06\xe5\x55\x90\x9c\x5a\xff\x52\x69\xaa"
    1488             :         "\x6a\x7a\x95\x38\x53\x4f\x7d\xa1\xe4\xc3\x03\xd2\xa3\x18\xa7\x28"
    1489             :         "\xc3\xc0\xc9\x51\x56\x80\x95\x39\xfc\xf0\xe2\x42\x9a\x6b\x52\x54"
    1490             :         "\x16\xae\xdb\xf5\xa0\xde\x6a\x57\xa6\x37\xb3\x9b", 60,
    1491             :         "\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef"
    1492             :         "\xab\xad\xda\xd2", 20,
    1493             :         "\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
    1494             :         "\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72"
    1495             :         "\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25"
    1496             :         "\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
    1497             :         60,
    1498             :         "\x5a\x8d\xef\x2f\x0c\x9e\x53\xf1\xf7\x5d\x78\x53\x65\x9e\x2a\x20"
    1499             :         "\xee\xb2\xb2\x2a\xaf\xde\x64\x19\xa0\x58\xab\x4f\x6f\x74\x6b\xf4"
    1500             :         "\x0f\xc0\xc3\xb7\x80\xf2\x44\x45\x2d\xa3\xeb\xf1\xc5\xd8\x2c\xde"
    1501             :         "\xa2\x41\x89\x97\x20\x0e\xf8\x2e\x44\xae\x7e\x3f",
    1502             :         "\xa4\x4a\x82\x66\xee\x1c\x8e\xb0\xc8\xb5\xd4\xcf\x5a\xe9\xf1\x9a" }
    1503             :     };
    1504             : 
    1505             :   gcry_cipher_hd_t hde, hdd;
    1506             :   unsigned char out[MAX_DATA_LEN];
    1507             :   unsigned char tag[GCRY_GCM_BLOCK_LEN];
    1508             :   int i, keylen;
    1509           4 :   gcry_error_t err = 0;
    1510             :   size_t pos, poslen, taglen2;
    1511             :   int byteNum;
    1512             : 
    1513           4 :   if (verbose)
    1514           0 :     fprintf (stderr, "  Starting GCM checks.\n");
    1515             : 
    1516          68 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    1517             :     {
    1518          64 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
    1519             :         {
    1520           0 :           if (verbose)
    1521           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    1522             :                      tv[i].algo);
    1523           0 :           continue;
    1524             :         }
    1525             : 
    1526          64 :       if (verbose)
    1527           0 :         fprintf (stderr, "    checking GCM mode for %s [%i]\n",
    1528             :                  gcry_cipher_algo_name (tv[i].algo),
    1529             :                  tv[i].algo);
    1530          64 :       err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_GCM, 0);
    1531          64 :       if (!err)
    1532          64 :         err = gcry_cipher_open (&hdd, tv[i].algo, GCRY_CIPHER_MODE_GCM, 0);
    1533          64 :       if (err)
    1534             :         {
    1535           0 :           fail ("aes-gcm, gcry_cipher_open failed: %s\n", gpg_strerror (err));
    1536           0 :           return;
    1537             :         }
    1538             : 
    1539          64 :       keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
    1540          64 :       if (!keylen)
    1541             :         {
    1542           0 :           fail ("aes-gcm, gcry_cipher_get_algo_keylen failed\n");
    1543           0 :           return;
    1544             :         }
    1545             : 
    1546          64 :       err = gcry_cipher_setkey (hde, tv[i].key, keylen);
    1547          64 :       if (!err)
    1548          64 :         err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
    1549          64 :       if (err)
    1550             :         {
    1551           0 :           fail ("aes-gcm, gcry_cipher_setkey failed: %s\n",
    1552             :                 gpg_strerror (err));
    1553           0 :           gcry_cipher_close (hde);
    1554           0 :           gcry_cipher_close (hdd);
    1555           0 :           return;
    1556             :         }
    1557             : 
    1558          64 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    1559          64 :       if (!err)
    1560          64 :         err = gcry_cipher_setiv (hdd, tv[i].iv, tv[i].ivlen);
    1561          64 :       if (err)
    1562             :         {
    1563           0 :           fail ("aes-gcm, gcry_cipher_setiv failed: %s\n",
    1564             :                 gpg_strerror (err));
    1565           0 :           gcry_cipher_close (hde);
    1566           0 :           gcry_cipher_close (hdd);
    1567           0 :           return;
    1568             :         }
    1569             : 
    1570          64 :       err = gcry_cipher_info (hde, GCRYCTL_GET_TAGLEN, NULL, &taglen2);
    1571          64 :       if (err)
    1572             :         {
    1573           0 :           fail ("cipher-gcm, gcryctl_get_taglen failed (tv %d): %s\n",
    1574             :                 i, gpg_strerror (err));
    1575           0 :           gcry_cipher_close (hde);
    1576           0 :           gcry_cipher_close (hdd);
    1577           0 :           return;
    1578             :         }
    1579          64 :       if (taglen2 != GCRY_GCM_BLOCK_LEN)
    1580             :         {
    1581           0 :           fail ("cipher-gcm, gcryctl_get_taglen returned bad length"
    1582             :                 " (tv %d): got=%zu want=%d\n",
    1583             :                 i, taglen2, GCRY_GCM_BLOCK_LEN);
    1584           0 :           gcry_cipher_close (hde);
    1585           0 :           gcry_cipher_close (hdd);
    1586           0 :           return;
    1587             :         }
    1588             : 
    1589         194 :       for (pos = 0; pos < tv[i].aadlen; pos += step)
    1590             :         {
    1591         130 :           poslen = (pos + step < tv[i].aadlen) ? step : tv[i].aadlen - pos;
    1592             : 
    1593         130 :           err = gcry_cipher_authenticate(hde, tv[i].aad + pos, poslen);
    1594         130 :           if (err)
    1595             :             {
    1596           0 :               fail ("aes-gcm, gcry_cipher_authenticate (%d) (%d:%d) failed: "
    1597             :                     "%s\n", i, pos, step, gpg_strerror (err));
    1598           0 :               gcry_cipher_close (hde);
    1599           0 :               gcry_cipher_close (hdd);
    1600           0 :               return;
    1601             :             }
    1602         130 :           err = gcry_cipher_authenticate(hdd, tv[i].aad + pos, poslen);
    1603         130 :           if (err)
    1604             :             {
    1605           0 :               fail ("aes-gcm, de gcry_cipher_authenticate (%d) (%d:%d) failed: "
    1606             :                     "%s\n", i, pos, step, gpg_strerror (err));
    1607           0 :               gcry_cipher_close (hde);
    1608           0 :               gcry_cipher_close (hdd);
    1609           0 :               return;
    1610             :             }
    1611             :         }
    1612             : 
    1613         534 :       for (pos = 0; pos < tv[i].inlen; pos += step)
    1614             :         {
    1615         470 :           poslen = (pos + step < tv[i].inlen) ? step : tv[i].inlen - pos;
    1616             : 
    1617         470 :           err = gcry_cipher_encrypt (hde, out + pos, poslen,
    1618         470 :                                      tv[i].plaintext + pos, poslen);
    1619         470 :           if (err)
    1620             :             {
    1621           0 :               fail ("aes-gcm, gcry_cipher_encrypt (%d) (%d:%d) failed: %s\n",
    1622             :                     i, pos, step, gpg_strerror (err));
    1623           0 :               gcry_cipher_close (hde);
    1624           0 :               gcry_cipher_close (hdd);
    1625           0 :               return;
    1626             :             }
    1627             :         }
    1628             : 
    1629          64 :       if (memcmp (tv[i].out, out, tv[i].inlen))
    1630           0 :         fail ("aes-gcm, encrypt mismatch entry %d (step %d)\n", i, step);
    1631             : 
    1632         534 :       for (pos = 0; pos < tv[i].inlen; pos += step)
    1633             :         {
    1634         470 :           poslen = (pos + step < tv[i].inlen) ? step : tv[i].inlen - pos;
    1635             : 
    1636         470 :           err = gcry_cipher_decrypt (hdd, out + pos, poslen, NULL, 0);
    1637         470 :           if (err)
    1638             :             {
    1639           0 :               fail ("aes-gcm, gcry_cipher_decrypt (%d) (%d:%d) failed: %s\n",
    1640             :                     i, pos, step, gpg_strerror (err));
    1641           0 :               gcry_cipher_close (hde);
    1642           0 :               gcry_cipher_close (hdd);
    1643           0 :               return;
    1644             :             }
    1645             :         }
    1646             : 
    1647          64 :       if (memcmp (tv[i].plaintext, out, tv[i].inlen))
    1648           0 :         fail ("aes-gcm, decrypt mismatch entry %d (step %d)\n", i, step);
    1649             : 
    1650          64 :       taglen2 = tv[i].taglen ? tv[i].taglen : GCRY_GCM_BLOCK_LEN;
    1651             : 
    1652          64 :       err = gcry_cipher_gettag (hde, out, taglen2);
    1653          64 :       if (err)
    1654             :         {
    1655           8 :           if (tv[i].should_fail)
    1656           8 :             goto next_tv;
    1657             : 
    1658           0 :           fail ("aes-gcm, gcry_cipher_gettag(%d) failed: %s\n",
    1659             :                 i, gpg_strerror (err));
    1660           0 :           gcry_cipher_close (hde);
    1661           0 :           gcry_cipher_close (hdd);
    1662           0 :           return;
    1663             :         }
    1664             : 
    1665          56 :       if (memcmp (tv[i].tag, out, taglen2))
    1666           0 :         fail ("aes-gcm, encrypt tag mismatch entry %d\n", i);
    1667             : 
    1668          56 :       err = gcry_cipher_checktag (hdd, out, taglen2);
    1669          56 :       if (err)
    1670             :         {
    1671           0 :           fail ("aes-gcm, gcry_cipher_checktag(%d) failed: %s\n",
    1672             :                 i, gpg_strerror (err));
    1673           0 :           gcry_cipher_close (hde);
    1674           0 :           gcry_cipher_close (hdd);
    1675           0 :           return;
    1676             :         }
    1677             : 
    1678          56 :       err = gcry_cipher_reset(hde);
    1679          56 :       if (!err)
    1680          56 :         err = gcry_cipher_reset(hdd);
    1681          56 :       if (err)
    1682             :         {
    1683           0 :           fail ("aes-gcm, gcry_cipher_reset (%d) failed: %s\n",
    1684             :                 i, gpg_strerror (err));
    1685           0 :           gcry_cipher_close (hde);
    1686           0 :           gcry_cipher_close (hdd);
    1687           0 :           return;
    1688             :         }
    1689             : 
    1690             :       /* gcry_cipher_reset clears the IV */
    1691          56 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    1692          56 :       if (!err)
    1693          56 :         err = gcry_cipher_setiv (hdd, tv[i].iv, tv[i].ivlen);
    1694          56 :       if (err)
    1695             :         {
    1696           0 :           fail ("aes-gcm, gcry_cipher_setiv failed: %s\n",
    1697             :                 gpg_strerror (err));
    1698           0 :           gcry_cipher_close (hde);
    1699           0 :           gcry_cipher_close (hdd);
    1700           0 :           return;
    1701             :         }
    1702             : 
    1703             :       /* this time we authenticate, encrypt and decrypt one byte at a time */
    1704         456 :       for (byteNum = 0; byteNum < tv[i].aadlen; ++byteNum)
    1705             :         {
    1706         400 :           err = gcry_cipher_authenticate(hde, tv[i].aad + byteNum, 1);
    1707         400 :           if (err)
    1708             :             {
    1709           0 :               fail ("aes-gcm, gcry_cipher_authenticate (%d) (byte-buf) failed: "
    1710             :                     "%s\n", i, gpg_strerror (err));
    1711           0 :               gcry_cipher_close (hde);
    1712           0 :               gcry_cipher_close (hdd);
    1713           0 :               return;
    1714             :             }
    1715         400 :           err = gcry_cipher_authenticate(hdd, tv[i].aad + byteNum, 1);
    1716         400 :           if (err)
    1717             :             {
    1718           0 :               fail ("aes-gcm, de gcry_cipher_authenticate (%d) (byte-buf) "
    1719             :                     "failed: %s\n", i, gpg_strerror (err));
    1720           0 :               gcry_cipher_close (hde);
    1721           0 :               gcry_cipher_close (hdd);
    1722           0 :               return;
    1723             :             }
    1724             :         }
    1725             : 
    1726        1576 :       for (byteNum = 0; byteNum < tv[i].inlen; ++byteNum)
    1727             :         {
    1728        1520 :           err = gcry_cipher_encrypt (hde, out+byteNum, 1,
    1729        1520 :                                      (tv[i].plaintext) + byteNum,
    1730             :                                      1);
    1731        1520 :           if (err)
    1732             :             {
    1733           0 :               fail ("aes-gcm, gcry_cipher_encrypt (%d) (byte-buf) failed: %s\n",
    1734             :                     i,  gpg_strerror (err));
    1735           0 :               gcry_cipher_close (hde);
    1736           0 :               gcry_cipher_close (hdd);
    1737           0 :               return;
    1738             :             }
    1739             :         }
    1740             : 
    1741          56 :       if (memcmp (tv[i].out, out, tv[i].inlen))
    1742           0 :         fail ("aes-gcm, encrypt mismatch entry %d, (byte-buf)\n", i);
    1743             : 
    1744             :       /* Test output to larger than 16-byte buffer. */
    1745          56 :       taglen2 = tv[i].taglen ? tv[i].taglen : GCRY_GCM_BLOCK_LEN + 1;
    1746             : 
    1747          56 :       err = gcry_cipher_gettag (hde, tag, taglen2);
    1748          56 :       if (err)
    1749             :         {
    1750           0 :           if (tv[i].should_fail)
    1751           0 :             goto next_tv;
    1752             : 
    1753           0 :           fail ("aes-gcm, gcry_cipher_gettag(%d, %d) (byte-buf) failed: %s\n",
    1754             :                 i, taglen2, gpg_strerror (err));
    1755           0 :           gcry_cipher_close (hde);
    1756           0 :           gcry_cipher_close (hdd);
    1757           0 :           return;
    1758             :         }
    1759             : 
    1760          56 :       taglen2 = tv[i].taglen ? tv[i].taglen : GCRY_GCM_BLOCK_LEN;
    1761             : 
    1762          56 :       if (memcmp (tv[i].tag, tag, taglen2))
    1763           0 :         fail ("aes-gcm, encrypt tag mismatch entry %d, (byte-buf)\n", i);
    1764             : 
    1765        1576 :       for (byteNum = 0; byteNum < tv[i].inlen; ++byteNum)
    1766             :         {
    1767        1520 :           err = gcry_cipher_decrypt (hdd, out+byteNum, 1, NULL, 0);
    1768        1520 :           if (err)
    1769             :             {
    1770           0 :               fail ("aes-gcm, gcry_cipher_decrypt (%d) (byte-buf) failed: %s\n",
    1771             :                     i, gpg_strerror (err));
    1772           0 :               gcry_cipher_close (hde);
    1773           0 :               gcry_cipher_close (hdd);
    1774           0 :               return;
    1775             :             }
    1776             :         }
    1777             : 
    1778          56 :       if (memcmp (tv[i].plaintext, out, tv[i].inlen))
    1779           0 :         fail ("aes-gcm, decrypt mismatch entry %d\n", i);
    1780             : 
    1781          56 :       err = gcry_cipher_checktag (hdd, tag, taglen2);
    1782          56 :       if (err)
    1783             :         {
    1784           0 :           fail ("aes-gcm, gcry_cipher_checktag(%d) (byte-buf) failed: %s\n",
    1785             :                 i, gpg_strerror (err));
    1786           0 :           gcry_cipher_close (hde);
    1787           0 :           gcry_cipher_close (hdd);
    1788           0 :           return;
    1789             :         }
    1790             : 
    1791          56 :       err = gcry_cipher_checktag (hdd, tag, 1);
    1792          56 :       if (!err)
    1793             :         {
    1794           0 :           fail ("aes-gcm, gcry_cipher_checktag(%d) did not fail for invalid "
    1795             :                 " tag length of '%d'\n", i, 1);
    1796           0 :           gcry_cipher_close (hde);
    1797           0 :           gcry_cipher_close (hdd);
    1798           0 :           return;
    1799             :         }
    1800          56 :       err = gcry_cipher_checktag (hdd, tag, 17);
    1801          56 :       if (!err)
    1802             :         {
    1803           0 :           fail ("aes-gcm, gcry_cipher_checktag(%d) did not fail for invalid "
    1804             :                 " tag length of '%d'\n", i, 17);
    1805           0 :           gcry_cipher_close (hde);
    1806           0 :           gcry_cipher_close (hdd);
    1807           0 :           return;
    1808             :         }
    1809             : 
    1810          56 :       if (tv[i].should_fail)
    1811             :         {
    1812           0 :           fail ("aes-gcm, negative test succeeded %d\n", i);
    1813           0 :           gcry_cipher_close (hde);
    1814           0 :           gcry_cipher_close (hdd);
    1815           0 :           return;
    1816             :         }
    1817             : 
    1818             :     next_tv:
    1819          64 :       gcry_cipher_close (hde);
    1820          64 :       gcry_cipher_close (hdd);
    1821             :     }
    1822           4 :   if (verbose)
    1823           0 :     fprintf (stderr, "  Completed GCM checks.\n");
    1824             : }
    1825             : 
    1826             : 
    1827             : static void
    1828           1 : check_gcm_cipher (void)
    1829             : {
    1830             :   /* Large buffers, no splitting. */
    1831           1 :   _check_gcm_cipher(0xffffffff);
    1832             :   /* Split input to one byte buffers. */
    1833           1 :   _check_gcm_cipher(1);
    1834             :   /* Split input to 7 byte buffers. */
    1835           1 :   _check_gcm_cipher(7);
    1836             :   /* Split input to 16 byte buffers. */
    1837           1 :   _check_gcm_cipher(16);
    1838           1 : }
    1839             : 
    1840             : 
    1841             : static void
    1842           4 : _check_poly1305_cipher (unsigned int step)
    1843             : {
    1844             :   struct tv
    1845             :   {
    1846             :     int algo;
    1847             :     const char *key;
    1848             :     const char *iv;
    1849             :     int ivlen;
    1850             :     const char *aad;
    1851             :     int aadlen;
    1852             :     const char *plaintext;
    1853             :     int inlen;
    1854             :     const char *out;
    1855             :     const char *tag;
    1856           4 :   } tv[] =
    1857             :     {
    1858             :       /* draft-irtf-cfrg-chacha20-poly1305-03 */
    1859             :       { GCRY_CIPHER_CHACHA20,
    1860             :         "\x1c\x92\x40\xa5\xeb\x55\xd3\x8a\xf3\x33\x88\x86\x04\xf6\xb5\xf0"
    1861             :         "\x47\x39\x17\xc1\x40\x2b\x80\x09\x9d\xca\x5c\xbc\x20\x70\x75\xc0",
    1862             :         "\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08", 12,
    1863             :         "\xf3\x33\x88\x86\x00\x00\x00\x00\x00\x00\x4e\x91", 12,
    1864             :         "\x49\x6e\x74\x65\x72\x6e\x65\x74\x2d\x44\x72\x61\x66\x74\x73\x20"
    1865             :         "\x61\x72\x65\x20\x64\x72\x61\x66\x74\x20\x64\x6f\x63\x75\x6d\x65"
    1866             :         "\x6e\x74\x73\x20\x76\x61\x6c\x69\x64\x20\x66\x6f\x72\x20\x61\x20"
    1867             :         "\x6d\x61\x78\x69\x6d\x75\x6d\x20\x6f\x66\x20\x73\x69\x78\x20\x6d"
    1868             :         "\x6f\x6e\x74\x68\x73\x20\x61\x6e\x64\x20\x6d\x61\x79\x20\x62\x65"
    1869             :         "\x20\x75\x70\x64\x61\x74\x65\x64\x2c\x20\x72\x65\x70\x6c\x61\x63"
    1870             :         "\x65\x64\x2c\x20\x6f\x72\x20\x6f\x62\x73\x6f\x6c\x65\x74\x65\x64"
    1871             :         "\x20\x62\x79\x20\x6f\x74\x68\x65\x72\x20\x64\x6f\x63\x75\x6d\x65"
    1872             :         "\x6e\x74\x73\x20\x61\x74\x20\x61\x6e\x79\x20\x74\x69\x6d\x65\x2e"
    1873             :         "\x20\x49\x74\x20\x69\x73\x20\x69\x6e\x61\x70\x70\x72\x6f\x70\x72"
    1874             :         "\x69\x61\x74\x65\x20\x74\x6f\x20\x75\x73\x65\x20\x49\x6e\x74\x65"
    1875             :         "\x72\x6e\x65\x74\x2d\x44\x72\x61\x66\x74\x73\x20\x61\x73\x20\x72"
    1876             :         "\x65\x66\x65\x72\x65\x6e\x63\x65\x20\x6d\x61\x74\x65\x72\x69\x61"
    1877             :         "\x6c\x20\x6f\x72\x20\x74\x6f\x20\x63\x69\x74\x65\x20\x74\x68\x65"
    1878             :         "\x6d\x20\x6f\x74\x68\x65\x72\x20\x74\x68\x61\x6e\x20\x61\x73\x20"
    1879             :         "\x2f\xe2\x80\x9c\x77\x6f\x72\x6b\x20\x69\x6e\x20\x70\x72\x6f\x67"
    1880             :         "\x72\x65\x73\x73\x2e\x2f\xe2\x80\x9d", 265,
    1881             :         "\x64\xa0\x86\x15\x75\x86\x1a\xf4\x60\xf0\x62\xc7\x9b\xe6\x43\xbd"
    1882             :         "\x5e\x80\x5c\xfd\x34\x5c\xf3\x89\xf1\x08\x67\x0a\xc7\x6c\x8c\xb2"
    1883             :         "\x4c\x6c\xfc\x18\x75\x5d\x43\xee\xa0\x9e\xe9\x4e\x38\x2d\x26\xb0"
    1884             :         "\xbd\xb7\xb7\x3c\x32\x1b\x01\x00\xd4\xf0\x3b\x7f\x35\x58\x94\xcf"
    1885             :         "\x33\x2f\x83\x0e\x71\x0b\x97\xce\x98\xc8\xa8\x4a\xbd\x0b\x94\x81"
    1886             :         "\x14\xad\x17\x6e\x00\x8d\x33\xbd\x60\xf9\x82\xb1\xff\x37\xc8\x55"
    1887             :         "\x97\x97\xa0\x6e\xf4\xf0\xef\x61\xc1\x86\x32\x4e\x2b\x35\x06\x38"
    1888             :         "\x36\x06\x90\x7b\x6a\x7c\x02\xb0\xf9\xf6\x15\x7b\x53\xc8\x67\xe4"
    1889             :         "\xb9\x16\x6c\x76\x7b\x80\x4d\x46\xa5\x9b\x52\x16\xcd\xe7\xa4\xe9"
    1890             :         "\x90\x40\xc5\xa4\x04\x33\x22\x5e\xe2\x82\xa1\xb0\xa0\x6c\x52\x3e"
    1891             :         "\xaf\x45\x34\xd7\xf8\x3f\xa1\x15\x5b\x00\x47\x71\x8c\xbc\x54\x6a"
    1892             :         "\x0d\x07\x2b\x04\xb3\x56\x4e\xea\x1b\x42\x22\x73\xf5\x48\x27\x1a"
    1893             :         "\x0b\xb2\x31\x60\x53\xfa\x76\x99\x19\x55\xeb\xd6\x31\x59\x43\x4e"
    1894             :         "\xce\xbb\x4e\x46\x6d\xae\x5a\x10\x73\xa6\x72\x76\x27\x09\x7a\x10"
    1895             :         "\x49\xe6\x17\xd9\x1d\x36\x10\x94\xfa\x68\xf0\xff\x77\x98\x71\x30"
    1896             :         "\x30\x5b\xea\xba\x2e\xda\x04\xdf\x99\x7b\x71\x4d\x6c\x6f\x2c\x29"
    1897             :         "\xa6\xad\x5c\xb4\x02\x2b\x02\x70\x9b",
    1898             :         "\xee\xad\x9d\x67\x89\x0c\xbb\x22\x39\x23\x36\xfe\xa1\x85\x1f\x38" },
    1899             :       /* draft-irtf-cfrg-chacha20-poly1305-03 */
    1900             :       { GCRY_CIPHER_CHACHA20,
    1901             :         "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
    1902             :         "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
    1903             :         "\x07\x00\x00\x00\x40\x41\x42\x43\x44\x45\x46\x47", 12,
    1904             :         "\x50\x51\x52\x53\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7", 12,
    1905             :         "Ladies and Gentlemen of the class of '99: If I could offer you "
    1906             :         "only one tip for the future, sunscreen would be it.", 114,
    1907             :         "\xd3\x1a\x8d\x34\x64\x8e\x60\xdb\x7b\x86\xaf\xbc\x53\xef\x7e\xc2"
    1908             :         "\xa4\xad\xed\x51\x29\x6e\x08\xfe\xa9\xe2\xb5\xa7\x36\xee\x62\xd6"
    1909             :         "\x3d\xbe\xa4\x5e\x8c\xa9\x67\x12\x82\xfa\xfb\x69\xda\x92\x72\x8b"
    1910             :         "\x1a\x71\xde\x0a\x9e\x06\x0b\x29\x05\xd6\xa5\xb6\x7e\xcd\x3b\x36"
    1911             :         "\x92\xdd\xbd\x7f\x2d\x77\x8b\x8c\x98\x03\xae\xe3\x28\x09\x1b\x58"
    1912             :         "\xfa\xb3\x24\xe4\xfa\xd6\x75\x94\x55\x85\x80\x8b\x48\x31\xd7\xbc"
    1913             :         "\x3f\xf4\xde\xf0\x8e\x4b\x7a\x9d\xe5\x76\xd2\x65\x86\xce\xc6\x4b"
    1914             :         "\x61\x16",
    1915             :         "\x1a\xe1\x0b\x59\x4f\x09\xe2\x6a\x7e\x90\x2e\xcb\xd0\x60\x06\x91" },
    1916             :     };
    1917             : 
    1918             :   gcry_cipher_hd_t hde, hdd;
    1919             :   unsigned char out[1024];
    1920             :   unsigned char tag[16];
    1921             :   int i, keylen;
    1922           4 :   gcry_error_t err = 0;
    1923             :   size_t pos, poslen, taglen2;
    1924             :   int byteNum;
    1925             : 
    1926           4 :   if (verbose)
    1927           0 :     fprintf (stderr, "  Starting POLY1305 checks.\n");
    1928             : 
    1929          12 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    1930             :     {
    1931           8 :       if (verbose)
    1932           0 :         fprintf (stderr, "    checking POLY1305 mode for %s [%i]\n",
    1933             :                  gcry_cipher_algo_name (tv[i].algo),
    1934             :                  tv[i].algo);
    1935           8 :       err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_POLY1305, 0);
    1936           8 :       if (!err)
    1937           8 :         err = gcry_cipher_open (&hdd, tv[i].algo, GCRY_CIPHER_MODE_POLY1305, 0);
    1938           8 :       if (err)
    1939             :         {
    1940           0 :           fail ("poly1305, gcry_cipher_open failed: %s\n", gpg_strerror (err));
    1941           0 :           return;
    1942             :         }
    1943             : 
    1944           8 :       keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
    1945           8 :       if (!keylen)
    1946             :         {
    1947           0 :           fail ("poly1305, gcry_cipher_get_algo_keylen failed\n");
    1948           0 :           return;
    1949             :         }
    1950             : 
    1951           8 :       err = gcry_cipher_setkey (hde, tv[i].key, keylen);
    1952           8 :       if (!err)
    1953           8 :         err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
    1954           8 :       if (err)
    1955             :         {
    1956           0 :           fail ("poly1305, gcry_cipher_setkey failed: %s\n",
    1957             :                 gpg_strerror (err));
    1958           0 :           gcry_cipher_close (hde);
    1959           0 :           gcry_cipher_close (hdd);
    1960           0 :           return;
    1961             :         }
    1962             : 
    1963           8 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    1964           8 :       if (!err)
    1965           8 :         err = gcry_cipher_setiv (hdd, tv[i].iv, tv[i].ivlen);
    1966           8 :       if (err)
    1967             :         {
    1968           0 :           fail ("poly1305, gcry_cipher_setiv failed: %s\n",
    1969             :                 gpg_strerror (err));
    1970           0 :           gcry_cipher_close (hde);
    1971           0 :           gcry_cipher_close (hdd);
    1972           0 :           return;
    1973             :         }
    1974             : 
    1975           8 :       err = gcry_cipher_info (hde, GCRYCTL_GET_TAGLEN, NULL, &taglen2);
    1976           8 :       if (err)
    1977             :         {
    1978           0 :           fail ("cipher-poly1305, gcryctl_get_taglen failed (tv %d): %s\n",
    1979             :                 i, gpg_strerror (err));
    1980           0 :           gcry_cipher_close (hde);
    1981           0 :           gcry_cipher_close (hdd);
    1982           0 :           return;
    1983             :         }
    1984           8 :       if (taglen2 != 16)
    1985             :         {
    1986           0 :           fail ("cipher-poly1305, gcryctl_get_taglen returned bad length"
    1987             :                 " (tv %d): got=%zu want=%d\n",
    1988             :                 i, taglen2, 16);
    1989           0 :           gcry_cipher_close (hde);
    1990           0 :           gcry_cipher_close (hdd);
    1991           0 :           return;
    1992             :         }
    1993             : 
    1994          40 :       for (pos = 0; pos < tv[i].aadlen; pos += step)
    1995             :         {
    1996          32 :           poslen = (pos + step < tv[i].aadlen) ? step : tv[i].aadlen - pos;
    1997             : 
    1998          32 :           err = gcry_cipher_authenticate(hde, tv[i].aad + pos, poslen);
    1999          32 :           if (err)
    2000             :             {
    2001           0 :               fail ("poly1305, gcry_cipher_authenticate (%d) (%d:%d) failed: "
    2002             :                     "%s\n", i, pos, step, gpg_strerror (err));
    2003           0 :               gcry_cipher_close (hde);
    2004           0 :               gcry_cipher_close (hdd);
    2005           0 :               return;
    2006             :             }
    2007          32 :           err = gcry_cipher_authenticate(hdd, tv[i].aad + pos, poslen);
    2008          32 :           if (err)
    2009             :             {
    2010           0 :               fail ("poly1305, de gcry_cipher_authenticate (%d) (%d:%d) failed: "
    2011             :                     "%s\n", i, pos, step, gpg_strerror (err));
    2012           0 :               gcry_cipher_close (hde);
    2013           0 :               gcry_cipher_close (hdd);
    2014           0 :               return;
    2015             :             }
    2016             :         }
    2017             : 
    2018         469 :       for (pos = 0; pos < tv[i].inlen; pos += step)
    2019             :         {
    2020         461 :           poslen = (pos + step < tv[i].inlen) ? step : tv[i].inlen - pos;
    2021             : 
    2022         461 :           err = gcry_cipher_encrypt (hde, out + pos, poslen,
    2023         461 :                                      tv[i].plaintext + pos, poslen);
    2024         461 :           if (err)
    2025             :             {
    2026           0 :               fail ("poly1305, gcry_cipher_encrypt (%d) (%d:%d) failed: %s\n",
    2027             :                     i, pos, step, gpg_strerror (err));
    2028           0 :               gcry_cipher_close (hde);
    2029           0 :               gcry_cipher_close (hdd);
    2030           0 :               return;
    2031             :             }
    2032             :         }
    2033             : 
    2034           8 :       if (memcmp (tv[i].out, out, tv[i].inlen))
    2035           0 :         fail ("poly1305, encrypt mismatch entry %d (step %d)\n", i, step);
    2036             : 
    2037         469 :       for (pos = 0; pos < tv[i].inlen; pos += step)
    2038             :         {
    2039         461 :           poslen = (pos + step < tv[i].inlen) ? step : tv[i].inlen - pos;
    2040             : 
    2041         461 :           err = gcry_cipher_decrypt (hdd, out + pos, poslen, NULL, 0);
    2042         461 :           if (err)
    2043             :             {
    2044           0 :               fail ("poly1305, gcry_cipher_decrypt (%d) (%d:%d) failed: %s\n",
    2045             :                     i, pos, step, gpg_strerror (err));
    2046           0 :               gcry_cipher_close (hde);
    2047           0 :               gcry_cipher_close (hdd);
    2048           0 :               return;
    2049             :             }
    2050             :         }
    2051             : 
    2052           8 :       if (memcmp (tv[i].plaintext, out, tv[i].inlen))
    2053           0 :         fail ("poly1305, decrypt mismatch entry %d (step %d)\n", i, step);
    2054             : 
    2055           8 :       err = gcry_cipher_gettag (hde, out, 16);
    2056           8 :       if (err)
    2057             :         {
    2058           0 :           fail ("poly1305, gcry_cipher_gettag(%d) failed: %s\n",
    2059             :                 i, gpg_strerror (err));
    2060           0 :           gcry_cipher_close (hde);
    2061           0 :           gcry_cipher_close (hdd);
    2062           0 :           return;
    2063             :         }
    2064             : 
    2065           8 :       if (memcmp (tv[i].tag, out, 16))
    2066           0 :         fail ("poly1305, encrypt tag mismatch entry %d\n", i);
    2067             : 
    2068             : 
    2069           8 :       err = gcry_cipher_checktag (hdd, out, 16);
    2070           8 :       if (err)
    2071             :         {
    2072           0 :           fail ("poly1305, gcry_cipher_checktag(%d) failed: %s\n",
    2073             :                 i, gpg_strerror (err));
    2074           0 :           gcry_cipher_close (hde);
    2075           0 :           gcry_cipher_close (hdd);
    2076           0 :           return;
    2077             :         }
    2078             : 
    2079           8 :       err = gcry_cipher_reset(hde);
    2080           8 :       if (!err)
    2081           8 :         err = gcry_cipher_reset(hdd);
    2082           8 :       if (err)
    2083             :         {
    2084           0 :           fail ("poly1305, gcry_cipher_reset (%d) failed: %s\n",
    2085             :                 i, gpg_strerror (err));
    2086           0 :           gcry_cipher_close (hde);
    2087           0 :           gcry_cipher_close (hdd);
    2088           0 :           return;
    2089             :         }
    2090             : 
    2091             :       /* gcry_cipher_reset clears the IV */
    2092           8 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    2093           8 :       if (!err)
    2094           8 :         err = gcry_cipher_setiv (hdd, tv[i].iv, tv[i].ivlen);
    2095           8 :       if (err)
    2096             :         {
    2097           0 :           fail ("poly1305, gcry_cipher_setiv failed: %s\n",
    2098             :                 gpg_strerror (err));
    2099           0 :           gcry_cipher_close (hde);
    2100           0 :           gcry_cipher_close (hdd);
    2101           0 :           return;
    2102             :         }
    2103             : 
    2104             :       /* this time we authenticate, encrypt and decrypt one byte at a time */
    2105         104 :       for (byteNum = 0; byteNum < tv[i].aadlen; ++byteNum)
    2106             :         {
    2107          96 :           err = gcry_cipher_authenticate(hde, tv[i].aad + byteNum, 1);
    2108          96 :           if (err)
    2109             :             {
    2110           0 :               fail ("poly1305, gcry_cipher_authenticate (%d) (byte-buf) failed: "
    2111             :                     "%s\n", i, gpg_strerror (err));
    2112           0 :               gcry_cipher_close (hde);
    2113           0 :               gcry_cipher_close (hdd);
    2114           0 :               return;
    2115             :             }
    2116          96 :           err = gcry_cipher_authenticate(hdd, tv[i].aad + byteNum, 1);
    2117          96 :           if (err)
    2118             :             {
    2119           0 :               fail ("poly1305, de gcry_cipher_authenticate (%d) (byte-buf) "
    2120             :                     "failed: %s\n", i, gpg_strerror (err));
    2121           0 :               gcry_cipher_close (hde);
    2122           0 :               gcry_cipher_close (hdd);
    2123           0 :               return;
    2124             :             }
    2125             :         }
    2126             : 
    2127        1524 :       for (byteNum = 0; byteNum < tv[i].inlen; ++byteNum)
    2128             :         {
    2129        1516 :           err = gcry_cipher_encrypt (hde, out+byteNum, 1,
    2130        1516 :                                      (tv[i].plaintext) + byteNum,
    2131             :                                      1);
    2132        1516 :           if (err)
    2133             :             {
    2134           0 :               fail ("poly1305, gcry_cipher_encrypt (%d) (byte-buf) failed: %s\n",
    2135             :                     i,  gpg_strerror (err));
    2136           0 :               gcry_cipher_close (hde);
    2137           0 :               gcry_cipher_close (hdd);
    2138           0 :               return;
    2139             :             }
    2140             :         }
    2141             : 
    2142           8 :       if (memcmp (tv[i].out, out, tv[i].inlen))
    2143           0 :         fail ("poly1305, encrypt mismatch entry %d, (byte-buf)\n", i);
    2144             : 
    2145           8 :       err = gcry_cipher_gettag (hde, tag, 16);
    2146           8 :       if (err)
    2147             :         {
    2148           0 :           fail ("poly1305, gcry_cipher_gettag(%d) (byte-buf) failed: %s\n",
    2149             :                 i, gpg_strerror (err));
    2150           0 :           gcry_cipher_close (hde);
    2151           0 :           gcry_cipher_close (hdd);
    2152           0 :           return;
    2153             :         }
    2154             : 
    2155           8 :       if (memcmp (tv[i].tag, tag, 16))
    2156           0 :         fail ("poly1305, encrypt tag mismatch entry %d, (byte-buf)\n", i);
    2157             : 
    2158        1524 :       for (byteNum = 0; byteNum < tv[i].inlen; ++byteNum)
    2159             :         {
    2160        1516 :           err = gcry_cipher_decrypt (hdd, out+byteNum, 1, NULL, 0);
    2161        1516 :           if (err)
    2162             :             {
    2163           0 :               fail ("poly1305, gcry_cipher_decrypt (%d) (byte-buf) failed: %s\n",
    2164             :                     i, gpg_strerror (err));
    2165           0 :               gcry_cipher_close (hde);
    2166           0 :               gcry_cipher_close (hdd);
    2167           0 :               return;
    2168             :             }
    2169             :         }
    2170             : 
    2171           8 :       if (memcmp (tv[i].plaintext, out, tv[i].inlen))
    2172           0 :         fail ("poly1305, decrypt mismatch entry %d\n", i);
    2173             : 
    2174           8 :       err = gcry_cipher_checktag (hdd, tag, 16);
    2175           8 :       if (err)
    2176             :         {
    2177           0 :           fail ("poly1305, gcry_cipher_checktag(%d) (byte-buf) failed: %s\n",
    2178             :                 i, gpg_strerror (err));
    2179           0 :           gcry_cipher_close (hde);
    2180           0 :           gcry_cipher_close (hdd);
    2181           0 :           return;
    2182             :         }
    2183             : 
    2184           8 :       gcry_cipher_close (hde);
    2185           8 :       gcry_cipher_close (hdd);
    2186             :     }
    2187           4 :   if (verbose)
    2188           0 :     fprintf (stderr, "  Completed POLY1305 checks.\n");
    2189             : }
    2190             : 
    2191             : 
    2192             : static void
    2193           1 : check_poly1305_cipher (void)
    2194             : {
    2195             :   /* Large buffers, no splitting. */
    2196           1 :   _check_poly1305_cipher(0xffffffff);
    2197             :   /* Split input to one byte buffers. */
    2198           1 :   _check_poly1305_cipher(1);
    2199             :   /* Split input to 7 byte buffers. */
    2200           1 :   _check_poly1305_cipher(7);
    2201             :   /* Split input to 16 byte buffers. */
    2202           1 :   _check_poly1305_cipher(16);
    2203           1 : }
    2204             : 
    2205             : 
    2206             : static void
    2207           1 : check_ccm_cipher (void)
    2208             : {
    2209             :   static const struct tv
    2210             :   {
    2211             :     int algo;
    2212             :     int keylen;
    2213             :     const char *key;
    2214             :     int noncelen;
    2215             :     const char *nonce;
    2216             :     int aadlen;
    2217             :     const char *aad;
    2218             :     int plainlen;
    2219             :     const char *plaintext;
    2220             :     int cipherlen;
    2221             :     const char *ciphertext;
    2222             :   } tv[] =
    2223             :     {
    2224             :       /* RFC 3610 */
    2225             :       { GCRY_CIPHER_AES, /* Packet Vector #1 */
    2226             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2227             :           13, "\x00\x00\x00\x03\x02\x01\x00\xA0\xA1\xA2\xA3\xA4\xA5",
    2228             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2229             :           23,
    2230             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2231             :           31,
    2232             :           "\x58\x8C\x97\x9A\x61\xC6\x63\xD2\xF0\x66\xD0\xC2\xC0\xF9\x89\x80\x6D\x5F\x6B\x61\xDA\xC3\x84\x17\xE8\xD1\x2C\xFD\xF9\x26\xE0"},
    2233             :       { GCRY_CIPHER_AES, /* Packet Vector #2 */
    2234             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2235             :           13, "\x00\x00\x00\x04\x03\x02\x01\xA0\xA1\xA2\xA3\xA4\xA5",
    2236             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2237             :           24,
    2238             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2239             :           32,
    2240             :           "\x72\xC9\x1A\x36\xE1\x35\xF8\xCF\x29\x1C\xA8\x94\x08\x5C\x87\xE3\xCC\x15\xC4\x39\xC9\xE4\x3A\x3B\xA0\x91\xD5\x6E\x10\x40\x09\x16"},
    2241             :       { GCRY_CIPHER_AES, /* Packet Vector #3 */
    2242             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2243             :           13, "\x00\x00\x00\x05\x04\x03\x02\xA0\xA1\xA2\xA3\xA4\xA5",
    2244             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2245             :           25,
    2246             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2247             :           33,
    2248             :           "\x51\xB1\xE5\xF4\x4A\x19\x7D\x1D\xA4\x6B\x0F\x8E\x2D\x28\x2A\xE8\x71\xE8\x38\xBB\x64\xDA\x85\x96\x57\x4A\xDA\xA7\x6F\xBD\x9F\xB0\xC5"},
    2249             :       { GCRY_CIPHER_AES, /* Packet Vector #4 */
    2250             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2251             :           13, "\x00\x00\x00\x06\x05\x04\x03\xA0\xA1\xA2\xA3\xA4\xA5",
    2252             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2253             :           19,
    2254             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2255             :           27,
    2256             :           "\xA2\x8C\x68\x65\x93\x9A\x9A\x79\xFA\xAA\x5C\x4C\x2A\x9D\x4A\x91\xCD\xAC\x8C\x96\xC8\x61\xB9\xC9\xE6\x1E\xF1"},
    2257             :       { GCRY_CIPHER_AES, /* Packet Vector #5 */
    2258             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2259             :           13, "\x00\x00\x00\x07\x06\x05\x04\xA0\xA1\xA2\xA3\xA4\xA5",
    2260             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2261             :           20,
    2262             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2263             :           28,
    2264             :           "\xDC\xF1\xFB\x7B\x5D\x9E\x23\xFB\x9D\x4E\x13\x12\x53\x65\x8A\xD8\x6E\xBD\xCA\x3E\x51\xE8\x3F\x07\x7D\x9C\x2D\x93"},
    2265             :       { GCRY_CIPHER_AES, /* Packet Vector #6 */
    2266             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2267             :           13, "\x00\x00\x00\x08\x07\x06\x05\xA0\xA1\xA2\xA3\xA4\xA5",
    2268             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2269             :           21,
    2270             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2271             :           29,
    2272             :           "\x6F\xC1\xB0\x11\xF0\x06\x56\x8B\x51\x71\xA4\x2D\x95\x3D\x46\x9B\x25\x70\xA4\xBD\x87\x40\x5A\x04\x43\xAC\x91\xCB\x94"},
    2273             :       { GCRY_CIPHER_AES, /* Packet Vector #7 */
    2274             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2275             :           13, "\x00\x00\x00\x09\x08\x07\x06\xA0\xA1\xA2\xA3\xA4\xA5",
    2276             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2277             :           23,
    2278             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2279             :           33,
    2280             :           "\x01\x35\xD1\xB2\xC9\x5F\x41\xD5\xD1\xD4\xFE\xC1\x85\xD1\x66\xB8\x09\x4E\x99\x9D\xFE\xD9\x6C\x04\x8C\x56\x60\x2C\x97\xAC\xBB\x74\x90"},
    2281             :       { GCRY_CIPHER_AES, /* Packet Vector #8 */
    2282             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2283             :           13, "\x00\x00\x00\x0A\x09\x08\x07\xA0\xA1\xA2\xA3\xA4\xA5",
    2284             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2285             :           24,
    2286             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2287             :           34,
    2288             :           "\x7B\x75\x39\x9A\xC0\x83\x1D\xD2\xF0\xBB\xD7\x58\x79\xA2\xFD\x8F\x6C\xAE\x6B\x6C\xD9\xB7\xDB\x24\xC1\x7B\x44\x33\xF4\x34\x96\x3F\x34\xB4"},
    2289             :       { GCRY_CIPHER_AES, /* Packet Vector #9 */
    2290             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2291             :           13, "\x00\x00\x00\x0B\x0A\x09\x08\xA0\xA1\xA2\xA3\xA4\xA5",
    2292             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2293             :           25,
    2294             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2295             :           35,
    2296             :           "\x82\x53\x1A\x60\xCC\x24\x94\x5A\x4B\x82\x79\x18\x1A\xB5\xC8\x4D\xF2\x1C\xE7\xF9\xB7\x3F\x42\xE1\x97\xEA\x9C\x07\xE5\x6B\x5E\xB1\x7E\x5F\x4E"},
    2297             :       { GCRY_CIPHER_AES, /* Packet Vector #10 */
    2298             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2299             :           13, "\x00\x00\x00\x0C\x0B\x0A\x09\xA0\xA1\xA2\xA3\xA4\xA5",
    2300             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2301             :           19,
    2302             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2303             :           29,
    2304             :           "\x07\x34\x25\x94\x15\x77\x85\x15\x2B\x07\x40\x98\x33\x0A\xBB\x14\x1B\x94\x7B\x56\x6A\xA9\x40\x6B\x4D\x99\x99\x88\xDD"},
    2305             :       { GCRY_CIPHER_AES, /* Packet Vector #11 */
    2306             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2307             :           13, "\x00\x00\x00\x0D\x0C\x0B\x0A\xA0\xA1\xA2\xA3\xA4\xA5",
    2308             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2309             :           20,
    2310             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2311             :           30,
    2312             :           "\x67\x6B\xB2\x03\x80\xB0\xE3\x01\xE8\xAB\x79\x59\x0A\x39\x6D\xA7\x8B\x83\x49\x34\xF5\x3A\xA2\xE9\x10\x7A\x8B\x6C\x02\x2C"},
    2313             :       { GCRY_CIPHER_AES, /* Packet Vector #12 */
    2314             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2315             :           13, "\x00\x00\x00\x0E\x0D\x0C\x0B\xA0\xA1\xA2\xA3\xA4\xA5",
    2316             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2317             :           21,
    2318             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2319             :           31,
    2320             :           "\xC0\xFF\xA0\xD6\xF0\x5B\xDB\x67\xF2\x4D\x43\xA4\x33\x8D\x2A\xA4\xBE\xD7\xB2\x0E\x43\xCD\x1A\xA3\x16\x62\xE7\xAD\x65\xD6\xDB"},
    2321             :       { GCRY_CIPHER_AES, /* Packet Vector #13 */
    2322             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2323             :           13, "\x00\x41\x2B\x4E\xA9\xCD\xBE\x3C\x96\x96\x76\x6C\xFA",
    2324             :           8, "\x0B\xE1\xA8\x8B\xAC\xE0\x18\xB1",
    2325             :           23,
    2326             :           "\x08\xE8\xCF\x97\xD8\x20\xEA\x25\x84\x60\xE9\x6A\xD9\xCF\x52\x89\x05\x4D\x89\x5C\xEA\xC4\x7C",
    2327             :           31,
    2328             :           "\x4C\xB9\x7F\x86\xA2\xA4\x68\x9A\x87\x79\x47\xAB\x80\x91\xEF\x53\x86\xA6\xFF\xBD\xD0\x80\xF8\xE7\x8C\xF7\xCB\x0C\xDD\xD7\xB3"},
    2329             :       { GCRY_CIPHER_AES, /* Packet Vector #14 */
    2330             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2331             :           13, "\x00\x33\x56\x8E\xF7\xB2\x63\x3C\x96\x96\x76\x6C\xFA",
    2332             :           8, "\x63\x01\x8F\x76\xDC\x8A\x1B\xCB",
    2333             :           24,
    2334             :           "\x90\x20\xEA\x6F\x91\xBD\xD8\x5A\xFA\x00\x39\xBA\x4B\xAF\xF9\xBF\xB7\x9C\x70\x28\x94\x9C\xD0\xEC",
    2335             :           32,
    2336             :           "\x4C\xCB\x1E\x7C\xA9\x81\xBE\xFA\xA0\x72\x6C\x55\xD3\x78\x06\x12\x98\xC8\x5C\x92\x81\x4A\xBC\x33\xC5\x2E\xE8\x1D\x7D\x77\xC0\x8A"},
    2337             :       { GCRY_CIPHER_AES, /* Packet Vector #15 */
    2338             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2339             :           13, "\x00\x10\x3F\xE4\x13\x36\x71\x3C\x96\x96\x76\x6C\xFA",
    2340             :           8, "\xAA\x6C\xFA\x36\xCA\xE8\x6B\x40",
    2341             :           25,
    2342             :           "\xB9\x16\xE0\xEA\xCC\x1C\x00\xD7\xDC\xEC\x68\xEC\x0B\x3B\xBB\x1A\x02\xDE\x8A\x2D\x1A\xA3\x46\x13\x2E",
    2343             :           33,
    2344             :           "\xB1\xD2\x3A\x22\x20\xDD\xC0\xAC\x90\x0D\x9A\xA0\x3C\x61\xFC\xF4\xA5\x59\xA4\x41\x77\x67\x08\x97\x08\xA7\x76\x79\x6E\xDB\x72\x35\x06"},
    2345             :       { GCRY_CIPHER_AES, /* Packet Vector #16 */
    2346             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2347             :           13, "\x00\x76\x4C\x63\xB8\x05\x8E\x3C\x96\x96\x76\x6C\xFA",
    2348             :           12, "\xD0\xD0\x73\x5C\x53\x1E\x1B\xEC\xF0\x49\xC2\x44",
    2349             :           19,
    2350             :           "\x12\xDA\xAC\x56\x30\xEF\xA5\x39\x6F\x77\x0C\xE1\xA6\x6B\x21\xF7\xB2\x10\x1C",
    2351             :           27,
    2352             :           "\x14\xD2\x53\xC3\x96\x7B\x70\x60\x9B\x7C\xBB\x7C\x49\x91\x60\x28\x32\x45\x26\x9A\x6F\x49\x97\x5B\xCA\xDE\xAF"},
    2353             :       { GCRY_CIPHER_AES, /* Packet Vector #17 */
    2354             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2355             :           13, "\x00\xF8\xB6\x78\x09\x4E\x3B\x3C\x96\x96\x76\x6C\xFA",
    2356             :           12, "\x77\xB6\x0F\x01\x1C\x03\xE1\x52\x58\x99\xBC\xAE",
    2357             :           20,
    2358             :           "\xE8\x8B\x6A\x46\xC7\x8D\x63\xE5\x2E\xB8\xC5\x46\xEF\xB5\xDE\x6F\x75\xE9\xCC\x0D",
    2359             :           28,
    2360             :           "\x55\x45\xFF\x1A\x08\x5E\xE2\xEF\xBF\x52\xB2\xE0\x4B\xEE\x1E\x23\x36\xC7\x3E\x3F\x76\x2C\x0C\x77\x44\xFE\x7E\x3C"},
    2361             :       { GCRY_CIPHER_AES, /* Packet Vector #18 */
    2362             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2363             :           13, "\x00\xD5\x60\x91\x2D\x3F\x70\x3C\x96\x96\x76\x6C\xFA",
    2364             :           12, "\xCD\x90\x44\xD2\xB7\x1F\xDB\x81\x20\xEA\x60\xC0",
    2365             :           21,
    2366             :           "\x64\x35\xAC\xBA\xFB\x11\xA8\x2E\x2F\x07\x1D\x7C\xA4\xA5\xEB\xD9\x3A\x80\x3B\xA8\x7F",
    2367             :           29,
    2368             :           "\x00\x97\x69\xEC\xAB\xDF\x48\x62\x55\x94\xC5\x92\x51\xE6\x03\x57\x22\x67\x5E\x04\xC8\x47\x09\x9E\x5A\xE0\x70\x45\x51"},
    2369             :       { GCRY_CIPHER_AES, /* Packet Vector #19 */
    2370             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2371             :           13, "\x00\x42\xFF\xF8\xF1\x95\x1C\x3C\x96\x96\x76\x6C\xFA",
    2372             :           8, "\xD8\x5B\xC7\xE6\x9F\x94\x4F\xB8",
    2373             :           23,
    2374             :           "\x8A\x19\xB9\x50\xBC\xF7\x1A\x01\x8E\x5E\x67\x01\xC9\x17\x87\x65\x98\x09\xD6\x7D\xBE\xDD\x18",
    2375             :           33,
    2376             :           "\xBC\x21\x8D\xAA\x94\x74\x27\xB6\xDB\x38\x6A\x99\xAC\x1A\xEF\x23\xAD\xE0\xB5\x29\x39\xCB\x6A\x63\x7C\xF9\xBE\xC2\x40\x88\x97\xC6\xBA"},
    2377             :       { GCRY_CIPHER_AES, /* Packet Vector #20 */
    2378             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2379             :           13, "\x00\x92\x0F\x40\xE5\x6C\xDC\x3C\x96\x96\x76\x6C\xFA",
    2380             :           8, "\x74\xA0\xEB\xC9\x06\x9F\x5B\x37",
    2381             :           24,
    2382             :           "\x17\x61\x43\x3C\x37\xC5\xA3\x5F\xC1\xF3\x9F\x40\x63\x02\xEB\x90\x7C\x61\x63\xBE\x38\xC9\x84\x37",
    2383             :           34,
    2384             :           "\x58\x10\xE6\xFD\x25\x87\x40\x22\xE8\x03\x61\xA4\x78\xE3\xE9\xCF\x48\x4A\xB0\x4F\x44\x7E\xFF\xF6\xF0\xA4\x77\xCC\x2F\xC9\xBF\x54\x89\x44"},
    2385             :       { GCRY_CIPHER_AES, /* Packet Vector #21 */
    2386             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2387             :           13, "\x00\x27\xCA\x0C\x71\x20\xBC\x3C\x96\x96\x76\x6C\xFA",
    2388             :           8, "\x44\xA3\xAA\x3A\xAE\x64\x75\xCA",
    2389             :           25,
    2390             :           "\xA4\x34\xA8\xE5\x85\x00\xC6\xE4\x15\x30\x53\x88\x62\xD6\x86\xEA\x9E\x81\x30\x1B\x5A\xE4\x22\x6B\xFA",
    2391             :           35,
    2392             :           "\xF2\xBE\xED\x7B\xC5\x09\x8E\x83\xFE\xB5\xB3\x16\x08\xF8\xE2\x9C\x38\x81\x9A\x89\xC8\xE7\x76\xF1\x54\x4D\x41\x51\xA4\xED\x3A\x8B\x87\xB9\xCE"},
    2393             :       { GCRY_CIPHER_AES, /* Packet Vector #22 */
    2394             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2395             :           13, "\x00\x5B\x8C\xCB\xCD\x9A\xF8\x3C\x96\x96\x76\x6C\xFA",
    2396             :           12, "\xEC\x46\xBB\x63\xB0\x25\x20\xC3\x3C\x49\xFD\x70",
    2397             :           19,
    2398             :           "\xB9\x6B\x49\xE2\x1D\x62\x17\x41\x63\x28\x75\xDB\x7F\x6C\x92\x43\xD2\xD7\xC2",
    2399             :           29,
    2400             :           "\x31\xD7\x50\xA0\x9D\xA3\xED\x7F\xDD\xD4\x9A\x20\x32\xAA\xBF\x17\xEC\x8E\xBF\x7D\x22\xC8\x08\x8C\x66\x6B\xE5\xC1\x97"},
    2401             :       { GCRY_CIPHER_AES, /* Packet Vector #23 */
    2402             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2403             :           13, "\x00\x3E\xBE\x94\x04\x4B\x9A\x3C\x96\x96\x76\x6C\xFA",
    2404             :           12, "\x47\xA6\x5A\xC7\x8B\x3D\x59\x42\x27\xE8\x5E\x71",
    2405             :           20,
    2406             :           "\xE2\xFC\xFB\xB8\x80\x44\x2C\x73\x1B\xF9\x51\x67\xC8\xFF\xD7\x89\x5E\x33\x70\x76",
    2407             :           30,
    2408             :           "\xE8\x82\xF1\xDB\xD3\x8C\xE3\xED\xA7\xC2\x3F\x04\xDD\x65\x07\x1E\xB4\x13\x42\xAC\xDF\x7E\x00\xDC\xCE\xC7\xAE\x52\x98\x7D"},
    2409             :       { GCRY_CIPHER_AES, /* Packet Vector #24 */
    2410             :           16, "\xD7\x82\x8D\x13\xB2\xB0\xBD\xC3\x25\xA7\x62\x36\xDF\x93\xCC\x6B",
    2411             :           13, "\x00\x8D\x49\x3B\x30\xAE\x8B\x3C\x96\x96\x76\x6C\xFA",
    2412             :           12, "\x6E\x37\xA6\xEF\x54\x6D\x95\x5D\x34\xAB\x60\x59",
    2413             :           21,
    2414             :           "\xAB\xF2\x1C\x0B\x02\xFE\xB8\x8F\x85\x6D\xF4\xA3\x73\x81\xBC\xE3\xCC\x12\x85\x17\xD4",
    2415             :           31,
    2416             :           "\xF3\x29\x05\xB8\x8A\x64\x1B\x04\xB9\xC9\xFF\xB5\x8C\xC3\x90\x90\x0F\x3D\xA1\x2A\xB1\x6D\xCE\x9E\x82\xEF\xA1\x6D\xA6\x20\x59"},
    2417             :       /* RFC 5528 */
    2418             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #1 */
    2419             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2420             :           13, "\x00\x00\x00\x03\x02\x01\x00\xA0\xA1\xA2\xA3\xA4\xA5",
    2421             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2422             :           23,
    2423             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2424             :           31,
    2425             :           "\xBA\x73\x71\x85\xE7\x19\x31\x04\x92\xF3\x8A\x5F\x12\x51\xDA\x55\xFA\xFB\xC9\x49\x84\x8A\x0D\xFC\xAE\xCE\x74\x6B\x3D\xB9\xAD"},
    2426             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #2 */
    2427             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2428             :           13, "\x00\x00\x00\x04\x03\x02\x01\xA0\xA1\xA2\xA3\xA4\xA5",
    2429             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2430             :           24,
    2431             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2432             :           32,
    2433             :           "\x5D\x25\x64\xBF\x8E\xAF\xE1\xD9\x95\x26\xEC\x01\x6D\x1B\xF0\x42\x4C\xFB\xD2\xCD\x62\x84\x8F\x33\x60\xB2\x29\x5D\xF2\x42\x83\xE8"},
    2434             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #3 */
    2435             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2436             :           13, "\x00\x00\x00\x05\x04\x03\x02\xA0\xA1\xA2\xA3\xA4\xA5",
    2437             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2438             :           25,
    2439             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2440             :           33,
    2441             :           "\x81\xF6\x63\xD6\xC7\x78\x78\x17\xF9\x20\x36\x08\xB9\x82\xAD\x15\xDC\x2B\xBD\x87\xD7\x56\xF7\x92\x04\xF5\x51\xD6\x68\x2F\x23\xAA\x46"},
    2442             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #4 */
    2443             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2444             :           13, "\x00\x00\x00\x06\x05\x04\x03\xA0\xA1\xA2\xA3\xA4\xA5",
    2445             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2446             :           19,
    2447             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2448             :           27,
    2449             :           "\xCA\xEF\x1E\x82\x72\x11\xB0\x8F\x7B\xD9\x0F\x08\xC7\x72\x88\xC0\x70\xA4\xA0\x8B\x3A\x93\x3A\x63\xE4\x97\xA0"},
    2450             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #5 */
    2451             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2452             :           13, "\x00\x00\x00\x07\x06\x05\x04\xA0\xA1\xA2\xA3\xA4\xA5",
    2453             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2454             :           20,
    2455             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2456             :           28,
    2457             :           "\x2A\xD3\xBA\xD9\x4F\xC5\x2E\x92\xBE\x43\x8E\x82\x7C\x10\x23\xB9\x6A\x8A\x77\x25\x8F\xA1\x7B\xA7\xF3\x31\xDB\x09"},
    2458             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #6 */
    2459             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2460             :           13, "\x00\x00\x00\x08\x07\x06\x05\xA0\xA1\xA2\xA3\xA4\xA5",
    2461             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2462             :           21,
    2463             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2464             :           29,
    2465             :           "\xFE\xA5\x48\x0B\xA5\x3F\xA8\xD3\xC3\x44\x22\xAA\xCE\x4D\xE6\x7F\xFA\x3B\xB7\x3B\xAB\xAB\x36\xA1\xEE\x4F\xE0\xFE\x28"},
    2466             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #7 */
    2467             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2468             :           13, "\x00\x00\x00\x09\x08\x07\x06\xA0\xA1\xA2\xA3\xA4\xA5",
    2469             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2470             :           23,
    2471             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2472             :           33,
    2473             :           "\x54\x53\x20\x26\xE5\x4C\x11\x9A\x8D\x36\xD9\xEC\x6E\x1E\xD9\x74\x16\xC8\x70\x8C\x4B\x5C\x2C\xAC\xAF\xA3\xBC\xCF\x7A\x4E\xBF\x95\x73"},
    2474             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #8 */
    2475             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2476             :           13, "\x00\x00\x00\x0A\x09\x08\x07\xA0\xA1\xA2\xA3\xA4\xA5",
    2477             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2478             :           24,
    2479             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2480             :           34,
    2481             :           "\x8A\xD1\x9B\x00\x1A\x87\xD1\x48\xF4\xD9\x2B\xEF\x34\x52\x5C\xCC\xE3\xA6\x3C\x65\x12\xA6\xF5\x75\x73\x88\xE4\x91\x3E\xF1\x47\x01\xF4\x41"},
    2482             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #9 */
    2483             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2484             :           13, "\x00\x00\x00\x0B\x0A\x09\x08\xA0\xA1\xA2\xA3\xA4\xA5",
    2485             :           8, "\x00\x01\x02\x03\x04\x05\x06\x07",
    2486             :           25,
    2487             :           "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2488             :           35,
    2489             :           "\x5D\xB0\x8D\x62\x40\x7E\x6E\x31\xD6\x0F\x9C\xA2\xC6\x04\x74\x21\x9A\xC0\xBE\x50\xC0\xD4\xA5\x77\x87\x94\xD6\xE2\x30\xCD\x25\xC9\xFE\xBF\x87"},
    2490             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #10 */
    2491             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2492             :           13, "\x00\x00\x00\x0C\x0B\x0A\x09\xA0\xA1\xA2\xA3\xA4\xA5",
    2493             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2494             :           19,
    2495             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E",
    2496             :           29,
    2497             :           "\xDB\x11\x8C\xCE\xC1\xB8\x76\x1C\x87\x7C\xD8\x96\x3A\x67\xD6\xF3\xBB\xBC\x5C\xD0\x92\x99\xEB\x11\xF3\x12\xF2\x32\x37"},
    2498             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #11 */
    2499             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2500             :           13, "\x00\x00\x00\x0D\x0C\x0B\x0A\xA0\xA1\xA2\xA3\xA4\xA5",
    2501             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2502             :           20,
    2503             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
    2504             :           30,
    2505             :           "\x7C\xC8\x3D\x8D\xC4\x91\x03\x52\x5B\x48\x3D\xC5\xCA\x7E\xA9\xAB\x81\x2B\x70\x56\x07\x9D\xAF\xFA\xDA\x16\xCC\xCF\x2C\x4E"},
    2506             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #12 */
    2507             :           16, "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF",
    2508             :           13, "\x00\x00\x00\x0E\x0D\x0C\x0B\xA0\xA1\xA2\xA3\xA4\xA5",
    2509             :           12, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B",
    2510             :           21,
    2511             :           "\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20",
    2512             :           31,
    2513             :           "\x2C\xD3\x5B\x88\x20\xD2\x3E\x7A\xA3\x51\xB0\xE9\x2F\xC7\x93\x67\x23\x8B\x2C\xC7\x48\xCB\xB9\x4C\x29\x47\x79\x3D\x64\xAF\x75"},
    2514             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #13 */
    2515             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2516             :           13, "\x00\xA9\x70\x11\x0E\x19\x27\xB1\x60\xB6\xA3\x1C\x1C",
    2517             :           8, "\x6B\x7F\x46\x45\x07\xFA\xE4\x96",
    2518             :           23,
    2519             :           "\xC6\xB5\xF3\xE6\xCA\x23\x11\xAE\xF7\x47\x2B\x20\x3E\x73\x5E\xA5\x61\xAD\xB1\x7D\x56\xC5\xA3",
    2520             :           31,
    2521             :           "\xA4\x35\xD7\x27\x34\x8D\xDD\x22\x90\x7F\x7E\xB8\xF5\xFD\xBB\x4D\x93\x9D\xA6\x52\x4D\xB4\xF6\x45\x58\xC0\x2D\x25\xB1\x27\xEE"},
    2522             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #14 */
    2523             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2524             :           13, "\x00\x83\xCD\x8C\xE0\xCB\x42\xB1\x60\xB6\xA3\x1C\x1C",
    2525             :           8, "\x98\x66\x05\xB4\x3D\xF1\x5D\xE7",
    2526             :           24,
    2527             :           "\x01\xF6\xCE\x67\x64\xC5\x74\x48\x3B\xB0\x2E\x6B\xBF\x1E\x0A\xBD\x26\xA2\x25\x72\xB4\xD8\x0E\xE7",
    2528             :           32,
    2529             :           "\x8A\xE0\x52\x50\x8F\xBE\xCA\x93\x2E\x34\x6F\x05\xE0\xDC\x0D\xFB\xCF\x93\x9E\xAF\xFA\x3E\x58\x7C\x86\x7D\x6E\x1C\x48\x70\x38\x06"},
    2530             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #15 */
    2531             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2532             :           13, "\x00\x5F\x54\x95\x0B\x18\xF2\xB1\x60\xB6\xA3\x1C\x1C",
    2533             :           8, "\x48\xF2\xE7\xE1\xA7\x67\x1A\x51",
    2534             :           25,
    2535             :           "\xCD\xF1\xD8\x40\x6F\xC2\xE9\x01\x49\x53\x89\x70\x05\xFB\xFB\x8B\xA5\x72\x76\xF9\x24\x04\x60\x8E\x08",
    2536             :           33,
    2537             :           "\x08\xB6\x7E\xE2\x1C\x8B\xF2\x6E\x47\x3E\x40\x85\x99\xE9\xC0\x83\x6D\x6A\xF0\xBB\x18\xDF\x55\x46\x6C\xA8\x08\x78\xA7\x90\x47\x6D\xE5"},
    2538             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #16 */
    2539             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2540             :           13, "\x00\xEC\x60\x08\x63\x31\x9A\xB1\x60\xB6\xA3\x1C\x1C",
    2541             :           12, "\xDE\x97\xDF\x3B\x8C\xBD\x6D\x8E\x50\x30\xDA\x4C",
    2542             :           19,
    2543             :           "\xB0\x05\xDC\xFA\x0B\x59\x18\x14\x26\xA9\x61\x68\x5A\x99\x3D\x8C\x43\x18\x5B",
    2544             :           27,
    2545             :           "\x63\xB7\x8B\x49\x67\xB1\x9E\xDB\xB7\x33\xCD\x11\x14\xF6\x4E\xB2\x26\x08\x93\x68\xC3\x54\x82\x8D\x95\x0C\xC5"},
    2546             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #17 */
    2547             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2548             :           13, "\x00\x60\xCF\xF1\xA3\x1E\xA1\xB1\x60\xB6\xA3\x1C\x1C",
    2549             :           12, "\xA5\xEE\x93\xE4\x57\xDF\x05\x46\x6E\x78\x2D\xCF",
    2550             :           20,
    2551             :           "\x2E\x20\x21\x12\x98\x10\x5F\x12\x9D\x5E\xD9\x5B\x93\xF7\x2D\x30\xB2\xFA\xCC\xD7",
    2552             :           28,
    2553             :           "\x0B\xC6\xBB\xE2\xA8\xB9\x09\xF4\x62\x9E\xE6\xDC\x14\x8D\xA4\x44\x10\xE1\x8A\xF4\x31\x47\x38\x32\x76\xF6\x6A\x9F"},
    2554             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #18 */
    2555             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2556             :           13, "\x00\x0F\x85\xCD\x99\x5C\x97\xB1\x60\xB6\xA3\x1C\x1C",
    2557             :           12, "\x24\xAA\x1B\xF9\xA5\xCD\x87\x61\x82\xA2\x50\x74",
    2558             :           21,
    2559             :           "\x26\x45\x94\x1E\x75\x63\x2D\x34\x91\xAF\x0F\xC0\xC9\x87\x6C\x3B\xE4\xAA\x74\x68\xC9",
    2560             :           29,
    2561             :           "\x22\x2A\xD6\x32\xFA\x31\xD6\xAF\x97\x0C\x34\x5F\x7E\x77\xCA\x3B\xD0\xDC\x25\xB3\x40\xA1\xA3\xD3\x1F\x8D\x4B\x44\xB7"},
    2562             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #19 */
    2563             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2564             :           13, "\x00\xC2\x9B\x2C\xAA\xC4\xCD\xB1\x60\xB6\xA3\x1C\x1C",
    2565             :           8, "\x69\x19\x46\xB9\xCA\x07\xBE\x87",
    2566             :           23,
    2567             :           "\x07\x01\x35\xA6\x43\x7C\x9D\xB1\x20\xCD\x61\xD8\xF6\xC3\x9C\x3E\xA1\x25\xFD\x95\xA0\xD2\x3D",
    2568             :           33,
    2569             :           "\x05\xB8\xE1\xB9\xC4\x9C\xFD\x56\xCF\x13\x0A\xA6\x25\x1D\xC2\xEC\xC0\x6C\xCC\x50\x8F\xE6\x97\xA0\x06\x6D\x57\xC8\x4B\xEC\x18\x27\x68"},
    2570             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #20 */
    2571             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2572             :           13, "\x00\x2C\x6B\x75\x95\xEE\x62\xB1\x60\xB6\xA3\x1C\x1C",
    2573             :           8, "\xD0\xC5\x4E\xCB\x84\x62\x7D\xC4",
    2574             :           24,
    2575             :           "\xC8\xC0\x88\x0E\x6C\x63\x6E\x20\x09\x3D\xD6\x59\x42\x17\xD2\xE1\x88\x77\xDB\x26\x4E\x71\xA5\xCC",
    2576             :           34,
    2577             :           "\x54\xCE\xB9\x68\xDE\xE2\x36\x11\x57\x5E\xC0\x03\xDF\xAA\x1C\xD4\x88\x49\xBD\xF5\xAE\x2E\xDB\x6B\x7F\xA7\x75\xB1\x50\xED\x43\x83\xC5\xA9"},
    2578             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #21 */
    2579             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2580             :           13, "\x00\xC5\x3C\xD4\xC2\xAA\x24\xB1\x60\xB6\xA3\x1C\x1C",
    2581             :           8, "\xE2\x85\xE0\xE4\x80\x8C\xDA\x3D",
    2582             :           25,
    2583             :           "\xF7\x5D\xAA\x07\x10\xC4\xE6\x42\x97\x79\x4D\xC2\xB7\xD2\xA2\x07\x57\xB1\xAA\x4E\x44\x80\x02\xFF\xAB",
    2584             :           35,
    2585             :           "\xB1\x40\x45\x46\xBF\x66\x72\x10\xCA\x28\xE3\x09\xB3\x9B\xD6\xCA\x7E\x9F\xC8\x28\x5F\xE6\x98\xD4\x3C\xD2\x0A\x02\xE0\xBD\xCA\xED\x20\x10\xD3"},
    2586             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #22 */
    2587             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2588             :           13, "\x00\xBE\xE9\x26\x7F\xBA\xDC\xB1\x60\xB6\xA3\x1C\x1C",
    2589             :           12, "\x6C\xAE\xF9\x94\x11\x41\x57\x0D\x7C\x81\x34\x05",
    2590             :           19,
    2591             :           "\xC2\x38\x82\x2F\xAC\x5F\x98\xFF\x92\x94\x05\xB0\xAD\x12\x7A\x4E\x41\x85\x4E",
    2592             :           29,
    2593             :           "\x94\xC8\x95\x9C\x11\x56\x9A\x29\x78\x31\xA7\x21\x00\x58\x57\xAB\x61\xB8\x7A\x2D\xEA\x09\x36\xB6\xEB\x5F\x62\x5F\x5D"},
    2594             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #23 */
    2595             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2596             :           13, "\x00\xDF\xA8\xB1\x24\x50\x07\xB1\x60\xB6\xA3\x1C\x1C",
    2597             :           12, "\x36\xA5\x2C\xF1\x6B\x19\xA2\x03\x7A\xB7\x01\x1E",
    2598             :           20,
    2599             :           "\x4D\xBF\x3E\x77\x4A\xD2\x45\xE5\xD5\x89\x1F\x9D\x1C\x32\xA0\xAE\x02\x2C\x85\xD7",
    2600             :           30,
    2601             :           "\x58\x69\xE3\xAA\xD2\x44\x7C\x74\xE0\xFC\x05\xF9\xA4\xEA\x74\x57\x7F\x4D\xE8\xCA\x89\x24\x76\x42\x96\xAD\x04\x11\x9C\xE7"},
    2602             :       { GCRY_CIPHER_CAMELLIA128, /* Packet Vector #24 */
    2603             :           16, "\xD7\x5C\x27\x78\x07\x8C\xA9\x3D\x97\x1F\x96\xFD\xE7\x20\xF4\xCD",
    2604             :           13, "\x00\x3B\x8F\xD8\xD3\xA9\x37\xB1\x60\xB6\xA3\x1C\x1C",
    2605             :           12, "\xA4\xD4\x99\xF7\x84\x19\x72\x8C\x19\x17\x8B\x0C",
    2606             :           21,
    2607             :           "\x9D\xC9\xED\xAE\x2F\xF5\xDF\x86\x36\xE8\xC6\xDE\x0E\xED\x55\xF7\x86\x7E\x33\x33\x7D",
    2608             :           31,
    2609             :           "\x4B\x19\x81\x56\x39\x3B\x0F\x77\x96\x08\x6A\xAF\xB4\x54\xF8\xC3\xF0\x34\xCC\xA9\x66\x94\x5F\x1F\xCE\xA7\xE1\x1B\xEE\x6A\x2F"}
    2610             :     };
    2611             :   static const int cut[] = { 0, 1, 8, 10, 16, 19, -1 };
    2612             :   gcry_cipher_hd_t hde, hdd;
    2613             :   unsigned char out[MAX_DATA_LEN];
    2614             :   u64 ctl_params[3];
    2615             :   int split, aadsplit;
    2616             :   size_t j, i, keylen, blklen, authlen, taglen2;
    2617           1 :   gcry_error_t err = 0;
    2618             : 
    2619           1 :   if (verbose)
    2620           0 :     fprintf (stderr, "  Starting CCM checks.\n");
    2621             : 
    2622          49 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    2623             :     {
    2624          48 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
    2625             :         {
    2626           0 :           if (verbose)
    2627           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    2628             :                      tv[i].algo);
    2629           0 :           continue;
    2630             :         }
    2631             : 
    2632          48 :       if (verbose)
    2633           0 :         fprintf (stderr, "    checking CCM mode for %s [%i]\n",
    2634             :                  gcry_cipher_algo_name (tv[i].algo),
    2635             :                  tv[i].algo);
    2636             : 
    2637         384 :       for (j = 0; j < sizeof (cut) / sizeof (cut[0]); j++)
    2638             :         {
    2639         336 :           split = cut[j] < 0 ? tv[i].plainlen : cut[j];
    2640         336 :           if (tv[i].plainlen < split)
    2641           0 :             continue;
    2642             : 
    2643         336 :           err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_CCM, 0);
    2644         336 :           if (!err)
    2645         336 :             err = gcry_cipher_open (&hdd, tv[i].algo, GCRY_CIPHER_MODE_CCM, 0);
    2646         336 :           if (err)
    2647             :             {
    2648           0 :               fail ("cipher-ccm, gcry_cipher_open failed: %s\n",
    2649             :                     gpg_strerror (err));
    2650           0 :               return;
    2651             :             }
    2652             : 
    2653         336 :           keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
    2654         336 :           if (!keylen)
    2655             :             {
    2656           0 :               fail ("cipher-ccm, gcry_cipher_get_algo_keylen failed\n");
    2657           0 :               return;
    2658             :             }
    2659             : 
    2660         336 :           err = gcry_cipher_setkey (hde, tv[i].key, keylen);
    2661         336 :           if (!err)
    2662         336 :             err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
    2663         336 :           if (err)
    2664             :             {
    2665           0 :               fail ("cipher-ccm, gcry_cipher_setkey failed: %s\n",
    2666             :                     gpg_strerror (err));
    2667           0 :               gcry_cipher_close (hde);
    2668           0 :               gcry_cipher_close (hdd);
    2669           0 :               return;
    2670             :             }
    2671             : 
    2672         336 :           blklen = gcry_cipher_get_algo_blklen(tv[i].algo);
    2673         336 :           if (!blklen)
    2674             :             {
    2675           0 :               fail ("cipher-ccm, gcry_cipher_get_algo_blklen failed\n");
    2676           0 :               return;
    2677             :             }
    2678             : 
    2679         336 :           err = gcry_cipher_setiv (hde, tv[i].nonce, tv[i].noncelen);
    2680         336 :           if (!err)
    2681         336 :             err = gcry_cipher_setiv (hdd, tv[i].nonce, tv[i].noncelen);
    2682         336 :           if (err)
    2683             :             {
    2684           0 :               fail ("cipher-ccm, gcry_cipher_setiv failed: %s\n",
    2685             :                     gpg_strerror (err));
    2686           0 :               gcry_cipher_close (hde);
    2687           0 :               gcry_cipher_close (hdd);
    2688           0 :               return;
    2689             :             }
    2690             : 
    2691         336 :           authlen = tv[i].cipherlen - tv[i].plainlen;
    2692         336 :           ctl_params[0] = tv[i].plainlen; /* encryptedlen */
    2693         336 :           ctl_params[1] = tv[i].aadlen; /* aadlen */
    2694         336 :           ctl_params[2] = authlen; /* authtaglen */
    2695         336 :           err = gcry_cipher_ctl (hde, GCRYCTL_SET_CCM_LENGTHS, ctl_params,
    2696             :                                  sizeof(ctl_params));
    2697         336 :           if (!err)
    2698         336 :             err = gcry_cipher_ctl (hdd, GCRYCTL_SET_CCM_LENGTHS, ctl_params,
    2699             :                                    sizeof(ctl_params));
    2700         336 :           if (err)
    2701             :             {
    2702           0 :               fail ("cipher-ccm, gcry_cipher_ctl GCRYCTL_SET_CCM_LENGTHS "
    2703             :                     "failed: %s\n", gpg_strerror (err));
    2704           0 :               gcry_cipher_close (hde);
    2705           0 :               gcry_cipher_close (hdd);
    2706           0 :               return;
    2707             :             }
    2708             : 
    2709         336 :           err = gcry_cipher_info (hde, GCRYCTL_GET_TAGLEN, NULL, &taglen2);
    2710         336 :           if (err)
    2711             :             {
    2712           0 :               fail ("cipher-ccm, gcryctl_get_taglen failed (tv %d): %s\n",
    2713             :                     i, gpg_strerror (err));
    2714           0 :               gcry_cipher_close (hde);
    2715           0 :               gcry_cipher_close (hdd);
    2716           0 :               return;
    2717             :             }
    2718         336 :           if (taglen2 != authlen)
    2719             :             {
    2720           0 :               fail ("cipher-ccm, gcryctl_get_taglen returned bad length"
    2721             :                     " (tv %d): got=%zu want=%zu\n",
    2722             :                     i, taglen2, authlen);
    2723           0 :               gcry_cipher_close (hde);
    2724           0 :               gcry_cipher_close (hdd);
    2725           0 :               return;
    2726             :             }
    2727             : 
    2728         336 :           aadsplit = split > tv[i].aadlen ? 0 : split;
    2729             : 
    2730         336 :           err = gcry_cipher_authenticate (hde, tv[i].aad,
    2731         336 :                                           tv[i].aadlen - aadsplit);
    2732         336 :           if (!err)
    2733         672 :             err = gcry_cipher_authenticate (hde,
    2734         336 :                                             &tv[i].aad[tv[i].aadlen - aadsplit],
    2735             :                                             aadsplit);
    2736         336 :           if (!err)
    2737         336 :             err = gcry_cipher_authenticate (hdd, tv[i].aad,
    2738         336 :                                             tv[i].aadlen - aadsplit);
    2739         336 :           if (!err)
    2740         672 :             err = gcry_cipher_authenticate (hdd,
    2741         336 :                                             &tv[i].aad[tv[i].aadlen - aadsplit],
    2742             :                                             aadsplit);
    2743         336 :           if (err)
    2744             :             {
    2745           0 :               fail ("cipher-ccm, gcry_cipher_authenticate failed: %s\n",
    2746             :                    gpg_strerror (err));
    2747           0 :               gcry_cipher_close (hde);
    2748           0 :               gcry_cipher_close (hdd);
    2749           0 :               return;
    2750             :             }
    2751             : 
    2752         336 :           err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN, tv[i].plaintext,
    2753         336 :                                      tv[i].plainlen - split);
    2754         336 :           if (!err)
    2755        1008 :             err = gcry_cipher_encrypt (hde, &out[tv[i].plainlen - split],
    2756         336 :                                        MAX_DATA_LEN - (tv[i].plainlen - split),
    2757         336 :                                        &tv[i].plaintext[tv[i].plainlen - split],
    2758             :                                        split);
    2759         336 :           if (err)
    2760             :             {
    2761           0 :               fail ("cipher-ccm, gcry_cipher_encrypt (%d:%d) failed: %s\n",
    2762             :                     i, j, gpg_strerror (err));
    2763           0 :               gcry_cipher_close (hde);
    2764           0 :               gcry_cipher_close (hdd);
    2765           0 :               return;
    2766             :             }
    2767             : 
    2768         336 :           err = gcry_cipher_gettag (hde, &out[tv[i].plainlen], authlen);
    2769         336 :           if (err)
    2770             :             {
    2771           0 :               fail ("cipher-ccm, gcry_cipher_gettag (%d:%d) failed: %s\n",
    2772             :                     i, j, gpg_strerror (err));
    2773           0 :               gcry_cipher_close (hde);
    2774           0 :               gcry_cipher_close (hdd);
    2775           0 :               return;
    2776             :             }
    2777             : 
    2778         336 :           if (memcmp (tv[i].ciphertext, out, tv[i].cipherlen))
    2779           0 :             fail ("cipher-ccm, encrypt mismatch entry %d:%d\n", i, j);
    2780             : 
    2781         336 :           err = gcry_cipher_decrypt (hdd, out, tv[i].plainlen - split, NULL, 0);
    2782         336 :           if (!err)
    2783         336 :             err = gcry_cipher_decrypt (hdd, &out[tv[i].plainlen - split], split,
    2784             :                                        NULL, 0);
    2785         336 :           if (err)
    2786             :             {
    2787           0 :               fail ("cipher-ccm, gcry_cipher_decrypt (%d:%d) failed: %s\n",
    2788             :                     i, j, gpg_strerror (err));
    2789           0 :               gcry_cipher_close (hde);
    2790           0 :               gcry_cipher_close (hdd);
    2791           0 :               return;
    2792             :             }
    2793             : 
    2794         336 :           if (memcmp (tv[i].plaintext, out, tv[i].plainlen))
    2795           0 :             fail ("cipher-ccm, decrypt mismatch entry %d:%d\n", i, j);
    2796             : 
    2797         336 :           err = gcry_cipher_checktag (hdd, &out[tv[i].plainlen], authlen);
    2798         336 :           if (err)
    2799             :             {
    2800           0 :               fail ("cipher-ccm, gcry_cipher_checktag (%d:%d) failed: %s\n",
    2801             :                     i, j, gpg_strerror (err));
    2802           0 :               gcry_cipher_close (hde);
    2803           0 :               gcry_cipher_close (hdd);
    2804           0 :               return;
    2805             :             }
    2806             : 
    2807         336 :           gcry_cipher_close (hde);
    2808         336 :           gcry_cipher_close (hdd);
    2809             :         }
    2810             :     }
    2811             : 
    2812             :   /* Large buffer tests.  */
    2813             : 
    2814             :   /* Test encoding of aadlen > 0xfeff.  */
    2815             :   {
    2816             :     static const char key[]={0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
    2817             :                              0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f};
    2818             :     static const char iv[]={0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
    2819             :     static const char tag[]={0x9C,0x76,0xE7,0x33,0xD5,0x15,0xB3,0x6C,
    2820             :                              0xBA,0x76,0x95,0xF7,0xFB,0x91};
    2821             :     char buf[1024];
    2822           1 :     size_t enclen = 0x20000;
    2823           1 :     size_t aadlen = 0x20000;
    2824           1 :     size_t taglen = sizeof(tag);
    2825             : 
    2826           1 :     err = gcry_cipher_open (&hde, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CCM, 0);
    2827           1 :     if (err)
    2828             :       {
    2829           0 :         fail ("cipher-ccm-large, gcry_cipher_open failed: %s\n",
    2830             :               gpg_strerror (err));
    2831           0 :         return;
    2832             :       }
    2833             : 
    2834           1 :     err = gcry_cipher_setkey (hde, key, sizeof (key));
    2835           1 :     if (err)
    2836             :       {
    2837           0 :          fail ("cipher-ccm-large, gcry_cipher_setkey failed: %s\n",
    2838             :                gpg_strerror (err));
    2839           0 :          gcry_cipher_close (hde);
    2840           0 :          return;
    2841             :       }
    2842             : 
    2843           1 :     err = gcry_cipher_setiv (hde, iv, sizeof (iv));
    2844           1 :     if (err)
    2845             :       {
    2846           0 :         fail ("cipher-ccm-large, gcry_cipher_setiv failed: %s\n",
    2847             :               gpg_strerror (err));
    2848           0 :         gcry_cipher_close (hde);
    2849           0 :         return;
    2850             :       }
    2851             : 
    2852           1 :     ctl_params[0] = enclen; /* encryptedlen */
    2853           1 :     ctl_params[1] = aadlen; /* aadlen */
    2854           1 :     ctl_params[2] = taglen; /* authtaglen */
    2855           1 :     err = gcry_cipher_ctl (hde, GCRYCTL_SET_CCM_LENGTHS, ctl_params,
    2856             :                            sizeof(ctl_params));
    2857           1 :     if (err)
    2858             :       {
    2859           0 :         fail ("cipher-ccm-large, gcry_cipher_ctl GCRYCTL_SET_CCM_LENGTHS "
    2860             :               "failed: %s\n", gpg_strerror (err));
    2861           0 :         gcry_cipher_close (hde);
    2862           0 :         return;
    2863             :       }
    2864             : 
    2865           1 :     memset (buf, 0xaa, sizeof(buf));
    2866             : 
    2867         129 :     for (i = 0; i < aadlen; i += sizeof(buf))
    2868             :       {
    2869         128 :         err = gcry_cipher_authenticate (hde, buf, sizeof (buf));
    2870         128 :         if (err)
    2871             :           {
    2872           0 :             fail ("cipher-ccm-large, gcry_cipher_authenticate failed: %s\n",
    2873             :                  gpg_strerror (err));
    2874           0 :             gcry_cipher_close (hde);
    2875           0 :             return;
    2876             :           }
    2877             :       }
    2878             : 
    2879         129 :     for (i = 0; i < enclen; i += sizeof(buf))
    2880             :       {
    2881         128 :         memset (buf, 0xee, sizeof(buf));
    2882         128 :         err = gcry_cipher_encrypt (hde, buf, sizeof (buf), NULL, 0);
    2883         128 :         if (err)
    2884             :           {
    2885           0 :             fail ("cipher-ccm-large, gcry_cipher_encrypt failed: %s\n",
    2886             :                  gpg_strerror (err));
    2887           0 :             gcry_cipher_close (hde);
    2888           0 :             return;
    2889             :           }
    2890             :       }
    2891             : 
    2892           1 :     err = gcry_cipher_gettag (hde, buf, taglen);
    2893           1 :     if (err)
    2894             :       {
    2895           0 :         fail ("cipher-ccm-large, gcry_cipher_gettag failed: %s\n",
    2896             :               gpg_strerror (err));
    2897           0 :         gcry_cipher_close (hde);
    2898           0 :         return;
    2899             :       }
    2900             : 
    2901           1 :     if (memcmp (buf, tag, taglen) != 0)
    2902           0 :       fail ("cipher-ccm-large, encrypt mismatch entry\n");
    2903             : 
    2904           1 :     gcry_cipher_close (hde);
    2905             :   }
    2906             : 
    2907             : #if 0
    2908             :   /* Test encoding of aadlen > 0xffffffff.  */
    2909             :   {
    2910             :     static const char key[]={0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
    2911             :                              0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f};
    2912             :     static const char iv[]={0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
    2913             :     static const char tag[]={0x01,0xB2,0xC3,0x4A,0xA6,0x6A,0x07,0x6D,
    2914             :                              0xBC,0xBD,0xEA,0x17,0xD3,0x73,0xD7,0xD4};
    2915             :     char buf[1024];
    2916             :     size_t enclen = (size_t)0xffffffff + 1 + 1024;
    2917             :     size_t aadlen = (size_t)0xffffffff + 1 + 1024;
    2918             :     size_t taglen = sizeof(tag);
    2919             : 
    2920             :     err = gcry_cipher_open (&hde, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CCM, 0);
    2921             :     if (err)
    2922             :       {
    2923             :         fail ("cipher-ccm-huge, gcry_cipher_open failed: %s\n",
    2924             :               gpg_strerror (err));
    2925             :         return;
    2926             :       }
    2927             : 
    2928             :     err = gcry_cipher_setkey (hde, key, sizeof (key));
    2929             :     if (err)
    2930             :       {
    2931             :          fail ("cipher-ccm-huge, gcry_cipher_setkey failed: %s\n",
    2932             :                gpg_strerror (err));
    2933             :          gcry_cipher_close (hde);
    2934             :          return;
    2935             :       }
    2936             : 
    2937             :     err = gcry_cipher_setiv (hde, iv, sizeof (iv));
    2938             :     if (err)
    2939             :       {
    2940             :         fail ("cipher-ccm-huge, gcry_cipher_setiv failed: %s\n",
    2941             :               gpg_strerror (err));
    2942             :         gcry_cipher_close (hde);
    2943             :         return;
    2944             :       }
    2945             : 
    2946             :     ctl_params[0] = enclen; /* encryptedlen */
    2947             :     ctl_params[1] = aadlen; /* aadlen */
    2948             :     ctl_params[2] = taglen; /* authtaglen */
    2949             :     err = gcry_cipher_ctl (hde, GCRYCTL_SET_CCM_LENGTHS, ctl_params,
    2950             :                            sizeof(ctl_params));
    2951             :     if (err)
    2952             :       {
    2953             :         fail ("cipher-ccm-huge, gcry_cipher_ctl GCRYCTL_SET_CCM_LENGTHS failed:"
    2954             :               "%s\n", gpg_strerror (err));
    2955             :         gcry_cipher_close (hde);
    2956             :         return;
    2957             :       }
    2958             : 
    2959             :     memset (buf, 0xaa, sizeof(buf));
    2960             : 
    2961             :     for (i = 0; i < aadlen; i += sizeof(buf))
    2962             :       {
    2963             :         err = gcry_cipher_authenticate (hde, buf, sizeof (buf));
    2964             :         if (err)
    2965             :           {
    2966             :             fail ("cipher-ccm-huge, gcry_cipher_authenticate failed: %s\n",
    2967             :                  gpg_strerror (err));
    2968             :             gcry_cipher_close (hde);
    2969             :             return;
    2970             :           }
    2971             :       }
    2972             : 
    2973             :     for (i = 0; i < enclen; i += sizeof(buf))
    2974             :       {
    2975             :         memset (buf, 0xee, sizeof(buf));
    2976             :         err = gcry_cipher_encrypt (hde, buf, sizeof (buf), NULL, 0);
    2977             :         if (err)
    2978             :           {
    2979             :             fail ("cipher-ccm-huge, gcry_cipher_encrypt failed: %s\n",
    2980             :                  gpg_strerror (err));
    2981             :             gcry_cipher_close (hde);
    2982             :             return;
    2983             :           }
    2984             :       }
    2985             : 
    2986             :     err = gcry_cipher_gettag (hde, buf, taglen);
    2987             :     if (err)
    2988             :       {
    2989             :         fail ("cipher-ccm-huge, gcry_cipher_gettag failed: %s\n",
    2990             :               gpg_strerror (err));
    2991             :         gcry_cipher_close (hde);
    2992             :         return;
    2993             :       }
    2994             : 
    2995             :     if (memcmp (buf, tag, taglen) != 0)
    2996             :       fail ("cipher-ccm-huge, encrypt mismatch entry\n");
    2997             : 
    2998             :     gcry_cipher_close (hde);
    2999             :   }
    3000             : 
    3001             :   if (verbose)
    3002             :     fprintf (stderr, "  Completed CCM checks.\n");
    3003             : #endif
    3004             : }
    3005             : 
    3006             : 
    3007             : static void
    3008           2 : do_check_ocb_cipher (int inplace)
    3009             : {
    3010             :   /* Note that we use hex strings and not binary strings in TV.  That
    3011             :      makes it easier to maintain the test vectors.  */
    3012             :   static const struct
    3013             :   {
    3014             :     int algo;
    3015             :     int taglen;         /* 16, 12, or 8 bytes  */
    3016             :     const char *key;    /* NULL means "000102030405060708090A0B0C0D0E0F" */
    3017             :     const char *nonce;
    3018             :     const char *aad;
    3019             :     const char *plain;
    3020             :     const char *ciph;
    3021             :   } tv[] = {
    3022             :     /* The RFC-7253 test vectos*/
    3023             :     { GCRY_CIPHER_AES, 16, NULL,
    3024             :       "BBAA99887766554433221100",
    3025             :       "",
    3026             :       "",
    3027             :       "785407BFFFC8AD9EDCC5520AC9111EE6"
    3028             :     },
    3029             :     { GCRY_CIPHER_AES, 16, NULL,
    3030             :       "BBAA99887766554433221101",
    3031             :       "0001020304050607",
    3032             :       "0001020304050607",
    3033             :       "6820B3657B6F615A5725BDA0D3B4EB3A257C9AF1F8F03009"
    3034             :     },
    3035             :     { GCRY_CIPHER_AES, 16, NULL,
    3036             :       "BBAA99887766554433221102",
    3037             :       "0001020304050607",
    3038             :       "",
    3039             :       "81017F8203F081277152FADE694A0A00"
    3040             :     },
    3041             :     { GCRY_CIPHER_AES, 16, NULL,
    3042             :       "BBAA99887766554433221103",
    3043             :       "",
    3044             :       "0001020304050607",
    3045             :       "45DD69F8F5AAE72414054CD1F35D82760B2CD00D2F99BFA9"
    3046             :     },
    3047             :     { GCRY_CIPHER_AES, 16, NULL,
    3048             :       "BBAA99887766554433221104",
    3049             :       "000102030405060708090A0B0C0D0E0F",
    3050             :       "000102030405060708090A0B0C0D0E0F",
    3051             :       "571D535B60B277188BE5147170A9A22C3AD7A4FF3835B8C5"
    3052             :       "701C1CCEC8FC3358"
    3053             :     },
    3054             :     { GCRY_CIPHER_AES, 16, NULL,
    3055             :       "BBAA99887766554433221105",
    3056             :       "000102030405060708090A0B0C0D0E0F",
    3057             :       "",
    3058             :       "8CF761B6902EF764462AD86498CA6B97"
    3059             :     },
    3060             :     { GCRY_CIPHER_AES, 16, NULL,
    3061             :       "BBAA99887766554433221106",
    3062             :       "",
    3063             :       "000102030405060708090A0B0C0D0E0F",
    3064             :       "5CE88EC2E0692706A915C00AEB8B2396F40E1C743F52436B"
    3065             :       "DF06D8FA1ECA343D"
    3066             :     },
    3067             :     { GCRY_CIPHER_AES, 16, NULL,
    3068             :       "BBAA99887766554433221107",
    3069             :       "000102030405060708090A0B0C0D0E0F1011121314151617",
    3070             :       "000102030405060708090A0B0C0D0E0F1011121314151617",
    3071             :       "1CA2207308C87C010756104D8840CE1952F09673A448A122"
    3072             :       "C92C62241051F57356D7F3C90BB0E07F"
    3073             :     },
    3074             :     { GCRY_CIPHER_AES, 16, NULL,
    3075             :       "BBAA99887766554433221108",
    3076             :       "000102030405060708090A0B0C0D0E0F1011121314151617",
    3077             :       "",
    3078             :       "6DC225A071FC1B9F7C69F93B0F1E10DE"
    3079             :     },
    3080             :     { GCRY_CIPHER_AES, 16, NULL,
    3081             :       "BBAA99887766554433221109",
    3082             :       "",
    3083             :       "000102030405060708090A0B0C0D0E0F1011121314151617",
    3084             :       "221BD0DE7FA6FE993ECCD769460A0AF2D6CDED0C395B1C3C"
    3085             :       "E725F32494B9F914D85C0B1EB38357FF"
    3086             :     },
    3087             :     { GCRY_CIPHER_AES, 16, NULL,
    3088             :       "BBAA9988776655443322110A",
    3089             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3090             :       "18191A1B1C1D1E1F",
    3091             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3092             :       "18191A1B1C1D1E1F",
    3093             :       "BD6F6C496201C69296C11EFD138A467ABD3C707924B964DE"
    3094             :       "AFFC40319AF5A48540FBBA186C5553C68AD9F592A79A4240"
    3095             :     },
    3096             :     { GCRY_CIPHER_AES, 16, NULL,
    3097             :       "BBAA9988776655443322110B",
    3098             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3099             :       "18191A1B1C1D1E1F",
    3100             :       "",
    3101             :       "FE80690BEE8A485D11F32965BC9D2A32"
    3102             :     },
    3103             :     { GCRY_CIPHER_AES, 16, NULL,
    3104             :       "BBAA9988776655443322110C",
    3105             :       "",
    3106             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3107             :       "18191A1B1C1D1E1F",
    3108             :       "2942BFC773BDA23CABC6ACFD9BFD5835BD300F0973792EF4"
    3109             :       "6040C53F1432BCDFB5E1DDE3BC18A5F840B52E653444D5DF"
    3110             :     },
    3111             :     { GCRY_CIPHER_AES, 16, NULL,
    3112             :       "BBAA9988776655443322110D",
    3113             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3114             :       "18191A1B1C1D1E1F2021222324252627",
    3115             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3116             :       "18191A1B1C1D1E1F2021222324252627",
    3117             :       "D5CA91748410C1751FF8A2F618255B68A0A12E093FF45460"
    3118             :       "6E59F9C1D0DDC54B65E8628E568BAD7AED07BA06A4A69483"
    3119             :       "A7035490C5769E60"
    3120             :     },
    3121             :     { GCRY_CIPHER_AES, 16, NULL,
    3122             :       "BBAA9988776655443322110E",
    3123             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3124             :       "18191A1B1C1D1E1F2021222324252627",
    3125             :       "",
    3126             :       "C5CD9D1850C141E358649994EE701B68"
    3127             :     },
    3128             :     { GCRY_CIPHER_AES, 16, NULL,
    3129             :       "BBAA9988776655443322110F",
    3130             :       "",
    3131             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3132             :       "18191A1B1C1D1E1F2021222324252627",
    3133             :       "4412923493C57D5DE0D700F753CCE0D1D2D95060122E9F15"
    3134             :       "A5DDBFC5787E50B5CC55EE507BCB084E479AD363AC366B95"
    3135             :       "A98CA5F3000B1479"
    3136             :     },
    3137             :     { GCRY_CIPHER_AES, 12, "0F0E0D0C0B0A09080706050403020100",
    3138             :       "BBAA9988776655443322110D",
    3139             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3140             :       "18191A1B1C1D1E1F2021222324252627",
    3141             :       "000102030405060708090A0B0C0D0E0F1011121314151617"
    3142             :       "18191A1B1C1D1E1F2021222324252627",
    3143             :       "1792A4E31E0755FB03E31B22116E6C2DDF9EFD6E33D536F1"
    3144             :       "A0124B0A55BAE884ED93481529C76B6AD0C515F4D1CDD4FD"
    3145             :       "AC4F02AA"
    3146             :     }
    3147             :   };
    3148           2 :   gpg_error_t err = 0;
    3149             :   gcry_cipher_hd_t hde, hdd;
    3150             :   unsigned char out[MAX_DATA_LEN];
    3151             :   unsigned char tag[16];
    3152             :   int tidx;
    3153             : 
    3154           2 :   if (verbose)
    3155           0 :     fprintf (stderr, "  Starting OCB checks.\n");
    3156             : 
    3157          72 :   for (tidx = 0; tidx < DIM (tv); tidx++)
    3158             :     {
    3159             :       char *key, *nonce, *aad, *ciph, *plain;
    3160             :       size_t keylen, noncelen, aadlen, ciphlen, plainlen;
    3161             :       int taglen;
    3162             :       size_t taglen2;
    3163             : 
    3164          34 :       if (verbose)
    3165           0 :         fprintf (stderr, "    checking OCB mode for %s [%i] (tv %d)\n",
    3166             :                  gcry_cipher_algo_name (tv[tidx].algo), tv[tidx].algo, tidx);
    3167             : 
    3168             :       /* Convert to hex strings to binary.  */
    3169          34 :       key   = hex2buffer (tv[tidx].key? tv[tidx].key
    3170             :                           /*        */: "000102030405060708090A0B0C0D0E0F",
    3171             :                           &keylen);
    3172          34 :       nonce = hex2buffer (tv[tidx].nonce, &noncelen);
    3173          34 :       aad   = hex2buffer (tv[tidx].aad, &aadlen);
    3174          34 :       plain = hex2buffer (tv[tidx].plain, &plainlen);
    3175          34 :       ciph  = hex2buffer (tv[tidx].ciph, &ciphlen);
    3176             : 
    3177             :       /* Check that our test vectors are sane.  */
    3178          34 :       assert (plainlen <= sizeof out);
    3179          34 :       assert (tv[tidx].taglen <= ciphlen);
    3180          34 :       assert (tv[tidx].taglen <= sizeof tag);
    3181             : 
    3182          34 :       err = gcry_cipher_open (&hde, tv[tidx].algo, GCRY_CIPHER_MODE_OCB, 0);
    3183          34 :       if (!err)
    3184          34 :         err = gcry_cipher_open (&hdd, tv[tidx].algo, GCRY_CIPHER_MODE_OCB, 0);
    3185          34 :       if (err)
    3186             :         {
    3187           0 :           fail ("cipher-ocb, gcry_cipher_open failed (tv %d): %s\n",
    3188             :                 tidx, gpg_strerror (err));
    3189           0 :           return;
    3190             :         }
    3191             : 
    3192             :       /* Set the taglen.  For the first handle we do this only for a
    3193             :          non-default taglen.  For the second handle we check that we
    3194             :          can also set to the default taglen.  */
    3195          34 :       taglen = tv[tidx].taglen;
    3196          34 :       if (taglen != 16)
    3197             :         {
    3198           2 :           err = gcry_cipher_ctl (hde, GCRYCTL_SET_TAGLEN,
    3199             :                                  &taglen, sizeof taglen);
    3200           2 :           if (err)
    3201             :             {
    3202           0 :               fail ("cipher-ocb, gcryctl_set_taglen failed (tv %d): %s\n",
    3203             :                     tidx, gpg_strerror (err));
    3204           0 :               gcry_cipher_close (hde);
    3205           0 :               gcry_cipher_close (hdd);
    3206           0 :               return;
    3207             :             }
    3208             :         }
    3209          34 :       err = gcry_cipher_ctl (hdd, GCRYCTL_SET_TAGLEN,
    3210             :                              &taglen, sizeof taglen);
    3211          34 :       if (err)
    3212             :         {
    3213           0 :           fail ("cipher-ocb, gcryctl_set_taglen failed (tv %d): %s\n",
    3214             :                 tidx, gpg_strerror (err));
    3215           0 :           gcry_cipher_close (hde);
    3216           0 :           gcry_cipher_close (hdd);
    3217           0 :           return;
    3218             :         }
    3219             : 
    3220          34 :       err = gcry_cipher_info (hde, GCRYCTL_GET_TAGLEN, NULL, &taglen2);
    3221          34 :       if (err)
    3222             :         {
    3223           0 :           fail ("cipher-ocb, gcryctl_get_taglen failed (tv %d): %s\n",
    3224             :                 tidx, gpg_strerror (err));
    3225           0 :           gcry_cipher_close (hde);
    3226           0 :           gcry_cipher_close (hdd);
    3227           0 :           return;
    3228             :         }
    3229          34 :       if (taglen2 != tv[tidx].taglen)
    3230             :         {
    3231           0 :           fail ("cipher-ocb, gcryctl_get_taglen returned bad length (tv %d): "
    3232             :                 "got=%zu want=%d\n",
    3233             :                 tidx, taglen2, tv[tidx].taglen);
    3234           0 :           gcry_cipher_close (hde);
    3235           0 :           gcry_cipher_close (hdd);
    3236           0 :           return;
    3237             :         }
    3238             : 
    3239          34 :       err = gcry_cipher_setkey (hde, key, keylen);
    3240          34 :       if (!err)
    3241          34 :         err = gcry_cipher_setkey (hdd, key, keylen);
    3242          34 :       if (err)
    3243             :         {
    3244           0 :           fail ("cipher-ocb, gcry_cipher_setkey failed (tv %d): %s\n",
    3245             :                 tidx, gpg_strerror (err));
    3246           0 :           gcry_cipher_close (hde);
    3247           0 :           gcry_cipher_close (hdd);
    3248           0 :           return;
    3249             :         }
    3250             : 
    3251          34 :       err = gcry_cipher_setiv (hde, nonce, noncelen);
    3252          34 :       if (!err)
    3253          34 :         err = gcry_cipher_setiv (hdd, nonce, noncelen);
    3254          34 :       if (err)
    3255             :         {
    3256           0 :           fail ("cipher-ocb, gcry_cipher_setiv failed (tv %d): %s\n",
    3257             :                 tidx, gpg_strerror (err));
    3258           0 :           gcry_cipher_close (hde);
    3259           0 :           gcry_cipher_close (hdd);
    3260           0 :           return;
    3261             :         }
    3262             : 
    3263          34 :       err = gcry_cipher_authenticate (hde, aad, aadlen);
    3264          34 :       if (err)
    3265             :         {
    3266           0 :           fail ("cipher-ocb, gcry_cipher_authenticate failed (tv %d): %s\n",
    3267             :                 tidx, gpg_strerror (err));
    3268           0 :           gcry_cipher_close (hde);
    3269           0 :           gcry_cipher_close (hdd);
    3270           0 :           return;
    3271             :         }
    3272             : 
    3273          34 :       err = gcry_cipher_final (hde);
    3274          34 :       if (!err)
    3275             :         {
    3276          34 :           if (inplace)
    3277             :             {
    3278          17 :               memcpy(out, plain, plainlen);
    3279          17 :               err = gcry_cipher_encrypt (hde, out, plainlen, NULL, 0);
    3280             :             }
    3281             :           else
    3282             :             {
    3283          17 :               err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
    3284             :                                          plain, plainlen);
    3285             :             }
    3286             :         }
    3287          34 :       if (err)
    3288             :         {
    3289           0 :           fail ("cipher-ocb, gcry_cipher_encrypt failed (tv %d): %s\n",
    3290             :                 tidx, gpg_strerror (err));
    3291           0 :           gcry_cipher_close (hde);
    3292           0 :           gcry_cipher_close (hdd);
    3293           0 :           return;
    3294             :         }
    3295             : 
    3296             :       /* Check that the encrypt output matches the expected cipher
    3297             :          text without the tag (i.e. at the length of plaintext).  */
    3298          34 :       if (memcmp (ciph, out, plainlen))
    3299             :         {
    3300           0 :           mismatch (ciph, plainlen, out, plainlen);
    3301           0 :           fail ("cipher-ocb, encrypt data mismatch (tv %d)\n", tidx);
    3302             :         }
    3303             : 
    3304             :       /* Check that the tag matches TAGLEN bytes from the end of the
    3305             :          expected ciphertext.  */
    3306          34 :       err = gcry_cipher_gettag (hde, tag, tv[tidx].taglen);
    3307          34 :       if (err)
    3308             :         {
    3309           0 :           fail ("cipher_ocb, gcry_cipher_gettag failed (tv %d): %s\n",
    3310             :                 tidx, gpg_strerror (err));
    3311             :         }
    3312          34 :       if (memcmp (ciph + ciphlen - tv[tidx].taglen, tag, tv[tidx].taglen))
    3313             :         {
    3314           0 :           mismatch (ciph + ciphlen - tv[tidx].taglen, tv[tidx].taglen,
    3315           0 :                     tag, tv[tidx].taglen);
    3316           0 :           fail ("cipher-ocb, encrypt tag mismatch (tv %d)\n", tidx);
    3317             :         }
    3318             : 
    3319             : 
    3320          34 :       err = gcry_cipher_authenticate (hdd, aad, aadlen);
    3321          34 :       if (err)
    3322             :         {
    3323           0 :           fail ("cipher-ocb, gcry_cipher_authenticate failed (tv %d): %s\n",
    3324             :                 tidx, gpg_strerror (err));
    3325           0 :           gcry_cipher_close (hde);
    3326           0 :           gcry_cipher_close (hdd);
    3327           0 :           return;
    3328             :         }
    3329             : 
    3330             :       /* Now for the decryption.  */
    3331          34 :       err = gcry_cipher_final (hdd);
    3332          34 :       if (!err)
    3333             :         {
    3334          34 :           if (inplace)
    3335             :             {
    3336          17 :               err = gcry_cipher_decrypt (hdd, out, plainlen, NULL, 0);
    3337             :             }
    3338             :           else
    3339             :             {
    3340             :               unsigned char tmp[MAX_DATA_LEN];
    3341             : 
    3342          17 :               memcpy(tmp, out, plainlen);
    3343          17 :               err = gcry_cipher_decrypt (hdd, out, plainlen, tmp, plainlen);
    3344             :             }
    3345             :         }
    3346          34 :       if (err)
    3347             :         {
    3348           0 :           fail ("cipher-ocb, gcry_cipher_decrypt (tv %d) failed: %s\n",
    3349             :                 tidx, gpg_strerror (err));
    3350           0 :           gcry_cipher_close (hde);
    3351           0 :           gcry_cipher_close (hdd);
    3352           0 :           return;
    3353             :         }
    3354             : 
    3355             :       /* We still have TAG from the encryption.  */
    3356          34 :       err = gcry_cipher_checktag (hdd, tag, tv[tidx].taglen);
    3357          34 :       if (err)
    3358             :         {
    3359           0 :           fail ("cipher-ocb, gcry_cipher_checktag failed (tv %d): %s\n",
    3360             :                 tidx, gpg_strerror (err));
    3361             :         }
    3362             : 
    3363             :       /* Check that the decrypt output matches the original plaintext.  */
    3364          34 :       if (memcmp (plain, out, plainlen))
    3365             :         {
    3366           0 :           mismatch (plain, plainlen, out, plainlen);
    3367           0 :           fail ("cipher-ocb, decrypt data mismatch (tv %d)\n", tidx);
    3368             :         }
    3369             : 
    3370             :       /* Check that gettag also works for decryption.  */
    3371          34 :       err = gcry_cipher_gettag (hdd, tag, tv[tidx].taglen);
    3372          34 :       if (err)
    3373             :         {
    3374           0 :           fail ("cipher_ocb, decrypt gettag failed (tv %d): %s\n",
    3375             :                 tidx, gpg_strerror (err));
    3376             :         }
    3377          34 :       if (memcmp (ciph + ciphlen - tv[tidx].taglen, tag, tv[tidx].taglen))
    3378             :         {
    3379           0 :           mismatch (ciph + ciphlen - tv[tidx].taglen, tv[tidx].taglen,
    3380           0 :                     tag, tv[tidx].taglen);
    3381           0 :           fail ("cipher-ocb, decrypt tag mismatch (tv %d)\n", tidx);
    3382             :         }
    3383             : 
    3384          34 :       gcry_cipher_close (hde);
    3385          34 :       gcry_cipher_close (hdd);
    3386             : 
    3387          34 :       xfree (nonce);
    3388          34 :       xfree (aad);
    3389          34 :       xfree (ciph);
    3390          34 :       xfree (plain);
    3391          34 :       xfree (key);
    3392             :     }
    3393             : 
    3394           2 :   if (verbose)
    3395           0 :     fprintf (stderr, "  Completed OCB checks.\n");
    3396             : }
    3397             : 
    3398             : 
    3399             : static void
    3400          60 : check_ocb_cipher_largebuf_split (int algo, int keylen, const char *tagexpect,
    3401             :                                  unsigned int splitpos)
    3402             : {
    3403             :   static const unsigned char key[32] =
    3404             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
    3405             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
    3406             :   static const unsigned char nonce[12] =
    3407             :         "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x00\x01\x02\x03";
    3408          60 :   const size_t buflen = 1024 * 1024 * 2 + 32;
    3409             :   unsigned char *inbuf;
    3410             :   unsigned char *outbuf;
    3411          60 :   gpg_error_t err = 0;
    3412             :   gcry_cipher_hd_t hde, hdd;
    3413             :   unsigned char tag[16];
    3414             :   int i;
    3415             : 
    3416          60 :   inbuf = xmalloc(buflen);
    3417          60 :   if (!inbuf)
    3418             :     {
    3419           0 :       fail ("out-of-memory\n");
    3420           0 :       return;
    3421             :     }
    3422          60 :   outbuf = xmalloc(buflen);
    3423          60 :   if (!outbuf)
    3424             :     {
    3425           0 :       fail ("out-of-memory\n");
    3426           0 :       xfree(inbuf);
    3427           0 :       return;
    3428             :     }
    3429             : 
    3430   125831100 :   for (i = 0; i < buflen; i++)
    3431   125831040 :     inbuf[i] = 'a';
    3432             : 
    3433          60 :   err = gcry_cipher_open (&hde, algo, GCRY_CIPHER_MODE_OCB, 0);
    3434          60 :   if (!err)
    3435          60 :     err = gcry_cipher_open (&hdd, algo, GCRY_CIPHER_MODE_OCB, 0);
    3436          60 :   if (err)
    3437             :     {
    3438           0 :       fail ("cipher-ocb, gcry_cipher_open failed (large, algo %d): %s\n",
    3439             :             algo, gpg_strerror (err));
    3440           0 :       goto out_free;
    3441             :     }
    3442             : 
    3443          60 :   err = gcry_cipher_setkey (hde, key, keylen);
    3444          60 :   if (!err)
    3445          60 :     err = gcry_cipher_setkey (hdd, key, keylen);
    3446          60 :   if (err)
    3447             :     {
    3448           0 :       fail ("cipher-ocb, gcry_cipher_setkey failed (large, algo %d): %s\n",
    3449             :             algo, gpg_strerror (err));
    3450           0 :       gcry_cipher_close (hde);
    3451           0 :       gcry_cipher_close (hdd);
    3452           0 :       goto out_free;
    3453             :     }
    3454             : 
    3455          60 :   err = gcry_cipher_setiv (hde, nonce, 12);
    3456          60 :   if (!err)
    3457          60 :     err = gcry_cipher_setiv (hdd, nonce, 12);
    3458          60 :   if (err)
    3459             :     {
    3460           0 :       fail ("cipher-ocb, gcry_cipher_setiv failed (large, algo %d): %s\n",
    3461             :             algo, gpg_strerror (err));
    3462           0 :       gcry_cipher_close (hde);
    3463           0 :       gcry_cipher_close (hdd);
    3464           0 :       goto out_free;
    3465             :     }
    3466             : 
    3467          60 :   if (splitpos)
    3468             :     {
    3469          50 :       err = gcry_cipher_authenticate (hde, inbuf, splitpos);
    3470             :     }
    3471          60 :   if (!err)
    3472             :     {
    3473          60 :       err = gcry_cipher_authenticate (hde, inbuf + splitpos, buflen - splitpos);
    3474             :     }
    3475          60 :   if (err)
    3476             :     {
    3477           0 :       fail ("cipher-ocb, gcry_cipher_authenticate failed (large, algo %d): %s\n",
    3478             :             algo, gpg_strerror (err));
    3479           0 :       gcry_cipher_close (hde);
    3480           0 :       gcry_cipher_close (hdd);
    3481           0 :       goto out_free;
    3482             :     }
    3483             : 
    3484          60 :   if (splitpos)
    3485             :     {
    3486          50 :       err = gcry_cipher_encrypt (hde, outbuf, splitpos, inbuf, splitpos);
    3487             :     }
    3488          60 :   if (!err)
    3489             :     {
    3490          60 :       err = gcry_cipher_final (hde);
    3491          60 :       if (!err)
    3492             :         {
    3493          60 :           err = gcry_cipher_encrypt (hde, outbuf + splitpos, buflen - splitpos,
    3494             :                                     inbuf + splitpos, buflen - splitpos);
    3495             :         }
    3496             :     }
    3497          60 :   if (err)
    3498             :     {
    3499           0 :       fail ("cipher-ocb, gcry_cipher_encrypt failed (large, algo %d): %s\n",
    3500             :             algo, gpg_strerror (err));
    3501           0 :       gcry_cipher_close (hde);
    3502           0 :       gcry_cipher_close (hdd);
    3503           0 :       goto out_free;
    3504             :     }
    3505             : 
    3506             :   /* Check that the tag matches. */
    3507          60 :   err = gcry_cipher_gettag (hde, tag, 16);
    3508          60 :   if (err)
    3509             :     {
    3510           0 :       fail ("cipher_ocb, gcry_cipher_gettag failed (large, algo %d): %s\n",
    3511             :             algo, gpg_strerror (err));
    3512             :     }
    3513          60 :   if (memcmp (tagexpect, tag, 16))
    3514             :     {
    3515           0 :       mismatch (tagexpect, 16, tag, 16);
    3516           0 :       fail ("cipher-ocb, encrypt tag mismatch (large, algo %d)\n", algo);
    3517             :     }
    3518             : 
    3519          60 :   err = gcry_cipher_authenticate (hdd, inbuf, buflen);
    3520          60 :   if (err)
    3521             :     {
    3522           0 :       fail ("cipher-ocb, gcry_cipher_authenticate failed (large, algo %d): %s\n",
    3523             :             algo, gpg_strerror (err));
    3524           0 :       gcry_cipher_close (hde);
    3525           0 :       gcry_cipher_close (hdd);
    3526           0 :       goto out_free;
    3527             :     }
    3528             : 
    3529             :   /* Now for the decryption.  */
    3530          60 :   if (splitpos)
    3531             :     {
    3532          50 :       err = gcry_cipher_decrypt (hdd, outbuf, splitpos, NULL, 0);
    3533             :     }
    3534          60 :   if (!err)
    3535             :     {
    3536          60 :       err = gcry_cipher_final (hdd);
    3537          60 :       if (!err)
    3538             :         {
    3539          60 :           err = gcry_cipher_decrypt (hdd, outbuf + splitpos, buflen - splitpos,
    3540             :                                      NULL, 0);
    3541             :         }
    3542             :     }
    3543          60 :   if (err)
    3544             :     {
    3545           0 :       fail ("cipher-ocb, gcry_cipher_decrypt (large, algo %d) failed: %s\n",
    3546             :             algo, gpg_strerror (err));
    3547           0 :       gcry_cipher_close (hde);
    3548           0 :       gcry_cipher_close (hdd);
    3549           0 :       goto out_free;
    3550             :     }
    3551             : 
    3552             :   /* We still have TAG from the encryption.  */
    3553          60 :   err = gcry_cipher_checktag (hdd, tag, 16);
    3554          60 :   if (err)
    3555             :     {
    3556           0 :       fail ("cipher-ocb, gcry_cipher_checktag failed (large, algo %d): %s\n",
    3557             :             algo, gpg_strerror (err));
    3558             :     }
    3559             : 
    3560             :   /* Check that the decrypt output matches the original plaintext.  */
    3561          60 :   if (memcmp (inbuf, outbuf, buflen))
    3562             :     {
    3563             :       /*mismatch (inbuf, buflen, outbuf, buflen);*/
    3564           0 :       fail ("cipher-ocb, decrypt data mismatch (large, algo %d)\n", algo);
    3565             :     }
    3566             : 
    3567             :   /* Check that gettag also works for decryption.  */
    3568          60 :   err = gcry_cipher_gettag (hdd, tag, 16);
    3569          60 :   if (err)
    3570             :     {
    3571           0 :       fail ("cipher_ocb, decrypt gettag failed (large, algo %d): %s\n",
    3572             :             algo, gpg_strerror (err));
    3573             :     }
    3574          60 :   if (memcmp (tagexpect, tag, 16))
    3575             :     {
    3576           0 :       mismatch (tagexpect, 16, tag, 16);
    3577           0 :       fail ("cipher-ocb, decrypt tag mismatch (large, algo %d)\n", algo);
    3578             :     }
    3579             : 
    3580          60 :   gcry_cipher_close (hde);
    3581          60 :   gcry_cipher_close (hdd);
    3582             : 
    3583             : out_free:
    3584          60 :   xfree(outbuf);
    3585          60 :   xfree(inbuf);
    3586             : }
    3587             : 
    3588             : 
    3589             : static void
    3590          10 : check_ocb_cipher_largebuf (int algo, int keylen, const char *tagexpect)
    3591             : {
    3592             :   unsigned int split;
    3593             : 
    3594          70 :   for (split = 0; split < 32 * 16; split = split * 2 + 16)
    3595             :     {
    3596          60 :       check_ocb_cipher_largebuf_split(algo, keylen, tagexpect, split);
    3597             :     }
    3598          10 : }
    3599             : 
    3600             : 
    3601             : static void
    3602           1 : check_ocb_cipher_splitaad (void)
    3603             : {
    3604           1 :   const char t_nonce[] = ("BBAA9988776655443322110D");
    3605           1 :   const char t_plain[] = ("000102030405060708090A0B0C0D0E0F1011121314151617"
    3606             :                           "18191A1B1C1D1E1F2021222324252627");
    3607           1 :   const char t_ciph[]  = ("D5CA91748410C1751FF8A2F618255B68A0A12E093FF45460"
    3608             :                           "6E59F9C1D0DDC54B65E8628E568BAD7AED07BA06A4A69483"
    3609             :                           "A7035490C5769E60");
    3610             :   struct {
    3611             :     const char *aad0;
    3612             :     const char *aad1;
    3613             :     const char *aad2;
    3614             :     const char *aad3;
    3615           1 :   } tv[] = {
    3616             :     {
    3617             :       "000102030405060708090A0B0C0D0E0F"
    3618             :       "101112131415161718191A1B1C1D1E1F2021222324252627"
    3619             :     },
    3620             :     {
    3621             :       "000102030405060708090A0B0C0D0E0F",
    3622             :       "101112131415161718191A1B1C1D1E1F",
    3623             :       "2021222324252627"
    3624             :     },
    3625             :     {
    3626             :       "000102030405060708090A0B0C0D0E0F",
    3627             :       "1011121314151617",
    3628             :       "18191A1B1C1D1E1F",
    3629             :       "2021222324252627"
    3630             :     },
    3631             :     {
    3632             :       "000102030405060708090A0B0C0D0E0F",
    3633             :       "101112131415161718191A1B1C1D1E1F",
    3634             :       "20",
    3635             :       "21222324252627"
    3636             :     },
    3637             :     {
    3638             :       "000102030405060708090A0B0C0D0E0F",
    3639             :       "101112131415161718191A1B1C1D1E1F",
    3640             :       "2021",
    3641             :       "222324252627"
    3642             :     },
    3643             :     {
    3644             :       "000102030405060708090A0B0C0D0E0F",
    3645             :       "101112131415161718191A1B1C1D1E1F",
    3646             :       "202122",
    3647             :       "2324252627"
    3648             :     },
    3649             :     {
    3650             :       "000102030405060708090A0B0C0D0E0F",
    3651             :       "101112131415161718191A1B1C1D1E1F",
    3652             :       "20212223",
    3653             :       "24252627"
    3654             :     },
    3655             :     {
    3656             :       "000102030405060708090A0B0C0D0E0F",
    3657             :       "101112131415161718191A1B1C1D1E1F",
    3658             :       "2021222324",
    3659             :       "252627"
    3660             :     },
    3661             :     {
    3662             :       "000102030405060708090A0B0C0D0E0F",
    3663             :       "101112131415161718191A1B1C1D1E1F",
    3664             :       "202122232425",
    3665             :       "2627"
    3666             :     },
    3667             :     {
    3668             :       "000102030405060708090A0B0C0D0E0F",
    3669             :       "101112131415161718191A1B1C1D1E1F",
    3670             :       "20212223242526"
    3671             :       "27"
    3672             :     },
    3673             :     {
    3674             :       "000102030405060708090A0B0C0D0E0F",
    3675             :       "1011121314151617",
    3676             :       "18191A1B1C1D1E1F2021222324252627"
    3677             :     },
    3678             :     {
    3679             :       "00",
    3680             :       "0102030405060708090A0B0C0D0E0F",
    3681             :       "1011121314151617",
    3682             :       "18191A1B1C1D1E1F2021222324252627"
    3683             :     },
    3684             :     {
    3685             :       "0001",
    3686             :       "02030405060708090A0B0C0D0E0F",
    3687             :       "1011121314151617",
    3688             :       "18191A1B1C1D1E1F2021222324252627"
    3689             :     },
    3690             :     {
    3691             :       "000102030405060708090A0B0C0D",
    3692             :       "0E0F",
    3693             :       "1011121314151617",
    3694             :       "18191A1B1C1D1E1F2021222324252627"
    3695             :     },
    3696             :     {
    3697             :       "000102030405060708090A0B0C0D0E",
    3698             :       "0F",
    3699             :       "1011121314151617",
    3700             :       "18191A1B1C1D1E1F2021222324252627"
    3701             :     },
    3702             :     {
    3703             :       "000102030405060708090A0B0C0D0E",
    3704             :       "0F101112131415161718191A1B1C1D1E1F20212223242526",
    3705             :       "27"
    3706             :     }
    3707             :   };
    3708             : 
    3709           1 :   gpg_error_t err = 0;
    3710             :   gcry_cipher_hd_t hde;
    3711             :   unsigned char out[MAX_DATA_LEN];
    3712             :   unsigned char tag[16];
    3713             :   int tidx;
    3714             :   char *key, *nonce, *ciph, *plain;
    3715             :   size_t keylen, noncelen, ciphlen, plainlen;
    3716             :   int i;
    3717             : 
    3718             :   /* Convert to hex strings to binary.  */
    3719           1 :   key   = hex2buffer ("000102030405060708090A0B0C0D0E0F", &keylen);
    3720           1 :   nonce = hex2buffer (t_nonce, &noncelen);
    3721           1 :   plain = hex2buffer (t_plain, &plainlen);
    3722           1 :   ciph  = hex2buffer (t_ciph, &ciphlen);
    3723             : 
    3724             :   /* Check that our test vectors are sane.  */
    3725           1 :   assert (plainlen <= sizeof out);
    3726           1 :   assert (16 <= ciphlen);
    3727             :   assert (16 <= sizeof tag);
    3728             : 
    3729          34 :   for (tidx = 0; tidx < DIM (tv); tidx++)
    3730             :     {
    3731             :       char *aad[4];
    3732             :       size_t aadlen[4];
    3733             : 
    3734          16 :       if (verbose)
    3735           0 :         fprintf (stderr, "    checking OCB aad split (tv %d)\n", tidx);
    3736             : 
    3737          16 :       aad[0] = tv[tidx].aad0? hex2buffer (tv[tidx].aad0, aadlen+0) : NULL;
    3738          16 :       aad[1] = tv[tidx].aad1? hex2buffer (tv[tidx].aad1, aadlen+1) : NULL;
    3739          16 :       aad[2] = tv[tidx].aad2? hex2buffer (tv[tidx].aad2, aadlen+2) : NULL;
    3740          16 :       aad[3] = tv[tidx].aad3? hex2buffer (tv[tidx].aad3, aadlen+3) : NULL;
    3741             : 
    3742          16 :       err = gcry_cipher_open (&hde, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_OCB, 0);
    3743          16 :       if (err)
    3744             :         {
    3745           0 :           fail ("cipher-ocb-splitadd, gcry_cipher_open failed: %s\n",
    3746             :                 gpg_strerror (err));
    3747           0 :           return;
    3748             :         }
    3749             : 
    3750          16 :       err = gcry_cipher_setkey (hde, key, keylen);
    3751          16 :       if (err)
    3752             :         {
    3753           0 :           fail ("cipher-ocb-splitaad, gcry_cipher_setkey failed: %s\n",
    3754             :                 gpg_strerror (err));
    3755           0 :           gcry_cipher_close (hde);
    3756           0 :           return;
    3757             :         }
    3758             : 
    3759          16 :       err = gcry_cipher_setiv (hde, nonce, noncelen);
    3760          16 :       if (err)
    3761             :         {
    3762           0 :           fail ("cipher-ocb-splitaad, gcry_cipher_setiv failed: %s\n",
    3763             :                 gpg_strerror (err));
    3764           0 :           gcry_cipher_close (hde);
    3765           0 :           return;
    3766             :         }
    3767             : 
    3768          80 :       for (i=0; i < DIM (aad); i++)
    3769             :         {
    3770          64 :           if (!aad[i])
    3771           7 :             continue;
    3772          57 :           err = gcry_cipher_authenticate (hde, aad[i], aadlen[i]);
    3773          57 :           if (err)
    3774             :             {
    3775           0 :               fail ("cipher-ocb-splitaad,"
    3776             :                     " gcry_cipher_authenticate failed (tv=%d,i=%d): %s\n",
    3777             :                     tidx, i, gpg_strerror (err));
    3778           0 :               gcry_cipher_close (hde);
    3779           0 :               return;
    3780             :             }
    3781             :         }
    3782             : 
    3783          16 :       err = gcry_cipher_final (hde);
    3784          16 :       if (!err)
    3785          16 :         err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN, plain, plainlen);
    3786          16 :       if (err)
    3787             :         {
    3788           0 :           fail ("cipher-ocb-splitaad, gcry_cipher_encrypt failed: %s\n",
    3789             :                 gpg_strerror (err));
    3790           0 :           gcry_cipher_close (hde);
    3791           0 :           return;
    3792             :         }
    3793             : 
    3794             :       /* Check that the encrypt output matches the expected cipher
    3795             :          text without the tag (i.e. at the length of plaintext).  */
    3796          16 :       if (memcmp (ciph, out, plainlen))
    3797             :         {
    3798           0 :           mismatch (ciph, plainlen, out, plainlen);
    3799           0 :           fail ("cipher-ocb-splitaad, encrypt data mismatch\n");
    3800             :         }
    3801             : 
    3802             :       /* Check that the tag matches TAGLEN bytes from the end of the
    3803             :          expected ciphertext.  */
    3804          16 :       err = gcry_cipher_gettag (hde, tag, 16);
    3805          16 :       if (err)
    3806             :         {
    3807           0 :           fail ("cipher-ocb-splitaad, gcry_cipher_gettag failed: %s\n",
    3808             :                 gpg_strerror (err));
    3809             :         }
    3810          16 :       if (memcmp (ciph + ciphlen - 16, tag, 16))
    3811             :         {
    3812           0 :           mismatch (ciph + ciphlen - 16, 16, tag, 16);
    3813           0 :           fail ("cipher-ocb-splitaad, encrypt tag mismatch\n");
    3814             :         }
    3815             : 
    3816             : 
    3817          16 :       gcry_cipher_close (hde);
    3818          16 :       xfree (aad[0]);
    3819          16 :       xfree (aad[1]);
    3820          16 :       xfree (aad[2]);
    3821          16 :       xfree (aad[3]);
    3822             :     }
    3823             : 
    3824           1 :   xfree (nonce);
    3825           1 :   xfree (ciph);
    3826           1 :   xfree (plain);
    3827           1 :   xfree (key);
    3828             : }
    3829             : 
    3830             : 
    3831             : static void
    3832           1 : check_ocb_cipher (void)
    3833             : {
    3834             :   /* Check OCB cipher with separate destination and source buffers for
    3835             :    * encryption/decryption. */
    3836           1 :   do_check_ocb_cipher(0);
    3837             : 
    3838             :   /* Check OCB cipher with inplace encrypt/decrypt. */
    3839           1 :   do_check_ocb_cipher(1);
    3840             : 
    3841             :   /* Check large buffer encryption/decryption. */
    3842           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_AES, 16,
    3843             :                             "\xf5\xf3\x12\x7d\x58\x2d\x96\xe8"
    3844             :                             "\x33\xfd\x7a\x4f\x42\x60\x5d\x20");
    3845           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_AES256, 32,
    3846             :                             "\xfa\x26\xa5\xbf\xf6\x7d\x3a\x8d"
    3847             :                             "\xfe\x96\x67\xc9\xc8\x41\x03\x51");
    3848           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_CAMELLIA128, 16,
    3849             :                             "\x28\x23\x38\x45\x2b\xfd\x42\x45"
    3850             :                             "\x43\x64\x7e\x67\x7f\xf4\x8b\xcd");
    3851           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_CAMELLIA192, 24,
    3852             :                             "\xee\xca\xe5\x39\x27\x2d\x33\xe7"
    3853             :                             "\x79\x74\xb0\x1d\x37\x12\xd5\x6c");
    3854           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_CAMELLIA256, 32,
    3855             :                             "\x39\x39\xd0\x2d\x05\x68\x74\xee"
    3856             :                             "\x18\x6b\xea\x3d\x0b\xd3\x58\xae");
    3857           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_TWOFISH, 16,
    3858             :                             "\x63\xe3\x0e\xb9\x11\x6f\x14\xba"
    3859             :                             "\x79\xe4\xa7\x9e\xad\x3c\x02\x0c");
    3860           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_TWOFISH, 32,
    3861             :                             "\xf6\xd4\xfe\x4e\x50\x85\x13\x59"
    3862             :                             "\x69\x0e\x4c\x67\x3e\xdd\x47\x90");
    3863           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_SERPENT128, 16,
    3864             :                             "\x3c\xfb\x66\x14\x3c\xc8\x6c\x67"
    3865             :                             "\x26\xb8\x23\xeb\xaf\x43\x98\x69");
    3866           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_SERPENT192, 24,
    3867             :                             "\x5e\x62\x27\xc5\x32\xc3\x1d\xe6"
    3868             :                             "\x2e\x65\xe7\xd6\xfb\x05\xd7\xb2");
    3869           1 :   check_ocb_cipher_largebuf(GCRY_CIPHER_SERPENT256, 32,
    3870             :                             "\xe7\x8b\xe6\xd4\x2f\x7a\x36\x4c"
    3871             :                             "\xba\xee\x20\xe2\x68\xf4\xcb\xcc");
    3872             : 
    3873             :   /* Check that the AAD data is correctly buffered.  */
    3874           1 :   check_ocb_cipher_splitaad ();
    3875           1 : }
    3876             : 
    3877             : static void
    3878           1 : check_gost28147_cipher (void)
    3879             : {
    3880             : #if USE_GOST28147
    3881             :   static const struct {
    3882             :     char key[MAX_DATA_LEN];
    3883             :     const char *oid;
    3884             :     unsigned char plaintext[MAX_DATA_LEN];
    3885             :     int inlen;
    3886             :     char out[MAX_DATA_LEN];
    3887             :   } tv[] =
    3888             :   {
    3889             :     {
    3890             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3891             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3892             :       "1.2.643.7.1.2.5.1.1",
    3893             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3894             :       8,
    3895             :       "\xce\x5a\x5e\xd7\xe0\x57\x7a\x5f",
    3896             :     }, {
    3897             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3898             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3899             :       "1.2.643.2.2.31.0",
    3900             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3901             :       8,
    3902             :       "\x98\x56\xcf\x8b\xfc\xc2\x82\xf4",
    3903             :     }, {
    3904             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3905             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3906             :       "1.2.643.2.2.31.1",
    3907             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3908             :       8,
    3909             :       "\x66\x81\x84\xae\xdc\x48\xc9\x17",
    3910             :     }, {
    3911             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3912             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3913             :       "1.2.643.2.2.31.2",
    3914             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3915             :       8,
    3916             :       "\xdb\xee\x81\x14\x7b\x74\xb0\xf2",
    3917             :     }, {
    3918             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3919             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3920             :       "1.2.643.2.2.31.3",
    3921             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3922             :       8,
    3923             :       "\x31\xa3\x85\x9d\x0a\xee\xb8\x0e",
    3924             :     }, {
    3925             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3926             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3927             :       "1.2.643.2.2.31.4",
    3928             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3929             :       8,
    3930             :       "\xb1\x32\x3e\x0b\x21\x73\xcb\xd1",
    3931             :     }, {
    3932             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3933             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3934             :       "1.2.643.2.2.30.0",
    3935             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3936             :       8,
    3937             :       "\xce\xd5\x2a\x7f\xf7\xf2\x60\xd5",
    3938             :     }, {
    3939             :       "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x80"
    3940             :       "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xd0",
    3941             :       "1.2.643.2.2.30.1",
    3942             :       "\x01\x02\x03\x04\x05\x06\x07\x08",
    3943             :       8,
    3944             :       "\xe4\x21\x75\xe1\x69\x22\xd0\xa8",
    3945             :     }
    3946             :   };
    3947             : 
    3948             :   gcry_cipher_hd_t hde, hdd;
    3949             :   unsigned char out[MAX_DATA_LEN];
    3950             :   int i, keylen;
    3951           1 :   gcry_error_t err = 0;
    3952             : 
    3953           1 :   if (verbose)
    3954           0 :     fprintf (stderr, "  Starting GOST28147 cipher checks.\n");
    3955           1 :   keylen = gcry_cipher_get_algo_keylen(GCRY_CIPHER_GOST28147);
    3956           1 :   if (!keylen)
    3957             :     {
    3958           0 :       fail ("gost28147, gcry_cipher_get_algo_keylen failed\n");
    3959           0 :       return;
    3960             :     }
    3961             : 
    3962           9 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    3963             :     {
    3964           8 :       err = gcry_cipher_open (&hde, GCRY_CIPHER_GOST28147,
    3965             :                               GCRY_CIPHER_MODE_ECB, 0);
    3966           8 :       if (!err)
    3967           8 :         err = gcry_cipher_open (&hdd, GCRY_CIPHER_GOST28147,
    3968             :                                 GCRY_CIPHER_MODE_ECB, 0);
    3969           8 :       if (err)
    3970             :         {
    3971           0 :           fail ("gost28147, gcry_cipher_open failed: %s\n", gpg_strerror (err));
    3972           0 :           return;
    3973             :         }
    3974             : 
    3975           8 :       err = gcry_cipher_setkey (hde, tv[i].key, keylen);
    3976           8 :       if (!err)
    3977           8 :         err = gcry_cipher_setkey (hdd, tv[i].key, keylen);
    3978           8 :       if (err)
    3979             :         {
    3980           0 :           fail ("gost28147, gcry_cipher_setkey failed: %s\n",
    3981             :                 gpg_strerror (err));
    3982           0 :           gcry_cipher_close (hde);
    3983           0 :           gcry_cipher_close (hdd);
    3984           0 :           return;
    3985             :         }
    3986             : 
    3987           8 :       err = gcry_cipher_set_sbox (hde, tv[i].oid);
    3988           8 :       if (!err)
    3989           8 :         err = gcry_cipher_set_sbox (hdd, tv[i].oid);
    3990           8 :       if (err)
    3991             :         {
    3992           0 :           fail ("gost28147, gcry_cipher_set_sbox failed: %s\n",
    3993             :                 gpg_strerror (err));
    3994           0 :           gcry_cipher_close (hde);
    3995           0 :           gcry_cipher_close (hdd);
    3996           0 :           return;
    3997             :         }
    3998             : 
    3999          24 :         err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
    4000           8 :                                    tv[i].plaintext,
    4001           8 :                                    tv[i].inlen == -1 ?
    4002           0 :                                    strlen ((char*)tv[i].plaintext) :
    4003           8 :                                    tv[i].inlen);
    4004           8 :         if (err)
    4005             :           {
    4006           0 :             fail ("gost28147, gcry_cipher_encrypt (%d) failed: %s\n",
    4007             :                   i, gpg_strerror (err));
    4008           0 :             gcry_cipher_close (hde);
    4009           0 :             gcry_cipher_close (hdd);
    4010           0 :             return;
    4011             :           }
    4012             : 
    4013           8 :         if (memcmp (tv[i].out, out, tv[i].inlen))
    4014             :           {
    4015           0 :             fail ("gost28147, encrypt mismatch entry %d\n", i);
    4016           0 :             mismatch (tv[i].out, tv[i].inlen,
    4017           0 :                       out, tv[i].inlen);
    4018             :           }
    4019             : 
    4020           8 :         err = gcry_cipher_decrypt (hdd, out, tv[i].inlen, NULL, 0);
    4021           8 :         if (err)
    4022             :           {
    4023           0 :             fail ("gost28147, gcry_cipher_decrypt (%d) failed: %s\n",
    4024             :                   i, gpg_strerror (err));
    4025           0 :             gcry_cipher_close (hde);
    4026           0 :             gcry_cipher_close (hdd);
    4027           0 :             return;
    4028             :           }
    4029             : 
    4030           8 :         if (memcmp (tv[i].plaintext, out, tv[i].inlen))
    4031             :           {
    4032           0 :             fail ("gost28147, decrypt mismatch entry %d\n", i);
    4033           0 :             mismatch (tv[i].plaintext, tv[i].inlen,
    4034           0 :                       out, tv[i].inlen);
    4035             :           }
    4036             : 
    4037           8 :         gcry_cipher_close (hde);
    4038           8 :         gcry_cipher_close (hdd);
    4039             :     }
    4040             : 
    4041             : #endif
    4042             : }
    4043             : 
    4044             : 
    4045             : static void
    4046           1 : check_stream_cipher (void)
    4047             : {
    4048             :   static const struct tv
    4049             :   {
    4050             :     const char *name;
    4051             :     int algo;
    4052             :     int keylen;
    4053             :     int ivlen;
    4054             :     const char *key;
    4055             :     const char *iv;
    4056             :     struct data
    4057             :     {
    4058             :       int inlen;
    4059             :       const char *plaintext;
    4060             :       const char *out;
    4061             :     } data[MAX_DATA_LEN];
    4062             :   } tv[] = {
    4063             : #ifdef USE_SALSA20
    4064             :     {
    4065             :       "Salsa20 128 bit, test 1",
    4066             :       GCRY_CIPHER_SALSA20, 16, 8,
    4067             :       "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4068             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4069             :       {
    4070             :         { 8,
    4071             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4072             :           "\x4D\xFA\x5E\x48\x1D\xA2\x3E\xA0"
    4073             :         }
    4074             :       }
    4075             :     },
    4076             :     {
    4077             :       "Salsa20 128 bit, test 2",
    4078             :       GCRY_CIPHER_SALSA20, 16, 8,
    4079             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4080             :       "\x80\x00\x00\x00\x00\x00\x00\x00",
    4081             :       {
    4082             :         { 8,
    4083             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4084             :           "\xB6\x6C\x1E\x44\x46\xDD\x95\x57"
    4085             :         }
    4086             :       }
    4087             :     },
    4088             :     {
    4089             :       "Salsa20 128 bit, test 3",
    4090             :       GCRY_CIPHER_SALSA20, 16, 8,
    4091             :       "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD",
    4092             :       "\x0D\x74\xDB\x42\xA9\x10\x77\xDE",
    4093             :       {
    4094             :         { 8,
    4095             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4096             :           "\x05\xE1\xE7\xBE\xB6\x97\xD9\x99"
    4097             :         }
    4098             :       }
    4099             :     },
    4100             :     {
    4101             :       "Salsa20 256 bit, test 1",
    4102             :       GCRY_CIPHER_SALSA20, 32, 8,
    4103             :       "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4104             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4105             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4106             :       {
    4107             :         { 8,
    4108             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4109             :           "\xE3\xBE\x8F\xDD\x8B\xEC\xA2\xE3"
    4110             :         }
    4111             :       }
    4112             :     },
    4113             :     {
    4114             :       "Salsa20 256 bit, test 2",
    4115             :       GCRY_CIPHER_SALSA20, 32, 8,
    4116             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4117             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4118             :       "\x80\x00\x00\x00\x00\x00\x00\x00",
    4119             :       {
    4120             :         { 8,
    4121             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4122             :           "\x2A\xBA\x3D\xC4\x5B\x49\x47\x00"
    4123             :         }
    4124             :       }
    4125             :     },
    4126             :     {
    4127             :       "Salsa20 256 bit, ecrypt verified, set 6, vector 0",
    4128             :       GCRY_CIPHER_SALSA20, 32, 8,
    4129             :       "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD"
    4130             :       "\x30\x83\xD6\x29\x7C\xCF\x22\x75\xC8\x1B\x6E\xC1\x14\x67\xBA\x0D",
    4131             :       "\x0D\x74\xDB\x42\xA9\x10\x77\xDE",
    4132             :       {
    4133             :         { 8,
    4134             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4135             :           "\xF5\xFA\xD5\x3F\x79\xF9\xDF\x58"
    4136             :         },
    4137             :         { 64,
    4138             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4139             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4140             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4141             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4142             :           "\xF5\xFA\xD5\x3F\x79\xF9\xDF\x58\xC4\xAE\xA0\xD0\xED\x9A\x96\x01"
    4143             :           "\xF2\x78\x11\x2C\xA7\x18\x0D\x56\x5B\x42\x0A\x48\x01\x96\x70\xEA"
    4144             :           "\xF2\x4C\xE4\x93\xA8\x62\x63\xF6\x77\xB4\x6A\xCE\x19\x24\x77\x3D"
    4145             :           "\x2B\xB2\x55\x71\xE1\xAA\x85\x93\x75\x8F\xC3\x82\xB1\x28\x0B\x71"
    4146             :         }
    4147             :       }
    4148             :     },
    4149             :     {
    4150             :       "Salsa20/12 128 bit, test 1",
    4151             :       GCRY_CIPHER_SALSA20R12, 16, 8,
    4152             :       "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4153             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4154             :       {
    4155             :         { 8,
    4156             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4157             :           "\xFC\x20\x7D\xBF\xC7\x6C\x5E\x17"
    4158             :         }
    4159             :       }
    4160             :     },
    4161             :     {
    4162             :       "Salsa20/12 128 bit, test 2",
    4163             :       GCRY_CIPHER_SALSA20R12, 16, 8,
    4164             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4165             :       "\x80\x00\x00\x00\x00\x00\x00\x00",
    4166             :       {
    4167             :         { 8,
    4168             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4169             :           "\x08\x28\x39\x9A\x6F\xEF\x20\xDA"
    4170             :         }
    4171             :       }
    4172             :     },
    4173             :     {
    4174             :       "Salsa20/12 128 bit, test 3",
    4175             :       GCRY_CIPHER_SALSA20R12, 16, 8,
    4176             :       "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD",
    4177             :       "\x0D\x74\xDB\x42\xA9\x10\x77\xDE",
    4178             :       {
    4179             :         { 8,
    4180             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4181             :           "\xAD\x9E\x60\xE6\xD2\xA2\x64\xB8"
    4182             :         }
    4183             :       }
    4184             :     },
    4185             :     {
    4186             :       "Salsa20/12 256 bit, test 1",
    4187             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4188             :       "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4189             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4190             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4191             :       {
    4192             :         { 8,
    4193             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4194             :           "\xAF\xE4\x11\xED\x1C\x4E\x07\xE4"
    4195             :         }
    4196             :       }
    4197             :     },
    4198             :     {
    4199             :       "Salsa20/12 256 bit, test 2",
    4200             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4201             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4202             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4203             :       "\x80\x00\x00\x00\x00\x00\x00\x00",
    4204             :       {
    4205             :         { 8,
    4206             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4207             :           "\x17\x2C\x51\x92\xCB\x6E\x64\x5B"
    4208             :         }
    4209             :       }
    4210             :     },
    4211             :     {
    4212             :       "Salsa20/12 256 bit, ecrypt verified, set 6, vector 0",
    4213             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4214             :       "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD"
    4215             :       "\x30\x83\xD6\x29\x7C\xCF\x22\x75\xC8\x1B\x6E\xC1\x14\x67\xBA\x0D",
    4216             :       "\x0D\x74\xDB\x42\xA9\x10\x77\xDE",
    4217             :       {
    4218             :         { 8,
    4219             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4220             :           "\x52\xE2\x0C\xF8\x77\x5A\xE8\x82"
    4221             :         },
    4222             :         { 64,
    4223             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4224             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4225             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4226             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4227             :           "\x52\xE2\x0C\xF8\x77\x5A\xE8\x82\xF2\x00\xC2\x99\x9F\xE4\xBA\x31"
    4228             :           "\xA7\xA1\x8F\x1D\x5C\x97\x16\x19\x1D\x12\x31\x75\xE1\x47\xBD\x4E"
    4229             :           "\x8C\xA6\xED\x16\x6C\xE0\xFC\x8E\x65\xA5\xCA\x60\x84\x20\xFC\x65"
    4230             :           "\x44\xC9\x70\x0A\x0F\x21\x38\xE8\xC1\xA2\x86\xFB\x8C\x1F\xBF\xA0"
    4231             :         }
    4232             :       }
    4233             :     },
    4234             : #endif /*USE_SALSA20*/
    4235             : #ifdef USE_CHACHA20
    4236             :     /* From draft-strombergson-chacha-test-vectors-01 */
    4237             :     {
    4238             :       "ChaCha20 128 bit, TC1",
    4239             :       GCRY_CIPHER_CHACHA20, 16, 8,
    4240             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4241             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4242             :       {
    4243             :         { 8,
    4244             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4245             :           "\x89\x67\x09\x52\x60\x83\x64\xfd"
    4246             :         },
    4247             :         { 112,
    4248             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4249             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4250             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4251             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4252             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4253             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4254             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4255             :           "\x89\x67\x09\x52\x60\x83\x64\xfd\x00\xb2\xf9\x09\x36\xf0\x31\xc8"
    4256             :           "\xe7\x56\xe1\x5d\xba\x04\xb8\x49\x3d\x00\x42\x92\x59\xb2\x0f\x46"
    4257             :           "\xcc\x04\xf1\x11\x24\x6b\x6c\x2c\xe0\x66\xbe\x3b\xfb\x32\xd9\xaa"
    4258             :           "\x0f\xdd\xfb\xc1\x21\x23\xd4\xb9\xe4\x4f\x34\xdc\xa0\x5a\x10\x3f"
    4259             :           "\x6c\xd1\x35\xc2\x87\x8c\x83\x2b\x58\x96\xb1\x34\xf6\x14\x2a\x9d"
    4260             :           "\x4d\x8d\x0d\x8f\x10\x26\xd2\x0a\x0a\x81\x51\x2c\xbc\xe6\xe9\x75"
    4261             :           "\x8a\x71\x43\xd0\x21\x97\x80\x22\xa3\x84\x14\x1a\x80\xce\xa3\x06"
    4262             :         },
    4263             :         { 128,
    4264             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4265             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4266             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4267             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4268             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4269             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4270             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4271             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4272             :           "\x89\x67\x09\x52\x60\x83\x64\xfd\x00\xb2\xf9\x09\x36\xf0\x31\xc8"
    4273             :           "\xe7\x56\xe1\x5d\xba\x04\xb8\x49\x3d\x00\x42\x92\x59\xb2\x0f\x46"
    4274             :           "\xcc\x04\xf1\x11\x24\x6b\x6c\x2c\xe0\x66\xbe\x3b\xfb\x32\xd9\xaa"
    4275             :           "\x0f\xdd\xfb\xc1\x21\x23\xd4\xb9\xe4\x4f\x34\xdc\xa0\x5a\x10\x3f"
    4276             :           "\x6c\xd1\x35\xc2\x87\x8c\x83\x2b\x58\x96\xb1\x34\xf6\x14\x2a\x9d"
    4277             :           "\x4d\x8d\x0d\x8f\x10\x26\xd2\x0a\x0a\x81\x51\x2c\xbc\xe6\xe9\x75"
    4278             :           "\x8a\x71\x43\xd0\x21\x97\x80\x22\xa3\x84\x14\x1a\x80\xce\xa3\x06"
    4279             :           "\x2f\x41\xf6\x7a\x75\x2e\x66\xad\x34\x11\x98\x4c\x78\x7e\x30\xad"
    4280             :         }
    4281             :       }
    4282             :     },
    4283             :     {
    4284             :       "ChaCha20 256 bit, TC1",
    4285             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4286             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4287             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4288             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4289             :       {
    4290             :         { 8,
    4291             :           "\x00\x00\x00\x00\x00\x00\x00\x00",
    4292             :           "\x76\xb8\xe0\xad\xa0\xf1\x3d\x90"
    4293             :         },
    4294             :         { 112,
    4295             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4296             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4297             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4298             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4299             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4300             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4301             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4302             :           "\x76\xb8\xe0\xad\xa0\xf1\x3d\x90\x40\x5d\x6a\xe5\x53\x86\xbd\x28"
    4303             :           "\xbd\xd2\x19\xb8\xa0\x8d\xed\x1a\xa8\x36\xef\xcc\x8b\x77\x0d\xc7"
    4304             :           "\xda\x41\x59\x7c\x51\x57\x48\x8d\x77\x24\xe0\x3f\xb8\xd8\x4a\x37"
    4305             :           "\x6a\x43\xb8\xf4\x15\x18\xa1\x1c\xc3\x87\xb6\x69\xb2\xee\x65\x86"
    4306             :           "\x9f\x07\xe7\xbe\x55\x51\x38\x7a\x98\xba\x97\x7c\x73\x2d\x08\x0d"
    4307             :           "\xcb\x0f\x29\xa0\x48\xe3\x65\x69\x12\xc6\x53\x3e\x32\xee\x7a\xed"
    4308             :           "\x29\xb7\x21\x76\x9c\xe6\x4e\x43\xd5\x71\x33\xb0\x74\xd8\x39\xd5"
    4309             :         },
    4310             :         { 128,
    4311             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4312             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4313             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4314             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4315             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4316             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4317             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4318             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4319             :           "\x76\xb8\xe0\xad\xa0\xf1\x3d\x90\x40\x5d\x6a\xe5\x53\x86\xbd\x28"
    4320             :           "\xbd\xd2\x19\xb8\xa0\x8d\xed\x1a\xa8\x36\xef\xcc\x8b\x77\x0d\xc7"
    4321             :           "\xda\x41\x59\x7c\x51\x57\x48\x8d\x77\x24\xe0\x3f\xb8\xd8\x4a\x37"
    4322             :           "\x6a\x43\xb8\xf4\x15\x18\xa1\x1c\xc3\x87\xb6\x69\xb2\xee\x65\x86"
    4323             :           "\x9f\x07\xe7\xbe\x55\x51\x38\x7a\x98\xba\x97\x7c\x73\x2d\x08\x0d"
    4324             :           "\xcb\x0f\x29\xa0\x48\xe3\x65\x69\x12\xc6\x53\x3e\x32\xee\x7a\xed"
    4325             :           "\x29\xb7\x21\x76\x9c\xe6\x4e\x43\xd5\x71\x33\xb0\x74\xd8\x39\xd5"
    4326             :           "\x31\xed\x1f\x28\x51\x0a\xfb\x45\xac\xe1\x0a\x1f\x4b\x79\x4d\x6f"
    4327             :         }
    4328             :       }
    4329             :     },
    4330             :     {
    4331             :       "ChaCha20 256 bit, TC2",
    4332             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4333             :       "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4334             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4335             :       "\x00\x00\x00\x00\x00\x00\x00\x00",
    4336             :       {
    4337             :         { 128,
    4338             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4339             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4340             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4341             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4342             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4343             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4344             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4345             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4346             :           "\xc5\xd3\x0a\x7c\xe1\xec\x11\x93\x78\xc8\x4f\x48\x7d\x77\x5a\x85"
    4347             :           "\x42\xf1\x3e\xce\x23\x8a\x94\x55\xe8\x22\x9e\x88\x8d\xe8\x5b\xbd"
    4348             :           "\x29\xeb\x63\xd0\xa1\x7a\x5b\x99\x9b\x52\xda\x22\xbe\x40\x23\xeb"
    4349             :           "\x07\x62\x0a\x54\xf6\xfa\x6a\xd8\x73\x7b\x71\xeb\x04\x64\xda\xc0"
    4350             :           "\x10\xf6\x56\xe6\xd1\xfd\x55\x05\x3e\x50\xc4\x87\x5c\x99\x30\xa3"
    4351             :           "\x3f\x6d\x02\x63\xbd\x14\xdf\xd6\xab\x8c\x70\x52\x1c\x19\x33\x8b"
    4352             :           "\x23\x08\xb9\x5c\xf8\xd0\xbb\x7d\x20\x2d\x21\x02\x78\x0e\xa3\x52"
    4353             :           "\x8f\x1c\xb4\x85\x60\xf7\x6b\x20\xf3\x82\xb9\x42\x50\x0f\xce\xac"
    4354             :         }
    4355             :       }
    4356             :     },
    4357             :     {
    4358             :       "ChaCha20 256 bit, TC3",
    4359             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4360             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4361             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4362             :       "\x01\x00\x00\x00\x00\x00\x00\x00",
    4363             :       {
    4364             :         { 128,
    4365             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4366             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4367             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4368             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4369             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4370             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4371             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4372             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4373             :           "\xef\x3f\xdf\xd6\xc6\x15\x78\xfb\xf5\xcf\x35\xbd\x3d\xd3\x3b\x80"
    4374             :           "\x09\x63\x16\x34\xd2\x1e\x42\xac\x33\x96\x0b\xd1\x38\xe5\x0d\x32"
    4375             :           "\x11\x1e\x4c\xaf\x23\x7e\xe5\x3c\xa8\xad\x64\x26\x19\x4a\x88\x54"
    4376             :           "\x5d\xdc\x49\x7a\x0b\x46\x6e\x7d\x6b\xbd\xb0\x04\x1b\x2f\x58\x6b"
    4377             :           "\x53\x05\xe5\xe4\x4a\xff\x19\xb2\x35\x93\x61\x44\x67\x5e\xfb\xe4"
    4378             :           "\x40\x9e\xb7\xe8\xe5\xf1\x43\x0f\x5f\x58\x36\xae\xb4\x9b\xb5\x32"
    4379             :           "\x8b\x01\x7c\x4b\x9d\xc1\x1f\x8a\x03\x86\x3f\xa8\x03\xdc\x71\xd5"
    4380             :           "\x72\x6b\x2b\x6b\x31\xaa\x32\x70\x8a\xfe\x5a\xf1\xd6\xb6\x90\x58"
    4381             :         }
    4382             :       }
    4383             :     },
    4384             :     {
    4385             :       "ChaCha20 256 bit, TC4",
    4386             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4387             :       "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
    4388             :       "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
    4389             :       "\xff\xff\xff\xff\xff\xff\xff\xff",
    4390             :       {
    4391             :         { 128,
    4392             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4393             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4394             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4395             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4396             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4397             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4398             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4399             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4400             :           "\xd9\xbf\x3f\x6b\xce\x6e\xd0\xb5\x42\x54\x55\x77\x67\xfb\x57\x44"
    4401             :           "\x3d\xd4\x77\x89\x11\xb6\x06\x05\x5c\x39\xcc\x25\xe6\x74\xb8\x36"
    4402             :           "\x3f\xea\xbc\x57\xfd\xe5\x4f\x79\x0c\x52\xc8\xae\x43\x24\x0b\x79"
    4403             :           "\xd4\x90\x42\xb7\x77\xbf\xd6\xcb\x80\xe9\x31\x27\x0b\x7f\x50\xeb"
    4404             :           "\x5b\xac\x2a\xcd\x86\xa8\x36\xc5\xdc\x98\xc1\x16\xc1\x21\x7e\xc3"
    4405             :           "\x1d\x3a\x63\xa9\x45\x13\x19\xf0\x97\xf3\xb4\xd6\xda\xb0\x77\x87"
    4406             :           "\x19\x47\x7d\x24\xd2\x4b\x40\x3a\x12\x24\x1d\x7c\xca\x06\x4f\x79"
    4407             :           "\x0f\x1d\x51\xcc\xaf\xf6\xb1\x66\x7d\x4b\xbc\xa1\x95\x8c\x43\x06"
    4408             :         }
    4409             :       }
    4410             :     },
    4411             :     {
    4412             :       "ChaCha20 256 bit, TC5",
    4413             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4414             :       "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"
    4415             :       "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55",
    4416             :       "\x55\x55\x55\x55\x55\x55\x55\x55",
    4417             :       {
    4418             :         { 128,
    4419             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4420             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4421             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4422             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4423             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4424             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4425             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4426             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4427             :           "\xbe\xa9\x41\x1a\xa4\x53\xc5\x43\x4a\x5a\xe8\xc9\x28\x62\xf5\x64"
    4428             :           "\x39\x68\x55\xa9\xea\x6e\x22\xd6\xd3\xb5\x0a\xe1\xb3\x66\x33\x11"
    4429             :           "\xa4\xa3\x60\x6c\x67\x1d\x60\x5c\xe1\x6c\x3a\xec\xe8\xe6\x1e\xa1"
    4430             :           "\x45\xc5\x97\x75\x01\x7b\xee\x2f\xa6\xf8\x8a\xfc\x75\x80\x69\xf7"
    4431             :           "\xe0\xb8\xf6\x76\xe6\x44\x21\x6f\x4d\x2a\x34\x22\xd7\xfa\x36\xc6"
    4432             :           "\xc4\x93\x1a\xca\x95\x0e\x9d\xa4\x27\x88\xe6\xd0\xb6\xd1\xcd\x83"
    4433             :           "\x8e\xf6\x52\xe9\x7b\x14\x5b\x14\x87\x1e\xae\x6c\x68\x04\xc7\x00"
    4434             :           "\x4d\xb5\xac\x2f\xce\x4c\x68\xc7\x26\xd0\x04\xb1\x0f\xca\xba\x86"
    4435             :         }
    4436             :       }
    4437             :     },
    4438             :     {
    4439             :       "ChaCha20 256 bit, TC6",
    4440             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4441             :       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    4442             :       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
    4443             :       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
    4444             :       {
    4445             :         { 128,
    4446             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4447             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4448             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4449             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4450             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4451             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4452             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4453             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4454             :           "\x9a\xa2\xa9\xf6\x56\xef\xde\x5a\xa7\x59\x1c\x5f\xed\x4b\x35\xae"
    4455             :           "\xa2\x89\x5d\xec\x7c\xb4\x54\x3b\x9e\x9f\x21\xf5\xe7\xbc\xbc\xf3"
    4456             :           "\xc4\x3c\x74\x8a\x97\x08\x88\xf8\x24\x83\x93\xa0\x9d\x43\xe0\xb7"
    4457             :           "\xe1\x64\xbc\x4d\x0b\x0f\xb2\x40\xa2\xd7\x21\x15\xc4\x80\x89\x06"
    4458             :           "\x72\x18\x44\x89\x44\x05\x45\xd0\x21\xd9\x7e\xf6\xb6\x93\xdf\xe5"
    4459             :           "\xb2\xc1\x32\xd4\x7e\x6f\x04\x1c\x90\x63\x65\x1f\x96\xb6\x23\xe6"
    4460             :           "\x2a\x11\x99\x9a\x23\xb6\xf7\xc4\x61\xb2\x15\x30\x26\xad\x5e\x86"
    4461             :           "\x6a\x2e\x59\x7e\xd0\x7b\x84\x01\xde\xc6\x3a\x09\x34\xc6\xb2\xa9"
    4462             :         }
    4463             :       }
    4464             :     },
    4465             :     {
    4466             :       "ChaCha20 256 bit, TC7",
    4467             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4468             :       "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
    4469             :       "\xff\xee\xdd\xcc\xbb\xaa\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00",
    4470             :       "\x0f\x1e\x2d\x3c\x4b\x5a\x69\x78",
    4471             :       {
    4472             :         { 128,
    4473             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4474             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4475             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4476             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4477             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4478             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4479             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4480             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4481             :           "\x9f\xad\xf4\x09\xc0\x08\x11\xd0\x04\x31\xd6\x7e\xfb\xd8\x8f\xba"
    4482             :           "\x59\x21\x8d\x5d\x67\x08\xb1\xd6\x85\x86\x3f\xab\xbb\x0e\x96\x1e"
    4483             :           "\xea\x48\x0f\xd6\xfb\x53\x2b\xfd\x49\x4b\x21\x51\x01\x50\x57\x42"
    4484             :           "\x3a\xb6\x0a\x63\xfe\x4f\x55\xf7\xa2\x12\xe2\x16\x7c\xca\xb9\x31"
    4485             :           "\xfb\xfd\x29\xcf\x7b\xc1\xd2\x79\xed\xdf\x25\xdd\x31\x6b\xb8\x84"
    4486             :           "\x3d\x6e\xde\xe0\xbd\x1e\xf1\x21\xd1\x2f\xa1\x7c\xbc\x2c\x57\x4c"
    4487             :           "\xcc\xab\x5e\x27\x51\x67\xb0\x8b\xd6\x86\xf8\xa0\x9d\xf8\x7e\xc3"
    4488             :           "\xff\xb3\x53\x61\xb9\x4e\xbf\xa1\x3f\xec\x0e\x48\x89\xd1\x8d\xa5"
    4489             :         }
    4490             :       }
    4491             :     },
    4492             :     {
    4493             :       "ChaCha20 256 bit, TC8",
    4494             :       GCRY_CIPHER_CHACHA20, 32, 8,
    4495             :       "\xc4\x6e\xc1\xb1\x8c\xe8\xa8\x78\x72\x5a\x37\xe7\x80\xdf\xb7\x35"
    4496             :       "\x1f\x68\xed\x2e\x19\x4c\x79\xfb\xc6\xae\xbe\xe1\xa6\x67\x97\x5d",
    4497             :       "\x1a\xda\x31\xd5\xcf\x68\x82\x21",
    4498             :       {
    4499             :         { 128,
    4500             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4501             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4502             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4503             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4504             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4505             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4506             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4507             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4508             :           "\xf6\x3a\x89\xb7\x5c\x22\x71\xf9\x36\x88\x16\x54\x2b\xa5\x2f\x06"
    4509             :           "\xed\x49\x24\x17\x92\x30\x2b\x00\xb5\xe8\xf8\x0a\xe9\xa4\x73\xaf"
    4510             :           "\xc2\x5b\x21\x8f\x51\x9a\xf0\xfd\xd4\x06\x36\x2e\x8d\x69\xde\x7f"
    4511             :           "\x54\xc6\x04\xa6\xe0\x0f\x35\x3f\x11\x0f\x77\x1b\xdc\xa8\xab\x92"
    4512             :           "\xe5\xfb\xc3\x4e\x60\xa1\xd9\xa9\xdb\x17\x34\x5b\x0a\x40\x27\x36"
    4513             :           "\x85\x3b\xf9\x10\xb0\x60\xbd\xf1\xf8\x97\xb6\x29\x0f\x01\xd1\x38"
    4514             :           "\xae\x2c\x4c\x90\x22\x5b\xa9\xea\x14\xd5\x18\xf5\x59\x29\xde\xa0"
    4515             :           "\x98\xca\x7a\x6c\xcf\xe6\x12\x27\x05\x3c\x84\xe4\x9a\x4a\x33\x32"
    4516             :         },
    4517             :         { 127,
    4518             :           "\xf6\x3a\x89\xb7\x5c\x22\x71\xf9\x36\x88\x16\x54\x2b\xa5\x2f\x06"
    4519             :           "\xed\x49\x24\x17\x92\x30\x2b\x00\xb5\xe8\xf8\x0a\xe9\xa4\x73\xaf"
    4520             :           "\xc2\x5b\x21\x8f\x51\x9a\xf0\xfd\xd4\x06\x36\x2e\x8d\x69\xde\x7f"
    4521             :           "\x54\xc6\x04\xa6\xe0\x0f\x35\x3f\x11\x0f\x77\x1b\xdc\xa8\xab\x92"
    4522             :           "\xe5\xfb\xc3\x4e\x60\xa1\xd9\xa9\xdb\x17\x34\x5b\x0a\x40\x27\x36"
    4523             :           "\x85\x3b\xf9\x10\xb0\x60\xbd\xf1\xf8\x97\xb6\x29\x0f\x01\xd1\x38"
    4524             :           "\xae\x2c\x4c\x90\x22\x5b\xa9\xea\x14\xd5\x18\xf5\x59\x29\xde\xa0"
    4525             :           "\x98\xca\x7a\x6c\xcf\xe6\x12\x27\x05\x3c\x84\xe4\x9a\x4a\x33",
    4526             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4527             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4528             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4529             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4530             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4531             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4532             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4533             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4534             :         }
    4535             :       }
    4536             :     },
    4537             :     /* from draft-nir-cfrg-chacha20-poly1305-02 */
    4538             :     {
    4539             :       "ChaCha20 256 bit, IV96-bit",
    4540             :       GCRY_CIPHER_CHACHA20, 32, 12,
    4541             :       "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
    4542             :       "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
    4543             :       "\x07\x00\x00\x00\x40\x41\x42\x43\x44\x45\x46\x47",
    4544             :       {
    4545             :         { 64,
    4546             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4547             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4548             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    4549             :           "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    4550             :           "\x7b\xac\x2b\x25\x2d\xb4\x47\xaf\x09\xb6\x7a\x55\xa4\xe9\x55\x84"
    4551             :           "\x0a\xe1\xd6\x73\x10\x75\xd9\xeb\x2a\x93\x75\x78\x3e\xd5\x53\xff"
    4552             :           "\xa2\x7e\xcc\xde\xad\xdb\x4d\xb4\xd1\x17\x9c\xe4\xc9\x0b\x43\xd8"
    4553             :           "\xbc\xb7\x94\x8c\x4b\x4b\x7d\x8b\x7d\xf6\x27\x39\x32\xa4\x69\x16"
    4554             :         },
    4555             :       },
    4556             :     },
    4557             : #endif /*USE_CHACHA20*/
    4558             :   };
    4559             : 
    4560             :   gcry_cipher_hd_t hde, hdd;
    4561             :   unsigned char out[MAX_DATA_LEN];
    4562             :   int i, j;
    4563           1 :   gcry_error_t err = 0;
    4564             : 
    4565             : 
    4566           1 :   if (verbose)
    4567           0 :     fprintf (stderr, "  Starting stream cipher checks.\n");
    4568             : 
    4569          23 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    4570             :     {
    4571          22 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
    4572             :         {
    4573           0 :           if (verbose)
    4574           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    4575             :                      tv[i].algo);
    4576           0 :           continue;
    4577             :         }
    4578          22 :       if (verbose)
    4579           0 :         fprintf (stderr, "    checking stream mode for %s [%i] (%s)\n",
    4580             :                  gcry_cipher_algo_name (tv[i].algo), tv[i].algo, tv[i].name);
    4581             : 
    4582          22 :       if (gcry_cipher_get_algo_blklen(tv[i].algo) != 1)
    4583             :         {
    4584           0 :           fail ("stream, gcry_cipher_get_algo_blklen: bad block length\n");
    4585           0 :           continue;
    4586             :         }
    4587             : 
    4588          22 :       err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_STREAM, 0);
    4589          22 :       if (!err)
    4590          22 :         err = gcry_cipher_open (&hdd, tv[i].algo, GCRY_CIPHER_MODE_STREAM, 0);
    4591          22 :       if (err)
    4592             :         {
    4593           0 :           fail ("stream, gcry_cipher_open for stream mode failed: %s\n",
    4594             :                 gpg_strerror (err));
    4595           0 :           continue;
    4596             :         }
    4597             : 
    4598             :       /* Now loop over all the data samples.  */
    4599          51 :       for (j = 0; tv[i].data[j].inlen; j++)
    4600             :         {
    4601          29 :           err = gcry_cipher_setkey (hde, tv[i].key, tv[i].keylen);
    4602          29 :           if (!err)
    4603          29 :             err = gcry_cipher_setkey (hdd, tv[i].key, tv[i].keylen);
    4604          29 :           if (err)
    4605             :             {
    4606           0 :               fail ("stream, gcry_cipher_setkey failed: %s\n",
    4607             :                     gpg_strerror (err));
    4608           0 :               goto next;
    4609             :             }
    4610             : 
    4611          29 :           err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    4612          29 :           if (!err)
    4613          29 :             err = gcry_cipher_setiv (hdd, tv[i].iv, tv[i].ivlen);
    4614          29 :           if (err)
    4615             :             {
    4616           0 :               fail ("stream, gcry_cipher_setiv failed: %s\n",
    4617             :                     gpg_strerror (err));
    4618           0 :               goto next;
    4619             :             }
    4620             : 
    4621          58 :           err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
    4622          29 :                                      tv[i].data[j].plaintext,
    4623          29 :                                      tv[i].data[j].inlen);
    4624          29 :           if (err)
    4625             :             {
    4626           0 :               fail ("stream, gcry_cipher_encrypt (%d, %d) failed: %s\n",
    4627             :                     i, j, gpg_strerror (err));
    4628           0 :               goto next;
    4629             :             }
    4630             : 
    4631          29 :           if (memcmp (tv[i].data[j].out, out, tv[i].data[j].inlen))
    4632             :             {
    4633           0 :               fail ("stream, encrypt mismatch entry %d:%d\n", i, j);
    4634           0 :               mismatch (tv[i].data[j].out, tv[i].data[j].inlen,
    4635           0 :                         out, tv[i].data[j].inlen);
    4636             :             }
    4637             : 
    4638          29 :           err = gcry_cipher_decrypt (hdd, out, tv[i].data[j].inlen, NULL, 0);
    4639          29 :           if (err)
    4640             :             {
    4641           0 :               fail ("stream, gcry_cipher_decrypt (%d, %d) failed: %s\n",
    4642             :                     i, j, gpg_strerror (err));
    4643           0 :               goto next;
    4644             :             }
    4645             : 
    4646          29 :           if (memcmp (tv[i].data[j].plaintext, out, tv[i].data[j].inlen))
    4647           0 :             fail ("stream, decrypt mismatch entry %d:%d\n", i, j);
    4648             :         }
    4649             : 
    4650             : 
    4651             :       /* This time we encrypt and decrypt one byte at a time */
    4652          51 :       for (j = 0; tv[i].data[j].inlen; j++)
    4653             :         {
    4654             :           int byteNum;
    4655             : 
    4656          29 :           err = gcry_cipher_setkey (hde, tv[i].key, tv[i].keylen);
    4657          29 :           if (!err)
    4658          29 :             err = gcry_cipher_setkey (hdd, tv[i].key, tv[i].keylen);
    4659          29 :           if (err)
    4660             :             {
    4661           0 :               fail ("stream, gcry_cipher_setkey failed: %s\n",
    4662             :                     gpg_strerror (err));
    4663           0 :               goto next;
    4664             :             }
    4665             : 
    4666          29 :           err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    4667          29 :           if (!err)
    4668          29 :             err = gcry_cipher_setiv (hdd, tv[i].iv, tv[i].ivlen);
    4669          29 :           if (err)
    4670             :             {
    4671           0 :               fail ("stream, gcry_cipher_setiv failed: %s\n",
    4672             :                     gpg_strerror (err));
    4673           0 :               goto next;
    4674             :             }
    4675             : 
    4676        1836 :           for (byteNum = 0; byteNum < tv[i].data[j].inlen; ++byteNum)
    4677             :             {
    4678        1807 :               err = gcry_cipher_encrypt (hde, out+byteNum, 1,
    4679        1807 :                                          (tv[i].data[j].plaintext) + byteNum,
    4680             :                                          1);
    4681        1807 :               if (err)
    4682             :                 {
    4683           0 :                   fail ("stream, gcry_cipher_encrypt (%d, %d) failed: %s\n",
    4684             :                         i, j, gpg_strerror (err));
    4685           0 :                   goto next;
    4686             :                 }
    4687             :             }
    4688             : 
    4689          29 :           if (memcmp (tv[i].data[j].out, out, tv[i].data[j].inlen))
    4690           0 :             fail ("stream, encrypt mismatch entry %d:%d (byte-wise)\n", i, j);
    4691             : 
    4692        1836 :           for (byteNum = 0; byteNum < tv[i].data[j].inlen; ++byteNum)
    4693             :             {
    4694        1807 :               err = gcry_cipher_decrypt (hdd, out+byteNum, 1, NULL, 0);
    4695        1807 :               if (err)
    4696             :                 {
    4697           0 :                   fail ("stream, gcry_cipher_decrypt (%d, %d) failed: %s\n",
    4698             :                         i, j, gpg_strerror (err));
    4699           0 :                   goto next;
    4700             :                 }
    4701             :             }
    4702             : 
    4703          29 :           if (memcmp (tv[i].data[j].plaintext, out, tv[i].data[j].inlen))
    4704           0 :             fail ("stream, decrypt mismatch entry %d:%d (byte-wise)\n", i, j);
    4705             :         }
    4706             : 
    4707             :     next:
    4708          22 :       gcry_cipher_close (hde);
    4709          22 :       gcry_cipher_close (hdd);
    4710             :     }
    4711           1 :   if (verbose)
    4712           0 :     fprintf (stderr, "  Completed stream cipher checks.\n");
    4713           1 : }
    4714             : 
    4715             : 
    4716             : static void
    4717           1 : check_stream_cipher_large_block (void)
    4718             : {
    4719             :   static const struct tv
    4720             :   {
    4721             :     const char *name;
    4722             :     int algo;
    4723             :     int keylen;
    4724             :     int ivlen;
    4725             :     const char *key;
    4726             :     const char *iv;
    4727             :     struct data
    4728             :     {
    4729             :       int offset, length;
    4730             :       const char *result;
    4731             :     } data[MAX_DATA_LEN];
    4732             :   } tv[] = {
    4733             : #ifdef USE_SALSA20
    4734             :     {
    4735             :       "Salsa20 256 bit, ecrypt verified, set 6, vector 0",
    4736             :       GCRY_CIPHER_SALSA20, 32, 8,
    4737             :       "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD"
    4738             :       "\x30\x83\xD6\x29\x7C\xCF\x22\x75\xC8\x1B\x6E\xC1\x14\x67\xBA\x0D",
    4739             :       "\x0D\x74\xDB\x42\xA9\x10\x77\xDE",
    4740             :       {
    4741             :         { 0, 64,
    4742             :           "\xF5\xFA\xD5\x3F\x79\xF9\xDF\x58\xC4\xAE\xA0\xD0\xED\x9A\x96\x01"
    4743             :           "\xF2\x78\x11\x2C\xA7\x18\x0D\x56\x5B\x42\x0A\x48\x01\x96\x70\xEA"
    4744             :           "\xF2\x4C\xE4\x93\xA8\x62\x63\xF6\x77\xB4\x6A\xCE\x19\x24\x77\x3D"
    4745             :           "\x2B\xB2\x55\x71\xE1\xAA\x85\x93\x75\x8F\xC3\x82\xB1\x28\x0B\x71"
    4746             :         },
    4747             :         { 65472, 64,
    4748             :          "\xB7\x0C\x50\x13\x9C\x63\x33\x2E\xF6\xE7\x7A\xC5\x43\x38\xA4\x07"
    4749             :          "\x9B\x82\xBE\xC9\xF9\xA4\x03\xDF\xEA\x82\x1B\x83\xF7\x86\x07\x91"
    4750             :          "\x65\x0E\xF1\xB2\x48\x9D\x05\x90\xB1\xDE\x77\x2E\xED\xA4\xE3\xBC"
    4751             :          "\xD6\x0F\xA7\xCE\x9C\xD6\x23\xD9\xD2\xFD\x57\x58\xB8\x65\x3E\x70"
    4752             :         },
    4753             :         { 65536, 64,
    4754             :          "\x81\x58\x2C\x65\xD7\x56\x2B\x80\xAE\xC2\xF1\xA6\x73\xA9\xD0\x1C"
    4755             :          "\x9F\x89\x2A\x23\xD4\x91\x9F\x6A\xB4\x7B\x91\x54\xE0\x8E\x69\x9B"
    4756             :          "\x41\x17\xD7\xC6\x66\x47\x7B\x60\xF8\x39\x14\x81\x68\x2F\x5D\x95"
    4757             :          "\xD9\x66\x23\xDB\xC4\x89\xD8\x8D\xAA\x69\x56\xB9\xF0\x64\x6B\x6E"
    4758             :         },
    4759             :         { 131008, 64,
    4760             :          "\xA1\x3F\xFA\x12\x08\xF8\xBF\x50\x90\x08\x86\xFA\xAB\x40\xFD\x10"
    4761             :          "\xE8\xCA\xA3\x06\xE6\x3D\xF3\x95\x36\xA1\x56\x4F\xB7\x60\xB2\x42"
    4762             :          "\xA9\xD6\xA4\x62\x8C\xDC\x87\x87\x62\x83\x4E\x27\xA5\x41\xDA\x2A"
    4763             :          "\x5E\x3B\x34\x45\x98\x9C\x76\xF6\x11\xE0\xFE\xC6\xD9\x1A\xCA\xCC"
    4764             :         }
    4765             :       }
    4766             :     },
    4767             :     {
    4768             :       "Salsa20 256 bit, ecrypt verified, set 6, vector 1",
    4769             :       GCRY_CIPHER_SALSA20, 32, 8,
    4770             :       "\x05\x58\xAB\xFE\x51\xA4\xF7\x4A\x9D\xF0\x43\x96\xE9\x3C\x8F\xE2"
    4771             :       "\x35\x88\xDB\x2E\x81\xD4\x27\x7A\xCD\x20\x73\xC6\x19\x6C\xBF\x12",
    4772             :       "\x16\x7D\xE4\x4B\xB2\x19\x80\xE7",
    4773             :       {
    4774             :         { 0, 64,
    4775             :           "\x39\x44\xF6\xDC\x9F\x85\xB1\x28\x08\x38\x79\xFD\xF1\x90\xF7\xDE"
    4776             :           "\xE4\x05\x3A\x07\xBC\x09\x89\x6D\x51\xD0\x69\x0B\xD4\xDA\x4A\xC1"
    4777             :           "\x06\x2F\x1E\x47\xD3\xD0\x71\x6F\x80\xA9\xB4\xD8\x5E\x6D\x60\x85"
    4778             :           "\xEE\x06\x94\x76\x01\xC8\x5F\x1A\x27\xA2\xF7\x6E\x45\xA6\xAA\x87"
    4779             :         },
    4780             :         { 65472, 64,
    4781             :           "\x36\xE0\x3B\x4B\x54\xB0\xB2\xE0\x4D\x06\x9E\x69\x00\x82\xC8\xC5"
    4782             :           "\x92\xDF\x56\xE6\x33\xF5\xD8\xC7\x68\x2A\x02\xA6\x5E\xCD\x13\x71"
    4783             :           "\x8C\xA4\x35\x2A\xAC\xCB\x0D\xA2\x0E\xD6\xBB\xBA\x62\xE1\x77\xF2"
    4784             :           "\x10\xE3\x56\x0E\x63\xBB\x82\x2C\x41\x58\xCA\xA8\x06\xA8\x8C\x82"
    4785             :         },
    4786             :         { 65536, 64,
    4787             :           "\x1B\x77\x9E\x7A\x91\x7C\x8C\x26\x03\x9F\xFB\x23\xCF\x0E\xF8\xE0"
    4788             :           "\x8A\x1A\x13\xB4\x3A\xCD\xD9\x40\x2C\xF5\xDF\x38\x50\x10\x98\xDF"
    4789             :           "\xC9\x45\xA6\xCC\x69\xA6\xA1\x73\x67\xBC\x03\x43\x1A\x86\xB3\xED"
    4790             :           "\x04\xB0\x24\x5B\x56\x37\x9B\xF9\x97\xE2\x58\x00\xAD\x83\x7D\x7D"
    4791             :         },
    4792             :         { 131008, 64,
    4793             :           "\x7E\xC6\xDA\xE8\x1A\x10\x5E\x67\x17\x2A\x0B\x8C\x4B\xBE\x7D\x06"
    4794             :           "\xA7\xA8\x75\x9F\x91\x4F\xBE\xB1\xAF\x62\xC8\xA5\x52\xEF\x4A\x4F"
    4795             :           "\x56\x96\x7E\xA2\x9C\x74\x71\xF4\x6F\x3B\x07\xF7\xA3\x74\x6E\x95"
    4796             :           "\x3D\x31\x58\x21\xB8\x5B\x6E\x8C\xB4\x01\x22\xB9\x66\x35\x31\x3C"
    4797             :         }
    4798             :       }
    4799             :     },
    4800             :     {
    4801             :       "Salsa20 256 bit, ecrypt verified, set 6, vector 2",
    4802             :       GCRY_CIPHER_SALSA20, 32, 8,
    4803             :       "\x0A\x5D\xB0\x03\x56\xA9\xFC\x4F\xA2\xF5\x48\x9B\xEE\x41\x94\xE7"
    4804             :       "\x3A\x8D\xE0\x33\x86\xD9\x2C\x7F\xD2\x25\x78\xCB\x1E\x71\xC4\x17",
    4805             :       "\x1F\x86\xED\x54\xBB\x22\x89\xF0",
    4806             :       {
    4807             :         { 0, 64,
    4808             :           "\x3F\xE8\x5D\x5B\xB1\x96\x0A\x82\x48\x0B\x5E\x6F\x4E\x96\x5A\x44"
    4809             :           "\x60\xD7\xA5\x45\x01\x66\x4F\x7D\x60\xB5\x4B\x06\x10\x0A\x37\xFF"
    4810             :           "\xDC\xF6\xBD\xE5\xCE\x3F\x48\x86\xBA\x77\xDD\x5B\x44\xE9\x56\x44"
    4811             :           "\xE4\x0A\x8A\xC6\x58\x01\x15\x5D\xB9\x0F\x02\x52\x2B\x64\x40\x23"
    4812             :         },
    4813             :         { 65472, 64,
    4814             :           "\xC8\xD6\xE5\x4C\x29\xCA\x20\x40\x18\xA8\x30\xE2\x66\xCE\xEE\x0D"
    4815             :           "\x03\x7D\xC4\x7E\x92\x19\x47\x30\x2A\xCE\x40\xD1\xB9\x96\xA6\xD8"
    4816             :           "\x0B\x59\x86\x77\xF3\x35\x2F\x1D\xAA\x6D\x98\x88\xF8\x91\xAD\x95"
    4817             :           "\xA1\xC3\x2F\xFE\xB7\x1B\xB8\x61\xE8\xB0\x70\x58\x51\x51\x71\xC9"
    4818             :         },
    4819             :         { 65536, 64,
    4820             :           "\xB7\x9F\xD7\x76\x54\x2B\x46\x20\xEF\xCB\x88\x44\x95\x99\xF2\x34"
    4821             :           "\x03\xE7\x4A\x6E\x91\xCA\xCC\x50\xA0\x5A\x8F\x8F\x3C\x0D\xEA\x8B"
    4822             :           "\x00\xE1\xA5\xE6\x08\x1F\x55\x26\xAE\x97\x5B\x3B\xC0\x45\x0F\x1A"
    4823             :           "\x0C\x8B\x66\xF8\x08\xF1\x90\x4B\x97\x13\x61\x13\x7C\x93\x15\x6F"
    4824             :         },
    4825             :         { 131008, 64,
    4826             :           "\x79\x98\x20\x4F\xED\x70\xCE\x8E\x0D\x02\x7B\x20\x66\x35\xC0\x8C"
    4827             :           "\x8B\xC4\x43\x62\x26\x08\x97\x0E\x40\xE3\xAE\xDF\x3C\xE7\x90\xAE"
    4828             :           "\xED\xF8\x9F\x92\x26\x71\xB4\x53\x78\xE2\xCD\x03\xF6\xF6\x23\x56"
    4829             :           "\x52\x9C\x41\x58\xB7\xFF\x41\xEE\x85\x4B\x12\x35\x37\x39\x88\xC8"
    4830             :         }
    4831             :       }
    4832             :     },
    4833             :     {
    4834             :       "Salsa20 256 bit, ecrypt verified, set 6, vector 3",
    4835             :       GCRY_CIPHER_SALSA20, 32, 8,
    4836             :       "\x0F\x62\xB5\x08\x5B\xAE\x01\x54\xA7\xFA\x4D\xA0\xF3\x46\x99\xEC"
    4837             :       "\x3F\x92\xE5\x38\x8B\xDE\x31\x84\xD7\x2A\x7D\xD0\x23\x76\xC9\x1C",
    4838             :       "\x28\x8F\xF6\x5D\xC4\x2B\x92\xF9",
    4839             :       {
    4840             :         { 0, 64,
    4841             :           "\x5E\x5E\x71\xF9\x01\x99\x34\x03\x04\xAB\xB2\x2A\x37\xB6\x62\x5B"
    4842             :           "\xF8\x83\xFB\x89\xCE\x3B\x21\xF5\x4A\x10\xB8\x10\x66\xEF\x87\xDA"
    4843             :           "\x30\xB7\x76\x99\xAA\x73\x79\xDA\x59\x5C\x77\xDD\x59\x54\x2D\xA2"
    4844             :           "\x08\xE5\x95\x4F\x89\xE4\x0E\xB7\xAA\x80\xA8\x4A\x61\x76\x66\x3F"
    4845             :         },
    4846             :         { 65472, 64,
    4847             :           "\x2D\xA2\x17\x4B\xD1\x50\xA1\xDF\xEC\x17\x96\xE9\x21\xE9\xD6\xE2"
    4848             :           "\x4E\xCF\x02\x09\xBC\xBE\xA4\xF9\x83\x70\xFC\xE6\x29\x05\x6F\x64"
    4849             :           "\x91\x72\x83\x43\x6E\x2D\x3F\x45\x55\x62\x25\x30\x7D\x5C\xC5\xA5"
    4850             :           "\x65\x32\x5D\x89\x93\xB3\x7F\x16\x54\x19\x5C\x24\x0B\xF7\x5B\x16"
    4851             :         },
    4852             :         { 65536, 64,
    4853             :           "\xAB\xF3\x9A\x21\x0E\xEE\x89\x59\x8B\x71\x33\x37\x70\x56\xC2\xFE"
    4854             :           "\xF4\x2D\xA7\x31\x32\x75\x63\xFB\x67\xC7\xBE\xDB\x27\xF3\x8C\x7C"
    4855             :           "\x5A\x3F\xC2\x18\x3A\x4C\x6B\x27\x7F\x90\x11\x52\x47\x2C\x6B\x2A"
    4856             :           "\xBC\xF5\xE3\x4C\xBE\x31\x5E\x81\xFD\x3D\x18\x0B\x5D\x66\xCB\x6C"
    4857             :         },
    4858             :         { 131008, 64,
    4859             :           "\x1B\xA8\x9D\xBD\x3F\x98\x83\x97\x28\xF5\x67\x91\xD5\xB7\xCE\x23"
    4860             :           "\x50\x36\xDE\x84\x3C\xCC\xAB\x03\x90\xB8\xB5\x86\x2F\x1E\x45\x96"
    4861             :           "\xAE\x8A\x16\xFB\x23\xDA\x99\x7F\x37\x1F\x4E\x0A\xAC\xC2\x6D\xB8"
    4862             :           "\xEB\x31\x4E\xD4\x70\xB1\xAF\x6B\x9F\x8D\x69\xDD\x79\xA9\xD7\x50"
    4863             :         }
    4864             :       }
    4865             :     },
    4866             :     {
    4867             :       "Salsa20/12 256 bit, ecrypt verified, set 6, vector 0",
    4868             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4869             :       "\x00\x53\xA6\xF9\x4C\x9F\xF2\x45\x98\xEB\x3E\x91\xE4\x37\x8A\xDD"
    4870             :       "\x30\x83\xD6\x29\x7C\xCF\x22\x75\xC8\x1B\x6E\xC1\x14\x67\xBA\x0D",
    4871             :       "\x0D\x74\xDB\x42\xA9\x10\x77\xDE",
    4872             :       {
    4873             :         { 0, 64,
    4874             :           "\x52\xE2\x0C\xF8\x77\x5A\xE8\x82\xF2\x00\xC2\x99\x9F\xE4\xBA\x31"
    4875             :           "\xA7\xA1\x8F\x1D\x5C\x97\x16\x19\x1D\x12\x31\x75\xE1\x47\xBD\x4E"
    4876             :           "\x8C\xA6\xED\x16\x6C\xE0\xFC\x8E\x65\xA5\xCA\x60\x84\x20\xFC\x65"
    4877             :           "\x44\xC9\x70\x0A\x0F\x21\x38\xE8\xC1\xA2\x86\xFB\x8C\x1F\xBF\xA0"
    4878             :         },
    4879             :         { 65472, 64,
    4880             :           "\x8F\xBC\x9F\xE8\x69\x1B\xD4\xF0\x82\xB4\x7F\x54\x05\xED\xFB\xC1"
    4881             :           "\x6F\x4D\x5A\x12\xDD\xCB\x2D\x75\x4E\x8A\x99\x98\xD0\xB2\x19\x55"
    4882             :           "\x7D\xFE\x29\x84\xF4\xA1\xD2\xDD\xA7\x6B\x95\x96\x92\x8C\xCE\x05"
    4883             :           "\x56\xF5\x00\x66\xCD\x59\x9E\x44\xEF\x5C\x14\xB2\x26\x68\x3A\xEF"
    4884             :         },
    4885             :         { 65536, 64,
    4886             :           "\xBC\xBD\x01\xDD\x28\x96\x1C\xC7\xAD\x30\x47\x38\x6C\xBC\xC6\x7C"
    4887             :           "\x10\x8D\x6A\xF1\x11\x67\xE4\x0D\x7A\xE1\xB2\xFC\x45\x18\xA8\x67"
    4888             :           "\xEF\xE4\x02\x65\x1D\x1D\x88\x51\xC4\xFD\x23\x30\xC5\x97\xB3\x6A"
    4889             :           "\x46\xD5\x68\x9E\x00\xFC\x96\xFE\xCF\x9C\xE3\xE2\x21\x1D\x44\xBE"
    4890             :         },
    4891             :         { 131008, 64,
    4892             :           "\x91\x66\xF3\x1C\xD8\x5B\x5B\xB1\x8F\xC6\x14\xE5\x4E\x4A\xD6\x7F"
    4893             :           "\xB8\x65\x8E\x3B\xF9\xFB\x19\xB7\xA8\x2F\x0F\xE7\xDC\x90\x2D\xF5"
    4894             :           "\x63\xC6\xAC\x4F\x44\x67\x48\xC4\xBC\x3E\x14\x05\xE1\x24\x82\x0D"
    4895             :           "\xC4\x09\x41\x99\x8F\x44\xA8\x10\xE7\x22\x78\x7F\xCD\x47\x78\x4C"
    4896             :         }
    4897             :       }
    4898             :     },
    4899             :     {
    4900             :       "Salsa20/12 256 bit, ecrypt verified, set 6, vector 1",
    4901             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4902             :       "\x05\x58\xAB\xFE\x51\xA4\xF7\x4A\x9D\xF0\x43\x96\xE9\x3C\x8F\xE2"
    4903             :       "\x35\x88\xDB\x2E\x81\xD4\x27\x7A\xCD\x20\x73\xC6\x19\x6C\xBF\x12",
    4904             :       "\x16\x7D\xE4\x4B\xB2\x19\x80\xE7",
    4905             :       {
    4906             :         { 0, 64,
    4907             :           "\xC0\x75\x60\xB3\xE7\x76\xB4\x71\xC5\xE2\x93\x14\x26\xCA\xF1\xED"
    4908             :           "\x3A\xE4\xB8\x67\x08\x76\x82\xCA\x9D\xFD\xC2\xBA\xE8\x93\x50\xBD"
    4909             :           "\x84\x82\x1C\xAE\xFF\x85\xAA\xC4\x9D\x74\x35\xA7\xD9\x88\x93\x52"
    4910             :           "\xF5\x27\x9E\x36\x12\x3F\x41\x72\x8A\x14\xEF\x26\x9F\xCB\x94\x4B"
    4911             :         },
    4912             :         { 65472, 64,
    4913             :           "\xEE\xD1\xBB\x58\xF9\x0C\x89\xE0\x5C\xC6\x8B\x2D\xB6\x05\x58\x49"
    4914             :           "\xB3\xD2\xB1\x87\xB7\xF0\x2F\x9A\x24\xCE\x34\x2A\xF0\xFC\x47\xA3"
    4915             :           "\x74\xBD\x75\x90\xFB\xF4\xFD\x9E\xE5\x9B\x1A\x38\x1E\xBF\xD2\x29"
    4916             :           "\xAD\x2A\x29\x01\xB3\xFB\x61\x08\x12\x90\x0B\x92\x30\xE6\x22\xE9"
    4917             :         },
    4918             :         { 65536, 64,
    4919             :           "\x70\xF0\x49\x3A\x1B\x62\x53\xCC\x5E\xD3\x45\x0A\x31\xCF\x37\x7D"
    4920             :           "\x83\x4B\xAD\x20\x72\x30\x29\x27\xCC\xD8\x30\x10\x4B\xD3\x05\xFF"
    4921             :           "\x59\xD2\x94\x17\xB2\x32\x88\x4E\xC9\x59\x19\x4D\x60\x47\xC3\xDD"
    4922             :           "\x66\x56\xC4\x7E\x32\x00\x64\xEB\x01\x44\xF7\x34\x1B\xC3\xD6\x97"
    4923             :         },
    4924             :         { 131008, 64,
    4925             :           "\xD2\xCC\xF7\xC1\xAF\x2A\xB4\x66\xE6\x27\xDB\x44\x08\x40\x96\x9A"
    4926             :           "\xBD\xAB\x68\xD8\x86\xAE\x6A\x38\xA1\x3F\xEE\x17\x50\xCA\x97\xB5"
    4927             :           "\xD3\x31\x5B\x84\x08\x47\x28\x86\x2F\xBC\xC7\xD4\xA9\x7C\x75\xC8"
    4928             :           "\x65\x5F\xF9\xD6\xBB\xC2\x61\x88\x63\x6F\x3E\xDF\xE1\x5C\x7D\x30"
    4929             :         }
    4930             :       }
    4931             :     },
    4932             :     {
    4933             :       "Salsa20/12 256 bit, ecrypt verified, set 6, vector 2",
    4934             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4935             :       "\x0A\x5D\xB0\x03\x56\xA9\xFC\x4F\xA2\xF5\x48\x9B\xEE\x41\x94\xE7"
    4936             :       "\x3A\x8D\xE0\x33\x86\xD9\x2C\x7F\xD2\x25\x78\xCB\x1E\x71\xC4\x17",
    4937             :       "\x1F\x86\xED\x54\xBB\x22\x89\xF0",
    4938             :       {
    4939             :         { 0, 64,
    4940             :           "\x51\x22\x52\x91\x01\x90\xD1\x54\xD1\x4D\x0B\x92\x32\xB8\x84\x31"
    4941             :           "\x8C\xCB\x43\x81\x9B\xD5\x42\x19\x32\xC0\x3A\x13\xF0\x7B\x40\x10"
    4942             :           "\x83\xD7\x89\x72\x5A\xA9\xDA\x0B\x41\xCB\x62\x24\x94\x5E\xDC\xB0"
    4943             :           "\xFB\x6F\xD7\xC2\x34\x22\x35\xC9\x70\xF6\x4E\x10\x1C\x25\x68\x64"
    4944             :         },
    4945             :         { 65472, 64,
    4946             :           "\x97\x96\x74\x55\x84\x0A\x4A\xE5\xC1\xCA\xCE\x49\x15\x19\x13\x8A"
    4947             :           "\xA3\x5E\x5F\x02\x40\x7D\x4A\x1F\xE5\x08\x6D\x35\xF3\x55\x1E\xF4"
    4948             :           "\x77\xD9\x28\x9D\x17\x23\x79\x7C\x1A\x49\xEC\x26\x62\x9A\xFA\xDC"
    4949             :           "\x56\xA0\x38\xA3\x8C\x75\x88\x1B\x62\x17\xFD\x74\x67\x25\x59\x09"
    4950             :         },
    4951             :         { 65536, 64,
    4952             :           "\x1B\xF8\x2E\x3D\x5C\x54\xDA\xAB\xCF\x84\x15\xF8\xA2\xA1\xA2\x2E"
    4953             :           "\x86\x88\x06\x33\x4F\xF3\x11\x36\x04\x74\x1C\x1D\xF2\xB9\x84\x0F"
    4954             :           "\x87\xDE\xEF\xB0\x07\x23\xA8\xA1\xB2\x4A\x4D\xA1\x7E\xCD\xAD\x00"
    4955             :           "\x01\xF9\x79\xDD\xAE\x2D\xF0\xC5\xE1\xE5\x32\xC4\x8F\x8E\x0D\x34"
    4956             :         },
    4957             :         { 131008, 64,
    4958             :           "\x06\xD8\x4F\x6A\x71\x34\x84\x20\x32\x9F\xCD\x0C\x41\x75\x9A\xD1"
    4959             :           "\x8F\x99\x57\xA3\x8F\x22\x89\x3B\xA5\x58\xC5\x05\x11\x97\x28\x5C"
    4960             :           "\x6B\xE2\xFD\x6C\x96\xA5\xC6\x62\xAF\xD3\x11\x78\xE7\x0F\x96\x0A"
    4961             :           "\xAB\x3F\x47\x96\x23\xA4\x44\xB6\x81\x91\xE4\xC5\x28\x46\x93\x88"
    4962             :         }
    4963             :       }
    4964             :     },
    4965             :     {
    4966             :       "Salsa20/12 256 bit, ecrypt verified, set 6, vector 3",
    4967             :       GCRY_CIPHER_SALSA20R12, 32, 8,
    4968             :       "\x0F\x62\xB5\x08\x5B\xAE\x01\x54\xA7\xFA\x4D\xA0\xF3\x46\x99\xEC"
    4969             :       "\x3F\x92\xE5\x38\x8B\xDE\x31\x84\xD7\x2A\x7D\xD0\x23\x76\xC9\x1C",
    4970             :       "\x28\x8F\xF6\x5D\xC4\x2B\x92\xF9",
    4971             :       {
    4972             :         { 0, 64,
    4973             :           "\x99\xDB\x33\xAD\x11\xCE\x0C\xCB\x3B\xFD\xBF\x8D\x0C\x18\x16\x04"
    4974             :           "\x52\xD0\x14\xCD\xE9\x89\xB4\xC4\x11\xA5\x59\xFF\x7C\x20\xA1\x69"
    4975             :           "\xE6\xDC\x99\x09\xD8\x16\xBE\xCE\xDC\x40\x63\xCE\x07\xCE\xA8\x28"
    4976             :           "\xF4\x4B\xF9\xB6\xC9\xA0\xA0\xB2\x00\xE1\xB5\x2A\xF4\x18\x59\xC5"
    4977             :         },
    4978             :         { 65472, 64,
    4979             :           "\x2F\xF2\x02\x64\xEE\xAF\x47\xAB\x7D\x57\xC3\x62\x24\x53\x54\x51"
    4980             :           "\x73\x5A\xC8\x36\xD3\x2D\xD2\x8A\xE6\x36\x45\xCE\x95\x2F\x7F\xDB"
    4981             :           "\xE6\x68\x9C\x69\x59\x77\xB1\xC7\x6E\x60\xDD\x5B\x27\xAC\xA4\x76"
    4982             :           "\xD2\x62\x0F\xDC\x93\x13\xE8\x48\x9B\xA5\x6A\x70\xC9\xF4\xC3\xA8"
    4983             :         },
    4984             :         { 65536, 64,
    4985             :           "\xEB\x30\xCD\xA7\x27\xC0\xF8\xB7\xE4\x5D\x5E\xF3\x0D\xB7\xCB\xE0"
    4986             :           "\x21\xF2\x29\x1E\x5F\x56\x93\x8D\x56\xF6\x87\xB7\x37\xC3\xB4\x27"
    4987             :           "\x54\x5C\x56\xA6\xD3\xA0\xBF\x2B\x2F\x47\xB4\x84\x93\xFA\xE4\x5E"
    4988             :           "\xD5\x0C\x2E\x9B\xBE\x49\xFD\x92\xD6\x7C\x76\x49\x05\x5F\x06\xFD"
    4989             :         },
    4990             :         { 131008, 64,
    4991             :           "\x0E\xBF\x6C\xC3\xCB\xCB\xE7\x4E\x6E\xE8\x07\x47\x1B\x49\x2A\x67"
    4992             :           "\x39\xA5\x2F\x57\x11\x31\xA2\x50\xBC\xDF\xA0\x76\xA2\x65\x90\xD7"
    4993             :           "\xED\xE6\x75\x1C\x03\x26\xA0\x2C\xB1\x1C\x58\x77\x35\x52\x80\x4F"
    4994             :           "\xD8\x68\x67\x15\x35\x5C\x5A\x5C\xC5\x91\x96\x3A\x75\xE9\x94\xB4"
    4995             :         }
    4996             :       }
    4997             :     }
    4998             : #endif /*USE_SALSA20*/
    4999             :   };
    5000             : 
    5001             : 
    5002             :   char zeroes[512];
    5003             :   gcry_cipher_hd_t hde;
    5004             :   unsigned char *buffer;
    5005             :   unsigned char *p;
    5006             :   size_t buffersize;
    5007             :   unsigned int n;
    5008             :   int i, j;
    5009           1 :   gcry_error_t err = 0;
    5010             : 
    5011           1 :   if (verbose)
    5012           0 :     fprintf (stderr, "  Starting large block stream cipher checks.\n");
    5013             : 
    5014           1 :   memset (zeroes, 0, 512);
    5015             : 
    5016           1 :   buffersize = 128 * 1024;
    5017           1 :   buffer = gcry_xmalloc (buffersize+1024);
    5018           1 :   memset (buffer+buffersize, 0x5a, 1024);
    5019             : 
    5020           9 :   for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
    5021             :     {
    5022           8 :       if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode)
    5023             :         {
    5024           0 :           if (verbose)
    5025           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    5026             :                      tv[i].algo);
    5027           0 :           continue;
    5028             :         }
    5029             : 
    5030           8 :       if (verbose)
    5031           0 :         fprintf (stderr, "    checking large block stream for %s [%i] (%s)\n",
    5032             :                  gcry_cipher_algo_name (tv[i].algo), tv[i].algo, tv[i].name);
    5033             : 
    5034           8 :       err = gcry_cipher_open (&hde, tv[i].algo, GCRY_CIPHER_MODE_STREAM, 0);
    5035           8 :       if (err)
    5036             :         {
    5037           0 :           fail ("large stream, gcry_cipher_open for stream mode failed: %s\n",
    5038             :                 gpg_strerror (err));
    5039           0 :           continue;
    5040             :         }
    5041             : 
    5042           8 :       err = gcry_cipher_setkey (hde, tv[i].key, tv[i].keylen);
    5043           8 :       if (err)
    5044             :         {
    5045           0 :           fail ("large stream, gcry_cipher_setkey failed: %s\n",
    5046             :                 gpg_strerror (err));
    5047           0 :           goto next;
    5048             :         }
    5049             : 
    5050           8 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    5051           8 :       if (err)
    5052             :         {
    5053           0 :           fail ("large stream, gcry_cipher_setiv failed: %s\n",
    5054             :                 gpg_strerror (err));
    5055           0 :           goto next;
    5056             :         }
    5057             : 
    5058        2056 :       for (j=0, p=buffer; j < buffersize/512; j++, p += 512)
    5059             :         {
    5060        2048 :           err = gcry_cipher_encrypt (hde, p, 512, zeroes, 512);
    5061        2048 :           if (err)
    5062             :             {
    5063           0 :               fail ("large stream, "
    5064             :                     "gcry_cipher_encrypt (%d) block %d failed: %s\n",
    5065             :                     i, j, gpg_strerror (err));
    5066           0 :               goto next;
    5067             :             }
    5068             :         }
    5069        8200 :       for (j=0, p=buffer+buffersize; j < 1024; j++, p++)
    5070        8192 :         if (*p != 0x5a)
    5071           0 :           die ("large stream, buffer corrupted at j=%d\n", j);
    5072             : 
    5073             :       /* Now loop over all the data samples.  */
    5074          40 :       for (j = 0; tv[i].data[j].length; j++)
    5075             :         {
    5076          32 :           assert (tv[i].data[j].offset + tv[i].data[j].length <= buffersize);
    5077             : 
    5078          64 :           if (memcmp (tv[i].data[j].result,
    5079          64 :                       buffer + tv[i].data[j].offset, tv[i].data[j].length))
    5080             :             {
    5081           0 :               fail ("large stream, encrypt mismatch entry %d:%d\n", i, j);
    5082           0 :               mismatch (tv[i].data[j].result, tv[i].data[j].length,
    5083           0 :                         buffer + tv[i].data[j].offset, tv[i].data[j].length);
    5084             :             }
    5085             :         }
    5086             : 
    5087             :       /*
    5088             :        *  Let's do the same thing again but using changing block sizes.
    5089             :        */
    5090           8 :       err = gcry_cipher_setkey (hde, tv[i].key, tv[i].keylen);
    5091           8 :       if (err)
    5092             :         {
    5093           0 :           fail ("large stream, gcry_cipher_setkey failed: %s\n",
    5094             :                 gpg_strerror (err));
    5095           0 :           goto next;
    5096             :         }
    5097             : 
    5098           8 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    5099           8 :       if (err)
    5100             :         {
    5101           0 :           fail ("large stream, gcry_cipher_setiv failed: %s\n",
    5102             :                 gpg_strerror (err));
    5103           0 :           goto next;
    5104             :         }
    5105             : 
    5106        2104 :       for (n=0, p=buffer, j = 0; n < buffersize; n += j, p += j)
    5107             :         {
    5108        2096 :           switch (j)
    5109             :             {
    5110           8 :             case   0: j =   1;  break;
    5111           8 :             case   1: j =  64; break;
    5112           8 :             case  64: j=  384; break;
    5113           8 :             case 384: j =  63; break;
    5114           8 :             case  63: j = 512; break;
    5115           8 :             case 512: j =  32; break;
    5116           8 :             case  32: j = 503; break;
    5117        2040 :             default:  j = 509; break;
    5118             :             }
    5119        2096 :           if ( n + j >= buffersize )
    5120           8 :             j = buffersize - n;
    5121        2096 :           assert (j <= 512);
    5122        2096 :           err = gcry_cipher_encrypt (hde, p, j, zeroes, j);
    5123        2096 :           if (err)
    5124             :             {
    5125           0 :               fail ("large stream, "
    5126             :                     "gcry_cipher_encrypt (%d) offset %u failed: %s\n",
    5127             :                     i, n, gpg_strerror (err));
    5128           0 :               goto next;
    5129             :             }
    5130             :         }
    5131        8200 :       for (j=0, p=buffer+buffersize; j < 1024; j++, p++)
    5132        8192 :         if (*p != 0x5a)
    5133           0 :           die ("large stream, buffer corrupted at j=%d (line %d)\n",
    5134             :                j, __LINE__);
    5135             : 
    5136             :       /* Now loop over all the data samples.  */
    5137          40 :       for (j = 0; tv[i].data[j].length; j++)
    5138             :         {
    5139          32 :           assert (tv[i].data[j].offset + tv[i].data[j].length <= buffersize);
    5140             : 
    5141          64 :           if (memcmp (tv[i].data[j].result,
    5142          64 :                       buffer + tv[i].data[j].offset, tv[i].data[j].length))
    5143             :             {
    5144           0 :               fail ("large stream var, encrypt mismatch entry %d:%d\n", i, j);
    5145           0 :               mismatch (tv[i].data[j].result, tv[i].data[j].length,
    5146           0 :                         buffer + tv[i].data[j].offset, tv[i].data[j].length);
    5147             :             }
    5148             :         }
    5149             : 
    5150             :     next:
    5151           8 :       gcry_cipher_close (hde);
    5152             :     }
    5153             : 
    5154           1 :   gcry_free (buffer);
    5155           1 :   if (verbose)
    5156           0 :     fprintf (stderr, "  Completed large block stream cipher checks.\n");
    5157           1 : }
    5158             : 
    5159             : 
    5160             : 
    5161             : /* Check that our bulk encryption fucntions work properly.  */
    5162             : static void
    5163           1 : check_bulk_cipher_modes (void)
    5164             : {
    5165             :   static const struct
    5166             :   {
    5167             :     int algo;
    5168             :     int mode;
    5169             :     const char *key;
    5170             :     int  keylen;
    5171             :     const char *iv;
    5172             :     int ivlen;
    5173             :     char t1_hash[20];
    5174             :   } tv[] = {
    5175             :     { GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CFB,
    5176             :       "abcdefghijklmnop", 16,
    5177             :       "1234567890123456", 16,
    5178             : /*[0]*/
    5179             :       { 0x53, 0xda, 0x27, 0x3c, 0x78, 0x3d, 0x54, 0x66, 0x19, 0x63,
    5180             :         0xd7, 0xe6, 0x20, 0x10, 0xcd, 0xc0, 0x5a, 0x0b, 0x06, 0xcc }
    5181             :     },
    5182             :     { GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CFB,
    5183             :       "abcdefghijklmnopABCDEFG", 24,
    5184             :       "1234567890123456", 16,
    5185             : /*[1]*/
    5186             :       { 0xc7, 0xb1, 0xd0, 0x09, 0x95, 0x04, 0x34, 0x61, 0x2b, 0xd9,
    5187             :         0xcb, 0xb3, 0xc7, 0xcb, 0xef, 0xea, 0x16, 0x19, 0x9b, 0x3e }
    5188             :     },
    5189             :     { GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CFB,
    5190             :       "abcdefghijklmnopABCDEFGHIJKLMNOP", 32,
    5191             :       "1234567890123456", 16,
    5192             : /*[2]*/
    5193             :       { 0x31, 0xe1, 0x1f, 0x63, 0x65, 0x47, 0x8c, 0x3f, 0x53, 0xdb,
    5194             :         0xd9, 0x4d, 0x91, 0x1d, 0x02, 0x9c, 0x05, 0x25, 0x58, 0x29 }
    5195             :     },
    5196             :     { GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC,
    5197             :       "abcdefghijklmnop", 16,
    5198             :       "1234567890123456", 16,
    5199             : /*[3]*/
    5200             :       { 0xdc, 0x0c, 0xc2, 0xd9, 0x6b, 0x47, 0xf9, 0xeb, 0x06, 0xb4,
    5201             :         0x2f, 0x6e, 0xec, 0x72, 0xbf, 0x55, 0x26, 0x7f, 0xa9, 0x97 }
    5202             :     },
    5203             :     { GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC,
    5204             :       "abcdefghijklmnopABCDEFG", 24,
    5205             :       "1234567890123456", 16,
    5206             : /*[4]*/
    5207             :       { 0x2b, 0x90, 0x9b, 0xe6, 0x40, 0xab, 0x6e, 0xc2, 0xc5, 0xb1,
    5208             :         0x87, 0xf5, 0x43, 0x84, 0x7b, 0x04, 0x06, 0x47, 0xd1, 0x8f }
    5209             :     },
    5210             :     { GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC,
    5211             :       "abcdefghijklmnopABCDEFGHIJKLMNOP", 32,
    5212             :       "1234567890123456", 16,
    5213             : /*[5]*/
    5214             :       { 0xaa, 0xa8, 0xdf, 0x03, 0xb0, 0xba, 0xc4, 0xe3, 0xc1, 0x02,
    5215             :         0x38, 0x31, 0x8d, 0x86, 0xcb, 0x49, 0x6d, 0xad, 0xae, 0x01 }
    5216             :     },
    5217             :     { GCRY_CIPHER_AES, GCRY_CIPHER_MODE_OFB,
    5218             :       "abcdefghijklmnop", 16,
    5219             :       "1234567890123456", 16,
    5220             : /*[6]*/
    5221             :       { 0x65, 0xfe, 0xde, 0x48, 0xd0, 0xa1, 0xa6, 0xf9, 0x24, 0x6b,
    5222             :         0x52, 0x5f, 0x21, 0x8a, 0x6f, 0xc7, 0x70, 0x3b, 0xd8, 0x4a }
    5223             :     },
    5224             :     { GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_OFB,
    5225             :       "abcdefghijklmnopABCDEFG", 24,
    5226             :       "1234567890123456", 16,
    5227             : /*[7]*/
    5228             :       { 0x59, 0x5b, 0x02, 0xa2, 0x88, 0xc0, 0xbe, 0x94, 0x43, 0xaa,
    5229             :         0x39, 0xf6, 0xbd, 0xcc, 0x83, 0x99, 0xee, 0x00, 0xa1, 0x91 }
    5230             :     },
    5231             :     { GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_OFB,
    5232             :       "abcdefghijklmnopABCDEFGHIJKLMNOP", 32,
    5233             :       "1234567890123456", 16,
    5234             : /*[8]*/
    5235             :       { 0x38, 0x8c, 0xe1, 0xe2, 0xbe, 0x67, 0x60, 0xe8, 0xeb, 0xce,
    5236             :         0xd0, 0xc6, 0xaa, 0xd6, 0xf6, 0x26, 0x15, 0x56, 0xd0, 0x2b }
    5237             :     },
    5238             :     { GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CTR,
    5239             :       "abcdefghijklmnop", 16,
    5240             :       "1234567890123456", 16,
    5241             : /*[9]*/
    5242             :       { 0x9a, 0x48, 0x94, 0xd6, 0x50, 0x46, 0x81, 0xdb, 0x68, 0x34,
    5243             :         0x3b, 0xc5, 0x9e, 0x66, 0x94, 0x81, 0x98, 0xa0, 0xf9, 0xff }
    5244             :     },
    5245             :     { GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CTR,
    5246             :       "abcdefghijklmnopABCDEFG", 24,
    5247             :       "1234567890123456", 16,
    5248             : /*[10]*/
    5249             :       { 0x2c, 0x2c, 0xd3, 0x75, 0x81, 0x2a, 0x59, 0x07, 0xeb, 0x08,
    5250             :         0xce, 0x28, 0x4c, 0x0c, 0x6a, 0xa8, 0x8f, 0xa3, 0x98, 0x7e }
    5251             :     },
    5252             :     { GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CTR,
    5253             :       "abcdefghijklmnopABCDEFGHIJKLMNOP", 32,
    5254             :       "1234567890123456", 16,
    5255             : /*[11]*/
    5256             :       { 0x64, 0xce, 0x73, 0x03, 0xc7, 0x89, 0x99, 0x1f, 0xf1, 0xce,
    5257             :         0xfe, 0xfb, 0xb9, 0x42, 0x30, 0xdf, 0xbb, 0x68, 0x6f, 0xd3 }
    5258             :     },
    5259             :     { GCRY_CIPHER_AES, GCRY_CIPHER_MODE_ECB,
    5260             :       "abcdefghijklmnop", 16,
    5261             :       "1234567890123456", 16,
    5262             : /*[12]*/
    5263             :       { 0x51, 0xae, 0xf5, 0xac, 0x22, 0xa0, 0xba, 0x11, 0xc5, 0xaa,
    5264             :         0xb4, 0x70, 0x99, 0xce, 0x18, 0x08, 0x12, 0x9b, 0xb1, 0xc5 }
    5265             :     },
    5266             :     { GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_ECB,
    5267             :       "abcdefghijklmnopABCDEFG", 24,
    5268             :       "1234567890123456", 16,
    5269             : /*[13]*/
    5270             :       { 0x57, 0x91, 0xea, 0x48, 0xd8, 0xbf, 0x9e, 0xc1, 0xae, 0x33,
    5271             :         0xb3, 0xfd, 0xf7, 0x7a, 0xeb, 0x30, 0xb1, 0x62, 0x0d, 0x82 }
    5272             :     },
    5273             :     { GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_ECB,
    5274             :       "abcdefghijklmnopABCDEFGHIJKLMNOP", 32,
    5275             :       "1234567890123456", 16,
    5276             : /*[14]*/
    5277             :       { 0x2d, 0x71, 0x54, 0xb9, 0xc5, 0x28, 0x76, 0xff, 0x76, 0xb5,
    5278             :         0x99, 0x37, 0x99, 0x9d, 0xf7, 0x10, 0x6d, 0x86, 0x4f, 0x3f }
    5279             :     }
    5280             :   };
    5281           1 :   gcry_cipher_hd_t hde = NULL;
    5282           1 :   gcry_cipher_hd_t hdd = NULL;
    5283             :   unsigned char *buffer_base, *outbuf_base; /* Allocated buffers.  */
    5284             :   unsigned char *buffer, *outbuf;           /* Aligned buffers.  */
    5285             :   size_t buflen;
    5286             :   unsigned char hash[20];
    5287             :   int i, j, keylen, blklen;
    5288           1 :   gcry_error_t err = 0;
    5289             : 
    5290           1 :   if (verbose)
    5291           0 :     fprintf (stderr, "Starting bulk cipher checks.\n");
    5292             : 
    5293           1 :   buflen = 16*100;  /* We check a 1600 byte buffer.  */
    5294           1 :   buffer_base = gcry_xmalloc (buflen+16);
    5295           1 :   buffer = buffer_base + (16 - ((size_t)buffer_base & 0x0f));
    5296           1 :   outbuf_base = gcry_xmalloc (buflen+16);
    5297           1 :   outbuf = outbuf_base + (16 - ((size_t)outbuf_base & 0x0f));
    5298             : 
    5299             : 
    5300          16 :   for (i = 0; i < DIM (tv); i++)
    5301             :     {
    5302          15 :       if (verbose)
    5303           0 :         fprintf (stderr, "    checking bulk encryption for %s [%i], mode %d\n",
    5304             :                  gcry_cipher_algo_name (tv[i].algo),
    5305             :                  tv[i].algo, tv[i].mode);
    5306          15 :       err = gcry_cipher_open (&hde, tv[i].algo, tv[i].mode, 0);
    5307          15 :       if (!err)
    5308          15 :         err = gcry_cipher_open (&hdd, tv[i].algo, tv[i].mode, 0);
    5309          15 :       if (err)
    5310             :         {
    5311           0 :           fail ("gcry_cipher_open failed: %s\n", gpg_strerror (err));
    5312           0 :           goto leave;
    5313             :         }
    5314             : 
    5315          15 :       keylen = gcry_cipher_get_algo_keylen(tv[i].algo);
    5316          15 :       if (!keylen)
    5317             :         {
    5318           0 :           fail ("gcry_cipher_get_algo_keylen failed\n");
    5319           0 :           goto leave;
    5320             :         }
    5321             : 
    5322          15 :       err = gcry_cipher_setkey (hde, tv[i].key, tv[i].keylen);
    5323          15 :       if (!err)
    5324          15 :         err = gcry_cipher_setkey (hdd, tv[i].key, tv[i].keylen);
    5325          15 :       if (err)
    5326             :         {
    5327           0 :           fail ("gcry_cipher_setkey failed: %s\n", gpg_strerror (err));
    5328           0 :           goto leave;
    5329             :         }
    5330             : 
    5331          15 :       blklen = gcry_cipher_get_algo_blklen(tv[i].algo);
    5332          15 :       if (!blklen)
    5333             :         {
    5334           0 :           fail ("gcry_cipher_get_algo_blklen failed\n");
    5335           0 :           goto leave;
    5336             :         }
    5337             : 
    5338          15 :       err = gcry_cipher_setiv (hde, tv[i].iv, tv[i].ivlen);
    5339          15 :       if (!err)
    5340          15 :         err = gcry_cipher_setiv (hdd, tv[i].iv,  tv[i].ivlen);
    5341          15 :       if (err)
    5342             :         {
    5343           0 :           fail ("gcry_cipher_setiv failed: %s\n", gpg_strerror (err));
    5344           0 :           goto leave;
    5345             :         }
    5346             : 
    5347             :       /* Fill the buffer with our test pattern.  */
    5348       24015 :       for (j=0; j < buflen; j++)
    5349       24000 :         buffer[j] = ((j & 0xff) ^ ((j >> 8) & 0xff));
    5350             : 
    5351          15 :       err = gcry_cipher_encrypt (hde, outbuf, buflen, buffer, buflen);
    5352          15 :       if (err)
    5353             :         {
    5354           0 :           fail ("gcry_cipher_encrypt (algo %d, mode %d) failed: %s\n",
    5355             :                 tv[i].algo, tv[i].mode, gpg_strerror (err));
    5356           0 :           goto leave;
    5357             :         }
    5358             : 
    5359          15 :       gcry_md_hash_buffer (GCRY_MD_SHA1, hash, outbuf, buflen);
    5360             : #if 0
    5361             :       printf ("/*[%d]*/\n", i);
    5362             :       fputs ("      {", stdout);
    5363             :       for (j=0; j < 20; j++)
    5364             :         printf (" 0x%02x%c%s", hash[j], j==19? ' ':',', j == 9? "\n       ":"");
    5365             :       puts ("}");
    5366             : #endif
    5367             : 
    5368          15 :       if (memcmp (hash, tv[i].t1_hash, 20))
    5369           0 :         fail ("encrypt mismatch (algo %d, mode %d)\n",
    5370             :               tv[i].algo, tv[i].mode);
    5371             : 
    5372          15 :       err = gcry_cipher_decrypt (hdd, outbuf, buflen, NULL, 0);
    5373          15 :       if (err)
    5374             :         {
    5375           0 :           fail ("gcry_cipher_decrypt (algo %d, mode %d) failed: %s\n",
    5376             :                 tv[i].algo, tv[i].mode, gpg_strerror (err));
    5377           0 :           goto leave;
    5378             :         }
    5379             : 
    5380          15 :       if (memcmp (buffer, outbuf, buflen))
    5381           0 :         fail ("decrypt mismatch (algo %d, mode %d)\n",
    5382             :               tv[i].algo, tv[i].mode);
    5383             : 
    5384          15 :       gcry_cipher_close (hde); hde = NULL;
    5385          15 :       gcry_cipher_close (hdd); hdd = NULL;
    5386             :     }
    5387             : 
    5388           1 :   if (verbose)
    5389           0 :     fprintf (stderr, "Completed bulk cipher checks.\n");
    5390             :  leave:
    5391           1 :   gcry_cipher_close (hde);
    5392           1 :   gcry_cipher_close (hdd);
    5393           1 :   gcry_free (buffer_base);
    5394           1 :   gcry_free (outbuf_base);
    5395           1 : }
    5396             : 
    5397             : 
    5398             : static unsigned int
    5399        2480 : get_algo_mode_blklen (int algo, int mode)
    5400             : {
    5401        2480 :   unsigned int blklen = gcry_cipher_get_algo_blklen(algo);
    5402             : 
    5403             :   /* Some modes override blklen. */
    5404        2480 :   switch (mode)
    5405             :     {
    5406             :     case GCRY_CIPHER_MODE_STREAM:
    5407             :     case GCRY_CIPHER_MODE_OFB:
    5408             :     case GCRY_CIPHER_MODE_CTR:
    5409             :     case GCRY_CIPHER_MODE_CCM:
    5410             :     case GCRY_CIPHER_MODE_GCM:
    5411             :     case GCRY_CIPHER_MODE_POLY1305:
    5412        1072 :       return 1;
    5413             :     }
    5414             : 
    5415        1408 :   return blklen;
    5416             : }
    5417             : 
    5418             : 
    5419             : static int
    5420       19840 : check_one_cipher_core_reset (gcry_cipher_hd_t hd, int algo, int mode, int pass,
    5421             :                              int nplain)
    5422             : {
    5423             :   static const unsigned char iv[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
    5424             :   u64 ctl_params[3];
    5425             :   int err;
    5426             : 
    5427       19840 :   gcry_cipher_reset (hd);
    5428             : 
    5429       19840 :   if (mode == GCRY_CIPHER_MODE_OCB || mode == GCRY_CIPHER_MODE_CCM)
    5430             :     {
    5431        3072 :       err = gcry_cipher_setiv (hd, iv, sizeof(iv));
    5432        3072 :       if (err)
    5433             :         {
    5434           0 :           fail ("pass %d, algo %d, mode %d, gcry_cipher_setiv failed: %s\n",
    5435             :                 pass, algo, mode, gpg_strerror (err));
    5436           0 :           gcry_cipher_close (hd);
    5437           0 :           return -1;
    5438             :         }
    5439             :     }
    5440             : 
    5441       19840 :   if (mode == GCRY_CIPHER_MODE_CCM)
    5442             :     {
    5443        1536 :       ctl_params[0] = nplain; /* encryptedlen */
    5444        1536 :       ctl_params[1] = 0; /* aadlen */
    5445        1536 :       ctl_params[2] = 16; /* authtaglen */
    5446        1536 :       err = gcry_cipher_ctl (hd, GCRYCTL_SET_CCM_LENGTHS, ctl_params,
    5447             :                             sizeof(ctl_params));
    5448        1536 :       if (err)
    5449             :         {
    5450           0 :           fail ("pass %d, algo %d, mode %d, gcry_cipher_ctl "
    5451             :                 "GCRYCTL_SET_CCM_LENGTHS failed: %s\n",
    5452             :                 pass, algo, mode, gpg_strerror (err));
    5453           0 :           gcry_cipher_close (hd);
    5454           0 :           return -1;
    5455             :         }
    5456             :     }
    5457             : 
    5458       19840 :   return 0;
    5459             : }
    5460             : 
    5461             : /* The core of the cipher check.  In addition to the parameters passed
    5462             :    to check_one_cipher it also receives the KEY and the plain data.
    5463             :    PASS is printed with error messages.  The function returns 0 on
    5464             :    success.  */
    5465             : static int
    5466        2480 : check_one_cipher_core (int algo, int mode, int flags,
    5467             :                        const char *key, size_t nkey,
    5468             :                        const unsigned char *plain, size_t nplain,
    5469             :                        int bufshift, int pass)
    5470             : {
    5471             :   gcry_cipher_hd_t hd;
    5472             :   unsigned char in_buffer[1040+1], out_buffer[1040+1];
    5473             :   unsigned char enc_result[1040];
    5474             :   unsigned char *in, *out;
    5475             :   int keylen;
    5476        2480 :   gcry_error_t err = 0;
    5477             :   unsigned int blklen;
    5478             :   unsigned int piecelen;
    5479             :   unsigned int pos;
    5480             : 
    5481        2480 :   blklen = get_algo_mode_blklen(algo, mode);
    5482             : 
    5483        2480 :   assert (nkey == 32);
    5484        2480 :   assert (nplain == 1040);
    5485        2480 :   assert (sizeof(in_buffer) == nplain + 1);
    5486             :   assert (sizeof(out_buffer) == sizeof(in_buffer));
    5487        2480 :   assert (blklen > 0);
    5488             : 
    5489        2480 :   if (mode == GCRY_CIPHER_MODE_CBC && (flags & GCRY_CIPHER_CBC_CTS))
    5490             :     {
    5491             :       /* TODO: examine why CBC with CTS fails. */
    5492         304 :       blklen = nplain;
    5493             :     }
    5494             : 
    5495        2480 :   if (!bufshift)
    5496             :     {
    5497         620 :       in = in_buffer;
    5498         620 :       out = out_buffer;
    5499             :     }
    5500        1860 :   else if (bufshift == 1)
    5501             :     {
    5502         620 :       in = in_buffer+1;
    5503         620 :       out = out_buffer;
    5504             :     }
    5505        1240 :   else if (bufshift == 2)
    5506             :     {
    5507         620 :       in = in_buffer+1;
    5508         620 :       out = out_buffer+1;
    5509             :     }
    5510             :   else
    5511             :     {
    5512         620 :       in = in_buffer;
    5513         620 :       out = out_buffer+1;
    5514             :     }
    5515             : 
    5516        2480 :   keylen = gcry_cipher_get_algo_keylen (algo);
    5517        2480 :   if (!keylen)
    5518             :     {
    5519           0 :       fail ("pass %d, algo %d, mode %d, gcry_cipher_get_algo_keylen failed\n",
    5520             :             pass, algo, mode);
    5521           0 :       return -1;
    5522             :     }
    5523             : 
    5524        2480 :   if (keylen < 40 / 8 || keylen > 32)
    5525             :     {
    5526           0 :       fail ("pass %d, algo %d, mode %d, keylength problem (%d)\n", pass, algo, mode, keylen);
    5527           0 :       return -1;
    5528             :     }
    5529             : 
    5530        2480 :   err = gcry_cipher_open (&hd, algo, mode, flags);
    5531        2480 :   if (err)
    5532             :     {
    5533           0 :       fail ("pass %d, algo %d, mode %d, gcry_cipher_open failed: %s\n",
    5534             :             pass, algo, mode, gpg_strerror (err));
    5535           0 :       return -1;
    5536             :     }
    5537             : 
    5538        2480 :   err = gcry_cipher_setkey (hd, key, keylen);
    5539        2480 :   if (err)
    5540             :     {
    5541           0 :       fail ("pass %d, algo %d, mode %d, gcry_cipher_setkey failed: %s\n",
    5542             :             pass, algo, mode, gpg_strerror (err));
    5543           0 :       gcry_cipher_close (hd);
    5544           0 :       return -1;
    5545             :     }
    5546             : 
    5547        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5548           0 :     return -1;
    5549             : 
    5550        2480 :   err = gcry_cipher_encrypt (hd, out, nplain, plain, nplain);
    5551        2480 :   if (err)
    5552             :     {
    5553           0 :       fail ("pass %d, algo %d, mode %d, gcry_cipher_encrypt failed: %s\n",
    5554             :             pass, algo, mode, gpg_strerror (err));
    5555           0 :       gcry_cipher_close (hd);
    5556           0 :       return -1;
    5557             :     }
    5558             : 
    5559        2480 :   memcpy (enc_result, out, nplain);
    5560             : 
    5561        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5562           0 :     return -1;
    5563             : 
    5564        2480 :   err = gcry_cipher_decrypt (hd, in, nplain, out, nplain);
    5565        2480 :   if (err)
    5566             :     {
    5567           0 :       fail ("pass %d, algo %d, mode %d, gcry_cipher_decrypt failed: %s\n",
    5568             :             pass, algo, mode, gpg_strerror (err));
    5569           0 :       gcry_cipher_close (hd);
    5570           0 :       return -1;
    5571             :     }
    5572             : 
    5573        2480 :   if (memcmp (plain, in, nplain))
    5574           0 :     fail ("pass %d, algo %d, mode %d, encrypt-decrypt mismatch\n",
    5575             :           pass, algo, mode);
    5576             : 
    5577             :   /* Again, using in-place encryption.  */
    5578        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5579           0 :     return -1;
    5580             : 
    5581        2480 :   memcpy (out, plain, nplain);
    5582        2480 :   err = gcry_cipher_encrypt (hd, out, nplain, NULL, 0);
    5583        2480 :   if (err)
    5584             :     {
    5585           0 :       fail ("pass %d, algo %d, mode %d, in-place, gcry_cipher_encrypt failed:"
    5586             :             " %s\n",
    5587             :             pass, algo, mode, gpg_strerror (err));
    5588           0 :       gcry_cipher_close (hd);
    5589           0 :       return -1;
    5590             :     }
    5591             : 
    5592        2480 :   if (memcmp (enc_result, out, nplain))
    5593           0 :     fail ("pass %d, algo %d, mode %d, in-place, encrypt mismatch\n",
    5594             :           pass, algo, mode);
    5595             : 
    5596        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5597           0 :     return -1;
    5598             : 
    5599        2480 :   err = gcry_cipher_decrypt (hd, out, nplain, NULL, 0);
    5600        2480 :   if (err)
    5601             :     {
    5602           0 :       fail ("pass %d, algo %d, mode %d, in-place, gcry_cipher_decrypt failed:"
    5603             :             " %s\n",
    5604             :             pass, algo, mode, gpg_strerror (err));
    5605           0 :       gcry_cipher_close (hd);
    5606           0 :       return -1;
    5607             :     }
    5608             : 
    5609        2480 :   if (memcmp (plain, out, nplain))
    5610           0 :     fail ("pass %d, algo %d, mode %d, in-place, encrypt-decrypt mismatch\n",
    5611             :           pass, algo, mode);
    5612             : 
    5613             :   /* Again, splitting encryption in multiple operations. */
    5614        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5615           0 :     return -1;
    5616             : 
    5617        2480 :   piecelen = blklen;
    5618        2480 :   pos = 0;
    5619       26192 :   while (pos < nplain)
    5620             :     {
    5621       21232 :       if (piecelen > nplain - pos)
    5622        2176 :         piecelen = nplain - pos;
    5623             : 
    5624       21232 :       err = gcry_cipher_encrypt (hd, out + pos, piecelen, plain + pos,
    5625             :                                  piecelen);
    5626       21232 :       if (err)
    5627             :         {
    5628           0 :           fail ("pass %d, algo %d, mode %d, split-buffer (pos: %d, "
    5629             :                 "piecelen: %d), gcry_cipher_encrypt failed: %s\n",
    5630             :                 pass, algo, mode, pos, piecelen, gpg_strerror (err));
    5631           0 :           gcry_cipher_close (hd);
    5632           0 :           return -1;
    5633             :         }
    5634             : 
    5635       21232 :       pos += piecelen;
    5636       21232 :       piecelen = piecelen * 2 - ((piecelen != blklen) ? blklen : 0);
    5637             :     }
    5638             : 
    5639        2480 :   if (memcmp (enc_result, out, nplain))
    5640           0 :     fail ("pass %d, algo %d, mode %d, split-buffer, encrypt mismatch\n",
    5641             :           pass, algo, mode);
    5642             : 
    5643        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5644           0 :     return -1;
    5645             : 
    5646        2480 :   piecelen = blklen;
    5647        2480 :   pos = 0;
    5648       26192 :   while (pos < nplain)
    5649             :     {
    5650       21232 :       if (piecelen > nplain - pos)
    5651        2176 :         piecelen = nplain - pos;
    5652             : 
    5653       21232 :       err = gcry_cipher_decrypt (hd, in + pos, piecelen, out + pos, piecelen);
    5654       21232 :       if (err)
    5655             :         {
    5656           0 :           fail ("pass %d, algo %d, mode %d, split-buffer (pos: %d, "
    5657             :                 "piecelen: %d), gcry_cipher_decrypt failed: %s\n",
    5658             :                 pass, algo, mode, pos, piecelen, gpg_strerror (err));
    5659           0 :           gcry_cipher_close (hd);
    5660           0 :           return -1;
    5661             :         }
    5662             : 
    5663       21232 :       pos += piecelen;
    5664       21232 :       piecelen = piecelen * 2 - ((piecelen != blklen) ? blklen : 0);
    5665             :     }
    5666             : 
    5667        2480 :   if (memcmp (plain, in, nplain))
    5668           0 :     fail ("pass %d, algo %d, mode %d, split-buffer, encrypt-decrypt mismatch\n",
    5669             :           pass, algo, mode);
    5670             : 
    5671             :   /* Again, using in-place encryption and splitting encryption in multiple
    5672             :    * operations. */
    5673        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5674           0 :     return -1;
    5675             : 
    5676        2480 :   piecelen = blklen;
    5677        2480 :   pos = 0;
    5678       26192 :   while (pos < nplain)
    5679             :     {
    5680       21232 :       if (piecelen > nplain - pos)
    5681        2176 :         piecelen = nplain - pos;
    5682             : 
    5683       21232 :       memcpy (out + pos, plain + pos, piecelen);
    5684       21232 :       err = gcry_cipher_encrypt (hd, out + pos, piecelen, NULL, 0);
    5685       21232 :       if (err)
    5686             :         {
    5687           0 :           fail ("pass %d, algo %d, mode %d, in-place split-buffer (pos: %d, "
    5688             :                 "piecelen: %d), gcry_cipher_encrypt failed: %s\n",
    5689             :                 pass, algo, mode, pos, piecelen, gpg_strerror (err));
    5690           0 :           gcry_cipher_close (hd);
    5691           0 :           return -1;
    5692             :         }
    5693             : 
    5694       21232 :       pos += piecelen;
    5695       21232 :       piecelen = piecelen * 2 - ((piecelen != blklen) ? blklen : 0);
    5696             :     }
    5697             : 
    5698        2480 :   if (memcmp (enc_result, out, nplain))
    5699           0 :     fail ("pass %d, algo %d, mode %d, in-place split-buffer, encrypt mismatch\n",
    5700             :           pass, algo, mode);
    5701             : 
    5702        2480 :   if (check_one_cipher_core_reset (hd, algo, mode, pass, nplain) < 0)
    5703           0 :     return -1;
    5704             : 
    5705        2480 :   piecelen = blklen;
    5706        2480 :   pos = 0;
    5707       26192 :   while (pos < nplain)
    5708             :     {
    5709       21232 :       if (piecelen > nplain - pos)
    5710        2176 :         piecelen = nplain - pos;
    5711             : 
    5712       21232 :       err = gcry_cipher_decrypt (hd, out + pos, piecelen, NULL, 0);
    5713       21232 :       if (err)
    5714             :         {
    5715           0 :           fail ("pass %d, algo %d, mode %d, in-place split-buffer (pos: %d, "
    5716             :                 "piecelen: %d), gcry_cipher_decrypt failed: %s\n",
    5717             :                 pass, algo, mode, pos, piecelen, gpg_strerror (err));
    5718           0 :           gcry_cipher_close (hd);
    5719           0 :           return -1;
    5720             :         }
    5721             : 
    5722       21232 :       pos += piecelen;
    5723       21232 :       piecelen = piecelen * 2 - ((piecelen != blklen) ? blklen : 0);
    5724             :     }
    5725             : 
    5726        2480 :   if (memcmp (plain, out, nplain))
    5727           0 :     fail ("pass %d, algo %d, mode %d, in-place split-buffer, encrypt-decrypt"
    5728             :           " mismatch\n", pass, algo, mode);
    5729             : 
    5730             : 
    5731        2480 :   gcry_cipher_close (hd);
    5732             : 
    5733        2480 :   return 0;
    5734             : }
    5735             : 
    5736             : 
    5737             : 
    5738             : static void
    5739         155 : check_one_cipher (int algo, int mode, int flags)
    5740             : {
    5741             :   char key[32+1];
    5742             :   unsigned char plain[1040+1];
    5743             :   int bufshift, i;
    5744             : 
    5745         775 :   for (bufshift=0; bufshift < 4; bufshift++)
    5746             :     {
    5747             :       /* Pass 0: Standard test.  */
    5748         620 :       memcpy (key, "0123456789abcdef.,;/[]{}-=ABCDEF", 32);
    5749         620 :       memcpy (plain, "foobar42FOOBAR17", 16);
    5750       40300 :       for (i = 16; i < 1040; i += 16)
    5751             :         {
    5752       39680 :           memcpy (&plain[i], &plain[i-16], 16);
    5753       39680 :           if (!++plain[i+7])
    5754           0 :             plain[i+6]++;
    5755       39680 :           if (!++plain[i+15])
    5756           0 :             plain[i+14]++;
    5757             :         }
    5758             : 
    5759         620 :       if (check_one_cipher_core (algo, mode, flags, key, 32, plain, 1040,
    5760             :                                  bufshift, 0+10*bufshift))
    5761           0 :         return;
    5762             : 
    5763             :       /* Pass 1: Key not aligned.  */
    5764         620 :       memmove (key+1, key, 32);
    5765         620 :       if (check_one_cipher_core (algo, mode, flags, key+1, 32, plain, 1040,
    5766         620 :                                  bufshift, 1+10*bufshift))
    5767           0 :         return;
    5768             : 
    5769             :       /* Pass 2: Key not aligned and data not aligned.  */
    5770         620 :       memmove (plain+1, plain, 1040);
    5771         620 :       if (check_one_cipher_core (algo, mode, flags, key+1, 32, plain+1, 1040,
    5772         620 :                                  bufshift, 2+10*bufshift))
    5773           0 :         return;
    5774             : 
    5775             :       /* Pass 3: Key aligned and data not aligned.  */
    5776         620 :       memmove (key, key+1, 32);
    5777         620 :       if (check_one_cipher_core (algo, mode, flags, key, 32, plain+1, 1040,
    5778         620 :                                  bufshift, 3+10*bufshift))
    5779           0 :         return;
    5780             :     }
    5781             : 
    5782         155 :   return;
    5783             : }
    5784             : 
    5785             : 
    5786             : 
    5787             : static void
    5788           1 : check_ciphers (void)
    5789             : {
    5790             :   static const int algos[] = {
    5791             : #if USE_BLOWFISH
    5792             :     GCRY_CIPHER_BLOWFISH,
    5793             : #endif
    5794             : #if USE_DES
    5795             :     GCRY_CIPHER_DES,
    5796             :     GCRY_CIPHER_3DES,
    5797             : #endif
    5798             : #if USE_CAST5
    5799             :     GCRY_CIPHER_CAST5,
    5800             : #endif
    5801             : #if USE_AES
    5802             :     GCRY_CIPHER_AES,
    5803             :     GCRY_CIPHER_AES192,
    5804             :     GCRY_CIPHER_AES256,
    5805             : #endif
    5806             : #if USE_TWOFISH
    5807             :     GCRY_CIPHER_TWOFISH,
    5808             :     GCRY_CIPHER_TWOFISH128,
    5809             : #endif
    5810             : #if USE_SERPENT
    5811             :     GCRY_CIPHER_SERPENT128,
    5812             :     GCRY_CIPHER_SERPENT192,
    5813             :     GCRY_CIPHER_SERPENT256,
    5814             : #endif
    5815             : #if USE_RFC2268
    5816             :     GCRY_CIPHER_RFC2268_40,
    5817             : #endif
    5818             : #if USE_SEED
    5819             :     GCRY_CIPHER_SEED,
    5820             : #endif
    5821             : #if USE_CAMELLIA
    5822             :     GCRY_CIPHER_CAMELLIA128,
    5823             :     GCRY_CIPHER_CAMELLIA192,
    5824             :     GCRY_CIPHER_CAMELLIA256,
    5825             : #endif
    5826             : #if USE_IDEA
    5827             :     GCRY_CIPHER_IDEA,
    5828             : #endif
    5829             : #if USE_GOST28147
    5830             :     GCRY_CIPHER_GOST28147,
    5831             : #endif
    5832             :     0
    5833             :   };
    5834             :   static const int algos2[] = {
    5835             : #if USE_ARCFOUR
    5836             :     GCRY_CIPHER_ARCFOUR,
    5837             : #endif
    5838             : #if USE_SALSA20
    5839             :     GCRY_CIPHER_SALSA20,
    5840             :     GCRY_CIPHER_SALSA20R12,
    5841             : #endif
    5842             : #if USE_CHACHA20
    5843             :     GCRY_CIPHER_CHACHA20,
    5844             : #endif
    5845             :     0
    5846             :   };
    5847             :   int i;
    5848             : 
    5849           1 :   if (verbose)
    5850           0 :     fprintf (stderr, "Starting Cipher checks.\n");
    5851          20 :   for (i = 0; algos[i]; i++)
    5852             :     {
    5853          19 :       if (gcry_cipher_test_algo (algos[i]) && in_fips_mode)
    5854             :         {
    5855           0 :           if (verbose)
    5856           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    5857             :                      algos[i]);
    5858           0 :           continue;
    5859             :         }
    5860          19 :       if (verbose)
    5861           0 :         fprintf (stderr, "  checking %s [%i]\n",
    5862             :                  gcry_cipher_algo_name (algos[i]),
    5863             :                  gcry_cipher_map_name (gcry_cipher_algo_name (algos[i])));
    5864             : 
    5865          19 :       check_one_cipher (algos[i], GCRY_CIPHER_MODE_ECB, 0);
    5866          19 :       check_one_cipher (algos[i], GCRY_CIPHER_MODE_CFB, 0);
    5867          19 :       check_one_cipher (algos[i], GCRY_CIPHER_MODE_OFB, 0);
    5868          19 :       check_one_cipher (algos[i], GCRY_CIPHER_MODE_CBC, 0);
    5869          19 :       check_one_cipher (algos[i], GCRY_CIPHER_MODE_CBC, GCRY_CIPHER_CBC_CTS);
    5870          19 :       check_one_cipher (algos[i], GCRY_CIPHER_MODE_CTR, 0);
    5871          19 :       if (gcry_cipher_get_algo_blklen (algos[i]) == GCRY_CCM_BLOCK_LEN)
    5872          12 :         check_one_cipher (algos[i], GCRY_CIPHER_MODE_CCM, 0);
    5873          19 :       if (gcry_cipher_get_algo_blklen (algos[i]) == GCRY_GCM_BLOCK_LEN)
    5874          12 :         check_one_cipher (algos[i], GCRY_CIPHER_MODE_GCM, 0);
    5875          19 :       if (gcry_cipher_get_algo_blklen (algos[i]) == GCRY_OCB_BLOCK_LEN)
    5876          12 :         check_one_cipher (algos[i], GCRY_CIPHER_MODE_OCB, 0);
    5877             :     }
    5878             : 
    5879           5 :   for (i = 0; algos2[i]; i++)
    5880             :     {
    5881           4 :       if (gcry_cipher_test_algo (algos2[i]) && in_fips_mode)
    5882             :         {
    5883           0 :           if (verbose)
    5884           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    5885             :                      algos2[i]);
    5886           0 :           continue;
    5887             :         }
    5888           4 :       if (verbose)
    5889           0 :         fprintf (stderr, "  checking %s\n",
    5890             :                  gcry_cipher_algo_name (algos2[i]));
    5891             : 
    5892           4 :       check_one_cipher (algos2[i], GCRY_CIPHER_MODE_STREAM, 0);
    5893           4 :       if (algos2[i] == GCRY_CIPHER_CHACHA20)
    5894           1 :         check_one_cipher (algos2[i], GCRY_CIPHER_MODE_POLY1305, 0);
    5895             :     }
    5896             :   /* we have now run all cipher's selftests */
    5897             : 
    5898           1 :   if (verbose)
    5899           0 :     fprintf (stderr, "Completed Cipher checks.\n");
    5900             : 
    5901             :   /* TODO: add some extra encryption to test the higher level functions */
    5902           1 : }
    5903             : 
    5904             : 
    5905             : static void
    5906           1 : check_cipher_modes(void)
    5907             : {
    5908           1 :   if (verbose)
    5909           0 :     fprintf (stderr, "Starting Cipher Mode checks.\n");
    5910             : 
    5911           1 :   check_aes128_cbc_cts_cipher ();
    5912           1 :   check_cbc_mac_cipher ();
    5913           1 :   check_ctr_cipher ();
    5914           1 :   check_cfb_cipher ();
    5915           1 :   check_ofb_cipher ();
    5916           1 :   check_ccm_cipher ();
    5917           1 :   check_gcm_cipher ();
    5918           1 :   check_poly1305_cipher ();
    5919           1 :   check_ocb_cipher ();
    5920           1 :   check_gost28147_cipher ();
    5921           1 :   check_stream_cipher ();
    5922           1 :   check_stream_cipher_large_block ();
    5923             : 
    5924           1 :   if (verbose)
    5925           0 :     fprintf (stderr, "Completed Cipher Mode checks.\n");
    5926           1 : }
    5927             : 
    5928             : 
    5929             : static void
    5930       66960 : fillbuf_count (char *buf, size_t buflen, unsigned char pos)
    5931             : {
    5932    31133920 :   while (buflen--)
    5933    31000000 :     *((unsigned char *)(buf++)) = pos++;
    5934       66960 : }
    5935             : 
    5936             : 
    5937             : static void
    5938        1162 : check_one_md (int algo, const char *data, int len, const char *expect, int elen)
    5939             : {
    5940             :   gcry_md_hd_t hd, hd2;
    5941             :   unsigned char *p;
    5942             :   int mdlen;
    5943             :   int i;
    5944        1162 :   int xof = 0;
    5945        1162 :   gcry_error_t err = 0;
    5946             : 
    5947        1162 :   err = gcry_md_open (&hd, algo, 0);
    5948        1162 :   if (err)
    5949             :     {
    5950           0 :       fail ("algo %d, gcry_md_open failed: %s\n", algo, gpg_strerror (err));
    5951           0 :       return;
    5952             :     }
    5953             : 
    5954        1162 :   mdlen = gcry_md_get_algo_dlen (algo);
    5955        1162 :   if (mdlen < 1 || mdlen > 500)
    5956             :     {
    5957           6 :       if (mdlen == 0 && (algo == GCRY_MD_SHAKE128 || algo == GCRY_MD_SHAKE256))
    5958             :         {
    5959           6 :           xof = 1;
    5960             :         }
    5961             :       else
    5962             :         {
    5963           0 :           fail ("algo %d, gcry_md_get_algo_dlen failed: %d\n", algo, mdlen);
    5964           0 :           return;
    5965             :         }
    5966             :     }
    5967             : 
    5968        2304 :   if ((*data == '!' && !data[1]) || /* hash one million times a "a" */
    5969        1158 :       (*data == '?' && !data[1]))   /* hash million byte data-set with byte pattern 0x00,0x01,0x02,... */
    5970          36 :     {
    5971             :       char aaa[1000];
    5972          36 :       size_t left = 1000 * 1000;
    5973          36 :       size_t startlen = 1;
    5974          36 :       size_t piecelen = startlen;
    5975             : 
    5976          36 :       if (*data == '!')
    5977          20 :         memset (aaa, 'a', 1000);
    5978             : 
    5979             :       /* Write in chuck with all sizes 1 to 1000 (500500 bytes)  */
    5980       36036 :       for (i = 1; i <= 1000 && left > 0; i++)
    5981             :         {
    5982       36000 :           piecelen = i;
    5983       36000 :           if (piecelen > sizeof(aaa))
    5984           0 :             piecelen = sizeof(aaa);
    5985       36000 :           if (piecelen > left)
    5986           0 :             piecelen = left;
    5987             : 
    5988       36000 :           if (*data == '?')
    5989       16000 :             fillbuf_count(aaa, piecelen, 1000 * 1000 - left);
    5990             : 
    5991       36000 :           gcry_md_write (hd, aaa, piecelen);
    5992             : 
    5993       36000 :           left -= piecelen;
    5994             :         }
    5995             : 
    5996             :       /* Write in odd size chunks so that we test the buffering.  */
    5997       41832 :       while (left > 0)
    5998             :         {
    5999       41760 :           if (piecelen > sizeof(aaa))
    6000        6768 :             piecelen = sizeof(aaa);
    6001       41760 :           if (piecelen > left)
    6002          36 :             piecelen = left;
    6003             : 
    6004       41760 :           if (*data == '?')
    6005       18560 :             fillbuf_count(aaa, piecelen, 1000 * 1000 - left);
    6006             : 
    6007       41760 :           gcry_md_write (hd, aaa, piecelen);
    6008             : 
    6009       41760 :           left -= piecelen;
    6010             : 
    6011       41760 :           if (piecelen == sizeof(aaa))
    6012        6804 :             piecelen = ++startlen;
    6013             :           else
    6014       34956 :             piecelen = piecelen * 2 - ((piecelen != startlen) ? startlen : 0);
    6015             :         }
    6016             :     }
    6017             :   else
    6018        1126 :     gcry_md_write (hd, data, len);
    6019             : 
    6020        1162 :   err = gcry_md_copy (&hd2, hd);
    6021        1162 :   if (err)
    6022             :     {
    6023           0 :       fail ("algo %d, gcry_md_copy failed: %s\n", algo, gpg_strerror (err));
    6024             :     }
    6025             : 
    6026        1162 :   gcry_md_close (hd);
    6027             : 
    6028        1162 :   if (!xof)
    6029             :     {
    6030        1156 :       p = gcry_md_read (hd2, algo);
    6031             : 
    6032        1156 :       if (memcmp (p, expect, mdlen))
    6033             :         {
    6034           0 :           printf ("computed: ");
    6035           0 :           for (i = 0; i < mdlen; i++)
    6036           0 :             printf ("%02x ", p[i] & 0xFF);
    6037           0 :           printf ("\nexpected: ");
    6038           0 :           for (i = 0; i < mdlen; i++)
    6039           0 :             printf ("%02x ", expect[i] & 0xFF);
    6040           0 :           printf ("\n");
    6041             : 
    6042           0 :           fail ("algo %d, digest mismatch\n", algo);
    6043             :         }
    6044             : 
    6045             :     }
    6046             :   else
    6047             :     {
    6048             :       char buf[1000];
    6049           6 :       int outmax = sizeof(buf) > elen ? elen : sizeof(buf);
    6050             : 
    6051           6 :       err = gcry_md_copy (&hd, hd2);
    6052           6 :       if (err)
    6053             :         {
    6054           0 :           fail ("algo %d, gcry_md_copy failed: %s\n", algo, gpg_strerror (err));
    6055             :         }
    6056             : 
    6057           6 :       err = gcry_md_extract(hd2, algo, buf, outmax);
    6058           6 :       if (err)
    6059             :         {
    6060           0 :           fail ("algo %d, gcry_md_extract failed: %s\n", algo, gpg_strerror (err));
    6061             :         }
    6062             : 
    6063           6 :       if (memcmp (buf, expect, outmax))
    6064             :         {
    6065           0 :           printf ("computed: ");
    6066           0 :           for (i = 0; i < outmax; i++)
    6067           0 :             printf ("%02x ", buf[i] & 0xFF);
    6068           0 :           printf ("\nexpected: ");
    6069           0 :           for (i = 0; i < outmax; i++)
    6070           0 :             printf ("%02x ", expect[i] & 0xFF);
    6071           0 :           printf ("\n");
    6072             : 
    6073           0 :           fail ("algo %d, digest mismatch\n", algo);
    6074             :         }
    6075             : 
    6076           6 :       memset(buf, 0, sizeof(buf));
    6077             : 
    6078             :       /* Extract one byte at time. */
    6079        3078 :       for (i = 0; i < outmax && !err; i++)
    6080        3072 :         err = gcry_md_extract(hd, algo, &buf[i], 1);
    6081           6 :       if (err)
    6082             :         {
    6083           0 :           fail ("algo %d, gcry_md_extract failed: %s\n", algo, gpg_strerror (err));
    6084             :         }
    6085             : 
    6086           6 :       if (memcmp (buf, expect, outmax))
    6087             :         {
    6088           0 :           printf ("computed: ");
    6089           0 :           for (i = 0; i < outmax; i++)
    6090           0 :             printf ("%02x ", buf[i] & 0xFF);
    6091           0 :           printf ("\nexpected: ");
    6092           0 :           for (i = 0; i < outmax; i++)
    6093           0 :             printf ("%02x ", expect[i] & 0xFF);
    6094           0 :           printf ("\n");
    6095             : 
    6096           0 :           fail ("algo %d, digest mismatch\n", algo);
    6097             :         }
    6098             : 
    6099           6 :       if (*data == '!' && !data[1])
    6100             :         {
    6101           2 :           int crcalgo = GCRY_MD_RMD160;
    6102             :           gcry_md_hd_t crc1, crc2;
    6103             :           size_t startlen;
    6104             :           size_t piecelen;
    6105             :           size_t left;
    6106             :           const unsigned char *p1, *p2;
    6107             :           int crclen;
    6108             : 
    6109           2 :           crclen = gcry_md_get_algo_dlen (crcalgo);
    6110             : 
    6111           2 :           err = gcry_md_open (&crc1, crcalgo, 0);
    6112           2 :           if (err)
    6113             :             {
    6114           0 :               fail ("algo %d, crcalgo: %d, gcry_md_open failed: %s\n", algo,
    6115             :                     crcalgo, gpg_strerror (err));
    6116           0 :               return;
    6117             :             }
    6118             : 
    6119           2 :           err = gcry_md_open (&crc2, crcalgo, 0);
    6120           2 :           if (err)
    6121             :             {
    6122           0 :               fail ("algo %d, crcalgo: %d, gcry_md_open failed: %s\n", algo,
    6123             :                     crcalgo, gpg_strerror (err));
    6124           0 :               return;
    6125             :             }
    6126             : 
    6127             :           /* Extract large chucks, total 1000000 additional bytes. */
    6128        2002 :           for (i = 0; i < 1000; i++)
    6129             :             {
    6130        2000 :               err = gcry_md_extract(hd, algo, buf, 1000);
    6131        2000 :               if (!err)
    6132        2000 :                 gcry_md_write(crc1, buf, 1000);
    6133             :             }
    6134           2 :           if (err)
    6135             :             {
    6136           0 :               fail ("algo %d, gcry_md_extract failed: %s\n", algo,
    6137             :                     gpg_strerror (err));
    6138             :             }
    6139             : 
    6140             :           /* Extract in odd size chunks, total 1000000 additional bytes.  */
    6141           2 :           left = 1000 * 1000;
    6142           2 :           startlen = 1;
    6143           2 :           piecelen = startlen;
    6144             : 
    6145        3862 :           while (!err && left > 0)
    6146             :             {
    6147        3858 :               if (piecelen > sizeof(buf))
    6148         778 :                 piecelen = sizeof(buf);
    6149        3858 :               if (piecelen > left)
    6150           2 :                 piecelen = left;
    6151             : 
    6152        3858 :               err = gcry_md_extract (hd2, algo, buf, piecelen);
    6153        3858 :               if (!err)
    6154        3858 :                 gcry_md_write(crc2, buf, piecelen);
    6155        3858 :               if (err)
    6156             :                 {
    6157           0 :                   fail ("algo %d, gcry_md_extract failed: %s\n", algo,
    6158             :                         gpg_strerror (err));
    6159             :                 }
    6160             : 
    6161        3858 :               left -= piecelen;
    6162             : 
    6163        3858 :               if (piecelen == sizeof(buf))
    6164         780 :                 piecelen = ++startlen;
    6165             :               else
    6166        3078 :                 piecelen = piecelen * 2 - ((piecelen != startlen) ? startlen : 0);
    6167             :             }
    6168             : 
    6169           2 :           p1 = gcry_md_read (crc1, crcalgo);
    6170           2 :           p2 = gcry_md_read (crc2, crcalgo);
    6171             : 
    6172           2 :           if (memcmp (p1, p2, crclen))
    6173             :             {
    6174           0 :               printf ("computed: ");
    6175           0 :               for (i = 0; i < crclen; i++)
    6176           0 :                 printf ("%02x ", p2[i] & 0xFF);
    6177           0 :               printf ("\nexpected: ");
    6178           0 :               for (i = 0; i < crclen; i++)
    6179           0 :                 printf ("%02x ", p1[i] & 0xFF);
    6180           0 :               printf ("\n");
    6181             : 
    6182           0 :               fail ("algo %d, large xof output mismatch\n", algo);
    6183             :             }
    6184             : 
    6185           2 :           gcry_md_close (crc1);
    6186           2 :           gcry_md_close (crc2);
    6187             :         }
    6188             : 
    6189           6 :       gcry_md_close (hd);
    6190             :     }
    6191             : 
    6192        1162 :   gcry_md_close (hd2);
    6193             : }
    6194             : 
    6195             : 
    6196             : static void
    6197        1162 : check_one_md_multi (int algo, const char *data, int len, const char *expect)
    6198             : {
    6199             :   gpg_error_t err;
    6200             :   gcry_buffer_t iov[3];
    6201             :   int iovcnt;
    6202             :   char digest[64];
    6203             :   int mdlen;
    6204             :   int i;
    6205             : 
    6206        1162 :   mdlen = gcry_md_get_algo_dlen (algo);
    6207        1162 :   if (mdlen < 1 || mdlen > 64)
    6208             :     {
    6209           6 :       if (mdlen == 0 && (algo == GCRY_MD_SHAKE128 || algo == GCRY_MD_SHAKE256))
    6210          46 :         return;
    6211             : 
    6212           0 :       fail ("check_one_md_multi: algo %d, gcry_md_get_algo_dlen failed: %d\n",
    6213             :             algo, mdlen);
    6214           0 :       return;
    6215             :     }
    6216             : 
    6217        1156 :   if (*data == '!' && !data[1])
    6218          18 :     return;  /* We can't do that here.  */
    6219        1138 :   if (*data == '?' && !data[1])
    6220          16 :     return;  /* We can't do that here.  */
    6221             : 
    6222        1122 :   memset (iov, 0, sizeof iov);
    6223             : 
    6224        1122 :   iov[0].data = (void*)data;
    6225        1122 :   if (len)
    6226             :     {
    6227        1103 :       iov[0].len = 1;
    6228        1103 :       len--;
    6229        1103 :       data++;
    6230             :     }
    6231        1122 :   iovcnt = 1;
    6232        1122 :   if (len >= 4)
    6233             :     {
    6234        1058 :       iov[iovcnt].data = (void*)data;
    6235        1058 :       iov[iovcnt].len = 4;
    6236        1058 :       iovcnt++;
    6237        1058 :       data += 4;
    6238        1058 :       len  -= 4;
    6239             :     }
    6240        1122 :   iov[iovcnt].data = (void*)data;
    6241        1122 :   iov[iovcnt].len = len;
    6242        1122 :   iovcnt++;
    6243        1122 :   assert (iovcnt <= DIM (iov));
    6244             : 
    6245        1122 :   err = gcry_md_hash_buffers (algo, 0, digest, iov, iovcnt);
    6246        1122 :   if (err)
    6247             :     {
    6248           0 :       fail ("check_one_md_multi: algo %d, gcry_hash_buffers failed: %s\n",
    6249             :             algo, gpg_strerror (err));
    6250           0 :       return;
    6251             :     }
    6252        1122 :   if (memcmp (digest, expect, mdlen))
    6253             :     {
    6254           0 :       printf ("computed: ");
    6255           0 :       for (i = 0; i < mdlen; i++)
    6256           0 :         printf ("%02x ", digest[i] & 0xFF);
    6257           0 :       printf ("\nexpected: ");
    6258           0 :       for (i = 0; i < mdlen; i++)
    6259           0 :         printf ("%02x ", expect[i] & 0xFF);
    6260           0 :       printf ("\n");
    6261             : 
    6262           0 :       fail ("check_one_md_multi: algo %d, digest mismatch\n", algo);
    6263             :     }
    6264             : }
    6265             : 
    6266             : 
    6267             : static void
    6268           1 : check_digests (void)
    6269             : {
    6270             :   static const struct algos
    6271             :   {
    6272             :     int md;
    6273             :     const char *data;
    6274             :     const char *expect;
    6275             :     int datalen;
    6276             :     int expectlen;
    6277             :   } algos[] =
    6278             :     {
    6279             :       { GCRY_MD_MD2, "",
    6280             :         "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69\x27\x73" },
    6281             :       { GCRY_MD_MD2, "a",
    6282             :         "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0\xb5\xd1" },
    6283             :       { GCRY_MD_MD2, "message digest",
    6284             :         "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe\x06\xb0" },
    6285             :       { GCRY_MD_MD4, "",
    6286             :         "\x31\xD6\xCF\xE0\xD1\x6A\xE9\x31\xB7\x3C\x59\xD7\xE0\xC0\x89\xC0" },
    6287             :       { GCRY_MD_MD4, "a",
    6288             :         "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb\x24" },
    6289             :       { GCRY_MD_MD4, "message digest",
    6290             :         "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01\x4b" },
    6291             :       { GCRY_MD_MD5, "",
    6292             :         "\xD4\x1D\x8C\xD9\x8F\x00\xB2\x04\xE9\x80\x09\x98\xEC\xF8\x42\x7E" },
    6293             :       { GCRY_MD_MD5, "a",
    6294             :         "\x0C\xC1\x75\xB9\xC0\xF1\xB6\xA8\x31\xC3\x99\xE2\x69\x77\x26\x61" },
    6295             :       { GCRY_MD_MD5, "abc",
    6296             :         "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72" },
    6297             :       { GCRY_MD_MD5, "message digest",
    6298             :         "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0" },
    6299             :       { GCRY_MD_MD5,
    6300             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6301             :         "y it under the terms of the GNU Lesser general Public License as"
    6302             :         " published by the Free Software Foundation; either version 2.1 o"
    6303             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6304             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6305             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6306             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6307             :         "ral Public License for more details.",
    6308             :         "\xc4\x1a\x5c\x0b\x44\x5f\xba\x1a\xda\xbc\xc0\x38\x0e\x0c\x9e\x33" },
    6309             :       { GCRY_MD_MD5, "!",
    6310             :         "\x77\x07\xd6\xae\x4e\x02\x7c\x70\xee\xa2\xa9\x35\xc2\x29\x6f\x21" },
    6311             :       { GCRY_MD_MD5, "?",
    6312             :         "\x5c\x72\x5c\xbc\x2d\xbb\xe1\x14\x81\x59\xe9\xd9\xcf\x90\x64\x8f" },
    6313             :       { GCRY_MD_SHA1, "abc",
    6314             :         "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
    6315             :         "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D" },
    6316             :       { GCRY_MD_SHA1,
    6317             :         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
    6318             :         "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE"
    6319             :         "\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1" },
    6320             :       { GCRY_MD_SHA1, "!" /* kludge for "a"*1000000 */ ,
    6321             :         "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E"
    6322             :         "\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F" },
    6323             :       { GCRY_MD_SHA1, "?" /* kludge for "\x00\x01\x02"..."\xfe\xff\x00\x01"... (length 1000000) */ ,
    6324             :         "\x5f\x8d\x3c\x4f\x12\xf0\x49\x9e\x28\x73"
    6325             :         "\x79\xec\x97\x3b\x98\x4c\x94\x75\xaa\x8f" },
    6326             :       { GCRY_MD_SHA1,
    6327             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6328             :         "y it under the terms of the GNU Lesser general Public License as"
    6329             :         " published by the Free Software Foundation; either version 2.1 o"
    6330             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6331             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6332             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6333             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6334             :         "ral Public License for more details.",
    6335             :         "\xf5\xd9\xcb\x66\x91\xb4\x7a\x7c\x60\x35\xe2\x1c\x38\x26\x52\x13"
    6336             :         "\x8e\xd5\xe5\xdf" },
    6337             :       /* From RFC3874 */
    6338             :       { GCRY_MD_SHA224, "abc",
    6339             :         "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55\xb3"
    6340             :         "\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7" },
    6341             :       { GCRY_MD_SHA224,
    6342             :         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
    6343             :         "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01\x50"
    6344             :         "\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25" },
    6345             :       { GCRY_MD_SHA224, "!",
    6346             :         "\x20\x79\x46\x55\x98\x0c\x91\xd8\xbb\xb4\xc1\xea\x97\x61\x8a\x4b"
    6347             :         "\xf0\x3f\x42\x58\x19\x48\xb2\xee\x4e\xe7\xad\x67" },
    6348             :       { GCRY_MD_SHA224, "?",
    6349             :         "\xfa\xb9\xf0\xdf\x12\xfe\xa1\x1a\x34\x78\x96\x31\xe6\x53\x48\xbf"
    6350             :         "\x3b\xca\x70\x78\xf2\x44\xdf\x62\xab\x27\xb8\xda" },
    6351             :       { GCRY_MD_SHA224,
    6352             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6353             :         "y it under the terms of the GNU Lesser general Public License as"
    6354             :         " published by the Free Software Foundation; either version 2.1 o"
    6355             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6356             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6357             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6358             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6359             :         "ral Public License for more details.",
    6360             :         "\x80\xf0\x60\x79\xb0\xe9\x65\xab\x8a\x76\xbf\x6e\x88\x64\x75\xe7"
    6361             :         "\xfd\xf0\xc2\x4c\xf6\xf2\xa6\x01\xed\x50\x71\x08" },
    6362             :       { GCRY_MD_SHA256, "abc",
    6363             :         "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
    6364             :         "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad" },
    6365             :       { GCRY_MD_SHA256,
    6366             :         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
    6367             :         "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
    6368             :         "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" },
    6369             :       { GCRY_MD_SHA256, "!",
    6370             :         "\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67"
    6371             :         "\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0" },
    6372             :       { GCRY_MD_SHA256, "?",
    6373             :         "\x67\x87\x0d\xfc\x9c\x64\xe7\xaa\x27\x0a\x3f\x7e\x80\x51\xae\x65"
    6374             :         "\xd2\x07\xf9\x3f\xc3\xdf\x04\xd7\x57\x2e\x63\x65\xaf\x69\xcd\x0d" },
    6375             :       { GCRY_MD_SHA256,
    6376             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6377             :         "y it under the terms of the GNU Lesser general Public License as"
    6378             :         " published by the Free Software Foundation; either version 2.1 o"
    6379             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6380             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6381             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6382             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6383             :         "ral Public License for more details.",
    6384             :         "\xb0\x18\x70\x67\xb8\xac\x68\x50\xec\x95\x43\x77\xb5\x44\x5b\x0f"
    6385             :         "\x2e\xbd\x40\xc9\xdc\x2a\x2c\x33\x8b\x53\xeb\x3e\x9e\x01\xd7\x02" },
    6386             :       { GCRY_MD_SHA384, "abc",
    6387             :         "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50\x07"
    6388             :         "\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff\x5b\xed"
    6389             :         "\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34\xc8\x25\xa7" },
    6390             :       { GCRY_MD_SHA384,
    6391             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6392             :         "y it under the terms of the GNU Lesser general Public License as"
    6393             :         " published by the Free Software Foundation; either version 2.1 o"
    6394             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6395             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6396             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6397             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6398             :         "ral Public License for more details.",
    6399             :         "\xe4\x6d\xb4\x28\x33\x77\x99\x49\x94\x0f\xcf\x87\xc2\x2f\x30\xd6"
    6400             :         "\x06\x24\x82\x9d\x80\x64\x8a\x07\xa1\x20\x8f\x5f\xf3\x85\xb3\xaa"
    6401             :         "\x39\xb8\x61\x00\xfc\x7f\x18\xc6\x82\x23\x4b\x45\xfa\xf1\xbc\x69" },
    6402             :       { GCRY_MD_SHA384, "!",
    6403             :         "\x9d\x0e\x18\x09\x71\x64\x74\xcb\x08\x6e\x83\x4e\x31\x0a\x4a\x1c"
    6404             :         "\xed\x14\x9e\x9c\x00\xf2\x48\x52\x79\x72\xce\xc5\x70\x4c\x2a\x5b"
    6405             :         "\x07\xb8\xb3\xdc\x38\xec\xc4\xeb\xae\x97\xdd\xd8\x7f\x3d\x89\x85" },
    6406             :       { GCRY_MD_SHA384, "?",
    6407             :         "\xfa\x77\xbb\x86\x3a\xd5\xae\x88\xa9\x9c\x5e\xda\xb5\xc7\xcb\x40"
    6408             :         "\xcd\xf4\x30\xef\xa8\x1b\x23\x7b\xa9\xde\xfd\x81\x12\xf6\x7e\xed"
    6409             :         "\xa7\xd2\x27\x91\xd1\xbc\x76\x44\x57\x59\x71\x11\xe6\x8a\x2c\xde" },
    6410             :       { GCRY_MD_SHA512, "abc",
    6411             :         "\xDD\xAF\x35\xA1\x93\x61\x7A\xBA\xCC\x41\x73\x49\xAE\x20\x41\x31"
    6412             :         "\x12\xE6\xFA\x4E\x89\xA9\x7E\xA2\x0A\x9E\xEE\xE6\x4B\x55\xD3\x9A"
    6413             :         "\x21\x92\x99\x2A\x27\x4F\xC1\xA8\x36\xBA\x3C\x23\xA3\xFE\xEB\xBD"
    6414             :         "\x45\x4D\x44\x23\x64\x3C\xE8\x0E\x2A\x9A\xC9\x4F\xA5\x4C\xA4\x9F" },
    6415             :       { GCRY_MD_SHA512,
    6416             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6417             :         "y it under the terms of the GNU Lesser general Public License as"
    6418             :         " published by the Free Software Foundation; either version 2.1 o"
    6419             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6420             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6421             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6422             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6423             :         "ral Public License for more details.",
    6424             :         "\x72\x8c\xde\xd8\xe4\xd7\xb6\xa5\x0f\xde\x6b\x4d\x33\xaf\x15\x19"
    6425             :         "\xdd\xec\x62\x0f\xf7\x1a\x1e\x10\x32\x05\x02\xa6\xb0\x1f\x70\x37"
    6426             :         "\xbc\xd7\x15\xed\x71\x6c\x78\x20\xc8\x54\x87\xd0\x66\x6a\x17\x83"
    6427             :         "\x05\x61\x92\xbe\xcc\x8f\x3b\xbf\x11\x72\x22\x69\x23\x5b\x48\x5c" },
    6428             :       { GCRY_MD_SHA512, "!",
    6429             :         "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
    6430             :         "\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
    6431             :         "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
    6432             :         "\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b" },
    6433             :       { GCRY_MD_SHA512, "?",
    6434             :         "\x91\xe9\x42\x4e\xa9\xdc\x44\x01\x40\x64\xa4\x5a\x69\xcc\xac\xa3"
    6435             :         "\x74\xee\x78\xeb\x79\x1f\x94\x38\x5b\x73\xef\xf8\xfd\x5d\x74\xd8"
    6436             :         "\x51\x36\xfe\x63\x52\xde\x07\x70\x95\xd6\x78\x2b\x7b\x46\x8a\x2c"
    6437             :         "\x30\x0f\x48\x0c\x74\x43\x06\xdb\xa3\x8d\x64\x3d\xe9\xa1\xa7\x72" },
    6438             :       { GCRY_MD_SHA3_224, "abc",
    6439             :         "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76\x6f"
    6440             :         "\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf" },
    6441             :       { GCRY_MD_SHA3_256, "abc",
    6442             :         "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90\xbd"
    6443             :         "\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43\x15\x32" },
    6444             :       { GCRY_MD_SHA3_384, "abc",
    6445             :         "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad\x8d"
    6446             :         "\xf9\xb4\x73\xcb\x0f\xc0\x8c\x25\x96\xda\x7c\xf0\xe4\x9b\xe4\xb2"
    6447             :         "\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28\x37\x6d\x25" },
    6448             :       { GCRY_MD_SHA3_512, "abc",
    6449             :         "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09\x6e"
    6450             :         "\x08\xf6\x21\x82\x74\x44\xf7\x0d\x88\x4f\x5d\x02\x40\xd2\x71\x2e"
    6451             :         "\x10\xe1\x16\xe9\x19\x2a\xf3\xc9\x1a\x7e\xc5\x76\x47\xe3\x93\x40"
    6452             :         "\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27\x4e\xec\x53\xf0" },
    6453             :       { GCRY_MD_SHA3_224, "",
    6454             :         "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1\xab"
    6455             :         "\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7" },
    6456             :       { GCRY_MD_SHA3_256, "",
    6457             :         "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6\x62"
    6458             :         "\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8\x43\x4a" },
    6459             :       { GCRY_MD_SHA3_384, "",
    6460             :         "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24\x85"
    6461             :         "\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98\x3a\x2a"
    6462             :         "\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58\xd5\xf0\x04" },
    6463             :       { GCRY_MD_SHA3_512, "",
    6464             :         "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75\x6e"
    6465             :         "\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c\x80\xa6"
    6466             :         "\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c\x11\xe3\xe9\x40\x2c\x3a\xc5\x58"
    6467             :         "\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86\x28\x1d\xcd\x26" },
    6468             :       { GCRY_MD_SHA3_224, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlm"
    6469             :         "nomnopnopq",
    6470             :         "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79\xba"
    6471             :         "\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33" },
    6472             :       { GCRY_MD_SHA3_256, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlm"
    6473             :         "nomnopnopq",
    6474             :         "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e\x2c"
    6475             :         "\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d\x33\x76" },
    6476             :       { GCRY_MD_SHA3_384, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlm"
    6477             :         "nomnopnopq",
    6478             :         "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49\x2e"
    6479             :         "\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd\xbc\x32\xb9\xd4\xad\x5a"
    6480             :         "\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22" },
    6481             :       { GCRY_MD_SHA3_512, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlm"
    6482             :         "nomnopnopq",
    6483             :         "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8\x18"
    6484             :         "\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7\xec\x2f\x1e\x91\x63\x6d"
    6485             :         "\xee\x69\x1f\xbe\x0c\x98\x53\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63"
    6486             :         "\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e" },
    6487             :       { GCRY_MD_SHA3_224, "abcdefghbcdefghicdefghijdefghijkefghijklfghijk"
    6488             :         "lmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
    6489             :         "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a\xe5"
    6490             :         "\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc" },
    6491             :       { GCRY_MD_SHA3_256, "abcdefghbcdefghicdefghijdefghijkefghijklfghijk"
    6492             :         "lmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
    6493             :         "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf\xdb"
    6494             :         "\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad\x1d\x18" },
    6495             :       { GCRY_MD_SHA3_384, "abcdefghbcdefghicdefghijdefghijkefghijklfghijk"
    6496             :         "lmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
    6497             :         "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47\x91"
    6498             :         "\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6\x25\xdc"
    6499             :         "\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79\xaa\x7f\xc7" },
    6500             :       { GCRY_MD_SHA3_512, "abcdefghbcdefghicdefghijdefghijkefghijklfghijk"
    6501             :         "lmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
    6502             :         "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78\xf9"
    6503             :         "\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18\xa4\xfa"
    6504             :         "\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8\x2e\x21\x89"
    6505             :         "\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55\xf2\x1d\xd1\x85" },
    6506             :       { GCRY_MD_SHA3_224, "!",
    6507             :         "\xd6\x93\x35\xb9\x33\x25\x19\x2e\x51\x6a\x91\x2e\x6d\x19\xa1\x5c"
    6508             :         "\xb5\x1c\x6e\xd5\xc1\x52\x43\xe7\xa7\xfd\x65\x3c" },
    6509             :       { GCRY_MD_SHA3_256, "!",
    6510             :         "\x5c\x88\x75\xae\x47\x4a\x36\x34\xba\x4f\xd5\x5e\xc8\x5b\xff\xd6"
    6511             :         "\x61\xf3\x2a\xca\x75\xc6\xd6\x99\xd0\xcd\xcb\x6c\x11\x58\x91\xc1" },
    6512             :       { GCRY_MD_SHA3_384, "!",
    6513             :         "\xee\xe9\xe2\x4d\x78\xc1\x85\x53\x37\x98\x34\x51\xdf\x97\xc8\xad"
    6514             :         "\x9e\xed\xf2\x56\xc6\x33\x4f\x8e\x94\x8d\x25\x2d\x5e\x0e\x76\x84"
    6515             :         "\x7a\xa0\x77\x4d\xdb\x90\xa8\x42\x19\x0d\x2c\x55\x8b\x4b\x83\x40" },
    6516             :       { GCRY_MD_SHA3_512, "!",
    6517             :         "\x3c\x3a\x87\x6d\xa1\x40\x34\xab\x60\x62\x7c\x07\x7b\xb9\x8f\x7e"
    6518             :         "\x12\x0a\x2a\x53\x70\x21\x2d\xff\xb3\x38\x5a\x18\xd4\xf3\x88\x59"
    6519             :         "\xed\x31\x1d\x0a\x9d\x51\x41\xce\x9c\xc5\xc6\x6e\xe6\x89\xb2\x66"
    6520             :         "\xa8\xaa\x18\xac\xe8\x28\x2a\x0e\x0d\xb5\x96\xc9\x0b\x0a\x7b\x87" },
    6521             :       { GCRY_MD_SHA3_224, "?",
    6522             :         "\x1b\xd1\xc6\x12\x02\x35\x52\x8b\x44\x7e\x16\x39\x20\x05\xec\x67"
    6523             :         "\x2d\x57\x20\xe0\x90\xc9\x78\x08\x86\x4f\x1b\xd0" },
    6524             :       { GCRY_MD_SHA3_256, "?",
    6525             :         "\xfe\xb7\xf4\x76\x78\x97\x48\x2f\xe2\x29\x1b\x66\x85\xc1\x7b\x45"
    6526             :         "\xc5\x08\xed\x82\x50\xcc\x5d\x99\x96\xd2\xc3\x82\x1a\xa8\xd4\xa7" },
    6527             :       { GCRY_MD_SHA3_384, "?",
    6528             :         "\x45\x1f\x0b\x93\x4b\xca\x3e\x65\x93\xd4\xaa\x8c\x18\xc1\x04\x84"
    6529             :         "\x12\xd5\x1e\x35\xe1\x05\xd9\x77\x3f\xc1\x08\x8b\x77\x36\xad\x4a"
    6530             :         "\x33\x70\xaf\x49\x8b\xea\x4c\x5c\x52\xe7\x5b\xed\x31\x74\x57\x12" },
    6531             :       { GCRY_MD_SHA3_512, "?",
    6532             :         "\xa2\xee\xb5\x6f\x2a\x87\xa5\xb3\x9b\xd9\x1c\xf0\xaa\xdf\xb1\xd5"
    6533             :         "\xad\x0a\x1a\xaa\xd3\x63\x81\xcf\xb8\x7c\x36\xa7\x80\x3b\x03\xd6"
    6534             :         "\x31\x5c\x5d\x33\x8e\x52\xb1\x42\x4d\x27\x1c\xa2\xa5\xf2\xc5\x97"
    6535             :         "\x10\x12\xe5\xee\x86\xa3\xcc\xaf\x91\x7a\x94\x28\x65\xea\x66\xe3" },
    6536             :       { GCRY_MD_RMD160, "",
    6537             :         "\x9c\x11\x85\xa5\xc5\xe9\xfc\x54\x61\x28"
    6538             :         "\x08\x97\x7e\xe8\xf5\x48\xb2\x25\x8d\x31" },
    6539             :       { GCRY_MD_RMD160, "a",
    6540             :         "\x0b\xdc\x9d\x2d\x25\x6b\x3e\xe9\xda\xae"
    6541             :         "\x34\x7b\xe6\xf4\xdc\x83\x5a\x46\x7f\xfe" },
    6542             :       { GCRY_MD_RMD160, "abc",
    6543             :         "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04"
    6544             :         "\x4a\x8e\x98\xc6\xb0\x87\xf1\x5a\x0b\xfc" },
    6545             :       { GCRY_MD_RMD160, "message digest",
    6546             :         "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8"
    6547             :         "\x81\xb1\x23\xa8\x5f\xfa\x21\x59\x5f\x36" },
    6548             :       { GCRY_MD_RMD160,
    6549             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6550             :         "y it under the terms of the GNU Lesser general Public License as"
    6551             :         " published by the Free Software Foundation; either version 2.1 o"
    6552             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6553             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6554             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6555             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6556             :         "ral Public License for more details.",
    6557             :         "\x06\x6d\x3c\x4e\xc9\xba\x89\x75\x16\x90\x96\x4e\xfd\x43\x07\xde"
    6558             :         "\x04\xca\x69\x6b" },
    6559             :       { GCRY_MD_RMD160, "!",
    6560             :         "\x52\x78\x32\x43\xc1\x69\x7b\xdb\xe1\x6d\x37\xf9\x7f\x68\xf0\x83"
    6561             :         "\x25\xdc\x15\x28" },
    6562             :       { GCRY_MD_RMD160, "?",
    6563             :         "\x68\x14\x86\x70\x3d\x51\x4e\x36\x68\x50\xf8\xb3\x00\x75\xda\x49"
    6564             :         "\x0a\xaa\x2c\xf6" },
    6565             :       { GCRY_MD_CRC32, "", "\x00\x00\x00\x00" },
    6566             :       { GCRY_MD_CRC32, "foo", "\x8c\x73\x65\x21" },
    6567             :       { GCRY_MD_CRC32,
    6568             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6569             :         "y it under the terms of the GNU Lesser general Public License as"
    6570             :         " published by the Free Software Foundation; either version 2.1 o"
    6571             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6572             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6573             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6574             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6575             :         "ral Public License for more details.",
    6576             :         "\x4A\x53\x7D\x67" },
    6577             :       { GCRY_MD_CRC32, "123456789", "\xcb\xf4\x39\x26" },
    6578             :       { GCRY_MD_CRC32, "!", "\xdc\x25\xbf\xbc" },
    6579             :       { GCRY_MD_CRC32, "?", "\x61\x82\x29\x1B" },
    6580             :       { GCRY_MD_CRC32_RFC1510, "", "\x00\x00\x00\x00" },
    6581             :       { GCRY_MD_CRC32_RFC1510, "foo", "\x73\x32\xbc\x33" },
    6582             :       { GCRY_MD_CRC32_RFC1510, "test0123456789", "\xb8\x3e\x88\xd6" },
    6583             :       { GCRY_MD_CRC32_RFC1510, "MASSACHVSETTS INSTITVTE OF TECHNOLOGY",
    6584             :         "\xe3\x41\x80\xf7" },
    6585             :       { GCRY_MD_CRC32_RFC1510, "\x80\x00", "\x3b\x83\x98\x4b", 2 },
    6586             :       { GCRY_MD_CRC32_RFC1510, "\x00\x08", "\x0e\xdb\x88\x32", 2 },
    6587             :       { GCRY_MD_CRC32_RFC1510, "\x00\x80", "\xed\xb8\x83\x20", 2 },
    6588             :       { GCRY_MD_CRC32_RFC1510, "\x80", "\xed\xb8\x83\x20" },
    6589             :       { GCRY_MD_CRC32_RFC1510, "\x80\x00\x00\x00", "\xed\x59\xb6\x3b", 4 },
    6590             :       { GCRY_MD_CRC32_RFC1510, "\x00\x00\x00\x01", "\x77\x07\x30\x96", 4 },
    6591             :       { GCRY_MD_CRC32_RFC1510, "123456789", "\x2d\xfd\x2d\x88" },
    6592             :       { GCRY_MD_CRC32_RFC1510, "!", "\xce\x5c\x74\x22" },
    6593             :       { GCRY_MD_CRC32_RFC1510, "?", "\x73\xfb\xe2\x85" },
    6594             :       { GCRY_MD_CRC24_RFC2440, "", "\xb7\x04\xce" },
    6595             :       { GCRY_MD_CRC24_RFC2440, "foo", "\x4f\xc2\x55" },
    6596             :       { GCRY_MD_CRC24_RFC2440, "123456789", "\x21\xcf\x02" },
    6597             :       { GCRY_MD_CRC24_RFC2440, "!", "\xa5\xcb\x6b" },
    6598             :       { GCRY_MD_CRC24_RFC2440, "?", "\x7f\x67\x03" },
    6599             : 
    6600             :       { GCRY_MD_TIGER, "",
    6601             :         "\x24\xF0\x13\x0C\x63\xAC\x93\x32\x16\x16\x6E\x76"
    6602             :         "\xB1\xBB\x92\x5F\xF3\x73\xDE\x2D\x49\x58\x4E\x7A" },
    6603             :       { GCRY_MD_TIGER, "abc",
    6604             :         "\xF2\x58\xC1\xE8\x84\x14\xAB\x2A\x52\x7A\xB5\x41"
    6605             :         "\xFF\xC5\xB8\xBF\x93\x5F\x7B\x95\x1C\x13\x29\x51" },
    6606             :       { GCRY_MD_TIGER, "Tiger",
    6607             :         "\x9F\x00\xF5\x99\x07\x23\x00\xDD\x27\x6A\xBB\x38"
    6608             :         "\xC8\xEB\x6D\xEC\x37\x79\x0C\x11\x6F\x9D\x2B\xDF" },
    6609             :       { GCRY_MD_TIGER, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg"
    6610             :         "hijklmnopqrstuvwxyz0123456789+-",
    6611             :         "\x87\xFB\x2A\x90\x83\x85\x1C\xF7\x47\x0D\x2C\xF8"
    6612             :         "\x10\xE6\xDF\x9E\xB5\x86\x44\x50\x34\xA5\xA3\x86" },
    6613             :       { GCRY_MD_TIGER, "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdef"
    6614             :         "ghijklmnopqrstuvwxyz+0123456789",
    6615             :         "\x46\x7D\xB8\x08\x63\xEB\xCE\x48\x8D\xF1\xCD\x12"
    6616             :         "\x61\x65\x5D\xE9\x57\x89\x65\x65\x97\x5F\x91\x97" },
    6617             :       { GCRY_MD_TIGER, "Tiger - A Fast New Hash Function, "
    6618             :         "by Ross Anderson and Eli Biham",
    6619             :         "\x0C\x41\x0A\x04\x29\x68\x86\x8A\x16\x71\xDA\x5A"
    6620             :         "\x3F\xD2\x9A\x72\x5E\xC1\xE4\x57\xD3\xCD\xB3\x03" },
    6621             :       { GCRY_MD_TIGER, "Tiger - A Fast New Hash Function, "
    6622             :         "by Ross Anderson and Eli Biham, proceedings of Fa"
    6623             :         "st Software Encryption 3, Cambridge.",
    6624             :         "\xEB\xF5\x91\xD5\xAF\xA6\x55\xCE\x7F\x22\x89\x4F"
    6625             :         "\xF8\x7F\x54\xAC\x89\xC8\x11\xB6\xB0\xDA\x31\x93" },
    6626             :       { GCRY_MD_TIGER, "Tiger - A Fast New Hash Function, "
    6627             :         "by Ross Anderson and Eli Biham, proceedings of Fa"
    6628             :         "st Software Encryption 3, Cambridge, 1996.",
    6629             :         "\x3D\x9A\xEB\x03\xD1\xBD\x1A\x63\x57\xB2\x77\x4D"
    6630             :         "\xFD\x6D\x5B\x24\xDD\x68\x15\x1D\x50\x39\x74\xFC" },
    6631             :       { GCRY_MD_TIGER, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgh"
    6632             :         "ijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRS"
    6633             :         "TUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-",
    6634             :         "\x00\xB8\x3E\xB4\xE5\x34\x40\xC5\x76\xAC\x6A\xAE"
    6635             :         "\xE0\xA7\x48\x58\x25\xFD\x15\xE7\x0A\x59\xFF\xE4" },
    6636             : 
    6637             :       { GCRY_MD_TIGER1, "",
    6638             :         "\x32\x93\xAC\x63\x0C\x13\xF0\x24\x5F\x92\xBB\xB1"
    6639             :         "\x76\x6E\x16\x16\x7A\x4E\x58\x49\x2D\xDE\x73\xF3" },
    6640             :       { GCRY_MD_TIGER1, "a",
    6641             :         "\x77\xBE\xFB\xEF\x2E\x7E\xF8\xAB\x2E\xC8\xF9\x3B"
    6642             :         "\xF5\x87\xA7\xFC\x61\x3E\x24\x7F\x5F\x24\x78\x09" },
    6643             :       { GCRY_MD_TIGER1, "abc",
    6644             :         "\x2A\xAB\x14\x84\xE8\xC1\x58\xF2\xBF\xB8\xC5\xFF"
    6645             :         "\x41\xB5\x7A\x52\x51\x29\x13\x1C\x95\x7B\x5F\x93" },
    6646             :       { GCRY_MD_TIGER1, "message digest",
    6647             :         "\xD9\x81\xF8\xCB\x78\x20\x1A\x95\x0D\xCF\x30\x48"
    6648             :         "\x75\x1E\x44\x1C\x51\x7F\xCA\x1A\xA5\x5A\x29\xF6" },
    6649             :       { GCRY_MD_TIGER1, "abcdefghijklmnopqrstuvwxyz",
    6650             :         "\x17\x14\xA4\x72\xEE\xE5\x7D\x30\x04\x04\x12\xBF"
    6651             :         "\xCC\x55\x03\x2A\x0B\x11\x60\x2F\xF3\x7B\xEE\xE9" },
    6652             :       { GCRY_MD_TIGER1,
    6653             :         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
    6654             :         "\x0F\x7B\xF9\xA1\x9B\x9C\x58\xF2\xB7\x61\x0D\xF7"
    6655             :         "\xE8\x4F\x0A\xC3\xA7\x1C\x63\x1E\x7B\x53\xF7\x8E" },
    6656             :       { GCRY_MD_TIGER1,
    6657             :         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    6658             :         "abcdefghijklmnopqrstuvwxyz" "0123456789",
    6659             :         "\x8D\xCE\xA6\x80\xA1\x75\x83\xEE\x50\x2B\xA3\x8A"
    6660             :         "\x3C\x36\x86\x51\x89\x0F\xFB\xCC\xDC\x49\xA8\xCC" },
    6661             :       { GCRY_MD_TIGER1,
    6662             :         "1234567890" "1234567890" "1234567890" "1234567890"
    6663             :         "1234567890" "1234567890" "1234567890" "1234567890",
    6664             :         "\x1C\x14\x79\x55\x29\xFD\x9F\x20\x7A\x95\x8F\x84"
    6665             :         "\xC5\x2F\x11\xE8\x87\xFA\x0C\xAB\xDF\xD9\x1B\xFD" },
    6666             :       { GCRY_MD_TIGER1, "!",
    6667             :         "\x6D\xB0\xE2\x72\x9C\xBE\xAD\x93\xD7\x15\xC6\xA7"
    6668             :         "\xD3\x63\x02\xE9\xB3\xCE\xE0\xD2\xBC\x31\x4B\x41" },
    6669             :       { GCRY_MD_TIGER1,
    6670             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6671             :         "y it under the terms of the GNU Lesser general Public License as"
    6672             :         " published by the Free Software Foundation; either version 2.1 o"
    6673             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6674             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6675             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6676             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6677             :         "ral Public License for more details.",
    6678             :         "\x60\xee\xdf\x95\x39\xc8\x44\x94\x64\xdc\xdf\x3d\x2e\x1c\xe5\x79"
    6679             :         "\x6a\x95\xbd\x30\x68\x8c\x7e\xb8" },
    6680             :       { GCRY_MD_TIGER1, "?",
    6681             :         "\x4b\xe2\x3f\x23\xf5\x34\xbe\xbf\x97\x42\x95\x80"
    6682             :         "\x54\xe4\x6c\x12\x64\x85\x44\x0a\xa9\x49\x9b\x65" },
    6683             : 
    6684             :       { GCRY_MD_TIGER2, "",
    6685             :         "\x44\x41\xBE\x75\xF6\x01\x87\x73\xC2\x06\xC2\x27"
    6686             :         "\x45\x37\x4B\x92\x4A\xA8\x31\x3F\xEF\x91\x9F\x41" },
    6687             :       { GCRY_MD_TIGER2, "a",
    6688             :         "\x67\xE6\xAE\x8E\x9E\x96\x89\x99\xF7\x0A\x23\xE7"
    6689             :         "\x2A\xEA\xA9\x25\x1C\xBC\x7C\x78\xA7\x91\x66\x36" },
    6690             :       { GCRY_MD_TIGER2, "abc",
    6691             :         "\xF6\x8D\x7B\xC5\xAF\x4B\x43\xA0\x6E\x04\x8D\x78"
    6692             :         "\x29\x56\x0D\x4A\x94\x15\x65\x8B\xB0\xB1\xF3\xBF" },
    6693             :       { GCRY_MD_TIGER2, "message digest",
    6694             :         "\xE2\x94\x19\xA1\xB5\xFA\x25\x9D\xE8\x00\x5E\x7D"
    6695             :         "\xE7\x50\x78\xEA\x81\xA5\x42\xEF\x25\x52\x46\x2D" },
    6696             :       { GCRY_MD_TIGER2, "abcdefghijklmnopqrstuvwxyz",
    6697             :         "\xF5\xB6\xB6\xA7\x8C\x40\x5C\x85\x47\xE9\x1C\xD8"
    6698             :         "\x62\x4C\xB8\xBE\x83\xFC\x80\x4A\x47\x44\x88\xFD" },
    6699             :       { GCRY_MD_TIGER2,
    6700             :         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
    6701             :         "\xA6\x73\x7F\x39\x97\xE8\xFB\xB6\x3D\x20\xD2\xDF"
    6702             :         "\x88\xF8\x63\x76\xB5\xFE\x2D\x5C\xE3\x66\x46\xA9" },
    6703             :       { GCRY_MD_TIGER2,
    6704             :         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    6705             :         "abcdefghijklmnopqrstuvwxyz" "0123456789",
    6706             :         "\xEA\x9A\xB6\x22\x8C\xEE\x7B\x51\xB7\x75\x44\xFC"
    6707             :         "\xA6\x06\x6C\x8C\xBB\x5B\xBA\xE6\x31\x95\x05\xCD" },
    6708             :       { GCRY_MD_TIGER2,
    6709             :         "1234567890" "1234567890" "1234567890" "1234567890"
    6710             :         "1234567890" "1234567890" "1234567890" "1234567890",
    6711             :         "\xD8\x52\x78\x11\x53\x29\xEB\xAA\x0E\xEC\x85\xEC"
    6712             :         "\xDC\x53\x96\xFD\xA8\xAA\x3A\x58\x20\x94\x2F\xFF" },
    6713             :       { GCRY_MD_TIGER2, "!",
    6714             :         "\xE0\x68\x28\x1F\x06\x0F\x55\x16\x28\xCC\x57\x15"
    6715             :         "\xB9\xD0\x22\x67\x96\x91\x4D\x45\xF7\x71\x7C\xF4" },
    6716             : 
    6717             :       { GCRY_MD_WHIRLPOOL, "",
    6718             :         "\x19\xFA\x61\xD7\x55\x22\xA4\x66\x9B\x44\xE3\x9C\x1D\x2E\x17\x26"
    6719             :         "\xC5\x30\x23\x21\x30\xD4\x07\xF8\x9A\xFE\xE0\x96\x49\x97\xF7\xA7"
    6720             :         "\x3E\x83\xBE\x69\x8B\x28\x8F\xEB\xCF\x88\xE3\xE0\x3C\x4F\x07\x57"
    6721             :         "\xEA\x89\x64\xE5\x9B\x63\xD9\x37\x08\xB1\x38\xCC\x42\xA6\x6E\xB3" },
    6722             :       { GCRY_MD_WHIRLPOOL, "a",
    6723             :         "\x8A\xCA\x26\x02\x79\x2A\xEC\x6F\x11\xA6\x72\x06\x53\x1F\xB7\xD7"
    6724             :         "\xF0\xDF\xF5\x94\x13\x14\x5E\x69\x73\xC4\x50\x01\xD0\x08\x7B\x42"
    6725             :         "\xD1\x1B\xC6\x45\x41\x3A\xEF\xF6\x3A\x42\x39\x1A\x39\x14\x5A\x59"
    6726             :         "\x1A\x92\x20\x0D\x56\x01\x95\xE5\x3B\x47\x85\x84\xFD\xAE\x23\x1A" },
    6727             :       { GCRY_MD_WHIRLPOOL, "?",
    6728             :         "\x88\xf0\x78\x6d\x0d\x47\xe5\x32\x1f\x88\xb1\x48\x05\x53\x58\x7d"
    6729             :         "\x19\x4b\x32\x9b\xf1\xfb\x17\xc5\x98\x3a\x87\xa2\x48\x61\x3d\x2b"
    6730             :         "\xb2\xbc\x9f\x0d\xd2\x14\x37\x30\x55\x30\x91\xa7\xb8\x0c\x0f\x80"
    6731             :         "\x7c\x7b\x94\xf6\x55\xf6\x0b\x12\x85\x0c\x8e\x6d\x17\x5b\x1e\x71" },
    6732             :       { GCRY_MD_WHIRLPOOL,
    6733             :         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
    6734             :         "\xDC\x37\xE0\x08\xCF\x9E\xE6\x9B\xF1\x1F\x00\xED\x9A\xBA\x26\x90"
    6735             :         "\x1D\xD7\xC2\x8C\xDE\xC0\x66\xCC\x6A\xF4\x2E\x40\xF8\x2F\x3A\x1E"
    6736             :         "\x08\xEB\xA2\x66\x29\x12\x9D\x8F\xB7\xCB\x57\x21\x1B\x92\x81\xA6"
    6737             :         "\x55\x17\xCC\x87\x9D\x7B\x96\x21\x42\xC6\x5F\x5A\x7A\xF0\x14\x67" },
    6738             :       { GCRY_MD_WHIRLPOOL,
    6739             :         "!",
    6740             :         "\x0C\x99\x00\x5B\xEB\x57\xEF\xF5\x0A\x7C\xF0\x05\x56\x0D\xDF\x5D"
    6741             :         "\x29\x05\x7F\xD8\x6B\x20\xBF\xD6\x2D\xEC\xA0\xF1\xCC\xEA\x4A\xF5"
    6742             :         "\x1F\xC1\x54\x90\xED\xDC\x47\xAF\x32\xBB\x2B\x66\xC3\x4F\xF9\xAD"
    6743             :         "\x8C\x60\x08\xAD\x67\x7F\x77\x12\x69\x53\xB2\x26\xE4\xED\x8B\x01" },
    6744             :       { GCRY_MD_WHIRLPOOL,
    6745             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6746             :         "y it under the terms of the GNU Lesser general Public License as"
    6747             :         " published by the Free Software Foundation; either version 2.1 o"
    6748             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6749             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6750             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6751             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6752             :         "ral Public License for more details.",
    6753             :         "\xcd\x4a\xa4\xaf\xf6\x7f\xec\xce\xbb\x6c\xdf\x91\x96\xe1\xf3\xf6"
    6754             :         "\x78\xe2\x8e\x3a\x76\xcf\x06\xc7\xa1\x20\x7b\x81\x32\x60\xf7\x8e"
    6755             :         "\x68\x19\x62\x33\x4f\xe5\x0a\x24\xfb\x9e\x74\x03\x74\xe4\x61\x29"
    6756             :         "\x6f\xb3\x13\xe6\x7e\xc2\x88\x99\x9e\xfb\xe7\x9d\x11\x30\x89\xd2" },
    6757             :       { GCRY_MD_GOSTR3411_94,
    6758             :         "This is message, length=32 bytes",
    6759             :         "\xB1\xC4\x66\xD3\x75\x19\xB8\x2E\x83\x19\x81\x9F\xF3\x25\x95\xE0"
    6760             :         "\x47\xA2\x8C\xB6\xF8\x3E\xFF\x1C\x69\x16\xA8\x15\xA6\x37\xFF\xFA" },
    6761             :       { GCRY_MD_GOSTR3411_94,
    6762             :         "Suppose the original message has length = 50 bytes",
    6763             :         "\x47\x1A\xBA\x57\xA6\x0A\x77\x0D\x3A\x76\x13\x06\x35\xC1\xFB\xEA"
    6764             :         "\x4E\xF1\x4D\xE5\x1F\x78\xB4\xAE\x57\xDD\x89\x3B\x62\xF5\x52\x08" },
    6765             :       { GCRY_MD_GOSTR3411_94,
    6766             :         "",
    6767             :         "\xCE\x85\xB9\x9C\xC4\x67\x52\xFF\xFE\xE3\x5C\xAB\x9A\x7B\x02\x78"
    6768             :         "\xAB\xB4\xC2\xD2\x05\x5C\xFF\x68\x5A\xF4\x91\x2C\x49\x49\x0F\x8D" },
    6769             :       { GCRY_MD_GOSTR3411_94,
    6770             :         "!",
    6771             :         "\x5C\x00\xCC\xC2\x73\x4C\xDD\x33\x32\xD3\xD4\x74\x95\x76\xE3\xC1"
    6772             :         "\xA7\xDB\xAF\x0E\x7E\xA7\x4E\x9F\xA6\x02\x41\x3C\x90\xA1\x29\xFA" },
    6773             :       { GCRY_MD_GOSTR3411_94,
    6774             :         "Libgcrypt is free software; you can redistribute it and/or modif"
    6775             :         "y it under the terms of the GNU Lesser general Public License as"
    6776             :         " published by the Free Software Foundation; either version 2.1 o"
    6777             :         "f the License, or (at your option) any later version.\nLibgcrypt"
    6778             :         " is distributed in the hope that it will be useful, but WITHOUT "
    6779             :         "ANY WARRANTY; without even the implied warranty of MERCHANTABILI"
    6780             :         "TY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Gene"
    6781             :         "ral Public License for more details.",
    6782             :         "\x00\x0c\x85\xc8\x54\xd2\x9a\x6e\x47\x2e\xff\xa4\xa2\xe7\xd0\x2e"
    6783             :         "\x8a\xcc\x14\x53\xb4\x87\xc8\x5c\x95\x9a\x3e\x85\x8c\x7d\x6e\x0c" },
    6784             :       { GCRY_MD_STRIBOG512,
    6785             :         "012345678901234567890123456789012345678901234567890123456789012",
    6786             :         "\x1b\x54\xd0\x1a\x4a\xf5\xb9\xd5\xcc\x3d\x86\xd6\x8d\x28\x54\x62"
    6787             :         "\xb1\x9a\xbc\x24\x75\x22\x2f\x35\xc0\x85\x12\x2b\xe4\xba\x1f\xfa"
    6788             :         "\x00\xad\x30\xf8\x76\x7b\x3a\x82\x38\x4c\x65\x74\xf0\x24\xc3\x11"
    6789             :         "\xe2\xa4\x81\x33\x2b\x08\xef\x7f\x41\x79\x78\x91\xc1\x64\x6f\x48" },
    6790             :       { GCRY_MD_STRIBOG256,
    6791             :         "012345678901234567890123456789012345678901234567890123456789012",
    6792             :         "\x9d\x15\x1e\xef\xd8\x59\x0b\x89\xda\xa6\xba\x6c\xb7\x4a\xf9\x27"
    6793             :         "\x5d\xd0\x51\x02\x6b\xb1\x49\xa4\x52\xfd\x84\xe5\xe5\x7b\x55\x00" },
    6794             :       { GCRY_MD_STRIBOG512,
    6795             :         "\xd1\xe5\x20\xe2\xe5\xf2\xf0\xe8\x2c\x20\xd1\xf2\xf0\xe8\xe1\xee"
    6796             :         "\xe6\xe8\x20\xe2\xed\xf3\xf6\xe8\x2c\x20\xe2\xe5\xfe\xf2\xfa\x20"
    6797             :         "\xf1\x20\xec\xee\xf0\xff\x20\xf1\xf2\xf0\xe5\xeb\xe0\xec\xe8\x20"
    6798             :         "\xed\xe0\x20\xf5\xf0\xe0\xe1\xf0\xfb\xff\x20\xef\xeb\xfa\xea\xfb"
    6799             :         "\x20\xc8\xe3\xee\xf0\xe5\xe2\xfb",
    6800             :         "\x1e\x88\xe6\x22\x26\xbf\xca\x6f\x99\x94\xf1\xf2\xd5\x15\x69\xe0"
    6801             :         "\xda\xf8\x47\x5a\x3b\x0f\xe6\x1a\x53\x00\xee\xe4\x6d\x96\x13\x76"
    6802             :         "\x03\x5f\xe8\x35\x49\xad\xa2\xb8\x62\x0f\xcd\x7c\x49\x6c\xe5\xb3"
    6803             :         "\x3f\x0c\xb9\xdd\xdc\x2b\x64\x60\x14\x3b\x03\xda\xba\xc9\xfb\x28" },
    6804             :       { GCRY_MD_STRIBOG256,
    6805             :         "\xd1\xe5\x20\xe2\xe5\xf2\xf0\xe8\x2c\x20\xd1\xf2\xf0\xe8\xe1\xee"
    6806             :         "\xe6\xe8\x20\xe2\xed\xf3\xf6\xe8\x2c\x20\xe2\xe5\xfe\xf2\xfa\x20"
    6807             :         "\xf1\x20\xec\xee\xf0\xff\x20\xf1\xf2\xf0\xe5\xeb\xe0\xec\xe8\x20"
    6808             :         "\xed\xe0\x20\xf5\xf0\xe0\xe1\xf0\xfb\xff\x20\xef\xeb\xfa\xea\xfb"
    6809             :         "\x20\xc8\xe3\xee\xf0\xe5\xe2\xfb",
    6810             :         "\x9d\xd2\xfe\x4e\x90\x40\x9e\x5d\xa8\x7f\x53\x97\x6d\x74\x05\xb0"
    6811             :         "\xc0\xca\xc6\x28\xfc\x66\x9a\x74\x1d\x50\x06\x3c\x55\x7e\x8f\x50" },
    6812             : #include "./sha3-224.h"
    6813             : #include "./sha3-256.h"
    6814             : #include "./sha3-384.h"
    6815             : #include "./sha3-512.h"
    6816             :       { GCRY_MD_SHAKE128,
    6817             :         "",
    6818             :         "\x7F\x9C\x2B\xA4\xE8\x8F\x82\x7D\x61\x60\x45\x50\x76\x05\x85\x3E"
    6819             :         "\xD7\x3B\x80\x93\xF6\xEF\xBC\x88\xEB\x1A\x6E\xAC\xFA\x66\xEF\x26"
    6820             :         "\x3C\xB1\xEE\xA9\x88\x00\x4B\x93\x10\x3C\xFB\x0A\xEE\xFD\x2A\x68"
    6821             :         "\x6E\x01\xFA\x4A\x58\xE8\xA3\x63\x9C\xA8\xA1\xE3\xF9\xAE\x57\xE2"
    6822             :         "\x35\xB8\xCC\x87\x3C\x23\xDC\x62\xB8\xD2\x60\x16\x9A\xFA\x2F\x75"
    6823             :         "\xAB\x91\x6A\x58\xD9\x74\x91\x88\x35\xD2\x5E\x6A\x43\x50\x85\xB2"
    6824             :         "\xBA\xDF\xD6\xDF\xAA\xC3\x59\xA5\xEF\xBB\x7B\xCC\x4B\x59\xD5\x38"
    6825             :         "\xDF\x9A\x04\x30\x2E\x10\xC8\xBC\x1C\xBF\x1A\x0B\x3A\x51\x20\xEA"
    6826             :         "\x17\xCD\xA7\xCF\xAD\x76\x5F\x56\x23\x47\x4D\x36\x8C\xCC\xA8\xAF"
    6827             :         "\x00\x07\xCD\x9F\x5E\x4C\x84\x9F\x16\x7A\x58\x0B\x14\xAA\xBD\xEF"
    6828             :         "\xAE\xE7\xEE\xF4\x7C\xB0\xFC\xA9\x76\x7B\xE1\xFD\xA6\x94\x19\xDF"
    6829             :         "\xB9\x27\xE9\xDF\x07\x34\x8B\x19\x66\x91\xAB\xAE\xB5\x80\xB3\x2D"
    6830             :         "\xEF\x58\x53\x8B\x8D\x23\xF8\x77\x32\xEA\x63\xB0\x2B\x4F\xA0\xF4"
    6831             :         "\x87\x33\x60\xE2\x84\x19\x28\xCD\x60\xDD\x4C\xEE\x8C\xC0\xD4\xC9"
    6832             :         "\x22\xA9\x61\x88\xD0\x32\x67\x5C\x8A\xC8\x50\x93\x3C\x7A\xFF\x15"
    6833             :         "\x33\xB9\x4C\x83\x4A\xDB\xB6\x9C\x61\x15\xBA\xD4\x69\x2D\x86\x19"
    6834             :         "\xF9\x0B\x0C\xDF\x8A\x7B\x9C\x26\x40\x29\xAC\x18\x5B\x70\xB8\x3F"
    6835             :         "\x28\x01\xF2\xF4\xB3\xF7\x0C\x59\x3E\xA3\xAE\xEB\x61\x3A\x7F\x1B"
    6836             :         "\x1D\xE3\x3F\xD7\x50\x81\xF5\x92\x30\x5F\x2E\x45\x26\xED\xC0\x96"
    6837             :         "\x31\xB1\x09\x58\xF4\x64\xD8\x89\xF3\x1B\xA0\x10\x25\x0F\xDA\x7F"
    6838             :         "\x13\x68\xEC\x29\x67\xFC\x84\xEF\x2A\xE9\xAF\xF2\x68\xE0\xB1\x70"
    6839             :         "\x0A\xFF\xC6\x82\x0B\x52\x3A\x3D\x91\x71\x35\xF2\xDF\xF2\xEE\x06"
    6840             :         "\xBF\xE7\x2B\x31\x24\x72\x1D\x4A\x26\xC0\x4E\x53\xA7\x5E\x30\xE7"
    6841             :         "\x3A\x7A\x9C\x4A\x95\xD9\x1C\x55\xD4\x95\xE9\xF5\x1D\xD0\xB5\xE9"
    6842             :         "\xD8\x3C\x6D\x5E\x8C\xE8\x03\xAA\x62\xB8\xD6\x54\xDB\x53\xD0\x9B"
    6843             :         "\x8D\xCF\xF2\x73\xCD\xFE\xB5\x73\xFA\xD8\xBC\xD4\x55\x78\xBE\xC2"
    6844             :         "\xE7\x70\xD0\x1E\xFD\xE8\x6E\x72\x1A\x3F\x7C\x6C\xCE\x27\x5D\xAB"
    6845             :         "\xE6\xE2\x14\x3F\x1A\xF1\x8D\xA7\xEF\xDD\xC4\xC7\xB7\x0B\x5E\x34"
    6846             :         "\x5D\xB9\x3C\xC9\x36\xBE\xA3\x23\x49\x1C\xCB\x38\xA3\x88\xF5\x46"
    6847             :         "\xA9\xFF\x00\xDD\x4E\x13\x00\xB9\xB2\x15\x3D\x20\x41\xD2\x05\xB4"
    6848             :         "\x43\xE4\x1B\x45\xA6\x53\xF2\xA5\xC4\x49\x2C\x1A\xDD\x54\x45\x12"
    6849             :         "\xDD\xA2\x52\x98\x33\x46\x2B\x71\xA4\x1A\x45\xBE\x97\x29\x0B\x6F",
    6850             :         0, 512, },
    6851             :       { GCRY_MD_SHAKE128,
    6852             :         "\x5A\xAB\x62\x75\x6D\x30\x7A\x66\x9D\x14\x6A\xBA\x98\x8D\x90\x74"
    6853             :         "\xC5\xA1\x59\xB3\xDE\x85\x15\x1A\x81\x9B\x11\x7C\xA1\xFF\x65\x97"
    6854             :         "\xF6\x15\x6E\x80\xFD\xD2\x8C\x9C\x31\x76\x83\x51\x64\xD3\x7D\xA7"
    6855             :         "\xDA\x11\xD9\x4E\x09\xAD\xD7\x70\xB6\x8A\x6E\x08\x1C\xD2\x2C\xA0"
    6856             :         "\xC0\x04\xBF\xE7\xCD\x28\x3B\xF4\x3A\x58\x8D\xA9\x1F\x50\x9B\x27"
    6857             :         "\xA6\x58\x4C\x47\x4A\x4A\x2F\x3E\xE0\xF1\xF5\x64\x47\x37\x92\x40"
    6858             :         "\xA5\xAB\x1F\xB7\x7F\xDC\xA4\x9B\x30\x5F\x07\xBA\x86\xB6\x27\x56"
    6859             :         "\xFB\x9E\xFB\x4F\xC2\x25\xC8\x68\x45\xF0\x26\xEA\x54\x20\x76\xB9"
    6860             :         "\x1A\x0B\xC2\xCD\xD1\x36\xE1\x22\xC6\x59\xBE\x25\x9D\x98\xE5\x84"
    6861             :         "\x1D\xF4\xC2\xF6\x03\x30\xD4\xD8\xCD\xEE\x7B\xF1\xA0\xA2\x44\x52"
    6862             :         "\x4E\xEC\xC6\x8F\xF2\xAE\xF5\xBF\x00\x69\xC9\xE8\x7A\x11\xC6\xE5"
    6863             :         "\x19\xDE\x1A\x40\x62\xA1\x0C\x83\x83\x73\x88\xF7\xEF\x58\x59\x8A"
    6864             :         "\x38\x46\xF4\x9D\x49\x96\x82\xB6\x83\xC4\xA0\x62\xB4\x21\x59\x4F"
    6865             :         "\xAF\xBC\x13\x83\xC9\x43\xBA\x83\xBD\xEF\x51\x5E\xFC\xF1\x0D",
    6866             :         "\xF0\x71\x5D\xE3\x56\x92\xFD\x70\x12\x3D\xC6\x83\x68\xD0\xFE\xEC"
    6867             :         "\x06\xA0\xC7\x4C\xF8\xAD\xB0\x5D\xDC\x25\x54\x87\xB1\xA8\xD4\xD1"
    6868             :         "\x21\x3E\x9E\xAB\xAF\x41\xF1\x16\x17\x19\xD0\x65\xD7\x94\xB7\x50"
    6869             :         "\xF8\x4B\xE3\x2A\x32\x34\xB4\xD5\x36\x46\x0D\x55\x20\x68\x8A\x5A"
    6870             :         "\x79\xA1\x7A\x4B\xA8\x98\x7F\xCB\x61\xBF\x7D\xAA\x8B\x54\x7B\xF5"
    6871             :         "\xC1\xCE\x36\xB5\x6A\x73\x25\x7D\xBB\xF1\xBA\xBB\x64\xF2\x49\xBD"
    6872             :         "\xCE\xB6\x7B\xA1\xC8\x88\x37\x0A\x96\x3D\xFD\x6B\x6A\x2A\xDE\x2C"
    6873             :         "\xEF\xD1\x4C\x32\x52\xCB\x37\x58\x52\x0F\x0C\x65\xF4\x52\x46\x82"
    6874             :         "\x77\x24\x99\x46\x3A\xE1\xA3\x41\x80\x01\x83\xAA\x60\xEF\xA0\x51"
    6875             :         "\x18\xA2\x82\x01\x74\x4F\x7B\xA0\xB0\xA3\x92\x8D\xD7\xC0\x26\x3F"
    6876             :         "\xD2\x64\xB7\xCD\x7B\x2E\x2E\x09\xB3\x22\xBF\xCE\xA8\xEE\xD0\x42"
    6877             :         "\x75\x79\x5B\xE7\xC0\xF0\x0E\x11\x38\x27\x37\x0D\x05\x1D\x50\x26"
    6878             :         "\x95\x80\x30\x00\x05\xAC\x12\x88\xFE\xA6\xCD\x9A\xE9\xF4\xF3\x7C"
    6879             :         "\xE0\xF8\xAC\xE8\xBF\x3E\xBE\x1D\x70\x56\x25\x59\x54\xC7\x61\x93"
    6880             :         "\x1D\x3C\x42\xED\x62\xF7\xF1\xCE\x1B\x94\x5C\xDE\xCC\x0A\x74\x32"
    6881             :         "\x2D\x7F\x64\xD6\x00\x4F\xF2\x16\x84\x14\x93\x07\x28\x8B\x44\x8E"
    6882             :         "\x45\x43\x34\x75\xB1\xEA\x13\x14\xB0\x0F\x1F\xC4\x50\x08\x9A\x9D"
    6883             :         "\x1F\x77\x10\xC6\xD7\x65\x2E\xCF\x65\x4F\x3B\x48\x7D\x02\x83\xD4"
    6884             :         "\xD8\xA2\x8E\xFB\x50\x66\xC4\x25\x0D\x5A\xD6\x98\xE1\x5D\xBA\x88"
    6885             :         "\xE9\x25\xE4\xDE\x99\xB6\x9B\xC3\x83\xAC\x80\x45\xB7\xF1\x02\x2A"
    6886             :         "\xDD\x39\xD4\x43\x54\x6A\xE0\x92\x4F\x13\xF4\x89\x60\x96\xDF\xDF"
    6887             :         "\x37\xCA\x72\x20\x79\x87\xC4\xA7\x70\x5A\x7A\xBE\x72\x4B\x7F\xA1"
    6888             :         "\x0C\x90\x9F\x39\x25\x44\x9F\x01\x0D\x61\xE2\x07\xAD\xD9\x52\x19"
    6889             :         "\x07\x1A\xCE\xED\xB9\xB9\xDC\xED\x32\xA9\xE1\x23\x56\x1D\x60\x82"
    6890             :         "\xD4\x6A\xEF\xAE\x07\xEE\x1B\xD1\x32\x76\x5E\x3E\x51\x3C\x66\x50"
    6891             :         "\x1B\x38\x7A\xB2\xEE\x09\xA0\x4A\xE6\x3E\x25\x80\x85\x17\xAF\xEA"
    6892             :         "\x3E\x05\x11\x69\xCF\xD2\xFF\xF8\xC5\x85\x8E\x2D\x96\x23\x89\x7C"
    6893             :         "\x9E\x85\x17\x5A\xC5\xA8\x63\x94\xCD\x0A\x32\xA0\xA6\x2A\x8F\x5D"
    6894             :         "\x6C\xCC\xBF\x49\x3D\xAA\x43\xF7\x83\x62\xBB\xCA\x40\xAD\xF7\x33"
    6895             :         "\xF8\x71\xE0\xC0\x09\x98\xD9\xBF\xD6\x88\x06\x56\x66\x6C\xD7\xBE"
    6896             :         "\x4F\xE9\x89\x2C\x61\xDC\xD5\xCD\x23\xA5\xE4\x27\x7E\xEE\x8B\x4A"
    6897             :         "\xFD\x29\xB6\x9B\xBA\x55\x66\x0A\x21\x71\x12\xFF\x6E\x34\x56\xB1",
    6898             :         223, 512, },
    6899             :       { GCRY_MD_SHAKE128,
    6900             :         "!",
    6901             :         "\x9d\x22\x2c\x79\xc4\xff\x9d\x09\x2c\xf6\xca\x86\x14\x3a\xa4\x11"
    6902             :         "\xe3\x69\x97\x38\x08\xef\x97\x09\x32\x55\x82\x6c\x55\x72\xef\x58"
    6903             :         "\x42\x4c\x4b\x5c\x28\x47\x5f\xfd\xcf\x98\x16\x63\x86\x7f\xec\x63"
    6904             :         "\x21\xc1\x26\x2e\x38\x7b\xcc\xf8\xca\x67\x68\x84\xc4\xa9\xd0\xc1"
    6905             :         "\x3b\xfa\x68\x69\x76\x3d\x5a\xe4\xbb\xc9\xb3\xcc\xd0\x9d\x1c\xa5"
    6906             :         "\xea\x74\x46\x53\x8d\x69\xb3\xfb\x98\xc7\x2b\x59\xa2\xb4\x81\x7d"
    6907             :         "\xb5\xea\xdd\x90\x11\xf9\x0f\xa7\x10\x91\x93\x1f\x81\x34\xf4\xf0"
    6908             :         "\x0b\x56\x2e\x2f\xe1\x05\x93\x72\x70\x36\x1c\x19\x09\x86\x2a\xd4"
    6909             :         "\x50\x46\xe3\x93\x2f\x5d\xd3\x11\xec\x72\xfe\xc5\xf8\xfb\x8f\x60"
    6910             :         "\xb4\x5a\x3b\xee\x3f\x85\xbb\xf7\xfc\xed\xc6\xa5\x55\x67\x76\x48"
    6911             :         "\xe0\x65\x4b\x38\x19\x41\xa8\x6b\xd3\xe5\x12\x65\x7b\x0d\x57\xa7"
    6912             :         "\x99\x1f\xc4\x54\x3f\x89\xd8\x29\x04\x92\x22\x2c\xe4\xa3\x3e\x17"
    6913             :         "\x60\x2b\x3b\x99\xc0\x09\xf7\x65\x5f\x87\x53\x5c\xda\xa3\x71\x6f"
    6914             :         "\x58\xc4\x7b\x8a\x15\x7a\xd1\x95\xf0\x28\x09\xf2\x75\x00\xb9\x25"
    6915             :         "\x49\x79\x31\x1c\x6b\xb4\x15\x96\x8c\xd1\x04\x31\x16\x9a\x27\xd5"
    6916             :         "\xa8\xd6\x1e\x13\xa6\xb8\xb7\x7a\xf1\xf8\xb6\xdd\x2e\xef\xde\xa0"
    6917             :         "\x40\x78\x96\x80\x49\x0b\x5e\xdc\xb1\xd3\xe5\x38\xa4\x66\xf7\x57"
    6918             :         "\xad\x71\x8f\xe1\xfd\x9f\xae\xef\xa4\x72\x46\xad\x5e\x36\x7f\x87"
    6919             :         "\xd3\xb4\x85\x0d\x44\x86\xeb\x21\x99\xe9\x4a\x79\x79\xe2\x09\x1a"
    6920             :         "\xbc\xdf\x3b\xc1\x33\x79\xc8\x96\xdc\xeb\x79\xa8\xfd\x08\xf1\x10"
    6921             :         "\x73\xf3\x3e\x3f\x99\x23\x22\xb3\x12\x02\xde\xe2\x34\x33\x0c\xf3"
    6922             :         "\x30\x4a\x58\x8f\x0d\x59\xda\xe4\xe6\x3b\xa2\xac\x3c\xe6\x82\xcc"
    6923             :         "\x19\xd4\xe3\x41\x67\x8c\xc3\xa6\x7a\x47\xc1\x13\xb4\xdb\x89\x0f"
    6924             :         "\x30\xa9\x2a\xa0\x8a\x1f\x6d\xc8\xfb\x64\x63\xf8\x03\x8c\x2b\x40"
    6925             :         "\xb2\x53\x00\x77\xb2\x36\xce\x88\xaf\xcc\xcd\xa0\x8a\xd6\xd7\x5e"
    6926             :         "\xee\x18\x99\xb1\x0c\xd8\x00\xc2\xce\x53\x72\xbf\xf2\x2e\xe3\xa3"
    6927             :         "\x39\xd4\xb9\xc1\xa2\xf5\xf4\xb8\x20\xf6\x87\xe5\x51\x9b\xd0\x5b"
    6928             :         "\x1f\xc5\xda\x0e\xb4\x53\x36\x81\x4f\x48\x13\x2c\x64\x0e\x66\xc3"
    6929             :         "\xa0\x2a\x22\xe6\x35\x98\xf9\x4f\x22\xf3\x51\x84\x11\x04\x46\xb6"
    6930             :         "\x48\xcf\x84\x74\xf3\x0c\x43\xea\xd5\x83\x09\xfb\x25\x90\x16\x09"
    6931             :         "\xe2\x41\x87\xe8\x01\xc8\x09\x56\x1a\x64\x80\x94\x50\xe6\x03\xc4"
    6932             :         "\xa8\x03\x95\x25\xc4\x76\xb5\x8e\x32\xce\x2c\x47\xb3\x7d\xa5\x91",
    6933             :         0, 512, },
    6934             :       { GCRY_MD_SHAKE256,
    6935             :         "",
    6936             :         "\x46\xB9\xDD\x2B\x0B\xA8\x8D\x13\x23\x3B\x3F\xEB\x74\x3E\xEB\x24"
    6937             :         "\x3F\xCD\x52\xEA\x62\xB8\x1B\x82\xB5\x0C\x27\x64\x6E\xD5\x76\x2F"
    6938             :         "\xD7\x5D\xC4\xDD\xD8\xC0\xF2\x00\xCB\x05\x01\x9D\x67\xB5\x92\xF6"
    6939             :         "\xFC\x82\x1C\x49\x47\x9A\xB4\x86\x40\x29\x2E\xAC\xB3\xB7\xC4\xBE"
    6940             :         "\x14\x1E\x96\x61\x6F\xB1\x39\x57\x69\x2C\xC7\xED\xD0\xB4\x5A\xE3"
    6941             :         "\xDC\x07\x22\x3C\x8E\x92\x93\x7B\xEF\x84\xBC\x0E\xAB\x86\x28\x53"
    6942             :         "\x34\x9E\xC7\x55\x46\xF5\x8F\xB7\xC2\x77\x5C\x38\x46\x2C\x50\x10"
    6943             :         "\xD8\x46\xC1\x85\xC1\x51\x11\xE5\x95\x52\x2A\x6B\xCD\x16\xCF\x86"
    6944             :         "\xF3\xD1\x22\x10\x9E\x3B\x1F\xDD\x94\x3B\x6A\xEC\x46\x8A\x2D\x62"
    6945             :         "\x1A\x7C\x06\xC6\xA9\x57\xC6\x2B\x54\xDA\xFC\x3B\xE8\x75\x67\xD6"
    6946             :         "\x77\x23\x13\x95\xF6\x14\x72\x93\xB6\x8C\xEA\xB7\xA9\xE0\xC5\x8D"
    6947             :         "\x86\x4E\x8E\xFD\xE4\xE1\xB9\xA4\x6C\xBE\x85\x47\x13\x67\x2F\x5C"
    6948             :         "\xAA\xAE\x31\x4E\xD9\x08\x3D\xAB\x4B\x09\x9F\x8E\x30\x0F\x01\xB8"
    6949             :         "\x65\x0F\x1F\x4B\x1D\x8F\xCF\x3F\x3C\xB5\x3F\xB8\xE9\xEB\x2E\xA2"
    6950             :         "\x03\xBD\xC9\x70\xF5\x0A\xE5\x54\x28\xA9\x1F\x7F\x53\xAC\x26\x6B"
    6951             :         "\x28\x41\x9C\x37\x78\xA1\x5F\xD2\x48\xD3\x39\xED\xE7\x85\xFB\x7F"
    6952             :         "\x5A\x1A\xAA\x96\xD3\x13\xEA\xCC\x89\x09\x36\xC1\x73\xCD\xCD\x0F"
    6953             :         "\xAB\x88\x2C\x45\x75\x5F\xEB\x3A\xED\x96\xD4\x77\xFF\x96\x39\x0B"
    6954             :         "\xF9\xA6\x6D\x13\x68\xB2\x08\xE2\x1F\x7C\x10\xD0\x4A\x3D\xBD\x4E"
    6955             :         "\x36\x06\x33\xE5\xDB\x4B\x60\x26\x01\xC1\x4C\xEA\x73\x7D\xB3\xDC"
    6956             :         "\xF7\x22\x63\x2C\xC7\x78\x51\xCB\xDD\xE2\xAA\xF0\xA3\x3A\x07\xB3"
    6957             :         "\x73\x44\x5D\xF4\x90\xCC\x8F\xC1\xE4\x16\x0F\xF1\x18\x37\x8F\x11"
    6958             :         "\xF0\x47\x7D\xE0\x55\xA8\x1A\x9E\xDA\x57\xA4\xA2\xCF\xB0\xC8\x39"
    6959             :         "\x29\xD3\x10\x91\x2F\x72\x9E\xC6\xCF\xA3\x6C\x6A\xC6\xA7\x58\x37"
    6960             :         "\x14\x30\x45\xD7\x91\xCC\x85\xEF\xF5\xB2\x19\x32\xF2\x38\x61\xBC"
    6961             :         "\xF2\x3A\x52\xB5\xDA\x67\xEA\xF7\xBA\xAE\x0F\x5F\xB1\x36\x9D\xB7"
    6962             :         "\x8F\x3A\xC4\x5F\x8C\x4A\xC5\x67\x1D\x85\x73\x5C\xDD\xDB\x09\xD2"
    6963             :         "\xB1\xE3\x4A\x1F\xC0\x66\xFF\x4A\x16\x2C\xB2\x63\xD6\x54\x12\x74"
    6964             :         "\xAE\x2F\xCC\x86\x5F\x61\x8A\xBE\x27\xC1\x24\xCD\x8B\x07\x4C\xCD"
    6965             :         "\x51\x63\x01\xB9\x18\x75\x82\x4D\x09\x95\x8F\x34\x1E\xF2\x74\xBD"
    6966             :         "\xAB\x0B\xAE\x31\x63\x39\x89\x43\x04\xE3\x58\x77\xB0\xC2\x8A\x9B"
    6967             :         "\x1F\xD1\x66\xC7\x96\xB9\xCC\x25\x8A\x06\x4A\x8F\x57\xE2\x7F\x2A",
    6968             :         0, 512, },
    6969             :       { GCRY_MD_SHAKE256,
    6970             :         "\xB3\x2D\x95\xB0\xB9\xAA\xD2\xA8\x81\x6D\xE6\xD0\x6D\x1F\x86\x00"
    6971             :         "\x85\x05\xBD\x8C\x14\x12\x4F\x6E\x9A\x16\x3B\x5A\x2A\xDE\x55\xF8"
    6972             :         "\x35\xD0\xEC\x38\x80\xEF\x50\x70\x0D\x3B\x25\xE4\x2C\xC0\xAF\x05"
    6973             :         "\x0C\xCD\x1B\xE5\xE5\x55\xB2\x30\x87\xE0\x4D\x7B\xF9\x81\x36\x22"
    6974             :         "\x78\x0C\x73\x13\xA1\x95\x4F\x87\x40\xB6\xEE\x2D\x3F\x71\xF7\x68"
    6975             :         "\xDD\x41\x7F\x52\x04\x82\xBD\x3A\x08\xD4\xF2\x22\xB4\xEE\x9D\xBD"
    6976             :         "\x01\x54\x47\xB3\x35\x07\xDD\x50\xF3\xAB\x42\x47\xC5\xDE\x9A\x8A"
    6977             :         "\xBD\x62\xA8\xDE\xCE\xA0\x1E\x3B\x87\xC8\xB9\x27\xF5\xB0\x8B\xEB"
    6978             :         "\x37\x67\x4C\x6F\x8E\x38\x0C\x04",
    6979             :         "\xCC\x2E\xAA\x04\xEE\xF8\x47\x9C\xDA\xE8\x56\x6E\xB8\xFF\xA1\x10"
    6980             :         "\x0A\x40\x79\x95\xBF\x99\x9A\xE9\x7E\xDE\x52\x66\x81\xDC\x34\x90"
    6981             :         "\x61\x6F\x28\x44\x2D\x20\xDA\x92\x12\x4C\xE0\x81\x58\x8B\x81\x49"
    6982             :         "\x1A\xED\xF6\x5C\xAA\xF0\xD2\x7E\x82\xA4\xB0\xE1\xD1\xCA\xB2\x38"
    6983             :         "\x33\x32\x8F\x1B\x8D\xA4\x30\xC8\xA0\x87\x66\xA8\x63\x70\xFA\x84"
    6984             :         "\x8A\x79\xB5\x99\x8D\xB3\xCF\xFD\x05\x7B\x96\xE1\xE2\xEE\x0E\xF2"
    6985             :         "\x29\xEC\xA1\x33\xC1\x55\x48\xF9\x83\x99\x02\x04\x37\x30\xE4\x4B"
    6986             :         "\xC5\x2C\x39\xFA\xDC\x1D\xDE\xEA\xD9\x5F\x99\x39\xF2\x20\xCA\x30"
    6987             :         "\x06\x61\x54\x0D\xF7\xED\xD9\xAF\x37\x8A\x5D\x4A\x19\xB2\xB9\x3E"
    6988             :         "\x6C\x78\xF4\x9C\x35\x33\x43\xA0\xB5\xF1\x19\x13\x2B\x53\x12\xD0"
    6989             :         "\x04\x83\x1D\x01\x76\x9A\x31\x6D\x2F\x51\xBF\x64\xCC\xB2\x0A\x21"
    6990             :         "\xC2\xCF\x7A\xC8\xFB\x6F\x6E\x90\x70\x61\x26\xBD\xAE\x06\x11\xDD"
    6991             :         "\x13\x96\x2E\x8B\x53\xD6\xEA\xE2\x6C\x7B\x0D\x25\x51\xDA\xF6\x24"
    6992             :         "\x8E\x9D\x65\x81\x73\x82\xB0\x4D\x23\x39\x2D\x10\x8E\x4D\x34\x43"
    6993             :         "\xDE\x5A\xDC\x72\x73\xC7\x21\xA8\xF8\x32\x0E\xCF\xE8\x17\x7A\xC0"
    6994             :         "\x67\xCA\x8A\x50\x16\x9A\x6E\x73\x00\x0E\xBC\xDC\x1E\x4E\xE6\x33"
    6995             :         "\x9F\xC8\x67\xC3\xD7\xAE\xAB\x84\x14\x63\x98\xD7\xBA\xDE\x12\x1D"
    6996             :         "\x19\x89\xFA\x45\x73\x35\x56\x4E\x97\x57\x70\xA3\xA0\x02\x59\xCA"
    6997             :         "\x08\x70\x61\x08\x26\x1A\xA2\xD3\x4D\xE0\x0F\x8C\xAC\x7D\x45\xD3"
    6998             :         "\x5E\x5A\xA6\x3E\xA6\x9E\x1D\x1A\x2F\x7D\xAB\x39\x00\xD5\x1E\x0B"
    6999             :         "\xC6\x53\x48\xA2\x55\x54\x00\x70\x39\xA5\x2C\x3C\x30\x99\x80\xD1"
    7000             :         "\x7C\xAD\x20\xF1\x15\x63\x10\xA3\x9C\xD3\x93\x76\x0C\xFE\x58\xF6"
    7001             :         "\xF8\xAD\xE4\x21\x31\x28\x82\x80\xA3\x5E\x1D\xB8\x70\x81\x83\xB9"
    7002             :         "\x1C\xFA\xF5\x82\x7E\x96\xB0\xF7\x74\xC4\x50\x93\xB4\x17\xAF\xF9"
    7003             :         "\xDD\x64\x17\xE5\x99\x64\xA0\x1B\xD2\xA6\x12\xFF\xCF\xBA\x18\xA0"
    7004             :         "\xF1\x93\xDB\x29\x7B\x9A\x6C\xC1\xD2\x70\xD9\x7A\xAE\x8F\x8A\x3A"
    7005             :         "\x6B\x26\x69\x5A\xB6\x64\x31\xC2\x02\xE1\x39\xD6\x3D\xD3\xA2\x47"
    7006             :         "\x78\x67\x6C\xEF\xE3\xE2\x1B\x02\xEC\x4E\x8F\x5C\xFD\x66\x58\x7A"
    7007             :         "\x12\xB4\x40\x78\xFC\xD3\x9E\xEE\x44\xBB\xEF\x4A\x94\x9A\x63\xC0"
    7008             :         "\xDF\xD5\x8C\xF2\xFB\x2C\xD5\xF0\x02\xE2\xB0\x21\x92\x66\xCF\xC0"
    7009             :         "\x31\x81\x74\x86\xDE\x70\xB4\x28\x5A\x8A\x70\xF3\xD3\x8A\x61\xD3"
    7010             :         "\x15\x5D\x99\xAA\xF4\xC2\x53\x90\xD7\x36\x45\xAB\x3E\x8D\x80\xF0",
    7011             :         136, 512, },
    7012             :       { GCRY_MD_SHAKE256,
    7013             :         "!",
    7014             :         "\x35\x78\xa7\xa4\xca\x91\x37\x56\x9c\xdf\x76\xed\x61\x7d\x31\xbb"
    7015             :         "\x99\x4f\xca\x9c\x1b\xbf\x8b\x18\x40\x13\xde\x82\x34\xdf\xd1\x3a"
    7016             :         "\x3f\xd1\x24\xd4\xdf\x76\xc0\xa5\x39\xee\x7d\xd2\xf6\xe1\xec\x34"
    7017             :         "\x61\x24\xc8\x15\xd9\x41\x0e\x14\x5e\xb5\x61\xbc\xd9\x7b\x18\xab"
    7018             :         "\x6c\xe8\xd5\x55\x3e\x0e\xab\x3d\x1f\x7d\xfb\x8f\x9d\xee\xfe\x16"
    7019             :         "\x84\x7e\x21\x92\xf6\xf6\x1f\xb8\x2f\xb9\x0d\xde\x60\xb1\x90\x63"
    7020             :         "\xc5\x6a\x4c\x55\xcd\xd7\xb6\x72\xb7\x5b\xf5\x15\xad\xbf\xe2\x04"
    7021             :         "\x90\x3c\x8c\x00\x36\xde\x54\xa2\x99\x9a\x92\x0d\xe9\x0f\x66\xd7"
    7022             :         "\xff\x6e\xc8\xe4\xc9\x3d\x24\xae\x34\x6f\xdc\xb3\xa5\xa5\xbd\x57"
    7023             :         "\x39\xec\x15\xa6\xed\xdb\x5c\xe5\xb0\x2d\xa5\x30\x39\xfa\xc6\x3e"
    7024             :         "\x19\x55\x5f\xaa\x2e\xdd\xc6\x93\xb1\xf0\xc2\xa6\xfc\xbe\x7c\x0a"
    7025             :         "\x0a\x09\x1d\x0e\xe7\x00\xd7\x32\x2e\x4b\x0f\xf0\x95\x90\xde\x16"
    7026             :         "\x64\x22\xf9\xea\xd5\xda\x4c\x99\x3d\x60\x5f\xe4\xd9\xc6\x34\x84"
    7027             :         "\x3a\xa1\x78\xb1\x76\x72\xc6\x56\x8c\x8a\x2e\x62\xab\xeb\xea\x2c"
    7028             :         "\x21\xc3\x02\xbd\x36\x6a\xd6\x98\x95\x9e\x1f\x6e\x43\x4a\xf1\x55"
    7029             :         "\x56\x8b\x27\x34\xd8\x37\x9f\xcd\x3f\xfe\x64\x89\xba\xff\xa6\xd7"
    7030             :         "\x11\x09\x44\x2e\x1b\x34\x4f\x13\x8a\x09\xca\xe3\xe2\xd3\x94\x2e"
    7031             :         "\xee\x82\x8f\xc4\x7e\x64\xde\xb5\xe0\x0a\x02\x4a\xe1\xf2\xc0\x77"
    7032             :         "\xe6\xb7\xb1\x33\xf6\xc1\xde\x91\x30\x92\xd4\xe8\x29\xec\xd2\xb2"
    7033             :         "\xef\x28\xca\x80\x20\x82\x1e\x2b\x8b\xe5\x17\xd9\x3e\xd0\x88\x36"
    7034             :         "\xf6\xf0\x66\xcc\x3d\x03\xb6\x25\xd8\x49\x7f\x29\xdb\xc1\xc3\x9e"
    7035             :         "\x6f\xe4\x63\x22\x6f\x85\xc1\x28\xa2\xc2\x98\x88\x11\x2e\x06\xa9"
    7036             :         "\x9c\x5d\x17\xb2\x5e\x90\x0d\x20\x4f\x39\x72\x31\xcd\xf7\x9c\x31"
    7037             :         "\x34\x46\x53\x2d\xad\x07\xf4\xc0\xbd\x9f\xba\x1d\xd4\x13\xd8\xa7"
    7038             :         "\xe6\xcb\xc0\xa0\x86\x2c\xc7\x69\x23\x9a\x89\xf9\xdb\x08\x5b\x78"
    7039             :         "\xa0\x54\x59\x6a\xd7\x08\x0d\xdf\x96\x01\x9b\x73\x99\xb5\x03\x48"
    7040             :         "\x0e\x5a\x65\xa2\x20\x8d\x74\x72\x4c\x98\x7d\x32\x5e\x9b\x0e\x82"
    7041             :         "\xfe\xcd\x4f\x27\xf3\x13\x5b\x1d\x9e\x27\xb4\x8e\x69\xdd\x6f\x59"
    7042             :         "\x62\xb8\xa6\x3b\x48\x92\x1e\xc8\xee\x53\x86\x9f\x1a\xc1\xc8\x18"
    7043             :         "\x23\x87\xee\x0d\x6c\xfe\xf6\x53\xff\x8b\xf6\x05\xf1\x47\x04\xb7"
    7044             :         "\x1b\xeb\x65\x53\xf2\x81\xfa\x75\x69\x48\xc4\x38\x49\x4b\x19\xb4"
    7045             :         "\xee\x69\xa5\x43\x6b\x22\x2b\xc9\x88\xed\xa4\xac\x60\x00\x24\xc9",
    7046             :         0, 512, },
    7047             :       { 0 }
    7048             :     };
    7049             :   gcry_error_t err;
    7050             :   int i;
    7051             : 
    7052           1 :   if (verbose)
    7053           0 :     fprintf (stderr, "Starting hash checks.\n");
    7054             : 
    7055        1166 :   for (i = 0; algos[i].md; i++)
    7056             :     {
    7057        1165 :       if (gcry_md_test_algo (algos[i].md))
    7058             :         {
    7059           3 :           show_md_not_available (algos[i].md);
    7060           3 :           continue;
    7061             :         }
    7062        1162 :       if (gcry_md_test_algo (algos[i].md) && in_fips_mode)
    7063             :         {
    7064           0 :           if (verbose)
    7065           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    7066             :                      algos[i].md);
    7067           0 :           continue;
    7068             :         }
    7069        1162 :       if (verbose)
    7070           0 :         fprintf (stderr, "  checking %s [%i] for length %d\n",
    7071             :                  gcry_md_algo_name (algos[i].md),
    7072             :                  algos[i].md,
    7073           0 :                  (!strcmp (algos[i].data, "!") || !strcmp (algos[i].data, "?"))?
    7074           0 :                  1000000 : (int)strlen(algos[i].data));
    7075             : 
    7076        2459 :       check_one_md (algos[i].md, algos[i].data,
    7077        1162 :                     algos[i].datalen > 0 ? algos[i].datalen
    7078         135 :                                          : strlen (algos[i].data),
    7079             :                     algos[i].expect, algos[i].expectlen);
    7080        2459 :       check_one_md_multi (algos[i].md, algos[i].data,
    7081        1162 :                           algos[i].datalen > 0 ? algos[i].datalen
    7082         135 :                                                : strlen (algos[i].data),
    7083             :                           algos[i].expect);
    7084             :     }
    7085             : 
    7086             :   /* Check the Whirlpool bug emulation.  */
    7087           1 :   if (!gcry_md_test_algo (GCRY_MD_WHIRLPOOL) && !in_fips_mode)
    7088             :     {
    7089             :       static const char expect[] =
    7090             :         "\x35\x28\xd6\x4c\x56\x2c\x55\x2e\x3b\x91\x93\x95\x7b\xdd\xcc\x6e"
    7091             :         "\x6f\xb7\xbf\x76\x22\x9c\xc6\x23\xda\x3e\x09\x9b\x36\xe8\x6d\x76"
    7092             :         "\x2f\x94\x3b\x0c\x63\xa0\xba\xa3\x4d\x66\x71\xe6\x5d\x26\x67\x28"
    7093             :         "\x36\x1f\x0e\x1a\x40\xf0\xce\x83\x50\x90\x1f\xfa\x3f\xed\x6f\xfd";
    7094             :       gcry_md_hd_t hd;
    7095           1 :       int algo = GCRY_MD_WHIRLPOOL;
    7096             :       unsigned char *p;
    7097             :       int mdlen;
    7098             : 
    7099           1 :       err = gcry_md_open (&hd, GCRY_MD_WHIRLPOOL, GCRY_MD_FLAG_BUGEMU1);
    7100           1 :       if (err)
    7101             :         {
    7102           0 :           fail ("algo %d, gcry_md_open failed: %s\n", algo, gpg_strerror (err));
    7103           0 :           goto leave;
    7104             :         }
    7105             : 
    7106           1 :       mdlen = gcry_md_get_algo_dlen (algo);
    7107           1 :       if (mdlen < 1 || mdlen > 500)
    7108             :         {
    7109           0 :           fail ("algo %d, gcry_md_get_algo_dlen failed: %d\n", algo, mdlen);
    7110           0 :           gcry_md_close (hd);
    7111           0 :           goto leave;
    7112             :         }
    7113             : 
    7114             :       /* Hash 62 byes in chunks.  */
    7115           1 :       gcry_md_write (hd, "1234567890", 10);
    7116           1 :       gcry_md_write (hd, "1234567890123456789012345678901234567890123456789012",
    7117             :                      52);
    7118             : 
    7119           1 :       p = gcry_md_read (hd, algo);
    7120             : 
    7121           1 :       if (memcmp (p, expect, mdlen))
    7122             :         {
    7123           0 :           printf ("computed: ");
    7124           0 :           for (i = 0; i < mdlen; i++)
    7125           0 :             printf ("%02x ", p[i] & 0xFF);
    7126           0 :           printf ("\nexpected: ");
    7127           0 :           for (i = 0; i < mdlen; i++)
    7128           0 :             printf ("%02x ", expect[i] & 0xFF);
    7129           0 :           printf ("\n");
    7130             : 
    7131           0 :           fail ("algo %d, digest mismatch\n", algo);
    7132             :         }
    7133             : 
    7134           1 :       gcry_md_close (hd);
    7135             :     }
    7136             : 
    7137             :  leave:
    7138           1 :   if (verbose)
    7139           0 :     fprintf (stderr, "Completed hash checks.\n");
    7140           1 : }
    7141             : 
    7142             : static void
    7143          31 : check_one_hmac (int algo, const char *data, int datalen,
    7144             :                 const char *key, int keylen, const char *expect)
    7145             : {
    7146             :   gcry_md_hd_t hd, hd2;
    7147             :   unsigned char *p;
    7148             :   int mdlen;
    7149             :   int i;
    7150          31 :   gcry_error_t err = 0;
    7151             : 
    7152          31 :   err = gcry_md_open (&hd, algo, GCRY_MD_FLAG_HMAC);
    7153          31 :   if (err)
    7154             :     {
    7155           0 :       fail ("algo %d, gcry_md_open failed: %s\n", algo, gpg_strerror (err));
    7156           0 :       return;
    7157             :     }
    7158             : 
    7159          31 :   mdlen = gcry_md_get_algo_dlen (algo);
    7160          31 :   if (mdlen < 1 || mdlen > 500)
    7161             :     {
    7162           0 :       fail ("algo %d, gcry_md_get_algo_dlen failed: %d\n", algo, mdlen);
    7163           0 :       return;
    7164             :     }
    7165             : 
    7166          31 :   gcry_md_setkey( hd, key, keylen );
    7167             : 
    7168          31 :   gcry_md_write (hd, data, datalen);
    7169             : 
    7170          31 :   err = gcry_md_copy (&hd2, hd);
    7171          31 :   if (err)
    7172             :     {
    7173           0 :       fail ("algo %d, gcry_md_copy failed: %s\n", algo, gpg_strerror (err));
    7174             :     }
    7175             : 
    7176          31 :   gcry_md_close (hd);
    7177             : 
    7178          31 :   p = gcry_md_read (hd2, algo);
    7179          31 :   if (!p)
    7180           0 :     fail("algo %d, hmac gcry_md_read failed\n", algo);
    7181             : 
    7182          31 :   if (memcmp (p, expect, mdlen))
    7183             :     {
    7184           0 :       printf ("computed: ");
    7185           0 :       for (i = 0; i < mdlen; i++)
    7186           0 :         printf ("%02x ", p[i] & 0xFF);
    7187           0 :       printf ("\nexpected: ");
    7188           0 :       for (i = 0; i < mdlen; i++)
    7189           0 :         printf ("%02x ", expect[i] & 0xFF);
    7190           0 :       printf ("\n");
    7191             : 
    7192           0 :       fail ("algo %d, digest mismatch\n", algo);
    7193             :     }
    7194             : 
    7195          31 :   gcry_md_close (hd2);
    7196             : }
    7197             : 
    7198             : static void
    7199           1 : check_hmac (void)
    7200             : {
    7201             :   static const struct algos
    7202             :   {
    7203             :     int md;
    7204             :     const char *data;
    7205             :     const char *key;
    7206             :     const char *expect;
    7207             :   } algos[] =
    7208             :     {
    7209             :       { GCRY_MD_MD5, "what do ya want for nothing?", "Jefe",
    7210             :         "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38" },
    7211             :       { GCRY_MD_MD5,
    7212             :         "Hi There",
    7213             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
    7214             :         "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d" },
    7215             :       { GCRY_MD_MD5,
    7216             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7217             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7218             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7219             :         "\xdd\xdd\xdd\xdd\xdd",
    7220             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
    7221             :         "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6" },
    7222             :       { GCRY_MD_MD5,
    7223             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7224             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7225             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7226             :         "\xcd\xcd\xcd\xcd\xcd",
    7227             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7228             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7229             :         "\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79" },
    7230             :       { GCRY_MD_MD5, "Test With Truncation",
    7231             :         "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
    7232             :         "\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c" },
    7233             :       { GCRY_MD_MD5, "Test Using Larger Than Block-Size Key - Hash Key First",
    7234             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7235             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7236             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7237             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7238             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7239             :         "\xaa\xaa\xaa\xaa\xaa",
    7240             :         "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd" },
    7241             :       { GCRY_MD_MD5,
    7242             :         "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
    7243             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7244             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7245             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7246             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7247             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7248             :         "\xaa\xaa\xaa\xaa\xaa",
    7249             :         "\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e", },
    7250             :       { GCRY_MD_SHA256, "what do ya want for nothing?", "Jefe",
    7251             :         "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75\xc7\x5a"
    7252             :         "\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec\x38\x43" },
    7253             :       { GCRY_MD_SHA256,
    7254             :         "Hi There",
    7255             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7256             :         "\x0b\x0b\x0b",
    7257             :         "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88"
    7258             :         "\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7" },
    7259             :       { GCRY_MD_SHA256,
    7260             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7261             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7262             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7263             :         "\xdd\xdd\xdd\xdd\xdd",
    7264             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7265             :         "\xAA\xAA\xAA\xAA",
    7266             :         "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81\xa7"
    7267             :         "\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5\x65\xfe" },
    7268             :       { GCRY_MD_SHA256,
    7269             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7270             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7271             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7272             :         "\xcd\xcd\xcd\xcd\xcd",
    7273             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7274             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7275             :         "\x82\x55\x8a\x38\x9a\x44\x3c\x0e\xa4\xcc\x81\x98\x99\xf2\x08"
    7276             :         "\x3a\x85\xf0\xfa\xa3\xe5\x78\xf8\x07\x7a\x2e\x3f\xf4\x67\x29\x66\x5b" },
    7277             :       { GCRY_MD_SHA256,
    7278             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7279             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7280             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7281             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7282             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7283             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7284             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7285             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7286             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7287             :         "\xaa\xaa\xaa",
    7288             :         "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7\x7f"
    7289             :         "\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3\x7f\x54" },
    7290             :       { GCRY_MD_SHA256,
    7291             :         "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.",
    7292             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7293             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7294             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7295             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7296             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7297             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7298             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7299             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7300             :         "\xaa\xaa\xaa",
    7301             :         "\x9b\x09\xff\xa7\x1b\x94\x2f\xcb\x27\x63\x5f\xbc\xd5\xb0\xe9\x44"
    7302             :         "\xbf\xdc\x63\x64\x4f\x07\x13\x93\x8a\x7f\x51\x53\x5c\x3a\x35\xe2" },
    7303             :       { GCRY_MD_SHA224, "what do ya want for nothing?", "Jefe",
    7304             :         "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d\x0f"
    7305             :         "\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44" },
    7306             :       { GCRY_MD_SHA224,
    7307             :         "Hi There",
    7308             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7309             :         "\x0b\x0b\x0b",
    7310             :         "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47"
    7311             :         "\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22" },
    7312             :       { GCRY_MD_SHA224,
    7313             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7314             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7315             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7316             :         "\xdd\xdd\xdd\xdd\xdd",
    7317             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7318             :         "\xAA\xAA\xAA\xAA",
    7319             :         "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2\x64"
    7320             :         "\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea" },
    7321             :       { GCRY_MD_SHA224,
    7322             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7323             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7324             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7325             :         "\xcd\xcd\xcd\xcd\xcd",
    7326             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7327             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7328             :         "\x6c\x11\x50\x68\x74\x01\x3c\xac\x6a\x2a\xbc\x1b\xb3\x82\x62"
    7329             :         "\x7c\xec\x6a\x90\xd8\x6e\xfc\x01\x2d\xe7\xaf\xec\x5a" },
    7330             :       { GCRY_MD_SHA224,
    7331             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7332             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7333             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7334             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7335             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7336             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7337             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7338             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7339             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7340             :         "\xaa\xaa\xaa",
    7341             :         "\x95\xe9\xa0\xdb\x96\x20\x95\xad\xae\xbe\x9b\x2d\x6f\x0d\xbc\xe2"
    7342             :         "\xd4\x99\xf1\x12\xf2\xd2\xb7\x27\x3f\xa6\x87\x0e" },
    7343             :       { GCRY_MD_SHA224,
    7344             :         "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.",
    7345             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7346             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7347             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7348             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7349             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7350             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7351             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7352             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7353             :         "\xaa\xaa\xaa",
    7354             :         "\x3a\x85\x41\x66\xac\x5d\x9f\x02\x3f\x54\xd5\x17\xd0\xb3\x9d\xbd"
    7355             :         "\x94\x67\x70\xdb\x9c\x2b\x95\xc9\xf6\xf5\x65\xd1" },
    7356             :       { GCRY_MD_SHA384, "what do ya want for nothing?", "Jefe",
    7357             :         "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b\x1b"
    7358             :         "\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22\x44\x5e"
    7359             :         "\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa\xb2\x16\x49" },
    7360             :       { GCRY_MD_SHA384,
    7361             :         "Hi There",
    7362             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7363             :         "\x0b\x0b\x0b",
    7364             :         "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15"
    7365             :         "\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea"
    7366             :         "\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6" },
    7367             :       { GCRY_MD_SHA384,
    7368             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7369             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7370             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7371             :         "\xdd\xdd\xdd\xdd\xdd",
    7372             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7373             :         "\xAA\xAA\xAA\xAA",
    7374             :         "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8\x6f"
    7375             :         "\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66\x14\x4b"
    7376             :         "\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01\xa3\x4f\x27" },
    7377             :       { GCRY_MD_SHA384,
    7378             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7379             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7380             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7381             :         "\xcd\xcd\xcd\xcd\xcd",
    7382             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7383             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7384             :         "\x3e\x8a\x69\xb7\x78\x3c\x25\x85\x19\x33\xab\x62\x90\xaf\x6c\xa7"
    7385             :         "\x7a\x99\x81\x48\x08\x50\x00\x9c\xc5\x57\x7c\x6e\x1f\x57\x3b\x4e"
    7386             :         "\x68\x01\xdd\x23\xc4\xa7\xd6\x79\xcc\xf8\xa3\x86\xc6\x74\xcf\xfb" },
    7387             :       { GCRY_MD_SHA384,
    7388             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7389             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7390             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7391             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7392             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7393             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7394             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7395             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7396             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7397             :         "\xaa\xaa\xaa",
    7398             :         "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5\xb4"
    7399             :         "\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a\xc4\xc6"
    7400             :         "\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63\xf4\x49\x52" },
    7401             :       { GCRY_MD_SHA384,
    7402             :         "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.",
    7403             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7404             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7405             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7406             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7407             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7408             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7409             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7410             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7411             :         "\xaa\xaa\xaa",
    7412             :         "\x66\x17\x17\x8e\x94\x1f\x02\x0d\x35\x1e\x2f\x25\x4e\x8f\xd3\x2c"
    7413             :         "\x60\x24\x20\xfe\xb0\xb8\xfb\x9a\xdc\xce\xbb\x82\x46\x1e\x99\xc5"
    7414             :         "\xa6\x78\xcc\x31\xe7\x99\x17\x6d\x38\x60\xe6\x11\x0c\x46\x52\x3e" },
    7415             :       { GCRY_MD_SHA512, "what do ya want for nothing?", "Jefe",
    7416             :         "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0\xa3"
    7417             :         "\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25\x05\x54"
    7418             :         "\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8\xf0\xe6\xfd"
    7419             :         "\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a\x38\xbc\xe7\x37" },
    7420             :       { GCRY_MD_SHA512,
    7421             :         "Hi There",
    7422             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7423             :         "\x0b\x0b\x0b",
    7424             :         "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0"
    7425             :         "\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde"
    7426             :         "\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4"
    7427             :         "\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54" },
    7428             :       { GCRY_MD_SHA512,
    7429             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7430             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7431             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7432             :         "\xdd\xdd\xdd\xdd\xdd",
    7433             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7434             :         "\xAA\xAA\xAA\xAA",
    7435             :         "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b\xe9"
    7436             :         "\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27\x9d\x39"
    7437             :         "\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e\x67\xc8\x07"
    7438             :         "\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59\xe1\x32\x92\xfb"  },
    7439             :       { GCRY_MD_SHA512,
    7440             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7441             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7442             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7443             :         "\xcd\xcd\xcd\xcd\xcd",
    7444             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7445             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7446             :         "\xb0\xba\x46\x56\x37\x45\x8c\x69\x90\xe5\xa8\xc5\xf6\x1d\x4a\xf7"
    7447             :         "\xe5\x76\xd9\x7f\xf9\x4b\x87\x2d\xe7\x6f\x80\x50\x36\x1e\xe3\xdb"
    7448             :         "\xa9\x1c\xa5\xc1\x1a\xa2\x5e\xb4\xd6\x79\x27\x5c\xc5\x78\x80\x63"
    7449             :         "\xa5\xf1\x97\x41\x12\x0c\x4f\x2d\xe2\xad\xeb\xeb\x10\xa2\x98\xdd" },
    7450             :       { GCRY_MD_SHA512,
    7451             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7452             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7453             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7454             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7455             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7456             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7457             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7458             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7459             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7460             :         "\xaa\xaa\xaa",
    7461             :         "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8\xb4"
    7462             :         "\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8\xf3\x52"
    7463             :         "\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d\x6a\x1e\x52"
    7464             :         "\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98\x5d\x78\x65\x98" },
    7465             :       { GCRY_MD_SHA512,
    7466             :         "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.",
    7467             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7468             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7469             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7470             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7471             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7472             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7473             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7474             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7475             :         "\xaa\xaa\xaa",
    7476             :         "\xe3\x7b\x6a\x77\x5d\xc8\x7d\xba\xa4\xdf\xa9\xf9\x6e\x5e\x3f\xfd"
    7477             :         "\xde\xbd\x71\xf8\x86\x72\x89\x86\x5d\xf5\xa3\x2d\x20\xcd\xc9\x44"
    7478             :         "\xb6\x02\x2c\xac\x3c\x49\x82\xb1\x0d\x5e\xeb\x55\xc3\xe4\xde\x15"
    7479             :         "\x13\x46\x76\xfb\x6d\xe0\x44\x60\x65\xc9\x74\x40\xfa\x8c\x6a\x58" },
    7480             :       { 0 },
    7481             :     };
    7482             :   int i;
    7483             : 
    7484           1 :   if (verbose)
    7485           0 :     fprintf (stderr, "Starting hashed MAC checks.\n");
    7486             : 
    7487          32 :   for (i = 0; algos[i].md; i++)
    7488             :     {
    7489          31 :       if (gcry_md_test_algo (algos[i].md))
    7490             :         {
    7491           0 :           show_old_hmac_not_available (algos[i].md);
    7492           0 :           continue;
    7493             :         }
    7494          31 :       if (gcry_md_test_algo (algos[i].md) && in_fips_mode)
    7495             :         {
    7496           0 :           if (verbose)
    7497           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    7498             :                      algos[i].md);
    7499           0 :           continue;
    7500             :         }
    7501          31 :       if (verbose)
    7502           0 :         fprintf (stderr,
    7503             :                  "  checking %s [%i] for %d byte key and %d byte data\n",
    7504             :                  gcry_md_algo_name (algos[i].md),
    7505             :                  algos[i].md,
    7506           0 :                  (int)strlen(algos[i].key), (int)strlen(algos[i].data));
    7507             : 
    7508          62 :       check_one_hmac (algos[i].md, algos[i].data, strlen (algos[i].data),
    7509          31 :                       algos[i].key, strlen(algos[i].key),
    7510             :                       algos[i].expect);
    7511             :     }
    7512             : 
    7513           1 :   if (verbose)
    7514           0 :     fprintf (stderr, "Completed hashed MAC checks.\n");
    7515           1 : }
    7516             : 
    7517             : 
    7518             : static void
    7519         224 : check_one_mac (int algo, const char *data, int datalen,
    7520             :                const char *key, int keylen, const char *iv, int ivlen,
    7521             :                const char *expect, int test_buffering)
    7522             : {
    7523             :   gcry_mac_hd_t hd;
    7524             :   unsigned char *p;
    7525             :   unsigned int maclen;
    7526             :   size_t macoutlen;
    7527             :   int i;
    7528         224 :   gcry_error_t err = 0;
    7529             : 
    7530         224 :   if (test_buffering)
    7531             :     {
    7532         224 :       if ((*data == '!' && !data[1]) ||
    7533         127 :           (*data == '?' && !data[1]))
    7534             :         {
    7535          30 :           return; /* Skip. */
    7536             :         }
    7537             :     }
    7538             : 
    7539         209 :   err = gcry_mac_open (&hd, algo, 0, NULL);
    7540         209 :   if (err)
    7541             :     {
    7542           0 :       fail ("algo %d, gcry_mac_open failed: %s\n", algo, gpg_strerror (err));
    7543           0 :       return;
    7544             :     }
    7545             : 
    7546         209 :   i = gcry_mac_get_algo (hd);
    7547         209 :   if (i != algo)
    7548             :     {
    7549           0 :       fail ("algo %d, gcry_mac_get_algo failed: %d\n", algo, i);
    7550             :     }
    7551             : 
    7552         209 :   maclen = gcry_mac_get_algo_maclen (algo);
    7553         209 :   if (maclen < 1 || maclen > 500)
    7554             :     {
    7555           0 :       fail ("algo %d, gcry_mac_get_algo_maclen failed: %d\n", algo, maclen);
    7556           0 :       return;
    7557             :     }
    7558             : 
    7559         209 :   p = malloc(maclen);
    7560         209 :   if (!p)
    7561             :     {
    7562           0 :       fail ("algo %d, could not malloc %d bytes\n", algo, maclen);
    7563           0 :       return;
    7564             :     }
    7565             : 
    7566         209 :   err = gcry_mac_setkey (hd, key, keylen);
    7567         209 :   if (err)
    7568           0 :     fail("algo %d, mac gcry_mac_setkey failed: %s\n", algo, gpg_strerror (err));
    7569         209 :   if (err)
    7570           0 :     goto out;
    7571             : 
    7572         209 :   if (ivlen && iv)
    7573             :     {
    7574          17 :       err = gcry_mac_setiv (hd, iv, ivlen);
    7575          17 :       if (err)
    7576           0 :         fail("algo %d, mac gcry_mac_ivkey failed: %s\n", algo,
    7577             :              gpg_strerror (err));
    7578          17 :       if (err)
    7579           0 :         goto out;
    7580             :     }
    7581             : 
    7582         209 :   if (test_buffering)
    7583             :     {
    7584        5149 :       for (i = 0; i < datalen; i++)
    7585             :         {
    7586        5052 :           err = gcry_mac_write (hd, &data[i], 1);
    7587        5052 :           if (err)
    7588           0 :             fail("algo %d, mac gcry_mac_write [buf-offset: %d] failed: %s\n",
    7589             :                  algo, i, gpg_strerror (err));
    7590        5052 :           if (err)
    7591           0 :             goto out;
    7592             :         }
    7593             :     }
    7594             :   else
    7595             :     {
    7596         224 :       if ((*data == '!' && !data[1]) || /* hash one million times a "a" */
    7597         127 :           (*data == '?' && !data[1]))   /* hash million byte data-set with byte pattern 0x00,0x01,0x02,... */
    7598          15 :         {
    7599             :           char aaa[1000];
    7600          15 :           size_t left = 1000 * 1000;
    7601          15 :           size_t startlen = 1;
    7602          15 :           size_t piecelen = startlen;
    7603             : 
    7604          15 :           if (*data == '!')
    7605           0 :             memset (aaa, 'a', 1000);
    7606             : 
    7607             :           /* Write in chuck with all sizes 1 to 1000 (500500 bytes)  */
    7608       15015 :           for (i = 1; i <= 1000 && left > 0; i++)
    7609             :             {
    7610       15000 :               piecelen = i;
    7611       15000 :               if (piecelen > sizeof(aaa))
    7612           0 :                 piecelen = sizeof(aaa);
    7613       15000 :               if (piecelen > left)
    7614           0 :                 piecelen = left;
    7615             : 
    7616       15000 :               if (*data == '?')
    7617       15000 :                 fillbuf_count(aaa, piecelen, 1000 * 1000 - left);
    7618             : 
    7619       15000 :               gcry_mac_write (hd, aaa, piecelen);
    7620             : 
    7621       15000 :               left -= piecelen;
    7622             :             }
    7623             : 
    7624             :           /* Write in odd size chunks so that we test the buffering.  */
    7625       17430 :           while (left > 0)
    7626             :             {
    7627       17400 :               if (piecelen > sizeof(aaa))
    7628        2820 :                 piecelen = sizeof(aaa);
    7629       17400 :               if (piecelen > left)
    7630          15 :                 piecelen = left;
    7631             : 
    7632       17400 :               if (*data == '?')
    7633       17400 :                 fillbuf_count(aaa, piecelen, 1000 * 1000 - left);
    7634             : 
    7635       17400 :               gcry_mac_write (hd, aaa, piecelen);
    7636             : 
    7637       17400 :               left -= piecelen;
    7638             : 
    7639       17400 :               if (piecelen == sizeof(aaa))
    7640        2835 :                 piecelen = ++startlen;
    7641             :               else
    7642       14565 :                 piecelen = piecelen * 2 - ((piecelen != startlen) ? startlen : 0);
    7643             :             }
    7644             :         }
    7645             :       else
    7646             :         {
    7647          97 :           err = gcry_mac_write (hd, data, datalen);
    7648             :         }
    7649             : 
    7650         112 :       if (err)
    7651           0 :         fail("algo %d, mac gcry_mac_write failed: %s\n", algo, gpg_strerror (err));
    7652         112 :       if (err)
    7653           0 :         goto out;
    7654             :     }
    7655             : 
    7656         209 :   err = gcry_mac_verify (hd, expect, maclen);
    7657         209 :   if (err)
    7658           0 :     fail("algo %d, mac gcry_mac_verify failed: %s\n", algo, gpg_strerror (err));
    7659             : 
    7660         209 :   macoutlen = maclen;
    7661         209 :   err = gcry_mac_read (hd, p, &macoutlen);
    7662         209 :   if (err)
    7663           0 :     fail("algo %d, mac gcry_mac_read failed: %s\n", algo, gpg_strerror (err));
    7664         209 :   if (err)
    7665           0 :     goto out;
    7666             : 
    7667         209 :   if (memcmp (p, expect, maclen))
    7668             :     {
    7669           0 :       printf ("computed: ");
    7670           0 :       for (i = 0; i < maclen; i++)
    7671           0 :         printf ("%02x ", p[i] & 0xFF);
    7672           0 :       printf ("\nexpected: ");
    7673           0 :       for (i = 0; i < maclen; i++)
    7674           0 :         printf ("%02x ", expect[i] & 0xFF);
    7675           0 :       printf ("\n");
    7676             : 
    7677           0 :       fail ("algo %d, digest mismatch\n", algo);
    7678             :     }
    7679         209 :   if (err)
    7680           0 :     goto out;
    7681             : 
    7682             : out:
    7683         209 :   free (p);
    7684         209 :   gcry_mac_close (hd);
    7685             : }
    7686             : 
    7687             : static void
    7688           1 : check_mac (void)
    7689             : {
    7690             :   static const struct algos
    7691             :   {
    7692             :     int algo;
    7693             :     const char *data;
    7694             :     const char *key;
    7695             :     const char *expect;
    7696             :     const char *iv;
    7697             :     unsigned int dlen;
    7698             :     unsigned int klen;
    7699             :   } algos[] =
    7700             :     {
    7701             :       { GCRY_MAC_HMAC_MD5, "what do ya want for nothing?", "Jefe",
    7702             :         "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38" },
    7703             :       { GCRY_MAC_HMAC_MD5,
    7704             :         "Hi There",
    7705             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
    7706             :         "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d" },
    7707             :       { GCRY_MAC_HMAC_MD5,
    7708             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7709             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7710             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7711             :         "\xdd\xdd\xdd\xdd\xdd",
    7712             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
    7713             :         "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6" },
    7714             :       { GCRY_MAC_HMAC_MD5,
    7715             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7716             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7717             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7718             :         "\xcd\xcd\xcd\xcd\xcd",
    7719             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7720             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7721             :         "\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79" },
    7722             :       { GCRY_MAC_HMAC_MD5, "Test With Truncation",
    7723             :         "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
    7724             :         "\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c" },
    7725             :       { GCRY_MAC_HMAC_MD5, "Test Using Larger Than Block-Size Key - Hash Key First",
    7726             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7727             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7728             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7729             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7730             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7731             :         "\xaa\xaa\xaa\xaa\xaa",
    7732             :         "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd" },
    7733             :       { GCRY_MAC_HMAC_MD5,
    7734             :         "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
    7735             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7736             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7737             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7738             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7739             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7740             :         "\xaa\xaa\xaa\xaa\xaa",
    7741             :         "\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e", },
    7742             :       { GCRY_MAC_HMAC_MD5, "?", "????????????????",
    7743             :         "\x7e\x28\xf8\x8e\xf4\x6c\x48\x30\xa2\x0c\xe3\xe1\x42\xd4\xb5\x6b" },
    7744             :       { GCRY_MAC_HMAC_SHA256, "what do ya want for nothing?", "Jefe",
    7745             :         "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75\xc7\x5a"
    7746             :         "\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec\x38\x43" },
    7747             :       { GCRY_MAC_HMAC_SHA256,
    7748             :         "Hi There",
    7749             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7750             :         "\x0b\x0b\x0b",
    7751             :         "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88"
    7752             :         "\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7" },
    7753             :       { GCRY_MAC_HMAC_SHA256,
    7754             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7755             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7756             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7757             :         "\xdd\xdd\xdd\xdd\xdd",
    7758             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7759             :         "\xAA\xAA\xAA\xAA",
    7760             :         "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81\xa7"
    7761             :         "\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5\x65\xfe" },
    7762             :       { GCRY_MAC_HMAC_SHA256,
    7763             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7764             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7765             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7766             :         "\xcd\xcd\xcd\xcd\xcd",
    7767             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7768             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7769             :         "\x82\x55\x8a\x38\x9a\x44\x3c\x0e\xa4\xcc\x81\x98\x99\xf2\x08"
    7770             :         "\x3a\x85\xf0\xfa\xa3\xe5\x78\xf8\x07\x7a\x2e\x3f\xf4\x67\x29\x66\x5b" },
    7771             :       { GCRY_MAC_HMAC_SHA256,
    7772             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7773             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7774             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7775             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7776             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7777             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7778             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7779             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7780             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7781             :         "\xaa\xaa\xaa",
    7782             :         "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7\x7f"
    7783             :         "\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3\x7f\x54" },
    7784             :       { GCRY_MAC_HMAC_SHA256,
    7785             :         "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.",
    7786             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7787             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7788             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7789             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7790             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7791             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7792             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7793             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7794             :         "\xaa\xaa\xaa",
    7795             :         "\x9b\x09\xff\xa7\x1b\x94\x2f\xcb\x27\x63\x5f\xbc\xd5\xb0\xe9\x44"
    7796             :         "\xbf\xdc\x63\x64\x4f\x07\x13\x93\x8a\x7f\x51\x53\x5c\x3a\x35\xe2" },
    7797             :       { GCRY_MAC_HMAC_SHA256, "?", "????????????????",
    7798             :         "\x1c\x0e\x57\xad\x4a\x02\xd2\x30\xce\x7e\xf8\x08\x23\x25\x71\x5e"
    7799             :         "\x16\x9b\x30\xca\xc3\xf4\x99\xc5\x1d\x4c\x25\x32\xa9\xf2\x15\x28" },
    7800             :       { GCRY_MAC_HMAC_SHA224, "what do ya want for nothing?", "Jefe",
    7801             :         "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d\x0f"
    7802             :         "\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44" },
    7803             :       { GCRY_MAC_HMAC_SHA224,
    7804             :         "Hi There",
    7805             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7806             :         "\x0b\x0b\x0b",
    7807             :         "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47"
    7808             :         "\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22" },
    7809             :       { GCRY_MAC_HMAC_SHA224,
    7810             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7811             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7812             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7813             :         "\xdd\xdd\xdd\xdd\xdd",
    7814             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7815             :         "\xAA\xAA\xAA\xAA",
    7816             :         "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2\x64"
    7817             :         "\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea" },
    7818             :       { GCRY_MAC_HMAC_SHA224,
    7819             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7820             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7821             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7822             :         "\xcd\xcd\xcd\xcd\xcd",
    7823             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7824             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7825             :         "\x6c\x11\x50\x68\x74\x01\x3c\xac\x6a\x2a\xbc\x1b\xb3\x82\x62"
    7826             :         "\x7c\xec\x6a\x90\xd8\x6e\xfc\x01\x2d\xe7\xaf\xec\x5a" },
    7827             :       { GCRY_MAC_HMAC_SHA224,
    7828             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7829             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7830             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7831             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7832             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7833             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7834             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7835             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7836             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7837             :         "\xaa\xaa\xaa",
    7838             :         "\x95\xe9\xa0\xdb\x96\x20\x95\xad\xae\xbe\x9b\x2d\x6f\x0d\xbc\xe2"
    7839             :         "\xd4\x99\xf1\x12\xf2\xd2\xb7\x27\x3f\xa6\x87\x0e" },
    7840             :       { GCRY_MAC_HMAC_SHA224,
    7841             :         "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.",
    7842             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7843             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7844             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7845             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7846             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7847             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7848             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7849             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7850             :         "\xaa\xaa\xaa",
    7851             :         "\x3a\x85\x41\x66\xac\x5d\x9f\x02\x3f\x54\xd5\x17\xd0\xb3\x9d\xbd"
    7852             :         "\x94\x67\x70\xdb\x9c\x2b\x95\xc9\xf6\xf5\x65\xd1" },
    7853             :       { GCRY_MAC_HMAC_SHA224, "?", "????????????????",
    7854             :         "\xc1\x88\xaf\xcf\xce\x51\xa2\x14\x3d\xc1\xaf\x93\xcc\x2b\xe9\x4d"
    7855             :         "\x39\x55\x90\x4c\x46\x70\xfc\xc2\x04\xcf\xab\xfa" },
    7856             :       { GCRY_MAC_HMAC_SHA384, "what do ya want for nothing?", "Jefe",
    7857             :         "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b\x1b"
    7858             :         "\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22\x44\x5e"
    7859             :         "\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa\xb2\x16\x49" },
    7860             :       { GCRY_MAC_HMAC_SHA384,
    7861             :         "Hi There",
    7862             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7863             :         "\x0b\x0b\x0b",
    7864             :         "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15"
    7865             :         "\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea"
    7866             :         "\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6" },
    7867             :       { GCRY_MAC_HMAC_SHA384,
    7868             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7869             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7870             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7871             :         "\xdd\xdd\xdd\xdd\xdd",
    7872             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7873             :         "\xAA\xAA\xAA\xAA",
    7874             :         "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8\x6f"
    7875             :         "\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66\x14\x4b"
    7876             :         "\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01\xa3\x4f\x27" },
    7877             :       { GCRY_MAC_HMAC_SHA384,
    7878             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7879             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7880             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7881             :         "\xcd\xcd\xcd\xcd\xcd",
    7882             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7883             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7884             :         "\x3e\x8a\x69\xb7\x78\x3c\x25\x85\x19\x33\xab\x62\x90\xaf\x6c\xa7"
    7885             :         "\x7a\x99\x81\x48\x08\x50\x00\x9c\xc5\x57\x7c\x6e\x1f\x57\x3b\x4e"
    7886             :         "\x68\x01\xdd\x23\xc4\xa7\xd6\x79\xcc\xf8\xa3\x86\xc6\x74\xcf\xfb" },
    7887             :       { GCRY_MAC_HMAC_SHA384,
    7888             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7889             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7890             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7891             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7892             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7893             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7894             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7895             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7896             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7897             :         "\xaa\xaa\xaa",
    7898             :         "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5\xb4"
    7899             :         "\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a\xc4\xc6"
    7900             :         "\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63\xf4\x49\x52" },
    7901             :       { GCRY_MAC_HMAC_SHA384,
    7902             :         "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.",
    7903             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7904             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7905             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7906             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7907             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7908             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7909             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7910             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7911             :         "\xaa\xaa\xaa",
    7912             :         "\x66\x17\x17\x8e\x94\x1f\x02\x0d\x35\x1e\x2f\x25\x4e\x8f\xd3\x2c"
    7913             :         "\x60\x24\x20\xfe\xb0\xb8\xfb\x9a\xdc\xce\xbb\x82\x46\x1e\x99\xc5"
    7914             :         "\xa6\x78\xcc\x31\xe7\x99\x17\x6d\x38\x60\xe6\x11\x0c\x46\x52\x3e" },
    7915             :       { GCRY_MAC_HMAC_SHA384, "?", "????????????????",
    7916             :         "\xe7\x96\x29\xa3\x40\x5f\x1e\x6e\x92\xa5\xdb\xa5\xc6\xe9\x60\xa8"
    7917             :         "\xf5\xd1\x6d\xcb\x10\xec\x30\x2f\x6b\x9c\x37\xe0\xea\xf1\x53\x28"
    7918             :         "\x08\x01\x9b\xe3\x4a\x43\xc6\xc2\x2b\x0c\xd9\x43\x64\x35\x25\x78" },
    7919             :       { GCRY_MAC_HMAC_SHA512, "what do ya want for nothing?", "Jefe",
    7920             :         "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0\xa3"
    7921             :         "\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25\x05\x54"
    7922             :         "\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8\xf0\xe6\xfd"
    7923             :         "\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a\x38\xbc\xe7\x37" },
    7924             :       { GCRY_MAC_HMAC_SHA512,
    7925             :         "Hi There",
    7926             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7927             :         "\x0b\x0b\x0b",
    7928             :         "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0"
    7929             :         "\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde"
    7930             :         "\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4"
    7931             :         "\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54" },
    7932             :       { GCRY_MAC_HMAC_SHA512,
    7933             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7934             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7935             :         "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
    7936             :         "\xdd\xdd\xdd\xdd\xdd",
    7937             :         "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
    7938             :         "\xAA\xAA\xAA\xAA",
    7939             :         "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b\xe9"
    7940             :         "\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27\x9d\x39"
    7941             :         "\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e\x67\xc8\x07"
    7942             :         "\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59\xe1\x32\x92\xfb"  },
    7943             :       { GCRY_MAC_HMAC_SHA512,
    7944             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7945             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7946             :         "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
    7947             :         "\xcd\xcd\xcd\xcd\xcd",
    7948             :         "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    7949             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
    7950             :         "\xb0\xba\x46\x56\x37\x45\x8c\x69\x90\xe5\xa8\xc5\xf6\x1d\x4a\xf7"
    7951             :         "\xe5\x76\xd9\x7f\xf9\x4b\x87\x2d\xe7\x6f\x80\x50\x36\x1e\xe3\xdb"
    7952             :         "\xa9\x1c\xa5\xc1\x1a\xa2\x5e\xb4\xd6\x79\x27\x5c\xc5\x78\x80\x63"
    7953             :         "\xa5\xf1\x97\x41\x12\x0c\x4f\x2d\xe2\xad\xeb\xeb\x10\xa2\x98\xdd" },
    7954             :       { GCRY_MAC_HMAC_SHA512,
    7955             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    7956             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7957             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7958             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7959             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7960             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7961             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7962             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7963             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7964             :         "\xaa\xaa\xaa",
    7965             :         "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8\xb4"
    7966             :         "\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8\xf3\x52"
    7967             :         "\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d\x6a\x1e\x52"
    7968             :         "\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98\x5d\x78\x65\x98" },
    7969             :       { GCRY_MAC_HMAC_SHA512,
    7970             :         "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.",
    7971             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7972             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7973             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7974             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7975             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7976             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7977             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7978             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    7979             :         "\xaa\xaa\xaa",
    7980             :         "\xe3\x7b\x6a\x77\x5d\xc8\x7d\xba\xa4\xdf\xa9\xf9\x6e\x5e\x3f\xfd"
    7981             :         "\xde\xbd\x71\xf8\x86\x72\x89\x86\x5d\xf5\xa3\x2d\x20\xcd\xc9\x44"
    7982             :         "\xb6\x02\x2c\xac\x3c\x49\x82\xb1\x0d\x5e\xeb\x55\xc3\xe4\xde\x15"
    7983             :         "\x13\x46\x76\xfb\x6d\xe0\x44\x60\x65\xc9\x74\x40\xfa\x8c\x6a\x58" },
    7984             :       { GCRY_MAC_HMAC_SHA512, "?", "????????????????",
    7985             :         "\xd4\x43\x61\xfa\x3d\x3d\x57\xd6\xac\xc3\x9f\x1c\x3d\xd9\x26\x84"
    7986             :         "\x1f\xfc\x4d\xf2\xbf\x78\x87\x72\x5e\x6c\x3e\x00\x6d\x39\x5f\xfa"
    7987             :         "\xd7\x3a\xf7\x83\xb7\xb5\x61\xbd\xfb\x33\xe0\x03\x97\xa7\x72\x79"
    7988             :         "\x66\x66\xbf\xbd\x44\xfa\x04\x01\x1b\xc1\x48\x1d\x9e\xde\x5b\x8e" },
    7989             :       /* HMAC-SHA3 test vectors from
    7990             :        * http://wolfgang-ehrhardt.de/hmac-sha3-testvectors.html */
    7991             :       { GCRY_MAC_HMAC_SHA3_224,
    7992             :         "Hi There",
    7993             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    7994             :         "\x0b\x0b\x0b",
    7995             :         "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
    7996             :         "\x98\x84\x36\x76\x41\xd8\xc5\x9a\xf3\xc8\x60\xf7" },
    7997             :       { GCRY_MAC_HMAC_SHA3_256,
    7998             :         "Hi There",
    7999             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    8000             :         "\x0b\x0b\x0b",
    8001             :         "\xba\x85\x19\x23\x10\xdf\xfa\x96\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
    8002             :         "\x14\x0b\xb7\x18\x5e\x12\x02\xcd\xcc\x91\x75\x89\xf9\x5e\x16\xbb" },
    8003             :       { GCRY_MAC_HMAC_SHA3_512,
    8004             :         "Hi There",
    8005             :         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
    8006             :         "\x0b\x0b\x0b",
    8007             :         "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
    8008             :         "\xec\x15\x77\x0a\x7c\xab\xac\x53\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
    8009             :         "\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
    8010             :         "\x3a\x66\x8f\xd3\x88\x8b\xb8\x05\x37\xc0\xa0\xb8\x64\x07\x68\x9e" },
    8011             :       { GCRY_MAC_HMAC_SHA3_224, "what do ya want for nothing?", "Jefe",
    8012             :         "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11"
    8013             :         "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66" },
    8014             :       { GCRY_MAC_HMAC_SHA3_256, "what do ya want for nothing?", "Jefe",
    8015             :         "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87"
    8016             :         "\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5" },
    8017             :       { GCRY_MAC_HMAC_SHA3_384, "what do ya want for nothing?", "Jefe",
    8018             :         "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21"
    8019             :         "\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce"
    8020             :         "\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a" },
    8021             :       { GCRY_MAC_HMAC_SHA3_512, "what do ya want for nothing?", "Jefe",
    8022             :         "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83"
    8023             :         "\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
    8024             :         "\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
    8025             :         "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24" },
    8026             :       { GCRY_MAC_HMAC_SHA3_224,
    8027             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    8028             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8029             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8030             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8031             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8032             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8033             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8034             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8035             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8036             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8037             :         "\xaa\xaa\xaa",
    8038             :         "\xb9\x6d\x73\x0c\x14\x8c\x2d\xaa\xd8\x64\x9d\x83\xde\xfa\xa3\x71"
    8039             :         "\x97\x38\xd3\x47\x75\x39\x7b\x75\x71\xc3\x85\x15" },
    8040             :       { GCRY_MAC_HMAC_SHA3_256,
    8041             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    8042             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8043             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8044             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8045             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8046             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8047             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8048             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8049             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8050             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8051             :         "\xaa\xaa\xaa",
    8052             :         "\xa6\x07\x2f\x86\xde\x52\xb3\x8b\xb3\x49\xfe\x84\xcd\x6d\x97\xfb"
    8053             :         "\x6a\x37\xc4\xc0\xf6\x2a\xae\x93\x98\x11\x93\xa7\x22\x9d\x34\x67" },
    8054             :       { GCRY_MAC_HMAC_SHA3_384,
    8055             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    8056             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8057             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8058             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8059             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8060             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8061             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8062             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8063             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8064             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8065             :         "\xaa\xaa\xaa",
    8066             :         "\x71\x3d\xff\x03\x02\xc8\x50\x86\xec\x5a\xd0\x76\x8d\xd6\x5a\x13"
    8067             :         "\xdd\xd7\x90\x68\xd8\xd4\xc6\x21\x2b\x71\x2e\x41\x64\x94\x49\x11"
    8068             :         "\x14\x80\x23\x00\x44\x18\x5a\x99\x10\x3e\xd8\x20\x04\xdd\xbf\xcc" },
    8069             :       { GCRY_MAC_HMAC_SHA3_512,
    8070             :         "Test Using Larger Than Block-Size Key - Hash Key First",
    8071             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8072             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8073             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8074             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8075             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8076             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8077             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8078             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8079             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8080             :         "\xaa\xaa\xaa",
    8081             :         "\xb1\x48\x35\xc8\x19\xa2\x90\xef\xb0\x10\xac\xe6\xd8\x56\x8d\xc6"
    8082             :         "\xb8\x4d\xe6\x0b\xc4\x9b\x00\x4c\x3b\x13\xed\xa7\x63\x58\x94\x51"
    8083             :         "\xe5\xdd\x74\x29\x28\x84\xd1\xbd\xce\x64\xe6\xb9\x19\xdd\x61\xdc"
    8084             :         "\x9c\x56\xa2\x82\xa8\x1c\x0b\xd1\x4f\x1f\x36\x5b\x49\xb8\x3a\x5b" },
    8085             :       { GCRY_MAC_HMAC_SHA3_224,
    8086             :         "This is a test using a larger than block-size key and a larger "
    8087             :         "than block-size data. The key needs to be hashed before being "
    8088             :         "used by the HMAC algorithm.",
    8089             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8090             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8091             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8092             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8093             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8094             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8095             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8096             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8097             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8098             :         "\xaa\xaa\xaa",
    8099             :         "\xc7\x9c\x9b\x09\x34\x24\xe5\x88\xa9\x87\x8b\xbc\xb0\x89\xe0\x18"
    8100             :         "\x27\x00\x96\xe9\xb4\xb1\xa9\xe8\x22\x0c\x86\x6a" },
    8101             :       { GCRY_MAC_HMAC_SHA3_256,
    8102             :         "This is a test using a larger than block-size key and a larger "
    8103             :         "than block-size data. The key needs to be hashed before being "
    8104             :         "used by the HMAC algorithm.",
    8105             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8106             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8107             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8108             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8109             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8110             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8111             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8112             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8113             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8114             :         "\xaa\xaa\xaa",
    8115             :         "\xe6\xa3\x6d\x9b\x91\x5f\x86\xa0\x93\xca\xc7\xd1\x10\xe9\xe0\x4c"
    8116             :         "\xf1\xd6\x10\x0d\x30\x47\x55\x09\xc2\x47\x5f\x57\x1b\x75\x8b\x5a" },
    8117             :       { GCRY_MAC_HMAC_SHA3_384,
    8118             :         "This is a test using a larger than block-size key and a larger "
    8119             :         "than block-size data. The key needs to be hashed before being "
    8120             :         "used by the HMAC algorithm.",
    8121             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8122             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8123             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8124             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8125             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8126             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8127             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8128             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8129             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8130             :         "\xaa\xaa\xaa",
    8131             :         "\xca\xd1\x8a\x8f\xf6\xc4\xcc\x3a\xd4\x87\xb9\x5f\x97\x69\xe9\xb6"
    8132             :         "\x1c\x06\x2a\xef\xd6\x95\x25\x69\xe6\xe6\x42\x18\x97\x05\x4c\xfc"
    8133             :         "\x70\xb5\xfd\xc6\x60\x5c\x18\x45\x71\x12\xfc\x6a\xaa\xd4\x55\x85" },
    8134             :       { GCRY_MAC_HMAC_SHA3_512,
    8135             :         "This is a test using a larger than block-size key and a larger "
    8136             :         "than block-size data. The key needs to be hashed before being "
    8137             :         "used by the HMAC algorithm.",
    8138             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8139             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8140             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8141             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8142             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8143             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8144             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8145             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8146             :         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
    8147             :         "\xaa\xaa\xaa",
    8148             :         "\xdc\x03\x0e\xe7\x88\x70\x34\xf3\x2c\xf4\x02\xdf\x34\x62\x2f\x31"
    8149             :         "\x1f\x3e\x6c\xf0\x48\x60\xc6\xbb\xd7\xfa\x48\x86\x74\x78\x2b\x46"
    8150             :         "\x59\xfd\xbd\xf3\xfd\x87\x78\x52\x88\x5c\xfe\x6e\x22\x18\x5f\xe7"
    8151             :         "\xb2\xee\x95\x20\x43\x62\x9b\xc9\xd5\xf3\x29\x8a\x41\xd0\x2c\x66" },
    8152             :       { GCRY_MAC_HMAC_SHA3_224, "?", "????????????????",
    8153             :         "\x80\x2b\x3c\x84\xfe\x3e\x01\x22\x14\xf8\xba\x74\x79\xfd\xb5\x02"
    8154             :         "\xea\x0c\x06\xa4\x7e\x01\xe3\x2c\xc7\x24\x89\xc3" },
    8155             :       { GCRY_MAC_HMAC_SHA3_256, "?", "????????????????",
    8156             :         "\x6c\x7c\x96\x5b\x19\xba\xcd\x61\x69\x8a\x2c\x7a\x2b\x96\xa1\xc3"
    8157             :         "\x33\xa0\x3c\x5d\x54\x87\x37\x60\xc8\x2f\xa2\xa6\x12\x38\x8d\x1b" },
    8158             :       { GCRY_MAC_HMAC_SHA3_384, "?", "????????????????",
    8159             :         "\xc0\x20\xd0\x9b\xa7\xb9\xd5\xb8\xa6\xa4\xba\x20\x55\xd9\x0b\x35"
    8160             :         "\x8b\xe0\xb7\xec\x1e\x9f\xe6\xb9\xbd\xd5\xe9\x9b\xfc\x0a\x11\x3a"
    8161             :         "\x15\x41\xed\xfd\xef\x30\x8d\x03\xb8\xca\x3a\xa8\xc7\x2d\x89\x32" },
    8162             :       { GCRY_MAC_HMAC_SHA3_512, "?", "????????????????",
    8163             :         "\xb4\xef\x24\xd2\x07\xa7\x01\xb3\xe1\x81\x11\x22\x93\x83\x64\xe0"
    8164             :         "\x5e\xad\x03\xb7\x43\x4f\x87\xa1\x14\x8e\x17\x8f\x2a\x97\x7d\xe8"
    8165             :         "\xbd\xb0\x37\x3b\x67\xb9\x97\x36\xa5\x82\x9b\xdc\x0d\xe4\x5a\x8c"
    8166             :         "\x5e\xda\xb5\xca\xea\xa9\xb4\x6e\xba\xca\x25\xc8\xbf\xa1\x0e\xb0" },
    8167             :       { GCRY_MAC_HMAC_STRIBOG256,
    8168             :         "\x01\x26\xbd\xb8\x78\x00\xaf\x21\x43\x41\x45\x65\x63\x78\x01\x00",
    8169             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    8170             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
    8171             :         "\xa1\xaa\x5f\x7d\xe4\x02\xd7\xb3\xd3\x23\xf2\x99\x1c\x8d\x45\x34"
    8172             :         "\x01\x31\x37\x01\x0a\x83\x75\x4f\xd0\xaf\x6d\x7c\xd4\x92\x2e\xd9",
    8173             :         NULL, 16, 32 },
    8174             :       { GCRY_MAC_HMAC_STRIBOG512,
    8175             :         "\x01\x26\xbd\xb8\x78\x00\xaf\x21\x43\x41\x45\x65\x63\x78\x01\x00",
    8176             :         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
    8177             :         "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
    8178             :         "\xa5\x9b\xab\x22\xec\xae\x19\xc6\x5f\xbd\xe6\xe5\xf4\xe9\xf5\xd8"
    8179             :         "\x54\x9d\x31\xf0\x37\xf9\xdf\x9b\x90\x55\x00\xe1\x71\x92\x3a\x77"
    8180             :         "\x3d\x5f\x15\x30\xf2\xed\x7e\x96\x4c\xb2\xee\xdc\x29\xe9\xad\x2f"
    8181             :         "\x3a\xfe\x93\xb2\x81\x4f\x79\xf5\x00\x0f\xfc\x03\x66\xc2\x51\xe6",
    8182             :         NULL, 16, 32 },
    8183             :       /* CMAC AES and DES test vectors from
    8184             :          http://web.archive.org/web/20130930212819/http://csrc.nist.gov/publica\
    8185             :          tions/nistpubs/800-38B/Updated_CMAC_Examples.pdf */
    8186             :       { GCRY_MAC_CMAC_AES,
    8187             :         "",
    8188             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8189             :         "\xbb\x1d\x69\x29\xe9\x59\x37\x28\x7f\xa3\x7d\x12\x9b\x75\x67\x46" },
    8190             :       { GCRY_MAC_CMAC_AES,
    8191             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    8192             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8193             :         "\x07\x0a\x16\xb4\x6b\x4d\x41\x44\xf7\x9b\xdd\x9d\xd0\x4a\x28\x7c" },
    8194             :       { GCRY_MAC_CMAC_AES,
    8195             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8196             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8197             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
    8198             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8199             :         "\xdf\xa6\x67\x47\xde\x9a\xe6\x30\x30\xca\x32\x61\x14\x97\xc8\x27" },
    8200             :       { GCRY_MAC_CMAC_AES,
    8201             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8202             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8203             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
    8204             :         "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    8205             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8206             :         "\x51\xf0\xbe\xbf\x7e\x3b\x9d\x92\xfc\x49\x74\x17\x79\x36\x3c\xfe" },
    8207             :       { GCRY_MAC_CMAC_AES,
    8208             :         "",
    8209             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
    8210             :         "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
    8211             :         "\xd1\x7d\xdf\x46\xad\xaa\xcd\xe5\x31\xca\xc4\x83\xde\x7a\x93\x67" },
    8212             :       { GCRY_MAC_CMAC_AES,
    8213             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    8214             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
    8215             :         "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
    8216             :         "\x9e\x99\xa7\xbf\x31\xe7\x10\x90\x06\x62\xf6\x5e\x61\x7c\x51\x84" },
    8217             :       { GCRY_MAC_CMAC_AES,
    8218             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8219             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8220             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
    8221             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
    8222             :         "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
    8223             :         "\x8a\x1d\xe5\xbe\x2e\xb3\x1a\xad\x08\x9a\x82\xe6\xee\x90\x8b\x0e" },
    8224             :       { GCRY_MAC_CMAC_AES,
    8225             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8226             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8227             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
    8228             :         "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    8229             :         "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
    8230             :         "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
    8231             :         "\xa1\xd5\xdf\x0e\xed\x79\x0f\x79\x4d\x77\x58\x96\x59\xf3\x9a\x11" },
    8232             :       { GCRY_MAC_CMAC_AES,
    8233             :         "",
    8234             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
    8235             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
    8236             :         "\x02\x89\x62\xf6\x1b\x7b\xf8\x9e\xfc\x6b\x55\x1f\x46\x67\xd9\x83" },
    8237             :       { GCRY_MAC_CMAC_AES,
    8238             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    8239             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
    8240             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
    8241             :         "\x28\xa7\x02\x3f\x45\x2e\x8f\x82\xbd\x4b\xf2\x8d\x8c\x37\xc3\x5c" },
    8242             :       { GCRY_MAC_CMAC_AES,
    8243             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8244             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8245             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
    8246             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
    8247             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
    8248             :         "\xaa\xf3\xd8\xf1\xde\x56\x40\xc2\x32\xf5\xb1\x69\xb9\xc9\x11\xe6" },
    8249             :       { GCRY_MAC_CMAC_AES,
    8250             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8251             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8252             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
    8253             :         "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    8254             :         "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
    8255             :         "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
    8256             :         "\xe1\x99\x21\x90\x54\x9f\x6e\xd5\x69\x6a\x2c\x05\x6c\x31\x54\x10" },
    8257             :       { GCRY_MAC_CMAC_AES, "?", "????????????????????????????????",
    8258             :         "\x9f\x72\x73\x68\xb0\x49\x2e\xb1\x35\xa0\x1d\xf9\xa8\x0a\xf6\xee" },
    8259             :       { GCRY_MAC_CMAC_3DES,
    8260             :         "",
    8261             :         "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
    8262             :         "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
    8263             :         "\xb7\xa6\x88\xe1\x22\xff\xaf\x95" },
    8264             :       { GCRY_MAC_CMAC_3DES,
    8265             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96",
    8266             :         "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
    8267             :         "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
    8268             :         "\x8e\x8f\x29\x31\x36\x28\x37\x97" },
    8269             :       { GCRY_MAC_CMAC_3DES,
    8270             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8271             :         "\xae\x2d\x8a\x57",
    8272             :         "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
    8273             :         "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
    8274             :         "\x74\x3d\xdb\xe0\xce\x2d\xc2\xed" },
    8275             :       { GCRY_MAC_CMAC_3DES,
    8276             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8277             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
    8278             :         "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
    8279             :         "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5",
    8280             :         "\x33\xe6\xb1\x09\x24\x00\xea\xe5" },
    8281             :       { GCRY_MAC_CMAC_3DES,
    8282             :         "",
    8283             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
    8284             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
    8285             :         "\xbd\x2e\xbf\x9a\x3b\xa0\x03\x61" },
    8286             :       { GCRY_MAC_CMAC_3DES,
    8287             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96",
    8288             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
    8289             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
    8290             :         "\x4f\xf2\xab\x81\x3c\x53\xce\x83" },
    8291             :       { GCRY_MAC_CMAC_3DES,
    8292             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8293             :         "\xae\x2d\x8a\x57",
    8294             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
    8295             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
    8296             :         "\x62\xdd\x1b\x47\x19\x02\xbd\x4e" },
    8297             :       { GCRY_MAC_CMAC_3DES,
    8298             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8299             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51",
    8300             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5\x8a\x3d\x10\xba\x80\x57\x0d\x38"
    8301             :         "\x4c\xf1\x51\x34\xa2\x85\x0d\xd5",
    8302             :         "\x31\xb1\xe4\x31\xda\xbc\x4e\xb8" },
    8303             :       { GCRY_MAC_CMAC_3DES, "?", "????????????????????????",
    8304             :         "\xc1\x38\x13\xb2\x31\x8f\x3a\xdf" },
    8305             :       /* CMAC Camellia test vectors from
    8306             :          http://tools.ietf.org/html/draft-kato-ipsec-camellia-cmac96and128-05 */
    8307             :       { GCRY_MAC_CMAC_CAMELLIA,
    8308             :         "",
    8309             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8310             :         "\xba\x92\x57\x82\xaa\xa1\xf5\xd9\xa0\x0f\x89\x64\x80\x94\xfc\x71" },
    8311             :       { GCRY_MAC_CMAC_CAMELLIA,
    8312             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
    8313             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8314             :         "\x6d\x96\x28\x54\xa3\xb9\xfd\xa5\x6d\x7d\x45\xa9\x5e\xe1\x79\x93" },
    8315             :       { GCRY_MAC_CMAC_CAMELLIA,
    8316             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8317             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8318             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
    8319             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8320             :         "\x5c\x18\xd1\x19\xcc\xd6\x76\x61\x44\xac\x18\x66\x13\x1d\x9f\x22" },
    8321             :       { GCRY_MAC_CMAC_CAMELLIA,
    8322             :         "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
    8323             :         "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
    8324             :         "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
    8325             :         "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
    8326             :         "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
    8327             :         "\xc2\x69\x9a\x6e\xba\x55\xce\x9d\x93\x9a\x8a\x4e\x19\x46\x6e\xe9" },
    8328             :       { GCRY_MAC_CMAC_CAMELLIA, "?", "????????????????????????????????",
    8329             :         "\xba\x8a\x5a\x8d\xa7\x54\x26\x83\x3e\xb1\x20\xb5\x45\xd0\x9f\x4e" },
    8330             :       /* http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip */
    8331             :       { GCRY_MAC_GMAC_AES,
    8332             :         "",
    8333             :         "\x11\x75\x4c\xd7\x2a\xec\x30\x9b\xf5\x2f\x76\x87\x21\x2e\x89\x57",
    8334             :         "\x25\x03\x27\xc6\x74\xaa\xf4\x77\xae\xf2\x67\x57\x48\xcf\x69\x71",
    8335             :         "\x3c\x81\x9d\x9a\x9b\xed\x08\x76\x15\x03\x0b\x65" },
    8336             :       { GCRY_MAC_GMAC_AES,
    8337             :         "\x2b\x63\x26\x64\x29\x67\x4a\xb5\xe2\xea\xff\x63\x9c\x23\x14\x66"
    8338             :         "\x2f\x92\x57\x4b\x29\x8f\x57\x7a\xcf\x7d\x6f\x99\x1a\x87\x92\x1f"
    8339             :         "\xc2\x32\xea\xfc\xc7\xb1\x46\x48\x96\x63\x2d\x6c\x8a\xbe\x88\xc2"
    8340             :         "\xcc\xa4\x04\xdb\xf8\x7c\x20\x6a\x19\xd3\x73\xed\x99\x50\x17\x34"
    8341             :         "\x69\x13\x4d\x7c\x14\xc2\x84\x7d\xf2\x4a\x88\xc1\xc5\x3b\x4d\xe4"
    8342             :         "\x9d\xb3\x66\x39\x2b\x6d\xc6\x51\x27\x6e",
    8343             :         "\x0f\x3b\x17\xde\xae\x62\x13\x64\x55\x4a\xe5\x39\xdb\x09\xde\x11",
    8344             :         "\xff\xb0\xbb\x6d\xfc\x23\x58\x75\x4f\x17\x78\x48\x5b\x59\x65\x7f",
    8345             :         "\xa7\xf6\x07\x4c\xda\x56\x1c\xd2\xaa\x15\xba\x8c\x2f\xa6\x39\x42"
    8346             :         "\x59\x3e\x7c\xcf\x45\xc2\x9a\x57\xda\xd8\xa6\xe2\xea\x63\x54\xce"
    8347             :         "\x8a\xde\x39\xdd\xde\x4a\xc4\x5b\xbd\xc6\x63\xf0\xa5\x37\xc9\x48"
    8348             :         "\x18\x23\x5a\x73\xd8\xa0\x8b\xd8\x98\xab\xd0\x99\xe1\x5c\x08\x8c"
    8349             :         "\x6e\x21\x17\x5a\xf4\xe9\xa4\x99\x70\x12\x82\xed\x32\x81\x50\xa6"
    8350             :         "\xd9\x90\xe8\xec\x87\x85\xce\x26\x1b\xe1\xb8\x3f\xd8\x59\x1e\x57"
    8351             :         "\x76\x5f\x3d\xc1\x11\x3f\xd0\x2a\x40\xf5\x01\x6a\xd0\xd0\xed\xc4"
    8352             :         "\x92\x9a\x02\xe0\x17\xb2\xc5\xf4\x18\xd2\x96\xab\xd6\xc2\xea\x2e" },
    8353             :       { GCRY_MAC_GMAC_AES,
    8354             :         "\x61\x14\x60\x11\x90\xf6\xef\x5e\x59\x23\x5d\xc0\x42\x8c\x09\xe3"
    8355             :         "\x27\x0b\x19\xea",
    8356             :         "\x15\xa4\x14\x46\x6a\x7f\x90\xea\x32\xbf\xd7\xf6\xe5\x8b\xfa\x06"
    8357             :         "\xe9\x07\xfc\x41\x66\x89\xd9\x60\x39\x45\xd7\x94\x54\xd4\x23\x17",
    8358             :         "\x19\x6e\x0e\x01\x0f\x08\x56\xf9\x82\xb4\x08\x92\x41\xd6\x24\x84",
    8359             :         "\xab" },
    8360             :       { GCRY_MAC_GMAC_AES,
    8361             :         "\x8b\x5c\x12\x4b\xef\x6e\x2f\x0f\xe4\xd8\xc9\x5c\xd5\xfa\x4c\xf1",
    8362             :         "\x41\xc5\xda\x86\x67\xef\x72\x52\x20\xff\xe3\x9a\xe0\xac\x59\x0a"
    8363             :         "\xc9\xfc\xa7\x29\xab\x60\xad\xa0",
    8364             :         "\x20\x4b\xdb\x1b\xd6\x21\x54\xbf\x08\x92\x2a\xaa\x54\xee\xd7\x05",
    8365             :         "\x05\xad\x13\xa5\xe2\xc2\xab\x66\x7e\x1a\x6f\xbc" },
    8366             :       { GCRY_MAC_GMAC_AES, "?", "????????????????????????????????",
    8367             :         "\x84\x37\xc3\x42\xae\xf5\xd0\x40\xd3\x73\x90\xa9\x36\xed\x8a\x12" },
    8368             :       /* from NaCl */
    8369             :       { GCRY_MAC_POLY1305,
    8370             :         "\x8e\x99\x3b\x9f\x48\x68\x12\x73\xc2\x96\x50\xba\x32\xfc\x76\xce"
    8371             :         "\x48\x33\x2e\xa7\x16\x4d\x96\xa4\x47\x6f\xb8\xc5\x31\xa1\x18\x6a"
    8372             :         "\xc0\xdf\xc1\x7c\x98\xdc\xe8\x7b\x4d\xa7\xf0\x11\xec\x48\xc9\x72"
    8373             :         "\x71\xd2\xc2\x0f\x9b\x92\x8f\xe2\x27\x0d\x6f\xb8\x63\xd5\x17\x38"
    8374             :         "\xb4\x8e\xee\xe3\x14\xa7\xcc\x8a\xb9\x32\x16\x45\x48\xe5\x26\xae"
    8375             :         "\x90\x22\x43\x68\x51\x7a\xcf\xea\xbd\x6b\xb3\x73\x2b\xc0\xe9\xda"
    8376             :         "\x99\x83\x2b\x61\xca\x01\xb6\xde\x56\x24\x4a\x9e\x88\xd5\xf9\xb3"
    8377             :         "\x79\x73\xf6\x22\xa4\x3d\x14\xa6\x59\x9b\x1f\x65\x4c\xb4\x5a\x74"
    8378             :         "\xe3\x55\xa5",
    8379             :         "\xee\xa6\xa7\x25\x1c\x1e\x72\x91\x6d\x11\xc2\xcb\x21\x4d\x3c\x25"
    8380             :         "\x25\x39\x12\x1d\x8e\x23\x4e\x65\x2d\x65\x1f\xa4\xc8\xcf\xf8\x80",
    8381             :         "\xf3\xff\xc7\x70\x3f\x94\x00\xe5\x2a\x7d\xfb\x4b\x3d\x33\x05\xd9" },
    8382             :       /* from draft-nir-cfrg-chacha20-poly1305-03 */
    8383             :       { GCRY_MAC_POLY1305,
    8384             :         "Cryptographic Forum Research Group",
    8385             :         "\x85\xd6\xbe\x78\x57\x55\x6d\x33\x7f\x44\x52\xfe\x42\xd5\x06\xa8"
    8386             :         "\x01\x03\x80\x8a\xfb\x0d\xb2\xfd\x4a\xbf\xf6\xaf\x41\x49\xf5\x1b",
    8387             :         "\xa8\x06\x1d\xc1\x30\x51\x36\xc6\xc2\x2b\x8b\xaf\x0c\x01\x27\xa9" },
    8388             :       { GCRY_MAC_POLY1305,
    8389             :         "'Twas brillig, and the slithy toves\n"
    8390             :         "Did gyre and gimble in the wabe:\n"
    8391             :         "All mimsy were the borogoves,\n"
    8392             :         "And the mome raths outgrabe.",
    8393             :         "\x1c\x92\x40\xa5\xeb\x55\xd3\x8a\xf3\x33\x88\x86\x04\xf6\xb5\xf0"
    8394             :         "\x47\x39\x17\xc1\x40\x2b\x80\x09\x9d\xca\x5c\xbc\x20\x70\x75\xc0",
    8395             :         "\x45\x41\x66\x9a\x7e\xaa\xee\x61\xe7\x08\xdc\x7c\xbc\xc5\xeb\x62" },
    8396             :       { GCRY_MAC_POLY1305,
    8397             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8398             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8399             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8400             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8401             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8402             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8403             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8404             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8405             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8406             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8407             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8408             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8409             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8410             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8411             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8412             :         NULL,
    8413             :         191, 32 },
    8414             :       { GCRY_MAC_POLY1305,
    8415             :         "Any submission to the IETF intended by the Contributor for "
    8416             :         "publication as all or part of an IETF Internet-Draft or RFC and "
    8417             :         "any statement made within the context of an IETF activity is "
    8418             :         "considered an \"IETF Contribution\". Such statements include "
    8419             :         "oral statements in IETF sessions, as well as written and "
    8420             :         "electronic communications made at any time or place, which are "
    8421             :         "addressed to",
    8422             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8423             :         "\x36\xe5\xf6\xb5\xc5\xe0\x60\x70\xf0\xef\xca\x96\x22\x7a\x86\x3e",
    8424             :         "\x36\xe5\xf6\xb5\xc5\xe0\x60\x70\xf0\xef\xca\x96\x22\x7a\x86\x3e",
    8425             :         NULL,
    8426             :         0, 32 },
    8427             :       { GCRY_MAC_POLY1305,
    8428             :         "Any submission to the IETF intended by the Contributor for "
    8429             :         "publication as all or part of an IETF Internet-Draft or RFC and "
    8430             :         "any statement made within the context of an IETF activity is "
    8431             :         "considered an \"IETF Contribution\". Such statements include "
    8432             :         "oral statements in IETF sessions, as well as written and "
    8433             :         "electronic communications made at any time or place, which are "
    8434             :         "addressed to",
    8435             :         "\x36\xe5\xf6\xb5\xc5\xe0\x60\x70\xf0\xef\xca\x96\x22\x7a\x86\x3e"
    8436             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8437             :         "\xf3\x47\x7e\x7c\xd9\x54\x17\xaf\x89\xa6\xb8\x79\x4c\x31\x0c\xf0",
    8438             :         NULL,
    8439             :         0, 32 },
    8440             :       /* draft-irtf-cfrg-chacha20-poly1305-01 */
    8441             :       /* TV#5 */
    8442             :       { GCRY_MAC_POLY1305,
    8443             :         "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
    8444             :         "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8445             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8446             :         "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8447             :         NULL,
    8448             :         16, 32 },
    8449             :       /* TV#6 */
    8450             :       { GCRY_MAC_POLY1305,
    8451             :         "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8452             :         "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8453             :         "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
    8454             :         "\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8455             :         NULL,
    8456             :         16, 32 },
    8457             :       /* TV#7 */
    8458             :       { GCRY_MAC_POLY1305,
    8459             :         "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
    8460             :         "\xF0\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
    8461             :         "\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8462             :         "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8463             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8464             :         "\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8465             :         NULL,
    8466             :         48, 32 },
    8467             :       /* TV#8 */
    8468             :       { GCRY_MAC_POLY1305,
    8469             :         "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
    8470             :         "\xFB\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE"
    8471             :         "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01",
    8472             :         "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8473             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8474             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8475             :         NULL,
    8476             :         48, 32 },
    8477             :       /* TV#9 */
    8478             :       { GCRY_MAC_POLY1305,
    8479             :         "\xFD\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
    8480             :         "\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8481             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8482             :         "\xFA\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
    8483             :         NULL,
    8484             :         16, 32 },
    8485             :       /* TV#10 */
    8486             :       { GCRY_MAC_POLY1305,
    8487             :         "\xE3\x35\x94\xD7\x50\x5E\x43\xB9\x00\x00\x00\x00\x00\x00\x00\x00"
    8488             :         "\x33\x94\xD7\x50\x5E\x43\x79\xCD\x01\x00\x00\x00\x00\x00\x00\x00"
    8489             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    8490             :         "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8491             :         "\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00"
    8492             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8493             :         "\x14\x00\x00\x00\x00\x00\x00\x00\x55\x00\x00\x00\x00\x00\x00\x00",
    8494             :         NULL,
    8495             :         64, 32 },
    8496             :       /* TV#11 */
    8497             :       { GCRY_MAC_POLY1305,
    8498             :         "\xE3\x35\x94\xD7\x50\x5E\x43\xB9\x00\x00\x00\x00\x00\x00\x00\x00"
    8499             :         "\x33\x94\xD7\x50\x5E\x43\x79\xCD\x01\x00\x00\x00\x00\x00\x00\x00"
    8500             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8501             :         "\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00"
    8502             :         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8503             :         "\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    8504             :         NULL,
    8505             :         48, 32 },
    8506             :       /* from http://cr.yp.to/mac/poly1305-20050329.pdf */
    8507             :       { GCRY_MAC_POLY1305,
    8508             :         "\xf3\xf6",
    8509             :         "\x85\x1f\xc4\x0c\x34\x67\xac\x0b\xe0\x5c\xc2\x04\x04\xf3\xf7\x00"
    8510             :         "\x58\x0b\x3b\x0f\x94\x47\xbb\x1e\x69\xd0\x95\xb5\x92\x8b\x6d\xbc",
    8511             :         "\xf4\xc6\x33\xc3\x04\x4f\xc1\x45\xf8\x4f\x33\x5c\xb8\x19\x53\xde",
    8512             :         NULL,
    8513             :         0, 32 },
    8514             :       { GCRY_MAC_POLY1305,
    8515             :         "",
    8516             :         "\xa0\xf3\x08\x00\x00\xf4\x64\x00\xd0\xc7\xe9\x07\x6c\x83\x44\x03"
    8517             :         "\xdd\x3f\xab\x22\x51\xf1\x1a\xc7\x59\xf0\x88\x71\x29\xcc\x2e\xe7",
    8518             :         "\xdd\x3f\xab\x22\x51\xf1\x1a\xc7\x59\xf0\x88\x71\x29\xcc\x2e\xe7",
    8519             :         NULL,
    8520             :         0, 32 },
    8521             :       { GCRY_MAC_POLY1305,
    8522             :         "\x66\x3c\xea\x19\x0f\xfb\x83\xd8\x95\x93\xf3\xf4\x76\xb6\xbc\x24"
    8523             :         "\xd7\xe6\x79\x10\x7e\xa2\x6a\xdb\x8c\xaf\x66\x52\xd0\x65\x61\x36",
    8524             :         "\x48\x44\x3d\x0b\xb0\xd2\x11\x09\xc8\x9a\x10\x0b\x5c\xe2\xc2\x08"
    8525             :         "\x83\x14\x9c\x69\xb5\x61\xdd\x88\x29\x8a\x17\x98\xb1\x07\x16\xef",
    8526             :         "\x0e\xe1\xc1\x6b\xb7\x3f\x0f\x4f\xd1\x98\x81\x75\x3c\x01\xcd\xbe",
    8527             :         NULL,
    8528             :         0, 32 },
    8529             :       { GCRY_MAC_POLY1305,
    8530             :         "\xab\x08\x12\x72\x4a\x7f\x1e\x34\x27\x42\xcb\xed\x37\x4d\x94\xd1"
    8531             :         "\x36\xc6\xb8\x79\x5d\x45\xb3\x81\x98\x30\xf2\xc0\x44\x91\xfa\xf0"
    8532             :         "\x99\x0c\x62\xe4\x8b\x80\x18\xb2\xc3\xe4\xa0\xfa\x31\x34\xcb\x67"
    8533             :         "\xfa\x83\xe1\x58\xc9\x94\xd9\x61\xc4\xcb\x21\x09\x5c\x1b\xf9",
    8534             :         "\x12\x97\x6a\x08\xc4\x42\x6d\x0c\xe8\xa8\x24\x07\xc4\xf4\x82\x07"
    8535             :         "\x80\xf8\xc2\x0a\xa7\x12\x02\xd1\xe2\x91\x79\xcb\xcb\x55\x5a\x57",
    8536             :         "\x51\x54\xad\x0d\x2c\xb2\x6e\x01\x27\x4f\xc5\x11\x48\x49\x1f\x1b" },
    8537             :       { GCRY_MAC_POLY1305, "?", "????????????????????????????????",
    8538             :         "\xc3\x88\xce\x8a\x52\xd6\xe7\x21\x86\xfa\xaa\x5d\x2d\x16\xf9\xa3" },
    8539             :       /* from http://cr.yp.to/mac/poly1305-20050329.pdf */
    8540             :       { GCRY_MAC_POLY1305_AES,
    8541             :         "\xf3\xf6",
    8542             :         "\xec\x07\x4c\x83\x55\x80\x74\x17\x01\x42\x5b\x62\x32\x35\xad\xd6"
    8543             :         "\x85\x1f\xc4\x0c\x34\x67\xac\x0b\xe0\x5c\xc2\x04\x04\xf3\xf7\x00",
    8544             :         "\xf4\xc6\x33\xc3\x04\x4f\xc1\x45\xf8\x4f\x33\x5c\xb8\x19\x53\xde",
    8545             :         "\xfb\x44\x73\x50\xc4\xe8\x68\xc5\x2a\xc3\x27\x5c\xf9\xd4\x32\x7e",
    8546             :         0, 32 },
    8547             :       { GCRY_MAC_POLY1305_AES,
    8548             :         "",
    8549             :         "\x75\xde\xaa\x25\xc0\x9f\x20\x8e\x1d\xc4\xce\x6b\x5c\xad\x3f\xbf"
    8550             :         "\xa0\xf3\x08\x00\x00\xf4\x64\x00\xd0\xc7\xe9\x07\x6c\x83\x44\x03",
    8551             :         "\xdd\x3f\xab\x22\x51\xf1\x1a\xc7\x59\xf0\x88\x71\x29\xcc\x2e\xe7",
    8552             :         "\x61\xee\x09\x21\x8d\x29\xb0\xaa\xed\x7e\x15\x4a\x2c\x55\x09\xcc",
    8553             :         0, 32 },
    8554             :       { GCRY_MAC_POLY1305_AES,
    8555             :         "\x66\x3c\xea\x19\x0f\xfb\x83\xd8\x95\x93\xf3\xf4\x76\xb6\xbc\x24"
    8556             :         "\xd7\xe6\x79\x10\x7e\xa2\x6a\xdb\x8c\xaf\x66\x52\xd0\x65\x61\x36",
    8557             :         "\x6a\xcb\x5f\x61\xa7\x17\x6d\xd3\x20\xc5\xc1\xeb\x2e\xdc\xdc\x74"
    8558             :         "\x48\x44\x3d\x0b\xb0\xd2\x11\x09\xc8\x9a\x10\x0b\x5c\xe2\xc2\x08",
    8559             :         "\x0e\xe1\xc1\x6b\xb7\x3f\x0f\x4f\xd1\x98\x81\x75\x3c\x01\xcd\xbe",
    8560             :         "\xae\x21\x2a\x55\x39\x97\x29\x59\x5d\xea\x45\x8b\xc6\x21\xff\x0e",
    8561             :         0, 32 },
    8562             :       { GCRY_MAC_POLY1305_AES,
    8563             :         "\xab\x08\x12\x72\x4a\x7f\x1e\x34\x27\x42\xcb\xed\x37\x4d\x94\xd1"
    8564             :         "\x36\xc6\xb8\x79\x5d\x45\xb3\x81\x98\x30\xf2\xc0\x44\x91\xfa\xf0"
    8565             :         "\x99\x0c\x62\xe4\x8b\x80\x18\xb2\xc3\xe4\xa0\xfa\x31\x34\xcb\x67"
    8566             :         "\xfa\x83\xe1\x58\xc9\x94\xd9\x61\xc4\xcb\x21\x09\x5c\x1b\xf9",
    8567             :         "\xe1\xa5\x66\x8a\x4d\x5b\x66\xa5\xf6\x8c\xc5\x42\x4e\xd5\x98\x2d"
    8568             :         "\x12\x97\x6a\x08\xc4\x42\x6d\x0c\xe8\xa8\x24\x07\xc4\xf4\x82\x07",
    8569             :         "\x51\x54\xad\x0d\x2c\xb2\x6e\x01\x27\x4f\xc5\x11\x48\x49\x1f\x1b",
    8570             :         "\x9a\xe8\x31\xe7\x43\x97\x8d\x3a\x23\x52\x7c\x71\x28\x14\x9e\x3a",
    8571             :         0, 32 },
    8572             :       { GCRY_MAC_POLY1305_AES, "?", "????????????????????????????????",
    8573             :         "\x9d\xeb\xb0\xcd\x24\x90\xd3\x9b\x47\x78\x37\x0a\x81\xf2\x83\x2a",
    8574             :         "\x61\xee\x09\x21\x8d\x29\xb0\xaa\xed\x7e\x15\x4a\x2c\x55\x09\xcc",
    8575             :         0, 32 },
    8576             :       { 0 },
    8577             :     };
    8578             :   int i;
    8579             : 
    8580           1 :   if (verbose)
    8581           0 :     fprintf (stderr, "Starting MAC checks.\n");
    8582             : 
    8583         113 :   for (i = 0; algos[i].algo; i++)
    8584             :     {
    8585             :       size_t klen, dlen;
    8586             : 
    8587         112 :       if (gcry_mac_test_algo (algos[i].algo))
    8588             :         {
    8589           0 :           show_mac_not_available (algos[i].algo);
    8590           0 :           continue;
    8591             :         }
    8592         112 :       if (gcry_mac_test_algo (algos[i].algo) && in_fips_mode)
    8593             :         {
    8594           0 :           if (verbose)
    8595           0 :             fprintf (stderr, "  algorithm %d not available in fips mode\n",
    8596             :                      algos[i].algo);
    8597           0 :           continue;
    8598             :         }
    8599         112 :       if (verbose)
    8600           0 :         fprintf (stderr,
    8601             :                  "  checking %s [%i] for %d byte key and %d byte data\n",
    8602             :                  gcry_mac_algo_name (algos[i].algo),
    8603           0 :                  algos[i].algo, (int)strlen(algos[i].key),
    8604           0 :                  (!strcmp(algos[i].data, "!") || !strcmp(algos[i].data, "?"))
    8605           0 :                    ? 1000000 : (int)strlen(algos[i].data));
    8606             : 
    8607         112 :       klen = algos[i].klen ? algos[i].klen : strlen(algos[i].key);
    8608         112 :       dlen = algos[i].dlen ? algos[i].dlen : strlen (algos[i].data);
    8609             : 
    8610         233 :       check_one_mac (algos[i].algo, algos[i].data, dlen, algos[i].key, klen,
    8611         121 :                      algos[i].iv, algos[i].iv ? strlen(algos[i].iv) : 0,
    8612             :                      algos[i].expect, 0);
    8613         233 :       check_one_mac (algos[i].algo, algos[i].data, dlen, algos[i].key, klen,
    8614         121 :                      algos[i].iv, algos[i].iv ? strlen(algos[i].iv) : 0,
    8615             :                      algos[i].expect, 1);
    8616             :     }
    8617             : 
    8618           1 :   if (verbose)
    8619           0 :     fprintf (stderr, "Completed MAC checks.\n");
    8620           1 : }
    8621             : 
    8622             : /* Check that the signature SIG matches the hash HASH. PKEY is the
    8623             :    public key used for the verification. BADHASH is a hash value which
    8624             :    should result in a bad signature status. */
    8625             : static void
    8626         115 : verify_one_signature (gcry_sexp_t pkey, gcry_sexp_t hash,
    8627             :                       gcry_sexp_t badhash, gcry_sexp_t sig)
    8628             : {
    8629             :   gcry_error_t rc;
    8630             : 
    8631         115 :   rc = gcry_pk_verify (sig, hash, pkey);
    8632         115 :   if (rc)
    8633           0 :     fail ("gcry_pk_verify failed: %s\n", gpg_strerror (rc));
    8634         115 :   rc = gcry_pk_verify (sig, badhash, pkey);
    8635         115 :   if (gcry_err_code (rc) != GPG_ERR_BAD_SIGNATURE)
    8636           0 :     fail ("gcry_pk_verify failed to detect a bad signature: %s\n",
    8637             :           gpg_strerror (rc));
    8638         115 : }
    8639             : 
    8640             : 
    8641             : /* Test the public key sign function using the private ket SKEY. PKEY
    8642             :    is used for verification. */
    8643             : static void
    8644          14 : check_pubkey_sign (int n, gcry_sexp_t skey, gcry_sexp_t pkey, int algo)
    8645             : {
    8646             :   gcry_error_t rc;
    8647             :   gcry_sexp_t sig, badhash, hash;
    8648             :   int dataidx;
    8649             :   static const char baddata[] =
    8650             :     "(data\n (flags pkcs1)\n"
    8651             :     " (hash sha1 #11223344556677889900AABBCCDDEEFF10203041#))\n";
    8652             :   static const struct
    8653             :   {
    8654             :     const char *data;
    8655             :     int algo;
    8656             :     int expected_rc;
    8657             :   } datas[] =
    8658             :     {
    8659             :       { "(data\n (flags pkcs1)\n"
    8660             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8661             :         GCRY_PK_RSA,
    8662             :         0 },
    8663             :       { "(data\n (flags pkcs1-raw)\n"
    8664             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8665             :         GCRY_PK_RSA,
    8666             :         GPG_ERR_CONFLICT },
    8667             :       { "(data\n (flags oaep)\n"
    8668             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8669             :         0,
    8670             :         GPG_ERR_CONFLICT },
    8671             :       /* This test is to see whether hash algorithms not hard wired in
    8672             :          pubkey.c are detected:  */
    8673             :       { "(data\n (flags pkcs1)\n"
    8674             :         " (hash oid.1.3.14.3.2.29 "
    8675             :         "       #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8676             :         GCRY_PK_RSA,
    8677             :         0 },
    8678             :       { "(data\n (flags )\n"
    8679             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8680             :         0,
    8681             :         GPG_ERR_CONFLICT },
    8682             :       { "(data\n (flags pkcs1)\n"
    8683             :         " (hash foo #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8684             :         GCRY_PK_RSA,
    8685             :         GPG_ERR_DIGEST_ALGO },
    8686             :       { "(data\n (flags )\n" " (value #11223344556677889900AA#))\n",
    8687             :         0,
    8688             :         0 },
    8689             :       { "(data\n (flags )\n" " (value #0090223344556677889900AA#))\n",
    8690             :         0,
    8691             :         0 },
    8692             :       { "(data\n (flags raw)\n" " (value #11223344556677889900AA#))\n",
    8693             :         0,
    8694             :         0 },
    8695             :       { "(data\n (flags pkcs1)\n"
    8696             :         " (value #11223344556677889900AA#))\n",
    8697             :         GCRY_PK_RSA,
    8698             :         GPG_ERR_CONFLICT },
    8699             :       { "(data\n (flags pkcs1-raw)\n"
    8700             :         " (value #11223344556677889900AA#))\n",
    8701             :         GCRY_PK_RSA,
    8702             :         0 },
    8703             :       { "(data\n (flags raw foo)\n"
    8704             :         " (value #11223344556677889900AA#))\n",
    8705             :         0,
    8706             :         GPG_ERR_INV_FLAG },
    8707             :       { "(data\n (flags pss)\n"
    8708             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8709             :         GCRY_PK_RSA,
    8710             :         0 },
    8711             :       { "(data\n (flags pss)\n"
    8712             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#)\n"
    8713             :         " (random-override #4253647587980912233445566778899019283747#))\n",
    8714             :         GCRY_PK_RSA,
    8715             :         0 },
    8716             :       { NULL }
    8717             :     };
    8718             : 
    8719          14 :   rc = gcry_sexp_sscan (&badhash, NULL, baddata, strlen (baddata));
    8720          14 :   if (rc)
    8721           0 :     die ("converting data failed: %s\n", gpg_strerror (rc));
    8722             : 
    8723         210 :   for (dataidx = 0; datas[dataidx].data; dataidx++)
    8724             :     {
    8725         196 :       if (datas[dataidx].algo && datas[dataidx].algo != algo)
    8726          16 :         continue;
    8727             : 
    8728         180 :       if (verbose)
    8729           0 :         fprintf (stderr, "  test %d, signature test %d (%s)\n",
    8730             :                  n, dataidx, gcry_pk_algo_name (algo));
    8731             : 
    8732         180 :       rc = gcry_sexp_sscan (&hash, NULL, datas[dataidx].data,
    8733             :                             strlen (datas[dataidx].data));
    8734         180 :       if (rc)
    8735           0 :         die ("converting data failed: %s\n", gpg_strerror (rc));
    8736             : 
    8737         180 :       rc = gcry_pk_sign (&sig, hash, skey);
    8738         180 :       if (gcry_err_code (rc) != datas[dataidx].expected_rc)
    8739           0 :         fail ("gcry_pk_sign failed: %s\n", gpg_strerror (rc));
    8740             : 
    8741         180 :       if (!rc)
    8742         102 :         verify_one_signature (pkey, hash, badhash, sig);
    8743             : 
    8744         180 :       gcry_sexp_release (sig);
    8745         180 :       sig = NULL;
    8746         180 :       gcry_sexp_release (hash);
    8747         180 :       hash = NULL;
    8748             :     }
    8749             : 
    8750          14 :   gcry_sexp_release (badhash);
    8751          14 : }
    8752             : 
    8753             : 
    8754             : /* Test the public key sign function using the private ket SKEY. PKEY
    8755             :    is used for verification.  This variant is only used for ECDSA.  */
    8756             : static void
    8757           8 : check_pubkey_sign_ecdsa (int n, gcry_sexp_t skey, gcry_sexp_t pkey)
    8758             : {
    8759             :   gcry_error_t rc;
    8760             :   gcry_sexp_t sig, badhash, hash;
    8761             :   unsigned int nbits;
    8762             :   int dataidx;
    8763             :   static const struct
    8764             :   {
    8765             :     unsigned int nbits;
    8766             :     const char *data;
    8767             :     int expected_rc;
    8768             :     const char *baddata;
    8769             :     int dummy;
    8770             :   } datas[] =
    8771             :     {
    8772             :       { 192,
    8773             :         "(data (flags raw)\n"
    8774             :         " (value #00112233445566778899AABBCCDDEEFF0001020304050607#))",
    8775             :         0,
    8776             :         "(data (flags raw)\n"
    8777             :         " (value #80112233445566778899AABBCCDDEEFF0001020304050607#))",
    8778             :         0
    8779             :       },
    8780             :       { 256,
    8781             :         "(data (flags raw)\n"
    8782             :         " (value #00112233445566778899AABBCCDDEEFF"
    8783             :         /* */    "000102030405060708090A0B0C0D0E0F#))",
    8784             :         0,
    8785             :         "(data (flags raw)\n"
    8786             :         " (value #80112233445566778899AABBCCDDEEFF"
    8787             :         /* */    "000102030405060708090A0B0C0D0E0F#))",
    8788             :         0
    8789             :       },
    8790             :       { 256,
    8791             :         "(data (flags raw)\n"
    8792             :         " (hash sha256 #00112233445566778899AABBCCDDEEFF"
    8793             :         /* */          "000102030405060708090A0B0C0D0E0F#))",
    8794             :         0,
    8795             :         "(data (flags raw)\n"
    8796             :         " (hash sha256 #80112233445566778899AABBCCDDEEFF"
    8797             :         /* */          "000102030405060708090A0B0C0D0E0F#))",
    8798             :         0
    8799             :       },
    8800             :       { 256,
    8801             :         "(data (flags gost)\n"
    8802             :         " (value #00112233445566778899AABBCCDDEEFF"
    8803             :         /* */    "000102030405060708090A0B0C0D0E0F#))",
    8804             :         0,
    8805             :         "(data (flags gost)\n"
    8806             :         " (value #80112233445566778899AABBCCDDEEFF"
    8807             :         /* */    "000102030405060708090A0B0C0D0E0F#))",
    8808             :         0
    8809             :       },
    8810             :       { 512,
    8811             :         "(data (flags gost)\n"
    8812             :         " (value #00112233445566778899AABBCCDDEEFF"
    8813             :         /* */    "000102030405060708090A0B0C0D0E0F"
    8814             :         /* */    "000102030405060708090A0B0C0D0E0F"
    8815             :         /* */    "000102030405060708090A0B0C0D0E0F#))",
    8816             :         0,
    8817             :         "(data (flags gost)\n"
    8818             :         " (value #80112233445566778899AABBCCDDEEFF"
    8819             :         /* */    "000102030405060708090A0B0C0D0E0F"
    8820             :         /* */    "000102030405060708090A0B0C0D0E0F"
    8821             :         /* */    "000102030405060708090A0B0C0D0E0F#))",
    8822             :         0
    8823             :       },
    8824             :       { 0, NULL }
    8825             :     };
    8826             : 
    8827           8 :   nbits = gcry_pk_get_nbits (skey);
    8828             : 
    8829          48 :   for (dataidx = 0; datas[dataidx].data; dataidx++)
    8830             :     {
    8831          40 :       if (datas[dataidx].nbits != nbits)
    8832          27 :         continue;
    8833             : 
    8834          13 :       if (verbose)
    8835           0 :         fprintf (stderr, "  test %d, signature test %d (%u bit ecdsa)\n",
    8836             :                  n, dataidx, nbits);
    8837             : 
    8838          13 :       rc = gcry_sexp_sscan (&hash, NULL, datas[dataidx].data,
    8839             :                             strlen (datas[dataidx].data));
    8840          13 :       if (rc)
    8841           0 :         die ("converting data failed: %s\n", gpg_strerror (rc));
    8842          13 :       rc = gcry_sexp_sscan (&badhash, NULL, datas[dataidx].baddata,
    8843             :                             strlen (datas[dataidx].baddata));
    8844          13 :       if (rc)
    8845           0 :         die ("converting data failed: %s\n", gpg_strerror (rc));
    8846             : 
    8847          13 :       rc = gcry_pk_sign (&sig, hash, skey);
    8848          13 :       if (gcry_err_code (rc) != datas[dataidx].expected_rc)
    8849           0 :         fail ("gcry_pk_sign failed: %s\n", gpg_strerror (rc));
    8850             : 
    8851          13 :       if (!rc && verbose > 1)
    8852           0 :         show_sexp ("ECDSA signature:\n", sig);
    8853             : 
    8854          13 :       if (!rc)
    8855          13 :         verify_one_signature (pkey, hash, badhash, sig);
    8856             : 
    8857          13 :       gcry_sexp_release (sig);
    8858          13 :       sig = NULL;
    8859          13 :       gcry_sexp_release (badhash);
    8860          13 :       badhash = NULL;
    8861          13 :       gcry_sexp_release (hash);
    8862          13 :       hash = NULL;
    8863             :     }
    8864           8 : }
    8865             : 
    8866             : 
    8867             : static void
    8868          13 : check_pubkey_crypt (int n, gcry_sexp_t skey, gcry_sexp_t pkey, int algo)
    8869             : {
    8870             :   gcry_error_t rc;
    8871          13 :   gcry_sexp_t plain = NULL;
    8872          13 :   gcry_sexp_t ciph = NULL;
    8873          13 :   gcry_sexp_t data = NULL;
    8874             :   int dataidx;
    8875             :   static const struct
    8876             :   {
    8877             :     int algo;    /* If not 0 run test only if ALGO matches.  */
    8878             :     const char *data;
    8879             :     const char *hint;
    8880             :     int unpadded;
    8881             :     int encrypt_expected_rc;
    8882             :     int decrypt_expected_rc;
    8883             :     int special;
    8884             :   } datas[] =
    8885             :     {
    8886             :       { GCRY_PK_RSA,
    8887             :         "(data\n (flags pkcs1)\n"
    8888             :         " (value #11223344556677889900AA#))\n",
    8889             :         NULL,
    8890             :         0,
    8891             :         0,
    8892             :         0 },
    8893             :       { GCRY_PK_RSA,
    8894             :         "(data\n (flags pkcs1)\n"
    8895             :         " (value #11223344556677889900AA#))\n",
    8896             :         "(flags pkcs1)",
    8897             :         1,
    8898             :         0,
    8899             :         0 },
    8900             :       { GCRY_PK_RSA,
    8901             :         "(data\n (flags oaep)\n"
    8902             :         " (value #11223344556677889900AA#))\n",
    8903             :         "(flags oaep)",
    8904             :         1,
    8905             :         0,
    8906             :         0 },
    8907             :       { GCRY_PK_RSA,
    8908             :         "(data\n (flags oaep)\n (hash-algo sha1)\n"
    8909             :         " (value #11223344556677889900AA#))\n",
    8910             :         "(flags oaep)(hash-algo sha1)",
    8911             :         1,
    8912             :         0,
    8913             :         0 },
    8914             :       { GCRY_PK_RSA,
    8915             :         "(data\n (flags oaep)\n (hash-algo sha1)\n (label \"test\")\n"
    8916             :         " (value #11223344556677889900AA#))\n",
    8917             :         "(flags oaep)(hash-algo sha1)(label \"test\")",
    8918             :         1,
    8919             :         0,
    8920             :         0 },
    8921             :       { GCRY_PK_RSA,
    8922             :         "(data\n (flags oaep)\n (hash-algo sha1)\n (label \"test\")\n"
    8923             :         " (value #11223344556677889900AA#)\n"
    8924             :         " (random-override #4253647587980912233445566778899019283747#))\n",
    8925             :         "(flags oaep)(hash-algo sha1)(label \"test\")",
    8926             :         1,
    8927             :         0,
    8928             :         0 },
    8929             :       { 0,
    8930             :         "(data\n (flags )\n" " (value #11223344556677889900AA#))\n",
    8931             :         NULL,
    8932             :         1,
    8933             :         0,
    8934             :         0 },
    8935             :       { 0,
    8936             :         "(data\n (flags )\n" " (value #0090223344556677889900AA#))\n",
    8937             :         NULL,
    8938             :         1,
    8939             :         0,
    8940             :         0 },
    8941             :       { 0,
    8942             :         "(data\n (flags raw)\n" " (value #11223344556677889900AA#))\n",
    8943             :         NULL,
    8944             :         1,
    8945             :         0,
    8946             :         0 },
    8947             :       { GCRY_PK_RSA,
    8948             :         "(data\n (flags pkcs1)\n"
    8949             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8950             :         NULL,
    8951             :         0,
    8952             :         GPG_ERR_CONFLICT,
    8953             :         0},
    8954             :       { 0,
    8955             :         "(data\n (flags raw foo)\n"
    8956             :         " (hash sha1 #11223344556677889900AABBCCDDEEFF10203040#))\n",
    8957             :         NULL,
    8958             :         0,
    8959             :         GPG_ERR_INV_FLAG,
    8960             :         0},
    8961             :       { 0,
    8962             :         "(data\n (flags raw)\n"
    8963             :         " (value #11223344556677889900AA#))\n",
    8964             :         "(flags oaep)",
    8965             :         1,
    8966             :         0,
    8967             :         GPG_ERR_ENCODING_PROBLEM, 1 },
    8968             :       { GCRY_PK_RSA,
    8969             :         "(data\n (flags oaep)\n"
    8970             :         " (value #11223344556677889900AA#))\n",
    8971             :         "(flags pkcs1)",
    8972             :         1,
    8973             :         0,
    8974             :         GPG_ERR_ENCODING_PROBLEM, 1 },
    8975             :       { 0,
    8976             :         "(data\n (flags pss)\n"
    8977             :         " (value #11223344556677889900AA#))\n",
    8978             :         NULL,
    8979             :         0,
    8980             :         GPG_ERR_CONFLICT },
    8981             :       { 0, NULL }
    8982             :     };
    8983             : 
    8984             :   (void)n;
    8985             : 
    8986         195 :   for (dataidx = 0; datas[dataidx].data; dataidx++)
    8987             :     {
    8988         182 :       if (datas[dataidx].algo && datas[dataidx].algo != algo)
    8989           8 :         continue;
    8990             : 
    8991         174 :       if (verbose)
    8992           0 :         fprintf (stderr, "  encryption/decryption test %d (algo %d)\n",
    8993             :                  dataidx, algo);
    8994             : 
    8995         174 :       rc = gcry_sexp_sscan (&data, NULL, datas[dataidx].data,
    8996             :                             strlen (datas[dataidx].data));
    8997         174 :       if (rc)
    8998           0 :         die ("converting data failed: %s\n", gpg_strerror (rc));
    8999             : 
    9000         174 :       rc = gcry_pk_encrypt (&ciph, data, pkey);
    9001         174 :       if (gcry_err_code (rc) != datas[dataidx].encrypt_expected_rc)
    9002           0 :         fail ("gcry_pk_encrypt failed: %s\n", gpg_strerror (rc));
    9003             : 
    9004         174 :       if (!rc)
    9005             :         {
    9006         136 :           int expect_mismatch = 0;
    9007             : 
    9008             :           /* Insert decoding hint to CIPH. */
    9009         136 :           if (datas[dataidx].hint)
    9010             :             {
    9011             :               size_t hint_len, len;
    9012             :               char *hint, *buf;
    9013             :               gcry_sexp_t list;
    9014             : 
    9015             :               /* Convert decoding hint into canonical sexp. */
    9016          85 :               hint_len = gcry_sexp_new (&list, datas[dataidx].hint,
    9017             :                                         strlen (datas[dataidx].hint), 1);
    9018          85 :               hint_len = gcry_sexp_sprint (list, GCRYSEXP_FMT_CANON, NULL, 0);
    9019          85 :               hint = gcry_malloc (hint_len);
    9020          85 :               if (!hint)
    9021           0 :                 die ("can't allocate memory\n");
    9022          85 :               hint_len = gcry_sexp_sprint (list, GCRYSEXP_FMT_CANON, hint,
    9023             :                                            hint_len);
    9024          85 :               gcry_sexp_release (list);
    9025             : 
    9026             :               /* Convert CIPH into canonical sexp. */
    9027          85 :               len = gcry_sexp_sprint (ciph, GCRYSEXP_FMT_CANON, NULL, 0);
    9028          85 :               buf = gcry_malloc (len + hint_len);
    9029          85 :               if (!buf)
    9030           0 :                 die ("can't allocate memory\n");
    9031          85 :               len = gcry_sexp_sprint (ciph, GCRYSEXP_FMT_CANON, buf, len);
    9032             :               /* assert (!strcmp (buf, "(7:enc-val", 10)); */
    9033             : 
    9034             :               /* Copy decoding hint into CIPH. */
    9035          85 :               memmove (buf + 10 + hint_len, buf + 10, len - 10);
    9036          85 :               memcpy (buf + 10, hint, hint_len);
    9037          85 :               gcry_free (hint);
    9038          85 :               gcry_sexp_new (&list, buf, len + hint_len, 1);
    9039          85 :               gcry_free (buf);
    9040          85 :               gcry_sexp_release (ciph);
    9041          85 :               ciph = list;
    9042             :             }
    9043         136 :           rc = gcry_pk_decrypt (&plain, ciph, skey);
    9044         136 :           if (!rc && datas[dataidx].special == 1)
    9045             :             {
    9046             :               /* It may happen that OAEP formatted data which is
    9047             :                  decrypted as pkcs#1 data returns a valid pkcs#1
    9048             :                  frame.  However, the returned value will not be
    9049             :                  identical - thus we expect a mismatch and test further on
    9050             :                  whether this mismatch actually happened.  */
    9051           0 :               expect_mismatch = 1;
    9052             :             }
    9053         136 :           else if (gcry_err_code (rc) != datas[dataidx].decrypt_expected_rc)
    9054             :             {
    9055           0 :               if (verbose)
    9056             :                 {
    9057           0 :                   show_sexp ("  data:\n", data);
    9058           0 :                   show_sexp ("  ciph:\n", ciph);
    9059           0 :                   show_sexp ("   key:\n", skey);
    9060             :                 }
    9061           0 :               fail ("gcry_pk_decrypt failed: expected %d (%s), got %d (%s)\n",
    9062             :                     datas[dataidx].decrypt_expected_rc,
    9063           0 :                     gpg_strerror (datas[dataidx].decrypt_expected_rc),
    9064             :                     rc, gpg_strerror (rc));
    9065             :             }
    9066             : 
    9067         136 :           if (!rc && datas[dataidx].unpadded)
    9068             :             {
    9069             :               gcry_sexp_t p1, p2;
    9070             : 
    9071          99 :               p1 = gcry_sexp_find_token (data, "value", 0);
    9072          99 :               p2 = gcry_sexp_find_token (plain, "value", 0);
    9073          99 :               if (p1 && p2)
    9074             :                 {
    9075             :                   const char *s1, *s2;
    9076             :                   size_t n1, n2;
    9077             : 
    9078          60 :                   s1 = gcry_sexp_nth_data (p1, 1, &n1);
    9079          60 :                   s2 = gcry_sexp_nth_data (p2, 1, &n2);
    9080          60 :                   if (n1 != n2 || memcmp (s1, s2, n1))
    9081             :                     {
    9082           0 :                       if (expect_mismatch)
    9083           0 :                         expect_mismatch = 0;
    9084             :                       else
    9085           0 :                         fail ("gcry_pk_encrypt/gcry_pk_decrypt "
    9086             :                               "do not roundtrip\n");
    9087             :                     }
    9088             :                 }
    9089             : 
    9090          99 :               if (expect_mismatch)
    9091           0 :                 fail ("gcry_pk_encrypt/gcry_pk_decrypt "
    9092             :                       "expected mismatch did not happen\n");
    9093             : 
    9094          99 :               gcry_sexp_release (p1);
    9095          99 :               gcry_sexp_release (p2);
    9096             :             }
    9097             :         }
    9098             : 
    9099         174 :       gcry_sexp_release (plain);
    9100         174 :       plain = NULL;
    9101         174 :       gcry_sexp_release (ciph);
    9102         174 :       ciph = NULL;
    9103         174 :       gcry_sexp_release (data);
    9104         174 :       data = NULL;
    9105             :     }
    9106          13 : }
    9107             : 
    9108             : static void
    9109           0 : check_pubkey_grip (int n, const unsigned char *grip,
    9110             :                    gcry_sexp_t skey, gcry_sexp_t pkey, int algo)
    9111             : {
    9112             :   unsigned char sgrip[20], pgrip[20];
    9113             : 
    9114             :   (void)algo;
    9115             : 
    9116           0 :   if (!gcry_pk_get_keygrip (skey, sgrip))
    9117           0 :     die ("get keygrip for private RSA key failed\n");
    9118           0 :   if (!gcry_pk_get_keygrip (pkey, pgrip))
    9119           0 :     die ("[%i] get keygrip for public RSA key failed\n", n);
    9120           0 :   if (memcmp (sgrip, pgrip, 20))
    9121           0 :     fail ("[%i] keygrips don't match\n", n);
    9122           0 :   if (memcmp (sgrip, grip, 20))
    9123           0 :     fail ("wrong keygrip for RSA key\n");
    9124           0 : }
    9125             : 
    9126             : static void
    9127          22 : do_check_one_pubkey (int n, gcry_sexp_t skey, gcry_sexp_t pkey,
    9128             :                      const unsigned char *grip, int algo, int flags)
    9129             : {
    9130          22 :  if (flags & FLAG_SIGN)
    9131             :    {
    9132          22 :      if (algo == GCRY_PK_ECDSA)
    9133           8 :        check_pubkey_sign_ecdsa (n, skey, pkey);
    9134             :      else
    9135          14 :        check_pubkey_sign (n, skey, pkey, algo);
    9136             :    }
    9137          22 :  if (flags & FLAG_CRYPT)
    9138          13 :    check_pubkey_crypt (n, skey, pkey, algo);
    9139          22 :  if (grip && (flags & FLAG_GRIP))
    9140           0 :    check_pubkey_grip (n, grip, skey, pkey, algo);
    9141          22 : }
    9142             : 
    9143             : static void
    9144          11 : check_one_pubkey (int n, test_spec_pubkey_t spec)
    9145             : {
    9146          11 :   gcry_error_t err = GPG_ERR_NO_ERROR;
    9147             :   gcry_sexp_t skey, pkey;
    9148             : 
    9149          11 :   err = gcry_sexp_sscan (&skey, NULL, spec.key.secret,
    9150             :                          strlen (spec.key.secret));
    9151          11 :   if (!err)
    9152          11 :     err = gcry_sexp_sscan (&pkey, NULL, spec.key.public,
    9153             :                            strlen (spec.key.public));
    9154          11 :   if (err)
    9155           0 :     die ("converting sample key failed: %s\n", gpg_strerror (err));
    9156             : 
    9157          22 :   do_check_one_pubkey (n, skey, pkey,
    9158          11 :                        (const unsigned char*)spec.key.grip,
    9159             :                        spec.id, spec.flags);
    9160             : 
    9161          11 :   gcry_sexp_release (skey);
    9162          11 :   gcry_sexp_release (pkey);
    9163          11 : }
    9164             : 
    9165             : static void
    9166          11 : get_keys_new (gcry_sexp_t *pkey, gcry_sexp_t *skey)
    9167             : {
    9168             :   gcry_sexp_t key_spec, key, pub_key, sec_key;
    9169             :   int rc;
    9170          11 :   if (verbose)
    9171           0 :     fprintf (stderr, "  generating RSA key:");
    9172          11 :   rc = gcry_sexp_new (&key_spec,
    9173          11 :                       in_fips_mode ? "(genkey (rsa (nbits 4:2048)))"
    9174             :                       : "(genkey (rsa (nbits 4:1024)(transient-key)))",
    9175             :                       0, 1);
    9176          11 :   if (rc)
    9177           0 :     die ("error creating S-expression: %s\n", gpg_strerror (rc));
    9178          11 :   rc = gcry_pk_genkey (&key, key_spec);
    9179          11 :   gcry_sexp_release (key_spec);
    9180          11 :   if (rc)
    9181           0 :     die ("error generating RSA key: %s\n", gpg_strerror (rc));
    9182             : 
    9183          11 :   pub_key = gcry_sexp_find_token (key, "public-key", 0);
    9184          11 :   if (! pub_key)
    9185           0 :     die ("public part missing in key\n");
    9186             : 
    9187          11 :   sec_key = gcry_sexp_find_token (key, "private-key", 0);
    9188          11 :   if (! sec_key)
    9189           0 :     die ("private part missing in key\n");
    9190             : 
    9191          11 :   gcry_sexp_release (key);
    9192          11 :   *pkey = pub_key;
    9193          11 :   *skey = sec_key;
    9194          11 : }
    9195             : 
    9196             : static void
    9197          11 : check_one_pubkey_new (int n)
    9198             : {
    9199             :   gcry_sexp_t skey, pkey;
    9200             : 
    9201          11 :   get_keys_new (&pkey, &skey);
    9202          11 :   do_check_one_pubkey (n, skey, pkey, NULL,
    9203             :                        GCRY_PK_RSA, FLAG_SIGN | FLAG_CRYPT);
    9204          11 :   gcry_sexp_release (pkey);
    9205          11 :   gcry_sexp_release (skey);
    9206          11 : }
    9207             : 
    9208             : /* Run all tests for the public key functions. */
    9209             : static void
    9210           1 : check_pubkey (void)
    9211             : {
    9212             :   static const test_spec_pubkey_t pubkeys[] = {
    9213             :   {
    9214             :     GCRY_PK_RSA, FLAG_CRYPT | FLAG_SIGN,
    9215             :     {
    9216             :       "(private-key\n"
    9217             :       " (rsa\n"
    9218             :       "  (n #00e0ce96f90b6c9e02f3922beada93fe50a875eac6bcc18bb9a9cf2e84965caa"
    9219             :       "      2d1ff95a7f542465c6c0c19d276e4526ce048868a7a914fd343cc3a87dd74291"
    9220             :       "      ffc565506d5bbb25cbac6a0e2dd1f8bcaab0d4a29c2f37c950f363484bf269f7"
    9221             :       "      891440464baf79827e03a36e70b814938eebdc63e964247be75dc58b014b7ea2"
    9222             :       "      51#)\n"
    9223             :       "  (e #010001#)\n"
    9224             :       "  (d #046129F2489D71579BE0A75FE029BD6CDB574EBF57EA8A5B0FDA942CAB943B11"
    9225             :       "      7D7BB95E5D28875E0F9FC5FCC06A72F6D502464DABDED78EF6B716177B83D5BD"
    9226             :       "      C543DC5D3FED932E59F5897E92E6F58A0F33424106A3B6FA2CBF877510E4AC21"
    9227             :       "      C3EE47851E97D12996222AC3566D4CCB0B83D164074ABF7DE655FC2446DA1781"
    9228             :       "      #)\n"
    9229             :       "  (p #00e861b700e17e8afe6837e7512e35b6ca11d0ae47d8b85161c67baf64377213"
    9230             :       "      fe52d772f2035b3ca830af41d8a4120e1c1c70d12cc22f00d28d31dd48a8d424"
    9231             :       "      f1#)\n"
    9232             :       "  (q #00f7a7ca5367c661f8e62df34f0d05c10c88e5492348dd7bddc942c9a8f369f9"
    9233             :       "      35a07785d2db805215ed786e4285df1658eed3ce84f469b81b50d358407b4ad3"
    9234             :       "      61#)\n"
    9235             :       "  (u #304559a9ead56d2309d203811a641bb1a09626bc8eb36fffa23c968ec5bd891e"
    9236             :       "      ebbafc73ae666e01ba7c8990bae06cc2bbe10b75e69fcacb353a6473079d8e9b"
    9237             :       "      #)))\n",
    9238             : 
    9239             :       "(public-key\n"
    9240             :       " (rsa\n"
    9241             :       "  (n #00e0ce96f90b6c9e02f3922beada93fe50a875eac6bcc18bb9a9cf2e84965caa"
    9242             :       "      2d1ff95a7f542465c6c0c19d276e4526ce048868a7a914fd343cc3a87dd74291"
    9243             :       "      ffc565506d5bbb25cbac6a0e2dd1f8bcaab0d4a29c2f37c950f363484bf269f7"
    9244             :       "      891440464baf79827e03a36e70b814938eebdc63e964247be75dc58b014b7ea2"
    9245             :       "      51#)\n"
    9246             :       "  (e #010001#)))\n",
    9247             : 
    9248             :       "\x32\x10\x0c\x27\x17\x3e\xf6\xe9\xc4\xe9"
    9249             :       "\xa2\x5d\x3d\x69\xf8\x6d\x37\xa4\xf9\x39"}
    9250             :   },
    9251             :   {
    9252             :     GCRY_PK_DSA, FLAG_SIGN,
    9253             :     {
    9254             :       "(private-key\n"
    9255             :       " (DSA\n"
    9256             :       "  (p #00AD7C0025BA1A15F775F3F2D673718391D00456978D347B33D7B49E7F32EDAB"
    9257             :       "      96273899DD8B2BB46CD6ECA263FAF04A28903503D59062A8865D2AE8ADFB5191"
    9258             :       "      CF36FFB562D0E2F5809801A1F675DAE59698A9E01EFE8D7DCFCA084F4C6F5A44"
    9259             :       "      44D499A06FFAEA5E8EF5E01F2FD20A7B7EF3F6968AFBA1FB8D91F1559D52D877"
    9260             :       "      7B#)\n"
    9261             :       "  (q #00EB7B5751D25EBBB7BD59D920315FD840E19AEBF9#)\n"
    9262             :       "  (g #1574363387FDFD1DDF38F4FBE135BB20C7EE4772FB94C337AF86EA8E49666503"
    9263             :       "      AE04B6BE81A2F8DD095311E0217ACA698A11E6C5D33CCDAE71498ED35D13991E"
    9264             :       "      B02F09AB40BD8F4C5ED8C75DA779D0AE104BC34C960B002377068AB4B5A1F984"
    9265             :       "      3FBA91F537F1B7CAC4D8DD6D89B0D863AF7025D549F9C765D2FC07EE208F8D15"
    9266             :       "      #)\n"
    9267             :       "  (y #64B11EF8871BE4AB572AA810D5D3CA11A6CDBC637A8014602C72960DB135BF46"
    9268             :       "      A1816A724C34F87330FC9E187C5D66897A04535CC2AC9164A7150ABFA8179827"
    9269             :       "      6E45831AB811EEE848EBB24D9F5F2883B6E5DDC4C659DEF944DCFD80BF4D0A20"
    9270             :       "      42CAA7DC289F0C5A9D155F02D3D551DB741A81695B74D4C8F477F9C7838EB0FB"
    9271             :       "      #)\n"
    9272             :       "  (x #11D54E4ADBD3034160F2CED4B7CD292A4EBF3EC0#)))\n",
    9273             : 
    9274             :       "(public-key\n"
    9275             :       " (DSA\n"
    9276             :       "  (p #00AD7C0025BA1A15F775F3F2D673718391D00456978D347B33D7B49E7F32EDAB"
    9277             :       "      96273899DD8B2BB46CD6ECA263FAF04A28903503D59062A8865D2AE8ADFB5191"
    9278             :       "      CF36FFB562D0E2F5809801A1F675DAE59698A9E01EFE8D7DCFCA084F4C6F5A44"
    9279             :       "      44D499A06FFAEA5E8EF5E01F2FD20A7B7EF3F6968AFBA1FB8D91F1559D52D877"
    9280             :       "      7B#)\n"
    9281             :       "  (q #00EB7B5751D25EBBB7BD59D920315FD840E19AEBF9#)\n"
    9282             :       "  (g #1574363387FDFD1DDF38F4FBE135BB20C7EE4772FB94C337AF86EA8E49666503"
    9283             :       "      AE04B6BE81A2F8DD095311E0217ACA698A11E6C5D33CCDAE71498ED35D13991E"
    9284             :       "      B02F09AB40BD8F4C5ED8C75DA779D0AE104BC34C960B002377068AB4B5A1F984"
    9285             :       "      3FBA91F537F1B7CAC4D8DD6D89B0D863AF7025D549F9C765D2FC07EE208F8D15"
    9286             :       "      #)\n"
    9287             :       "  (y #64B11EF8871BE4AB572AA810D5D3CA11A6CDBC637A8014602C72960DB135BF46"
    9288             :       "      A1816A724C34F87330FC9E187C5D66897A04535CC2AC9164A7150ABFA8179827"
    9289             :       "      6E45831AB811EEE848EBB24D9F5F2883B6E5DDC4C659DEF944DCFD80BF4D0A20"
    9290             :       "      42CAA7DC289F0C5A9D155F02D3D551DB741A81695B74D4C8F477F9C7838EB0FB"
    9291             :       "      #)))\n",
    9292             : 
    9293             :       "\xc6\x39\x83\x1a\x43\xe5\x05\x5d\xc6\xd8"
    9294             :       "\x4a\xa6\xf9\xeb\x23\xbf\xa9\x12\x2d\x5b" }
    9295             :   },
    9296             :   {
    9297             :     GCRY_PK_ELG, FLAG_SIGN | FLAG_CRYPT,
    9298             :     {
    9299             :       "(private-key\n"
    9300             :       " (ELG\n"
    9301             :       "  (p #00B93B93386375F06C2D38560F3B9C6D6D7B7506B20C1773F73F8DE56E6CD65D"
    9302             :       "      F48DFAAA1E93F57A2789B168362A0F787320499F0B2461D3A4268757A7B27517"
    9303             :       "      B7D203654A0CD484DEC6AF60C85FEB84AAC382EAF2047061FE5DAB81A20A0797"
    9304             :       "      6E87359889BAE3B3600ED718BE61D4FC993CC8098A703DD0DC942E965E8F18D2"
    9305             :       "      A7#)\n"
    9306             :       "  (g #05#)\n"
    9307             :       "  (y #72DAB3E83C9F7DD9A931FDECDC6522C0D36A6F0A0FEC955C5AC3C09175BBFF2B"
    9308             :       "      E588DB593DC2E420201BEB3AC17536918417C497AC0F8657855380C1FCF11C5B"
    9309             :       "      D20DB4BEE9BDF916648DE6D6E419FA446C513AAB81C30CB7B34D6007637BE675"
    9310             :       "      56CE6473E9F9EE9B9FADD275D001563336F2186F424DEC6199A0F758F6A00FF4"
    9311             :       "      #)\n"
    9312             :       "  (x #03C28900087B38DABF4A0AB98ACEA39BB674D6557096C01D72E31C16BDD32214"
    9313             :       "      #)))\n",
    9314             : 
    9315             :       "(public-key\n"
    9316             :       " (ELG\n"
    9317             :       "  (p #00B93B93386375F06C2D38560F3B9C6D6D7B7506B20C1773F73F8DE56E6CD65D"
    9318             :       "      F48DFAAA1E93F57A2789B168362A0F787320499F0B2461D3A4268757A7B27517"
    9319             :       "      B7D203654A0CD484DEC6AF60C85FEB84AAC382EAF2047061FE5DAB81A20A0797"
    9320             :       "      6E87359889BAE3B3600ED718BE61D4FC993CC8098A703DD0DC942E965E8F18D2"
    9321             :       "      A7#)\n"
    9322             :       "  (g #05#)\n"
    9323             :       "  (y #72DAB3E83C9F7DD9A931FDECDC6522C0D36A6F0A0FEC955C5AC3C09175BBFF2B"
    9324             :       "      E588DB593DC2E420201BEB3AC17536918417C497AC0F8657855380C1FCF11C5B"
    9325             :       "      D20DB4BEE9BDF916648DE6D6E419FA446C513AAB81C30CB7B34D6007637BE675"
    9326             :       "      56CE6473E9F9EE9B9FADD275D001563336F2186F424DEC6199A0F758F6A00FF4"
    9327             :       "      #)))\n",
    9328             : 
    9329             :       "\xa7\x99\x61\xeb\x88\x83\xd2\xf4\x05\xc8"
    9330             :       "\x4f\xba\x06\xf8\x78\x09\xbc\x1e\x20\xe5" }
    9331             :   },
    9332             :   { /* ECDSA test.  */
    9333             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9334             :     {
    9335             :       "(private-key\n"
    9336             :       " (ecdsa\n"
    9337             :       "  (curve nistp192)\n"
    9338             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9339             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)\n"
    9340             :       "  (d #00D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D#)))\n",
    9341             : 
    9342             :       "(public-key\n"
    9343             :       " (ecdsa\n"
    9344             :       "  (curve nistp192)\n"
    9345             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9346             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)))\n",
    9347             : 
    9348             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9349             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9350             :   },
    9351             :   { /* ECDSA test with the public key algorithm given as "ecc".  */
    9352             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9353             :     {
    9354             :       "(private-key\n"
    9355             :       " (ecdsa\n"
    9356             :       "  (curve nistp192)\n"
    9357             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9358             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)\n"
    9359             :       "  (d #00D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D#)))\n",
    9360             : 
    9361             :       "(public-key\n"
    9362             :       " (ecc\n"
    9363             :       "  (curve nistp192)\n"
    9364             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9365             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)))\n",
    9366             : 
    9367             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9368             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9369             :   },
    9370             :   { /* ECDSA test with the private key algorithm given as "ecc".  */
    9371             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9372             :     {
    9373             :       "(private-key\n"
    9374             :       " (ecc\n"
    9375             :       "  (curve nistp192)\n"
    9376             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9377             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)\n"
    9378             :       "  (d #00D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D#)))\n",
    9379             : 
    9380             :       "(public-key\n"
    9381             :       " (ecdsa\n"
    9382             :       "  (curve nistp192)\n"
    9383             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9384             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)))\n",
    9385             : 
    9386             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9387             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9388             :   },
    9389             :   { /* ECDSA test with the key algorithms given as "ecc".  */
    9390             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9391             :     {
    9392             :       "(private-key\n"
    9393             :       " (ecc\n"
    9394             :       "  (curve nistp192)\n"
    9395             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9396             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)\n"
    9397             :       "  (d #00D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D#)))\n",
    9398             : 
    9399             :       "(public-key\n"
    9400             :       " (ecc\n"
    9401             :       "  (curve nistp192)\n"
    9402             :       "  (q #048532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE"
    9403             :       "        C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966#)))\n",
    9404             : 
    9405             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9406             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9407             :   },
    9408             :   { /* ECDSA test 256 bit.  */
    9409             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9410             :     {
    9411             :       "(private-key\n"
    9412             :       " (ecc\n"
    9413             :       "  (curve nistp256)\n"
    9414             :       "  (q #04D4F6A6738D9B8D3A7075C1E4EE95015FC0C9B7E4272D2B"
    9415             :       "      EB6644D3609FC781B71F9A8072F58CB66AE2F89BB1245187"
    9416             :       "      3ABF7D91F9E1FBF96BF2F70E73AAC9A283#)\n"
    9417             :       "  (d #5A1EF0035118F19F3110FB81813D3547BCE1E5BCE77D1F74"
    9418             :       "      4715E1D5BBE70378#)))\n",
    9419             : 
    9420             :       "(public-key\n"
    9421             :       " (ecc\n"
    9422             :       "  (curve nistp256)\n"
    9423             :       "  (q #04D4F6A6738D9B8D3A7075C1E4EE95015FC0C9B7E4272D2B"
    9424             :       "      EB6644D3609FC781B71F9A8072F58CB66AE2F89BB1245187"
    9425             :       "      3ABF7D91F9E1FBF96BF2F70E73AAC9A283#)))\n",
    9426             : 
    9427             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9428             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9429             :   },
    9430             :   { /* GOST R 34.10-2001/2012 test 256 bit.  */
    9431             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9432             :     {
    9433             :       "(private-key\n"
    9434             :       " (ecc\n"
    9435             :       "  (curve GOST2001-test)\n"
    9436             :       "  (q #047F2B49E270DB6D90D8595BEC458B50C58585BA1D4E9B78"
    9437             :       "      8F6689DBD8E56FD80B26F1B489D6701DD185C8413A977B3C"
    9438             :       "      BBAF64D1C593D26627DFFB101A87FF77DA#)\n"
    9439             :       "  (d #7A929ADE789BB9BE10ED359DD39A72C11B60961F49397EEE"
    9440             :       "      1D19CE9891EC3B28#)))\n",
    9441             : 
    9442             :       "(public-key\n"
    9443             :       " (ecc\n"
    9444             :       "  (curve GOST2001-test)\n"
    9445             :       "  (q #047F2B49E270DB6D90D8595BEC458B50C58585BA1D4E9B78"
    9446             :       "      8F6689DBD8E56FD80B26F1B489D6701DD185C8413A977B3C"
    9447             :       "      BBAF64D1C593D26627DFFB101A87FF77DA#)))\n",
    9448             : 
    9449             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9450             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9451             :   },
    9452             :   { /* GOST R 34.10-2012 test 512 bit.  */
    9453             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9454             :     {
    9455             :       "(private-key\n"
    9456             :       " (ecc\n"
    9457             :       "  (curve GOST2012-test)\n"
    9458             :       "  (q #04115DC5BC96760C7B48598D8AB9E740D4C4A85A65BE33C1"
    9459             :       "        815B5C320C854621DD5A515856D13314AF69BC5B924C8B"
    9460             :       "        4DDFF75C45415C1D9DD9DD33612CD530EFE137C7C90CD4"
    9461             :       "        0B0F5621DC3AC1B751CFA0E2634FA0503B3D52639F5D7F"
    9462             :       "        B72AFD61EA199441D943FFE7F0C70A2759A3CDB84C114E"
    9463             :       "        1F9339FDF27F35ECA93677BEEC#)\n"
    9464             :       "  (d #0BA6048AADAE241BA40936D47756D7C93091A0E851466970"
    9465             :       "      0EE7508E508B102072E8123B2200A0563322DAD2827E2714"
    9466             :       "      A2636B7BFD18AADFC62967821FA18DD4#)))\n",
    9467             : 
    9468             :       "(public-key\n"
    9469             :       " (ecc\n"
    9470             :       "  (curve GOST2012-test)\n"
    9471             :       "  (q #04115DC5BC96760C7B48598D8AB9E740D4C4A85A65BE33C1"
    9472             :       "        815B5C320C854621DD5A515856D13314AF69BC5B924C8B"
    9473             :       "        4DDFF75C45415C1D9DD9DD33612CD530EFE137C7C90CD4"
    9474             :       "        0B0F5621DC3AC1B751CFA0E2634FA0503B3D52639F5D7F"
    9475             :       "        B72AFD61EA199441D943FFE7F0C70A2759A3CDB84C114E"
    9476             :       "        1F9339FDF27F35ECA93677BEEC#)))\n"
    9477             : 
    9478             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9479             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9480             :   },
    9481             :   { /* secp256k1 test 256 bit.  */
    9482             :     GCRY_PK_ECDSA, FLAG_SIGN,
    9483             :     {
    9484             :       "(private-key\n"
    9485             :       " (ecc\n"
    9486             :       "  (curve secp256k1)\n"
    9487             :       "  (q #0439A36013301597DAEF41FBE593A02CC513D0B55527EC2D"
    9488             :       "      F1050E2E8FF49C85C23CBE7DED0E7CE6A594896B8F62888F"
    9489             :       "      DBC5C8821305E2EA42BF01E37300116281#)\n"
    9490             :       "  (d #E8F32E723DECF4051AEFAC8E2C93C9C5B214313817CDB01A"
    9491             :       "      1494B917C8436B35#)))\n",
    9492             : 
    9493             :       "(public-key\n"
    9494             :       " (ecc\n"
    9495             :       "  (curve secp256k1)\n"
    9496             :       "  (q #0439A36013301597DAEF41FBE593A02CC513D0B55527EC2D"
    9497             :       "      F1050E2E8FF49C85C23CBE7DED0E7CE6A594896B8F62888F"
    9498             :       "      DBC5C8821305E2EA42BF01E37300116281#)))\n"
    9499             : 
    9500             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    9501             :       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
    9502             :     }
    9503             :   };
    9504             :   int i;
    9505             : 
    9506           1 :   if (verbose)
    9507           0 :     fprintf (stderr, "Starting public key checks.\n");
    9508          12 :   for (i = 0; i < sizeof (pubkeys) / sizeof (*pubkeys); i++)
    9509          11 :     if (pubkeys[i].id)
    9510             :       {
    9511          11 :         if (gcry_pk_test_algo (pubkeys[i].id) && in_fips_mode)
    9512             :           {
    9513           0 :             if (verbose)
    9514           0 :               fprintf (stderr, "  algorithm %d not available in fips mode\n",
    9515             :                        pubkeys[i].id);
    9516           0 :             continue;
    9517             :           }
    9518          11 :         check_one_pubkey (i, pubkeys[i]);
    9519             :       }
    9520           1 :   if (verbose)
    9521           0 :     fprintf (stderr, "Completed public key checks.\n");
    9522             : 
    9523           1 :   if (verbose)
    9524           0 :     fprintf (stderr, "Starting additional public key checks.\n");
    9525          12 :   for (i = 0; i < sizeof (pubkeys) / sizeof (*pubkeys); i++)
    9526          11 :     if (pubkeys[i].id)
    9527             :       {
    9528          11 :         if (gcry_pk_test_algo (pubkeys[i].id) && in_fips_mode)
    9529             :           {
    9530           0 :             if (verbose)
    9531           0 :               fprintf (stderr, "  algorithm %d not available in fips mode\n",
    9532             :                        pubkeys[i].id);
    9533           0 :             continue;
    9534             :           }
    9535          11 :         check_one_pubkey_new (i);
    9536             :       }
    9537           1 :   if (verbose)
    9538           0 :     fprintf (stderr, "Completed additional public key checks.\n");
    9539             : 
    9540           1 : }
    9541             : 
    9542             : int
    9543           1 : main (int argc, char **argv)
    9544             : {
    9545             :   gpg_error_t err;
    9546           1 :   int last_argc = -1;
    9547           1 :   int debug = 0;
    9548           1 :   int use_fips = 0;
    9549           1 :   int selftest_only = 0;
    9550           1 :   int pubkey_only = 0;
    9551           1 :   int cipher_modes_only = 0;
    9552           1 :   int loop = 0;
    9553           1 :   unsigned int loopcount = 0;
    9554             : 
    9555           1 :   if (argc)
    9556           1 :     { argc--; argv++; }
    9557             : 
    9558           2 :   while (argc && last_argc != argc )
    9559             :     {
    9560           0 :       last_argc = argc;
    9561           0 :       if (!strcmp (*argv, "--"))
    9562             :         {
    9563           0 :           argc--; argv++;
    9564           0 :           break;
    9565             :         }
    9566           0 :       else if (!strcmp (*argv, "--verbose"))
    9567             :         {
    9568           0 :           verbose++;
    9569           0 :           argc--; argv++;
    9570             :         }
    9571           0 :       else if (!strcmp (*argv, "--debug"))
    9572             :         {
    9573           0 :           verbose = debug = 1;
    9574           0 :           argc--; argv++;
    9575             :         }
    9576           0 :       else if (!strcmp (*argv, "--fips"))
    9577             :         {
    9578           0 :           use_fips = 1;
    9579           0 :           argc--; argv++;
    9580             :         }
    9581           0 :       else if (!strcmp (*argv, "--selftest"))
    9582             :         {
    9583           0 :           selftest_only = 1;
    9584           0 :           verbose += 2;
    9585           0 :           argc--; argv++;
    9586             :         }
    9587           0 :       else if (!strcmp (*argv, "--pubkey"))
    9588             :         {
    9589           0 :           pubkey_only = 1;
    9590           0 :           argc--; argv++;
    9591             :         }
    9592           0 :       else if (!strcmp (*argv, "--cipher-modes"))
    9593             :         {
    9594           0 :           cipher_modes_only = 1;
    9595           0 :           argc--; argv++;
    9596             :         }
    9597           0 :       else if (!strcmp (*argv, "--die"))
    9598             :         {
    9599           0 :           die_on_error = 1;
    9600           0 :           argc--; argv++;
    9601             :         }
    9602           0 :       else if (!strcmp (*argv, "--loop"))
    9603             :         {
    9604           0 :           argc--; argv++;
    9605           0 :           if (argc)
    9606             :             {
    9607           0 :               loop = atoi (*argv);
    9608           0 :               argc--; argv++;
    9609             :             }
    9610             :         }
    9611           0 :       else if (!strcmp (*argv, "--disable-hwf"))
    9612             :         {
    9613           0 :           argc--;
    9614           0 :           argv++;
    9615           0 :           if (argc)
    9616             :             {
    9617           0 :               if (gcry_control (GCRYCTL_DISABLE_HWF, *argv, NULL))
    9618           0 :                 fprintf (stderr,
    9619             :                         PGM
    9620             :                         ": unknown hardware feature `%s' - option ignored\n",
    9621             :                         *argv);
    9622           0 :               argc--;
    9623           0 :               argv++;
    9624             :             }
    9625             :         }
    9626             :     }
    9627             : 
    9628           1 :   gcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose);
    9629             : 
    9630           1 :   if (use_fips)
    9631           0 :     gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
    9632             : 
    9633             :   /* Check that we test exactly our version - including the patchlevel.  */
    9634           1 :   if (strcmp (GCRYPT_VERSION, gcry_check_version (NULL)))
    9635           0 :     die ("version mismatch; pgm=%s, library=%s\n",
    9636             :          GCRYPT_VERSION,gcry_check_version (NULL));
    9637             : 
    9638           1 :   if ( gcry_fips_mode_active () )
    9639           0 :     in_fips_mode = 1;
    9640             : 
    9641           1 :   if (!in_fips_mode)
    9642           1 :     gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
    9643             : 
    9644           1 :   if (verbose)
    9645           0 :     gcry_set_progress_handler (progress_handler, NULL);
    9646             : 
    9647           1 :   gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
    9648           1 :   if (debug)
    9649           0 :     gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
    9650             :   /* No valuable keys are create, so we can speed up our RNG. */
    9651           1 :   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
    9652             : 
    9653             :   do
    9654             :     {
    9655           1 :       if (pubkey_only)
    9656           0 :         check_pubkey ();
    9657           1 :       else if (cipher_modes_only)
    9658             :         {
    9659           0 :           check_ciphers ();
    9660           0 :           check_cipher_modes ();
    9661             :         }
    9662           1 :       else if (!selftest_only)
    9663             :         {
    9664           1 :           check_ciphers ();
    9665           1 :           check_cipher_modes ();
    9666           1 :           check_bulk_cipher_modes ();
    9667           1 :           check_digests ();
    9668           1 :           check_hmac ();
    9669           1 :           check_mac ();
    9670           1 :           check_pubkey ();
    9671             :         }
    9672           1 :       loopcount++;
    9673           1 :       if (loop)
    9674             :         {
    9675           0 :           fprintf (stderr, "Test iteration %u completed.\n", loopcount);
    9676           0 :           if (loop != -1)
    9677           0 :             loop--;
    9678             :         }
    9679             :     }
    9680           1 :   while (loop);
    9681             : 
    9682           1 :   if (in_fips_mode && !selftest_only)
    9683           0 :     {
    9684             :       /* If we are in fips mode do some more tests. */
    9685             :       gcry_md_hd_t md;
    9686             : 
    9687             :       /* First trigger a self-test.  */
    9688           0 :       gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
    9689           0 :       if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0))
    9690           0 :         fail ("not in operational state after self-test\n");
    9691             : 
    9692             :       /* Get us into the error state.  */
    9693           0 :       err = gcry_md_open (&md, GCRY_MD_SHA1, 0);
    9694           0 :       if (err)
    9695           0 :         fail ("failed to open SHA-1 hash context: %s\n", gpg_strerror (err));
    9696             :       else
    9697             :         {
    9698           0 :           err = gcry_md_enable (md, GCRY_MD_SHA256);
    9699           0 :           if (err)
    9700           0 :             fail ("failed to add SHA-256 hash context: %s\n",
    9701             :                   gpg_strerror (err));
    9702             :           else
    9703             :             {
    9704             :               /* gcry_md_get_algo is only defined for a context with
    9705             :                  just one digest algorithm.  With our setup it should
    9706             :                  put the oibrary intoerror state.  */
    9707           0 :               fputs ("Note: Two lines with error messages follow "
    9708             :                      "- this is expected\n", stderr);
    9709           0 :               gcry_md_get_algo (md);
    9710           0 :               gcry_md_close (md);
    9711           0 :               if (gcry_control (GCRYCTL_OPERATIONAL_P, 0))
    9712           0 :                 fail ("expected error state but still in operational state\n");
    9713             :               else
    9714             :                 {
    9715             :                   /* Now run a self-test and to get back into
    9716             :                      operational state.  */
    9717           0 :                   gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
    9718           0 :                   if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0))
    9719           0 :                     fail ("did not reach operational after error "
    9720             :                           "and self-test\n");
    9721             :                 }
    9722             :             }
    9723             :         }
    9724             : 
    9725             :     }
    9726             :   else
    9727             :     {
    9728             :       /* If in standard mode, run selftests.  */
    9729           1 :       if (gcry_control (GCRYCTL_SELFTEST, 0))
    9730           0 :         fail ("running self-test failed\n");
    9731             :     }
    9732             : 
    9733           1 :   if (verbose)
    9734           0 :     fprintf (stderr, "\nAll tests completed. Errors: %i\n", error_count);
    9735             : 
    9736           1 :   if (in_fips_mode && !gcry_fips_mode_active ())
    9737           0 :     fprintf (stderr, "FIPS mode is not anymore active\n");
    9738             : 
    9739           1 :   return error_count ? 1 : 0;
    9740             : }

Generated by: LCOV version 1.11