2
* Copyright (C) 2003, 2004, 2005, 2008 Free Software Foundation
4
* Author: Nikos Mavrogiannopoulos
6
* This file is part of GNUTLS.
8
* The GNUTLS library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* as published by the Free Software Foundation; either version 2.1 of
11
* the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25
/* This file contains code for DSA keys.
28
#include <gnutls_int.h>
29
#include <gnutls_errors.h>
30
#include <gnutls_datum.h>
34
/* resarr will contain: p(0), q(1), g(2), y(3), x(4).
37
_gnutls_dsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
41
gcry_sexp_t parms, key, list;
43
/* FIXME: Remove me once we depend on 1.3.1 */
44
if (bits > 1024 && gcry_check_version("1.3.1")==NULL)
47
return GNUTLS_E_INVALID_REQUEST;
53
return GNUTLS_E_INVALID_REQUEST;
56
ret = gcry_sexp_build (&parms, NULL, "(genkey(dsa(nbits %d)))", bits);
60
return GNUTLS_E_INTERNAL_ERROR;
63
/* generate the DSA key
65
ret = gcry_pk_genkey (&key, parms);
66
gcry_sexp_release (parms);
71
return GNUTLS_E_INTERNAL_ERROR;
74
list = gcry_sexp_find_token (key, "p", 0);
78
gcry_sexp_release (key);
79
return GNUTLS_E_INTERNAL_ERROR;
82
resarr[0] = gcry_sexp_nth_mpi (list, 1, 0);
83
gcry_sexp_release (list);
85
list = gcry_sexp_find_token (key, "q", 0);
89
gcry_sexp_release (key);
90
return GNUTLS_E_INTERNAL_ERROR;
93
resarr[1] = gcry_sexp_nth_mpi (list, 1, 0);
94
gcry_sexp_release (list);
96
list = gcry_sexp_find_token (key, "g", 0);
100
gcry_sexp_release (key);
101
return GNUTLS_E_INTERNAL_ERROR;
104
resarr[2] = gcry_sexp_nth_mpi (list, 1, 0);
105
gcry_sexp_release (list);
107
list = gcry_sexp_find_token (key, "y", 0);
111
gcry_sexp_release (key);
112
return GNUTLS_E_INTERNAL_ERROR;
115
resarr[3] = gcry_sexp_nth_mpi (list, 1, 0);
116
gcry_sexp_release (list);
119
list = gcry_sexp_find_token (key, "x", 0);
123
gcry_sexp_release (key);
124
return GNUTLS_E_INTERNAL_ERROR;
127
resarr[4] = gcry_sexp_nth_mpi (list, 1, 0);
128
gcry_sexp_release (list);
131
gcry_sexp_release (key);
133
_gnutls_dump_mpi ("p: ", resarr[0]);
134
_gnutls_dump_mpi ("q: ", resarr[1]);
135
_gnutls_dump_mpi ("g: ", resarr[2]);
136
_gnutls_dump_mpi ("y: ", resarr[3]);
137
_gnutls_dump_mpi ("x: ", resarr[4]);