Verifying the signature of unhashed data with Ruby OpenSSL
I have an RSA public key, some data and a signature of that data. I need to verify the signature. However, the signature is not a digest of data, but of all data. (The data itself is only 16 bytes, so the signer does not document the data before signing it.) I can verify the signature in C by specifying a NULL engine when initializing the context:
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(verify_key, NULL);
However, I was unable to find an equivalent in the Ruby OpenSSL :: PKey :: PKey validator method. This method requires a Digest object, and there is no digest I can find which is not actually a hash, but simply returns the data as it is. I tried to create my own Digest subclass, but I don't think it might work as the underlying OpenSSL library will not be aware of the existence of a custom digest type.
Am I stuck or is there a way to fix this given that I cannot change the code the signer is executing?
source to share
To summarize the answer from comments to remove this question from the "No Answer" filter ...
owlstead :
Have you tried to find a function like
public_decrypt
? It might work as you normally don't have to encrypt with the private key and decrypt with the public key. With a little luck, it will accept the PKCS # 1 signature version (note that the add-on used for encryption and signing is different in PKCS # 1).
Wammer :
Of course - decrypting the signature with the public key and verifying that it matches the data works great. So far this works fine with the standard PKCS # 1 add-on, but I'll do some more research to see if different encryption and signing of shims is a problem in practice. Thank.
owlstead :
After decrypting and verifying the padding, all that's left is a (safe if possible) comparison. So replacing the check function is pretty good. Much of the security is in modular arithmetic and complement.
source to share