示例#1
0
文件: keytool.c 项目: gpg/gsti
static void
genkey (int algo)
{
  gcry_sexp_t s_key = NULL, s_param = NULL;
  gsti_error_t err;
  gsti_key_t key;
  const char * s;
  int nbits = 1024;

  algo = SSH_PK_RSA; /* XXX */
  switch (algo)
    {
    case SSH_PK_DSS: s = "(genkey(dsa(nbits %d)))"; break;
    case SSH_PK_RSA: s = "(genkey(rsa(nbits %d)))"; break;
    default:         printf ("invalid pk algo '%d'\n", algo); return;
    }
  err = gcry_sexp_build (&s_param, NULL, s, nbits);
  if (!err)
    err = gcry_pk_genkey (&s_key, s_param);
  if (err)
    printf ("genkey: %s\n", gsti_strerror (err));

  gcry_sexp_release (s_param);
  gcry_sexp_dump (s_key);

  gsti_key_from_sexp (s_key, &key);
  gcry_sexp_release (s_key);

  gsti_key_save (RSA_PUBKEY, 0, key);
  gsti_key_save (RSA_SECKEY, 1, key);
  gsti_key_free (key);
}
示例#2
0
int p2p_sign(unsigned char *msg, size_t msglen, unsigned char *buf, size_t buflen, gcry_sexp_t d_key) {
    gcry_sexp_t data;
    size_t err;
    
    gcry_sexp_build(&data, &err, "(data (flags pkcs1) (hash sha256 %b))", msglen, msg);
    gcry_sexp_dump(data);
    return 0;
}
示例#3
0
void
test_sexp ( int argc, char **argv )
{
    int rc, nbits;
    gcry_sexp_t sexp;
    gcry_mpi_t key[3];
    size_t n;
    char *buf;

    if ( gcry_mpi_scan( &key[0], GCRYMPI_FMT_HEX, elg_testkey1.p, NULL ) )
	BUG();
    if ( gcry_mpi_scan( &key[1], GCRYMPI_FMT_HEX, elg_testkey1.g, NULL ) )
	BUG();
    if ( gcry_mpi_scan( &key[2], GCRYMPI_FMT_HEX, elg_testkey1.y, NULL ) )
	BUG();

    /* get nbits from a key */
    rc = gcry_sexp_build ( &sexp, NULL,
			   "(public-key(elg(p%m)(g%m)(y%m)))",
				  key[0], key[1], key[2] );
    fputs ( "DUMP of PK:\n", stderr );
    gcry_sexp_dump ( sexp );
    {  gcry_sexp_t x;
       x = gcry_sexp_cdr ( sexp );
       fputs ( "DUMP of CDR:\n", stderr );
       gcry_sexp_dump ( x );
       gcry_sexp_release ( x );
    }
    nbits = gcry_pk_get_nbits( sexp );
    printf ( "elg_testkey1 - nbits=%d\n", nbits );
    n = gcry_sexp_sprint ( sexp, 0, NULL, 0 );
    buf = gcry_xmalloc ( n );
    n = gcry_sexp_sprint ( sexp, 0, buf, n );
    printf ( "sprint length=%u\n", (unsigned int)n );
    gcry_free ( buf );
    gcry_sexp_release( sexp );
}
示例#4
0
void
test_genkey ( int argc, char **argv )
{
    int rc, nbits = 1024;
    gcry_sexp_t s_parms, s_key;

    gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
    rc = gcry_sexp_build ( &s_parms, NULL, "(genkey(dsa(nbits %d)))", nbits );
    rc = gcry_pk_genkey( &s_key, s_parms );
    if ( rc ) {
	fprintf ( stderr, "genkey failed: %s\n", gpg_strerror (rc) );
	return;
    }
    gcry_sexp_release( s_parms );
    gcry_sexp_dump ( s_key );
    gcry_sexp_release( s_key );
}