openssl/crypto/dsa
Matt Caswell d54897cf54 Pick a q size consistent with the digest for DSA param generation
There are two undocumented DSA parameter generation options available in
the genpkey command line app:
dsa_paramgen_md and dsa_paramgen_q_bits.

These can also be accessed via the EVP API but only by using
EVP_PKEY_CTX_ctrl() or EVP_PKEY_CTX_ctrl_str() directly. There are no
helper macros for these options.

dsa_paramgen_q_bits sets the length of q in bits (default 160 bits).
dsa_paramgen_md sets the digest that is used during the parameter
generation (default SHA1). In particular the output length of the digest
used must be equal to or greater than the number of bits in q because of
this code:

            if (!EVP_Digest(seed, qsize, md, NULL, evpmd, NULL))
                goto err;
            if (!EVP_Digest(buf, qsize, buf2, NULL, evpmd, NULL))
                goto err;
            for (i = 0; i < qsize; i++)
                md[i] ^= buf2[i];

            /* step 3 */
            md[0] |= 0x80;
            md[qsize - 1] |= 0x01;
            if (!BN_bin2bn(md, qsize, q))
                goto err;

qsize here is the number of bits in q and evpmd is the digest set via
dsa_paramgen_md. md and buf2 are buffers of length SHA256_DIGEST_LENGTH.
buf2 has been filled with qsize bits of random seed data, and md is
uninitialised.

If the output size of evpmd is less than qsize then the line "md[i] ^=
buf2[i]" will be xoring an uninitialised value and the random seed data
together to form the least significant bits of q (and not using the
output of the digest at all for those bits) - which is probably not what
was intended. The same seed is then used as an input to generating p. If
the uninitialised data is actually all zeros (as seems quite likely)
then the least significant bits of q will exactly match the least
significant bits of the seed.

This problem only occurs if you use these undocumented and difficult to
find options and you set the size of q to be greater than the message
digest output size. This is for parameter generation only not key
generation. This scenario is considered highly unlikely and
therefore the security risk of this is considered negligible.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5800)
2018-04-05 15:44:24 +01:00
..
build.info
dsa_ameth.c Check return value of OBJ_nid2obj in dsa_pub_encode. 2017-11-03 15:46:51 +01:00
dsa_asn1.c Remove parentheses of return. 2017-10-18 16:05:06 +01:00
dsa_depr.c
dsa_err.c Pick a q size consistent with the digest for DSA param generation 2018-04-05 15:44:24 +01:00
dsa_gen.c Pick a q size consistent with the digest for DSA param generation 2018-04-05 15:44:24 +01:00
dsa_key.c Remove parentheses of return. 2017-10-18 16:05:06 +01:00
dsa_lib.c Remove parentheses of return. 2017-10-18 16:05:06 +01:00
dsa_locl.h
dsa_meth.c Update copyright year 2018-04-03 13:57:12 +01:00
dsa_ossl.c Address a timing side channel whereby it is possible to determine some 2017-11-01 15:47:28 +00:00
dsa_pmeth.c Don't crash if an unrecognised digest is used with dsa_paramgen_md 2018-04-05 15:44:24 +01:00
dsa_prn.c Remove parentheses of return. 2017-10-18 16:05:06 +01:00
dsa_sign.c Remove email addresses from source code. 2017-10-13 10:06:59 -04:00
dsa_vrf.c Remove email addresses from source code. 2017-10-13 10:06:59 -04:00