Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenerateRandomWithKeySize calls debug break #1279

Closed
TheNormalnij opened this issue Jun 23, 2024 · 1 comment
Closed

GenerateRandomWithKeySize calls debug break #1279

TheNormalnij opened this issue Jun 23, 2024 · 1 comment

Comments

@TheNormalnij
Copy link

TheNormalnij commented Jun 23, 2024

OS: Windows 10 19045.4529 x64
Crypto++ version: on commit (Guard use of ModularSquareRoot (GH https://github.com/weidai11/cryptopp/issues/1249[)](https://github.com/weidai11/cryptopp/commit/9aa07aebbdc62461c3ac32f958d7c3ab89ff6f73)
Compiler: MSVC 17.9.34607.119 (x86)

Code:

struct KeyPair {
    std::string publicKey, privateKey;
};

// size if 1024, 2048 or 4096
inline KeyPair GenerateRsaKeyPair(const unsigned int size)
    {
        KeyPair rsaKeyPair;

        CryptoPP::AutoSeededRandomPool asrp;

        CryptoPP::RSA::PrivateKey rsaPrivateKey;

        // next line causes debug break
        rsaPrivateKey.GenerateRandomWithKeySize(asrp, size);
        CryptoPP::RSA::PublicKey rsaPublicKey(rsaPrivateKey);

        CryptoPP::StringSink rawPrivateKeySink(rsaKeyPair.privateKey);
        rsaPrivateKey.DEREncode(rawPrivateKeySink);

        CryptoPP::StringSink rawPublicKeySink(rsaKeyPair.publicKey);
        rsaPublicKey.DEREncode(rawPublicKeySink);

        return rsaKeyPair;
    }

When i debug my application, this function calls debug break here:

// nbtheory.cpp:526
Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, const Integer &q, const Integer &u)
{
	// Callers must ensure p and q are prime, GH #1249
	CRYPTOPP_ASSERT(IsPrime(p) && IsPrime(q));

	// isn't operator overloading great?
	return p * (u * (xq-xp) % q) + xp;
/*
	Integer t1 = xq-xp;
	cout << hex << t1 << endl;
	Integer t2 = u * t1;
	cout << hex << t2 << endl;
	Integer t3 = t2 % q;
	cout << hex << t3 << endl;
	Integer t4 = p * t3;
	cout << hex << t4 << endl;
	Integer t5 = t4 + xp;
	cout << hex << t5 << endl;
	return t5;
*/
}

AutoSeededX917RNG<CryptoPP::AES> asrp; doesn't work too.

Expected behavior: rsaPrivateKey.GenerateRandomWithKeySize doesn't cause debug break.

Thanks!

noloader added a commit that referenced this issue Jun 23, 2024
@TheNormalnij
Copy link
Author

It was fast. Thanks!

nalyd88 added a commit to ViperScience/cryptopp that referenced this issue Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant