mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
ChaCha20 decrypt
This commit is contained in:
parent
af65af5be9
commit
9188e3ad3f
3 changed files with 26 additions and 3 deletions
|
@ -1228,6 +1228,23 @@ namespace crypto
|
|||
#endif
|
||||
}
|
||||
|
||||
void ChaCha20 (const uint8_t * msg, size_t msgLen, const uint8_t * key, const uint8_t * nonce, uint8_t * out)
|
||||
{
|
||||
#if OPENSSL_AEAD_CHACHA20_POLY1305
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new ();
|
||||
EVP_EncryptInit_ex(ctx, EVP_chacha20 (), 0, key, nonce);
|
||||
int outlen = 0;
|
||||
EVP_EncryptUpdate(ctx, out, &outlen, msg, msgLen);
|
||||
EVP_EncryptFinal_ex(ctx, NULL, &outlen);
|
||||
EVP_CIPHER_CTX_free (ctx);
|
||||
#else
|
||||
chacha::Chacha20State state;
|
||||
chacha::Chacha20Init (state, nonce, key, 0);
|
||||
if (out != msg) memcpy (out, msg, msgLen);
|
||||
chacha::Chacha20Encrypt (state, out, msgLen);
|
||||
#endif
|
||||
}
|
||||
|
||||
// init and terminate
|
||||
|
||||
/* std::vector <std::unique_ptr<std::mutex> > m_OpenSSLMutexes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue