[Botan-devel] DSA signature verification always returns false

Jack Lloyd lloyd at randombit.net
Thu Apr 16 21:25:05 EDT 2009

On Thu, Apr 16, 2009 at 09:16:24PM -0400, Z. S. O. wrote:
> The following code should (in theory) return true, but does not:
> AutoSeeded_RNG rng;
> DSA_PrivateKey dsaprivkey(rng, DL_Group("dsa/jce/1024"));
> string publickey = X509::PEM_encode(dsaprivkey);
> SecureVector<byte> msg(reinterpret_cast<const byte*>(message.data()),
> message.length());
> SecureVector<byte> sig = dsaprivkey.sign(msg, sizeof(msg), rng);
> DataSource_Memory pubkeysrc(publickey);
> auto_ptr<X509_PublicKey> loadedPublicKey(X509::load_key(pubkeysrc));
> DSA_PublicKey* dsapubkey =
> dynamic_cast<DSA_PublicKey*>(loadedPublicKey.get());
> return dsapubkey->verify(msg, sizeof(msg), sig, sizeof(sig));

Replace sizeof(msg) / sizeof(sig) with msg.length() and sig.length():
sizeof() will return the size of the structure (the length+pointer)
not the size of the pointed-to-memory-block. -Jack

More information about the botan-devel mailing list