首页 > 解决方案 > Crypto++ - InvertibleRSAFunction::GenerateRandomWithKeySize 中的内存泄漏?

问题描述

我使用crypto++创建了以下函数,但如果使用它,程序会因GenerateRandomWithKeySize()调用导致内存泄漏而退出。这是正常的还是我做错了什么?我是否必须清理不能自行清理的对象?

#include "rsa.h"
using CryptoPP::RSA;
using CryptoPP::InvertibleRSAFunction;
using CryptoPP::RSAES;
using CryptoPP::OAEP;

#include "sha.h"
using CryptoPP::SHA256;

#include "osrng.h"
using CryptoPP::AutoSeededRandomPool;

#include "cryptlib.h"
using CryptoPP::Exception;
using CryptoPP::DecodingResult;

DOCUMENTED_TYPEDEF(RSAES<OAEP<SHA256> >::Encryptor, RSAES_OAEP_SHA256_Encryptor);
DOCUMENTED_TYPEDEF(RSAES<OAEP<SHA256> >::Decryptor , RSAES_OAEP_SHA256_Decryptor);


bool CryptoCreateKeys(RSA::PrivateKey& privatekey, RSA::PublicKey& publickey)
{
  bool result=true;

  try {
    // Generate keys
    AutoSeededRandomPool rng;

    InvertibleRSAFunction parameters;
    parameters.GenerateRandomWithKeySize(rng, 4096);

    privatekey=parameters;
    publickey=parameters;
  }
  catch (CryptoPP::Exception) {
    result=false;
  }

  return result;
}

// this isn't real - I just put it here for the basic call structure
int main(void)
{
  RSA::PrivateKey privatekey;
  RSA::PublicKey  publickey;
  CryptoCreateKeys(privatekey, publickey);
  return 0
}

标签: crypto++

解决方案


推荐阅读