Example #1
0
static void
check_get_params (void)
{
  gcry_sexp_t param;
  const char *name;

  param = gcry_pk_get_param (GCRY_PK_ECDSA, sample_key_1_curve);
  if (!param)
    fail ("error gerring parameters for `%s'\n", sample_key_1_curve);

  name = gcry_pk_get_curve (param, 0, NULL);
  if (!name)
    fail ("get_param: curve name not found for sample_key_1\n");
  else if (strcmp (name, sample_key_1_curve))
    fail ("get_param: expected curve name %s but got %s for sample_key_1\n",
          sample_key_1_curve, name);

  gcry_sexp_release (param);


  param = gcry_pk_get_param (GCRY_PK_ECDSA, sample_key_2_curve);
  if (!param)
    fail ("error gerring parameters for `%s'\n", sample_key_2_curve);

  name = gcry_pk_get_curve (param, 0, NULL);
  if (!name)
    fail ("get_param: curve name not found for sample_key_2\n");
  else if (strcmp (name, sample_key_2_curve))
    fail ("get_param: expected curve name %s but got %s for sample_key_2\n",
          sample_key_2_curve, name);

  gcry_sexp_release (param);
}
Example #2
0
static void
list_curves (void)
{
  int idx;
  const char *name;
  unsigned int nbits;

  for (idx=0; (name = gcry_pk_get_curve (NULL, idx, &nbits)); idx++)
    {
      if (verbose)
        printf ("%s - %u bits\n", name, nbits);
    }
  if (idx != N_CURVES)
    fail ("expected %d curves but got %d\n", N_CURVES, idx);
  if (gcry_pk_get_curve (NULL, -1, NULL))
    fail ("curve iteration failed\n");
}
Example #3
0
static void
check_matching (void)
{
  gpg_error_t err;
  gcry_sexp_t key;
  const char *name;
  unsigned int nbits;

  err = gcry_sexp_new (&key, sample_key_1, 0, 1);
  if (err)
    die ("parsing s-expression string failed: %s\n", gpg_strerror (err));
  name = gcry_pk_get_curve (key, 0, &nbits);
  if (!name)
    fail ("curve name not found for sample_key_1\n");
  else if (strcmp (name, sample_key_1_curve))
    fail ("expected curve name %s but got %s for sample_key_1\n",
          sample_key_1_curve, name);
  else if (nbits != sample_key_1_nbits)
    fail ("expected curve size %u but got %u for sample_key_1\n",
          sample_key_1_nbits, nbits);

  gcry_sexp_release (key);

  err = gcry_sexp_new (&key, sample_key_2, 0, 1);
  if (err)
    die ("parsing s-expression string failed: %s\n", gpg_strerror (err));
  name = gcry_pk_get_curve (key, 0, &nbits);
  if (!name)
    fail ("curve name not found for sample_key_2\n");
  else if (strcmp (name, sample_key_2_curve))
    fail ("expected curve name %s but got %s for sample_key_2\n",
          sample_key_2_curve, name);
  else if (nbits != sample_key_2_nbits)
    fail ("expected curve size %u but got %u for sample_key_2\n",
          sample_key_2_nbits, nbits);

  gcry_sexp_release (key);
}
Example #4
0
static void
check_get_params (void)
{
  gcry_sexp_t param;
  const char *name;

  param = gcry_pk_get_param (GCRY_PK_ECDSA, sample_key_1_curve);
  if (!param)
    fail ("error gerring parameters for `%s'\n", sample_key_1_curve);

  name = gcry_pk_get_curve (param, 0, NULL);
  if (!name)
    fail ("get_param: curve name not found for sample_key_1\n");
  else if (strcmp (name, sample_key_1_curve))
    fail ("get_param: expected curve name %s but got %s for sample_key_1\n",
          sample_key_1_curve, name);

  gcry_sexp_release (param);

  /* Brainpool curves are not supported in fips mode */
  if (gcry_fips_mode_active())
    return;

  param = gcry_pk_get_param (GCRY_PK_ECDSA, sample_key_2_curve);
  if (!param)
    fail ("error gerring parameters for `%s'\n", sample_key_2_curve);

  name = gcry_pk_get_curve (param, 0, NULL);
  if (!name)
    fail ("get_param: curve name not found for sample_key_2\n");
  else if (strcmp (name, sample_key_2_curve))
    fail ("get_param: expected curve name %s but got %s for sample_key_2\n",
          sample_key_2_curve, name);

  gcry_sexp_release (param);
}