Hello,

I want to implement a mechanism that allows no access :), read-only, write-only and read-write access to a structure. To be sure this is done properly, I make use of encryption, and more specifically of the RSA public key cryptosystem.

I am thinking of doing this the following way: one key will be for writing (the public key) and one key will be for reading (the private key). The user having both keys will have read-write access.

The problem I am dealing with is that in the implementation in Crypto++ of the public key and private key structures (RSAFunction and InvertibleRSAFunction) the private key includes the public key. Is this really necessary? I thought that the public key would consist of  (n,e) and the private key of (n,d). Anyway, given the 5.1 implementation of Crypto++ that I am using, I can only implement a write-only and a read-write mechanism: the user having the public key will have write-only access, and the user having the private key will have read-write access.

For solving my problem, I couldn't easily modify the InvertibleRSAFunction class not to include the members I thought unnecessary, at least because that would have ruined the key encoding/decoding and of the way CalculateInverse  was implemented. The next possibility I found was adding a decrypt method to  TF_EncryptorBase class (I would have surely found it useful if it had already existed) and then using in my implementation of the described features an RSAES_OAEP_SHA_Encryptor for both encryption and decryption. Here I would initialize the object used for decryption with (modulus, decryption exponent).

So, here is the method added in pubkey.cpp:

DecodingResult TF_EncryptorBase::FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const

{

SecByteBlock paddedBlock(PaddedBlockByteLength());

Integer x = GetTrapdoorFunctionInterface().ApplyRandomizedFunction(rng,Integer(cipherText, FixedCiphertextLength()));

if (x.ByteCount() > paddedBlock.size())

x = Integer::Zero();

x.Encode(paddedBlock, paddedBlock.size());

return GetMessageEncodingInterface().Unpad(paddedBlock, PaddedBlockBitLength(), plainText);

}

And, to my surprise, it did work.

Since I am not very happy of modifying the library, could you tell me whether this looks right? Or maybe I can do the same without modifying the library? What am I missing  in terms of security by not doing the computations present in RSAInvertibleFunction::CalculateInverse marked with blind and unblind? And would it be difficult to have a filter doing this decryption?

 

Thanks for reading this,

Adrian

Reply via email to