RustCrypto / stream-ciphers

Collection of stream cipher algorithms
255 stars 49 forks source link

Does it allow to call decryption method explicitly? #321

Closed oilel closed 1 year ago

oilel commented 1 year ago

The document says:

// decrypt ciphertext by applying keystream again
cipher.apply_keystream(&mut buffer);

Does it have explicit methods for encryption and decryption rather than applying key again?

newpavlov commented 1 year ago

(Synchronous) stream ciphers work by generating keystream and XORing it with data, so encryption and decryption is the same operation. In other words, "encrypting" plaintext twice with the same cipher will result in plaintext. Stream ciphers are rarely used in isolation (a naive use of unauthenticated stream ciphers often leads to serious vulnerabilities), usually it's a building block for higher-level constructs. I strongly recommend you use one of the AEAD algorithms.