Commit e218daf9 authored by Niels Möller's avatar Niels Möller
Browse files

* tools/pkcs1-conv.c: Updated for dsa/der interface change.

* der2dsa.c (dsa_public_key_from_der_iterators): Split into two
new functions...
(dsa_params_from_der_iterator): New function.
(dsa_public_key_from_der_iterator): New function.
(dsa_openssl_private_key_from_der_iterator): Renamed, was
dsa_private_key_from_der_iterator.
(dsa_openssl_private_key_from_der): Likewise.
* dsa.h: Corresponding changees to prototypes and #defines.

Rev: nettle/ChangeLog:1.45
Rev: nettle/der2dsa.c:1.3
Rev: nettle/dsa.h:1.3
Rev: nettle/tools/pkcs1-conv.c:1.3
parent 46810000
2009-10-19 Niels Mller <nisse@lysator.liu.se>
* tools/pkcs1-conv.c: Updated for dsa/der interface change.
* der2dsa.c (dsa_public_key_from_der_iterators): Split into two
new functions...
(dsa_params_from_der_iterator): New function.
(dsa_public_key_from_der_iterator): New function.
(dsa_openssl_private_key_from_der_iterator): Renamed, was
dsa_private_key_from_der_iterator.
(dsa_openssl_private_key_from_der): Likewise.
* dsa.h: Corresponding changees to prototypes and #defines.
2009-10-12 Niels Mller <nisse@lysator.liu.se> 2009-10-12 Niels Mller <nisse@lysator.liu.se>
* sexp-format.c: Removed conditioning on HAVE_LIBGMP. * sexp-format.c: Removed conditioning on HAVE_LIBGMP.
...@@ -14,7 +27,8 @@ ...@@ -14,7 +27,8 @@
* configure.ac (LIBHOGWEED_MINOR): Bumped libhogweed minor * configure.ac (LIBHOGWEED_MINOR): Bumped libhogweed minor
version, now it's 1.1. version, now it's 1.1.
* testsuite/rsa2sexp-test.c (test_main): Updated testcase for "rsa-pkcs1". * testsuite/rsa2sexp-test.c (test_main): Updated testcase for
"rsa-pkcs1".
2009-10-11 Niels Mller <nisse@lysator.liu.se> 2009-10-11 Niels Mller <nisse@lysator.liu.se>
......
...@@ -39,34 +39,42 @@ ...@@ -39,34 +39,42 @@
&& mpz_sgn((x)) > 0) && mpz_sgn((x)) > 0)
int int
dsa_public_key_from_der_iterators(struct dsa_public_key *pub, dsa_params_from_der_iterator(struct dsa_public_key *pub,
unsigned limit, unsigned limit,
struct asn1_der_iterator *i, struct asn1_der_iterator *i)
struct asn1_der_iterator *j)
{ {
/* DSAPublicKey ::= INTEGER /* Dss-Parms ::= SEQUENCE {
Dss-Parms ::= SEQUENCE {
p INTEGER, p INTEGER,
q INTEGER, q INTEGER,
g INTEGER g INTEGER
} }
*/ */
return (i->type == ASN1_INTEGER return (i->type == ASN1_INTEGER
&& asn1_der_get_bignum(i, pub->y, limit) && asn1_der_get_bignum(i, pub->p, limit)
&& mpz_sgn(pub->y) > 0
&& j->type == ASN1_INTEGER
&& asn1_der_get_bignum(j, pub->p, limit)
&& mpz_sgn(pub->p) > 0 && mpz_sgn(pub->p) > 0
&& GET(j, pub->q, limit) && GET(i, pub->q, limit)
&& GET(j, pub->g, limit) && GET(i, pub->g, limit)
&& asn1_der_iterator_next(i) == ASN1_ITERATOR_END); && asn1_der_iterator_next(i) == ASN1_ITERATOR_END);
}
int
dsa_public_key_from_der_iterator(struct dsa_public_key *pub,
unsigned limit,
struct asn1_der_iterator *i)
{
/* DSAPublicKey ::= INTEGER
*/
return (i->type == ASN1_INTEGER
&& asn1_der_get_bignum(i, pub->y, limit)
&& mpz_sgn(pub->y) > 0);
} }
/* FIXME: Rename this and the next function to something /* FIXME: Rename this and the next function to something
openssl-specific? */ openssl-specific? */
int int
dsa_private_key_from_der_iterator(struct dsa_public_key *pub, dsa_openssl_private_key_from_der_iterator(struct dsa_public_key *pub,
struct dsa_private_key *priv, struct dsa_private_key *priv,
unsigned limit, unsigned limit,
struct asn1_der_iterator *i) struct asn1_der_iterator *i)
...@@ -97,7 +105,7 @@ dsa_private_key_from_der_iterator(struct dsa_public_key *pub, ...@@ -97,7 +105,7 @@ dsa_private_key_from_der_iterator(struct dsa_public_key *pub,
} }
int int
dsa_keypair_from_der(struct dsa_public_key *pub, dsa_openssl_private_key_from_der(struct dsa_public_key *pub,
struct dsa_private_key *priv, struct dsa_private_key *priv,
unsigned limit, unsigned limit,
unsigned length, const uint8_t *data) unsigned length, const uint8_t *data)
...@@ -107,11 +115,6 @@ dsa_keypair_from_der(struct dsa_public_key *pub, ...@@ -107,11 +115,6 @@ dsa_keypair_from_der(struct dsa_public_key *pub,
res = asn1_der_iterator_first(&i, length, data); res = asn1_der_iterator_first(&i, length, data);
if (res != ASN1_ITERATOR_CONSTRUCTED) return (res == ASN1_ITERATOR_CONSTRUCTED
return 0; && dsa_openssl_private_key_from_der_iterator(pub, priv, limit, &i));
if (priv)
return dsa_private_key_from_der_iterator(pub, priv, limit, &i);
else
return 0;
} }
...@@ -55,9 +55,10 @@ extern "C" { ...@@ -55,9 +55,10 @@ extern "C" {
#define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp #define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp
#define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist #define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
#define dsa_keypair_from_sexp nettle_dsa_keypair_from_sexp #define dsa_keypair_from_sexp nettle_dsa_keypair_from_sexp
#define dsa_public_key_from_der_iterators nettle_dsa_public_key_from_der_iterators #define dsa_params_from_der_iterator nettle_dsa_params_from_der_iterator
#define dsa_private_key_from_der_iterator nettle_dsa_private_key_from_der_iterator #define dsa_public_key_from_der_iterator nettle_dsa_public_key_from_der_iterator
#define dsa_keypair_from_der nettle_dsa_keypair_from_der #define dsa_openssl_private_key_from_der_iterator nettle_dsa_openssl_private_key_from_der_iterator
#define dsa_openssl_private_key_from_der nettle_openssl_provate_key_from_der
#define DSA_MIN_P_BITS 512 #define DSA_MIN_P_BITS 512
#define DSA_Q_OCTETS 20 #define DSA_Q_OCTETS 20
...@@ -213,20 +214,22 @@ dsa_keypair_from_sexp(struct dsa_public_key *pub, ...@@ -213,20 +214,22 @@ dsa_keypair_from_sexp(struct dsa_public_key *pub,
struct asn1_der_iterator; struct asn1_der_iterator;
int int
dsa_public_key_from_der_iterators(struct dsa_public_key *pub, dsa_params_from_der_iterator(struct dsa_public_key *pub,
unsigned limit, unsigned limit,
struct asn1_der_iterator *i, struct asn1_der_iterator *i);
struct asn1_der_iterator *j); int
dsa_public_key_from_der_iterator(struct dsa_public_key *pub,
unsigned limit,
struct asn1_der_iterator *i);
int int
dsa_private_key_from_der_iterator(struct dsa_public_key *pub, dsa_openssl_private_key_from_der_iterator(struct dsa_public_key *pub,
struct dsa_private_key *priv, struct dsa_private_key *priv,
unsigned limit, unsigned limit,
struct asn1_der_iterator *i); struct asn1_der_iterator *i);
/* For public keys, use PRIV == NULL */
int int
dsa_keypair_from_der(struct dsa_public_key *pub, dsa_openssl_private_key_from_der(struct dsa_public_key *pub,
struct dsa_private_key *priv, struct dsa_private_key *priv,
unsigned limit, unsigned limit,
unsigned length, const uint8_t *data); unsigned length, const uint8_t *data);
......
...@@ -317,7 +317,7 @@ convert_dsa_private_key(struct nettle_buffer *buffer, unsigned length, const uin ...@@ -317,7 +317,7 @@ convert_dsa_private_key(struct nettle_buffer *buffer, unsigned length, const uin
dsa_public_key_init(&pub); dsa_public_key_init(&pub);
dsa_private_key_init(&priv); dsa_private_key_init(&priv);
if (dsa_keypair_from_der(&pub, &priv, 0, if (dsa_openssl_private_key_from_der(&pub, &priv, 0,
length, data)) length, data))
{ {
/* Reuses the buffer */ /* Reuses the buffer */
...@@ -408,7 +408,8 @@ convert_public_key(struct nettle_buffer *buffer, unsigned length, const uint8_t ...@@ -408,7 +408,8 @@ convert_public_key(struct nettle_buffer *buffer, unsigned length, const uint8_t
dsa_public_key_init(&pub); dsa_public_key_init(&pub);
if (dsa_public_key_from_der_iterators(&pub, 0, &i, &j)) if (dsa_params_from_der_iterator(&pub, 0, &i)
&& dsa_public_key_from_der_iterator(&pub, 0, &j))
{ {
nettle_buffer_reset(buffer); nettle_buffer_reset(buffer);
res = dsa_keypair_to_sexp(buffer, NULL, &pub, NULL) > 0; res = dsa_keypair_to_sexp(buffer, NULL, &pub, NULL) > 0;
......
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