Commit 1258396d authored by Matt Caswell's avatar Matt Caswell
Browse files

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: default avatarRichard Levitte <levitte@openssl.org>
Reviewed-by: default avatarStephen Henson <steve@openssl.org>
parent 25c78440
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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");
    }

+5 −5
Original line number Diff line number Diff line
@@ -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"
+1 −1
Original line number Diff line number Diff line
@@ -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;

+78 −27
Original line number Diff line number Diff line
@@ -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[] =
+1 −1
Original line number Diff line number Diff line
@@ -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");
Loading