Commit 5549b2f4 authored by Niels Möller's avatar Niels Möller

Convert dsa_keypair_from_sexp_alist to use struct dsa_params.

parent fb4e324a
2014-03-26 Niels Möller <nisse@lysator.liu.se>
* sexp2dsa.c (dsa_keypair_from_sexp_alist): Converted to new DSA
interface. Allow q_size == 0, meaning any q < p is allowed.
Additional validity checks.
(dsa_sha1_keypair_from_sexp, dsa_sha256_keypair_from_sexp):
Converted to new DSA interface.
* dsa2sexp.c (dsa_keypair_to_sexp): Converted to new DSA
interface.
* tools/pkcs1-conv.c: Updated uses of dsa_keypair_to_sexp.
......
......@@ -256,8 +256,9 @@ dsa_signature_from_sexp(struct dsa_signature *rs,
unsigned q_bits);
int
dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
struct dsa_private_key *priv,
dsa_keypair_from_sexp_alist(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
unsigned q_bits,
struct sexp_iterator *i);
......@@ -267,14 +268,16 @@ dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
* the public key. */
/* Keys must be initialized before calling this function, as usual. */
int
dsa_sha1_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
dsa_sha1_keypair_from_sexp(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *expr);
int
dsa_sha256_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
dsa_sha256_keypair_from_sexp(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *expr);
......
......@@ -303,7 +303,9 @@ bench_dsa_init (unsigned size)
if (! (sexp_transport_iterator_first (&i, sizeof(dsa1024) - 1, dsa1024)
&& sexp_iterator_check_type (&i, "private-key")
&& sexp_iterator_check_type (&i, "dsa")
&& dsa_keypair_from_sexp_alist (&ctx->pub, &ctx->key, 0, DSA_SHA1_Q_BITS, &i)) )
&& dsa_keypair_from_sexp_alist ((struct dsa_params *) &ctx->pub,
ctx->pub.y, ctx->key.x,
0, DSA_SHA1_Q_BITS, &i)) )
die ("Internal error.\n");
ctx->digest = hash_string (&nettle_sha1, 3, "foo");
......
......@@ -47,8 +47,9 @@ do { \
*/
int
dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
struct dsa_private_key *priv,
dsa_keypair_from_sexp_alist(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
unsigned q_bits,
struct sexp_iterator *i)
......@@ -57,26 +58,39 @@ dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
= { "p", "q", "g", "y", "x" };
struct sexp_iterator values[5];
unsigned nvalues = priv ? 5 : 4;
unsigned p_bits;
if (!sexp_iterator_assoc(i, nvalues, names, values))
return 0;
if (priv)
GET(priv->x, q_bits, &values[4]);
GET(pub->p, p_max_bits, &values[0]);
GET(pub->q, q_bits, &values[1]);
if (mpz_sizeinbase(pub->q, 2) != q_bits)
GET(params->p, p_max_bits, &values[0]);
p_bits = mpz_sizeinbase (params->p, 2);
GET(params->q, q_bits ? q_bits : p_bits, &values[1]);
if (q_bits > 0 && mpz_sizeinbase(params->q, 2) != q_bits)
return 0;
if (mpz_cmp (params->q, params->p) >= 0)
return 0;
GET(params->g, p_bits, &values[2]);
if (mpz_cmp (params->g, params->p) >= 0)
return 0;
GET(pub->g, p_max_bits, &values[2]);
GET(pub->y, p_max_bits, &values[3]);
GET(pub, p_bits, &values[3]);
if (mpz_cmp (pub, params->p) >= 0)
return 0;
if (priv)
{
GET(priv, mpz_sizeinbase (params->q, 2), &values[4]);
if (mpz_cmp (priv, params->q) >= 0)
return 0;
}
return 1;
}
int
dsa_sha1_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
dsa_sha1_keypair_from_sexp(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *expr)
{
......@@ -85,12 +99,14 @@ dsa_sha1_keypair_from_sexp(struct dsa_public_key *pub,
return sexp_iterator_first(&i, length, expr)
&& sexp_iterator_check_type(&i, priv ? "private-key" : "public-key")
&& sexp_iterator_check_type(&i, "dsa")
&& dsa_keypair_from_sexp_alist(pub, priv, p_max_bits, DSA_SHA1_Q_BITS, &i);
&& dsa_keypair_from_sexp_alist(params, pub, priv,
p_max_bits, DSA_SHA1_Q_BITS, &i);
}
int
dsa_sha256_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
dsa_sha256_keypair_from_sexp(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *expr)
{
......@@ -99,7 +115,8 @@ dsa_sha256_keypair_from_sexp(struct dsa_public_key *pub,
return sexp_iterator_first(&i, length, expr)
&& sexp_iterator_check_type(&i, priv ? "private-key" : "public-key")
&& sexp_iterator_check_type(&i, "dsa-sha256")
&& dsa_keypair_from_sexp_alist(pub, priv, p_max_bits, DSA_SHA256_Q_BITS, &i);
&& dsa_keypair_from_sexp_alist(params, pub, priv,
p_max_bits, DSA_SHA256_Q_BITS, &i);
}
int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment