pqc-thunderbird / libgcrypt

GNU General Public License v2.0
1 stars 0 forks source link

HMAC test ignores failure when setting key (not security relevant) #21

Closed falko-strenzke closed 1 year ago

falko-strenzke commented 1 year ago

HMAC test ignores failure when setting key

tests/basic.c:

static void
check_one_hmac (int algo, const char *data, int datalen,
        const char *key, int keylen, const char *expect)
{
  gcry_md_hd_t hd, hd2;
  unsigned char *p;
  int mdlen;
  int i;
  gcry_error_t err = 0;

  [...]

  err = gcry_md_setkey( hd, key, keylen );
  if (err)
    {
      if (in_fips_mode)
        {
          if (verbose)
            fprintf (stderr,
                     "  shorter key (%d) rejected correctly in fips mode\n",
                     keylen);
        }
      gcry_md_close (hd);
      return;
    }

The equivalent MAC test does it correctly, though:

  err = gcry_mac_setkey (hd, key, keylen);
  if (err)
    {
      if (in_fips_mode)
        {
          if (verbose)
            fprintf (stderr,
                     "  shorter key (%d) rejected correctly in fips mode\n",
                     keylen);
        }
      else
        fail("algo %d, mac gcry_mac_setkey failed: %s\n", algo, gpg_strerror (err));
      goto out;
    }