== How to fix it in CryptoPP

=== Code examples

==== Noncompliant code example

include::../../common/fix/rsa.adoc[]

[source,cpp,diff-id=21,diff-type=noncompliant]
----
#include <cryptopp/rsa.h>
#include <cryptopp/rng.h>

void encrypt() {
    CryptoPP::AutoSeededRandomPool  rng;
    CryptoPP::InvertibleRSAFunction rsa_trapdoor;

    rsa_trapdoor.GenerateRandomWithKeySize(rng, 1024); // Noncompliant
}
----

include::../../common/fix/dsa.adoc[]

[source,cpp,diff-id=22,diff-type=noncompliant]
----
#include <cryptopp/dsa.h>
#include <cryptopp/rng.h>

cryptopp::autoseededrandompool rng;
cryptopp::dsa::privatekey      dsa_private_key;

dsa_private_key.GenerateRandomWithKeySize(rng, 1024); // Noncompliant
----

include::../../common/fix/dh.adoc[]

[source,cpp,diff-id=23,diff-type=noncompliant]
----
#include <cryptopp/dh.h>
#include <cryptopp/rng.h>

cryptopp::autoseededrandompool rng;
CryptoPP::DH                   dh;

dh.AccessGroupParameters().GenerateRandomWithKeySize(rng, 1024); // Noncompliant
----

include::../../common/fix/ec.adoc[]

[source,cpp,diff-id=24,diff-type=noncompliant]
----
#include <cryptopp/osrng.h>

void ecnrypt() {
    CryptoPP::ASN1::secp112r1(); // Noncompliant
}
----

==== Compliant solution

[source,cpp,diff-id=21,diff-type=compliant]
----
#include <cryptopp/rsa.h>
#include <cryptopp/rng.h>

void encrypt() {
    CryptoPP::AutoSeededRandomPool  rng;
    CryptoPP::InvertibleRSAFunction rsa_trapdoor;

    rsa_trapdoor.GenerateRandomWithKeySize(rng, 2048);
}
----

[source,cpp,diff-id=22,diff-type=compliant]
----
#include <cryptopp/dsa.h>
#include <cryptopp/rng.h>

cryptopp::autoseededrandompool rng;
cryptopp::dsa::privatekey      dsa_private_key;

dsa_private_key.GenerateRandomWithKeySize(rng, 2048);
----

[source,cpp,diff-id=23,diff-type=compliant]
----
#include <cryptopp/dh.h>
#include <cryptopp/rng.h>

cryptopp::autoseededrandompool rng;
CryptoPP::DH                   dh;

dh.AccessGroupParameters().GenerateRandomWithKeySize(rng, 2048);
----

[source,cpp,diff-id=24,diff-type=compliant]
----
#include <cryptopp/osrng.h>

void ecnrypt() {
    CryptoPP::ASN1::secp256r1();
}
----

=== How does this work?

include::../../common/fix/fix.adoc[]

=== Going the extra mile

include::../../common/extra-mile/pre-quantum.adoc[]
