- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找 OpenSSL EVP_BytesToKey
函数的 C 实现。
这是 EVP_BytesToKey 方法的伪代码解释(在 OpenSSL 源代码的/doc/ssleay.txt 中):
/* M[] is an array of message digests
* MD() is the message digest function */
M[0]=MD(data . salt);
for (i=1; i<count; i++) M[0]=MD(M[0]);
i=1
while (data still needed for key and iv)
{
M[i]=MD(M[i-1] . data . salt);
for (i=1; i<count; i++) M[i]=MD(M[i]);
i++;
}
If the salt is NULL, it is not used.
The digests are concatenated together.
M = M[0] . M[1] . M[2] .......
这是我的代码(MD()是sha512。我需要 key 是32字节,iv是16字节):
int main()
{
unsigned long long out[8];
unsigned char key[9] = {0x4b,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c};
int len, i;
len = sizeof(key);
sha512(out, key, len);
unsigned char a[sizeof(out)];
for (i = 0; i < count; i++)
{
long2char(out, a); // unsigned long long to unsigned char;
sha512(out, a, sizeof(out));
}
return 0;
}
经过 count
次 sha512()
后,输出为 64 字节,所以我认为我不需要其余的伪代码。但结果不正确,不知道哪里出了问题。
我希望你能帮我解决这个问题。谢谢!
最佳答案
I'm looking for C implementation of the OpenSSL EVP_BytesToKey function...
也许您应该只使用 OpenSSL 提供的一个?您知道,evp_key.c
中名为 EVP_BytesToKey
的那个。 (如下所示)。
OpenSSL 1.1.0c changed the digest algorithm用于一些内部组件。之前使用MD5,1.1.0改用SHA256。请注意,更改不会影响 EVP_BytesToKey 和 openssl enc 等命令
<小时/>int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
const unsigned char *salt, const unsigned char *data,
int datal, int count, unsigned char *key,
unsigned char *iv)
{
EVP_MD_CTX *c;
unsigned char md_buf[EVP_MAX_MD_SIZE];
int niv, nkey, addmd = 0;
unsigned int mds = 0, i;
int rv = 0;
nkey = EVP_CIPHER_key_length(type);
niv = EVP_CIPHER_iv_length(type);
OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
if (data == NULL)
return nkey;
c = EVP_MD_CTX_new();
if (c == NULL)
goto err;
for (;;) {
if (!EVP_DigestInit_ex(c, md, NULL))
goto err;
if (addmd++)
if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
goto err;
if (!EVP_DigestUpdate(c, data, datal))
goto err;
if (salt != NULL)
if (!EVP_DigestUpdate(c, salt, PKCS5_SALT_LEN))
goto err;
if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
goto err;
for (i = 1; i < (unsigned int)count; i++) {
if (!EVP_DigestInit_ex(c, md, NULL))
goto err;
if (!EVP_DigestUpdate(c, &(md_buf[0]), mds))
goto err;
if (!EVP_DigestFinal_ex(c, &(md_buf[0]), &mds))
goto err;
}
i = 0;
if (nkey) {
for (;;) {
if (nkey == 0)
break;
if (i == mds)
break;
if (key != NULL)
*(key++) = md_buf[i];
nkey--;
i++;
}
}
if (niv && (i != mds)) {
for (;;) {
if (niv == 0)
break;
if (i == mds)
break;
if (iv != NULL)
*(iv++) = md_buf[i];
niv--;
i++;
}
}
if ((nkey == 0) && (niv == 0))
break;
}
rv = EVP_CIPHER_key_length(type);
err:
EVP_MD_CTX_free(c);
OPENSSL_cleanse(md_buf, sizeof(md_buf));
return rv;
}
关于OpenSSL EVP_BytesToKey 方法的 C 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534656/
如果我使用open ssl命令 sudo openssl genrsa -out privkey.pem 2048 要生成rsa key ,它仅生成1个文件。这是私钥。我如何获得公钥。 最佳答案 回答
三个不同版本的 openssl 正在同时更新 openssl.org : 0.98, 1.0.0, 1.0.1?它们之间有什么区别,我该如何选择要使用的版本? 最佳答案 https://en.wiki
我有以下命令用于 OpenSSL 生成私钥和公钥: openssl genrsa –aes-128-cbc –out priv.pem –passout pass:[privateKeyPass] 2
我正在尝试使用对应的 gcc (arm-none-eabi-5_4-2016q2) 为 cortex m3 机器交叉编译 openssl。机器应该有能力做 TCP 请求,我们希望在一天结束时做 HTT
我正在尝试使用 openssl dsa 实现,但我对以下细节感到非常困惑: 命令 openssl dsa .... 的选项“-text”:输出中的十六进制数字,我是否正确地假设这些是字节,因此它们是按
我正在尝试制作一个假 CA 并用它签署一个证书以与 stunnel 一起使用(这似乎只是调用 OpenSSL 例程,因此您可能不需要了解该程序来提供帮助:)。然而,stunnel 一直拒绝我的证书,说
不幸的是,Perl 在尝试安装 OpenSSL 的手册页(例如 OpenSSL_1_0_1g)时不知何故遇到了错误。因为我不需要它们 - 我只想使用 OpenSSL 作为 C 库,我想我可以通过完全跳
OpenSSL 中的 BIO 对到底是什么?它的用途是什么?我已经检查过 OpenSSL 文档,但任何细节都很少。 最佳答案 OpenSSL 中的 BIO 类似于文件句柄。您可以使用一对它们来安全地相
openssl ca 和 openssl x509 命令有什么区别?我正在使用它来创建和签署我的 root-ca、intermed-ca 和客户端证书,但是 openssl ca 命令不会在证书上注册
如何(如果有的话)为 OpenSSL 定义一个单一的可信证书文件在 Windows(Win-7,OpenSSL 1.0.1c)上使用 SSL_CERT_FILE 环境变量? 各种研究促使我下载了 Mo
我有一个自签名证书,其中显示了列出的基本约束,但从中生成的签名请求不显示这些属性,例如 [v3_req]。我怎样才能让它可见?我正在使用 openssl 生成证书。 场景: 我使用以下方法创建自签名证
这个问题在这里已经有了答案: Check if a connection is TLSv1 vs SSLv3 (SSL_CIPHER_description/SSL_CIPHER_get_name)
是否有更简单的方法来确定在构建 openssl 期间指定的选项,例如当时是否定义了 OPENSSL_NO_SRTP? 我只能从以下方面获得有限的信息: openssl 版本 -a 命令。但是,如果我只
我们正在与 AWS Nitro 合作,仅提供 3 小时的证书。 我们正在寻找一种可以跳过验证中的过期部分并仍然确认证书链有效的方法。 最佳答案 根据 openssl-verify 文档
嗨,我如何在 Easyphp 中启用 openssl,因为我收到错误消息无法发送。Mailer 错误:缺少扩展:opensslTime:使用 phpmailer 时。谢谢 最佳答案 在您的 php.i
我正在尝试以编程方式读取 OpenSSL 警报消息,但无法找到执行此操作的方法。 OpenSSL API 提供如下功能: const char *SSL_alert_type_string(int v
我跑了openssl speed在我的 Ubuntu 计算机上。一些结果: Doing md4 for 3s on 16 size blocks: 9063888 md4's in 3.00s Doi
我编译了带有cryptodev支持(即硬件加速)的OpenSSL,但不幸的是默认引擎仍然是软件。 time openssl speed -evp aes-128-cbc -engine cryptod
我需要从 RedHat Linux 服务器连接到 Microsoft Dynamics CRM 服务器。地址是xxx.api.crm4.dynamics.com。服务器接受 TLSv1 但不接受 1.
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 上个月关闭。 Improve thi
我是一名优秀的程序员,十分优秀!