我只想使用 128 位密钥对 4096 字节数据进行 DES 加密
...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
的函数,尽管我不太确定 - 我绝对不知道这里不需要填充,我必须关心 ivec
和 num
是,以及我想如何生成它们......
我缺少什么?
...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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DES_ede2_cbc_encrypt
是正常选择。对于ivec
(8字节数组)来说,它的作用之一是防止同一条消息以可预测的方式加密成同一个密文;如果对手可以从两个密文中判断出他们是否加密相同的明文(或只是相同的初始块),他们也许能够使用该信息。因此,您对每条消息使用不同的ivec
;它不必是秘密的,只是不同而已。如果你确实确定不需要它,可以将其设置为八个零字节。 (例如,如果您只使用该密钥一次,则这样做是安全的。)DES_ede2_cbc_encrypt
is the normal choice. As forivec
(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 differentivec
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.)