我只想使用 128 位密钥对 4096 字节数据进行 DES 加密

发布于 2024-10-11 07:33:07 字数 1378 浏览 5 评论 0原文

...OpenSSL 的好心人慷慨地为我提供的是 这个。 :)

现在,因为你不应该猜测使用密码学时,我来这里是为了确认:我要使用的函数调用是什么?


我的理解

128 位密钥有 16 字节大,所以我需要双 DES(2 × 8 字节)。这让我只剩下几个函数调用:

void DES_ede2_cfb64_encrypt(const unsigned char *in,
       unsigned char *out, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int *num, int enc);

void DES_ede2_cbc_encrypt(const unsigned char *input,
       unsigned char *output, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int enc);

void DES_ede2_cfb64_encrypt(const unsigned char *in,
       unsigned char *out, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int *num, int enc);

void DES_ede2_ofb64_encrypt(const unsigned char *in,
       unsigned char *out, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int *num);

在这种情况下,我猜测我想要调用DES_ede2_cfb64_encrypt的函数,尽管我不太确定 - 我绝对不知道这里不需要填充,我必须关心 ivecnum 是,以及我想如何生成它们......

我缺少什么?

...and what the nice folks at OpenSSL gratiously provide me with is this. :)

Now, since you shouldn't be guessing when using cryptography, I come here for confirmation: what is the function call I want to use?


What I understood

A 128 bits key is 16 byte large, so I'll need double DES (2 × 8 byte). This leaves me with only a few function calls:

void DES_ede2_cfb64_encrypt(const unsigned char *in,
       unsigned char *out, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int *num, int enc);

void DES_ede2_cbc_encrypt(const unsigned char *input,
       unsigned char *output, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int enc);

void DES_ede2_cfb64_encrypt(const unsigned char *in,
       unsigned char *out, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int *num, int enc);

void DES_ede2_ofb64_encrypt(const unsigned char *in,
       unsigned char *out, long length, DES_key_schedule *ks1,
       DES_key_schedule *ks2, DES_cblock *ivec, int *num);

In this case, I guess the function I want to call DES_ede2_cfb64_encrypt, although I'm not so sure -- I definitely don't need padding here and I'd have to care about what ivec and num are, and how I want to generate them...

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

‖放下 2024-10-18 07:33:07

DES_ede2_cbc_encrypt 是正常选择。对于ivec(8字节数组)来说,它的作用之一是防止同一条消息以可预测的方式加密成同一个密文;如果对手可以从两个密文中判断出他们是否加密相同的明文(或只是相同的初始块),他们也许能够使用该信息。因此,您对每条消息使用不同的ivec;它不必是秘密的,只是不同而已。如果你确实确定不需要它,可以将其设置为八个零字节。 (例如,如果您只使用该密钥一次,则这样做是安全的。)

DES_ede2_cbc_encrypt is the normal choice. As for ivec (an 8-byte array), one of its functions is to prevent the same message encrypting to the same ciphertext in a predictable way; if an adversary can tell from two ciphertexts whether or not they encrypt the same plaintext (or just the same initial blocks), they might be able to use that information. So you use a different ivec for each message; it doesn't have to be secret, just different. If you're really sure that you don't need it, you can set it to eight zero bytes. (For instance, if you're just using the key once, it's safe to do this.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文