c++ - 使用 cryptopp 库编译时收到警告

标签 c++ c++11 crypto++

我有一个在 CBC 模式下使用 AES 算法的加密文件。我有数据库中的 key 。 我正在尝试使用 cryptopp 5.6.2 库编译以下代码。它在没有 -Wall 标志的情况下进行编译,但是当我启用该标志时,会出现以下警告。

#include <iostream>
#include <fstream>
#include <exception>
#include <sstream>

#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
#include "cryptopp/filters.h"
#include "cryptopp/cryptlib.h"
#include "cryptopp/hex.h"
#include "cryptopp/filters.h"
#include "cryptopp/aes.h"
#include "cryptopp/ccm.h"
#include "cryptopp/files.h"

using namespace std;
using namespace CryptoPP;

int main(int argc, char* argv[])
{
    try
    {
        byte no[16]  ;
        byte noiv[16];
        std::string out;
        std::string fileName("./encrypted.txt");
        CBC_Mode<AES>::Decryption d;
        d.SetKeyWithIV(no, sizeof(no), noiv);
        CryptoPP::FileSource(fileName.c_str(), true, new StreamTransformationFilter(d, new CryptoPP::FileSink("decrypted.txt"), CryptoPP::StreamTransformationFilter::PKCS_PADDING));
    }
    catch (CryptoPP::Exception& e)
    {
        std::cout << std::endl << e.what() << std::endl;
    }
    return 0;
}

启用 -Wall 标志时出现以下错误

In file included from ./cryptopp_5.6.2/include/cryptopp/modes.h:12,
                 from poc.cpp:6:
./cryptopp_5.6.2/include/cryptopp/algparam.h: In constructor ‘CryptoPP::ConstByteArrayParameter::ConstByteArrayParameter(const T&, bool) [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
./cryptopp_5.6.2/include/cryptopp/filters.h:793:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:26: warning: unused variable ‘cryptopp_assert_26’
In file included from ./cryptopp_5.6.2/include/cryptopp/modes.h:12,
                 from poc.cpp:6:
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = std::ostream*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const wchar_t*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const char*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = std::istream*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const int*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = unsigned char]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const byte*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = CryptoPP::RandomNumberGenerator*]’:
poc.cpp:36:   instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/misc.h: At global scope:
./cryptopp_5.6.2/include/cryptopp/misc.h:548: warning: ‘std::string CryptoPP::StringNarrow(const wchar_t*, bool)’ defined but not used

最佳答案

below code using cryptopp 5.6.2 library...

5.6.2 有点旧了。我们正准备发布 Crypto++ 5.6.5。


It gets compiled without -Wall flag but when I enable that flag below warnings appears.

./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’

该警告大约 18 个月前被清除。它首次出现在 Crypto++ 5.6.3 的版本中。另请参阅Commit 5f25c736: Add CRYPTOPP_UNUSED to help supress unused variable warnings .


Gets below errors on enabling -Wall flag ...

Crypto++ 现在在 GCC 和兼容版本下的 -Wall -Wextra 中是干净的。它也可以在 MSC 下使用 /W4 进行清理。最后,它在 Solaris 的 SunCC 下是干净的。

如果有兴趣,这里是我们发布时需要通过的发布流程和安全门(来自 Release Process | Analysis Tools ):

  • 编译器警告
  • Clang 和 GCC sanitizer
  • 瓦尔格林德
  • 企业分析
  • 覆盖率

目前,Coverity 正在暂停 5.6.5。我们最近将 Coverity 覆盖范围扩大到 Linux, Unix, OS X, and Windows (以前仅限 Linux)。 Coverity 正在得出调查结果,我们正在研究这些结果。

关于c++ - 使用 cryptopp 库编译时收到警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39770259/

相关文章:

c++ - 在 linux 下的 c++ 程序中包含 amp.h 库

c++ - 输入特征以检测可调用对象是否有副作用?

c++ - CEdit不显示特殊字符

c++ - std::thread 构造函数如何检测右值引用?

c++ - crypto++ ECIES BERDecodePrivateKey 的问题

c++ - OpenCV 1.x 后端

c++ - 在 C++11 中编写 Copy/Move/operator= 三重奏的 "correct"方法是什么?

c++ - 在 C++11 中将结构作为输出参数传递

c++ - 使用 FIPS 验证库和 AES 时的 CryptoPP::selfTestFailure

javascript - 加载在 JSBN 中创建的 RSA 公钥,然后加密一条消息