Sign precomputed hash with ECDSA or DSA

Viewed 910

I'm playing around with Crypto++ signers and use the following code, straight out of the wiki:

ECDSA<ECP, SHA256>::PrivateKey privateKey;
const Integer D(string("8964e19c5ae38669db3047f6b460863f5dc6c4510d3427e33545caf9527aafcf").c_str());
privateKey.Initialize(CryptoPP::ASN1::secp256r1(), D);
if (!privateKey.Validate(rng, 3)) {
    cerr << "ECDSA privateKey key validation failed after setting private parameter." << endl;
    return 1;
}

ECDSA<ECP,SHA256>::Signer signer(privateKey);
StringSource ss1(message, true,
    new SignerFilter(rng, signer,
        new HexEncoder(new StringSink(signature), false)
    ) // SignerFilter
); // StringSource
int slen = signature.length() / 2;
// since it's IEEE P1363 format to display r and s:
cout << signature.substr(0, slen) << "\n"
     << signature.substr(slen, slen) << endl;

Now, I'd like to know how I could override the SHA256 there to specify directly the digest value I want to pass to the signature algorithm.

I've digged into the wiki and the doxygen documentation, but had no success doing so. At first I thought maybe the NullHash could help there, but it is really only the zero hash according to the source. I also had some hope with the PK_MessageAccumulator but it does not appear to work as I expected.

So, is there some sort of "identity" function inheriting from the HashTransformation class that I completely missed?
If not, how would you go around building something like that allowing to specify the digest to be signed directly?

1 Answers
Related