Crypto++ 5.6.3rc5 GenerateBlock 未实现

Crypto++ 5.6.3rc5 GenerateBlock Not Implemented

我正在尝试从密码派生密钥并想随机生成盐(我不知道 SHA-256 的大小应该是多少,这与 AES256 中的 IV 一样重要,它应该是 128 位,如果有人知道请给出提示)使用 AutoSeededRandomPool 但例外是咳嗽

RandomNumberGenerator:GenerateBlock Not Implemented

我正在使用带有 QT 5.5.1 和 /MD 发布模式的 crypto++ 5.6.3rc5,这可能是一个错误,或者是某人未完成的工作。

#include <QCoreApplication>
#include <sha.h>
#include <base64.h>
#include <iostream>
#include <string>
#include <pwdbased.h>
#include <cstdio>
#include <iostream>
#include <osrng.h>
using CryptoPP::AutoSeededRandomPool;

#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

#include <string>
using std::string;

#include <cstdlib>
using std::exit;

#include <cryptlib.h>
using CryptoPP::Exception;

#include <hex.h>
using CryptoPP::HexEncoder;
using CryptoPP::HexDecoder;

#include <filters.h>
using CryptoPP::StringSink;

//#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{  

    QCoreApplication a(argc, argv);

    try
    {
        AutoSeededRandomPool rng;
        byte salt[16*8];
        rng.GenerateBlock(salt, 16*8);

        byte password[] ="password";
        size_t plen = strlen((const char*)password);

        size_t slen = strlen((const char*)salt);

        int c = 1;
        byte derived[32];

        CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256> pbkdf2;
        pbkdf2.DeriveKey(derived, sizeof(derived), 0, password, plen, salt, slen, c);

        string result;
        HexEncoder encoder(new StringSink(result));

        encoder.Put(derived, sizeof(derived));
        encoder.MessageEnd();

        cout << "Derived: " << result << endl;
    }
    catch (const Exception& ex) {
        cerr << ex.what() << endl;
    }
    return a.exec();
}

Crypto++ 5.6.3rc5 GenerateBlock Not Implemented ...

您可以在 Crash in RandomNumberGenerator::GenerateWord32 due to stack recursion 阅读有关更改的历史记录。更改最终被取消。

已在 RC6 中修复,但尚未公布。在 Crypto++ 5.6.3 Files 有一个准 RC6 之前的版本。但一经公布,便一成不变。

现在,由于 Debian Unstable 上的 Cygwin、MinGW 和 C++11,RC6 正在经历微小的变化。这些变化还算不错,但测试它们很痛苦。有些脚本在模拟平台下 运行 需要半天,比如 S/390x.

如果您想回避这个问题并避免下载 pre-RC6,那么您可以使用以下生成器之一。他们称 GenerateIntoBufferedTransformation:

  • AutoSeededX917RNG< AES >
  • X917RNG
  • RandomPool

或者,您可以使用 OS_GenerateRandomBlock 直接从 OS 的池中提取。

或者,您可以删除抛出的代码。打开cryptlib.h,找到RandomNumberGenerator,去掉守卫旧代码的#if 0/#endif,删除throw.

另请参阅 Crypto++ wiki 上的 RandomNumberGenerator