On Friday, August 30, 2013 2:59:51 PM UTC-4, Stu wrote: > > >>GetModulus() returns a Crypto++ Integer. Integer has a class method > BitCount(). > > Yes, but as I noted above, this will sometimes return the wrong value... > Well, you asked about keysize: "... I need a way to determine what the keysize is." ;)
> When using the high level decryptor > > RSAES_OAEP_SHA_Decryptor decryptor( privateKey ); > > size_t dpl = decryptor.MaxPlaintextLength( ciphertext.size() ); returns 0 > if ciphertext.size() does not equal decryptor.FixedCiphertextLength(), > which means that any other size is invalid. The computation is from line > 158 in here: > > http://www.cryptopp.com/docs/ref/pubkey_8h_source.html > > size_t FixedCiphertextLength() const {return > this->GetTrapdoorFunctionBounds().MaxImage().ByteCount();} > > I believe RSAES_OAEP_SHA_Decryptor and friends use InvertibleRSAFunction and RSAFunction. These references might be helpful: http://www.cryptopp.com/docs/ref/class_r_s_a_function.html and http://www.cryptopp.com/docs/ref/class_invertible_r_s_a_function.html. I believe MaxPreImage() is the maximum plaintext size; and MaxImage() is the maximum ciphertext size. Looking at InvertibleRSAFunction, both return ++(n >> 1) and RSAFunction returns m_n. I don't know how blinding or OAEP affect the values returned. >From the testing below, it looks like both MaxPreImage() and MaxImage() return n-1. That's what I expected. So, the official correct value must be returned by > GetTrapdoorFunctionBounds().MaxImage().ByteCount(); > > What precisely are you looking for? Message size is a bit different than key size. The message has to be smaller than the modulus, or the modular exponentiation will lose information (m and m_prime will not be equal after the inversion). The message probably cannot be 0 either. But again, I don't know how blinding and OAEP affect that range. If the plaintext message is too large, Crypto++ will throw an exception. Jeff CryptoPP::InvertibleRSAFunction rsa; CryptoPP::AutoSeededRandomPool pool; rsa.GenerateRandomWithKeySize(pool, 128); std::ostringstream ss; ss << "n: " << rsa.GetModulus() << std::endl; ss << "Preimage: " << rsa.MaxPreimage() << std::endl; ss << "Image: " << rsa.MaxImage() << std::endl; std::cout << ss.str() << std::endl; n: 240963096710590365560537833800742742569. Preimage: 240963096710590365560537833800742742568. Image: 240963096710590365560537833800742742568. -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [email protected]. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
