I am trying to port the AquaticPrime framework for Mac to Windows.
On the Mac, it uses the opensll library, and I try to understand how to port this to Windows, where I have to use the CryptoAPI, I guess.
I mainly need the code for validation of the generated signature with a given public key.
Here's how verification is done with openssl:
So, how do I do this with CryptoAPI? I've gotten this far:
At this point, I call:
CryptVerifySignature (hashHdl, sig, sigLen, keyHdl, 0, 0)
This fails with error code ERROR_INVALID_PARAMETER.
The odd thing is that when I first accidentally had stored a twice as large public key into the PUBLICKEYBLOB structure, I received a NTE_BAD_SIGNATURE error instead. This might suggest that now the public key I am passing is correct.
Why the ERROR_INVALID_PARAMETER error now, then? I've verified that the hash value is correct, and the key appears to be accepted, too. And the "sig" parameter is just a pointer to the 128 bytes of the signature, and sigLen is 128.
So, what am I missing here?
OK, I solved the problem after lots of trial-and-error.
Both the signature and the public key data, when in their pure byte string form, need to be reversed, i.e. first byte to last position, and so on. Then the above works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With