dsa2sexp.c 1.58 KB
Newer Older
1
2
3
4
5
6
/* dsa2sexp.c
 *
 */

/* nettle, low-level cryptographics library
 *
7
 * Copyright (C) 2002, 2009, 2014 Niels Möller, Magnus Holmgren
8
9
10
11
12
13
14
15
16
17
18
19
20
 *  
 * The nettle library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * The nettle library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
21
22
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02111-1301, USA.
23
24
25
26
27
28
29
30
31
32
33
34
35
 */

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include "dsa.h"

#include "sexp.h"

int
dsa_keypair_to_sexp(struct nettle_buffer *buffer,
		    const char *algorithm_name,
36
37
38
		    const struct dsa_params *params,
		    const mpz_t pub,
		    const mpz_t priv)
39
40
41
{
  if (!algorithm_name)
    algorithm_name = "dsa";
42

43
44
45
46
  if (priv)
    return sexp_format(buffer,
		       "(private-key(%0s(p%b)(q%b)"
		       "(g%b)(y%b)(x%b)))",
47
48
49
		       algorithm_name, params->p, params->q,
		       params->g, pub, priv);

50
51
52
53
  else
    return sexp_format(buffer,
		       "(public-key(%0s(p%b)(q%b)"
		       "(g%b)(y%b)))",
54
55
		       algorithm_name, params->p, params->q,
		       params->g, pub);
56
}