    private void testKeyGeneration(int keysize)
        throws Exception
    {
        KeyPairGenerator generator = KeyPairGenerator.getInstance("DSA", "BC");
        generator.initialize(keysize);
        KeyPair keyPair = generator.generateKeyPair();
        DSAPrivateKey priv = (DSAPrivateKey)keyPair.getPrivate();
        DSAParams params = priv.getParams();
        isTrue("keysize mismatch", keysize == params.getP().bitLength());
        // The NIST standard does not fully specify the size of q that
        // must be used for a given key size. Hence there are differences.
        // For example if keysize = 2048, then OpenSSL uses 256 bit q's by default,
        // but the SUN provider uses 224 bits. Both are acceptable sizes.
        // The tests below simply asserts that the size of q does not decrease the
        // overall security of the DSA.
        int qsize = params.getQ().bitLength();
        switch (keysize)
        {
        case 1024:
            isTrue("Invalid qsize for 1024 bit key:" + qsize, qsize >= 160);
            break;
        case 2048:
            isTrue("Invalid qsize for 2048 bit key:" + qsize, qsize >= 224);
            break;
        case 3072:
            isTrue("Invalid qsize for 3072 bit key:" + qsize, qsize >= 256);
            break;
        default:
            fail("Invalid key size:" + keysize);
        }
        // Check the length of the private key.
        // For example GPG4Browsers or the KJUR library derived from it use
        // q.bitCount() instead of q.bitLength() to determine the size of the private key
        // and hence would generate keys that are much too small.
        isTrue("privkey error", priv.getX().bitLength() >= qsize - 32);
    }
Weaknesses in this category are related to the design and implementation of data confidentiality and integrity. Frequently these deal with the use of encoding techniques, encryption libraries, and hashing algorithms. The weaknesses in this category could lead to a degradation of the quality data if they are not addressed.