OpenSSL:加密/解密例程的输入和输出缓冲区可以相同吗? [英] OpenSSL: can input and output buffers be the same for encrypt/decrypt routines?
本文介绍了OpenSSL:加密/解密例程的输入和输出缓冲区可以相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,在:
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
int *outl, unsigned char *in, int inl);
... out
== in
可以吗?
… can out
== in
?
推荐答案
我只是偶然发现了这个问题,因为我很好奇.由于没有人回答,我尝试了一下,它确实可以工作(至少使用AES CTR 128解密),所以我敢猜测它也可以用于其他类型.如果您有兴趣,这是我的代码示例.
I just stumbled upon this question because I was curious myself. Since no one answered, I tried it out and it does indeed work (at least with AES CTR 128 decryption) so I would venture to guess that it works for other types as well. Here's my code sample in case you are interested.
/* Test Vector from http://www.inconteam.com/software-development/41-encryption/55-aes-test-vectors */
const unsigned char key[16] = { 0x2b, 0x7e, 0x15, 0x16,
0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88,
0x09, 0xcf, 0x4f, 0x3c };
const unsigned char IV[16] = { 0xf0, 0xf1, 0xf2, 0xf3,
0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb,
0xfc, 0xfd, 0xfe, 0xff };
unsigned char test[16] = { 0x6b, 0xc1, 0xbe, 0xe2,
0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11,
0x73, 0x93, 0x17, 0x2a };
EVP_CIPHER_CTX mCtx;
EVP_DecryptInit(&mCtx, EVP_aes_128_ctr(), key, IV);
int out_size;
EVP_DecryptUpdate(&mCtx, test, &out_size, test, 16);
这篇关于OpenSSL:加密/解密例程的输入和输出缓冲区可以相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文