summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-03-30 15:21:39 +0100
committerMatt Caswell <matt@openssl.org>2016-04-03 00:23:56 +0100
commit1258396d73cf937e4daaf2c35377011b9366f956 (patch)
tree6448183bf775904be79b29786795ade508f7fe4d /apps
parent25c78440d21c814705e0e50c6e567300936aa02b (diff)
Make the DSA structure opaque
Move the dsa_st structure out of the public header file. Add some accessor functions to enable access to the internal fields, and update all internal usage to use the new functions. Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Stephen Henson <steve@openssl.org>
Diffstat (limited to 'apps')
-rw-r--r--apps/dsa.c2
-rw-r--r--apps/dsaparam.c10
-rw-r--r--apps/gendsa.c2
-rw-r--r--apps/testdsa.h105
-rw-r--r--apps/x509.c2
5 files changed, 86 insertions, 35 deletions
diff --git a/apps/dsa.c b/apps/dsa.c
index ed5bf0175f..9038e3bfb7 100644
--- a/apps/dsa.c
+++ b/apps/dsa.c
@@ -244,7 +244,7 @@ int dsa_main(int argc, char **argv)
if (modulus) {
BIO_printf(out, "Public Key=");
- BN_print(out, dsa->pub_key);
+ BN_print(out, DSA_get0_pub_key(dsa));
BIO_printf(out, "\n");
}
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 7b9ca631a7..5b0bb625c6 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -263,14 +263,14 @@ int dsaparam_main(int argc, char **argv)
}
if (C) {
- int len = BN_num_bytes(dsa->p);
- int bits_p = BN_num_bits(dsa->p);
+ int len = BN_num_bytes(DSA_get0_p(dsa));
+ int bits_p = BN_num_bits(DSA_get0_p(dsa));
unsigned char *data = app_malloc(len + 20, "BN space");
BIO_printf(bio_out, "DSA *get_dsa%d()\n{\n", bits_p);
- print_bignum_var(bio_out, dsa->p, "dsap", len, data);
- print_bignum_var(bio_out, dsa->q, "dsaq", len, data);
- print_bignum_var(bio_out, dsa->g, "dsag", len, data);
+ print_bignum_var(bio_out, DSA_get0_p(dsa), "dsap", len, data);
+ print_bignum_var(bio_out, DSA_get0_q(dsa), "dsaq", len, data);
+ print_bignum_var(bio_out, DSA_get0_g(dsa), "dsag", len, data);
BIO_printf(bio_out, " DSA *dsa = DSA_new();\n"
"\n");
BIO_printf(bio_out, " if (dsa == NULL)\n"
diff --git a/apps/gendsa.c b/apps/gendsa.c
index 6769968cdf..bf01f563ba 100644
--- a/apps/gendsa.c
+++ b/apps/gendsa.c
@@ -168,7 +168,7 @@ int gendsa_main(int argc, char **argv)
BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
app_RAND_load_files(inrand));
- BIO_printf(bio_err, "Generating DSA key, %d bits\n", BN_num_bits(dsa->p));
+ BIO_printf(bio_err, "Generating DSA key, %d bits\n", BN_num_bits(DSA_get0_p(dsa)));
if (!DSA_generate_key(dsa))
goto end;
diff --git a/apps/testdsa.h b/apps/testdsa.h
index 4eb13d14b2..6519948fe6 100644
--- a/apps/testdsa.h
+++ b/apps/testdsa.h
@@ -92,18 +92,35 @@ static unsigned char dsa512_g[] = {
DSA *get_dsa512()
{
DSA *dsa;
+ BIGNUM *priv_key, *pub_key, *p, *q, *g;
if ((dsa = DSA_new()) == NULL)
return (NULL);
- dsa->priv_key = BN_bin2bn(dsa512_priv, sizeof(dsa512_priv), NULL);
- dsa->pub_key = BN_bin2bn(dsa512_pub, sizeof(dsa512_pub), NULL);
- dsa->p = BN_bin2bn(dsa512_p, sizeof(dsa512_p), NULL);
- dsa->q = BN_bin2bn(dsa512_q, sizeof(dsa512_q), NULL);
- dsa->g = BN_bin2bn(dsa512_g, sizeof(dsa512_g), NULL);
- if ((dsa->priv_key == NULL) || (dsa->pub_key == NULL) || (dsa->p == NULL)
- || (dsa->q == NULL) || (dsa->g == NULL))
- return (NULL);
- return (dsa);
+ priv_key = BN_bin2bn(dsa512_priv, sizeof(dsa512_priv), NULL);
+ pub_key = BN_bin2bn(dsa512_pub, sizeof(dsa512_pub), NULL);
+ p = BN_bin2bn(dsa512_p, sizeof(dsa512_p), NULL);
+ q = BN_bin2bn(dsa512_q, sizeof(dsa512_q), NULL);
+ g = BN_bin2bn(dsa512_g, sizeof(dsa512_g), NULL);
+ if ((priv_key == NULL) || (pub_key == NULL) || (p == NULL) || (q == NULL)
+ || (g == NULL)) {
+ goto err;
+ }
+ if (!DSA_set0_pqg(dsa, p, q, g))
+ goto err;
+ p = q = g = NULL;
+
+ if (!DSA_set0_key(dsa, pub_key, priv_key))
+ goto err;
+
+ return dsa;
+ err:
+ DSA_free(dsa);
+ BN_free(priv_key);
+ BN_free(pub_key);
+ BN_free(p);
+ BN_free(q);
+ BN_free(g);
+ return NULL;
}
static unsigned char dsa1024_priv[] = {
@@ -161,18 +178,35 @@ static unsigned char dsa1024_g[] = {
DSA *get_dsa1024()
{
DSA *dsa;
+ BIGNUM *priv_key, *pub_key, *p, *q, *g;
if ((dsa = DSA_new()) == NULL)
return (NULL);
- dsa->priv_key = BN_bin2bn(dsa1024_priv, sizeof(dsa1024_priv), NULL);
- dsa->pub_key = BN_bin2bn(dsa1024_pub, sizeof(dsa1024_pub), NULL);
- dsa->p = BN_bin2bn(dsa1024_p, sizeof(dsa1024_p), NULL);
- dsa->q = BN_bin2bn(dsa1024_q, sizeof(dsa1024_q), NULL);
- dsa->g = BN_bin2bn(dsa1024_g, sizeof(dsa1024_g), NULL);
- if ((dsa->priv_key == NULL) || (dsa->pub_key == NULL) || (dsa->p == NULL)
- || (dsa->q == NULL) || (dsa->g == NULL))
- return (NULL);
- return (dsa);
+ priv_key = BN_bin2bn(dsa1024_priv, sizeof(dsa1024_priv), NULL);
+ pub_key = BN_bin2bn(dsa1024_pub, sizeof(dsa1024_pub), NULL);
+ p = BN_bin2bn(dsa1024_p, sizeof(dsa1024_p), NULL);
+ q = BN_bin2bn(dsa1024_q, sizeof(dsa1024_q), NULL);
+ g = BN_bin2bn(dsa1024_g, sizeof(dsa1024_g), NULL);
+ if ((priv_key == NULL) || (pub_key == NULL) || (p == NULL) || (q == NULL)
+ || (g == NULL)) {
+ goto err;
+ }
+ if (!DSA_set0_pqg(dsa, p, q, g))
+ goto err;
+ p = q = g = NULL;
+
+ if (!DSA_set0_key(dsa, pub_key, priv_key))
+ goto err;
+
+ return dsa;
+ err:
+ DSA_free(dsa);
+ BN_free(priv_key);
+ BN_free(pub_key);
+ BN_free(p);
+ BN_free(q);
+ BN_free(g);
+ return NULL;
}
static unsigned char dsa2048_priv[] = {
@@ -263,18 +297,35 @@ static unsigned char dsa2048_g[] = {
DSA *get_dsa2048()
{
DSA *dsa;
+ BIGNUM *priv_key, *pub_key, *p, *q, *g;
if ((dsa = DSA_new()) == NULL)
return (NULL);
- dsa->priv_key = BN_bin2bn(dsa2048_priv, sizeof(dsa2048_priv), NULL);
- dsa->pub_key = BN_bin2bn(dsa2048_pub, sizeof(dsa2048_pub), NULL);
- dsa->p = BN_bin2bn(dsa2048_p, sizeof(dsa2048_p), NULL);
- dsa->q = BN_bin2bn(dsa2048_q, sizeof(dsa2048_q), NULL);
- dsa->g = BN_bin2bn(dsa2048_g, sizeof(dsa2048_g), NULL);
- if ((dsa->priv_key == NULL) || (dsa->pub_key == NULL) || (dsa->p == NULL)
- || (dsa->q == NULL) || (dsa->g == NULL))
- return (NULL);
- return (dsa);
+ priv_key = BN_bin2bn(dsa2048_priv, sizeof(dsa2048_priv), NULL);
+ pub_key = BN_bin2bn(dsa2048_pub, sizeof(dsa2048_pub), NULL);
+ p = BN_bin2bn(dsa2048_p, sizeof(dsa2048_p), NULL);
+ q = BN_bin2bn(dsa2048_q, sizeof(dsa2048_q), NULL);
+ g = BN_bin2bn(dsa2048_g, sizeof(dsa2048_g), NULL);
+ if ((priv_key == NULL) || (pub_key == NULL) || (p == NULL) || (q == NULL)
+ || (g == NULL)) {
+ goto err;
+ }
+ if (!DSA_set0_pqg(dsa, p, q, g))
+ goto err;
+ p = q = g = NULL;
+
+ if (!DSA_set0_key(dsa, pub_key, priv_key))
+ goto err;
+
+ return dsa;
+ err:
+ DSA_free(dsa);
+ BN_free(priv_key);
+ BN_free(pub_key);
+ BN_free(p);
+ BN_free(q);
+ BN_free(g);
+ return NULL;
}
static const char rnd_seed[] =
diff --git a/apps/x509.c b/apps/x509.c
index 66dd2ff77e..4319d69f81 100644
--- a/apps/x509.c
+++ b/apps/x509.c
@@ -735,7 +735,7 @@ int x509_main(int argc, char **argv)
#endif
#ifndef OPENSSL_NO_DSA
if (EVP_PKEY_id(pkey) == EVP_PKEY_DSA)
- BN_print(out, EVP_PKEY_get0_DSA(pkey)->pub_key);
+ BN_print(out, DSA_get0_pub_key(EVP_PKEY_get0_DSA(pkey)));
else
#endif
BIO_printf(out, "Wrong Algorithm type");