鍍金池/ 問答/C++  Linux  網(wǎng)絡(luò)安全/ chacha20流加密的解密問題

chacha20流加密的解密問題

ChaCha20 is a stream cipher developed by Daniel J. Bernstein. Its original design expands a 256-bit key into 2^64 randomly accessible streams, each containing 2^64 randomly accessible 64-byte (512 bits) blocks. It is a variant of Salsa20 with better diffusion.

在用libsodium的庫 chacha20流加密算法

int crypto_stream_chacha20(unsigned char *c, unsigned long long clen,
                           const unsigned char *n, const unsigned char *k);

第一個函數(shù)是不可逆的 不知道有什么意義 只能得到密文 把密文再扔進去什么都不變

int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,
                               unsigned long long mlen, const unsigned char *n,
                               const unsigned char *k);
                               

第二個函數(shù)可以
1.將m用k,n計算輸出c(密文)
2.把m換成密文c則輸出明文

那么問題來了,如果你的密文缺了一段
比如說一個4個char長度密文 0x01 0x02 0x03 0x04
如果你缺了0x01 0x02 你是沒有辦法解密后面兩個的
但是你缺了0x03 0x04 前面兩個還是可以解出明文

這種情況也屬于流加密?
這不是塊加密嗎 這將明文定了界,要數(shù)據(jù)塊完整才能正確解密啊

回答
編輯回答
疚幼

無解 只能手動分塊加長度header 需要無腦加解密只能用table
一直以為流加密逐個對單字節(jié)加密 然而全部實現(xiàn)都分塊處理分塊異或
所以市面上的aes rc4 chacha 各種流加密都是假的

總結(jié): 只有塊加密

2018年3月16日 11:59