- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如标题所示,我正在寻找 cryptopp 库中此声明 之间的差异:
CBC_Mode<AES>::Decryption
cbcDecryption.SetKeyWithIV(key, AES::DEFAULT_KEYLENGTH, iv);
和这个:
AES::Decryption aesDecryption(key, AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
此外,我不明白这是为什么:
AES::Decryption aesDecryption(key, AES::DEFAULT_KEYLENGTH);
CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
StreamTransformationFilter stfDecryptor(
cbcDecryption,
new StringSink( recoveredtext )
);
stfDecryptor.Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );
stfDecryptor.MessageEnd();
一切正常在使用模板化模式时我在运行时期间遇到此错误:
AES128CBC: /usr/local/include/cryptopp/misc.h:304: void CryptoPP::memcpy_s(void*, size_t, const void*, size_t): Assertion `dest != __null' failed.
Aborted (core dumped)
不应该一样吗?
我看过this但我不太了解其中的区别,在网上搜索我找不到问题的答案。
最佳答案
What's the difference between templated mode object and external cipher object?
*_ExternalCiphers
的解释在 modes.h
中给出。 , 它出现在网络上 CipherModeDocumentation Class Reference
.它不容易找到,而且我只知道它是因为我与消息来源密切合作。
这是正文:
Each class derived from this one [CipherModeDocumentation] defines two types, Encryption and Decryption, both of which implement the SymmetricCipher interface. For each mode there are two classes, one of which is a template class, and the other one has a name that ends in "_ExternalCipher".
The "external cipher" mode objects hold a reference to the underlying block cipher, instead of holding an instance of it. The reference must be passed in to the constructor. For the "cipher holder" classes, the CIPHER template parameter should be a class derived from BlockCipherDocumentation, for example DES or AES.
所以不同之处在于操作模式如何与密码相关联 - 从字面上看是外部还是内部。
外部 - 下面是两个不同的对象。第一个是对称密码,第二个是操作模式:
AES::Encryption aes(key, ...);
CBC_Mode_ExternalCipher::Encryption cbc(aes, ...);
内部 - 下面是单个对象。操作模式“有一个”通过模板实例化的对称密码:
CBC_Mode<AES>::Encryption enc(key, ...);
all works fine while using the templated mode I have this error during run time...
好的,这是一个不同的问题。让我们看看如何使用它:
$ grep -IR "CBC_Mode_ExternalCipher::Decryption" *
fipstest.cpp: KnownAnswerTest(CBC_Mode_ExternalCipher::Encryption(encryption, iv).Ref(), ...);
validat1.cpp: CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
validat1.cpp: CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
validat1.cpp: CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
validat1.cpp: CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
你可以找到validat1.cpp online , 从 line 1366 开始:
bool ValidateCipherModes()
{
...
DESEncryption desE(key);
DESDecryption desD(key);
...
CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
...
CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
...
}
因此通配符是DESEncryption
和DESDecryption
。让我们看看:
$ grep -IR DESEncryption *
des.h:typedef DES::Encryption DESEncryption;
所以 AES 应该干净地切入。现在,测试程序:
#include "filters.h"
#include "osrng.h"
#include "modes.h"
#include "files.h"
#include "aes.h"
using namespace CryptoPP;
#include <iostream>
#include <string>
using namespace std;
// g++ -DNDEBUG -g2 -O2 -I. test.cxx ./libcryptopp.a -o test.exe
int main(int argc, char* argv[])
{
AutoSeededRandomPool prng;
string plain = "Now is the time for all good men to come to the aide of their country";
string cipher, recover;
SecByteBlock key(AES::DEFAULT_KEYLENGTH), iv(AES::BLOCKSIZE);
prng.GenerateBlock(key, key.size());
prng.GenerateBlock(iv, iv.size());
AES::Encryption aes1(key, key.size());
CBC_Mode_ExternalCipher::Encryption cbc1(aes1, iv);
StringSource ss1(plain, true, new StreamTransformationFilter(cbc1, new StringSink(cipher)));
AES::Decryption aes2(key, key.size());
CBC_Mode_ExternalCipher::Decryption cbc2(aes2, iv);
StringSource ss2(cipher, true, new StreamTransformationFilter(cbc2, new StringSink(recover)));
cout << "Plain: " << plain << endl;
cout << "Recover: " << recover << endl;
return 0;
}
编译运行:
$ g++ -DNDEBUG -g2 -O2 -I. test.cxx ./libcryptopp.a -o test.exe
$
$ ./test.exe
Plain: Now is the time for all good men to come to the aide of their country
Recover: Now is the time for all good men to come to the aide of their country
所以一切似乎都按预期工作。
现在,对于这个问题:
AES128CBC: /usr/local/include/cryptopp/misc.h:304: void CryptoPP::memcpy_s(void*, size_t, const void*, size_t):
Assertion `dest != __null' failed.
在AES128 in CBC mode implementation using cryptopp library ,你被告知使用最新的 Crypto++ 库,因为我们清理了其中的一些。参见 this comment :
You should use the latest version of the Crypto++ sources. I believe this issue was cleared some time ago:
void CryptoPP::memcpy_s(void*, size_t, const void*, size_t): Assertion 'dest != __null' failed
. You can get the latest sources with agit clone https://github.com/weidai11/cryptopp.git
.
您还接受了 Zaph's answer ,所以这应该是关于你的解密和断言问题的结束。这向我和 Stack Overflow 社区表明您不需要额外的帮助或答案。
您可能遇到的问题是将位于 /usr/local
的 Crypto++ 版本与您通过发行版使用 sudo apt 安装的版本混合在一起-获取安装 libcrypto++-dev libcrypto++-doc libcrypto++-utils
。断言是混合和匹配它们的经典标志,因为发行版提供了旧版本的库。
如果你注意到我使用的命令行,你会看到:
-DNDEBUG -g2 -O2
以确保我使用的选项与用于构建库的选项相同-I
以确保我在 PWD 中使用 Crypto++ header ./libcryptopp.a
以确保我链接到 PWD 中库的静态版本并避免运行时链接/加载错误的库您可能在运行时链接了错误的 Crypto++ 库。我通过准确控制链接的内容来避免它们,而不是依赖于运行时链接/加载程序。
您可以自由使用运行时链接/加载程序来执行这些操作,但必须注意确保您在运行时获得正确的库。为此,请参阅 GNUmakefile | Compiling and Linking .我认为您在第二种情况下被称为BAD:
Bad: the following will create problems because you compile and link against your copy of the library, but at runtime it links to the distro's copy of the library:
$ ls
cryptopp test.cxx
$ g++ -DNDEBUG -g2 -O2 -I . test.cxx -o test.exe -L ./cryptopp -lcryptopp
如果没有解决,那么你需要发布一个Minimal, Complete, and Verifiable example (MCVE) .很可能是在您的数据集下触发了一个断言。我们最近在 Trying to do CMAC on VS2013 and found this error. "Assertion failed: (input && length) || !(input || length)" 有一个.我们在收到报告后的数小时内 checkin 了修复程序,这还不到 30 天前。
我还需要查看您的编译和链接命令,以及 ldd
的输出以查看您链接的对象。
有时,如果您不提供纯文本或密文数据(input0.txt
和 output0.txt
),或者您没有提供,我们将无能为力'提供编译和链接命令等详细信息。
关于c++ - 模板化模式对象和外部密码对象有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36247336/
对此感到疯狂,真的缺少一些东西。 我有webpack 4.6.0,webpack-cli ^ 2.1.2,所以是最新的。 在文档(https://webpack.js.org/concepts/mod
object Host "os.google.com" { import "windows" address = "linux.google.com" groups = ["linux"] } obj
每当我安装我的应用程序时,我都可以将数据库从 Assets 文件夹复制到 /data/data/packagename/databases/ .到此为止,应用程序工作得很好。 但 10 或 15 秒后
我在 cc 模式缓冲区中使用 hideshow.el 来折叠我不查看的文件部分。 如果能够在 XML 文档中做到这一点就好了。我使用 emacs 22.2.1 和内置的 sgml-mode 进行 xm
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
根据java: public Scanner useDelimiter(String pattern) Sets this scanner's delimiting pattern to a patt
我读过一些关于 PRG 模式以及它如何防止用户重新提交表单的文章。比如this post有一张不错的图: 我能理解为什么在收到 2xx 后用户刷新页面时不会发生表单提交。但我仍然想知道: (1) 如果
看看下面的图片,您可能会清楚地看到这一点。 那么如何在带有其他一些 View 的简单屏幕中实现没有任何弹出/对话框/模式的微调器日期选择器? 我在整个网络上进行了谷歌搜索,但没有找到与之相关的任何合适
我不知道该怎么做,我一直遇到问题。 以下是代码: rows = int(input()) for i in range(1,rows): for j in range(1,i+1):
我想为重写创建一个正则表达式。 将所有请求重写为 index.php(不需要匹配),它不是以/api 开头,或者不是以('.html',或'.js'或'.css'或'.png'结束) 我的例子还是这样
MVC模式代表 Model-View-Controller(模型-视图-控制器) 模式 MVC模式用于应用程序的分层开发 Model(模型) - 模型代表一个存取数据的对象或 JAVA PO
我想为组织模式创建一个 RDF 模式世界。您可能知道,组织模式文档基于层次结构大纲,其中标题是主要的分组实体。 * March auxiliary :PROPERTIES: :HLEVEL: 1 :E
我正在编写一个可以从文件中读取 JSON 数据的软件。该文件包含“person”——一个值为对象数组的对象。我打算使用 JSON 模式验证库来验证内容,而不是自己编写代码。符合代表以下数据的 JSON
假设我有 4 张 table 人 公司 团体 和 账单 现在bills/persons和bills/companys和bills/groups之间是多对多的关系。 我看到了 4 种可能的 sql 模式
假设您有这样的文档: doc1: id:1 text: ... references: Journal1, 2013, pag 123 references: Journal2, 2014,
我有这个架构。它检查评论,目前工作正常。 var schema = { id: '', type: 'object', additionalProperties: false, pro
这可能很简单,但有人可以解释为什么以下模式匹配不明智吗?它说其他规则,例如1, 0, _ 永远不会匹配。 let matchTest(n : int) = let ran = new Rand
我有以下选择序列作为 XML 模式的一部分。理想情况下,我想要一个序列: 来自 my:namespace 的元素必须严格解析。 来自任何其他命名空间的元素,不包括 ##targetNamespace和
我希望编写一个 json 模式来涵盖这个(简化的)示例 { "errorMessage": "", "nbRunningQueries": 0, "isError": Fals
首先,我是 f# 的新手,所以也许答案很明显,但我没有看到。所以我有一些带有 id 和值的元组。我知道我正在寻找的 id,我想从我传入的三个元组中选择正确的元组。我打算用两个 match 语句来做到这
我是一名优秀的程序员,十分优秀!