Search code examples
opensslencryption-symmetriclibsodium

ChaCha20 without authentication in either libsodium or OpenSSL


I'm trying to use ChaCha20 without any authentication. I don't think I can do it in libsodium https://download.libsodium.org/doc/secret-key_cryptography/original_chacha20-poly1305_construction.html

I looked up OpenSSL's API https://github.com/openssl/openssl/blob/master/crypto/include/internal/chacha.h and this seems to allow it without any authentication. However, there is no encrypt or decrypt function, only

void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp,
                    size_t len, const unsigned int key[8],
                    const unsigned int counter[4]);

I'm confused about what this does, does it encrypt or decrypt?


Solution

  • The OpenSSL header file you are pointing at is an internal header file and does not form part of the public API. What you need to use is the EVP API using the EVP_chacha20() cipher.

    See this man page for the various functions: https://www.openssl.org/docs/man1.1.0/crypto/EVP_EncryptInit_ex.html

    There is some sample code here: https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption