~ubuntu-branches/ubuntu/maverick/gnutls26/maverick-security

« back to all changes in this revision

Viewing changes to lib/x509/dsa.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2009-04-14 14:23:19 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090414142319-ok7xejzbqkofno1q
Tags: 2.6.5-1
* Sync sections in debian/control with override file. libgnutls26-dbg is
  section debug, guile-gnutls is section lisp.
* New upstream version. (Needed for Libtasn1-3 2.0)
* New patch 15_tasn1inpc.diff. Make sure libtasn1 is listed in Libs.private.
* Standards-Version: 3.8.1, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003, 2004, 2005, 2008 Free Software Foundation
3
 
 *
4
 
 * Author: Nikos Mavrogiannopoulos
5
 
 *
6
 
 * This file is part of GNUTLS.
7
 
 *
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.
12
 
 *
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.
17
 
 *
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,
21
 
 * USA
22
 
 *
23
 
 */
24
 
 
25
 
/* This file contains code for DSA keys.
26
 
 */
27
 
 
28
 
#include <gnutls_int.h>
29
 
#include <gnutls_errors.h>
30
 
#include <gnutls_datum.h>
31
 
#include <x509_int.h>
32
 
#include <debug.h>
33
 
 
34
 
/* resarr will contain: p(0), q(1), g(2), y(3), x(4).
35
 
 */
36
 
int
37
 
_gnutls_dsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
38
 
{
39
 
 
40
 
  int ret;
41
 
  gcry_sexp_t parms, key, list;
42
 
 
43
 
  /* FIXME: Remove me once we depend on 1.3.1 */
44
 
  if (bits > 1024 && gcry_check_version("1.3.1")==NULL)
45
 
    {
46
 
      gnutls_assert ();
47
 
      return GNUTLS_E_INVALID_REQUEST;
48
 
    }
49
 
 
50
 
  if (bits < 512)
51
 
    {
52
 
      gnutls_assert ();
53
 
      return GNUTLS_E_INVALID_REQUEST;
54
 
    }
55
 
 
56
 
  ret = gcry_sexp_build (&parms, NULL, "(genkey(dsa(nbits %d)))", bits);
57
 
  if (ret != 0)
58
 
    {
59
 
      gnutls_assert ();
60
 
      return GNUTLS_E_INTERNAL_ERROR;
61
 
    }
62
 
 
63
 
  /* generate the DSA key 
64
 
   */
65
 
  ret = gcry_pk_genkey (&key, parms);
66
 
  gcry_sexp_release (parms);
67
 
 
68
 
  if (ret != 0)
69
 
    {
70
 
      gnutls_assert ();
71
 
      return GNUTLS_E_INTERNAL_ERROR;
72
 
    }
73
 
 
74
 
  list = gcry_sexp_find_token (key, "p", 0);
75
 
  if (list == NULL)
76
 
    {
77
 
      gnutls_assert ();
78
 
      gcry_sexp_release (key);
79
 
      return GNUTLS_E_INTERNAL_ERROR;
80
 
    }
81
 
 
82
 
  resarr[0] = gcry_sexp_nth_mpi (list, 1, 0);
83
 
  gcry_sexp_release (list);
84
 
 
85
 
  list = gcry_sexp_find_token (key, "q", 0);
86
 
  if (list == NULL)
87
 
    {
88
 
      gnutls_assert ();
89
 
      gcry_sexp_release (key);
90
 
      return GNUTLS_E_INTERNAL_ERROR;
91
 
    }
92
 
 
93
 
  resarr[1] = gcry_sexp_nth_mpi (list, 1, 0);
94
 
  gcry_sexp_release (list);
95
 
 
96
 
  list = gcry_sexp_find_token (key, "g", 0);
97
 
  if (list == NULL)
98
 
    {
99
 
      gnutls_assert ();
100
 
      gcry_sexp_release (key);
101
 
      return GNUTLS_E_INTERNAL_ERROR;
102
 
    }
103
 
 
104
 
  resarr[2] = gcry_sexp_nth_mpi (list, 1, 0);
105
 
  gcry_sexp_release (list);
106
 
 
107
 
  list = gcry_sexp_find_token (key, "y", 0);
108
 
  if (list == NULL)
109
 
    {
110
 
      gnutls_assert ();
111
 
      gcry_sexp_release (key);
112
 
      return GNUTLS_E_INTERNAL_ERROR;
113
 
    }
114
 
 
115
 
  resarr[3] = gcry_sexp_nth_mpi (list, 1, 0);
116
 
  gcry_sexp_release (list);
117
 
 
118
 
 
119
 
  list = gcry_sexp_find_token (key, "x", 0);
120
 
  if (list == NULL)
121
 
    {
122
 
      gnutls_assert ();
123
 
      gcry_sexp_release (key);
124
 
      return GNUTLS_E_INTERNAL_ERROR;
125
 
    }
126
 
 
127
 
  resarr[4] = gcry_sexp_nth_mpi (list, 1, 0);
128
 
  gcry_sexp_release (list);
129
 
 
130
 
 
131
 
  gcry_sexp_release (key);
132
 
 
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]);
138
 
 
139
 
  *resarr_len = 5;
140
 
 
141
 
  return 0;
142
 
 
143
 
}