5
/* nettle, low-level cryptographics library
7
* Copyright (C) 2002 Niels M�ller
9
* The nettle library is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or (at your
12
* option) any later version.
14
* The nettle library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with the nettle library; see the file COPYING.LIB. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
38
#define GET(x, l, v) \
40
if (!nettle_mpz_set_sexp((x), (l), (v)) \
45
/* Iterator should point past the algorithm tag, e.g.
47
* (public-key (dsa (p |xxxx|) ...)
52
dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
53
struct dsa_private_key *priv,
55
struct sexp_iterator *i)
57
static const uint8_t *names[5]
58
= { "p", "q", "g", "y", "x" };
59
struct sexp_iterator values[5];
60
unsigned nvalues = priv ? 5 : 4;
62
if (!sexp_iterator_assoc(i, nvalues, names, values))
66
GET(priv->x, limit, &values[4]);
68
GET(pub->p, limit, &values[0]);
69
GET(pub->q, DSA_Q_BITS, &values[1]);
70
GET(pub->g, limit, &values[2]);
71
GET(pub->y, limit, &values[3]);
77
dsa_keypair_from_sexp(struct dsa_public_key *pub,
78
struct dsa_private_key *priv,
80
unsigned length, const uint8_t *expr)
82
struct sexp_iterator i;
84
return sexp_iterator_first(&i, length, expr)
85
&& sexp_iterator_check_type(&i, priv ? "private-key" : "public-key")
86
&& sexp_iterator_check_type(&i, "dsa")
87
&& dsa_keypair_from_sexp_alist(pub, priv, limit, &i);
91
dsa_signature_from_sexp(struct dsa_signature *rs,
92
struct sexp_iterator *i)
94
static const uint8_t *names[2] = { "r", "s" };
95
struct sexp_iterator values[2];
97
if (!sexp_iterator_assoc(i, 2, names, values))
100
GET(rs->r, 160, &values[0]);
101
GET(rs->s, 160, &values[1]);
106
#endif /* WITH_PUBLIC_KEY */