Subject: | DSA is being done on message contents |
I was trying to see which has was being used, when I discovered that Crypt::PK::DSA is using the message itself rather than the hash. libtommath's dsa_sign_hash expects a hash as the input, not the message. This is either an issue with the code or documentation.
libtommath doesn't properly implement DSA according to FIPS 186, but we can still use that as a reference. From section 4.6 of FIPS 186-4:
z = the leftmost min(N, outlen) bits of Hash(M).
s = (k^-1(z+xr)) mod q
so the documentation should either note that the input needs to be a truncated hash of the appropriate size and strength (from SP 800-57), or the code will need to perform the hash and truncation.
A minor suggestion is that for people familiar with FIPS 186 and most of the rest of the world, some translation of the libtommath variables might be nice. "group size" is the 'q' size in octets, and "modulus size" is the 'p' size
in octets. From section 4.2 of FIPS 186-4 (L and N are the bit lengths of p and q respectively):
L = 1024, N = 160 => generate_key(20, 128)
L = 2048, N = 224 => generate_key(28, 256)
L = 2048, N = 256 => generate_key(32, 256)
L = 3072, N = 256 => generate_key(32, 384)
There's also the problem with libtommath's broken primality tests, but that's a tougher issue to solve.