everard / Salsa20

C++ implementation of stream cypher Salsa20
MIT License
22 stars 9 forks source link

Decrypt #2

Open Valduis4 opened 2 years ago

Valduis4 commented 2 years ago

I am trying to decrypt the encryption but it keeps encrypting further. Is there something I am missing? `string sKey = "help"; string siv = "test"; uint8_t key =(uint8_t ) sKey.c_str(); uint8_t iv =(uint8_t ) siv.c_str(); ucstk::Salsa20 salsa20(key); salsa20.setIv(iv);

string sinput = "help";
uint8_t * input =(uint8_t *) sinput.c_str();
// uint8_t * output;

salsa20.processBytes(input, input, sinput.size());

cout << "Output: "<< input << "\n";`

Output : )┴à┴

`string sKey = "help"; string siv = "test"; uint8_t key =(uint8_t ) sKey.c_str(); uint8_t iv =(uint8_t ) siv.c_str(); ucstk::Salsa20 salsa20(key); salsa20.setIv(iv);

string sinput = ")┴à┴";
uint8_t * input =(uint8_t *) sinput.c_str();
// uint8_t * output;

salsa20.processBytes(input, input, sinput.size());

cout << "Output: "<< input << "\n";

` Output: hF}♣╔┤‼0o

everard commented 2 years ago

Sorry for the late reply. Salsa's IV must be 8 bytes long, but you are using only 4 bytes for it, so you have Undefined Behavior in your code.

As a side note: this repo is really-really old, but there is a type-safe C++20 implementation of the Salsa stream cypher: https://github.com/everard/libecstk-crypto/blob/master/src/crypto_stream_salsa.hh https://github.com/everard/libecstk-buffer/blob/master/src/buffer.hh