- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在编写一个程序,用 pbkdf2 method using cryptopp 散列密码.
我在验证密码时遇到问题。我试图比较“长度常数”时间的输出,但它总是失败并返回 false。
// a and b are std strings containing the output of the DeriveKey function
unsigned diff = a.length() ^ b.length();
for(unsigned i = 0; i < a.length() && i < b.length(); i++)
{
diff |= (unsigned)a[i] ^ (unsigned)b[i];
}
bool equal = diff == 0;
使用“slow equals”甚至是验证 pbkdf2 密码的正确方法吗?我对此有点困惑。
最佳答案
I'm writing a program which hashes passwords with the pbkdf2 method using cryptopp.
您链接到 Crypto++ 主页,而不是您对 PBKDF 的特定使用。这是 some code以防万一(它使用来自 RFC 6070 的 IETF 测试 vector ):
int main(int argc, char* argv[])
{
byte password[] ="password";
size_t plen = strlen((const char*)password);
byte salt[] = "salt";
size_t slen = strlen((const char*)salt);
int c = 1;
byte derived[20];
PKCS5_PBKDF2_HMAC<CryptoPP::SHA1> 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;
return 0;
}
I have tried to compare the output in "length-constant" time but it always fails and returns false.
Crypto++ 具有内置的恒定时间比较。使用来自 misc.h
的 VerifyBufsEqual
.来源可在 misc.cpp
中找到。 .
$ cd cryptopp
$ grep -R VerifyBufsEqual *
cryptlib.cpp: return VerifyBufsEqual(digest, digestIn, digestLength);
default.cpp: if (!VerifyBufsEqual(check, check+BLOCKSIZE, BLOCKSIZE))
fipstest.cpp: if (!VerifyBufsEqual(expectedModuleMac, actualMac, macSize))
fipstest.cpp: if (VerifyBufsEqual(expectedModuleMac, actualMac, macSize))
misc.cpp:bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
misc.h:CRYPTOPP_DLL bool CRYPTOPP_API VerifyBufsEqual(const byte *buf1, const byte *buf2, size_t count);
pssr.cpp: valid = VerifyBufsEqual(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second) && valid;
pubkey.cpp: return VerifyBufsEqual(representative, computedRepresentative, computedRepresentative.size());
secblock.h: return m_size == t.m_size && VerifyBufsEqual(m_ptr, t.m_ptr, m_size*sizeof(T));
我不清楚的是:VerifyBufsEqual
是基于相等长度的缓冲区。我不确定是否可以忽略“不等长”的情况。
Information Stack Exchange 上还有一个可能相关的问题:Timing attacks on password hashes .但我不确定它是否/如何推广到任意缓冲区比较。
这个问题激起了我对一般问题的答案的兴趣(这个问题一直存在):Constant time compares when array sizes are not equal? .这应该告诉我们是否在 VerifyBufsEqual
(Crypto++)、CRYPTO_memcmp
(OpenSSL) 等中有合适的工具。
关于c++ - 使用 Crypto++ 比较恒定时间密码摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21890441/
我正在尝试更新一些较旧的代码以消除警告。我已经升级了一些使用加密模块的代码。然而,webpack 5.88.2没有识别新的语法。我的新导入内容如下所示:。完整的错误如下所示。这表明我可能需要另一个插件
是否有任何 C 或 C++ 函数可以产生与此 python 代码相同的输出(SHA512 with salt)? import crypt; crypt.crypt('test', '$6$Salte
我正在开发一个使用 Crypto++ 使用 RSA 加密一些数据的项目。 这是我的 Crypto++ 代码: string plain = "Text123", encoded, cipher; st
收到错误,因为 require 不是一个函数,尝试在 typescript 组件中使用加密 js 函数 // Load modules 'use strict'; var Crypto = requi
我正在尝试将下面的java代码转换为nodejs。 public static String encrypt(String accessToken) throws Exception {
我有一个旨在在 Node.js 中使用的签名方法,但我想使用 crypto-js 在客户端实现它。它应该可以在最新的 Chrome 版本中运行。 我尝试遵循以下一些答案:Decode a Base64
我想知道 Crypto.Signature.PKCS1_v1_5 和 Crypto.Signature.pkcs1_15 有什么区别? 在documentation他们使用此函数 Crypto.Sig
我们有一个使用 Crypto++ 库的 ECC 部分的 C++ 解决方案,但必须转移到 .NET 解决方案。由于 Microsoft 的 ECC 代码的文档最少,我目前正在试验文档最少的 Bouncy
我在验证 Web Crypto API 创建的签名时遇到问题。 这是我用来在浏览器中生成 RSA key 的代码: let keys; const generateKeys = async () =>
嗨,所以我有一个运行 Crypto 的服务器,它工作得很好。我使用 electrojs 作为客户端,并且加密应该内置到 Node 中。当我尝试使用该模块时,它返回“crypto.scryptSync
使用 Apple 的 Common Crypto 和 Crypto++ 使用相同的 key 加密相同的文件(二进制数据)时,我得到了不同的结果。我使用的算法是 AES。 这是使用 Common Cry
如何存储 crypto.createHash('sha1') 的当前状态(在它被 hash.update(buffer) 填充后)以在另一个地方使用它http请求可能发生在node.js的不同进程?
我正在使用 NodeJS 的捆绑 crypto服务器端的 SHA256 哈希模块。在客户端,我使用一个名为 Crypto-JS 的 javascript 库. 我将 SHA256 哈希值用于使用基于经
我想编写一个使用 linux crypto-api 进行数字签名的 C 程序。不幸的是,我找不到关于 linux api 和 linux/crypto.h 中定义的函数的良好文档(谷歌搜索没有帮助,这
我正在尝试使用 JUNIT 在实际执行 AES 加密的方法中模拟 cipher.doFinal()。我在启动 JUNIT 测试用例时遇到异常 "Tried to access class javax.
您好,我在Liferay dxp项目中使用Paytm校验和依赖项 但我得到error :com.sun.crypto.provider.AESCipher$General cannot be cast
我正在尝试使用 crypto-js javascript 库加密数据,并尝试使用 Node 加密库在 Nodejs 端解密相同的加密文本。我正在使用 AES 256 加密算法和 CTR 模式,没有填充
我想了解 javax.crypto.Mac 之间的区别和 javax.crypto.Cipher 。这两个类看起来非常相似(它们具有相似的方法,但是这两个类并不互相继承)。 这两个类之间的根本区别是什
我正在尝试在设备上生成 SHA256 和 HmacSHA512 哈希值,不幸的是,该设备不支持标准 Node crypto 库。所以我正在调整代码以使用 CryptoJS 代替。但是,CryptoJS
我正在使用 Android FingerPrintManager API 并使用 KeyPairGenerator 创建 key 对,我想使用公钥加密密码,然后在用户通过输入 fingerPrint
我是一名优秀的程序员,十分优秀!